2 * Basic IView implementation for displaying the test results list, by collection.
4 * This component creates a Table object and feed it with the results. It adds a collection chooser to its viewPane header.
6 * It creates the following commands : "loadtestlist", "polllistloading", "opentest", "download", "copytocollection", "deletetest".
8 qx
.Class
.define("org.argeo.slc.web.TestList",
10 extend
: qx
.ui
.container
.Composite
,
11 implement
: [org
.argeo
.ria
.components
.IView
],
13 construct : function(){
14 this.base(arguments
, new qx
.ui
.layout
.VBox());
15 var model
= new qx
.ui
.table
.model
.Simple();
16 model
.setColumns(["Test Case", "Date"]);
17 this.table
= new qx
.ui
.table
.Table(model
, {
18 tableColumnModel: function(obj
){
19 return new qx
.ui
.table
.columnmodel
.Resize(obj
)
27 * The viewPane containing this applet.
33 * The load list of available collection (Map of ids => labels)
40 * The current collection id selected.
43 init
: 'My Collection',
47 * The applet commands.
52 label
: "Load Collection",
53 icon
: "resource/slc/view-refresh.png",
54 shortcut
: "Control+l",
57 toolbar
: "collection",
58 callback : function(e
){
65 icon
: "resource/slc/document-open-recent.png",
66 shortcut
: "Control+l",
70 toolbar
: "collection",
71 callback : function(event
){
72 this.pollListLoading(event
.getTarget().getUserData("slc.command.toggleState"));
77 "copyfullcollection" : {
79 icon : "resource/slc/edit-copy.png",
83 toolbar : "collection",
84 callback : function(e){
85 // Call service to copy
88 submenuCallback : function(commandId){
89 this.copySelectionToCollection(commandId, "current_collection");
92 // Call at command creation
93 org.argeo.ria.remote.RequestManager.getInstance().addListener("reload", function(event){
94 if(event.getDataType() == "collection" || event.getDataType() == "test_cases"){
95 var testList = org.argeo.ria.components.ViewsManager.getInstance().getViewPaneById("list").getContent();
96 testList.collectionListToMenu(this);
105 icon
: "resource/slc/media-playback-start.png",
106 shortcut
: "Control+o",
109 toolbar
: "selection",
110 callback : function(e
){
111 var viewsManager
= org
.argeo
.ria
.components
.ViewsManager
.getInstance();
112 var classObj
= org
.argeo
.slc
.ria
.Applet
;
113 var iView
= viewsManager
.initIViewClass(classObj
, "applet");
114 var xmlNodes
= viewsManager
.getViewPaneSelection("list").getNodes();
115 iView
.load(xmlNodes
[0]);
117 selectionChange : function(viewId
, xmlNodes
){
118 if(viewId
!= "list") return;
119 this.setEnabled(false);
120 if(xmlNodes
== null || !xmlNodes
.length
) return;
121 this.setEnabled(true);
126 label
: "Download as...",
127 icon
: "resource/slc/go-down.png",
131 toolbar
: "selection",
132 callback : function(e
){ },
135 {'label':"Xsl", 'icon':'resource/slc/mime-xsl.png', 'commandId':'xsl'},
136 {'label':"Xml", 'icon':'resource/slc/mime-xml.png', 'commandId':'xml'},
137 {'label':"Excel", 'icon':'resource/slc/mime-xls.png', 'commandId':'xls'},
138 {'label':"Pdf", 'icon':'resource/slc/mime-pdf.png', 'commandId':'pdf'}
140 submenuCallback : function(commandId
){
141 var uuid
= this.extractTestUuid();
143 xsl
: "resultView.xslt",
144 xml
: "resultViewXml.xslt",
145 xls
: "resultView.xls",
146 pdf
: "resultView.pdf"
148 var url
= "../"+urls
[commandId
]+"?uuid="+uuid
;
149 if(commandId
== "xls" || commandId
== "pdf"){
150 document
.location
.href
= url
;
152 var win
= window
.open(url
);
155 selectionChange : function(viewId
, xmlNodes
){
156 if(viewId
!="list")return;
158 this.setEnabled(false);
159 if(xmlNodes
== null || !xmlNodes
.length
) return;
160 this.setEnabled(true);
163 "copytocollection" : {
164 label
: "Copy to...",
165 icon
: "resource/slc/edit-copy.png",
166 shortcut
: "Control+c",
169 toolbar
: "selection",
170 callback : function(e
){
171 // Call service to copy
174 submenuCallback : function(commandId
){
175 this.copySelectionToCollection(commandId
, "current_selection");
178 // Call at command creation
179 org
.argeo
.ria
.remote
.RequestManager
.getInstance().addListener("reload", function(event
){
180 if(event
.getDataType() == "collection" || event
.getDataType() == "test_cases"){
181 var testList
= org
.argeo
.ria
.components
.ViewsManager
.getInstance().getViewPaneById("list").getContent();
182 testList
.collectionListToMenu(this, true);
186 selectionChange : function(viewId
, xmlNodes
){
187 if(viewId
!= "list") return;
188 this.setEnabled(false);
189 if(xmlNodes
== null || !xmlNodes
.length
) return;
190 this.setEnabled(true);
196 icon
: "resource/slc/edit-delete.png",
197 shortcut
: "Control+d",
200 toolbar
: "selection",
201 callback : function(e
){
203 var request
= org
.argeo
.slc
.ria
.SlcApi
.getRemoveResultService(this.getCollectionId(), this.extractTestUuid());
204 request
.addListener("completed", function(response
){
205 this.loadCollections();
207 this.info("Test was successfully deleted");
211 selectionChange : function(viewId
, xmlNodes
){
212 if(viewId
!= "list") return;
213 this.setEnabled(false);
214 if(xmlNodes
== null || !xmlNodes
.length
) return;
215 this.setEnabled(true);
224 init : function(viewPane
){
225 this.setView(viewPane
);
227 load : function(data
){
229 statusBarVisible
: false,
230 showCellFocusIndicator
:false,
231 columnVisibilityButtonVisible
:false,
232 contextMenu
: org
.argeo
.ria
.event
.CommandsManager
.getInstance().createMenuFromIds(["opentest", "download", "copytocollection", "deletetest"]),
233 decorator
: new qx
.ui
.decoration
.Background("#fff")
235 var viewPane
= this.getView();
236 this.table
.addListener("dblclick", function(e
){
237 org
.argeo
.ria
.event
.CommandsManager
.getInstance().executeCommand("opentest");
239 var columnModel
= this.table
.getTableColumnModel();
240 columnModel
.getBehavior().setWidth(0, "60%");
241 var renderer
= new org
.argeo
.slc
.web
.XmlRenderer();
242 columnModel
.setDataCellRenderer(0, renderer
);
243 columnModel
.setDataCellRenderer(1, renderer
);
245 this.table
.getSelectionManager().getSelectionModel().addListener("changeSelection", function(e
){
246 var viewSelection
= viewPane
.getViewSelection();
247 viewSelection
.clear();
248 var selectionModel
= this.table
.getSelectionManager().getSelectionModel();
249 if(!selectionModel
.getSelectedCount()){
252 var ranges
= this.table
.getSelectionManager().getSelectionModel().getSelectedRanges();
253 var xmlNode
= this.table
.getTableModel().getRowData(ranges
[0].minIndex
);
254 viewSelection
.addNode(xmlNode
);
255 viewPane
.setViewSelection(viewSelection
);
258 var select
= new qx
.ui
.form
.SelectBox();
259 this.getView().addHeaderComponent(select
);
260 this.getView().setViewTitle("");
261 this.add(this.table
, {flex
:1});
263 select
.addListener("changeValue", this.collectionSelectorListener
, this);
265 org
.argeo
.ria
.remote
.RequestManager
.getInstance().addListener("reload", function(event
){
266 if(event
.getDataType()!="collection") return;
267 select
.removeListener("changeValue", this.collectionSelectorListener
, this);
268 var collectionList
= event
.getContent();
270 for(key
in collectionList
){
271 var item
= new qx
.ui
.form
.ListItem(collectionList
[key
], "resource/slc/folder.png", key
);
273 if(key
== this.getCollectionId()){
274 select
.setSelected(item
);
277 this.setCollectionId(select
.getSelected().getValue());
278 select
.addListener("changeValue", this.collectionSelectorListener
, this);
284 * Use SlcApi to load the available collections.
286 loadCollections : function(){
287 var request
= org
.argeo
.slc
.ria
.SlcApi
.getListCollectionsService();
288 var NSMap
= {slc
:"http://argeo.org/projects/slc/schemas"};
289 request
.addListener("completed", function(response
){
290 var xml
= response
.getContent();
291 var collections
= {};
292 var nodes
= org
.argeo
.ria
.util
.Element
.selectNodes(xml
, "//slc:ref", NSMap
);
293 for(var i
=0;i
<nodes
.length
;i
++){
294 var collId
= qx
.xml
.Element
.getSingleNodeText(nodes
[i
], ".");
295 collections
[collId
] = collId
;
297 this.setCollectionList(collections
);
298 org
.argeo
.ria
.remote
.RequestManager
.getInstance().fireReloadEvent("collection", this.getCollectionList());
300 request
.setAsynchronous(false);
305 * Load the results of the currently selected collection.
307 loadList : function(){
308 var model
= this.table
.getTableModel();
309 model
.removeRows(0, model
.getRowCount());
310 var commandManager
= org
.argeo
.ria
.event
.CommandsManager
.getInstance();
311 var request
= org
.argeo
.slc
.ria
.SlcApi
.getListResultsService(this.getCollectionId(), null, [commandManager
.getCommandById("loadtestlist"), this.getView()]);
312 var NSMap
= {slc
:"http://argeo.org/projects/slc/schemas"};
313 request
.addListener("completed", function(response
){
314 var xml
= response
.getContent();
315 this.debug("Successfully loaded XML");
316 var nodes
= org
.argeo
.ria
.util
.Element
.selectNodes(xml
, "//slc:result-attributes", NSMap
);
317 //model.addRows(nodes);
319 for(var i
=0; i
<nodes
.length
;i
++){
320 model
.addRows([nodes
[i
]]);
327 * Enable/disable the automatic reloading of the list.
328 * @param state {Boolean} Whether the automatic reloading must be started or stopped.
330 pollListLoading : function(state
){
332 this.timer
= new qx
.event
.Timer(5000);
333 this.timer
.addListener("interval", this.loadList
, this);
344 * Creates a menu gui component from the currently loaded collectionList.
345 * @param command {qx.event.Command} The command on which to attach the created menu.
346 * @param checkSelection {Boolean} Whether at the end, we must check the current viewSelection to enable/disable the command accordingly.
348 collectionListToMenu : function(command
, checkSelection
){
349 command
.setEnabled(false);
350 command
.clearMenus();
351 var collectionList
= this.getCollectionList();
352 if(!collectionList
) return;
354 for(var key
in collectionList
){
355 if(this.getCollectionId() && key
== this.getCollectionId()) continue;
357 "label":collectionList
[key
],
358 "icon":"resource/slc/folder.png",
362 submenus
.push({'separator':true});
363 submenus
.push({"label":"New...", "icon":"resource/slc/folder-new.png", "commandId":"slc.client.create"});
364 command
.setMenu(submenus
);
366 var viewSelection
= this.getView().getViewSelection();
367 if(viewSelection
.getCount()) command
.setEnabled(true);
369 command
.setEnabled(true);
373 * Use SlcApi "addResult" service to add selected results to a given collection.
374 * If collectionId is "slc.client.create", first triggers a modal dialog to enter a new collection name, then retrigger itself with the new id.
375 * @param collectionId {String} The id of the destination collection, or "slc.client.create".
376 * @param selectionType {String} "current_collection"|"current_selection". The first adds the whole collection content to the destination, the second only selected results.
378 copySelectionToCollection:function(collectionId
, selectionType
){
379 if(collectionId
== "slc.client.create"){
380 var modal
= new org
.argeo
.ria
.components
.Modal("Create collection", "resource/slc/folder-new.png");
381 modal
.makePromptForm("Enter the new collection name", function(value
){
383 alert("Please enter a name for the new collection!");
387 // Create the collection now, then recall the callback with the new name.
388 this.copySelectionToCollection(value
, selectionType
);
392 modal
.attachAndShow();
396 if(selectionType
== "current_collection"){
397 this.error("Not implemented yet!");
398 }else if(selectionType
== "current_selection"){
400 var request
= org
.argeo
.slc
.ria
.SlcApi
.getAddResultService(collectionId
,this.extractTestUuid());
401 request
.addListener("completed", function(response
){
402 this.info("Result successfully copied to collection!");
403 this.loadCollections();
410 * Utilitary function to extract test unique id from the currently selected node.
411 * @return {String} The test unique id.
413 extractTestUuid: function(){
414 var NSMap
= {slc
:"http://argeo.org/projects/slc/schemas"};
415 var xmlNodes
= this.getView().getViewSelection().getNodes();
416 var uuid
= qx
.dom
.Node
.getText(org
.argeo
.ria
.util
.Element
.selectSingleNode(xmlNodes
[0], "slc:uuid"));
421 * Listener of the collection selector (select box added to the viewpane header).
422 * @param event {qx.event.type.Event} The event.
424 collectionSelectorListener : function(event
){
425 this.setCollectionId(event
.getData());
429 addScroll : function(){
435 this.pollListLoading(false);