Coding paradigm: line by line all my opinions are belong to me

HowTo: Reusing JIRA gadgets on the issue operations

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
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.
3. As you may see, MyWebAction depends on GadgetRequestContextFactory and GadgetViewFactory which are OSGi components, so you should import them as component dependencies.
4. Let's add add web-action definition to attlasian-plugin.xml
5. Lets specify /templates/mywebaction/render.vm template.
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:
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 3. And the AJS javascript magic itself

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. 

NB. If you've found typos or errors, please suggest a correction or edit on github.
comments powered by Disqus