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
],
12 include
: [org
.argeo
.ria
.session
.MPrefHolder
],
16 "slc.web.TestList.DefaultAction" : {
17 label
: "Test List : Double Click default action",
19 list
: ["Open","Download Xls"],
25 construct : function(){
26 this.base(arguments
, new qx
.ui
.layout
.VBox());
27 var model
= new qx
.ui
.table
.model
.Simple();
28 model
.setColumns(["Test Case", "Date"]);
29 this.table
= new qx
.ui
.table
.Table(model
, {
30 tableColumnModel: function(obj
){
31 return new qx
.ui
.table
.columnmodel
.Resize(obj
)
39 * The viewPane containing this applet.
46 check
:"org.argeo.ria.components.ViewSelection"
48 instanceId
: {init
:""},
49 instanceLabel
: {init
:""},
51 * The load list of available collection (Map of ids => labels)
58 * The current collection id selected.
61 init
: 'My Collection',
64 currentOpenInstanceId
: {
69 * The applet commands.
74 label
: "Load Collection",
75 icon
: "org.argeo.slc.ria/view-refresh.png",
76 shortcut
: "Control+l",
79 toolbar
: "collection",
80 callback : function(e
){
87 icon
: "org.argeo.slc.ria/document-open-recent.png",
88 shortcut
: "Control+l",
92 toolbar
: "collection",
93 callback : function(event
){
94 this.pollListLoading(event
.getTarget().getUserData("slc.command.toggleState"));
99 "copyfullcollection" : {
100 label : "Copy to...",
101 icon : "org.argeo.slc.ria/edit-copy.png",
105 toolbar : "collection",
106 callback : function(e){
107 // Call service to copy
110 submenuCallback : function(commandId){
111 this.copySelectionToCollection(commandId, "current_collection");
114 // Call at command creation
115 org.argeo.ria.remote.RequestManager.getInstance().addListener("reload", function(event){
116 if(event.getDataType() == "collection" || event.getDataType() == "test_cases"){
117 var testList = org.argeo.ria.components.ViewsManager.getInstance().getViewPaneById("list").getContent();
118 testList.collectionListToMenu(this);
127 icon
: "org.argeo.slc.ria/media-playback-start.png",
128 shortcut
: "Control+o",
131 toolbar
: "selection",
132 callback : function(e
){
133 var viewsManager
= org
.argeo
.ria
.components
.ViewsManager
.getInstance();
134 var classObj
= org
.argeo
.slc
.ria
.Applet
;
135 var xmlNodes
= viewsManager
.getViewPaneSelection("list").getNodes();
136 var iView
= viewsManager
.initIViewClass(classObj
, "applet", xmlNodes
[0]);
137 this.setCurrentOpenInstanceId(iView
.getInstanceId());
138 iView
.load(xmlNodes
[0]);
140 selectionChange : function(viewId
, xmlNodes
){
141 if(viewId
!= "list") return;
142 this.setEnabled(false);
143 if(xmlNodes
== null || !xmlNodes
.length
) return;
144 this.setEnabled(true);
149 label
: "Download as...",
150 icon
: "org.argeo.slc.ria/go-down.png",
154 toolbar
: "selection",
155 callback : function(e
){ },
158 {'label':"Xsl", 'icon':'org.argeo.slc.ria/mime-xsl.png', 'commandId':'xsl'},
159 {'label':"Xml", 'icon':'org.argeo.slc.ria/mime-xml.png', 'commandId':'xml'},
160 {'label':"Excel", 'icon':'org.argeo.slc.ria/mime-xls.png', 'commandId':'xls'},
161 {'label':"Pdf", 'icon':'org.argeo.slc.ria/mime-pdf.png', 'commandId':'pdf'}
163 submenuCallback : function(commandId
){
164 var uuid
= this.extractTestUuid();
166 xsl
: "resultView.xslt",
167 xml
: "resultViewXml.xslt",
168 xls
: "resultView.xls",
169 pdf
: "resultView.pdf"
171 var url
= "../"+urls
[commandId
]+"?uuid="+uuid
;
172 if(commandId
== "xls" || commandId
== "pdf"){
173 document
.location
.href
= url
;
175 var win
= window
.open(url
);
178 selectionChange : function(viewId
, xmlNodes
){
179 if(viewId
!="list")return;
181 this.setEnabled(false);
182 if(xmlNodes
== null || !xmlNodes
.length
) return;
183 this.setEnabled(true);
187 label
: "Attachments",
188 icon
: "org.argeo.slc.ria/document-save-as.png",
192 toolbar
: "selection",
193 callback : function(e
){ },
196 submenuCallback : function(commandId
){
197 var split
= commandId
.split("__commandseparator__");
199 var contentType
= split
[1];
201 var url
= org
.argeo
.slc
.ria
.SlcApi
.buildGetAttachmentUrl(uuid
, contentType
, name
);
202 var win
= window
.open(url
);
204 selectionChange : function(viewId
, xmlNodes
){
205 if(viewId
!="list")return;
207 this.setEnabled(false);
208 if(xmlNodes
== null || !xmlNodes
.length
|| xmlNodes
.length
!= 1) return;
209 // Check slc:simple-attachment tags
210 var attachs
= org
.argeo
.ria
.util
.Element
.selectNodes(xmlNodes
[0], "slc:attachments/slc:simple-attachment");
211 if(attachs
&& attachs
.length
){
213 for(var i
=0;i
<attachs
.length
;i
++){
214 var uuid
= org
.argeo
.ria
.util
.Element
.getSingleNodeText(attachs
[i
], "slc:uuid");
215 var contentType
= (org
.argeo
.ria
.util
.Element
.getSingleNodeText(attachs
[i
], "slc:content-type")||'');
216 var name
= org
.argeo
.ria
.util
.Element
.getSingleNodeText(attachs
[i
], "slc:name");
219 icon
: 'org.argeo.slc.ria/mime-text-plain.png',
220 commandId
:uuid
+'__commandseparator__'+contentType
+'__commandseparator__'+name
223 this.setMenu(submenus
);
224 this.setEnabled(true);
228 "copytocollection" : {
229 label
: "Copy to...",
230 icon
: "org.argeo.slc.ria/edit-copy.png",
231 shortcut
: "Control+c",
234 toolbar
: "selection",
235 callback : function(e
){
236 // Call service to copy
239 submenuCallback : function(commandId
){
240 this.copySelectionToCollection(commandId
, "current_selection");
243 // Call at command creation
244 org
.argeo
.ria
.remote
.RequestManager
.getInstance().addListener("reload", function(event
){
245 if(event
.getDataType() == "collection" || event
.getDataType() == "test_cases"){
246 var testList
= org
.argeo
.ria
.components
.ViewsManager
.getInstance().getViewPaneById("list").getContent();
247 testList
.collectionListToMenu(this, true);
251 selectionChange : function(viewId
, xmlNodes
){
252 if(viewId
!= "list") return;
253 this.setEnabled(false);
254 if(xmlNodes
== null || !xmlNodes
.length
) return;
255 this.setEnabled(true);
261 icon
: "org.argeo.slc.ria/edit-delete.png",
262 shortcut
: "Control+d",
265 toolbar
: "selection",
266 callback : function(e
){
267 var modal
= new org
.argeo
.ria
.components
.Modal("Confirm", null);
268 var testUuid
= this.extractTestUuid();
269 modal
.addConfirm("Are you sure you want to delete<br> test " + testUuid
+ "?");
270 modal
.addListener("ok", function(){
271 var request
= org
.argeo
.slc
.ria
.SlcApi
.getRemoveResultService(this.getCollectionId(), this.extractTestUuid());
272 request
.addListener("completed", function(response
){
273 if(this.getCurrentOpenInstanceId() == "test:"+testUuid
){
274 var appletView
= org
.argeo
.ria
.components
.ViewsManager
.getInstance().getViewPaneById("applet");
275 appletView
.closeCurrent();
276 this.setCurrentOpenInstanceId(null);
278 this.loadCollections();
280 this.info("Test was successfully deleted");
284 modal
.attachAndShow();
286 selectionChange : function(viewId
, xmlNodes
){
287 if(viewId
!= "list") return;
288 this.setEnabled(false);
289 if(xmlNodes
== null || !xmlNodes
.length
) return;
290 this.setEnabled(true);
299 init : function(viewPane
, data
){
300 this.setView(viewPane
);
301 this.setViewSelection(new org
.argeo
.ria
.components
.ViewSelection(viewPane
.getViewId()));
305 statusBarVisible
: false,
306 showCellFocusIndicator
:false,
307 columnVisibilityButtonVisible
:false,
308 contextMenu
: org
.argeo
.ria
.event
.CommandsManager
.getInstance().createMenuFromIds(["opentest", "download", "copytocollection", "deletetest"]),
309 decorator
: new qx
.ui
.decoration
.Background("#fff")
311 var viewPane
= this.getView();
312 this.table
.addListener("dblclick", function(e
){
313 var pref
= this.getRiaPreferenceValue("slc.web.TestList.DefaultAction");
315 org
.argeo
.ria
.event
.CommandsManager
.getInstance().executeCommand("opentest");
317 var uuid
= this.extractTestUuid();
318 var url
= "../resultView.xslt?uuid="+uuid
;
319 alert('Should download : '+url
);
322 var columnModel
= this.table
.getTableColumnModel();
323 columnModel
.getBehavior().setWidth(0, "60%");
324 var renderer
= new org
.argeo
.slc
.web
.XmlRenderer();
325 columnModel
.setDataCellRenderer(0, renderer
);
326 columnModel
.setDataCellRenderer(1, renderer
);
328 this.table
.getSelectionManager().getSelectionModel().addListener("changeSelection", function(e
){
329 var viewSelection
= this.getViewSelection();
330 viewSelection
.clear();
331 var selectionModel
= this.table
.getSelectionManager().getSelectionModel();
332 if(!selectionModel
.getSelectedCount()){
335 var ranges
= this.table
.getSelectionManager().getSelectionModel().getSelectedRanges();
336 var xmlNode
= this.table
.getTableModel().getRowData(ranges
[0].minIndex
);
337 viewSelection
.addNode(xmlNode
);
338 //viewPane.setViewSelection(viewSelection);
341 var select
= new qx
.ui
.form
.SelectBox();
342 this.getView().addHeaderComponent(select
);
343 this.getView().setViewTitle("");
344 this.add(this.table
, {flex
:1});
346 select
.addListener("changeValue", this.collectionSelectorListener
, this);
348 org
.argeo
.ria
.remote
.RequestManager
.getInstance().addListener("reload", function(event
){
349 if(event
.getDataType()!="collection") return;
350 select
.removeListener("changeValue", this.collectionSelectorListener
, this);
351 var collectionList
= event
.getContent();
353 for(key
in collectionList
){
354 var item
= new qx
.ui
.form
.ListItem(collectionList
[key
], "org.argeo.slc.ria/folder.png", key
);
356 if(key
== this.getCollectionId()){
357 select
.setSelected(item
);
360 if(qx
.lang
.Object
.getLength(collectionList
)){
361 this.setCollectionId(select
.getSelected().getValue());
363 select
.addListener("changeValue", this.collectionSelectorListener
, this);
369 * Use SlcApi to load the available collections.
371 loadCollections : function(){
372 var request
= org
.argeo
.slc
.ria
.SlcApi
.getListCollectionsService();
373 var NSMap
= {slc
:"http://argeo.org/projects/slc/schemas"};
374 request
.addListener("completed", function(response
){
375 var xml
= response
.getContent();
376 var collections
= {};
377 var nodes
= org
.argeo
.ria
.util
.Element
.selectNodes(xml
, "//slc:ref", NSMap
);
378 for(var i
=0;i
<nodes
.length
;i
++){
379 var collId
= qx
.xml
.Element
.getSingleNodeText(nodes
[i
], ".");
380 collections
[collId
] = collId
;
382 this.setCollectionList(collections
);
383 org
.argeo
.ria
.remote
.RequestManager
.getInstance().fireReloadEvent("collection", this.getCollectionList());
385 request
.setAsynchronous(false);
390 * Load the results of the currently selected collection.
392 loadList : function(){
393 var model
= this.table
.getTableModel();
394 model
.removeRows(0, model
.getRowCount());
395 var commandManager
= org
.argeo
.ria
.event
.CommandsManager
.getInstance();
396 var request
= org
.argeo
.slc
.ria
.SlcApi
.getListResultsService(this.getCollectionId(), null, [commandManager
.getCommandById("loadtestlist"), this.getView()]);
397 var NSMap
= {slc
:"http://argeo.org/projects/slc/schemas"};
398 request
.addListener("completed", function(response
){
399 var xml
= response
.getContent();
400 this.debug("Successfully loaded XML");
401 var nodes
= org
.argeo
.ria
.util
.Element
.selectNodes(xml
, "//slc:result-attributes", NSMap
);
402 //model.addRows(nodes);
404 for(var i
=0; i
<nodes
.length
;i
++){
405 model
.addRows([nodes
[i
]]);
412 * Enable/disable the automatic reloading of the list.
413 * @param state {Boolean} Whether the automatic reloading must be started or stopped.
415 pollListLoading : function(state
){
417 this.timer
= new qx
.event
.Timer(5000);
418 this.timer
.addListener("interval", this.loadList
, this);
429 * Creates a menu gui component from the currently loaded collectionList.
430 * @param command {qx.event.Command} The command on which to attach the created menu.
431 * @param checkSelection {Boolean} Whether at the end, we must check the current viewSelection to enable/disable the command accordingly.
433 collectionListToMenu : function(command
, checkSelection
){
434 command
.setEnabled(false);
435 command
.clearMenus();
436 var collectionList
= this.getCollectionList();
437 if(!collectionList
) return;
439 for(var key
in collectionList
){
440 if(this.getCollectionId() && key
== this.getCollectionId()) continue;
442 "label":collectionList
[key
],
443 "icon":"org.argeo.slc.ria/folder.png",
447 submenus
.push({'separator':true});
448 submenus
.push({"label":"New...", "icon":"org.argeo.slc.ria/folder-new.png", "commandId":"slc.client.create"});
449 command
.setMenu(submenus
);
451 var viewSelection
= this.getView().getViewSelection();
452 if(viewSelection
.getCount()) command
.setEnabled(true);
454 command
.setEnabled(true);
458 * Use SlcApi "addResult" service to add selected results to a given collection.
459 * If collectionId is "slc.client.create", first triggers a modal dialog to enter a new collection name, then retrigger itself with the new id.
460 * @param collectionId {String} The id of the destination collection, or "slc.client.create".
461 * @param selectionType {String} "current_collection"|"current_selection". The first adds the whole collection content to the destination, the second only selected results.
463 copySelectionToCollection:function(collectionId
, selectionType
){
464 if(collectionId
== "slc.client.create"){
465 var modal
= new org
.argeo
.ria
.components
.Modal("Create collection", "org.argeo.slc.ria/folder-new.png");
466 modal
.makePromptForm("Enter the new collection name", function(value
){
468 alert("Please enter a name for the new collection!");
472 // Create the collection now, then recall the callback with the new name.
473 this.copySelectionToCollection(value
, selectionType
);
477 modal
.attachAndShow();
481 var currentFocus
= org
.argeo
.ria
.components
.ViewsManager
.getInstance().getCurrentFocus();
482 if(currentFocus
.getViewId() == "applet"){
483 alert("Should copy data from the applet - command was " + collectionId
);
487 if(selectionType
== "current_collection"){
488 this.error("Not implemented yet!");
489 }else if(selectionType
== "current_selection"){
491 var request
= org
.argeo
.slc
.ria
.SlcApi
.getAddResultService(collectionId
,this.extractTestUuid());
492 request
.addListener("completed", function(response
){
493 this.info("Result successfully copied to collection!");
494 this.loadCollections();
501 * Utilitary function to extract test unique id from the currently selected node.
502 * @return {String} The test unique id.
504 extractTestUuid: function(){
505 var NSMap
= {slc
:"http://argeo.org/projects/slc/schemas"};
506 var xmlNodes
= this.getView().getViewSelection().getNodes();
507 var uuid
= qx
.dom
.Node
.getText(org
.argeo
.ria
.util
.Element
.selectSingleNode(xmlNodes
[0], "slc:uuid"));
512 * Listener of the collection selector (select box added to the viewpane header).
513 * @param event {qx.event.type.Event} The event.
515 collectionSelectorListener : function(event
){
516 this.setCollectionId(event
.getData());
520 addScroll : function(){
526 this.pollListLoading(false);