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

I want to develop a gadget which will list all projects in JIRA via a REST call.

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.
March 20, 2014

I am looking at the code for my gadget.xml file which will list out all the projects present in the db via a rest call and gets listed out in a multiselect listbox. user can select the projects of his choice and then save his change.

I have wriiten something down although its not complete. Is this right? What should i write in the view section of module? Can anyone post their implementation for this approach.

<?xml version="1.0" encoding="UTF-8" ?>
<Module>
<ModulePrefs 
title="__MSG_gadget.title__" 
directory_title="__MSG_gadget.title__"   
description="__MSG_gadget.description__">

 <Require feature="views" />
 <Require feature="settitle"/>
 <Require feature="oauthpopup" />
 
<Optional feature="gadget-directory">
<Param name="categories">
 JIRA  
</Param> 
</Optional>

 <Optional feature="atlassian.util" />
 <Optional feature="auth-refresh" />

 #oauth
 
 <Locale messages="__ATLASSIAN_BASE_URL__/download/resources/jira-gadget-tutorial-plugin/i18n/ALL_ALL.xml"/>
 
 </ModulePrefs>
 <UserPref name="isConfigured" datatype="hidden" default_value="false"/>
 <Content type="html">
 <![CDATA[
 #requireResource("com.atlassian.gadgets.publisher:ajs-gadgets")
 
 <script type="text/javascript">
 (function () 
   {
            var gadget = AJS.Gadget({
				baseUrl: "__ATLASSIAN_BASE_URL__",
				useOauth: "__ATLASSIAN_BASE_URL__/rest/api/2/myself",				
	config: {				 
				 descriptor: function(args)
				 {
				    var gadget = this;				    
				    gadgets.window.setTitle("Choose the projects");
				    
				    var projectpicker = AJS.gadget.fields.projectPicker(gadget,"projectId",args.projects);				    
				    return {
                             fields: [
                                      projectpicker,
                                      {
	                                	userpref: "selectedprojects",
	                                    label: "Projects",
	                                    description: Projects",
	                                    type: "multiselect",
	                                    selected: gadget.getPref("selectedprojects"),                                         
                                       },
                                        AJS.gadget.fields.nowConfigured()
                                     ]
                           };
                 },
           
				 args: function()
				   {     
				      return [
				        {
				           key: "projects",
				           ajaxOptions:  "/rest/baseline-gadget/1.0/baselinecomparison/getBaselines.json"			     
				        }
				     
				            ];
				   }()
            },
            
            view: {
					enableReload: true,
                    onResizeReload: true,
         		    template: function(args) {
         		    var gadget = this;
 
 ]]></Content>
 </Module> 

2 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Onkar Ahire
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.
March 20, 2014

Why don't you try multi select list,

You can learn from

https://docs.atlassian.com/aui/latest/sandbox/#

Please try, I didn't try before but I guess,

    <label for="project">Projects</label>
            <select class="multi-select" size="4" multiple="multiple" id="project" name="project">
#foreach($data in getAllProjects()) <option>$data</option> #end </select>

Cheers.

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.
April 10, 2014

Hi Onkar if you dont mind can you please provide the complete implementation for the project listing. I have tried out some simple example on rest based exmaple as given in the book and jtricks by jobin but each time i get some exception.

i have described it here https://answers.atlassian.com/questions/282117/anyone-tried-the-simple-jira-gadget-implementation

So could you please post the entire implementation for this project listing. i would want to have a look into the atlassian.xml, pom.xml and the gadget.xml files. Would highly appreciate your help.

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 7, 2014

Hi Onkar, the project snippet which you pasted here isnt working. i get some error.

This page contains the following errors:

error on line 1 at column 551: Opening and ending tag mismatch: link line 0 and head

Below is a rendering of the page up to the first error.

1 vote
Onkar Ahire
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.
March 20, 2014

Hi Jayashri,

please try below code,

function getAllProjects()

	{  

		var allProjects;

		

		AJS.$.ajax({	  

	    	baseUrl: "__ATLASSIAN_BASE_URL__",

	        url: AJS.params.baseURL+"/jira/rest/api/2/project",

	        type: "get",             

	        dataType: 'json',

	        async: false, 

	        success: function(data) 

	        {

	        	allProjects = data.value;

	        }

	     });

	     return allProjects;

	}

Regards

Onkar ahire

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.
March 20, 2014

Thnaks Onkar. This i will write it in <![CDATA[ ] right? Or this would go into the .view section of CDATA[]?Also this would probably display list of projects. I need the user to select multiple projects from the list. How can i achieve that?



TAGS
AUG Leaders

Atlassian Community Events