]> git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.webapp/src/main/webapp/argeo-ria-lib/slc/class/org/argeo/slc/ria/Applet.js
Splitted the LauncherApplet into two different applets. The first one is a generic...
[gpl/argeo-slc.git] / org.argeo.slc.webapp / src / main / webapp / argeo-ria-lib / slc / class / org / argeo / slc / ria / Applet.js
1 /**
2 * The canonical SLC applet for test result viewing. It will display a TreeTestResult in a TreeVirtual component
3 * composed of four columns : test name, state (passed/failed/error), message and date.
4 *
5 * It makes use of the StatusCellRenderer class for the "state" cell being a background-colored cell, the color depending on the FAILED or PASSED state message.
6 * The only associated command is the "Close" command.
7 */
8 qx.Class.define("org.argeo.slc.ria.Applet",
9 {
10 extend : qx.ui.container.Composite,
11 implement : [org.argeo.ria.components.IView],
12
13 construct : function(){
14 this.base(arguments);
15 this.setLayout(new qx.ui.layout.VBox());
16 this.passedStatus = "PASSED";
17 this.failedStatus = "FAILED";
18 },
19
20 properties :
21 {
22 /**
23 * The viewPane inside which this applet is added.
24 */
25 view : {
26 init : null
27 },
28 /**
29 * Commands definition, see {@link org.argeo.ria.event.CommandsManager#definitions}
30 */
31 commands : {
32 init : {
33 "close" : {
34 label : "Close Result",
35 icon : "resource/slc/window-close.png",
36 shortcut : "Control+w",
37 enabled : true,
38 menu : "Test",
39 toolbar : "result",
40 callback : function(e){
41 // Call service to delete
42 this.getView().empty();
43 //alert(this.testId);
44
45 },
46 selectionChange : function(viewId, xmlNode){
47 if(viewId != "applet") return;
48 },
49 command : null
50 }
51 }
52 }
53 },
54
55 members :
56 {
57 /**
58 * Called at applet creation. Just registers viewPane.
59 * @param viewPane {org.argeo.ria.components.ViewPane} The viewPane.
60 */
61 init : function(viewPane){
62 this.setView(viewPane);
63 },
64
65 /**
66 * Load a given test : the data passed must be an XML node containing the test unique ID.
67 * @param xmlNode {Element} The text xml description.
68 */
69 load : function(xmlNode){
70 this.data = xmlNode;
71 if(!xmlNode) return;
72 // Load XML or Whatever
73 var service;
74 var NSMap = {slc:"http://argeo.org/projects/slc/schemas"};
75 this.testId = qx.dom.Node.getText(org.argeo.ria.util.Element.selectSingleNode(this.data, "slc:uuid"));
76 this.getView().setViewTitle("Test "+this.testId);
77 var request = org.argeo.slc.ria.SlcApi.getLoadResultService(this.testId);
78 request.addListener("completed", function(response){
79 this.createXmlGui(response.getContent());
80 this.getView().setOnLoad(false);
81 }, this);
82 this.getView().setOnLoad(true);
83 request.send();
84
85 },
86
87 addScroll : function(){
88 return false;
89 },
90
91 close : function(){
92
93 },
94
95 /**
96 * Creates the GUI.
97 * @param responseXml {Document} The xml response of the "load" query.
98 */
99 createXmlGui : function(responseXml){
100 var NSMap = {
101 "slc" : "http://argeo.org/projects/slc/schemas"
102 }
103 if(!qx.Class.hasMixin(qx.ui.treevirtual.TreeVirtual, qx.ui.treevirtual.MNode)){
104 qx.Class.include(qx.ui.treevirtual.TreeVirtual,qx.ui.treevirtual.MNode);
105 }
106 this.tree = new qx.ui.treevirtual.TreeVirtual(["Test", "State", "Message", "Id"]);
107 this.tree.getTableColumnModel().setDataCellRenderer(0, new org.argeo.ria.util.TreeDataCellRenderer());
108 this.tree.getDataRowRenderer().setHighlightFocusRow(false); // Default row renderer
109 this.tree.setRowHeight(18);
110 this.tree.setStatusBarVisible(false);
111 this.tree.setDecorator(new qx.ui.decoration.Background("#fff"));
112 var model = this.tree.getDataModel();
113 var resNodes = org.argeo.ria.util.Element.selectNodes(responseXml, "//slc:result-part", NSMap);
114 var resultParts = {};
115 var addedPaths = {};
116 for(var i=0;i<resNodes.length;i++){
117 var currentParentId = null;
118 var node = resNodes[i];
119 var pathAttr = qx.xml.Element.getSingleNodeText(node, "@path");
120 var pathParts = pathAttr.split("/");
121 if(pathParts[0] == ""){
122 pathParts.shift();
123 }
124 var crtPath = "";
125 for(var j=0;j<pathParts.length;j++){
126 //if(pathParts[j] == "") continue;
127 crtPath = crtPath.concat("/", pathParts[j]);
128 if(addedPaths[crtPath]) {
129 currentParentId = addedPaths[crtPath];
130 continue; // Node already exists, set as parent and go to next!
131 }
132 var element = org.argeo.ria.util.Element.selectSingleNode(responseXml, '//slc:element[@path="'+crtPath+'"]', NSMap);
133 var label;
134 if(element != null){
135 label = org.argeo.ria.util.Element.getSingleNodeText(element, "*/slc:label", NSMap);
136 }else{
137 label = crtPath;
138 }
139 var simpleResults = org.argeo.ria.util.Element.selectNodes(node, "slc:part-sub-list/slc:parts/slc:simple-result-part", NSMap);
140
141 var newId;
142 //newId = model.addBranch(currentParentId, label, false);
143
144 // Test Leaf Node
145 if(!simpleResults || !simpleResults.length){
146 newId = model.addBranch(currentParentId, label, false);
147 addedPaths[crtPath] = newId;
148 currentParentId = newId;
149 continue;
150 }
151 if(simpleResults.length == 1){
152 //newId = model.addBranch(currentParentId, label, false);
153 var sResNode = simpleResults[0];
154 newId = model.addBranch(currentParentId, label);
155 model.setColumnData(newId, 3, org.argeo.ria.util.Element.getSingleNodeText(sResNode, "slc:test-run-uuid", NSMap));
156 model.setColumnData(newId, 2, org.argeo.ria.util.Element.getSingleNodeText(sResNode, "slc:message", NSMap));
157 var status = org.argeo.ria.util.Element.getSingleNodeText(sResNode, "slc:status", NSMap);
158 if(status != "PASSED"){
159 status = this.failedStatus ;
160 this._setParentBranchAsFailed(newId);
161 }else{
162 status = this.passedStatus;
163 }
164 model.setColumnData(newId, 1, status);
165 addedPaths[crtPath] = newId;
166 currentParentId = newId;
167 continue;
168 }
169 newId = model.addBranch(currentParentId, label, false);
170 for(var k=0;k<simpleResults.length;k++){
171 var sResNode = simpleResults[k];
172 resId = model.addLeaf(currentParentId, label);
173 model.setColumnData(resId, 3, org.argeo.ria.util.Element.getSingleNodeText(sResNode, "slc:test-run-uuid", NSMap));
174 model.setColumnData(resId, 2, org.argeo.ria.util.Element.getSingleNodeText(sResNode, "slc:message", NSMap));
175 var status = org.argeo.ria.util.Element.getSingleNodeText(sResNode, "slc:status", NSMap);
176 if(status != "PASSED"){
177 status = this.failedStatus ;
178 this._setParentBranchAsFailed(resId);
179 }else{
180 status = this.passedStatus;
181 }
182 model.setColumnData(resId, 1, status);
183 }
184
185 addedPaths[crtPath] = newId;
186 currentParentId = newId;
187 }
188 }
189 this._refineLeaves(this.tree, 0);
190 this.add(this.tree, {flex:1});
191 model.setData();
192 var columnModel = this.tree.getTableColumnModel();
193 var resize = columnModel.getBehavior();
194 resize.set(0, {width:250, minWidth:250});
195 resize.set(1, {width:55});
196 resize.set(2, {width:"1*"});
197 resize.set(3, {width:150});
198 columnModel.setDataCellRenderer(1, new org.argeo.slc.ria.StatusCellRenderer());
199
200 this.tree.getSelectionManager().getSelectionModel().addListener("changeSelection", function(e){
201 var viewSelection = this.getView().getViewSelection();
202 viewSelection.clear();
203 var nodes = this.tree.getDataModel().getSelectedNodes();
204 if(nodes.length){
205 viewSelection.addNode(nodes[0]);
206 this.getView().setViewSelection(viewSelection);
207 }
208 }, this);
209
210 var contextMenu = org.argeo.ria.event.CommandsManager.getInstance().createMenuFromIds(["close"]);
211 this.tree.setContextMenu(contextMenu);
212
213 },
214
215 /**
216 * Goes up the parents recursively to set a whole tree branch in "failed" mode.
217 * @param id {Integer} The id of the child node.
218 */
219 _setParentBranchAsFailed : function(id){
220 var model = this.tree.getDataModel();
221 while(id != null && id!=0){
222 var node = this.tree.nodeGet(id);
223 id = node.parentNodeId;
224 if(id != null && id!=0){
225 model.setColumnData(id, 1, this.failedStatus);
226 this.tree.nodeSetOpened(id, true);
227 }
228 }
229 },
230
231 /**
232 * Recursively make sur the last children are of qx.ui.treevirtual.SimpleTreeDataModel.Type.LEAF type.
233 *
234 * @param tree {qx.ui.treevirtual.TreeVirtual} The main tree of the applet.
235 * @param nodeId {Integer} Current node id.
236 */
237 _refineLeaves : function(tree, nodeId){
238 var node = tree.nodeGet(nodeId);
239 if(node.children && node.children.length){
240 for(var i=0;i<node.children.length;i++){
241 this._refineLeaves(tree, node.children[i]);
242 }
243 }else{
244 node.type = qx.ui.treevirtual.SimpleTreeDataModel.Type.LEAF;
245 }
246 },
247
248 /**
249 * Alternatively to the createXmlGui, create a simple HtmlElement and append the query responseText.
250 * Not used but sample.
251 * @param responseText {String} Html code to display.
252 */
253 createHtmlGui : function(responseText){
254 var htmlElement = new qx.ui.embed.Html(responseText);
255 htmlElement.setOverflowX("auto");
256 htmlElement.setOverflowY("auto");
257 this.add(htmlElement, {flex:1});
258 }
259
260 }
261 });