From 5522f6008caf2160a092285a7d416d94611f05aa Mon Sep 17 00:00:00 2001 From: Martin Pokorny <89339813+mPokornyETM@users.noreply.github.com> Date: Mon, 2 Jan 2023 14:10:17 -0400 Subject: [PATCH] Allow formatted markup for node descriptions (#6511) Co-authored-by: Adrien Lecharpentier Co-authored-by: Daniel Beck <1831569+daniel-beck@users.noreply.github.com> Co-authored-by: Alexander Brandes Co-authored-by: Daniel Beck Co-authored-by: Basil Crow Co-authored-by: Tim Jacomb Co-authored-by: Tim Jacomb <21194782+timja@users.noreply.github.com> --- .../java/hudson/slaves/SlaveComputer.java | 17 +++++++++++++++ .../AbstractModelObject/descriptionForm.jelly | 12 +++++++++-- .../hudson/model/Computer/index-top.jelly | 11 ++++++++++ .../hudson/model/Computer/index.jelly | 11 +--------- .../slaves/DumbSlave/configure-entries.jelly | 8 ++++--- .../slaves/SlaveComputer/systemInfo.jelly | 7 ++----- .../Jenkins/MasterComputer/index-top.jelly | 13 ++++++++++++ .../MasterComputer/index-top.properties | 4 ++++ .../lib/hudson/editable-description.js | 16 ++++++++++++++ .../lib/hudson/editableDescription.jelly | 21 ++++++++++++++----- .../main/webapp/scripts/hudson-behavior.js | 10 ++++++++- 11 files changed, 104 insertions(+), 26 deletions(-) create mode 100644 core/src/main/resources/hudson/model/Computer/index-top.jelly create mode 100644 core/src/main/resources/jenkins/model/Jenkins/MasterComputer/index-top.jelly create mode 100644 core/src/main/resources/jenkins/model/Jenkins/MasterComputer/index-top.properties create mode 100644 core/src/main/resources/lib/hudson/editable-description.js diff --git a/core/src/main/java/hudson/slaves/SlaveComputer.java b/core/src/main/java/hudson/slaves/SlaveComputer.java index daaba7a211d7..ccc90ec0873b 100644 --- a/core/src/main/java/hudson/slaves/SlaveComputer.java +++ b/core/src/main/java/hudson/slaves/SlaveComputer.java @@ -780,6 +780,23 @@ public List getLogRecords() throws IOException, InterruptedException return channel.call(new SlaveLogFetcher()); } + /** + * Inline editing of description + */ + @RequirePOST + @Restricted(NoExternalUse.class) + public synchronized void doSubmitDescription(StaplerResponse rsp, @QueryParameter String description) throws IOException { + checkPermission(CONFIGURE); + + final Slave node = this.getNode(); + if (node != null) { + node.setNodeDescription(description); + } else { // Node has been disabled/removed during other session tries to change the description. + throw new IOException("Description will be not set. The node " + nodeName + " does not exist (anymore)."); + } + rsp.sendRedirect("."); + } + @RequirePOST public HttpResponse doDoDisconnect(@QueryParameter String offlineMessage) { if (channel != null) { diff --git a/core/src/main/resources/hudson/model/AbstractModelObject/descriptionForm.jelly b/core/src/main/resources/hudson/model/AbstractModelObject/descriptionForm.jelly index 2d793ab4b91d..633e67f3568f 100644 --- a/core/src/main/resources/hudson/model/AbstractModelObject/descriptionForm.jelly +++ b/core/src/main/resources/hudson/model/AbstractModelObject/descriptionForm.jelly @@ -30,11 +30,19 @@ THE SOFTWARE. + + + + + + + + -
+ -
diff --git a/core/src/main/resources/hudson/model/Computer/index-top.jelly b/core/src/main/resources/hudson/model/Computer/index-top.jelly new file mode 100644 index 000000000000..2d2e116c059a --- /dev/null +++ b/core/src/main/resources/hudson/model/Computer/index-top.jelly @@ -0,0 +1,11 @@ + + + +

+ + ${it.caption} +

+ + + +
diff --git a/core/src/main/resources/hudson/model/Computer/index.jelly b/core/src/main/resources/hudson/model/Computer/index.jelly index 2961982f37ed..ed11d71d44c4 100644 --- a/core/src/main/resources/hudson/model/Computer/index.jelly +++ b/core/src/main/resources/hudson/model/Computer/index.jelly @@ -28,6 +28,7 @@ THE SOFTWARE. +
@@ -53,16 +54,6 @@ THE SOFTWARE.
-

- - - - ${it.caption} - - (${it.node.nodeDescription}) - -

- diff --git a/core/src/main/resources/hudson/slaves/DumbSlave/configure-entries.jelly b/core/src/main/resources/hudson/slaves/DumbSlave/configure-entries.jelly index 1e0b8624fc60..bb6ca2e99838 100644 --- a/core/src/main/resources/hudson/slaves/DumbSlave/configure-entries.jelly +++ b/core/src/main/resources/hudson/slaves/DumbSlave/configure-entries.jelly @@ -28,9 +28,11 @@ THE SOFTWARE. - - - +
+ + + +
diff --git a/core/src/main/resources/hudson/slaves/SlaveComputer/systemInfo.jelly b/core/src/main/resources/hudson/slaves/SlaveComputer/systemInfo.jelly index 692e93d645f1..41946d8be476 100644 --- a/core/src/main/resources/hudson/slaves/SlaveComputer/systemInfo.jelly +++ b/core/src/main/resources/hudson/slaves/SlaveComputer/systemInfo.jelly @@ -38,11 +38,8 @@ THE SOFTWARE.

- - ${it.caption} ${%System Information} - - (${it.node.nodeDescription}) - + ${it.caption} + ${%System Information}

diff --git a/core/src/main/resources/jenkins/model/Jenkins/MasterComputer/index-top.jelly b/core/src/main/resources/jenkins/model/Jenkins/MasterComputer/index-top.jelly new file mode 100644 index 000000000000..d3b03a03b22e --- /dev/null +++ b/core/src/main/resources/jenkins/model/Jenkins/MasterComputer/index-top.jelly @@ -0,0 +1,13 @@ + + + +

+ + ${it.caption} +

+ + +
+ ${%blurb} +
+
diff --git a/core/src/main/resources/jenkins/model/Jenkins/MasterComputer/index-top.properties b/core/src/main/resources/jenkins/model/Jenkins/MasterComputer/index-top.properties new file mode 100644 index 000000000000..f66557ace431 --- /dev/null +++ b/core/src/main/resources/jenkins/model/Jenkins/MasterComputer/index-top.properties @@ -0,0 +1,4 @@ +blurb = This is the Jenkins controller''s built-in node. \ + Builds running on this node will execute on the same system and as the same user as the Jenkins controller. \ + This is appropriate e.g. for special jobs performing backups, but in general you should run builds on agents. \ + Learn more about distributed builds. diff --git a/core/src/main/resources/lib/hudson/editable-description.js b/core/src/main/resources/lib/hudson/editable-description.js new file mode 100644 index 000000000000..30a5e01efdaf --- /dev/null +++ b/core/src/main/resources/lib/hudson/editable-description.js @@ -0,0 +1,16 @@ +/* global replaceDescription */ +(function () { + document.addEventListener("DOMContentLoaded", function () { + let descriptionLink = document.querySelector("#description-link"); + descriptionLink.addEventListener("click", function (e) { + e.preventDefault(); + let url = descriptionLink.getAttribute("data-url"); + let description = descriptionLink.getAttribute("data-description"); + if (url == null && description == null) { + return replaceDescription(); + } else { + return replaceDescription(description, url); + } + }); + }); +})(); diff --git a/core/src/main/resources/lib/hudson/editableDescription.jelly b/core/src/main/resources/lib/hudson/editableDescription.jelly index 2ed80ba5e91c..f3c5bb6d76dc 100644 --- a/core/src/main/resources/lib/hudson/editableDescription.jelly +++ b/core/src/main/resources/lib/hudson/editableDescription.jelly @@ -32,19 +32,30 @@ THE SOFTWARE. If the current user doesn't have this permission, the description is not editable. + + Optional value of the description. If not specified, will use '${it.description}'. + + + Optional submission URL. If not specified, will use 'submitDescription'. + -