Missed Team ’24? Catch up on announcements here.

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

[Gadget] projectOrFilterPicker does not reload config

Hans de Groot
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.
November 11, 2013

I'm working on a gadget that requires a configured project of filter. So I made my gadget configurable and added the projectOrFilterPicker. This works pretty good, except that when I reload an already configured gadget the configured project or filter does not show up. This is what the gadget configuration then looks like:

Instead of the text "No Filter/Project selected" I want the name of the configured project or filter. This is the normal behaviour for ie the "Average Age Chart".

<?xml version="1.0" encoding="UTF-8" ?>
<Module>
    <ModulePrefs title="testtile" directory_title="testtitle"
        description="__MSG_gadget.description__">
        <Optional feature="gadget-directory">
            <Param name="categories">
                JIRA
            </Param>
        </Optional>
        <Optional feature="atlassian.util" />
		<Optional feature="auth-refresh" />
		<Require feature="views" />
		<Require feature="settitle" />
		<Require feature="oauthpopup" />
		<Require feature="setprefs" />
		<Require feature="dynamic-height" />
        #oauth		
		#supportedLocales("gadget.common")
    </ModulePrefs>
	
	<UserPref name="isConfigured" datatype="hidden" default_value="false" />
	<UserPref name="refresh" datatype="hidden" default_value="false" />
	<UserPref name="projectOrFilterId" datatype="hidden" />
	
    <Content type="html" view="profile">
         <![CDATA[
		
		#requireResource("com.atlassian.gadgets.publisher:ajs-gadgets")
        #requireResource("com.atlassian.jira.gadgets:jira-global")
        #requireResource("com.atlassian.jira.gadgets:autocomplete")
		#includeResources()
        <script type="text/javascript">
            (function () {
                var gadget = AJS.Gadget({
                    baseUrl: "__ATLASSIAN_BASE_URL__",
                    useOauth: "/rest/gadget/1.0/currentUser",
					config: {
						descriptor: function(args)
						{
							var gadget = this;
							var searchParam = AJS.gadget.fields.projectOrFilterPicker(gadget,"projectOrFilterId", args.options);
							
							return {
								action: "/rest/gadget/1.0/averageage/validate",								
								fields: [
                                searchParam,   
							    AJS.gadget.fields.nowConfigured()
                            ]
							};
						},
					     args: [
					            {
					                key: "options",
					                ajaxOptions: "/rest/gadget/1.0/filtersAndProjects"
					            }
					     ]   					
					},
                    view: {
						enableReload: true,
						onResizeReload: true,
						template: function(args) {
							var gadget = this;							
                            gadget.getView().html("project:"+gadget.getPref("projectOrFilterId")+"!");
                        }
                    }
                });
            })();
        </script>
        ]]>
    </Content>
 </Module>

What am I missing here? I searched for examples on how to do this, but I cannot find a working one with configuration reload.

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
Hans de Groot
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.
November 11, 2013

I solved it by using the rest api to pass all projects and filters into the gadget and filter there for the value and extract the label. After I found the correct label I set 'this.projectOrFilterName'.

code:

config: {
						descriptor: function(args)
						{
							var gadget = this;
							var searchParam = AJS.gadget.fields.projectOrFilterPicker(gadget,"projectOrFilterId");
							var projectOrFilterId = gadget.getPref("projectOrFilterId");
							this.projectOrFilterName = "";
							for( var i = 0; i &lt; args.options.options.length; i++)
							{
								for( var j = 0; j &lt; args.options.options[i].group.options.length; j++)
								{
									if(args.options.options[i].group.options[j].value == projectOrFilterId )
									{
										this.projectOrFilterName = args.options.options[i].group.options[j].label;
										break;
									}
								}
								if(this.projectOrFilterName != "" )
								{
									break;
								}
							}
							
							return {
								action: "/rest/gadget/1.0/averageage/validate",								
								fields: [
                                searchParam,   
							    AJS.gadget.fields.nowConfigured()
                            ]
							};
						},
					     args: [
					            {
					                key: "options",
					                ajaxOptions: "/rest/gadget/1.0/filtersAndProjects"
					            }
					     ]   					
					}

It works, but it seems like a lot of work something that should just work...

Jayashree Shetty
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 18, 2014

can you please post the complete code? i mean what does this code do?

return{

action: "/rest/gadget/1.0/averageage/validate"
Like Madhuri K likes this
0 votes
uuuu March 12, 2014

I was able to get the filter id using the information mentioned above. How can I get the JQL behind it? can I use this filter in some what with the ajax option of the gadget to filter data?

TAGS
AUG Leaders

Atlassian Community Events