Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion assets/app/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
9 changes: 9 additions & 0 deletions assets/app/scripts/directives/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,13 @@ angular.module('openshiftConsole')
},
template: '<span data-timestamp="{{timestamp}}" class="timestamp" title="{{timestamp | date : \'short\'}}">{{timestamp | dateRelative}}</span>'
};
})
.directive("durationUntilNow", function() {
return {
restrict: 'E',
scope: {
timestamp: '='
},
template: '<span data-timestamp="{{timestamp}}" class="duration">{{timestamp | duration}}</span>'
};
});
48 changes: 48 additions & 0 deletions assets/app/scripts/filters/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
28 changes: 28 additions & 0 deletions assets/app/views/builds.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,20 @@ <h3>{{build.metadata.name}}</h3>
<span ng-switch-default class="fa fa-refresh fa-spin" aria-hidden="true"></span>
</span>
</div>
<div>
<span style="margin-right: 5px;">Duration: </span>
<span ng-switch="build.status" class="hide-ng-leave">
<span ng-switch-when="Complete">{{(build.startTimestamp || build.metadata.creationTimestamp) | duration : build.completionTimestamp}}</span>
<span ng-switch-when="Failed">{{build.startTimestamp | duration : build.completionTimestamp}}</span>
<span ng-switch-when="Running">running for <duration-until-now timestamp="build.startTimestamp"></duration-until-now></span>
<span ng-switch-when="New">waiting for <duration-until-now timestamp="build.metadata.creationTimestamp"></duration-until-now></span>
<span ng-switch-when="Pending">waiting for <duration-until-now timestamp="build.metadata.creationTimestamp"></duration-until-now></span>
<span ng-switch-default>
<span ng-if="build.startTimestamp">{{build.startTimestamp | duration : build.completionTimestamp}}</span>
<span ng-if="!build.startTimestamp">waited for {{build.metadata.creationTimestamp | duration : build.completionTimestamp}}</span>
</span>
</span>
</div>
<div ng-if="buildConfig.parameters.strategy.type != build.parameters.strategy.type">
<div>Build strategy: {{build.parameters.strategy.type}}</div>
</div>
Expand Down Expand Up @@ -138,6 +152,20 @@ <h3>{{build.metadata.name}}</h3>
<span ng-switch-default class="fa fa-refresh fa-spin" aria-hidden="true"></span>
</span>
</div>
<div>
<span style="margin-right: 5px;">Duration: </span>
<span ng-switch="build.status" class="hide-ng-leave">
<span ng-switch-when="Complete">{{(build.startTimestamp || build.metadata.creationTimestamp) | duration : build.completionTimestamp}}</span>
<span ng-switch-when="Failed">{{build.startTimestamp | duration : build.completionTimestamp}}</span>
<span ng-switch-when="Running">running for <duration-until-now timestamp="build.startTimestamp"></duration-until-now></span>
<span ng-switch-when="New">waiting for <duration-until-now timestamp="build.metadata.creationTimestamp"></duration-until-now></span>
<span ng-switch-when="Pending">waiting for <duration-until-now timestamp="build.metadata.creationTimestamp"></duration-until-now></span>
<span ng-switch-default>
<span ng-if="build.startTimestamp">{{build.startTimestamp | duration : build.completionTimestamp}}</span>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what will this do if there's no completionTimestamp?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when duration gets an undefined / null value for the second value it falls back to assume it should be compared against the current time, the only reason for startTimestamp to exist but not completionTimestamp would be if the build is still in progress, theoretically that means the state should be in Running but threw this is in as a default in case someone changes the states without us realizing it.

<span ng-if="!build.startTimestamp">waited for {{build.metadata.creationTimestamp | duration : build.completionTimestamp}}</span>
</span>
</span>
</div>
<div>Build strategy: {{build.parameters.strategy.type}}</div>
<div ng-switch="build.parameters.strategy.type">
<div ng-switch-when="STI">
Expand Down
51 changes: 49 additions & 2 deletions pkg/assets/bindata.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -14626,6 +14630,14 @@ timestamp:"="
},
template:'<span data-timestamp="{{timestamp}}" class="timestamp" title="{{timestamp | date : \'short\'}}">{{timestamp | dateRelative}}</span>'
};
}).directive("durationUntilNow", function() {
return {
restrict:"E",
scope:{
timestamp:"="
},
template:'<span data-timestamp="{{timestamp}}" class="duration">{{timestamp | duration}}</span>'
};
}), angular.module("openshiftConsole").directive("podTemplate", function() {
return {
restrict:"E",
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -59690,6 +59709,20 @@ Image change on image repository {{trigger.imageChange.from.name}}:{{trigger.ima
<span ng-switch-default class="fa fa-refresh fa-spin" aria-hidden="true"></span>
</span>
</div>
<div>
<span style="margin-right: 5px">Duration: </span>
<span ng-switch="build.status" class="hide-ng-leave">
<span ng-switch-when="Complete">{{(build.startTimestamp || build.metadata.creationTimestamp) | duration : build.completionTimestamp}}</span>
<span ng-switch-when="Failed">{{build.startTimestamp | duration : build.completionTimestamp}}</span>
<span ng-switch-when="Running">running for <duration-until-now timestamp="build.startTimestamp"></duration-until-now></span>
<span ng-switch-when="New">waiting for <duration-until-now timestamp="build.metadata.creationTimestamp"></duration-until-now></span>
<span ng-switch-when="Pending">waiting for <duration-until-now timestamp="build.metadata.creationTimestamp"></duration-until-now></span>
<span ng-switch-default>
<span ng-if="build.startTimestamp">{{build.startTimestamp | duration : build.completionTimestamp}}</span>
<span ng-if="!build.startTimestamp">waited for {{build.metadata.creationTimestamp | duration : build.completionTimestamp}}</span>
</span>
</span>
</div>
<div ng-if="buildConfig.parameters.strategy.type != build.parameters.strategy.type">
<div>Build strategy: {{build.parameters.strategy.type}}</div>
</div>
Expand Down Expand Up @@ -59748,6 +59781,20 @@ Output image: {{build.parameters.output.dockerImageReference}}
<span ng-switch-default class="fa fa-refresh fa-spin" aria-hidden="true"></span>
</span>
</div>
<div>
<span style="margin-right: 5px">Duration: </span>
<span ng-switch="build.status" class="hide-ng-leave">
<span ng-switch-when="Complete">{{(build.startTimestamp || build.metadata.creationTimestamp) | duration : build.completionTimestamp}}</span>
<span ng-switch-when="Failed">{{build.startTimestamp | duration : build.completionTimestamp}}</span>
<span ng-switch-when="Running">running for <duration-until-now timestamp="build.startTimestamp"></duration-until-now></span>
<span ng-switch-when="New">waiting for <duration-until-now timestamp="build.metadata.creationTimestamp"></duration-until-now></span>
<span ng-switch-when="Pending">waiting for <duration-until-now timestamp="build.metadata.creationTimestamp"></duration-until-now></span>
<span ng-switch-default>
<span ng-if="build.startTimestamp">{{build.startTimestamp | duration : build.completionTimestamp}}</span>
<span ng-if="!build.startTimestamp">waited for {{build.metadata.creationTimestamp | duration : build.completionTimestamp}}</span>
</span>
</span>
</div>
<div>Build strategy: {{build.parameters.strategy.type}}</div>
<div ng-switch="build.parameters.strategy.type">
<div ng-switch-when="STI">
Expand Down