From f905a3f7cc7619a5f2a7cc5ee9466d7e87f22022 Mon Sep 17 00:00:00 2001 From: imonteroperez Date: Mon, 4 Oct 2021 13:40:05 +0200 Subject: [PATCH] Jenkins header revamp proposal --- core/src/main/java/hudson/Functions.java | 17 +++ core/src/main/java/jenkins/views/Header.java | 13 +++ .../java/jenkins/views/JenkinsHeader.java | 13 +++ .../views/JenkinsHeader/headerContent.jelly | 80 +++++++++++++ .../JenkinsHeader/headerDocumentation.jelly | 28 +++++ .../views/JenkinsHeader/postHeader.jelly | 3 + .../views/JenkinsHeader/preHeader.jelly | 3 + .../resources/lib/layout/pageHeader.jelly | 108 +----------------- 8 files changed, 162 insertions(+), 103 deletions(-) create mode 100644 core/src/main/java/jenkins/views/Header.java create mode 100644 core/src/main/java/jenkins/views/JenkinsHeader.java create mode 100644 core/src/main/resources/jenkins/views/JenkinsHeader/headerContent.jelly create mode 100644 core/src/main/resources/jenkins/views/JenkinsHeader/headerDocumentation.jelly create mode 100644 core/src/main/resources/jenkins/views/JenkinsHeader/postHeader.jelly create mode 100644 core/src/main/resources/jenkins/views/JenkinsHeader/preHeader.jelly diff --git a/core/src/main/java/hudson/Functions.java b/core/src/main/java/hudson/Functions.java index c727d22435f1..21a2a382b4f5 100644 --- a/core/src/main/java/hudson/Functions.java +++ b/core/src/main/java/hudson/Functions.java @@ -153,6 +153,9 @@ import jenkins.model.ModelObjectWithContextMenu; import jenkins.model.SimplePageDecorator; import jenkins.util.SystemProperties; +import jenkins.views.Header; +import jenkins.views.JenkinsHeader; + import org.apache.commons.jelly.JellyContext; import org.apache.commons.jelly.JellyTagException; import org.apache.commons.jelly.Script; @@ -2282,4 +2285,18 @@ public static boolean isContextMenuVisible(Action a) { return true; } } + + @Restricted(NoExternalUse.class) + @CheckForNull + public static Header header() { + List
headers = ExtensionList.lookup(Header.class).stream().filter(header -> header.isHeaderEnabled()).collect(Collectors.toList()); + if (headers.size() > 0) { + if (headers.size() > 1) { + LOGGER.warning("More than one configured header. This should not happen. Serving the Jenkins default header and please review"); + } else { + return headers.get(0); + } + } + return new JenkinsHeader(); + } } diff --git a/core/src/main/java/jenkins/views/Header.java b/core/src/main/java/jenkins/views/Header.java new file mode 100644 index 000000000000..1da916a2811b --- /dev/null +++ b/core/src/main/java/jenkins/views/Header.java @@ -0,0 +1,13 @@ +package jenkins.views; + +import hudson.ExtensionPoint; + +public interface Header extends ExtensionPoint { + + /** + * Checks if header is enabled. By default it is if installed, but the logic is deferred in the plugins. + * @return + */ + boolean isHeaderEnabled(); + +} diff --git a/core/src/main/java/jenkins/views/JenkinsHeader.java b/core/src/main/java/jenkins/views/JenkinsHeader.java new file mode 100644 index 000000000000..6e4886df691b --- /dev/null +++ b/core/src/main/java/jenkins/views/JenkinsHeader.java @@ -0,0 +1,13 @@ +package jenkins.views; + +import hudson.Extension; + +@Extension(ordinal = Integer.MIN_VALUE) +public class JenkinsHeader implements Header { + + @Override + public boolean isHeaderEnabled() { + return true; + } + +} diff --git a/core/src/main/resources/jenkins/views/JenkinsHeader/headerContent.jelly b/core/src/main/resources/jenkins/views/JenkinsHeader/headerContent.jelly new file mode 100644 index 000000000000..4f344a9977b6 --- /dev/null +++ b/core/src/main/resources/jenkins/views/JenkinsHeader/headerContent.jelly @@ -0,0 +1,80 @@ + + + + diff --git a/core/src/main/resources/jenkins/views/JenkinsHeader/headerDocumentation.jelly b/core/src/main/resources/jenkins/views/JenkinsHeader/headerDocumentation.jelly new file mode 100644 index 000000000000..9d48a25667bc --- /dev/null +++ b/core/src/main/resources/jenkins/views/JenkinsHeader/headerDocumentation.jelly @@ -0,0 +1,28 @@ + + + + Generates the page header, along with its associated dynamic behaviours. + This tag is used by l:layout and not expected to be used by anyone else, + but it's written as separate tag for better readability of code. + + + Page title and title attribute for the logo + + + + Alt text for the logo + + + + Placeholder text for the search input + + + + Link value for the help icon on the search box + + + + Text for the logout link + + + \ No newline at end of file diff --git a/core/src/main/resources/jenkins/views/JenkinsHeader/postHeader.jelly b/core/src/main/resources/jenkins/views/JenkinsHeader/postHeader.jelly new file mode 100644 index 000000000000..88fbccd10421 --- /dev/null +++ b/core/src/main/resources/jenkins/views/JenkinsHeader/postHeader.jelly @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/core/src/main/resources/jenkins/views/JenkinsHeader/preHeader.jelly b/core/src/main/resources/jenkins/views/JenkinsHeader/preHeader.jelly new file mode 100644 index 000000000000..88fbccd10421 --- /dev/null +++ b/core/src/main/resources/jenkins/views/JenkinsHeader/preHeader.jelly @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/core/src/main/resources/lib/layout/pageHeader.jelly b/core/src/main/resources/lib/layout/pageHeader.jelly index 987142bb623a..b793259536e7 100644 --- a/core/src/main/resources/lib/layout/pageHeader.jelly +++ b/core/src/main/resources/lib/layout/pageHeader.jelly @@ -1,106 +1,8 @@ - - Generates the page header, along with its associated dynamic behaviours. - This tag is used by l:layout and not expected to be used by anyone else, - but it's written as separate tag for better readability of code. - - - Page title and title attribute for the logo - - - - Alt text for the logo - - - - Placeholder text for the search input - - - - Link value for the help icon on the search box - - - - Text for the logout link - - - - + + + + +