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',
65 * The applet commands.
70 label
: "Load Collection",
71 icon
: "org.argeo.slc.ria/view-refresh.png",
72 shortcut
: "Control+l",
75 toolbar
: "collection",
76 callback : function(e
){
83 icon
: "org.argeo.slc.ria/document-open-recent.png",
84 shortcut
: "Control+l",
88 toolbar
: "collection",
89 callback : function(event
){
90 this.pollListLoading(event
.getTarget().getUserData("slc.command.toggleState"));
95 "copyfullcollection" : {
97 icon : "org.argeo.slc.ria/edit-copy.png",
101 toolbar : "collection",
102 callback : function(e){
103 // Call service to copy
106 submenuCallback : function(commandId){
107 this.copySelectionToCollection(commandId, "current_collection");
110 // Call at command creation
111 org.argeo.ria.remote.RequestManager.getInstance().addListener("reload", function(event){
112 if(event.getDataType() == "collection" || event.getDataType() == "test_cases"){
113 var testList = org.argeo.ria.components.ViewsManager.getInstance().getViewPaneById("list").getContent();
114 testList.collectionListToMenu(this);
123 icon
: "org.argeo.slc.ria/media-playback-start.png",
124 shortcut
: "Control+o",
127 toolbar
: "selection",
128 callback : function(e
){
129 var viewsManager
= org
.argeo
.ria
.components
.ViewsManager
.getInstance();
130 var classObj
= org
.argeo
.slc
.ria
.Applet
;
131 var xmlNodes
= viewsManager
.getViewPaneSelection("list").getNodes();
132 var iView
= viewsManager
.initIViewClass(classObj
, "applet", xmlNodes
[0]);
133 iView
.load(xmlNodes
[0]);
135 selectionChange : function(viewId
, xmlNodes
){
136 if(viewId
!= "list") return;
137 this.setEnabled(false);
138 if(xmlNodes
== null || !xmlNodes
.length
) return;
139 this.setEnabled(true);
144 label
: "Download as...",
145 icon
: "org.argeo.slc.ria/go-down.png",
149 toolbar
: "selection",
150 callback : function(e
){ },
153 {'label':"Xsl", 'icon':'org.argeo.slc.ria/mime-xsl.png', 'commandId':'xsl'},
154 {'label':"Xml", 'icon':'org.argeo.slc.ria/mime-xml.png', 'commandId':'xml'},
155 {'label':"Excel", 'icon':'org.argeo.slc.ria/mime-xls.png', 'commandId':'xls'},
156 {'label':"Pdf", 'icon':'org.argeo.slc.ria/mime-pdf.png', 'commandId':'pdf'}
158 submenuCallback : function(commandId
){
159 var uuid
= this.extractTestUuid();
161 xsl
: "resultView.xslt",
162 xml
: "resultViewXml.xslt",
163 xls
: "resultView.xls",
164 pdf
: "resultView.pdf"
166 var url
= "../"+urls
[commandId
]+"?uuid="+uuid
;
167 if(commandId
== "xls" || commandId
== "pdf"){
168 document
.location
.href
= url
;
170 var win
= window
.open(url
);
173 selectionChange : function(viewId
, xmlNodes
){
174 if(viewId
!="list")return;
176 this.setEnabled(false);
177 if(xmlNodes
== null || !xmlNodes
.length
) return;
178 this.setEnabled(true);
182 label
: "Attachments",
183 icon
: "org.argeo.slc.ria/document-save-as.png",
187 toolbar
: "selection",
188 callback : function(e
){ },
191 submenuCallback : function(commandId
){
192 var split
= commandId
.split("__commandseparator__");
194 var contentType
= split
[1];
196 var url
= org
.argeo
.slc
.ria
.SlcApi
.buildGetAttachmentUrl(uuid
, contentType
, name
);
197 var win
= window
.open(url
);
199 selectionChange : function(viewId
, xmlNodes
){
200 if(viewId
!="list")return;
202 this.setEnabled(false);
203 if(xmlNodes
== null || !xmlNodes
.length
|| xmlNodes
.length
!= 1) return;
204 // Check slc:simple-attachment tags
205 var attachs
= org
.argeo
.ria
.util
.Element
.selectNodes(xmlNodes
[0], "slc:attachments/slc:simple-attachment");
206 if(attachs
&& attachs
.length
){
208 for(var i
=0;i
<attachs
.length
;i
++){
209 var uuid
= org
.argeo
.ria
.util
.Element
.getSingleNodeText(attachs
[i
], "slc:uuid");
210 var contentType
= (org
.argeo
.ria
.util
.Element
.getSingleNodeText(attachs
[i
], "slc:content-type")||'');
211 var name
= org
.argeo
.ria
.util
.Element
.getSingleNodeText(attachs
[i
], "slc:name");
214 icon
: 'org.argeo.slc.ria/mime-text-plain.png',
215 commandId
:uuid
+'__commandseparator__'+contentType
+'__commandseparator__'+name
218 this.setMenu(submenus
);
219 this.setEnabled(true);
223 "copytocollection" : {
224 label
: "Copy to...",
225 icon
: "org.argeo.slc.ria/edit-copy.png",
226 shortcut
: "Control+c",
229 toolbar
: "selection",
230 callback : function(e
){
231 // Call service to copy
234 submenuCallback : function(commandId
){
235 this.copySelectionToCollection(commandId
, "current_selection");
238 // Call at command creation
239 org
.argeo
.ria
.remote
.RequestManager
.getInstance().addListener("reload", function(event
){
240 if(event
.getDataType() == "collection" || event
.getDataType() == "test_cases"){
241 var testList
= org
.argeo
.ria
.components
.ViewsManager
.getInstance().getViewPaneById("list").getContent();
242 testList
.collectionListToMenu(this, true);
246 selectionChange : function(viewId
, xmlNodes
){
247 if(viewId
!= "list") return;
248 this.setEnabled(false);
249 if(xmlNodes
== null || !xmlNodes
.length
) return;
250 this.setEnabled(true);
256 icon
: "org.argeo.slc.ria/edit-delete.png",
257 shortcut
: "Control+d",
260 toolbar
: "selection",
261 callback : function(e
){
262 var modal
= new org
.argeo
.ria
.components
.Modal("Confirm", null);
263 modal
.addConfirm("Are you sure you want to delete<br> test " + this.extractTestUuid() + "?");
264 modal
.addListener("ok", function(){
265 var request
= org
.argeo
.slc
.ria
.SlcApi
.getRemoveResultService(this.getCollectionId(), this.extractTestUuid());
266 request
.addListener("completed", function(response
){
267 this.loadCollections();
269 this.info("Test was successfully deleted");
273 modal
.attachAndShow();
275 selectionChange : function(viewId
, xmlNodes
){
276 if(viewId
!= "list") return;
277 this.setEnabled(false);
278 if(xmlNodes
== null || !xmlNodes
.length
) return;
279 this.setEnabled(true);
288 init : function(viewPane
, data
){
289 this.setView(viewPane
);
290 this.setViewSelection(new org
.argeo
.ria
.components
.ViewSelection(viewPane
.getViewId()));
294 statusBarVisible
: false,
295 showCellFocusIndicator
:false,
296 columnVisibilityButtonVisible
:false,
297 contextMenu
: org
.argeo
.ria
.event
.CommandsManager
.getInstance().createMenuFromIds(["opentest", "download", "copytocollection", "deletetest"]),
298 decorator
: new qx
.ui
.decoration
.Background("#fff")
300 var viewPane
= this.getView();
301 this.table
.addListener("dblclick", function(e
){
302 var pref
= this.getRiaPreferenceValue("slc.web.TestList.DefaultAction");
304 org
.argeo
.ria
.event
.CommandsManager
.getInstance().executeCommand("opentest");
306 var uuid
= this.extractTestUuid();
307 var url
= "../resultView.xslt?uuid="+uuid
;
308 alert('Should download : '+url
);
311 var columnModel
= this.table
.getTableColumnModel();
312 columnModel
.getBehavior().setWidth(0, "60%");
313 var renderer
= new org
.argeo
.slc
.web
.XmlRenderer();
314 columnModel
.setDataCellRenderer(0, renderer
);
315 columnModel
.setDataCellRenderer(1, renderer
);
317 this.table
.getSelectionManager().getSelectionModel().addListener("changeSelection", function(e
){
318 var viewSelection
= this.getViewSelection();
319 viewSelection
.clear();
320 var selectionModel
= this.table
.getSelectionManager().getSelectionModel();
321 if(!selectionModel
.getSelectedCount()){
324 var ranges
= this.table
.getSelectionManager().getSelectionModel().getSelectedRanges();
325 var xmlNode
= this.table
.getTableModel().getRowData(ranges
[0].minIndex
);
326 viewSelection
.addNode(xmlNode
);
327 //viewPane.setViewSelection(viewSelection);
330 var select
= new qx
.ui
.form
.SelectBox();
331 this.getView().addHeaderComponent(select
);
332 this.getView().setViewTitle("");
333 this.add(this.table
, {flex
:1});
335 select
.addListener("changeValue", this.collectionSelectorListener
, this);
337 org
.argeo
.ria
.remote
.RequestManager
.getInstance().addListener("reload", function(event
){
338 if(event
.getDataType()!="collection") return;
339 select
.removeListener("changeValue", this.collectionSelectorListener
, this);
340 var collectionList
= event
.getContent();
342 for(key
in collectionList
){
343 var item
= new qx
.ui
.form
.ListItem(collectionList
[key
], "org.argeo.slc.ria/folder.png", key
);
345 if(key
== this.getCollectionId()){
346 select
.setSelected(item
);
349 if(qx
.lang
.Object
.getLength(collectionList
)){
350 this.setCollectionId(select
.getSelected().getValue());
352 select
.addListener("changeValue", this.collectionSelectorListener
, this);
358 * Use SlcApi to load the available collections.
360 loadCollections : function(){
361 var request
= org
.argeo
.slc
.ria
.SlcApi
.getListCollectionsService();
362 var NSMap
= {slc
:"http://argeo.org/projects/slc/schemas"};
363 request
.addListener("completed", function(response
){
364 var xml
= response
.getContent();
365 var collections
= {};
366 var nodes
= org
.argeo
.ria
.util
.Element
.selectNodes(xml
, "//slc:ref", NSMap
);
367 for(var i
=0;i
<nodes
.length
;i
++){
368 var collId
= qx
.xml
.Element
.getSingleNodeText(nodes
[i
], ".");
369 collections
[collId
] = collId
;
371 this.setCollectionList(collections
);
372 org
.argeo
.ria
.remote
.RequestManager
.getInstance().fireReloadEvent("collection", this.getCollectionList());
374 request
.setAsynchronous(false);
379 * Load the results of the currently selected collection.
381 loadList : function(){
382 var model
= this.table
.getTableModel();
383 model
.removeRows(0, model
.getRowCount());
384 var commandManager
= org
.argeo
.ria
.event
.CommandsManager
.getInstance();
385 var request
= org
.argeo
.slc
.ria
.SlcApi
.getListResultsService(this.getCollectionId(), null, [commandManager
.getCommandById("loadtestlist"), this.getView()]);
386 var NSMap
= {slc
:"http://argeo.org/projects/slc/schemas"};
387 request
.addListener("completed", function(response
){
388 var xml
= response
.getContent();
389 this.debug("Successfully loaded XML");
390 var nodes
= org
.argeo
.ria
.util
.Element
.selectNodes(xml
, "//slc:result-attributes", NSMap
);
391 //model.addRows(nodes);
393 for(var i
=0; i
<nodes
.length
;i
++){
394 model
.addRows([nodes
[i
]]);
401 * Enable/disable the automatic reloading of the list.
402 * @param state {Boolean} Whether the automatic reloading must be started or stopped.
404 pollListLoading : function(state
){
406 this.timer
= new qx
.event
.Timer(5000);
407 this.timer
.addListener("interval", this.loadList
, this);
418 * Creates a menu gui component from the currently loaded collectionList.
419 * @param command {qx.event.Command} The command on which to attach the created menu.
420 * @param checkSelection {Boolean} Whether at the end, we must check the current viewSelection to enable/disable the command accordingly.
422 collectionListToMenu : function(command
, checkSelection
){
423 command
.setEnabled(false);
424 command
.clearMenus();
425 var collectionList
= this.getCollectionList();
426 if(!collectionList
) return;
428 for(var key
in collectionList
){
429 if(this.getCollectionId() && key
== this.getCollectionId()) continue;
431 "label":collectionList
[key
],
432 "icon":"org.argeo.slc.ria/folder.png",
436 submenus
.push({'separator':true});
437 submenus
.push({"label":"New...", "icon":"org.argeo.slc.ria/folder-new.png", "commandId":"slc.client.create"});
438 command
.setMenu(submenus
);
440 var viewSelection
= this.getView().getViewSelection();
441 if(viewSelection
.getCount()) command
.setEnabled(true);
443 command
.setEnabled(true);
447 * Use SlcApi "addResult" service to add selected results to a given collection.
448 * If collectionId is "slc.client.create", first triggers a modal dialog to enter a new collection name, then retrigger itself with the new id.
449 * @param collectionId {String} The id of the destination collection, or "slc.client.create".
450 * @param selectionType {String} "current_collection"|"current_selection". The first adds the whole collection content to the destination, the second only selected results.
452 copySelectionToCollection:function(collectionId
, selectionType
){
453 if(collectionId
== "slc.client.create"){
454 var modal
= new org
.argeo
.ria
.components
.Modal("Create collection", "org.argeo.slc.ria/folder-new.png");
455 modal
.makePromptForm("Enter the new collection name", function(value
){
457 alert("Please enter a name for the new collection!");
461 // Create the collection now, then recall the callback with the new name.
462 this.copySelectionToCollection(value
, selectionType
);
466 modal
.attachAndShow();
470 var currentFocus
= org
.argeo
.ria
.components
.ViewsManager
.getInstance().getCurrentFocus();
471 if(currentFocus
.getViewId() == "applet"){
472 alert("Should copy data from the applet - command was " + collectionId
);
476 if(selectionType
== "current_collection"){
477 this.error("Not implemented yet!");
478 }else if(selectionType
== "current_selection"){
480 var request
= org
.argeo
.slc
.ria
.SlcApi
.getAddResultService(collectionId
,this.extractTestUuid());
481 request
.addListener("completed", function(response
){
482 this.info("Result successfully copied to collection!");
483 this.loadCollections();
490 * Utilitary function to extract test unique id from the currently selected node.
491 * @return {String} The test unique id.
493 extractTestUuid: function(){
494 var NSMap
= {slc
:"http://argeo.org/projects/slc/schemas"};
495 var xmlNodes
= this.getView().getViewSelection().getNodes();
496 var uuid
= qx
.dom
.Node
.getText(org
.argeo
.ria
.util
.Element
.selectSingleNode(xmlNodes
[0], "slc:uuid"));
501 * Listener of the collection selector (select box added to the viewpane header).
502 * @param event {qx.event.type.Event} The event.
504 collectionSelectorListener : function(event
){
505 this.setCollectionId(event
.getData());
509 addScroll : function(){
515 this.pollListLoading(false);