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);
169 "copytocollection" : {
170 label
: "Copy to...",
171 icon
: "resource/slc/edit-copy.png",
172 shortcut
: "Control+c",
175 toolbar
: "selection",
176 callback : function(e
){
177 // Call service to copy
180 submenuCallback : function(commandId
){
181 this.copySelectionToCollection(commandId
, "current_selection");
184 // Call at command creation
185 org
.argeo
.ria
.remote
.RequestManager
.getInstance().addListener("reload", function(event
){
186 if(event
.getDataType() == "collection" || event
.getDataType() == "test_cases"){
187 var testList
= org
.argeo
.ria
.components
.ViewsManager
.getInstance().getViewPaneById("list").getContent();
188 testList
.collectionListToMenu(this, true);
192 selectionChange : function(viewId
, xmlNodes
){
193 if(viewId
!= "list") return;
194 this.setEnabled(false);
195 if(xmlNodes
== null || !xmlNodes
.length
) return;
196 this.setEnabled(true);
202 icon
: "resource/slc/edit-delete.png",
203 shortcut
: "Control+d",
206 toolbar
: "selection",
207 callback : function(e
){
208 var modal
= new org
.argeo
.ria
.components
.Modal("Confirm", null);
209 modal
.addConfirm("Are you sure you want to delete<br> test " + this.extractTestUuid() + "?");
210 modal
.addListener("ok", function(){
211 var request
= org
.argeo
.slc
.ria
.SlcApi
.getRemoveResultService(this.getCollectionId(), this.extractTestUuid());
212 request
.addListener("completed", function(response
){
213 this.loadCollections();
215 this.info("Test was successfully deleted");
219 modal
.attachAndShow();
221 selectionChange : function(viewId
, xmlNodes
){
222 if(viewId
!= "list") return;
223 this.setEnabled(false);
224 if(xmlNodes
== null || !xmlNodes
.length
) return;
225 this.setEnabled(true);
234 init : function(viewPane
, data
){
235 this.setView(viewPane
);
236 this.setViewSelection(new org
.argeo
.ria
.components
.ViewSelection(viewPane
.getViewId()));
240 statusBarVisible
: false,
241 showCellFocusIndicator
:false,
242 columnVisibilityButtonVisible
:false,
243 contextMenu
: org
.argeo
.ria
.event
.CommandsManager
.getInstance().createMenuFromIds(["opentest", "download", "copytocollection", "deletetest"]),
244 decorator
: new qx
.ui
.decoration
.Background("#fff")
246 var viewPane
= this.getView();
247 this.table
.addListener("dblclick", function(e
){
248 org
.argeo
.ria
.event
.CommandsManager
.getInstance().executeCommand("opentest");
250 var columnModel
= this.table
.getTableColumnModel();
251 columnModel
.getBehavior().setWidth(0, "60%");
252 var renderer
= new org
.argeo
.slc
.web
.XmlRenderer();
253 columnModel
.setDataCellRenderer(0, renderer
);
254 columnModel
.setDataCellRenderer(1, renderer
);
256 this.table
.getSelectionManager().getSelectionModel().addListener("changeSelection", function(e
){
257 var viewSelection
= this.getViewSelection();
258 viewSelection
.clear();
259 var selectionModel
= this.table
.getSelectionManager().getSelectionModel();
260 if(!selectionModel
.getSelectedCount()){
263 var ranges
= this.table
.getSelectionManager().getSelectionModel().getSelectedRanges();
264 var xmlNode
= this.table
.getTableModel().getRowData(ranges
[0].minIndex
);
265 viewSelection
.addNode(xmlNode
);
266 //viewPane.setViewSelection(viewSelection);
269 var select
= new qx
.ui
.form
.SelectBox();
270 this.getView().addHeaderComponent(select
);
271 this.getView().setViewTitle("");
272 this.add(this.table
, {flex
:1});
274 select
.addListener("changeValue", this.collectionSelectorListener
, this);
276 org
.argeo
.ria
.remote
.RequestManager
.getInstance().addListener("reload", function(event
){
277 if(event
.getDataType()!="collection") return;
278 select
.removeListener("changeValue", this.collectionSelectorListener
, this);
279 var collectionList
= event
.getContent();
281 for(key
in collectionList
){
282 var item
= new qx
.ui
.form
.ListItem(collectionList
[key
], "resource/slc/folder.png", key
);
284 if(key
== this.getCollectionId()){
285 select
.setSelected(item
);
288 if(qx
.lang
.Object
.getLength(collectionList
)){
289 this.setCollectionId(select
.getSelected().getValue());
291 select
.addListener("changeValue", this.collectionSelectorListener
, this);
297 * Use SlcApi to load the available collections.
299 loadCollections : function(){
300 var request
= org
.argeo
.slc
.ria
.SlcApi
.getListCollectionsService();
301 var NSMap
= {slc
:"http://argeo.org/projects/slc/schemas"};
302 request
.addListener("completed", function(response
){
303 var xml
= response
.getContent();
304 var collections
= {};
305 var nodes
= org
.argeo
.ria
.util
.Element
.selectNodes(xml
, "//slc:ref", NSMap
);
306 for(var i
=0;i
<nodes
.length
;i
++){
307 var collId
= qx
.xml
.Element
.getSingleNodeText(nodes
[i
], ".");
308 collections
[collId
] = collId
;
310 this.setCollectionList(collections
);
311 org
.argeo
.ria
.remote
.RequestManager
.getInstance().fireReloadEvent("collection", this.getCollectionList());
313 request
.setAsynchronous(false);
318 * Load the results of the currently selected collection.
320 loadList : function(){
321 var model
= this.table
.getTableModel();
322 model
.removeRows(0, model
.getRowCount());
323 var commandManager
= org
.argeo
.ria
.event
.CommandsManager
.getInstance();
324 var request
= org
.argeo
.slc
.ria
.SlcApi
.getListResultsService(this.getCollectionId(), null, [commandManager
.getCommandById("loadtestlist"), this.getView()]);
325 var NSMap
= {slc
:"http://argeo.org/projects/slc/schemas"};
326 request
.addListener("completed", function(response
){
327 var xml
= response
.getContent();
328 this.debug("Successfully loaded XML");
329 var nodes
= org
.argeo
.ria
.util
.Element
.selectNodes(xml
, "//slc:result-attributes", NSMap
);
330 //model.addRows(nodes);
332 for(var i
=0; i
<nodes
.length
;i
++){
333 model
.addRows([nodes
[i
]]);
340 * Enable/disable the automatic reloading of the list.
341 * @param state {Boolean} Whether the automatic reloading must be started or stopped.
343 pollListLoading : function(state
){
345 this.timer
= new qx
.event
.Timer(5000);
346 this.timer
.addListener("interval", this.loadList
, this);
357 * Creates a menu gui component from the currently loaded collectionList.
358 * @param command {qx.event.Command} The command on which to attach the created menu.
359 * @param checkSelection {Boolean} Whether at the end, we must check the current viewSelection to enable/disable the command accordingly.
361 collectionListToMenu : function(command
, checkSelection
){
362 command
.setEnabled(false);
363 command
.clearMenus();
364 var collectionList
= this.getCollectionList();
365 if(!collectionList
) return;
367 for(var key
in collectionList
){
368 if(this.getCollectionId() && key
== this.getCollectionId()) continue;
370 "label":collectionList
[key
],
371 "icon":"resource/slc/folder.png",
375 submenus
.push({'separator':true});
376 submenus
.push({"label":"New...", "icon":"resource/slc/folder-new.png", "commandId":"slc.client.create"});
377 command
.setMenu(submenus
);
379 var viewSelection
= this.getView().getViewSelection();
380 if(viewSelection
.getCount()) command
.setEnabled(true);
382 command
.setEnabled(true);
386 * Use SlcApi "addResult" service to add selected results to a given collection.
387 * If collectionId is "slc.client.create", first triggers a modal dialog to enter a new collection name, then retrigger itself with the new id.
388 * @param collectionId {String} The id of the destination collection, or "slc.client.create".
389 * @param selectionType {String} "current_collection"|"current_selection". The first adds the whole collection content to the destination, the second only selected results.
391 copySelectionToCollection:function(collectionId
, selectionType
){
392 if(collectionId
== "slc.client.create"){
393 var modal
= new org
.argeo
.ria
.components
.Modal("Create collection", "resource/slc/folder-new.png");
394 modal
.makePromptForm("Enter the new collection name", function(value
){
396 alert("Please enter a name for the new collection!");
400 // Create the collection now, then recall the callback with the new name.
401 this.copySelectionToCollection(value
, selectionType
);
405 modal
.attachAndShow();
409 var currentFocus
= org
.argeo
.ria
.components
.ViewsManager
.getInstance().getCurrentFocus();
410 if(currentFocus
.getViewId() == "applet"){
411 alert("Should copy data from the applet - command was " + collectionId
);
415 if(selectionType
== "current_collection"){
416 this.error("Not implemented yet!");
417 }else if(selectionType
== "current_selection"){
419 var request
= org
.argeo
.slc
.ria
.SlcApi
.getAddResultService(collectionId
,this.extractTestUuid());
420 request
.addListener("completed", function(response
){
421 this.info("Result successfully copied to collection!");
422 this.loadCollections();
429 * Utilitary function to extract test unique id from the currently selected node.
430 * @return {String} The test unique id.
432 extractTestUuid: function(){
433 var NSMap
= {slc
:"http://argeo.org/projects/slc/schemas"};
434 var xmlNodes
= this.getView().getViewSelection().getNodes();
435 var uuid
= qx
.dom
.Node
.getText(org
.argeo
.ria
.util
.Element
.selectSingleNode(xmlNodes
[0], "slc:uuid"));
440 * Listener of the collection selector (select box added to the viewpane header).
441 * @param event {qx.event.type.Event} The event.
443 collectionSelectorListener : function(event
){
444 this.setCollectionId(event
.getData());
448 addScroll : function(){
454 this.pollListLoading(false);