Web UI Plugin module
Sections and ItemsWeb UI plugins can consist of two kinds of plugin modules:
Web items or web sections (referred to collectively as 'web fragments') may be displayed in a number of different ways, depending on the location of the fragment. LocationsIn a number of places in the Jira UI, there are lists of links representing operations relevant to the content being viewed. These are the locations and sections that you can customise:
Web Item DefinitionHere's a sample atlassian-plugin.xml fragment for a web item:
<web-item key="popup_recent_history" name="Recent History Popup Link" section="system.user.navigation.bar/popups" weight="10"> <label key="bodytop.history" /> <tooltip key="tooltip.history" /> <link linkId="user_history">/secure/popups/recenthistory.jsp</link> <param name="windowHeight">$historyWindowHeight</param> <context-provider class="com.atlassian.jira.plugin.web.contextproviders.HeightContextProvider" /> <condition class="com.atlassian.jira.plugin.web.conditions.UserHasIssueHistoryCondition" /> </web-item> The web-item has the following attributes:
The web-item has the following elements
Label elementsLabel elements may contain optional parameters, as shown below:
<label key="common.concepts.create.new.issue"> <param name="param0">$helper.project.name</param> </label>
Tooltip elementsTooltip elements have the same attributes and parameters as the label elements. Link elementsLink elements may contain additional information:
<link linkId="create_link" accessKey="$authcontext.i18nBean.getText('alt.text.createnewissue.accessKey')">/secure/CreateIssue!default.jspa</link>
Icon elementsIcon elements have a height and width attribute. The location of the icon is specified within a link element: <icon height="16" width="16"> <link>/images/icons/print.gif</link> </icon> Param elementsParam elements represent a Map of key/value pairs, where each entry corresponds to the param elements attribute: name and value respectively. <param name="key" value="value" />
its value can be retrieved from within the velocity view by (where $item is an WebItemModuleDescriptor): $item.webParams.get("key") <!-- retrieve the value --> $item.webParams.getRenderedParam("key", $user, $helper) <!-- retrieve the velocity rendered value --> If the value attribute is not specified the value will be set to the body of the element. ie. the following two param elements are equivalent <param name="isPopupLink" value="true" /> <param name="isPopupLink">true</param> Context-provider elementAdds to the velocity context available to the web-section and web-item modules. This means you can add what you need to the context to build more flexible section and item elements. Currently only one context-provider can be specified per module, additional context-providers are ignored. context-provider element must contain a class attribute with the fully-qualified name of a Java class. The referenced class:
For example, the following context-provider will add historyWindowHeight and filtersWindowHeight to the context.
public class HeightContextProvider extends AbstractJiraContextProvider { private final ApplicationProperties applicationProperties; public HeightContextProvider(ApplicationProperties applicationProperties) { this.applicationProperties = applicationProperties; } public Map getContextMap(User user, JiraHelper jiraHelper) { int historyIssues = 0; if (jiraHelper != null && jiraHelper.getRequest() != null) { UserHistory history = (UserHistory) jiraHelper.getRequest().getSession().getAttribute(SessionKeys.USER_ISSUE_HISTORY); if (history != null) { historyIssues = history.getIssues().size(); } } int logoHeight = TextUtils.parseInt(applicationProperties.getDefaultBackedString(APKeys.JIRA_LF_LOGO_HEIGHT)); String historyHeight = String.valueOf(80 + logoHeight + (25 * historyIssues)); String filterHeight = String.valueOf(205 + logoHeight); return EasyMap.build("historyWindowHeight", historyHeight, "filtersWindowHeight", filterHeight); } } The above HeightContextProvider can be used by nesting the following element in a web-item module. <context-provider class="com.atlassian.jira.plugin.web.contextproviders.HeightContextProvider" />
The newly added context entries historyWindowHeight and filtersWindowHeight can be used in the XML module descriptors just like normal velocity context variables by prefixing it with the dollar symbol ($) <!-- pass the value of historyWindowHeight as a parameter called windowHeight (see param element above for its usage) --> <param name="windowHeight">$historyWindowHeight</param> <!-- set the link's label to print the value of filtersWindowHeight --> <label>filter window height is: $filtersWindowHeight</label> Condition and Conditions elementsConditions can be added to the web-section and web-item modules to display them only when all its conditions are true. Condition elements must contain a class attribute with the fully-qualified name of a Java class. The referenced class:
Condition elements can take optional parameters. These parameters will be passed in to the Condition's init() method as a Map of String key/value pairs after autowiring, but before any condition checks are performed. For example:
<condition class="com.atlassian.jira.plugin.web.conditions.JiraGlobalPermissionCondition"> <param name="permission">admin</param> </condition> To invert a condition, add the attribute 'invert="true"' to the condition element. This is useful where you want to show the section if a certain condition is not satisfied.
<conditions type="OR"> <condition class="com.atlassian.jira.plugin.web.conditions.JiraGlobalPermissionCondition"> <param name="permission">admin</param> </condition> <condition class="com.atlassian.jira.plugin.web.conditions.UserHasProjectsCondition"> <param name="permission">project</param> </condition> </conditions> Web Section DefinitionHere's a sample atlassian-plugin.xml for a web section:
<web-section key="usersgroups" name="Users and Groups Section" location="system.admin" weight="110"> <label key="admin.menu.usersandgroups.users.and.groups" /> <condition class="com.atlassian.jira.plugin.web.conditions.UserIsAdminCondition" /> </web-section>
Velocity ContextThe following table lists out the velocity context available for use in the XML descriptor and velocity views.
ExamplesHeres a simple example that uses both the web UI module and the webwork plugin module. The following plugin modules will:
<webwork1 key="HelloWorld" name="Hello World Example Action"> <description key="action.hello.world.desc">Webwork plugin example that prints hello world. Can also specify a name to say hello to.</description> <actions> <action name="HelloWorldAction" alias="Hello"> <view name="success">/templates/example/helloworld.vm</view> </action> </actions> </webwork1> <web-section key="example1" name="Example 1 Section" location="system.admin" weight="105"> <label key="section.example.one.label" /> </web-section> <web-item key="google_home" name="Google Home" section="system.admin/example1" weight="10"> <description key="item.google.home.desc">Simple link to google.com.</description> <label key="item.google.home.label" /> <link linkId="google_home">http://google.com</link> </web-item> <web-item key="hello_world" name="Webwork Hello World Example" section="system.admin/example1" weight="20"> <description key="item.hello.world.desc">Link to the Hello World action. No name parameter specified.</description> <label key="item.hello.world.label" /> <link linkId="hello_world">/secure/Hello.jspa</link> </web-item> <web-item key="hello_user" name="Webwork Hello User Example" section="system.admin/example1" weight="30"> <description key="item.hello.user.desc">Link to the Hello World action with name set to the current user's full name.</description> <label key="item.hello.user.label" /> <link linkId="hello_user">/secure/Hello.jspa?name=${user.fullName}</link> <condition class="com.atlassian.jira.plugin.web.conditions.UserLoggedInCondition" /> </web-item> Here is the screenshot of the new administration menu:
|


Comments (2)
Apr 19, 2007
Ferenc Kiss says:
Guys, I think that the XML snippets are wrong: the condition classes are located...Guys, I think that the XML snippets are wrong: the condition classes are located in the com.atlassian.jira.plugin.webfragment.conditions.JiraGlobalPermissionCondition package, not in com.atlassian.jira.plugin.web.conditions.JiraGlobalPermissionCondition!(At least in 3.8 I got ClassNotFoundException.)
May 17, 2007
Keertikar Pandey says:
Can someone provide codesnippet for creating WEBITEM plugins.Can someone provide code-snippet for creating WEB-ITEM plugins.