From 07f4abb002949298384ae4e69ff808a91b1eaabf Mon Sep 17 00:00:00 2001 From: Markus Winter Date: Fri, 16 Aug 2024 00:56:32 +0200 Subject: [PATCH] [JENKINS-73613] refresh buildhistory in all cases refresh the buildHistory widget instantly when the window gets focus, e.g. after switching browser tabs but also when one was in another application and clicks in the browser window. When the window is visible it will update even when it has no focus. Additionally the buildHistory will be updated now when it is not on the first page as long as there are still runs that are not finished. As soon as all runs are finished refresh will end. Minor drawback would be that if someone deletes a run, adjusts displayname or changes the description this would not be reflected. On the pro side it will stop polling the controller when all runs are finished. --- .../jenkins/widgets/HistoryPageFilter.java | 7 +++ .../hudson/widgets/HistoryWidget/index.jelly | 5 +- .../HistoryPageFilter/ajaxBuildHistory.jelly | 3 +- war/src/main/js/pages/project/builds-card.js | 51 +++++++++++++------ 4 files changed, 48 insertions(+), 18 deletions(-) diff --git a/core/src/main/java/jenkins/widgets/HistoryPageFilter.java b/core/src/main/java/jenkins/widgets/HistoryPageFilter.java index 6b6d9fa214cb5..9c06799d6db44 100644 --- a/core/src/main/java/jenkins/widgets/HistoryPageFilter.java +++ b/core/src/main/java/jenkins/widgets/HistoryPageFilter.java @@ -73,6 +73,7 @@ public class HistoryPageFilter { public long newestOnPage = Long.MIN_VALUE; // see updateNewestOldest() public long oldestOnPage = Long.MAX_VALUE; // see updateNewestOldest() + public boolean activeRuns = false; /** * Create a history page filter instance. @@ -259,6 +260,7 @@ private void addQueueItem(QueueItem item) { HistoryPageEntry entry = new HistoryPageEntry<>(item); queueItems.add(entry); updateNewestOldest(entry.getEntryId()); + updateActiveRuns(true); } private void addRun(Run run) { @@ -271,6 +273,7 @@ private void addRun(Run run) { } runs.add(entry); updateNewestOldest(entry.getEntryId()); + updateActiveRuns(run.isBuilding()); } private void updateNewestOldest(long entryId) { @@ -278,6 +281,10 @@ private void updateNewestOldest(long entryId) { oldestOnPage = Math.min(oldestOnPage, entryId); } + private void updateActiveRuns(boolean isActive) { + activeRuns = activeRuns || isActive; + } + private boolean add(Object entry) { // Purposely not calling isFull(). May need to add a greater number of entries // to the page initially, newerThan then cutting it back down to size using cutLeading() diff --git a/core/src/main/resources/hudson/widgets/HistoryWidget/index.jelly b/core/src/main/resources/hudson/widgets/HistoryWidget/index.jelly index 8d4663bb00dde..a7fb11d54b512 100644 --- a/core/src/main/resources/hudson/widgets/HistoryWidget/index.jelly +++ b/core/src/main/resources/hudson/widgets/HistoryWidget/index.jelly @@ -43,7 +43,8 @@ THE SOFTWARE. data-page-entry-newest="${page.newestOnPage}" data-page-entry-oldest="${page.oldestOnPage}" data-page-has-up="${page.hasUpPage}" - data-page-has-down="${page.hasDownPage}"> + data-page-has-down="${page.hasDownPage}" + data-active-runs="${page.activeRuns}"> @@ -56,7 +57,7 @@ THE SOFTWARE.
-
+