Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

accessing current issue object in velocity template of issuetabpanel

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

 

.

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

4 votes
Answer accepted
Volodymyr Krupach
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 20, 2015

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.

Travis DePuy September 16, 2016

I think there might be a couple lines missing from the YourTabPanel class. Where does the `descriptor` come from inside the getActions method? 

Volodymyr Krupach
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 16, 2016

Updated YourTabPanel constructor to inject the descriptor. Thanks for notifying.

Travis DePuy September 19, 2016

ok, and anything special about the extra curly bracket in the getActions method? 

0 votes
Volodymyr Krupach
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 20, 2015

Yes, to pass issue you need to use populateVelocityParams method. Please see my answer.

TAGS
AUG Leaders

Atlassian Community Events