Skip to content

Commit

Permalink
fix #6058: raydata start and stop search times pre-populated (#6082)
Browse files Browse the repository at this point in the history
  • Loading branch information
rorour authored Jul 11, 2023
1 parent e118393 commit c1f7ad0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
23 changes: 22 additions & 1 deletion sirepo/package_data/static/js/raydata.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,12 @@ SIREPO.app.directive('dateTimePicker', function() {
$scope.model[$scope.field] = timeService.unixTime(newTime);
}
});

$scope.$watch('model.' + $scope.field, function(newTime, oldTime) {
if (newTime !== oldTime) {
$scope.dateTime = timeService.unixTimeToDate(newTime);
}
});
}
};
});
Expand Down Expand Up @@ -402,7 +408,7 @@ SIREPO.app.directive('scansTable', function() {
</div>
<div data-view-log-iframe-wrapper data-scan-id="runLogScanId" data-modal-id="runLogModalId" data-show-log="showLog"></div>
`,
controller: function(appState, errorService, panelState, raydataService, requestSender, $scope, $interval) {
controller: function(appState, errorService, panelState, raydataService, requestSender, timeService, $scope, $interval) {
$scope.analysisModalId = 'sr-analysis-output-' + $scope.analysisStatus;
$scope.availableColumns = [];
$scope.awaitingScans = false;
Expand Down Expand Up @@ -624,6 +630,20 @@ SIREPO.app.directive('scansTable', function() {
];
};

$scope.setDefaultStartStopTime = () => {
const m = appState.models[$scope.modelName];
if (!m.searchStartTime && !m.searchStopTime) {
$scope.setSearchTimeLastHour();
appState.saveChanges($scope.modelName);
}
};

$scope.setSearchTimeLastHour = () => {
const m = appState.models[$scope.modelName];
m.searchStartTime = timeService.roundUnixTimeToMinutes(timeService.unixTimeOneHourAgo());
m.searchStopTime = timeService.roundUnixTimeToMinutes(timeService.unixTimeNow());
};

$scope.setSelectedScan = (scan) => {
$scope.selectedScan = scan;
if ($scope.selectedScan !== null && ! [raydataService.ANALYSIS_STATUS_NONE, raydataService.ANALYSIS_STATUS_PENDING].includes($scope.selectedScan.status)) {
Expand Down Expand Up @@ -682,6 +702,7 @@ SIREPO.app.directive('scansTable', function() {
}
};

$scope.setDefaultStartStopTime();
$scope.$on(`${$scope.modelName}.changed`, sendScanRequest);
$scope.$on('catalog.changed', sendScanRequest);
$scope.$watchCollection('appState.models.metadataColumns.selected', (newValue, previousValue) => {
Expand Down
8 changes: 8 additions & 0 deletions sirepo/package_data/static/js/sirepo.js
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,10 @@ SIREPO.app.factory('timeService', function() {
const UNIX_TIMESTAMP_SCALE = 1000;
const self = {};

self.roundUnixTimeToMinutes = (date) => {
return Number.parseInt(date / 60) * 60;
};

self.unixTime = (date) => {
return Math.round(date.getTime() / UNIX_TIMESTAMP_SCALE);
};
Expand All @@ -1078,6 +1082,10 @@ SIREPO.app.factory('timeService', function() {
return self.unixTime(new Date());
};

self.unixTimeOneHourAgo = () => {
return self.unixTimeNow() - (60 * 60);
};

self.unixTimeToDate = (unixTime) => {
return new Date(unixTime * UNIX_TIMESTAMP_SCALE);
};
Expand Down

0 comments on commit c1f7ad0

Please sign in to comment.