Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default settings to Build Monitor Views #573

Merged
merged 2 commits into from
Feb 15, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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"));
Expand All @@ -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) {
Expand Down Expand Up @@ -178,13 +225,13 @@ private List<JobView> 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<Job<?, ?>> projects = new ArrayList(filter(super.getItems(), Job.class));
List<JobView> jobs = new ArrayList<>();

projects.sort(currentConfig().getOrder());

for (Job project : projects) {
for (Job<?, ?> project : projects) {
jobs.add(views.viewOf(project));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,30 @@

</f:section>

<f:section title="${%Build Monitor - Default Display Settings}">

<f:entry title="${%Text scale}" field="textScale">
<f:textbox name="textScale" value="${it.textScale}" />
</f:entry>

<f:entry title="${%Maximum number of columns}" field="maxColumns">
<f:textbox name="maxColumns" value="${it.maxColumns}" />
</f:entry>

<f:entry title="${%Enable Colour blind mode}">
<f:checkbox id="colourBlindMode" field="colourBlindMode" />
</f:entry>

<f:entry title="${%Enable Reduce motion}">
<f:checkbox id="reduceMotion" field="reduceMotion" />
</f:entry>

<f:entry title="${%Enable Show badges}">
<f:checkbox id="showBadges" field="showBadges" />
</f:entry>

</f:section>

<f:section title="${%Build Monitor - Widget Settings}">

<f:entry title="${%Display committers}" help="${descriptor.getHelpFile('displayCommitters')}">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core">
<nav data-ng-controller="controlPanel" data-ng-init="built_at = '${it.installation.buildMonitorBuiltAt()}'">
<nav data-ng-controller="controlPanel" data-ng-init="built_at = '${it.installation.buildMonitorBuiltAt()}'; defaults.fontSize = ${it.textScale}; defaults.numberOfColumns = ${it.maxColumns}; defaults.colourBlind = ${it.colourBlindMode}; defaults.reduceMotion = ${it.reduceMotion}; defaults.showBadges = ${it.showBadges}; addCookie()">
<span data-ng-show="newVersionAvailable" class="notifications">!</span>
<section data-ng-class="{ showSettings:toggleSettings }">
<input id="settings-toggle" type="checkbox" class="settings" data-ng-model="toggleSettings" />
Expand All @@ -15,11 +15,11 @@
</li>
<li class="settings-option">
<span class="slider-label">Text scale</span>
<rzslider rz-slider-model="settings.fontSize" rz-slider-options="{ floor: 0.1, ceil: 2, step: 0.1, precision: 1 }"></rzslider>
<rzslider rz-slider-model="settings.fontSize" rz-slider-options="{ floor: 0.1, ceil: 5, step: 0.1, precision: 1 }"></rzslider>
</li>
<li class="settings-option">
<span class="slider-label">Maximum number of columns</span>
<rzslider rz-slider-model="settings.numberOfColumns" rz-slider-options="{ floor: 1, ceil: 8, step: 1, precision: 0 }"></rzslider>
<rzslider rz-slider-model="settings.numberOfColumns" rz-slider-options="{ floor: 1, ceil: 20, step: 1, precision: 0 }"></rzslider>
</li>
<li class="settings-option">
<input ng-model="settings.colourBlind"
Expand All @@ -42,6 +42,11 @@
id="settings-show-badges" type="checkbox" />
<label for="settings-show-badges" title="Show the last build badges">Show badges?</label>
</li>
<li class="buttons">
<a class="btn"
data-ng-click="resetSettings()"
title="Reset to defaults.">Reset to defaults</a>
</li>
<li class="buttons">
<a class="btn"
href="configure"
Expand Down
46 changes: 32 additions & 14 deletions build-monitor-plugin/src/main/webapp/scripts/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,38 @@ angular.
function ($scope, cookieJar, townCrier) {
'use strict';

$scope.settings.fontSize = cookieJar.get('fontSize', 1);
$scope.settings.numberOfColumns = cookieJar.get('numberOfColumns', 2);
$scope.settings.colourBlind = cookieJar.get('colourBlind', 0);
$scope.settings.reduceMotion = cookieJar.get('reduceMotion', 0);
$scope.settings.showBadges = cookieJar.get('showBadges', 0);

angular.forEach($scope.settings, function(value, name) {
$scope.$watch('settings.' + name, function(currentValue) {
cookieJar.put(name, currentValue);
$scope.updateCookie = function() {
angular.forEach($scope.settings, function(value, name) {
$scope.$watch('settings.' + name, function(currentValue) {
cookieJar.put(name, currentValue);
});
});
});
}

// that's the minimum viable product .. at its tiniest
townCrier.uponNewVersion(function() {
$scope.newVersionAvailable = true;
});
$scope.addCookie = function() {
$scope.defaults.colourBlind = $scope.defaults.colourBlind ? "1" : "0"
$scope.defaults.reduceMotion = $scope.defaults.reduceMotion ? "1" : "0"
$scope.defaults.showBadges = $scope.defaults.showBadges ? "1" : "0"

$scope.settings.fontSize = cookieJar.get('fontSize', $scope.defaults.fontSize);
$scope.settings.numberOfColumns = cookieJar.get('numberOfColumns', $scope.defaults.numberOfColumns);
$scope.settings.colourBlind = cookieJar.get('colourBlind', $scope.defaults.colourBlind);
$scope.settings.reduceMotion = cookieJar.get('reduceMotion', $scope.defaults.reduceMotion);
$scope.settings.showBadges = cookieJar.get('showBadges', $scope.defaults.showBadges);

$scope.updateCookie();

// that's the minimum viable product .. at its tiniest
townCrier.uponNewVersion(function() {
$scope.newVersionAvailable = true;
});
}

$scope.resetSettings = function() {
angular.forEach($scope.defaults, function(value, name) {
$scope.settings[name] = value;
});

$scope.updateCookie();
}
}]);