How to dynamically show and hide web-panel depending on particular condition

I have a web panel on issue page that web panel should be display for a particular project (not for all project) which are store in my AO table.

The projet which are present in AO table for that project only i have to show web panel otherwise it will be hide

15 answers

This widget could not be displayed.

This is xml file :

<web-panel name="WorkBreakdownStructure" i18n-name-key="work-breakdown-structure.name" key="work-breakdown-structure" location="atl.jira.view.issue.left.context" weight="100">
    <description key="work-breakdown-structure.description">The WorkBreakdownStructure Plugin</description>
    <label key="work-breakdown-structure.title"/>
    <context-provider class="com.jira.example.web.contextproviders.WBSContextProvider"/>
    <resource name="view" type="velocity" location="templates/webpanels/wbs-indicator.vm"/>
   <condition class="com.jira.example.condition.wbsConfiguration" invert="true" />
  </web-panel>

wbsConfiguration is class file

public class wbsConfiguration extends AbstractIssueCondition {

	private static  ApplicationProperties ap;
	private final ActiveObjects ao;
	WbsGenerator wbsGenerator;
	public wbsConfiguration(ActiveObjects ao, ApplicationProperties ap2)
	{
		this.ao=ao;
	    this.ap=ap2;
	    wbsGenerator = new WbsGenerator(ao,ap2);
	}

	@Override
	public boolean shouldDisplay(User arg0, Issue arg1, JiraHelper arg2) {
		
		boolean flag=false;
		//here u write u r logic for whic project u want to show web panel
		if(res.equals("Y"))
		{
			flag = false;
		}
		else
		{
			flag = true;
		}
		return flag;
	}

}

if flag is false then panel get display

we can also refere cookbook in that search webpanel condition

Thanks Sachin.I too did the same way. But its like i am hardcoding the project name like this


if

(projKey == "nn")

return true;

else

return false;

How can i get rid of this?Its like to whichever project i dont want the web-panel to get displayed i need to check in this class file. Is there a way by which we can avoid this hardcoding.

This widget could not be displayed.

Go to this link : "https://developer.atlassian.com/display/DOCS/Getting+Started+with+Active+Objects"

here you get how to create AO table information please like the answer if it helpful for you

Thank you Sachin . Do we need to get AO installed or does it come part of the JIRA's higher version. Because i read that Active Objects shouldnt be installed in production environment?

This widget could not be displayed.

1.First u have to store projectName in AO table

if its dine then from condition class u have to retrive that data

and check wheather current project is present in that or not

refer jira development cookbook for store , delete and access data from AO table

This widget could not be displayed.

You have to make module for this called webwork

so it will create section in administartion part

in that section you can make GUI and write buisness logic

just search how to create administraion section on net

Something similar to this?

http://www.j-tricks.com/1/post/2012/10/use-of-decorators-on-jira-pages.html

So on a higher level view what i understood is in your atlassian.xml gadget of your gadget you have added another module "webwork". You make the required GUI for it and wrote your business logic to load the projects into it. The logic of this says is written in a logic.java file. This been referred to the context-provider section of your webpanel?

Have in understood correctly? How are you listing out the projects in your GUI? If you dont mind can you post your implementation. I tried using a rest service but its not working.

how to get due date on dashboard? not on project page or issue page

 

This widget could not be displayed.

use this for grtting all project in jira

ProjectManager myProjectManager = new ProjectManager()

public List<Project> getAllProjects() {
return myProjectManager.getProjectObjects();
}

ProjectManager is object you have to inject it constructer

this will return list of project

in vm file you have to call methos and iterate it

#foreach($p in $action.getAllProjects())
<option value="$p.name">$p.name</option>
#end`

This widget could not be displayed.

Have you tried adding the condition to your web-panel. Read here.

Yes but it check for jiras inbuilt condition

i want to check by programmatically

This widget could not be displayed.

<condition class="com.jira.example.condition.wbsConfiguration" invert="true" />

create one class called wbsConfiguration and extend AbstractIssueCondition class

but AbstractIssueCondition is deprecated method is there any method for this

Hi Sachin. I too have the same requirement where i want my web-panel to get displayed for particular project and not all. I checked the web-panel package from here. But i didnt find any suitable condition to add in the atlassian-plugin.xml page. Did youget this resolved?

This widget could not be displayed.

<condition class="com.jira.example.condition.wbsConfiguration" invert="true" />

use this in .xml file in your

wbsConfiguration is a class in that you have to right u r logic

if condition is true the return flase

if condition false then panel get display otherwise it hide

Thanks Sachin, Can you share your code for understanding

as well as the condition part of xml file

This widget could not be displayed.

my question is how u decide for which project you want webpanel.

if you have separate GUI for this then

you can store the project key in AO table for which you want to display webpanel from that GUI

and then check whether selected project key present in AO table or not if not then hide web panel.

so it will be dyanamic

Thanks Sachin. Since i have recently started coding in JIRA i dont have ideahow to create an AO Table. Do you have any links/tutorial which explains this.

Need some help here.

Step 1: I have a plugin created, which is appearing on the jira issue view page

Step 2: Added these dependancies in the pom.xml file

<dependency>
<groupId>com.atlassian.activeobjects</groupId>
<artifactId>activeobjects-plugin</artifactId>
<version>0.20</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.atlassian.sal</groupId>
<artifactId>sal-api</artifactId>
<version>2.4.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.collections</groupId>
<artifactId>google-collections</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
<scope>provided</scope>
</dependency>

and

<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>maven-refapp-plugin</artifactId>
<version>${amps.version}</version>
<extensions>true</extensions>
<configuration>
<pluginArtifacts>
<pluginArtifact>
<groupId>com.atlassian.activeobjects</groupId>
<artifactId>activeobjects-plugin</artifactId>
<version>${ao.version}</version>
</pluginArtifact>
<pluginArtifact>
<groupId>com.atlassian.activeobjects</groupId>
<artifactId>activeobjects-refapp-spi</artifactId>
<version>${ao.version}</version>
</pluginArtifact>
</pluginArtifacts>
<productVersion>${refapp.version}</productVersion>
</configuration>
</plugin>

step 3: added this in atlassian.xml

<ao key="ao-module">
<description>The configuration of the Active Objects service</description>
<entity>com.example.plugins.entity.ProjectEntity</entity>
</ao>

<component-import key="ao" name="Active Objects components" interface="com.atlassian.activeobjects.external.ActiveObjects">
<description>Access to the Active Objects service</description>
</component-import>

step 4: created a package and added an interface named ProjectEntity

package com.example.plugins.entity;
import net.java.ao.Entity;

public interface ProjectEntity extends Entity
{
public String getProjectName();
public void SetProjectName(String Name);
}

step5: Added a class named AOClass

when i import this

<font></font>

import

<font></font> com.atlassian.activeobjects.external.ActiveObjects;

i get namespace not resolved.

i am stuck here, how can i proceed further

This widget could not be displayed.
import net.java.ao.Entity;
import net.java.ao.Preload;

@Preload
public interface name extends Entity{

    String getColumnData();
    void setColumnData(String columnData);   
   
}

write entity file like this

Thanks did that. But why is Preload required?

Thanks did that. But why is Preload required? Seems like the resolve error of active object namespace resolved too by doing atlas clean

This widget could not be displayed.

This is my atlassian-plugin.xml

<component-import key="applicationProperties" interface="com.atlassian.sal.api.ApplicationProperties"/>

<web-panel name="DueDateIndicator" i18n-name-key="due-date-indicator.name" key="due-date-indicator"

location="atl.jira.view.issue.right.context" weight="1000">

<description key="due-date-indicator.description">The DueDateIndicator Plugin</description>

<context-provider class="com.example.plugins.tutorial.DueDateIndicator"/>

<resource name="view" type="velocity" location="due-date-indicator.vm"/>

<condition class="com.example.plugins.entity.Enabledprojects"></condition>

<label key="due-date-indicator.title"/>

</web-panel>

My webpanel is DueDateIndicator

I have created a project entity class to get and set the project list as follows

package com.example.plugins.entity;

import net.java.ao.Entity;

import net.java.ao.Preload;

@Preload

public interface ProjectEntity extends Entity

{

public String getProjectName();

public void SetProjectName(String Name);

}

My condition class is Enabledprojects

package com.example.plugins.entity;
import com.atlassian.activeobjects.external.ActiveObjects;
public class Enabledprojects
{
private final ActiveObjects ao;
public Enabledprojects(ActiveObjects ao)
{
this.ao = ao;
}
}
Now how do i proceed to get the list of projects which i have created in JIRA and how can i store this in active objects
This widget could not be displayed.

I did refer the cookbook howeveer have some doubts. Can you share how have you stored the projectnames in AO table? Do you do this in Entity interface?

What i have done is i have an entity class "ProjectEntity " and i have getter and setter for ProjectName and ProjectId.

Now i have a class called "Enabledprojects". According to the book what i understood is that we need to add all the projects to the project entity and use the activeobject to get the projects. In case if i have some 40 projects then i need to add one by one to this list?? is there any other way to do this? Can i have all the project list stored in one xml file and load the data from this xml file?

This widget could not be displayed.

For example, we need to store the name, city and country as part of the address
entity. In this case, the AddressEntity interface will look like the following:
public interface AddressEntity extends Entity{
public String getName();
public void setName(String name);
public String getState();
public void setState(String state);
public String getCountry();
public void setCountry(String country);
}

By doing this, we have setup the entity to facilitate the storage of all the three attributes.
We can now create, modify, or delete the data using the ActiveObjects component.
The component can be instantiated by injecting it into the constructor.


private ActiveObjects ao;
public ManageProperties(ActiveObjects ao) {
this.ao = ao;
}


A new row can be added to the database using the following piece of code:


AddressEntity addressEntity = ao.create(AddressEntity.class);
addressEntity.setName(name);
addressEntity.setState(state);
addressEntity.setCountry(country);
addressEntity.save();


Details can be read either using the id, which is the primary key, or by querying the data
using a net.java.ao.Query object. Using ID is as simple as is shown next:


AddressEntity addressEntity = ao.get(AddressEntity.class, id);

The Query object can be used as follows:
AddressEntity[] addressEntities = ao.find(AddressEntity.class, Query.
select().where("name = ?", name));
for (AddressEntity addressEntity : addressEntities) {
System.out.println("Name:"+addressEntity.getName()+",
State:"+addressEntity.getState()+", Country:"+addressEntity.
getCountry());
}
Here, we are querying for all records with a given name.
Once you get hold of an entity by either means, we can edit the contents simply by using the
setter method:
addressEntity.setState(newState);
addressEntity.save();
Deleting is even simpler!
ao.delete(addressEntity);
Hopefully, that gives a fair introduction to active objects.

thanks i did read this from cookbook as suggested by you. I just have a small doubt. If we use the internal db HSQL which would contain the list of projects in it then i guess we need to use only the select query to retrieve all the projects rgt?we need not use create/delete when its just retreiving records. Am i right?

This widget could not be displayed.

yes i just give you that for feature use

Hi Sachin.

Could you please share your code for the hiding and displaying of web-panel. I was doing some other dev so cudnt try this. But now i need to implement this and somethings are not working. Can you please share you code for this so that i can relate to what i am doing. I am still not clear about implementing the active objects.

Did you create a separate GUI for your project lists? Could you explain your code.

thanks

This widget could not be displayed.

just refer my first answer

in that u have to make change in xml file add this in web panel

<condition class="com.jira.example.condition.wbsConfiguration" invert="true" />

create wbsConfiguration class in that write u r buissness ligic

for project list i have create seperate GUI with that user can select project

This GUI is another gadget i suppose? Is this configured in dashboard? How do these gadgets talk with each other?

I mean i thought that the GUI you are talking about is another gdaget which is added to a dashboard and the user can select the projects which will generate an o/p of xml file with selected project lists and this would be then fed as an input to the gadget in issue view page. Then we have a condition to check if the current project is among the list of selected projects, if yes then display the gadget which is in the issue view page else hide it.

How have you implemented this ?

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Aug 06, 2018 in Jira Service Desk

A is for Activate: Share your top Jira Service Desk onboarding tips for new users!

Hi, everyone! Molly here from the Jira Service Desk Product Marketing Team :).  In the spirit of this month's  august-challenge, we're sourcing stories of Jira Service Desk activation fro...

536 views 23 15
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you