From 457854ac96964b61bb597ddd4461f8ddab418f60 Mon Sep 17 00:00:00 2001 From: Daniel Beland Date: Sat, 12 Feb 2022 15:59:52 -0500 Subject: [PATCH 1/2] adding default settings to the configuration page --- .../buildmonitor/BuildMonitorDescriptor.java | 30 +++++++++++ .../buildmonitor/BuildMonitorView.java | 51 ++++++++++++++++++- .../plugins/buildmonitor/Config.java | 51 +++++++++++++++++-- .../BuildMonitorView/configure-entries.jelly | 24 +++++++++ .../BuildMonitorView/main-settings.jelly | 11 ++-- .../src/main/webapp/scripts/settings.js | 46 ++++++++++++----- 6 files changed, 191 insertions(+), 22 deletions(-) diff --git a/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/BuildMonitorDescriptor.java b/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/BuildMonitorDescriptor.java index 3e5cd89c3..44fbbd9a8 100644 --- a/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/BuildMonitorDescriptor.java +++ b/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/BuildMonitorDescriptor.java @@ -53,4 +53,34 @@ public boolean getPermissionToCollectAnonymousUsageStatistics() { public void setPermissionToCollectAnonymousUsageStatistics(boolean collect) { this.permissionToCollectAnonymousUsageStatistics = collect; } + + public FormValidation doCheckMaxColumns(@QueryParameter String value) { + try { + int intValue = Integer.parseInt(value); + if(intValue > 0) { + return FormValidation.ok(); + } else { + return FormValidation.error("Must be an integer, greater than 0."); + } + } catch (NullPointerException npe) { + return FormValidation.error("Cannot be null."); + } catch (NumberFormatException nfe) { + return FormValidation.error("Must be an integer."); + } + } + + public FormValidation doCheckTextScale(@QueryParameter String value) { + try { + double doubleValue = Double.parseDouble(value); + if(doubleValue > 0.0) { + return FormValidation.ok(); + } else { + return FormValidation.error("Must be a double, greater than 0.0."); + } + } catch (NullPointerException npe) { + return FormValidation.error("Cannot be null."); + } catch (NumberFormatException nfe) { + return FormValidation.error("Must be a double."); + } + } } \ No newline at end of file diff --git a/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/BuildMonitorView.java b/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/BuildMonitorView.java index 47e5ca199..b33c4900e 100644 --- a/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/BuildMonitorView.java +++ b/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/BuildMonitorView.java @@ -96,6 +96,36 @@ public boolean isDisplayCommitters() { return currentConfig().shouldDisplayCommitters(); } + // used in the configure-entries.jelly and main-settings.jelly forms + @SuppressWarnings("unused") + public double getTextScale() { + return currentConfig().getTextScale(); + } + + // used in the configure-entries.jelly and main-settings.jelly forms + @SuppressWarnings("unused") + public int getMaxColumns() { + return currentConfig().getMaxColumns(); + } + + // used in the configure-entries.jelly and main-settings.jelly forms + @SuppressWarnings("unused") + public boolean isColourBlindMode() { + return currentConfig().colourBlindMode(); + } + + // used in the configure-entries.jelly and main-settings.jelly forms + @SuppressWarnings("unused") + public boolean isReduceMotion() { + return currentConfig().reduceMotion(); + } + + // used in the configure-entries.jelly and main-settings.jelly forms + @SuppressWarnings("unused") + public boolean isShowBadges() { + return currentConfig().showBadges(); + } + @SuppressWarnings("unused") // used in the configure-entries.jelly form public String currentDisplayBadges() { return currentConfig().getDisplayBadges().name(); @@ -138,7 +168,12 @@ protected void submit(StaplerRequest req) throws ServletException, IOException, String requestedOrdering = req.getParameter("order"); String displayBadgesFrom = req.getParameter("displayBadgesFrom"); title = req.getParameter("title"); + String maxColumns = req.getParameter("maxColumns"); + String textScale = req.getParameter("textScale"); + currentConfig().setColourBlindMode(json.optBoolean("colourBlindMode", false)); + currentConfig().setReduceMotion(json.optBoolean("reduceMotion", false)); + currentConfig().setShowBadges(json.optBoolean("showBadges", true)); currentConfig().setDisplayBadges(req.getParameter("displayBadges")); currentConfig().setDisplayCommitters(json.optBoolean("displayCommitters", true)); currentConfig().setBuildFailureAnalyzerDisplayedField(req.getParameter("buildFailureAnalyzerDisplayedField")); @@ -150,6 +185,18 @@ protected void submit(StaplerRequest req) throws ServletException, IOException, throw new FormException("Can't order projects by " + requestedOrdering, "order"); } + try { + currentConfig().setMaxColumns(Integer.parseInt(maxColumns)); + } catch (Exception e) { + throw new FormException("Invalid value of 'Maximum number of columns': '" + maxColumns + "' (should be double).", maxColumns); + } + + try { + currentConfig().setTextScale(Double.parseDouble(textScale)); + } catch (Exception e) { + throw new FormException("Invalid value of 'Text scale': '" + textScale + "' (should be double).", textScale); + } + try { currentConfig().setDisplayBadgesFrom(getBuildViewModelIn(displayBadgesFrom)); } catch (Exception e) { @@ -178,13 +225,13 @@ private List jobViews() { JobViews views = new JobViews(new StaticJenkinsAPIs(), currentConfig()); //A little bit of evil to make the type system happy. - @SuppressWarnings("unchecked") + @SuppressWarnings({ "unchecked", "rawtypes" }) List> projects = new ArrayList(filter(super.getItems(), Job.class)); List jobs = new ArrayList<>(); projects.sort(currentConfig().getOrder()); - for (Job project : projects) { + for (Job project : projects) { jobs.add(views.viewOf(project)); } diff --git a/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/Config.java b/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/Config.java index edcce92d3..ef08a8de0 100644 --- a/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/Config.java +++ b/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/Config.java @@ -10,11 +10,16 @@ public class Config { - private boolean displayCommitters; + private Boolean colourBlindMode; + private Boolean displayCommitters; + private Boolean reduceMotion; + private Integer maxColumns; + private Double textScale; + private Boolean showBadges; private DisplayOptions displayBadges; private GetBuildViewModel displayBadgesFrom; private BuildFailureAnalyzerDisplayedField buildFailureAnalyzerDisplayedField; - private boolean displayJUnitProgress; + private Boolean displayJUnitProgress; public static Config defaultConfig() { return new Config(); @@ -43,6 +48,14 @@ public BuildFailureAnalyzerDisplayedField getBuildFailureAnalyzerDisplayedField( public void setBuildFailureAnalyzerDisplayedField(String buildFailureAnalyzerDisplayedField) { this.buildFailureAnalyzerDisplayedField = BuildFailureAnalyzerDisplayedField.valueOf(buildFailureAnalyzerDisplayedField); } + + public boolean colourBlindMode() { + return Optional.ofNullable(colourBlindMode).orElse(false); + } + + public void setColourBlindMode(boolean flag) { + this.colourBlindMode = flag; + } public boolean shouldDisplayCommitters() { return Optional.ofNullable(displayCommitters).orElse(true); @@ -51,6 +64,22 @@ public boolean shouldDisplayCommitters() { public void setDisplayCommitters(boolean flag) { this.displayCommitters = flag; } + + public boolean reduceMotion() { + return Optional.ofNullable(reduceMotion).orElse(false); + } + + public void setReduceMotion(boolean flag) { + this.reduceMotion = flag; + } + + public boolean showBadges() { + return Optional.ofNullable(showBadges).orElse(true); + } + + public void setShowBadges(boolean flag) { + this.showBadges = flag; + } public DisplayOptions getDisplayBadges() { return Optional.ofNullable(displayBadges).orElse(DisplayOptions.UserSetting); @@ -69,13 +98,29 @@ public void setDisplayBadgesFrom(GetBuildViewModel displayBadgesFrom) { } public boolean shouldDisplayJUnitProgress() { - return Optional.of(displayJUnitProgress).orElse(true); + return Optional.ofNullable(displayJUnitProgress).orElse(true); } public void setDisplayJUnitProgress(boolean flag) { this.displayJUnitProgress = flag; } + public int getMaxColumns() { + return Optional.ofNullable(maxColumns).orElse(2); + } + + public void setMaxColumns(int maxColumns) { + this.maxColumns = maxColumns; + } + + public double getTextScale() { + return Optional.ofNullable(textScale).orElse(1.0); + } + + public void setTextScale(double scale) { + this.textScale = scale; + } + @Override public String toString() { return String.format("Config{order=%s}", order.getClass().getSimpleName()); diff --git a/build-monitor-plugin/src/main/resources/com/smartcodeltd/jenkinsci/plugins/buildmonitor/BuildMonitorView/configure-entries.jelly b/build-monitor-plugin/src/main/resources/com/smartcodeltd/jenkinsci/plugins/buildmonitor/BuildMonitorView/configure-entries.jelly index dcc84dfcf..d4c8b44ca 100644 --- a/build-monitor-plugin/src/main/resources/com/smartcodeltd/jenkinsci/plugins/buildmonitor/BuildMonitorView/configure-entries.jelly +++ b/build-monitor-plugin/src/main/resources/com/smartcodeltd/jenkinsci/plugins/buildmonitor/BuildMonitorView/configure-entries.jelly @@ -70,6 +70,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/build-monitor-plugin/src/main/resources/com/smartcodeltd/jenkinsci/plugins/buildmonitor/BuildMonitorView/main-settings.jelly b/build-monitor-plugin/src/main/resources/com/smartcodeltd/jenkinsci/plugins/buildmonitor/BuildMonitorView/main-settings.jelly index b0805cd87..e26c80a9e 100644 --- a/build-monitor-plugin/src/main/resources/com/smartcodeltd/jenkinsci/plugins/buildmonitor/BuildMonitorView/main-settings.jelly +++ b/build-monitor-plugin/src/main/resources/com/smartcodeltd/jenkinsci/plugins/buildmonitor/BuildMonitorView/main-settings.jelly @@ -1,6 +1,6 @@ -