You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by yu...@apache.org on 2012/12/09 15:42:33 UTC

svn commit: r1418981 - in /incubator/ambari/branches/AMBARI-666: ./ ambari-web/ ambari-web/app/assets/licenses/ ambari-web/app/mappers/ ambari-web/app/models/ ambari-web/app/styles/ ambari-web/app/templates/main/service/info/ ambari-web/app/views/main/...

Author: yusaku
Date: Sun Dec  9 14:42:31 2012
New Revision: 1418981

URL: http://svn.apache.org/viewvc?rev=1418981&view=rev
Log:
AMBARI-1039. Improve Nagios alerts time display. (Srimanth Gunturi via yusaku)

Added:
    incubator/ambari/branches/AMBARI-666/ambari-web/vendor/scripts/jquery.timeago.js
Modified:
    incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt
    incubator/ambari/branches/AMBARI-666/ambari-web/app/assets/licenses/NOTICE.txt
    incubator/ambari/branches/AMBARI-666/ambari-web/app/mappers/alerts_mapper.js
    incubator/ambari/branches/AMBARI-666/ambari-web/app/models/alert.js
    incubator/ambari/branches/AMBARI-666/ambari-web/app/styles/application.less
    incubator/ambari/branches/AMBARI-666/ambari-web/app/templates/main/service/info/client_summary.hbs
    incubator/ambari/branches/AMBARI-666/ambari-web/app/templates/main/service/info/summary.hbs
    incubator/ambari/branches/AMBARI-666/ambari-web/app/views/main/service/info/summary.js
    incubator/ambari/branches/AMBARI-666/ambari-web/config.coffee

Modified: incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt?rev=1418981&r1=1418980&r2=1418981&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt (original)
+++ incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt Sun Dec  9 14:42:31 2012
@@ -424,6 +424,8 @@ AMBARI-666 branch (unreleased changes)
 
   IMPROVEMENTS
 
+  AMBARI-1039. Improve Nagios alerts time display. (Srimanth Gunturi via yusaku)
+
   AMBARI-1036. Service Info/Quick Links do not display external hostnames.
   (Srimanth Gunturi via yusaku)
 

Modified: incubator/ambari/branches/AMBARI-666/ambari-web/app/assets/licenses/NOTICE.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-web/app/assets/licenses/NOTICE.txt?rev=1418981&r1=1418980&r2=1418981&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-web/app/assets/licenses/NOTICE.txt (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-web/app/assets/licenses/NOTICE.txt Sun Dec  9 14:42:31 2012
@@ -33,4 +33,7 @@ Copyright (c) 2012 Stefan Petre
 This product includes Font Awesome 2.0 (http://fortawesome.github.com/Font-Awesome - Creative Commons 3.0)
 
 This product incudes Rickshaw 1.1.2 (http://code.shutterstock.com/rickshaw/ - MIT License)
-Copyright (C) 2011 by Shutterstock Images, LLC
\ No newline at end of file
+Copyright (C) 2011 by Shutterstock Images, LLC
+
+This product includes Timeago (http://timeago.yarp.com/ - MIT License)
+Copyright (c) 2008-2012, Ryan McGeary (ryan -[at]- mcgeary [*dot*] org)
\ No newline at end of file

Modified: incubator/ambari/branches/AMBARI-666/ambari-web/app/mappers/alerts_mapper.js
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-web/app/mappers/alerts_mapper.js?rev=1418981&r1=1418980&r2=1418981&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-web/app/mappers/alerts_mapper.js (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-web/app/mappers/alerts_mapper.js Sun Dec  9 14:42:31 2012
@@ -23,7 +23,7 @@ App.alertsMapper = App.QuickDataMapper.c
     $alert_id:'' ,
     title: "service_description",
     service_type: "service_type",
-    date: "last_check",
+    date: "last_hard_state_change",
     status: "current_state",
     message: "plugin_output",
     host_name: "host_name",

Modified: incubator/ambari/branches/AMBARI-666/ambari-web/app/models/alert.js
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-web/app/models/alert.js?rev=1418981&r1=1418980&r2=1418981&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-web/app/models/alert.js (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-web/app/models/alert.js Sun Dec  9 14:42:31 2012
@@ -53,19 +53,41 @@ App.Alert = DS.Model.extend({
   }.property('status'),
 
   /**
-   * Used to show appropriate date in UI
+   * Provides how long ago this alert happened.
+   * 
+   * @type {String}
    */
-  dateDisplay: function () {
+  timeSinceAlert: function () {
     var d = this.get('date');
     if (d) {
-      var dateString = d.toDateString() + ". " + d.toLocaleTimeString();
-      dateString = dateString.substr(dateString.indexOf(" ") + 1);
-      return dateString;
+      return $.timeago(d);
     }
     return "";
   }.property('date'),
 
   /**
+   * Provides more details about when this alert happened.
+   * 
+   * @type {String}
+   */
+  timeSinceAlertDetails: function () {
+    var details = "";
+    var date = this.get('date');
+    if (date) {
+      var dateString = date.toDateString();
+      dateString = dateString.substr(dateString.indexOf(" ") + 1);
+      dateString = "Occurred on " + dateString + ", " + date.toLocaleTimeString();
+      details += dateString;
+    }
+    var lastCheck = this.get('lastCheck');
+    if (lastCheck) {
+      lastCheck = new Date(lastCheck * 1000);
+      details = details + "<br>Last checked " + $.timeago(lastCheck);
+    }
+    return details;
+  }.property('lastCheck', 'date'),
+
+  /**
    * Used to show appropriate service label in UI
    */
   serviceName: function () {

Modified: incubator/ambari/branches/AMBARI-666/ambari-web/app/styles/application.less
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-web/app/styles/application.less?rev=1418981&r1=1418980&r2=1418981&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-web/app/styles/application.less (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-web/app/styles/application.less Sun Dec  9 14:42:31 2012
@@ -196,6 +196,10 @@ h1 {
   color: #FF4B4B;
 }
 
+.tooltip-inner {
+  text-align: left;
+}
+
 #installer, #add-host, #add-service {
   h2 {
     margin-top: 0;
@@ -632,7 +636,10 @@ a:focus {
       padding-top: 7px;
     }
     .date-time {
-      color: #777;
+      color: #999;
+      font-style: italic;
+      font-size: small;
+      text-align: right;
     }
     .message {
       font-size: 13px;

Modified: incubator/ambari/branches/AMBARI-666/ambari-web/app/templates/main/service/info/client_summary.hbs
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-web/app/templates/main/service/info/client_summary.hbs?rev=1418981&r1=1418980&r2=1418981&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-web/app/templates/main/service/info/client_summary.hbs (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-web/app/templates/main/service/info/client_summary.hbs Sun Dec  9 14:42:31 2012
@@ -86,7 +86,7 @@
                 <div class="row-fluid">
                   <div class="span7 title">{{title}}
                   </div>
-                  <div class="span5 date-time">{{dateDisplay}}</div>
+                  <div rel="tooltip" {{bindAttr data-title="timeSinceAlertDetails"}} data-placement="right" class="span5 date-time">{{timeSinceAlert}}</div>
                 </div>
                 <div class="row-fluid message">{{message}}</div>
               </div>

Modified: incubator/ambari/branches/AMBARI-666/ambari-web/app/templates/main/service/info/summary.hbs
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-web/app/templates/main/service/info/summary.hbs?rev=1418981&r1=1418980&r2=1418981&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-web/app/templates/main/service/info/summary.hbs (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-web/app/templates/main/service/info/summary.hbs Sun Dec  9 14:42:31 2012
@@ -149,7 +149,7 @@
 	                <div class="row-fluid">
 	                  <div class="span7 title">{{title}}
 	                  </div>
-	                  <div class="span5 date-time">{{dateDisplay}}</div>
+	                  <div rel="tooltip" {{bindAttr data-title="timeSinceAlertDetails"}} data-placement="right" class="span5 date-time">{{timeSinceAlert}}</div>
 	                </div>
 	                <div class="row-fluid message">{{message}}</div>
 	              </div>

Modified: incubator/ambari/branches/AMBARI-666/ambari-web/app/views/main/service/info/summary.js
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-web/app/views/main/service/info/summary.js?rev=1418981&r1=1418980&r2=1418981&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-web/app/views/main/service/info/summary.js (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-web/app/views/main/service/info/summary.js Sun Dec  9 14:42:31 2012
@@ -183,6 +183,8 @@ App.MainServiceInfoSummaryView = Em.View
         $(summaryTable).attr('style', "height:" + alertsList.clientHeight + "px;");
       }
     }
+    // Tooltips for alerts need to be enabled.
+    $("div[rel=tooltip]").tooltip();
   },
 
   clientHosts:App.Host.find(),

Modified: incubator/ambari/branches/AMBARI-666/ambari-web/config.coffee
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-web/config.coffee?rev=1418981&r1=1418980&r2=1418981&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-web/config.coffee (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-web/config.coffee Sun Dec  9 14:42:31 2012
@@ -52,6 +52,7 @@ exports.config =
           'vendor/scripts/jquery.ui.sortable.js',
           'vendor/scripts/jquery.ui.custom-effects.js',
           'vendor/scripts/jquery.dataTables.js',
+          'vendor/scripts/jquery.timeago.js',
           'vendor/scripts/workflow_visualization.js',
           'vendor/scripts/rickshaw.js'
           ]

Added: incubator/ambari/branches/AMBARI-666/ambari-web/vendor/scripts/jquery.timeago.js
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-web/vendor/scripts/jquery.timeago.js?rev=1418981&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-web/vendor/scripts/jquery.timeago.js (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-web/vendor/scripts/jquery.timeago.js Sun Dec  9 14:42:31 2012
@@ -0,0 +1,152 @@
+/**
+ * Timeago is a jQuery plugin that makes it easy to support automatically
+ * updating fuzzy timestamps (e.g. "4 minutes ago" or "about 1 day ago").
+ *
+ * @name timeago
+ * @version 0.11.4
+ * @requires jQuery v1.2.3+
+ * @author Ryan McGeary
+ * @license MIT License - http://www.opensource.org/licenses/mit-license.php
+ *
+ * For usage and examples, visit:
+ * http://timeago.yarp.com/
+ *
+ * Copyright (c) 2008-2012, Ryan McGeary (ryan -[at]- mcgeary [*dot*] org)
+ */
+(function($) {
+  $.timeago = function(timestamp) {
+    if (timestamp instanceof Date) {
+      return inWords(timestamp);
+    } else if (typeof timestamp === "string") {
+      return inWords($.timeago.parse(timestamp));
+    } else if (typeof timestamp === "number") {
+      return inWords(new Date(timestamp));
+    } else {
+      return inWords($.timeago.datetime(timestamp));
+    }
+  };
+  var $t = $.timeago;
+
+  $.extend($.timeago, {
+    settings: {
+      refreshMillis: 60000,
+      allowFuture: false,
+      strings: {
+        prefixAgo: null,
+        prefixFromNow: null,
+        suffixAgo: "ago",
+        suffixFromNow: "from now",
+        seconds: "less than a minute",
+        minute: "about a minute",
+        minutes: "%d minutes",
+        hour: "about an hour",
+        hours: "about %d hours",
+        day: "a day",
+        days: "%d days",
+        month: "about a month",
+        months: "%d months",
+        year: "about a year",
+        years: "%d years",
+        wordSeparator: " ",
+        numbers: []
+      }
+    },
+    inWords: function(distanceMillis) {
+      var $l = this.settings.strings;
+      var prefix = $l.prefixAgo;
+      var suffix = $l.suffixAgo;
+      if (this.settings.allowFuture) {
+        if (distanceMillis < 0) {
+          prefix = $l.prefixFromNow;
+          suffix = $l.suffixFromNow;
+        }
+      }
+
+      var seconds = Math.abs(distanceMillis) / 1000;
+      var minutes = seconds / 60;
+      var hours = minutes / 60;
+      var days = hours / 24;
+      var years = days / 365;
+
+      function substitute(stringOrFunction, number) {
+        var string = $.isFunction(stringOrFunction) ? stringOrFunction(number, distanceMillis) : stringOrFunction;
+        var value = ($l.numbers && $l.numbers[number]) || number;
+        return string.replace(/%d/i, value);
+      }
+
+      var words = seconds < 45 && substitute($l.seconds, Math.round(seconds)) ||
+        seconds < 90 && substitute($l.minute, 1) ||
+        minutes < 45 && substitute($l.minutes, Math.round(minutes)) ||
+        minutes < 90 && substitute($l.hour, 1) ||
+        hours < 24 && substitute($l.hours, Math.round(hours)) ||
+        hours < 42 && substitute($l.day, 1) ||
+        days < 30 && substitute($l.days, Math.round(days)) ||
+        days < 45 && substitute($l.month, 1) ||
+        days < 365 && substitute($l.months, Math.round(days / 30)) ||
+        years < 1.5 && substitute($l.year, 1) ||
+        substitute($l.years, Math.round(years));
+
+      var separator = $l.wordSeparator === undefined ?  " " : $l.wordSeparator;
+      return $.trim([prefix, words, suffix].join(separator));
+    },
+    parse: function(iso8601) {
+      var s = $.trim(iso8601);
+      s = s.replace(/\.\d+/,""); // remove milliseconds
+      s = s.replace(/-/,"/").replace(/-/,"/");
+      s = s.replace(/T/," ").replace(/Z/," UTC");
+      s = s.replace(/([\+\-]\d\d)\:?(\d\d)/," $1$2"); // -04:00 -> -0400
+      return new Date(s);
+    },
+    datetime: function(elem) {
+      var iso8601 = $t.isTime(elem) ? $(elem).attr("datetime") : $(elem).attr("title");
+      return $t.parse(iso8601);
+    },
+    isTime: function(elem) {
+      // jQuery's `is()` doesn't play well with HTML5 in IE
+      return $(elem).get(0).tagName.toLowerCase() === "time"; // $(elem).is("time");
+    }
+  });
+
+  $.fn.timeago = function() {
+    var self = this;
+    self.each(refresh);
+
+    var $s = $t.settings;
+    if ($s.refreshMillis > 0) {
+      setInterval(function() { self.each(refresh); }, $s.refreshMillis);
+    }
+    return self;
+  };
+
+  function refresh() {
+    var data = prepareData(this);
+    if (!isNaN(data.datetime)) {
+      $(this).text(inWords(data.datetime));
+    }
+    return this;
+  }
+
+  function prepareData(element) {
+    element = $(element);
+    if (!element.data("timeago")) {
+      element.data("timeago", { datetime: $t.datetime(element) });
+      var text = $.trim(element.text());
+      if (text.length > 0 && !($t.isTime(element) && element.attr("title"))) {
+        element.attr("title", text);
+      }
+    }
+    return element.data("timeago");
+  }
+
+  function inWords(date) {
+    return $t.inWords(distance(date));
+  }
+
+  function distance(date) {
+    return (new Date().getTime() - date.getTime());
+  }
+
+  // fix for IE6 suckage
+  document.createElement("abbr");
+  document.createElement("time");
+}(jQuery));