浏览代码

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

Xi Wang 11 年之前
父节点
当前提交
7dd65f2e25
共有 3 个文件被更改,包括 51 次插入19 次删除
  1. 16 5
      ambari-web/app/messages.js
  2. 27 9
      ambari-web/app/models/alert.js
  3. 8 5
      ambari-web/app/utils/helper.js

+ 16 - 5
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',

+ 27 - 9
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'),

+ 8 - 5
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);