Issue Web Panel Resource Loaded Once, but need to have it for each issue after change the one

Hello,
Currently in process of developing plugin for Jira Server (version 8.0.2)

Had a problem with loading web resource (JS file) into web panel module component.
The example of web resource inside atlassian-plugin.xml. Plugin key is “com.subject7.jira-addon-server”

<web-resource name="Issue Right Panel Js Resource" i18n-name-key="issue-right-panel-js-resource.name" key="issue-right-panel-js-resource">
    <description key="issue-right-panel-js-resource.description">Issue Right Panel Js Resource Plugin</description>
    <resource name="issue-right-panel-module.bundle.js" type="download" location="/reactbundle/issue-right-panel-module.bundle.js"/>
  </web-resource>

Used all of these approaches:

  1. web resource manager inside of Velocity template
<html>
<head>
    <title>Test Render Simple</title>
$webResourceManager.requireResource("com.subject7.jira-addon-server:issue-right-panel-js-resource")
</head>
<body>
<div class="pagecontent">
    <div id="issue-right-panel">Loading ...</div>
</div>
</body>
</html>
  1. context provider with using PageBuilderService to add resource
@Named
public class IssueRightPanelContextProvider extends AbstractJiraContextProvider {

    private final PageBuilderService pageBuilderService;

    @Inject
    public IssueRightPanelContextProvider(@ComponentImport PageBuilderService pageBuilderService) {
        this.pageBuilderService = pageBuilderService;
    }

    @Override
    public Map getContextMap(ApplicationUser applicationUser, JiraHelper jiraHelper) {
        pageBuilderService
                .assembler()
                .resources()
                .requireWebResource("com.subject7.jira-addon-server:issue-right-panel-js-resource");
        return jiraHelper.getContextParams();
    }
}

None of them worked.

The last thing that I tried was adding WRM.require call inside of Velocity template.

<html>
<head>
    <title>Test Render Simple</title>
   <script>
        WRM.require("com.subject7.jira-addon-server:issue-right-panel-js-resource");
    </script>
</head>
<body>
<div class="pagecontent">
    <div id="issue-right-panel">Loading ...</div>
</div>
</body>
</html>

So it started to load the necessary JS file for Issue Web Panel.
But it works just for first load and after going to another issue the JS file is not executed again.

Maybe there are additional steps for executing JS for each of opened issue (issue web panel)?

Hi Ivan,

in order to load the web resource in the template I would suggest to add a context to the resource like this:

<web-resource name="Issue Right Panel Js Resource" i18n-name-key="issue-right-panel-js-resource.name" key="issue-right-panel-js-resource">
    <description key="issue-right-panel-js-resource.description">Issue Right Panel Js Resource Plugin</description>
    <resource name="issue-right-panel-module.bundle.js" type="download" location="/reactbundle/issue-right-panel-module.bundle.js"/>
    <context>issue-right-panel-context</context>
</web-resource>

and then pass the context to the requireResource method:

<html>
<head>
    <title>Test Render Simple</title>
    $webResourceManager.requireResourcesForContext("issue-right-panel-context")
</head>
<body>
<div class="pagecontent">
    <div id="issue-right-panel">Loading ...</div>
</div>
</body>
</html>

Let me know if it works.
Vojtěch Schlemmer [MoroSystems, s.r.o., Czech Republic]

1 Like

Vojtěch, thank you for your reply,

It does not load any resources.
I put js and css inside web-resource module and specified context.
Updated template with requireResourcesForContext.
But neither css nor js was loaded.

Maybe web panel has specific rules.

Hi,

In case you want to add your resource into any issue view Context, you could try the following:

<web-resource name="Issue Right Panel Js Resource" i18n-name-key="issue-right-panel-js-resource.name" key="issue-right-panel-js-resource">
    <description key="issue-right-panel-js-resource.description">Issue Right Panel Js Resource Plugin</description>
    <resource name="issue-right-panel-module.bundle.js" type="download" location="/reactbundle/issue-right-panel-module.bundle.js"/>
    <context>jira.view.issue</context>
  </web-resource>

This will add your resource to all issue views, so you should keep your bundle size in mind.

The downside of this approach is, that you may need to listen to Jira Events to init your Javascript code. That may be the case if a issue is beeing displayed from a search, where the resources are not reloaded when you switch the issue

AJS.$(function() {
	JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function(e, context, reason) {
		//Init your 
	});
});

Hello m.herrmann,

Thanks for your reply.

It helped. Now I can see resources and JS works. As you mentioned it loads just one time.
But, at least it works!
Thank you