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.
Community moderators have prevented the ability to post new answers.
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 < args.options.options.length; i++) { for( var j = 0; j < 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...
can you please post the complete code? i mean what does this code do?
return
{
action:
"/rest/gadget/1.0/averageage/validate"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.