From 19d1cc315e7827406c75f3b7a9ce996fd5bf7870 Mon Sep 17 00:00:00 2001 From: Alexander Zobnin Date: Wed, 3 Feb 2016 19:54:44 +0300 Subject: [PATCH] Trigger panel: able to set custom last change time format (based on moment.js). --- plugins/panel-triggers/editor.html | 34 +++++++++++++++++++++++++++++- plugins/panel-triggers/module.js | 12 ++++++++--- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/plugins/panel-triggers/editor.html b/plugins/panel-triggers/editor.html index bed41eb..d92105c 100644 --- a/plugins/panel-triggers/editor.html +++ b/plugins/panel-triggers/editor.html @@ -61,7 +61,7 @@ placeholder="trigger name" class="input-large tight-form-input last" ng-style="panel.triggers.trigger.style" - empty-to-null"> + empty-to-null>
@@ -192,6 +192,38 @@
+
+ +
+
diff --git a/plugins/panel-triggers/module.js b/plugins/panel-triggers/module.js index 6bf8cff..8f780bd 100644 --- a/plugins/panel-triggers/module.js +++ b/plugins/panel-triggers/module.js @@ -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