From d5bdc46bdb969ecd842165c54d507e0038b848ab Mon Sep 17 00:00:00 2001 From: Jessica Forrester Date: Thu, 19 Mar 2015 14:40:20 -0400 Subject: [PATCH] Add build duration to web console --- assets/app/scripts/app.js | 7 +++- assets/app/scripts/directives/date.js | 9 +++++ assets/app/scripts/filters/date.js | 48 +++++++++++++++++++++++++ assets/app/views/builds.html | 28 +++++++++++++++ pkg/assets/bindata.go | 51 +++++++++++++++++++++++++-- 5 files changed, 140 insertions(+), 3 deletions(-) diff --git a/assets/app/scripts/app.js b/assets/app/scripts/app.js index 6652bbde374c..20a54ddb889c 100644 --- a/assets/app/scripts/app.js +++ b/assets/app/scripts/app.js @@ -169,12 +169,17 @@ angular HawtioNav.add(tabs[i]); } }]) - .run(function($interval, dateRelativeFilter) { + .run(function($interval, dateRelativeFilter, durationFilter) { $interval(function() { $('.timestamp[data-timestamp]').text(function(i, existing) { return dateRelativeFilter($(this).attr("data-timestamp")) || existing; }); }, 30000); + $interval(function() { + $('.duration[data-timestamp]').text(function(i, existing) { + return durationFilter($(this).attr("data-timestamp")) || existing; + }); + }, 1000); }); hawtioPluginLoader.addModule('openshiftConsole'); diff --git a/assets/app/scripts/directives/date.js b/assets/app/scripts/directives/date.js index dafca74dadf4..b37270accea4 100644 --- a/assets/app/scripts/directives/date.js +++ b/assets/app/scripts/directives/date.js @@ -7,4 +7,13 @@ angular.module('openshiftConsole') }, template: '{{timestamp | dateRelative}}' }; + }) + .directive("durationUntilNow", function() { + return { + restrict: 'E', + scope: { + timestamp: '=' + }, + template: '{{timestamp | duration}}' + }; }); \ No newline at end of file diff --git a/assets/app/scripts/filters/date.js b/assets/app/scripts/filters/date.js index ffd7fc151709..adb037f8ef34 100644 --- a/assets/app/scripts/filters/date.js +++ b/assets/app/scripts/filters/date.js @@ -7,6 +7,54 @@ angular.module('openshiftConsole') return moment(timestamp).fromNow(); }; }) + .filter('duration', function() { + return function(timestampLhs, timestampRhs) { + if (!timestampLhs) { + return timestampLhs; + } + timestampRhs = timestampRhs || Date(); + + var ms = moment(timestampRhs).diff(timestampLhs); + var duration = moment.duration(ms); + // the out of the box humanize in moment.js rounds to the nearest time unit + // but we need more details + var humanizedDuration = []; + var years = duration.years(); + var months = duration.months(); + var days = duration.days(); + var hours = duration.hours(); + var minutes = duration.minutes(); + var seconds = duration.seconds(); + if (years > 0) { + humanizedDuration.push(years + (years == 1 ? " year" : " years")); + } + if (months > 0) { + humanizedDuration.push(months + (months == 1 ? " month" : " months")); + } + if (days > 0) { + humanizedDuration.push(days + (days == 1 ? " day" : " days")); + } + if (hours > 0) { + humanizedDuration.push(hours + (hours == 1 ? " hour" : " hours")); + } + if (minutes > 0) { + humanizedDuration.push(minutes + (minutes == 1 ? " minute" : " minutes")); + } + if (seconds > 0) { + humanizedDuration.push(seconds + (seconds == 1 ? " second" : " seconds")); + } + + if (humanizedDuration.length == 0) { + humanizedDuration.push("0 seconds"); + } + + if (humanizedDuration.length > 2) { + humanizedDuration.length = 2; + } + + return humanizedDuration.join(", "); + }; + }) .filter('ageLessThan', function() { // ex: amt = 5 and unit = 'minutes' return function(timestamp, amt, unit) { diff --git a/assets/app/views/builds.html b/assets/app/views/builds.html index 7246c2a411fb..e7371ef0bb28 100644 --- a/assets/app/views/builds.html +++ b/assets/app/views/builds.html @@ -80,6 +80,20 @@

{{build.metadata.name}}

+
+ Duration: + + {{(build.startTimestamp || build.metadata.creationTimestamp) | duration : build.completionTimestamp}} + {{build.startTimestamp | duration : build.completionTimestamp}} + running for + waiting for + waiting for + + {{build.startTimestamp | duration : build.completionTimestamp}} + waited for {{build.metadata.creationTimestamp | duration : build.completionTimestamp}} + + +
Build strategy: {{build.parameters.strategy.type}}
@@ -138,6 +152,20 @@

{{build.metadata.name}}

+
+ Duration: + + {{(build.startTimestamp || build.metadata.creationTimestamp) | duration : build.completionTimestamp}} + {{build.startTimestamp | duration : build.completionTimestamp}} + running for + waiting for + waiting for + + {{build.startTimestamp | duration : build.completionTimestamp}} + waited for {{build.metadata.creationTimestamp | duration : build.completionTimestamp}} + + +
Build strategy: {{build.parameters.strategy.type}}
diff --git a/pkg/assets/bindata.go b/pkg/assets/bindata.go index b2fa963c6d93..825b667c6276 100644 --- a/pkg/assets/bindata.go +++ b/pkg/assets/bindata.go @@ -13222,12 +13222,16 @@ a.interceptors.push("AuthInterceptor"), b.LoginService("RedirectLoginService"), a.aHrefSanitizationWhitelist(/^\s*(https?|mailto|git):/i); } ]).run([ "mainNavTabs", "HawtioNav", function(a, b) { for (var c = 0; c < a.length; c++) b.add(a[c]); -} ]).run([ "$interval", "dateRelativeFilter", function(a, b) { +} ]).run([ "$interval", "dateRelativeFilter", "durationFilter", function(a, b, c) { a(function() { $(".timestamp[data-timestamp]").text(function(a, c) { return b($(this).attr("data-timestamp")) || c; }); -}, 3e4); +}, 3e4), a(function() { +$(".duration[data-timestamp]").text(function(a, b) { +return c($(this).attr("data-timestamp")) || b; +}); +}, 1e3); } ]), hawtioPluginLoader.addModule("openshiftConsole"), LabelSelector.prototype.addConjunct = function(a, b, c) { var d = { key:a, @@ -14626,6 +14630,14 @@ timestamp:"=" }, template:'{{timestamp | dateRelative}}' }; +}).directive("durationUntilNow", function() { +return { +restrict:"E", +scope:{ +timestamp:"=" +}, +template:'{{timestamp | duration}}' +}; }), angular.module("openshiftConsole").directive("podTemplate", function() { return { restrict:"E", @@ -14854,6 +14866,13 @@ a.url(c.toString()); return function(a) { return a ? moment(a).fromNow() :a; }; +}).filter("duration", function() { +return function(a, b) { +if (!a) return a; +b = b || Date(); +var c = moment(b).diff(a), d = moment.duration(c), e = [], f = d.years(), g = d.months(), h = d.days(), i = d.hours(), j = d.minutes(), k = d.seconds(); +return f > 0 && e.push(f + (1 == f ? " year" :" years")), g > 0 && e.push(g + (1 == g ? " month" :" months")), h > 0 && e.push(h + (1 == h ? " day" :" days")), i > 0 && e.push(i + (1 == i ? " hour" :" hours")), j > 0 && e.push(j + (1 == j ? " minute" :" minutes")), k > 0 && e.push(k + (1 == k ? " second" :" seconds")), 0 == e.length && e.push("0 seconds"), e.length > 2 && (e.length = 2), e.join(", "); +}; }).filter("ageLessThan", function() { return function(a, b, c) { return moment().subtract(b, c).diff(moment(a)) < 0; @@ -59690,6 +59709,20 @@ Image change on image repository {{trigger.imageChange.from.name}}:{{trigger.ima
+
+Duration: + +{{(build.startTimestamp || build.metadata.creationTimestamp) | duration : build.completionTimestamp}} +{{build.startTimestamp | duration : build.completionTimestamp}} +running for +waiting for +waiting for + +{{build.startTimestamp | duration : build.completionTimestamp}} +waited for {{build.metadata.creationTimestamp | duration : build.completionTimestamp}} + + +
Build strategy: {{build.parameters.strategy.type}}
@@ -59748,6 +59781,20 @@ Output image: {{build.parameters.output.dockerImageReference}}
+
+Duration: + +{{(build.startTimestamp || build.metadata.creationTimestamp) | duration : build.completionTimestamp}} +{{build.startTimestamp | duration : build.completionTimestamp}} +running for +waiting for +waiting for + +{{build.startTimestamp | duration : build.completionTimestamp}} +waited for {{build.metadata.creationTimestamp | duration : build.completionTimestamp}} + + +
Build strategy: {{build.parameters.strategy.type}}