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.
34 check
:"org.argeo.ria.components.ViewSelection"
36 instanceId
: {init
:""},
37 instanceLabel
: {init
:""},
39 * The load list of available collection (Map of ids => labels)
46 * The current collection id selected.
49 init
: 'My Collection',
53 * The applet commands.
58 label
: "Load Collection",
59 icon
: "resource/slc/view-refresh.png",
60 shortcut
: "Control+l",
63 toolbar
: "collection",
64 callback : function(e
){
71 icon
: "resource/slc/document-open-recent.png",
72 shortcut
: "Control+l",
76 toolbar
: "collection",
77 callback : function(event
){
78 this.pollListLoading(event
.getTarget().getUserData("slc.command.toggleState"));
83 "copyfullcollection" : {
85 icon : "resource/slc/edit-copy.png",
89 toolbar : "collection",
90 callback : function(e){
91 // Call service to copy
94 submenuCallback : function(commandId){
95 this.copySelectionToCollection(commandId, "current_collection");
98 // Call at command creation
99 org.argeo.ria.remote.RequestManager.getInstance().addListener("reload", function(event){
100 if(event.getDataType() == "collection" || event.getDataType() == "test_cases"){
101 var testList = org.argeo.ria.components.ViewsManager.getInstance().getViewPaneById("list").getContent();
102 testList.collectionListToMenu(this);
111 icon
: "resource/slc/media-playback-start.png",
112 shortcut
: "Control+o",
115 toolbar
: "selection",
116 callback : function(e
){
117 var viewsManager
= org
.argeo
.ria
.components
.ViewsManager
.getInstance();
118 var classObj
= org
.argeo
.slc
.ria
.Applet
;
119 var xmlNodes
= viewsManager
.getViewPaneSelection("list").getNodes();
120 var iView
= viewsManager
.initIViewClass(classObj
, "applet", xmlNodes
[0]);
121 iView
.load(xmlNodes
[0]);
123 selectionChange : function(viewId
, xmlNodes
){
124 if(viewId
!= "list") return;
125 this.setEnabled(false);
126 if(xmlNodes
== null || !xmlNodes
.length
) return;
127 this.setEnabled(true);
132 label
: "Download as...",
133 icon
: "resource/slc/go-down.png",
137 toolbar
: "selection",
138 callback : function(e
){ },
141 {'label':"Xsl", 'icon':'resource/slc/mime-xsl.png', 'commandId':'xsl'},
142 {'label':"Xml", 'icon':'resource/slc/mime-xml.png', 'commandId':'xml'},
143 {'label':"Excel", 'icon':'resource/slc/mime-xls.png', 'commandId':'xls'},
144 {'label':"Pdf", 'icon':'resource/slc/mime-pdf.png', 'commandId':'pdf'}
146 submenuCallback : function(commandId
){
147 var uuid
= this.extractTestUuid();
149 xsl
: "resultView.xslt",
150 xml
: "resultViewXml.xslt",
151 xls
: "resultView.xls",
152 pdf
: "resultView.pdf"
154 var url
= "../"+urls
[commandId
]+"?uuid="+uuid
;
155 if(commandId
== "xls" || commandId
== "pdf"){
156 document
.location
.href
= url
;
158 var win
= window
.open(url
);
161 selectionChange : function(viewId
, xmlNodes
){
162 if(viewId
!="list")return;
164 this.setEnabled(false);
165 if(xmlNodes
== null || !xmlNodes
.length
) return;
166 this.setEnabled(true);
170 label
: "Attachments",
171 icon
: "resource/slc/document-save-as.png",
175 toolbar
: "selection",
176 callback : function(e
){ },
179 submenuCallback : function(commandId
){
180 var split
= commandId
.split("__commandseparator__");
182 var contentType
= split
[1];
184 var url
= org
.argeo
.slc
.ria
.SlcApi
.buildGetAttachmentUrl(uuid
, contentType
, name
);
185 var win
= window
.open(url
);
187 selectionChange : function(viewId
, xmlNodes
){
188 if(viewId
!="list")return;
190 this.setEnabled(false);
191 if(xmlNodes
== null || !xmlNodes
.length
|| xmlNodes
.length
!= 1) return;
192 // Check slc:simple-attachment tags
193 var attachs
= org
.argeo
.ria
.util
.Element
.selectNodes(xmlNodes
[0], "slc:attachments/slc:simple-attachment");
194 if(attachs
&& attachs
.length
){
196 for(var i
=0;i
<attachs
.length
;i
++){
197 var uuid
= org
.argeo
.ria
.util
.Element
.getSingleNodeText(attachs
[i
], "slc:uuid");
198 var contentType
= (org
.argeo
.ria
.util
.Element
.getSingleNodeText(attachs
[i
], "slc:content-type")||'');
199 var name
= org
.argeo
.ria
.util
.Element
.getSingleNodeText(attachs
[i
], "slc:name");
202 icon
: 'resource/slc/mime-text-plain.png',
203 commandId
:uuid
+'__commandseparator__'+contentType
+'__commandseparator__'+name
206 this.setMenu(submenus
);
207 this.setEnabled(true);
211 "copytocollection" : {
212 label
: "Copy to...",
213 icon
: "resource/slc/edit-copy.png",
214 shortcut
: "Control+c",
217 toolbar
: "selection",
218 callback : function(e
){
219 // Call service to copy
222 submenuCallback : function(commandId
){
223 this.copySelectionToCollection(commandId
, "current_selection");
226 // Call at command creation
227 org
.argeo
.ria
.remote
.RequestManager
.getInstance().addListener("reload", function(event
){
228 if(event
.getDataType() == "collection" || event
.getDataType() == "test_cases"){
229 var testList
= org
.argeo
.ria
.components
.ViewsManager
.getInstance().getViewPaneById("list").getContent();
230 testList
.collectionListToMenu(this, true);
234 selectionChange : function(viewId
, xmlNodes
){
235 if(viewId
!= "list") return;
236 this.setEnabled(false);
237 if(xmlNodes
== null || !xmlNodes
.length
) return;
238 this.setEnabled(true);
244 icon
: "resource/slc/edit-delete.png",
245 shortcut
: "Control+d",
248 toolbar
: "selection",
249 callback : function(e
){
250 var modal
= new org
.argeo
.ria
.components
.Modal("Confirm", null);
251 modal
.addConfirm("Are you sure you want to delete<br> test " + this.extractTestUuid() + "?");
252 modal
.addListener("ok", function(){
253 var request
= org
.argeo
.slc
.ria
.SlcApi
.getRemoveResultService(this.getCollectionId(), this.extractTestUuid());
254 request
.addListener("completed", function(response
){
255 this.loadCollections();
257 this.info("Test was successfully deleted");
261 modal
.attachAndShow();
263 selectionChange : function(viewId
, xmlNodes
){
264 if(viewId
!= "list") return;
265 this.setEnabled(false);
266 if(xmlNodes
== null || !xmlNodes
.length
) return;
267 this.setEnabled(true);
276 init : function(viewPane
, data
){
277 this.setView(viewPane
);
278 this.setViewSelection(new org
.argeo
.ria
.components
.ViewSelection(viewPane
.getViewId()));
282 statusBarVisible
: false,
283 showCellFocusIndicator
:false,
284 columnVisibilityButtonVisible
:false,
285 contextMenu
: org
.argeo
.ria
.event
.CommandsManager
.getInstance().createMenuFromIds(["opentest", "download", "copytocollection", "deletetest"]),
286 decorator
: new qx
.ui
.decoration
.Background("#fff")
288 var viewPane
= this.getView();
289 this.table
.addListener("dblclick", function(e
){
290 org
.argeo
.ria
.event
.CommandsManager
.getInstance().executeCommand("opentest");
292 var columnModel
= this.table
.getTableColumnModel();
293 columnModel
.getBehavior().setWidth(0, "60%");
294 var renderer
= new org
.argeo
.slc
.web
.XmlRenderer();
295 columnModel
.setDataCellRenderer(0, renderer
);
296 columnModel
.setDataCellRenderer(1, renderer
);
298 this.table
.getSelectionManager().getSelectionModel().addListener("changeSelection", function(e
){
299 var viewSelection
= this.getViewSelection();
300 viewSelection
.clear();
301 var selectionModel
= this.table
.getSelectionManager().getSelectionModel();
302 if(!selectionModel
.getSelectedCount()){
305 var ranges
= this.table
.getSelectionManager().getSelectionModel().getSelectedRanges();
306 var xmlNode
= this.table
.getTableModel().getRowData(ranges
[0].minIndex
);
307 viewSelection
.addNode(xmlNode
);
308 //viewPane.setViewSelection(viewSelection);
311 var select
= new qx
.ui
.form
.SelectBox();
312 this.getView().addHeaderComponent(select
);
313 this.getView().setViewTitle("");
314 this.add(this.table
, {flex
:1});
316 select
.addListener("changeValue", this.collectionSelectorListener
, this);
318 org
.argeo
.ria
.remote
.RequestManager
.getInstance().addListener("reload", function(event
){
319 if(event
.getDataType()!="collection") return;
320 select
.removeListener("changeValue", this.collectionSelectorListener
, this);
321 var collectionList
= event
.getContent();
323 for(key
in collectionList
){
324 var item
= new qx
.ui
.form
.ListItem(collectionList
[key
], "resource/slc/folder.png", key
);
326 if(key
== this.getCollectionId()){
327 select
.setSelected(item
);
330 if(qx
.lang
.Object
.getLength(collectionList
)){
331 this.setCollectionId(select
.getSelected().getValue());
333 select
.addListener("changeValue", this.collectionSelectorListener
, this);
339 * Use SlcApi to load the available collections.
341 loadCollections : function(){
342 var request
= org
.argeo
.slc
.ria
.SlcApi
.getListCollectionsService();
343 var NSMap
= {slc
:"http://argeo.org/projects/slc/schemas"};
344 request
.addListener("completed", function(response
){
345 var xml
= response
.getContent();
346 var collections
= {};
347 var nodes
= org
.argeo
.ria
.util
.Element
.selectNodes(xml
, "//slc:ref", NSMap
);
348 for(var i
=0;i
<nodes
.length
;i
++){
349 var collId
= qx
.xml
.Element
.getSingleNodeText(nodes
[i
], ".");
350 collections
[collId
] = collId
;
352 this.setCollectionList(collections
);
353 org
.argeo
.ria
.remote
.RequestManager
.getInstance().fireReloadEvent("collection", this.getCollectionList());
355 request
.setAsynchronous(false);
360 * Load the results of the currently selected collection.
362 loadList : function(){
363 var model
= this.table
.getTableModel();
364 model
.removeRows(0, model
.getRowCount());
365 var commandManager
= org
.argeo
.ria
.event
.CommandsManager
.getInstance();
366 var request
= org
.argeo
.slc
.ria
.SlcApi
.getListResultsService(this.getCollectionId(), null, [commandManager
.getCommandById("loadtestlist"), this.getView()]);
367 var NSMap
= {slc
:"http://argeo.org/projects/slc/schemas"};
368 request
.addListener("completed", function(response
){
369 var xml
= response
.getContent();
370 this.debug("Successfully loaded XML");
371 var nodes
= org
.argeo
.ria
.util
.Element
.selectNodes(xml
, "//slc:result-attributes", NSMap
);
372 //model.addRows(nodes);
374 for(var i
=0; i
<nodes
.length
;i
++){
375 model
.addRows([nodes
[i
]]);
382 * Enable/disable the automatic reloading of the list.
383 * @param state {Boolean} Whether the automatic reloading must be started or stopped.
385 pollListLoading : function(state
){
387 this.timer
= new qx
.event
.Timer(5000);
388 this.timer
.addListener("interval", this.loadList
, this);
399 * Creates a menu gui component from the currently loaded collectionList.
400 * @param command {qx.event.Command} The command on which to attach the created menu.
401 * @param checkSelection {Boolean} Whether at the end, we must check the current viewSelection to enable/disable the command accordingly.
403 collectionListToMenu : function(command
, checkSelection
){
404 command
.setEnabled(false);
405 command
.clearMenus();
406 var collectionList
= this.getCollectionList();
407 if(!collectionList
) return;
409 for(var key
in collectionList
){
410 if(this.getCollectionId() && key
== this.getCollectionId()) continue;
412 "label":collectionList
[key
],
413 "icon":"resource/slc/folder.png",
417 submenus
.push({'separator':true});
418 submenus
.push({"label":"New...", "icon":"resource/slc/folder-new.png", "commandId":"slc.client.create"});
419 command
.setMenu(submenus
);
421 var viewSelection
= this.getView().getViewSelection();
422 if(viewSelection
.getCount()) command
.setEnabled(true);
424 command
.setEnabled(true);
428 * Use SlcApi "addResult" service to add selected results to a given collection.
429 * If collectionId is "slc.client.create", first triggers a modal dialog to enter a new collection name, then retrigger itself with the new id.
430 * @param collectionId {String} The id of the destination collection, or "slc.client.create".
431 * @param selectionType {String} "current_collection"|"current_selection". The first adds the whole collection content to the destination, the second only selected results.
433 copySelectionToCollection:function(collectionId
, selectionType
){
434 if(collectionId
== "slc.client.create"){
435 var modal
= new org
.argeo
.ria
.components
.Modal("Create collection", "resource/slc/folder-new.png");
436 modal
.makePromptForm("Enter the new collection name", function(value
){
438 alert("Please enter a name for the new collection!");
442 // Create the collection now, then recall the callback with the new name.
443 this.copySelectionToCollection(value
, selectionType
);
447 modal
.attachAndShow();
451 var currentFocus
= org
.argeo
.ria
.components
.ViewsManager
.getInstance().getCurrentFocus();
452 if(currentFocus
.getViewId() == "applet"){
453 alert("Should copy data from the applet - command was " + collectionId
);
457 if(selectionType
== "current_collection"){
458 this.error("Not implemented yet!");
459 }else if(selectionType
== "current_selection"){
461 var request
= org
.argeo
.slc
.ria
.SlcApi
.getAddResultService(collectionId
,this.extractTestUuid());
462 request
.addListener("completed", function(response
){
463 this.info("Result successfully copied to collection!");
464 this.loadCollections();
471 * Utilitary function to extract test unique id from the currently selected node.
472 * @return {String} The test unique id.
474 extractTestUuid: function(){
475 var NSMap
= {slc
:"http://argeo.org/projects/slc/schemas"};
476 var xmlNodes
= this.getView().getViewSelection().getNodes();
477 var uuid
= qx
.dom
.Node
.getText(org
.argeo
.ria
.util
.Element
.selectSingleNode(xmlNodes
[0], "slc:uuid"));
482 * Listener of the collection selector (select box added to the viewpane header).
483 * @param event {qx.event.type.Event} The event.
485 collectionSelectorListener : function(event
){
486 this.setCollectionId(event
.getData());
490 addScroll : function(){
496 this.pollListLoading(false);