From 5c5b88011ae9cc166edaf978f1a3f49586add9d5 Mon Sep 17 00:00:00 2001 From: DeepData-Diver <132279273+DeepData-Diver@users.noreply.github.com> Date: Mon, 25 Nov 2024 15:54:35 -0800 Subject: [PATCH] Enhancement: Add Year to Job Run Timestamp in pipeline-stage-view-plugin (#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 * 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 --- ui/src/main/js/view/templates/index.js | 61 ++++++++++++++----- .../js/view/templates/pipeline-staged.hbs | 1 + .../render/04_rest_api_runs_failed.html | 2 + .../render/07_rest_api_runs_in_progress.html | 1 + .../view/pipeline_staged/render/expected.html | 3 + 5 files changed, 52 insertions(+), 16 deletions(-) diff --git a/ui/src/main/js/view/templates/index.js b/ui/src/main/js/view/templates/index.js index 6cf8b453..8e50314e 100644 --- a/ui/src/main/js/view/templates/index.js +++ b/ui/src/main/js/view/templates/index.js @@ -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) { @@ -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); }); /** @@ -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; } @@ -197,4 +226,4 @@ exports.apply = function (templateName, dataModel, divWrap) { */ exports.dateFormatting = function (on) { dateFormattingOn = on; -} +} \ No newline at end of file diff --git a/ui/src/main/js/view/templates/pipeline-staged.hbs b/ui/src/main/js/view/templates/pipeline-staged.hbs index 1a191446..a2c59d58 100644 --- a/ui/src/main/js/view/templates/pipeline-staged.hbs +++ b/ui/src/main/js/view/templates/pipeline-staged.hbs @@ -47,6 +47,7 @@
{{formatDate this.startTimeMillis 'month'}} {{formatDate this.startTimeMillis 'dom'}}
+
{{formatDate this.startTimeMillis 'year'}}
{{formatDate this.startTimeMillis 'time'}}
{{#if this._links.changesets}}
diff --git a/ui/src/test/resources/view/pipeline_staged/render/04_rest_api_runs_failed.html b/ui/src/test/resources/view/pipeline_staged/render/04_rest_api_runs_failed.html index cad5b9a6..facafeac 100644 --- a/ui/src/test/resources/view/pipeline_staged/render/04_rest_api_runs_failed.html +++ b/ui/src/test/resources/view/pipeline_staged/render/04_rest_api_runs_failed.html @@ -59,6 +59,7 @@

Stage View

1414318349569 1414318349569
+
1414318349569
1414318349569
No Changes
@@ -125,6 +126,7 @@

Stage View

1414318232950 1414318232950
+
1414318232950
1414318232950
No Changes
diff --git a/ui/src/test/resources/view/pipeline_staged/render/07_rest_api_runs_in_progress.html b/ui/src/test/resources/view/pipeline_staged/render/07_rest_api_runs_in_progress.html index 363ba148..ef624a81 100644 --- a/ui/src/test/resources/view/pipeline_staged/render/07_rest_api_runs_in_progress.html +++ b/ui/src/test/resources/view/pipeline_staged/render/07_rest_api_runs_in_progress.html @@ -43,6 +43,7 @@

Stage View

1414318232950 1414318232950
+
1414318232950
1414318232950
No Changes
diff --git a/ui/src/test/resources/view/pipeline_staged/render/expected.html b/ui/src/test/resources/view/pipeline_staged/render/expected.html index 59b132b0..bf082029 100644 --- a/ui/src/test/resources/view/pipeline_staged/render/expected.html +++ b/ui/src/test/resources/view/pipeline_staged/render/expected.html @@ -51,6 +51,7 @@

Stage View

1411556423000 1411556423000
+
1411556423000
1411556423000
No Changes
@@ -108,6 +109,7 @@

Stage View

1411556089000 1411556089000
+
1411556089000
1411556089000
No Changes
@@ -162,6 +164,7 @@

Stage View

1411552553000 1411552553000
+
1411552553000
1411552553000
No Changes