Fix date format and duration of alert in the web ui

This commit is contained in:
Floran Brutel 2015-05-05 22:12:32 +02:00
parent 9798fb41ca
commit 0dd873151e
2 changed files with 15 additions and 19 deletions

View File

@ -1,7 +1,7 @@
<div class="table">
<div class="table-row" ng-repeat="alert in result['alert']">
<div class="table-cell text-left">
{{alert.begin}} ({{(alert[1]-alert[0]) | date : 'h:mm:ss'}}) - {{alert[2]}} on {{alert[3]}} ({{alert[4]}})
{{alert.begin | date : 'yyyy-MM-dd H:mm:ss'}} ({{ alert.ongoing ? 'ongoing' : alert.duration }}) - {{alert[2]}} on {{alert[3]}} ({{alert[4]}})
</div>
</div>
</div>

View File

@ -106,22 +106,13 @@ glancesApp.controller('statsController', function($scope, $http, $interval, $q,
return hour +":" + minutes + ":" + seconds + "." + millisecondsStr
};
function dateformat(input) {
var millis = input * 1000.0;
var d = new Date(millis)
var year = d.getFullYear()
var month = leftpad(d.getMonth() + 1) // JANUARY = 0
var day = leftpad(d.getDate())
return year + "-" + month + "-" + day + " " + datetimeformat(input)
function durationBetweenTwoDates(startDate, endDate) {
var duration = endDate - startDate;
var seconds = parseInt((duration/1000)%60)
, minutes = parseInt((duration/(1000*60))%60)
, hours = parseInt((duration/(1000*60*60))%24);
}
function datetimeformat(input) {
var millis = input * 1000.0;
var d = new Date(millis)
var hour = leftpad(d.getUTCHours()) // TODO : multiple days ( * (d.getDay() * 24)))
var minutes = leftpad(d.getUTCMinutes())
var seconds = leftpad(d.getUTCSeconds())
return hour + ":" + minutes + ":" + seconds
return _.padLeft(hours,2,'0') + ":" + _.padLeft(minutes,2,'0') + ":" + _.padLeft(seconds,2,'0');
}
for (var i = 0; i < response['processlist'].length; i++) {
@ -134,9 +125,14 @@ glancesApp.controller('statsController', function($scope, $http, $interval, $q,
process.io_write = (process.io_counters[1] - process.io_counters[3]) / process.time_since_update
}
for (var i = 0; i < response['alert'].length; i++) {
var alert = response['alert'][i]
alert.begin = dateformat(alert[0])
alert.end = datetimeformat(alert[1] - alert[0])
var alert = response['alert'][i];
alert.begin = alert[0] * 1000;
alert.end = alert[1] * 1000;
alert.ongoing = alert[1] == -1;
if (!alert.ongoing) {
alert.duration = durationBetweenTwoDates(alert.begin, alert.end);
}
}
$scope.result = response;
canceler.resolve()