summaryrefslogtreecommitdiff
path: root/web-ui/app/js
diff options
context:
space:
mode:
authorZara Gebru <zgebru@thoughtworks.com>2016-04-15 11:27:01 +0200
committerZara Gebru <zgebru@thoughtworks.com>2016-04-15 11:31:25 +0200
commitf7b9384d261beaa70994340eb83d6b77ac6535af (patch)
treebdd6e97321d92987fdc1ae9f72eab3a89fe9635c /web-ui/app/js
parentcd571f8542566a83e7f95e23859433e09b7df814 (diff)
Issue #678: added utility converting time passed and dynamically changing version timestamp
Diffstat (limited to 'web-ui/app/js')
-rw-r--r--web-ui/app/js/helpers/view_helper.js44
-rw-r--r--web-ui/app/js/page/version.js14
2 files changed, 56 insertions, 2 deletions
diff --git a/web-ui/app/js/helpers/view_helper.js b/web-ui/app/js/helpers/view_helper.js
index 7e07df75..f8152ff7 100644
--- a/web-ui/app/js/helpers/view_helper.js
+++ b/web-ui/app/js/helpers/view_helper.js
@@ -103,10 +103,53 @@ define(
return fingerprint.replace(/(.{4})/g, '$1 ').trim();
}
+ function getSinceDate(sinceDate){
+ var commitDate = new Date(sinceDate);
+ var number = Date.now();
+ var millisecondsSince = number - commitDate;
+
+ var SECONDS = 1000,
+ MIN = 60 * SECONDS,
+ HOUR = MIN * 60,
+ DAY = HOUR * 24,
+ WEEK = DAY * 7,
+ MONTH = WEEK * 4,
+ YEAR = DAY * 365;
+
+ var years = Math.floor(millisecondsSince / YEAR);
+ if (years >= 1){
+ return years + ' year(s)';
+ }
+
+ var months = Math.floor(millisecondsSince / MONTH);
+ if (months >= 1) {
+ return months + ' month(s)';
+ }
+
+ var weeks = Math.floor(millisecondsSince / WEEK);
+ if (weeks >= 1) {
+ return weeks + ' week(s)';
+ }
+
+ var days = Math.floor(millisecondsSince / DAY);
+ if (days >= 1) {
+ return days + ' day(s)';
+ }
+
+ var hours = Math.floor(millisecondsSince / HOUR);
+ if (hours >= 1) {
+ return hours + ' hour(s)';
+ }
+
+ var minutes = Math.floor(millisecondsSince / MIN);
+ return minutes + ' minute(s)';
+ }
+
Handlebars.registerHelper('formatDate', formatDate);
Handlebars.registerHelper('formatSize', formatSize);
Handlebars.registerHelper('formatStatusClasses', formatStatusClasses);
Handlebars.registerHelper('formatFingerPrint', formatFingerPrint);
+ Handlebars.registerHelper('sinceDate', getSinceDate);
return {
formatStatusClasses: formatStatusClasses,
@@ -115,6 +158,7 @@ define(
formatFingerPrint: formatFingerPrint,
moveCaretToEndOfText: moveCaretToEndOfText,
quoteMail: quoteMail,
+ sinceDate: getSinceDate,
i18n: i18n
};
});
diff --git a/web-ui/app/js/page/version.js b/web-ui/app/js/page/version.js
index e5299f52..9fd5e629 100644
--- a/web-ui/app/js/page/version.js
+++ b/web-ui/app/js/page/version.js
@@ -14,13 +14,23 @@
* You should have received a copy of the GNU Affero General Public License
* along with Pixelated. If not, see <http://www.gnu.org/licenses/>.
*/
-define(['flight/lib/component', 'views/templates'], function (defineComponent, templates) {
+define(['flight/lib/component', 'views/templates', 'helpers/view_helper'], function (defineComponent, templates, viewHelper) {
'use strict';
return defineComponent(function () {
-
+ this.defaultAttrs({
+ 'sinceDate': '#version-date'
+ });
+
this.render = function () {
this.$node.html(templates.page.version());
+ this.renderCommitDate();
+ };
+
+ this.renderCommitDate = function(){
+ var since = this.select('sinceDate').attr('data-since'),
+ commitDate = viewHelper.sinceDate(since);
+ this.select('sinceDate').html(commitDate + ' ago');
};
this.after('initialize', function () {