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 Add condition to web-panel; refactor code; Styling
- Loading branch information
1 parent
0ca5e7a
commit 9d53dd9
Showing
6 changed files
with
104 additions
and
55 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
src/main/java/com/aprey/jira/plugin/openpoker/api/config/AllowedProjectsCondition.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,31 @@ | ||
package com.aprey.jira.plugin.openpoker.api.config; | ||
|
||
import java.util.List; | ||
|
||
import com.atlassian.jira.plugin.webfragment.conditions.AbstractWebCondition; | ||
import com.atlassian.jira.plugin.webfragment.model.JiraHelper; | ||
import com.atlassian.jira.user.ApplicationUser; | ||
|
||
/** | ||
* Class that defines a condition for the web fragment visibility | ||
*/ | ||
public class AllowedProjectsCondition extends AbstractWebCondition { | ||
|
||
/** | ||
* Method to determine whether the web fragment should be displayed or not | ||
* @param applicationUser The user currently viewing the page | ||
* @param jiraHelper The JiraHelper that provides access to various Jira-related objects | ||
* @return boolean value indicating whether the web fragment should be displayed or not | ||
*/ | ||
@Override | ||
public boolean shouldDisplay(ApplicationUser applicationUser, JiraHelper jiraHelper) { | ||
List<String> allowedProjects = ConfigurationManager.getStoredAllowedProjects(); | ||
if ( allowedProjects.isEmpty() ) { | ||
return true; | ||
} | ||
if ( jiraHelper.getProject() != null ) { | ||
return allowedProjects.contains(jiraHelper.getProject().getKey()); | ||
} | ||
return true; | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/main/java/com/aprey/jira/plugin/openpoker/api/config/ConfigurationManager.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,51 @@ | ||
package com.aprey.jira.plugin.openpoker.api.config; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.stream.Collectors; | ||
|
||
import com.atlassian.jira.component.ComponentAccessor; | ||
import com.atlassian.sal.api.pluginsettings.PluginSettings; | ||
import com.atlassian.sal.api.pluginsettings.PluginSettingsFactory; | ||
|
||
public abstract class ConfigurationManager { | ||
private static PluginSettingsFactory pluginSettingsFactory = ComponentAccessor.getOSGiComponentInstanceOfType(PluginSettingsFactory.class); | ||
|
||
//Key for plugin settings | ||
private static String OPEN_POKER_KEY = "com.aprey.jira.plugin.openpoker"; | ||
|
||
/** | ||
* Method to get the plugin settings | ||
* | ||
* @return pluginSettings instance | ||
*/ | ||
public static PluginSettings getPluginSettings() { | ||
PluginSettingsFactory pluginSettingsFactory = ComponentAccessor.getOSGiComponentInstanceOfType(PluginSettingsFactory.class); | ||
PluginSettings pluginSettings = pluginSettingsFactory.createSettingsForKey(OPEN_POKER_KEY); | ||
return pluginSettings; | ||
} | ||
|
||
/** | ||
* Method to get the stored allowed projects from plugin settings | ||
* | ||
* @return ArrayList of allowed projects | ||
*/ | ||
public static ArrayList<String> getStoredAllowedProjects() { | ||
PluginSettings pluginSettings = getPluginSettings(); | ||
String storedProjects = ((String) pluginSettings.get("allowedProjects")); | ||
if ( storedProjects != null && !storedProjects.isEmpty() ) { | ||
return Arrays.stream(storedProjects.split(",")).collect(Collectors.toCollection(ArrayList::new)); | ||
} | ||
return new ArrayList<>(); | ||
} | ||
|
||
/** | ||
* Method to store the updated allowed projects in plugin settings | ||
* | ||
* @param updatedAllowedProjects String of allowed projects | ||
*/ | ||
public static void storeAllowedProjects(String updatedAllowedProjects) { | ||
PluginSettings pluginSettings = getPluginSettings(); | ||
pluginSettings.put("allowedProjects", updatedAllowedProjects); | ||
} | ||
} |
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
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
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 |
---|---|---|
@@ -1,12 +1,16 @@ | ||
AJS.$(document).ready(() => { | ||
const initialize = () => { | ||
let $allowedProjectsSelect = AJS.$("#allowedProjectsSelect"); | ||
$allowedProjectsSelect.auiSelect2(); | ||
$allowedProjectsSelect.auiSelect2( | ||
{ | ||
placeholder: "Open poker will be available for each project", | ||
allowClear: true | ||
}); | ||
|
||
$allowedProjectsSelect.on("change", () => { | ||
AJS.$("#allowedProjects").val(AJS.$("#allowedProjectsSelect").val()) | ||
}) | ||
} | ||
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