Hi,
How can i get the current issue object in a Issuetabpanel. I am trying to get the issue object in the velocity template and call a custom rest api module via javascript by passing it as a parameter .
I also tried populating the populateVelocityParams method where I populate the current user by
params.put("user", this.authenticationContext.getUser().getDisplayName());
Is there a similair way to pass the current issue object ?
Appreciate your help
.
Community moderators have prevented the ability to post new answers.
Hi Jeideep!
To add your custom issue tab panel you need:
1) add issue-tabpanel descriptor to you atlassian-plugin.xml (pure documentation we have for this: https://developer.atlassian.com/jiradev/jira-architecture/building-jira-add-ons/jira-plugins2-overview/jira-plugin-module-types/issue-tab-panel-plugin-module):
<issue-tabpanel key="your-tabpanel" name="your-tabpanel" class="YourTabPanel"> <label key="yourpugini18.tabLabel">Your Tab</label> <resource type="velocity" name="view" location="/templates/yourTab.vm" /> <order>200</order> <sortable>true</sortable> <supports-ajax-load>true</supports-ajax-load> </issue-tabpanel>
2) Extend from https://docs.atlassian.com/jira/latest/com/atlassian/jira/plugin/issuetabpanel/AbstractIssueTabPanel.html
In the class that extends from AbstractIssueTabPanel you have to implement getActions method that is supposed to return list of IssueAction instances. Here you already have user and issue and need to create your custom implementation of IssueAction to pass values to "yourTab.vm" velocity.
public class YourTabPanel extends AbstractIssueTabPanel { private final IssueTabPanelModuleDescriptor descriptor; public YourTabPanel(IssueTabPanelModuleDescriptor descriptor, /* pass services to inject */) { this.descriptor = descriptor; // Inject services that you need } @Override public List<IssueAction> getActions(Issue issue, User remoteUser) { List<IssueAction> issueActions = Lists.newArrayList(); issueActions.add(new YourAction(descriptor, issue, remoteUser)); return issueActions; } @Override public boolean showPanel(Issue issue, User remoteUser) { return true; // i.e. show always } }
3) In your class that extends from AbstractIssueAction your use populateVelocityParams to pass values to the velocity:
public class YourAction extends AbstractIssueAction { private final Issue issue; private final User remoteUser; public YourAction(IssueTabPanelModuleDescriptor descriptor, Issue issue, User remoteUser) { super(descriptor); this.issue = issue; this.remoteUser = remoteUser; } public Date getTimePerformed() { return issue.getCreated(); } protected void populateVelocityParams(Map params) { params.put("action", this); params.put("issue", issue); params.put("user", remoteUser); } }
4) Please note that the velocity file is processed for each IssueAction you added to the list in the getActions method and here you can access params you passed in populateVelocityParams method:
<p>User: $user.displayName </p> <p>Issue id: $issue.id</p>
For more deep understanding you should look into one of IssueTabPanel implementation in JIRA sources. WorklogTabPanel looks as good example for me.
Thanks much for your time and help. I was able to work it out as you said.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think there might be a couple lines missing from the YourTabPanel class. Where does the `descriptor` come from inside the getActions method?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Updated YourTabPanel constructor to inject the descriptor. Thanks for notifying.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
ok, and anything special about the extra curly bracket in the getActions method?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, to pass issue you need to use populateVelocityParams method. Please see my answer.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.