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.
51 "openexecutionapplet" : {
53 icon
: "resource/slc/utilities-terminal.png",
54 shortcut
: "Control+i",
58 callback : function(e
){
59 var manager
= org
.argeo
.ria
.components
.ViewsManager
.getInstance();
60 var iView
= manager
.initIViewClass(org
.argeo
.slc
.ria
.LauncherApplet
, "applet");
66 label
: "Load Collection",
67 icon
: "resource/slc/view-refresh.png",
68 shortcut
: "Control+l",
71 toolbar
: "collection",
72 callback : function(e
){
79 icon
: "resource/slc/document-open-recent.png",
80 shortcut
: "Control+l",
84 toolbar
: "collection",
85 callback : function(event
){
86 this.pollListLoading(event
.getTarget().getUserData("slc.command.toggleState"));
91 "copyfullcollection" : {
93 icon : "resource/slc/edit-copy.png",
97 toolbar : "collection",
98 callback : function(e){
99 // Call service to copy
102 submenuCallback : function(commandId){
103 this.copySelectionToCollection(commandId, "current_collection");
106 // Call at command creation
107 org.argeo.ria.remote.RequestManager.getInstance().addListener("reload", function(event){
108 if(event.getDataType() == "collection" || event.getDataType() == "test_cases"){
109 var testList = org.argeo.ria.components.ViewsManager.getInstance().getViewPaneById("list").getContent();
110 testList.collectionListToMenu(this);
119 icon
: "resource/slc/media-playback-start.png",
120 shortcut
: "Control+o",
123 toolbar
: "selection",
124 callback : function(e
){
125 var viewsManager
= org
.argeo
.ria
.components
.ViewsManager
.getInstance();
126 var classObj
= org
.argeo
.slc
.ria
.Applet
;
127 var iView
= viewsManager
.initIViewClass(classObj
, "applet");
128 var xmlNodes
= viewsManager
.getViewPaneSelection("list").getNodes();
129 iView
.load(xmlNodes
[0]);
131 selectionChange : function(viewId
, xmlNodes
){
132 if(viewId
!= "list") return;
133 this.setEnabled(false);
134 if(xmlNodes
== null || !xmlNodes
.length
) return;
135 this.setEnabled(true);
140 label
: "Download as...",
141 icon
: "resource/slc/go-down.png",
145 toolbar
: "selection",
146 callback : function(e
){ },
149 {'label':"Xsl", 'icon':'resource/slc/mime-xsl.png', 'commandId':'xsl'},
150 {'label':"Xml", 'icon':'resource/slc/mime-xml.png', 'commandId':'xml'},
151 {'label':"Excel", 'icon':'resource/slc/mime-xls.png', 'commandId':'xls'},
152 {'label':"Pdf", 'icon':'resource/slc/mime-pdf.png', 'commandId':'pdf'}
154 submenuCallback : function(commandId
){
155 var uuid
= this.extractTestUuid();
157 xsl
: "resultView.xslt",
158 xml
: "resultViewXml.xslt",
159 xls
: "resultView.xls",
160 pdf
: "resultView.pdf"
162 var url
= "../"+urls
[commandId
]+"?uuid="+uuid
;
163 if(commandId
== "xls" || commandId
== "pdf"){
164 document
.location
.href
= url
;
166 var win
= window
.open(url
);
169 selectionChange : function(viewId
, xmlNodes
){
170 if(viewId
!="list")return;
172 this.setEnabled(false);
173 if(xmlNodes
== null || !xmlNodes
.length
) return;
174 this.setEnabled(true);
177 "copytocollection" : {
178 label
: "Copy to...",
179 icon
: "resource/slc/edit-copy.png",
180 shortcut
: "Control+c",
183 toolbar
: "selection",
184 callback : function(e
){
185 // Call service to copy
188 submenuCallback : function(commandId
){
189 this.copySelectionToCollection(commandId
, "current_selection");
192 // Call at command creation
193 org
.argeo
.ria
.remote
.RequestManager
.getInstance().addListener("reload", function(event
){
194 if(event
.getDataType() == "collection" || event
.getDataType() == "test_cases"){
195 var testList
= org
.argeo
.ria
.components
.ViewsManager
.getInstance().getViewPaneById("list").getContent();
196 testList
.collectionListToMenu(this, true);
200 selectionChange : function(viewId
, xmlNodes
){
201 if(viewId
!= "list") return;
202 this.setEnabled(false);
203 if(xmlNodes
== null || !xmlNodes
.length
) return;
204 this.setEnabled(true);
210 icon
: "resource/slc/edit-delete.png",
211 shortcut
: "Control+d",
214 toolbar
: "selection",
215 callback : function(e
){
217 var request
= org
.argeo
.slc
.ria
.SlcApi
.getRemoveResultService(this.getCollectionId(), this.extractTestUuid());
218 request
.addListener("completed", function(response
){
219 this.loadCollections();
221 this.info("Test was successfully deleted");
225 selectionChange : function(viewId
, xmlNodes
){
226 if(viewId
!= "list") return;
227 this.setEnabled(false);
228 if(xmlNodes
== null || !xmlNodes
.length
) return;
229 this.setEnabled(true);
238 init : function(viewPane
){
239 this.setView(viewPane
);
241 load : function(data
){
243 statusBarVisible
: false,
244 showCellFocusIndicator
:false,
245 columnVisibilityButtonVisible
:false,
246 contextMenu
: org
.argeo
.ria
.event
.CommandsManager
.getInstance().createMenuFromIds(["opentest", "download", "copytocollection", "deletetest"]),
247 decorator
: new qx
.ui
.decoration
.Background("#fff")
249 var viewPane
= this.getView();
250 this.table
.addListener("dblclick", function(e
){
251 org
.argeo
.ria
.event
.CommandsManager
.getInstance().executeCommand("opentest");
253 var columnModel
= this.table
.getTableColumnModel();
254 columnModel
.getBehavior().setWidth(0, "60%");
255 var renderer
= new org
.argeo
.slc
.web
.XmlRenderer();
256 columnModel
.setDataCellRenderer(0, renderer
);
257 columnModel
.setDataCellRenderer(1, renderer
);
259 this.table
.getSelectionManager().getSelectionModel().addListener("changeSelection", function(e
){
260 var viewSelection
= viewPane
.getViewSelection();
261 viewSelection
.clear();
262 var selectionModel
= this.table
.getSelectionManager().getSelectionModel();
263 if(!selectionModel
.getSelectedCount()){
266 var ranges
= this.table
.getSelectionManager().getSelectionModel().getSelectedRanges();
267 var xmlNode
= this.table
.getTableModel().getRowData(ranges
[0].minIndex
);
268 viewSelection
.addNode(xmlNode
);
269 viewPane
.setViewSelection(viewSelection
);
272 var select
= new qx
.ui
.form
.SelectBox();
273 this.getView().addHeaderComponent(select
);
274 this.getView().setViewTitle("");
275 this.add(this.table
, {flex
:1});
277 select
.addListener("changeValue", this.collectionSelectorListener
, this);
279 org
.argeo
.ria
.remote
.RequestManager
.getInstance().addListener("reload", function(event
){
280 if(event
.getDataType()!="collection") return;
281 select
.removeListener("changeValue", this.collectionSelectorListener
, this);
282 var collectionList
= event
.getContent();
284 for(key
in collectionList
){
285 var item
= new qx
.ui
.form
.ListItem(collectionList
[key
], "resource/slc/folder.png", key
);
287 if(key
== this.getCollectionId()){
288 select
.setSelected(item
);
291 this.setCollectionId(select
.getSelected().getValue());
292 select
.addListener("changeValue", this.collectionSelectorListener
, this);
298 * Use SlcApi to load the available collections.
300 loadCollections : function(){
301 var request
= org
.argeo
.slc
.ria
.SlcApi
.getListCollectionsService();
302 var NSMap
= {slc
:"http://argeo.org/projects/slc/schemas"};
303 request
.addListener("completed", function(response
){
304 var xml
= response
.getContent();
305 var collections
= {};
306 var nodes
= org
.argeo
.ria
.util
.Element
.selectNodes(xml
, "//slc:ref", NSMap
);
307 for(var i
=0;i
<nodes
.length
;i
++){
308 var collId
= qx
.xml
.Element
.getSingleNodeText(nodes
[i
], ".");
309 collections
[collId
] = collId
;
311 this.setCollectionList(collections
);
312 org
.argeo
.ria
.remote
.RequestManager
.getInstance().fireReloadEvent("collection", this.getCollectionList());
314 request
.setAsynchronous(false);
319 * Load the results of the currently selected collection.
321 loadList : function(){
322 var model
= this.table
.getTableModel();
323 model
.removeRows(0, model
.getRowCount());
324 var commandManager
= org
.argeo
.ria
.event
.CommandsManager
.getInstance();
325 var request
= org
.argeo
.slc
.ria
.SlcApi
.getListResultsService(this.getCollectionId(), null, [commandManager
.getCommandById("loadtestlist"), this.getView()]);
326 var NSMap
= {slc
:"http://argeo.org/projects/slc/schemas"};
327 request
.addListener("completed", function(response
){
328 var xml
= response
.getContent();
329 this.debug("Successfully loaded XML");
330 var nodes
= org
.argeo
.ria
.util
.Element
.selectNodes(xml
, "//slc:result-attributes", NSMap
);
331 //model.addRows(nodes);
333 for(var i
=0; i
<nodes
.length
;i
++){
334 model
.addRows([nodes
[i
]]);
341 * Enable/disable the automatic reloading of the list.
342 * @param state {Boolean} Whether the automatic reloading must be started or stopped.
344 pollListLoading : function(state
){
346 this.timer
= new qx
.event
.Timer(5000);
347 this.timer
.addListener("interval", this.loadList
, this);
358 * Creates a menu gui component from the currently loaded collectionList.
359 * @param command {qx.event.Command} The command on which to attach the created menu.
360 * @param checkSelection {Boolean} Whether at the end, we must check the current viewSelection to enable/disable the command accordingly.
362 collectionListToMenu : function(command
, checkSelection
){
363 command
.setEnabled(false);
364 command
.clearMenus();
365 var collectionList
= this.getCollectionList();
366 if(!collectionList
) return;
368 for(var key
in collectionList
){
369 if(this.getCollectionId() && key
== this.getCollectionId()) continue;
371 "label":collectionList
[key
],
372 "icon":"resource/slc/folder.png",
376 submenus
.push({'separator':true});
377 submenus
.push({"label":"New...", "icon":"resource/slc/folder-new.png", "commandId":"slc.client.create"});
378 command
.setMenu(submenus
);
380 var viewSelection
= this.getView().getViewSelection();
381 if(viewSelection
.getCount()) command
.setEnabled(true);
383 command
.setEnabled(true);
387 * Use SlcApi "addResult" service to add selected results to a given collection.
388 * If collectionId is "slc.client.create", first triggers a modal dialog to enter a new collection name, then retrigger itself with the new id.
389 * @param collectionId {String} The id of the destination collection, or "slc.client.create".
390 * @param selectionType {String} "current_collection"|"current_selection". The first adds the whole collection content to the destination, the second only selected results.
392 copySelectionToCollection:function(collectionId
, selectionType
){
393 if(collectionId
== "slc.client.create"){
394 var modal
= new org
.argeo
.ria
.components
.Modal("Create collection", "resource/slc/folder-new.png");
395 modal
.makePromptForm("Enter the new collection name", function(value
){
397 alert("Please enter a name for the new collection!");
401 // Create the collection now, then recall the callback with the new name.
402 this.copySelectionToCollection(value
, selectionType
);
406 modal
.attachAndShow();
410 if(selectionType
== "current_collection"){
411 this.error("Not implemented yet!");
412 }else if(selectionType
== "current_selection"){
414 var request
= org
.argeo
.slc
.ria
.SlcApi
.getAddResultService(collectionId
,this.extractTestUuid());
415 request
.addListener("completed", function(response
){
416 this.info("Result successfully copied to collection!");
417 this.loadCollections();
424 * Utilitary function to extract test unique id from the currently selected node.
425 * @return {String} The test unique id.
427 extractTestUuid: function(){
428 var NSMap
= {slc
:"http://argeo.org/projects/slc/schemas"};
429 var xmlNodes
= this.getView().getViewSelection().getNodes();
430 var uuid
= qx
.dom
.Node
.getText(org
.argeo
.ria
.util
.Element
.selectSingleNode(xmlNodes
[0], "slc:uuid"));
435 * Listener of the collection selector (select box added to the viewpane header).
436 * @param event {qx.event.type.Event} The event.
438 collectionSelectorListener : function(event
){
439 this.setCollectionId(event
.getData());
443 addScroll : function(){