Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
43 lines (38 sloc) 9.86 KB
layout title date comments permalink tags
post
HowTo: Reusing JIRA gadgets on the issue operations
2011-01-10
false
2011/01/howto-reusing-jira-gadgets-on-issue_10.html
atlassian
jira
java

Hi everybody,

Problem description Recently I had to implement the following use case:

  • Customer has very strict defined issue creation policy and wants to control the every bit of issue creation (things like enhanced priority etc support).
  • The main focus is on usability and rich user interface support.
  • Basically it's multi-step procedure.
After reviewing customer requirements it was decided to go with custom Dashboard Open Social Gadgets.
So the initial solution mockup looked like that:
The wizard-gadget itself was tricky to implement as well, but's an another story.
For the sake of this article let's consider that we already have out plugin implemented with the REST  services to create / update, read issue data.
Transforming gadget to it an Issue operation
At some complicated updates are required from the user interface.We want to reuse the wizard created previously. The way I decided to proceed is to implement issue operation. So, that does it mean for end user? See the mockup below:
But! Jira does not provide this kind of functionality. So, we need to implement this on out own.
First of all we will create our own issue operation (useful information web-fragments, updating jira plugins for jira 4.1). 
1. See the atlassian-plugin.xml snippet for that
<script src="https://gist.github.com/773063.js?file=issue-operation-snippet.xml"></script>
So, we have implemented new Issue Operation which will open web-work action page we have not defined yet so far. Let's do so.
2. See action code.
<script src="https://gist.github.com/773088.js?file=MyWebAction.java"></script>
3. As you may see, MyWebAction depends on GadgetRequestContextFactory and GadgetViewFactory which are OSGi components, so you should import them as component dependencies.
<script src="https://gist.github.com/773100.js?file=component-import-snippet.xml"></script>
4. Let's add add web-action definition to attlasian-plugin.xml
<script src="https://gist.github.com/773113.js?file=mywebaction-atlassian-plugin.xml"></script>
5. Lets specify /templates/mywebaction/render.vm template.
<script src="https://gist.github.com/773138.js?file=render.vm"></script>
And we are finally done. Note xx.yy.zz.arguments.issueId javascript assignment. It's done to pass in arguments to gadget instance. 
6. The following code could be used to get the overall idea:
<script src="https://gist.github.com/773145.js?file=gadget-load-issue-data-snippet.js"></script>
Implementing issue operations the Jira way - using AJS popup dialogs
At this stage you have working and complete issue-gadget-operation. Cool? Yeah!
anyway, purists would argue that it's not inline with Jira Look&Feel. At the moment it does open as separate action, which is not inline with the rest of issue operation actions.
Basically we want our action too look like that (in the popup dialog as all the other actions):
Is it possible? Yes, it is.
To make our wizard to appear as popup dialog box we need to include some javascript to browse issue page. The easiest way to do so is via servlet filter.
1. See atlassian-plugin.xml snippet for defining the servlet filter and javascript resource.
2. See the filter definition itself <script src="https://gist.github.com/773173.js?file=IncludeResourcesFilter.java"></script> 3. And the AJS javascript magic itself <script src="https://gist.github.com/773182.js?file=xxx-yyy.js"></script>

And finally, all the pieces are tight together and you have Jira-AJS-POPUP style issue operation. And the cool part is - it reuses gadget instance created previously.

Hopefully you will find this stuff useful.