PageBuilderService - Not Loading my Web-Resource

Hey there,

I try to load my Javascript Resources for my velocity view and I have this simple ContextProvider:

public class IssueContactPanelContextProvider extends AbstractJiraContextProvider {

    @ComponentImport
    PageBuilderService pageBuilderService;

    @Autowired
    public IssueContactPanelContextProvider(PageBuilderService pageBuilderService) {
        this.pageBuilderService = pageBuilderService;
    }

    @Override
    public Map getContextMap(ApplicationUser applicationUser, JiraHelper jiraHelper) {
        pageBuilderService.assembler().resources().requireContext("issue-contact-panel");
        Map<String, Object> contextMap = new HashMap<>();

        return contextMap;
    }
}

I have my web-resource right here:

	<web-resource key="issue-contact-panel" name="Main" >
		<resource type="download" name="issue-contact-panel.js" location="js/issue-contact-panel.js" />
		<context>issue-contact-panel</context>
	</web-resource>

I defined the “issue-contact-panel”-context and try to load it in my ContextProvider. When I navigate to the Issue-View it works just fine (URL is /browse/ISSUE-KEY), but when Im browsing through the projects issues (URL is projects/PROJECT-KEY/issues/ISSUE-KEY) the Resources are not loaded.

It seems the resource is not loaded in every case and I just wonder why? There is no error when the PageBuilderService require the context, so what did I missed?

So long.

Could you provide mode context?
How is your plugin loaded? Via webwork action? Web section?
How is IssueContactPanelContextProvider being invoked?
Loading web resources in getContextMap seems like a hack…
Chances are it is only configured to show up in issue view…

I’m using a web-panel to extend the Jira Issue View with a new panel on the right side

	<web-panel name="Contacts" i18n-name-key="contacts.issue-panel.title" key="issue-contacts-panel" location="atl.jira.view.issue.right.context" weight="1000">
		<description key="issue-contact-panel.describtion">Issue Panel for rendering Contact information</description>
		<context-provider class="de.scag.jira.plugin.mailhandler.contextprovider.IssueContactPanelContextProvider"/>
		<resource name="view" type="velocity" location="template/issue-contact-panel/issue-contact-panel.vm"/>
		<label key="contacts.issue-panel.title"/>
	</web-panel>

So everytime the Issue view is rendered my ContextProvider will be invoked.

Why does it only show up in issue view? And how can I require my resources for the panel when its loaded?

<web-panel> can only have one resource so looks like your options are to do $webResourceManager.requireResource() inside the velocity template or what you’re doing now.

Why does it only show up in issue view?

Because you configured it with location="atl.jira.view.issue.right.context".
So it’ll only be loaded in jira pages that has this plugin point, which is probably only the main view issue page.

<web-panel> can only have one resource so looks like your options are to do $webResourceManager.requireResource() inside the velocity template or what you’re doing now.

ok, but Im developing for Jira 7.13.X and the WebResourceManager is deprecated since at least 4 years, so why should I use it?

Why does it only show up in issue view?

Because you configured it with location="atl.jira.view.issue.right.context" .
So it’ll only be loaded in jira pages that has this plugin point, which is probably only the main view issue page.

Okay sorry that doesnt make sense to me. The Panel will be rendered, no matter if its the “main” view issue page, or the view issue page with the issue-list on the left side. The panel is rendered and the ContextProvider got invoked. The PageBuilderService calls the function to require my resource, there is no error or warning in the logs, so it should load my resources.

In the first screen you can see the “main” view issue page. You can see the “Kontakt”-Panel on the right side, its rendered and the JS-resources are provided (I can see the log entrys in the console).

Now, on the next screen you can see that I’m still in the view issue page, the only difference is the list view of the other issues in the current project. You can also see the panel on the right side again, and when I debug it, I can ensure the ContextProvider is invoked and the PageBuilderService requires the resources. But the JS-File is NOT loaded, there is no console log, no error nor a warning about anything.

regards.

1 Like

Hello,
Does a solution exist for this case? I have a similar issue and $webResourceManager.requireResource()
did not help with it.
Regards

We updated to the latest libraries that are also used by Jira to mitigate the problem.

If I understood this issue correctly, this is a limitation of WRM - it doesn’t append scripts to an already loaded page, unless the request for resources is made via WRM’s client side API.

When you switch between issue navigation “details” view via issues on the left sidebar, page is not re-rendered.

Another example would be trying to load resources in a “dialog”, which doesn’t refresh the page.

In such cases you should load an “initializer” (my-plugin-init.js) JavaScript file using pageBuilderService when page the parent page loads, with content similar to this:

    /**
     * IssueNav plugin (issueviewer/js/IssueViewer.js ) triggers following event when issue panels are rendered
     * Events.trigger(Types.NEW_CONTENT_ADDED, [renderedPanel, Reasons.panelRefreshed]);
     */
    Events.bind(Types.NEW_CONTENT_ADDED, function (e, $renderedPanel) {
    // Or dialog init in the case of a dialog 
        wrmRequire(['wr!my-plugin-web-resource'], function () {
                // resources loaded
        });
    }

This will then request and download the resources when user interactions happen on the page after initial load.

Respective AMD modules:

  • 'jira/util/events'
  • 'jira/util/events/types',
  • 'wrm/require'