Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Merge pull request #304 from vrockai/HAWKULAR-433
Browse files Browse the repository at this point in the history
HAWKULAR-433 Refactored ht-time-interval to support millis
  • Loading branch information
mtho11 committed Jul 8, 2015
2 parents 15566bf + 042d73e commit 4ac8f15
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,26 +84,59 @@ module Alert {
}
}

export class HkTime {

public static $inject = [];

public humanizeTime(timeMillis: number): any {
var result: any = {};

var sec_num: number = Math.floor(timeMillis / 1000);
var hours: number = Math.floor(sec_num / 3600);
var minutes: number = Math.floor((sec_num - (hours * 3600)) / 60);
var seconds: number = sec_num - (hours * 3600) - (minutes * 60);

if (hours !== 0) {
result.hours = hours;
}
if (minutes !== 0) {
result.minutes = minutes;
}
if (seconds !== 0) {
result.seconds = seconds;
}

return result;
}
}

export class HkTimeInterval {

public link: (scope: any, element: ng.IAugmentedJQuery, attrs: ng.IAttributes) => void;
public replace = 'true';
public scope = {
hkTime: '='
hkTimeMillis: '=hkTime'
};
public templateUrl = 'plugins/directives/alert/html/timeInterval.html';

constructor(private HkTime) {
this.link = (scope: any, element: ng.IAugmentedJQuery, attrs: ng.IAttributes) => {
scope.hkTime = HkTime.humanizeTime(scope.hkTimeMillis);
};
}

public static Factory() {
var directive = () => {
return new HkTimeInterval();
var directive = (HkTime: any) => {
return new HkTimeInterval(HkTime);
};

directive['$inject'] = [];
directive['$inject'] = ['hkTime'];

return directive;
}
}

_module.service('hkTime', Alert.HkTime);
_module.directive('hkAlertPanelList', Alert.HkAlertPanelList.Factory());
_module.directive('hkAlertPanel', Alert.HkAlertPanel.Factory());
_module.directive('hkTimeInterval', Alert.HkTimeInterval.Factory());
Expand Down
23 changes: 1 addition & 22 deletions console/src/main/scripts/plugins/metrics/ts/alertsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,27 +274,6 @@ module HawkularMetrics {
headers = getHeaders();
var momentNow = this.$moment();

var toTimeObj = (timeMillis: number) => {
var result: any = {};

var sec_num: number = Math.floor(timeMillis / 1000);
var hours: number = Math.floor(sec_num / 3600);
var minutes: number = Math.floor((sec_num - (hours * 3600)) / 60);
var seconds: number = sec_num - (hours * 3600) - (minutes * 60);

if (hours !== 0) {
result.hours = hours;
}
if (minutes !== 0) {
result.minutes = minutes;
}
if (seconds !== 0) {
result.seconds = seconds;
}

return result;
};

for (var i = 0; i < serverAlerts.length; i++) {
var consoleAlert: any = {};
var serverAlert = serverAlerts[i];
Expand Down Expand Up @@ -335,7 +314,7 @@ module HawkularMetrics {

consoleAlert.avg = sum/count;

consoleAlert.durationTime = toTimeObj(consoleAlert.end - consoleAlert.start);
consoleAlert.durationTime = consoleAlert.end - consoleAlert.start;

alertList.push(consoleAlert);
}
Expand Down

0 comments on commit 4ac8f15

Please sign in to comment.