How to hide some issue link types in the Issue Link pop up window for Jira 5.1.8 using javascript?

允我心安 提交于 2019-12-22 00:35:32

问题


I wanted to hide some issue link outward & inwards strings of Link type from the Link Issues Popup Window using java script.

I have tried using java script but I am not getting the popup screen from the java script.

Please see the screenshot below :

Can anyone tell me how can I get this popup screen in the java script? Is there any other method to hide this?

Thanks & Regards,

Renuka.


回答1:


To hide the clone issue link every page:

edit the file system-webresources-plugin.xml (should be at /atlassian-jira/WEB-INF/classes/), and add to <web-resource key="jira-fields"> this code:

    <resource type="download" name="myScript.js" location="/includes/jira/field/script.js">
        <param name="source" value="webContextStatic"/>
    </resource>

than, on /includes/jira/field/myScript.js write this:

AJS.$(document).ready(function() {
    if (AJS.$("#link-type option[value*='clon']").size() > 0) {
        // will work even when right clicking on More 
        // Actions->Link & open it into a new window
        AJS.$("#link-type option[value*='clon']").remove()
    } else if (AJS.$("#link-issue").size() > 0) {
        // will work in case the link menu showing via popup
        AJS.$("#link-issue").click(function(){
            // wait for the popup to show, and remove the clone options
            setTimeout(function (){
                AJS.$("#link-type option[value*='clon']").remove();
             }, 300);
        });
    }
});

restart Jira and it that it!

The script attaches a function to the link-menu opening, than gives the menu 0.3 seconds to load, and removes the unwanted items. If it doesn't work well for you, try to raise the timeout from 300 to 500-1000.

On jira 4, run instead:

    AJS.$("#issue-link-link-type option[value*='clon']").remove();



回答2:


The previous solution has an issue: It will only work when clicking the "Link Issue"-Menu-Item. When I use the Point (.)-Shortcut-Menu, it won't remove the issue types.

I have established the following solution:

JS-Binding-Part:

AJS.$(document).ready(function() {
JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function(e, context, reason) {
     hideIssueLinkTypes();
  });
});

JS-Backing-Function:

function hideIssueLinkTypes() {
var apiURL = "/rest/scriptrunner/latest/custom/getHiddenLinkTypes"

  $.getJSON( apiURL, {
  }).done(function( objectData ) {
      $.each( objectData, function( i, item ) {
        var issueLinkType = item.issueLinkType[0];
        AJS.$("#link-type option[value='"+issueLinkType.inwardDescription+"']").remove();
        AJS.$("#link-type option[value='"+issueLinkType.outwardDescription+"']").remove();
      });
    });
}

Scriptrunner-REST-Endpoint:

import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonBuilder
import groovy.transform.BaseScript
import com.atlassian.jira.issue.link.DefaultIssueLinkTypeManager
import com.atlassian.jira.issue.link.IssueLinkTypeManager
import com.atlassian.jira.issue.link.IssueLinkType
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.properties.ApplicationProperties

import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response


@BaseScript CustomEndpointDelegate delegate

String HIDDEN_IDENT="[hidden]"

getHiddenLinkTypes(httpMethod: "GET") { MultivaluedMap queryParams, String body ->   

    def appProperties = ((ApplicationProperties) ComponentAccessor.getComponentOfType(ApplicationProperties.class));
    def appClonersLinkTypeName = appProperties.getDefaultBackedText("jira.clone.linktype.name");

    def jsBuilder=new JsonBuilder();
    def issueLinkTypes = ((IssueLinkTypeManager) ComponentAccessor.getComponentOfType(IssueLinkTypeManager.class)).getIssueLinkTypes();

    jsBuilder issueLinkTypes.findAll({it.getName().contains(HIDDEN_IDENT) || it.getName()==appClonersLinkTypeName }),
    { IssueLinkType linkType ->
        issueLinkType linkType.getId(),
        name: linkType.getName(),
        inwardDescription: linkType.getInward(),
        outwardDescription: linkType.getOutward()
    }

    return Response.ok(jsBuilder.toString()).build();
}

What you can do then ist just annotate and Link-Type with putting [hidden] in the link name and it will disappear for all users (It can still be programmatically added though or created by cloning).

If you don't have Scriptrunner or don't need the dynamic nature of the implementation, you can still hard-code the values as Kuf described in the answer above in hideIssueTypes() like this:

AJS.$("#issue-link-link-type option[value*='clon']").remove();


来源:https://stackoverflow.com/questions/14495618/how-to-hide-some-issue-link-types-in-the-issue-link-pop-up-window-for-jira-5-1-8

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!