Skip to content

Commit

Permalink
aprey10#17 define configuration page for admins; add resources to atl…
Browse files Browse the repository at this point in the history
…assian-plugin.xml; add WebAction; Add store functions (plugin settings); add form to define projects
  • Loading branch information
mfrank-decadis committed Jan 17, 2023
1 parent e1d5aac commit 0ca5e7a
Show file tree
Hide file tree
Showing 6 changed files with 208 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@
<artifactId>jira-maven-plugin</artifactId>
<version>${amps.version}</version>
<extensions>true</extensions>
<executions>
<execution>
<id>default-test-jar</id>
<phase>none</phase>
</execution>
</executions>
<configuration>
<productVersion>${jira.version}</productVersion>
<productDataVersion>${jira.version}</productDataVersion>
Expand All @@ -172,7 +178,7 @@
</pluginArtifacts>
-->
<enableQuickReload>true</enableQuickReload>
<enableFastdev>false</enableFastdev>
<compressResources>false</compressResources>
<!-- See here for an explanation of default instructions: -->
<!-- https://developer.atlassian.com/docs/advanced-topics/configuration-of-instructions-in-atlassian-plugins -->
<instructions>
Expand Down
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";
}
}
32 changes: 32 additions & 0 deletions src/main/resources/atlassian-plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,57 @@
<context>jira.navigator.advanced</context>
<context>jira.navigator.simple</context>
</web-resource>
<web-resource key="open-poker-config-resources" name="open-poker config web resources">
<context>open-poker-config</context>
<dependency>com.atlassian.auiplugin:ajs</dependency>
<dependency>com.atlassian.auiplugin:aui-select2</dependency>
<dependency>com.atlassian.auiplugin:aui-tooltips</dependency>
<resource type="download" name="open-poker-config.css" location="/css/config/open-poker-config.css"/>
<resource type="download" name="open-poker-config.js" location="/js/config/open-poker-config.js"/>
<resource type="download" name="images/" location="/images"/>
</web-resource>

<web-panel name="PlanningPoker" i18n-name-key="planning-poker.name" key="planning-poker"
location="atl.jira.view.issue.right.context" weight="1000">
<description key="planning-poker.description">The PlanningPoker Plugin</description>
<context-provider class="com.aprey.jira.plugin.openpoker.api.PlanningPokerWebPanelProvider"/>
<resource name="view" type="velocity" location="templates/planning-poker.vm"/>
<label key="planning-poker.title"/>
</web-panel>

<ao key="ao-module">
<description>The module configuring the Active Objects service used by this plugin</description>
<entity>com.aprey.jira.plugin.openpoker.persistence.PokerSessionEntity</entity>
<entity>com.aprey.jira.plugin.openpoker.persistence.EstimateEntity</entity>
<entity>com.aprey.jira.plugin.openpoker.persistence.FinalEstEntity</entity>
</ao>

<servlet name="Poker Planning Servlet" class="com.aprey.jira.plugin.openpoker.api.PokerSessionServlet"
key="poker-session">
<description>A servlet to add new Planning Poker session</description>
<url-pattern>/open-poker/session</url-pattern>
</servlet>

<rest key="rest" path="/open-poker" version="1.0">
<description>Rest resource for</description>
</rest>

<web-section key="openpoker-section" name="Openpoker" location="admin_plugins_menu" weight="80">
<label key="Openpoker"/>
</web-section>

<web-item key="openpokerConfiguration" section="admin_plugins_menu/openpoker-section" name="openpokerConfiguration" weight="200">
<description>Page, to configure open poker.</description>
<label key="Configuration"/>
<description>xOpenpoker Configuration</description>
<link linkId="open-poker-configuration">/secure/admin/open-poker/openPokerConfig!default.jspa</link>
</web-item>

<webwork1 key="open-poker-pages" name="Openpoker administration pages" class="java.lang.Object">
<actions>
<action name="com.aprey.jira.plugin.openpoker.config.PokerConfigPage" alias="openPokerConfig" roles-required="admin">
<view name="input">/templates/config/open-poker-config.vm</view>
</action>
</actions>
</webwork1>
</atlassian-plugin>
Empty file.
12 changes: 12 additions & 0 deletions src/main/resources/js/config/open-poker-config.js
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();
})
37 changes: 37 additions & 0 deletions src/main/resources/templates/config/open-poker-config.vm
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>

0 comments on commit 0ca5e7a

Please sign in to comment.