Trigger panel: able to set custom last change time format (based

on moment.js).
This commit is contained in:
Alexander Zobnin
2016-02-03 19:54:44 +03:00
parent 4c73f74159
commit 19d1cc315e
2 changed files with 42 additions and 4 deletions

View File

@@ -81,7 +81,7 @@ function (angular, app, _, $, moment, config, PanelMeta) {
sortTriggersBy: { text: 'last change', value: 'lastchange' },
showEvents: { text: 'Problem events', value: '1' },
triggerSeverity: grafanaDefaultSeverity,
okEventColor: '#890F02'
okEventColor: '#890F02',
};
_.defaults($scope.panel, panelDefaults);
@@ -97,7 +97,8 @@ function (angular, app, _, $, moment, config, PanelMeta) {
var scopeDefaults = {
metric: {},
inputStyles: {},
oldTarget: _.cloneDeep($scope.panel.triggers)
oldTarget: _.cloneDeep($scope.panel.triggers),
defaultTimeFormat: "DD MMM YYYY HH:mm:ss"
};
_.defaults($scope, scopeDefaults);
@@ -141,7 +142,12 @@ function (angular, app, _, $, moment, config, PanelMeta) {
// Format last change and age
trigger.lastchangeUnix = Number(trigger.lastchange);
var timestamp = moment.unix(trigger.lastchangeUnix);
triggerObj.lastchange = timestamp.format("DD MMM YYYY, HH:mm:ss");
if ($scope.panel.customLastChangeFormat) {
// User defined format
triggerObj.lastchange = timestamp.format($scope.panel.lastChangeFormat);
} else {
triggerObj.lastchange = timestamp.format($scope.defaultTimeFormat);
}
triggerObj.age = timestamp.fromNow(true);
// Set color