forked from aprey10/open-poker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
aprey10#17 define configuration page for admins; add resources to atl…
…assian-plugin.xml; add WebAction; Add store functions (plugin settings); add form to define projects
- Loading branch information
1 parent
e1d5aac
commit 0ca5e7a
Showing
6 changed files
with
208 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
src/main/java/com/aprey/jira/plugin/openpoker/config/PokerConfigPage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package com.aprey.jira.plugin.openpoker.config; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import com.atlassian.jira.component.ComponentAccessor; | ||
import com.atlassian.jira.project.Project; | ||
import com.atlassian.jira.security.request.RequestMethod; | ||
import com.atlassian.jira.security.request.SupportedMethods; | ||
import com.atlassian.jira.security.xsrf.DoesNotRequireXsrfCheck; | ||
import com.atlassian.jira.web.action.JiraWebActionSupport; | ||
import com.atlassian.sal.api.pluginsettings.PluginSettings; | ||
import com.atlassian.sal.api.pluginsettings.PluginSettingsFactory; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import webwork.action.Action; | ||
import webwork.action.ServletActionContext; | ||
|
||
@SupportedMethods({ RequestMethod.GET }) | ||
public class PokerConfigPage extends JiraWebActionSupport { | ||
|
||
//Logger instance for the class | ||
private static Logger log = LoggerFactory.getLogger(PokerConfigPage.class); | ||
//Key for plugin settings | ||
private static String OPEN_POKER_KEY = "com.aprey.jira.plugin.openpoker"; | ||
//List of allowed projects | ||
private List<String> allowedProjects = new ArrayList<>(); | ||
|
||
/** | ||
* Method is called when the page is first loaded | ||
*/ | ||
@Override | ||
public String doDefault() throws Exception { | ||
allowedProjects.addAll(getStoredAllowedProjects()); | ||
return Action.INPUT; | ||
} | ||
|
||
/** | ||
* Method to get the stored allowed projects from plugin settings | ||
* @return ArrayList of allowed projects | ||
*/ | ||
private static ArrayList<String> getStoredAllowedProjects() { | ||
PluginSettings pluginSettings = getPluginSettings(); | ||
String storedProjects = ((String) pluginSettings.get("allowedProjects")); | ||
if ( storedProjects != null ) { | ||
return Arrays.stream(storedProjects.split(",")).collect(Collectors.toCollection(ArrayList::new)); | ||
} | ||
return new ArrayList<>(); | ||
} | ||
|
||
/** | ||
* Method is called when the form is submitted | ||
*/ | ||
@Override | ||
@DoesNotRequireXsrfCheck | ||
@SupportedMethods({ RequestMethod.POST }) | ||
protected String doExecute() throws Exception { | ||
String updatedAllowedProjects = getUpdatedAllowedProjects(); | ||
storeAllowedProjects(updatedAllowedProjects); | ||
|
||
if ( !getHasErrorMessages() ) { | ||
return returnComplete("openPokerConfig!default.jspa"); | ||
} | ||
return Action.INPUT; | ||
} | ||
|
||
/** | ||
* Method to get the updated allowed projects from the form | ||
* @return String of allowed projects | ||
*/ | ||
private static String getUpdatedAllowedProjects() { | ||
HttpServletRequest request | ||
= ServletActionContext.getRequest(); | ||
String updatedAllowedProjects = request.getParameter("allowedProjects"); | ||
return updatedAllowedProjects; | ||
} | ||
|
||
/** | ||
* Method to store the updated allowed projects in plugin settings | ||
* @param updatedAllowedProjects String of allowed projects | ||
*/ | ||
private static void storeAllowedProjects(String updatedAllowedProjects) { | ||
PluginSettings pluginSettings = getPluginSettings(); | ||
pluginSettings.put("allowedProjects", updatedAllowedProjects); | ||
} | ||
|
||
/** | ||
* Method to get the plugin settings | ||
* @return pluginSettings instance | ||
*/ | ||
private static PluginSettings getPluginSettings() { | ||
PluginSettingsFactory pluginSettingsFactory = ComponentAccessor.getOSGiComponentInstanceOfType(PluginSettingsFactory.class); | ||
PluginSettings pluginSettings = pluginSettingsFactory.createSettingsForKey(OPEN_POKER_KEY); | ||
return pluginSettings; | ||
} | ||
|
||
|
||
public List<String> getAllowedProjects() { | ||
return allowedProjects; | ||
} | ||
|
||
public String getAllowedProjectsValue() { | ||
return String.join(",", allowedProjects); | ||
} | ||
|
||
public void setAllowedProjects(List<String> allowedProjects) { | ||
this.allowedProjects = allowedProjects; | ||
} | ||
|
||
public List<Project> getProjects() { | ||
return ComponentAccessor.getProjectManager().getProjects(); | ||
} | ||
|
||
public String getURL() { | ||
return "openPokerConfig.jspa"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
AJS.$(document).ready(() => { | ||
const initialize = () => { | ||
let $allowedProjectsSelect = AJS.$("#allowedProjectsSelect"); | ||
$allowedProjectsSelect.auiSelect2(); | ||
|
||
$allowedProjectsSelect.on("change", () => { | ||
AJS.$("#allowedProjects").val(AJS.$("#allowedProjectsSelect").val()) | ||
}) | ||
} | ||
|
||
initialize(); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
$webResourceManager.requireResource("com.aprey.jira.plugin.openpoker.open-poker:open-poker-config-resources") | ||
<html> | ||
<head> | ||
<title>Open poker configuration</title> | ||
</head> | ||
<body> | ||
|
||
<header class="aui-page-header"> | ||
<div class="aui-page-header-inner"> | ||
<div class="aui-page-header-main"> | ||
<h1>Open poker configuration</h1> | ||
</div> | ||
</div> | ||
</header> | ||
<h2>Permissions</h2> | ||
<form action="$action.getURL()" class="aui" method="POST"> | ||
<input type="hidden" id="allowedProjects" name="allowedProjects" value="$action.getAllowedProjectsValue()"/> | ||
<fieldset> | ||
<div class="field-group"> | ||
<label for="allowedProjects" class="paramName">Used projects:</label> | ||
<select id="allowedProjectsSelect" name="allowedProjectsSelect" style="padding: 5px 0 0 0" multiple> | ||
#foreach ($project in $projects) | ||
<option #if(${allowedProjects.contains(${project.getKey()})}) selected #end value="${project.getKey()}">${project.getName()} (${project.getKey()})</option> | ||
#end | ||
</select> | ||
<div class="description">Define the projects, where open poker should be rendered on the issue view. If no project is selected, it will be enabled for all projects.</div> | ||
</div> | ||
</fieldset> | ||
|
||
<div class="buttons-container" style="padding: 10px 0 4px 0;"> | ||
<div class="buttons"> | ||
<button id="save_button" class="aui-button aui-button-primary" type="submit">Save</button> | ||
</div> | ||
</div> | ||
</form> | ||
</body> | ||
</html> |