Am 21.12.2016 um 01:24 schrieb PF66 <pedrodi...@gmail.com>:I'm creating a dashboard plugin on Jenkins where I want to show just some of my views and their content inside it.
For that, I pretend to create a list of check boxes similar to the 'View' configuration page, where you can select which Jobs to include (like the folowing):
I'm fairly new to jelly and Jenkins itself, so it's being a trouble to find the solution.
What I'm trying to do is:
- Create a
Map<K, V>in my Dashboard where I want to populate with all the Views of my Jenkins instance and being 'false' as default.Constructor:
private Map<String, Boolean> selectedViews;public MyDashboard(String name, String viewName) { super(name); //more variables inside this.selectedViews.putAll(initSelectedViews()); } protected Object readResolve() { //more variables inside if (selectedViews == null || selectedViews.isEmpty()){ this.selectedViews.putAll(initSelectedViews()); }
And the initializing function
public Map<String, Boolean> initSelectedViews(){ Map<String,Boolean> selectedViews = new HashMap<>(); for (View v: Jenkins.getInstance().getViews()) { //Debugged here, never happens a single iteration. //Maybe getViews() returns 'null' while creating the plugin? selectedViews.put(v.getViewName(), false); } return selectedViews; }
The problem is that in other functions, where I want to iterate through views,
Jenkins.getInstance().getViews()works just fine. But when I try to initialize this Map, I always get an empty array.Should I use other methods to get the Views? Or save them in a different variable?
On the configure-entries.jelly I want to save in the
selectedViewsMap which are those selected, and so far I have:<f:section title="${%Views Filter}"> <f:entry title="Views: ${it.selectedViews}"/> <f:entry title="${%Select views to display}"> <j:forEach var="view" items="${it.selectedViews}"> <span> <f:checkbox name="${it.selectedViews.view}" title="${view.key}" checked="${view.value}" json="true"/> <br/> </span> </j:forEach> </f:entry>Where they display correctly both 'Name' and 'Value' because I already tried with an hardcoded Map, but can't manage to save them properly.
An alternative I was also trying, was to push every value of selected checkboxes to an Array, that will then pass to the backend, as you can see in the following code. But don't know how to pass the array variable with each name of the selections:
Introduzir código aqui...<f:section title="${%Views Filter}"><f:entry title="${%Select views to display:}">
<script type="text/javascript">
var array;
if('${it.selectedViews.isEmpty()}'){
array = new Array();
}else{
array = new Array('${it.selectedViews}');
}
function selectView(name){
var i = array.indexOf(name);
if(i == -1){
array.push(name);
}else{
array.splice(i, 1);
}
array.sort(); //This is the array I want to pass when I click 'Apply'
}
</script>
<j:forEach var="view" items="${it.views}">
<span class="selectedBox">
<f:checkbox title="${view.displayName}" value="${view.displayName}" checked="${it.selectedViews.contains(view.displayName)}" onclick="selectView(this.value)"/>
<br/>
</span>
</j:forEach>
</f:entry>
</f:section>
Any help or suggestion is appreciated.
--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/37dadad8-e25e-446e-96c0-8dce89296b20%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/68f845a0-94de-4c6e-a540-15567e4b1389%40googlegroups.com.
<j:forEach var="view" items="${it.views}">
<span class="selectedBox">
<f:checkbox title="${view.displayName}" value="${view.displayName}" checked="${it.selectedViews.contains(view.displayName)}" onclick="selectView(this.value)"/>
<br/>
</span>
</j:forEach>