Skip to content

Commit

Permalink
Enhancement: Add Year to Job Run Timestamp in pipeline-stage-view-plu…
Browse files Browse the repository at this point in the history
…gin (#347)

* updating parent pom

* Added year to job run timestamp in pipeline-stage-view-plugin

* Update ui/src/main/js/view/templates/index.js

Co-authored-by: Jesse Glick <[email protected]>

* Remove pom.xml.versionsBackup and reverted plugin version to 2.361.4

* Reverted POM version back to version 2.361.4

* Improve date formatting in Stage View based on build age

---------

Co-authored-by: Jesse Glick <[email protected]>
  • Loading branch information
DeepData-Diver and jglick authored Nov 25, 2024
1 parent b5deb9c commit 5c5b880
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 16 deletions.
61 changes: 45 additions & 16 deletions ui/src/main/js/view/templates/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,11 @@ registerHBSHelper('formatDate', function (date, toFormat) {
return date;
}

var options = { month: 'short', day: '2-digit', hour: '2-digit', minute: '2-digit', hour12: false };
if (timeZone) {
options.timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
}
var theDate = new Date(date);
var now = new Date();
var diff = now - theDate; // Difference in milliseconds
var oneDay = 24 * 60 * 60 * 1000; // milliseconds in one day
var oneYear = 365 * oneDay; // milliseconds in one year

let userLocale
if (navigator.languages && navigator.languages.length) {
Expand All @@ -90,17 +91,45 @@ registerHBSHelper('formatDate', function (date, toFormat) {
userLocale = navigator.language
}

var theDate = new Date(date);
if (toFormat == 'month') {
return theDate.toLocaleDateString(userLocale, {month: 'short'});
}
if (toFormat == 'dom') {
return theDate.toLocaleDateString(userLocale, {day: '2-digit'});
}
if (toFormat == 'time') {
return theDate.toLocaleTimeString(userLocale, {hour: '2-digit',minute: '2-digit', hour12: false });
var options = {};

// Determine which components to display based on the age of the job
var showYear = diff >= oneYear;
var showDate = diff >= oneDay;
var showTime = true; // Always show time if requested

if (toFormat === 'month') {
if (showDate) {
options.month = 'short';
} else {
return ''; // Do not display month
}
} else if (toFormat === 'dom') {
if (showDate) {
options.day = '2-digit';
} else {
return ''; // Do not display day
}
} else if (toFormat === 'year') {
if (showYear) {
options.year = 'numeric';
} else {
return ''; // Do not display year
}
} else if (toFormat === 'time') {
if (showTime) {
options.hour = '2-digit';
options.minute = '2-digit';
options.hour12 = false;
} else {
return ''; // This case won't occur since we always show time
}
} else {
// Default case: return full date if needed
return theDate.toLocaleString(userLocale);
}
return theDate.toLocaleDateString(userLocale, options)

return theDate.toLocaleString(userLocale, options);
});

/**
Expand Down Expand Up @@ -148,7 +177,7 @@ function getTemplate(templateName) {
if (!templateInstance) {
throw 'No template by the name "' + templateName + '". Check ui/src/main/js/view/templates/index.js and make sure the template is registered in the templateCache.';
}

// handles precompiled and compiled templates
return templateInstance.default || templateInstance;
}
Expand Down Expand Up @@ -197,4 +226,4 @@ exports.apply = function (templateName, dataModel, divWrap) {
*/
exports.dateFormatting = function (on) {
dateFormattingOn = on;
}
}
1 change: 1 addition & 0 deletions ui/src/main/js/view/templates/pipeline-staged.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<div class="stage-start-box">
<div class="stage-start-time">
<div class="date">{{formatDate this.startTimeMillis 'month'}} {{formatDate this.startTimeMillis 'dom'}}</div>
<div class="year">{{formatDate this.startTimeMillis 'year'}}</div>
<div class="time">{{formatDate this.startTimeMillis 'time'}}</div>
</div>
{{#if this._links.changesets}}<div class="changeset-box" cbwf-controller="run-changesets" objectUrl="{{this._links.changesets.href}}"></div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ <h2>Stage View</h2>
<div class="stage-start-box">
<div class="stage-start-time">
<div class="date">1414318349569 1414318349569</div>
<div class="year">1414318349569</div>
<div class="time">1414318349569</div>
</div>
<div class="changeset-box no-changes">No Changes</div>
Expand Down Expand Up @@ -125,6 +126,7 @@ <h2>Stage View</h2>
<div class="stage-start-box">
<div class="stage-start-time">
<div class="date">1414318232950 1414318232950</div>
<div class="year">1414318232950</div>
<div class="time">1414318232950</div>
</div>
<div class="changeset-box no-changes">No Changes</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ <h2>Stage View</h2>
<div class="stage-start-box">
<div class="stage-start-time">
<div class="date">1414318232950 1414318232950</div>
<div class="year">1414318232950</div>
<div class="time">1414318232950</div>
</div>
<div class="changeset-box no-changes">No Changes</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ <h2>Stage View</h2>
<div class="stage-start-box">
<div class="stage-start-time">
<div class="date">1411556423000 1411556423000</div>
<div class="year">1411556423000</div>
<div class="time">1411556423000</div>
</div>
<div class="changeset-box no-changes">No Changes</div>
Expand Down Expand Up @@ -108,6 +109,7 @@ <h2>Stage View</h2>
<div class="stage-start-box">
<div class="stage-start-time">
<div class="date">1411556089000 1411556089000</div>
<div class="year">1411556089000</div>
<div class="time">1411556089000</div>
</div>
<div class="changeset-box no-changes">No Changes</div>
Expand Down Expand Up @@ -162,6 +164,7 @@ <h2>Stage View</h2>
<div class="stage-start-box">
<div class="stage-start-time">
<div class="date">1411552553000 1411552553000</div>
<div class="year">1411552553000</div>
<div class="time">1411552553000</div>
</div>
<div class="changeset-box no-changes">No Changes</div>
Expand Down

0 comments on commit 5c5b880

Please sign in to comment.