ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xiw...@apache.org
Subject git commit: AMBARI-5116. Alert Duration shows 44 years. (xiwang)
Date Mon, 17 Mar 2014 23:39:38 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 1d2900fcc -> 7dd65f2e2


AMBARI-5116. Alert Duration shows 44 years. (xiwang)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/7dd65f2e
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/7dd65f2e
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/7dd65f2e

Branch: refs/heads/trunk
Commit: 7dd65f2e25c3ddd93858b3ca7fc8653d3d8fbc12
Parents: 1d2900f
Author: Xi Wang <xiwang@apache.org>
Authored: Mon Mar 17 14:08:04 2014 -0700
Committer: Xi Wang <xiwang@apache.org>
Committed: Mon Mar 17 16:38:40 2014 -0700

----------------------------------------------------------------------
 ambari-web/app/messages.js     | 21 ++++++++++++++++-----
 ambari-web/app/models/alert.js | 36 +++++++++++++++++++++++++++---------
 ambari-web/app/utils/helper.js | 13 ++++++++-----
 3 files changed, 51 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/7dd65f2e/ambari-web/app/messages.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/messages.js b/ambari-web/app/messages.js
index 02c2af3..38273a3 100644
--- a/ambari-web/app/messages.js
+++ b/ambari-web/app/messages.js
@@ -196,6 +196,9 @@ Em.I18n.translations = {
   'common.maintenance.task': ' Toggle Maintenance Mode',
   'common.used': 'used',
   'common.free': 'free',
+  'common.type.string': 'string',
+  'common.type.number': 'number',
+
   'passiveState.turnOn':'Turn On Maintenance Mode',
   'passiveState.turnOff':'Turn Off Maintenance Mode',
   'passiveState.turnOnFor':'Turn On Maintenance Mode for {0}',
@@ -298,11 +301,19 @@ Em.I18n.translations = {
 
 
   'services.alerts.head':'You have {0} critical alert notification(s).',
-  'services.alerts.OK.timePrefix': 'OK for ',
-  'services.alerts.WARN.timePrefix': 'WARN for ',
-  'services.alerts.CRIT.timePrefix': 'CRIT for ',
-  'services.alerts.MAINT.timePrefix': 'MAINT for ',
-  'services.alerts.UNKNOWN.timePrefix': 'UNKNOWN for ',
+  'services.alerts.OK.timePrefixShort': 'OK',
+  'services.alerts.WARN.timePrefixShort': 'WARN',
+  'services.alerts.CRIT.timePrefixShort': 'CRIT',
+  'services.alerts.MAINT.timePrefixShort': 'MAINT',
+  'services.alerts.UNKNOWN.timePrefixShort': 'UNKNOWN',
+  'services.alerts.OK.timePrefix': 'OK for {0}',
+  'services.alerts.WARN.timePrefix': 'WARN for {0}',
+  'services.alerts.CRIT.timePrefix': 'CRIT for {0}',
+  'services.alerts.MAINT.timePrefix': 'MAINT for {0}',
+  'services.alerts.UNKNOWN.timePrefix': 'UNKNOWN for {0}',
+  'services.alerts.lastCheck': 'Last Checked {0}',
+  'services.alerts.brLastCheck': '<br>Last Checked {0}',
+  'services.alerts.occurredOn': 'Occurred on {0}, {1}',
   'services.alerts.headingOfList': 'Alerts and Health Checks',
   'services.alerts.goToService': 'Go to Service',
   'services.alerts.goToNagios': 'Go to Nagios Web UI',

http://git-wip-us.apache.org/repos/asf/ambari/blob/7dd65f2e/ambari-web/app/models/alert.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/models/alert.js b/ambari-web/app/models/alert.js
index cd3e92a..9a5281e 100644
--- a/ambari-web/app/models/alert.js
+++ b/ambari-web/app/models/alert.js
@@ -85,28 +85,46 @@ App.Alert = Em.Object.extend({
   timeSinceAlert: function () {
     var d = this.get('date');
     if (d) {
-      var prefix = this.t('services.alerts.OK.timePrefix');
+      var timeFormat = this.t('services.alerts.OK.timePrefix');
       switch (this.get('status')) {
         case "1":
-          prefix = this.t('services.alerts.WARN.timePrefix');
+          timeFormat = this.t('services.alerts.WARN.timePrefix');
           break;
         case "2":
-          prefix = this.t('services.alerts.CRIT.timePrefix');
+          timeFormat = this.t('services.alerts.CRIT.timePrefix');
           break;
         case "3":
-          prefix = this.t('services.alerts.MAINT.timePrefix');
+          timeFormat = this.t('services.alerts.MAINT.timePrefix');
           break;
         case "4":
-          prefix = this.t('services.alerts.UNKNOWN.timePrefix');
+          timeFormat = this.t('services.alerts.UNKNOWN.timePrefix');
           break;
       }
       var prevSuffix = $.timeago.settings.strings.suffixAgo;
       $.timeago.settings.strings.suffixAgo = '';
-      var since = prefix + $.timeago(this.makeTimeAtleastMinuteAgo(d));
+      var since = timeFormat.format($.timeago(this.makeTimeAtleastMinuteAgo(d)));
       $.timeago.settings.strings.suffixAgo = prevSuffix;
       return since;
+    } else if (d == 0) {
+      var timeFormat = this.t('services.alerts.OK.timePrefixShort');
+      switch (this.get('status')) {
+        case "1":
+          timeFormat = this.t('services.alerts.WARN.timePrefixShort');
+          break;
+        case "2":
+          timeFormat = this.t('services.alerts.CRIT.timePrefixShort');
+          break;
+        case "3":
+          timeFormat = this.t('services.alerts.MAINT.timePrefixShort');
+          break;
+        case "4":
+          timeFormat = this.t('services.alerts.UNKNOWN.timePrefixShort');
+          break;
+      }
+      return timeFormat;
+    } else {
+      return "";
     }
-    return "";
   }.property('date', 'status'),
   
   makeTimeAtleastMinuteAgo: function(d){
@@ -129,13 +147,13 @@ App.Alert = Em.Object.extend({
     if (date) {
       var dateString = date.toDateString();
       dateString = dateString.substr(dateString.indexOf(" ") + 1);
-      dateString = "Occurred on " + dateString + ", " + date.toLocaleTimeString();
+      dateString = Em.I18n.t('services.alerts.occurredOn').format(dateString, date.toLocaleTimeString());
       details += dateString;
     }
     var lastCheck = this.get('lastCheck');
     if (lastCheck) {
       lastCheck = new Date(lastCheck * 1000);
-      details = details + "<br>Last checked " + $.timeago(lastCheck);
+      details = details ? details + Em.I18n.t('services.alerts.brLastCheck').format($.timeago(lastCheck))
: Em.I18n.t('services.alerts.lastCheck').format($.timeago(lastCheck));
     }
     return details;
   }.property('lastCheck', 'date'),

http://git-wip-us.apache.org/repos/asf/ambari/blob/7dd65f2e/ambari-web/app/utils/helper.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/utils/helper.js b/ambari-web/app/utils/helper.js
index 1830c42..162fad0 100644
--- a/ambari-web/app/utils/helper.js
+++ b/ambari-web/app/utils/helper.js
@@ -476,15 +476,18 @@ App.registerBoundHelper('formatWordBreak', Em.View.extend({
 DS.attr.transforms.date = {
   from: function (serialized) {
     var type = typeof serialized;
-    if (type === "string") {
+    if (type === Em.I18n.t('common.type.string')) {
       serialized = parseInt(serialized);
       type = typeof serialized;
     }
-    if (type === "number") {
+    if (type === Em.I18n.t('common.type.number')) {
+      if (!serialized ){  //serialized timestamp = 0;
+        return 0;
+      }
       // The number could be seconds or milliseconds.
-      // If seconds, then multiplying with 1000 should still
-      // keep it below the current time.
-      if (serialized * 1000 < App.dateTime()) {
+      // If seconds, then the length is 10
+      // If milliseconds, the length is 13
+      if (serialized.toString().length < 13) {
         serialized = serialized * 1000;
       }
       return new Date(serialized);


Mime
View raw message