]>
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
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.
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.
8 qx
. Class
. define ( "org.argeo.slc.ria.Applet" ,
10 extend
: qx
. ui
. container
. Composite
,
11 implement
: [ org
. argeo
. ria
. components
. IView
],
13 construct : function (){
15 this . setLayout ( new qx
. ui
. layout
. VBox ());
16 this . passedStatus
= "PASSED" ;
17 this . failedStatus
= "FAILED" ;
23 * The viewPane inside which this applet is added.
29 * Commands definition, see {@link org.argeo.ria.event.CommandsManager#definitions}
34 label
: "Close Result" ,
35 icon
: "resource/slc/window-close.png" ,
36 shortcut
: "Control+w" ,
40 callback : function ( e
){
41 // Call service to delete
42 this . getView (). empty ();
44 selectionChange : function ( viewId
, xmlNode
){
45 if ( viewId
!= "applet" ) return ;
56 * Called at applet creation. Just registers viewPane.
57 * @param viewPane {org.argeo.ria.components.ViewPane} The viewPane.
59 init : function ( viewPane
){
60 this . setView ( viewPane
);
64 * Load a given test : the data passed must be an XML node containing the test unique ID.
65 * @param xmlNode {Element} The text xml description.
67 load : function ( xmlNode
){
70 // Load XML or Whatever
72 var NSMap
= { slc
: "http://argeo.org/projects/slc/schemas" };
73 var testId
= qx
. dom
. Node
. getText ( org
. argeo
. ria
. util
. Element
. selectSingleNode ( this . data
, "slc:uuid" ));
74 this . getView (). setViewTitle ( "Test " + testId
);
75 var request
= org
. argeo
. slc
. ria
. SlcApi
. getLoadResultService ( testId
);
76 request
. addListener ( "completed" , function ( response
){
77 this . createXmlGui ( response
. getContent ());
78 this . getView (). setOnLoad ( false );
80 this . getView (). setOnLoad ( true );
85 addScroll : function (){
91 * @param responseXml {Document} The xml response of the "load" query.
93 createXmlGui : function ( responseXml
){
95 "slc" : "http://argeo.org/projects/slc/schemas"
97 if (! qx
. Class
. hasMixin ( qx
. ui
. treevirtual
. TreeVirtual
, qx
. ui
. treevirtual
. MNode
)){
98 qx
. Class
. include ( qx
. ui
. treevirtual
. TreeVirtual
, qx
. ui
. treevirtual
. MNode
);
100 this . tree
= new qx
. ui
. treevirtual
. TreeVirtual ([ "Test" , "State" , "Message" , "Id" ]);
101 this . tree
. getTableColumnModel (). setDataCellRenderer ( 0 , new org
. argeo
. ria
. util
. TreeDataCellRenderer ());
102 this . tree
. getDataRowRenderer (). setHighlightFocusRow ( false ); // Default row renderer
103 this . tree
. setRowHeight ( 18 );
104 this . tree
. setStatusBarVisible ( false );
105 this . tree
. setDecorator ( new qx
. ui
. decoration
. Background ( "#fff" ));
106 var model
= this . tree
. getDataModel ();
107 var resNodes
= org
. argeo
. ria
. util
. Element
. selectNodes ( responseXml
, "//slc:result-part" , NSMap
);
108 var resultParts
= {};
110 for ( var i
= 0 ; i
< resNodes
. length
; i
++){
111 var currentParentId
= null ;
112 var node
= resNodes
[ i
];
113 var pathAttr
= qx
. xml
. Element
. getSingleNodeText ( node
, "@path" );
114 var pathParts
= pathAttr
. split ( "/" );
115 if ( pathParts
[ 0 ] == "" ){
119 for ( var j
= 0 ; j
< pathParts
. length
; j
++){
120 //if(pathParts[j] == "") continue;
121 crtPath
= crtPath
. concat ( "/" , pathParts
[ j
]);
122 if ( addedPaths
[ crtPath
]) {
123 currentParentId
= addedPaths
[ crtPath
];
124 continue ; // Node already exists, set as parent and go to next!
126 var element
= org
. argeo
. ria
. util
. Element
. selectSingleNode ( responseXml
, '//slc:element[@path="' + crtPath
+ '"]' , NSMap
);
129 label
= org
. argeo
. ria
. util
. Element
. getSingleNodeText ( element
, "*/slc:label" , NSMap
);
133 var simpleResults
= org
. argeo
. ria
. util
. Element
. selectNodes ( node
, "slc:part-sub-list/slc:parts/slc:simple-result-part" , NSMap
);
136 //newId = model.addBranch(currentParentId, label, false);
139 if (! simpleResults
|| ! simpleResults
. length
){
140 newId
= model
. addBranch ( currentParentId
, label
, false );
141 addedPaths
[ crtPath
] = newId
;
142 currentParentId
= newId
;
145 if ( simpleResults
. length
== 1 ){
146 //newId = model.addBranch(currentParentId, label, false);
147 var sResNode
= simpleResults
[ 0 ];
148 newId
= model
. addBranch ( currentParentId
, label
);
149 model
. setColumnData ( newId
, 3 , org
. argeo
. ria
. util
. Element
. getSingleNodeText ( sResNode
, "slc:test-run-uuid" , NSMap
));
150 model
. setColumnData ( newId
, 2 , org
. argeo
. ria
. util
. Element
. getSingleNodeText ( sResNode
, "slc:message" , NSMap
));
151 var status
= org
. argeo
. ria
. util
. Element
. getSingleNodeText ( sResNode
, "slc:status" , NSMap
);
152 if ( status
!= "PASSED" ){
153 status
= this . failedStatus
;
154 this . _setParentBranchAsFailed ( newId
);
156 status
= this . passedStatus
;
158 model
. setColumnData ( newId
, 1 , status
);
159 addedPaths
[ crtPath
] = newId
;
160 currentParentId
= newId
;
163 newId
= model
. addBranch ( currentParentId
, label
, false );
164 for ( var k
= 0 ; k
< simpleResults
. length
; k
++){
165 var sResNode
= simpleResults
[ k
];
166 resId
= model
. addLeaf ( currentParentId
, label
);
167 model
. setColumnData ( resId
, 3 , org
. argeo
. ria
. util
. Element
. getSingleNodeText ( sResNode
, "slc:test-run-uuid" , NSMap
));
168 model
. setColumnData ( resId
, 2 , org
. argeo
. ria
. util
. Element
. getSingleNodeText ( sResNode
, "slc:message" , NSMap
));
169 var status
= org
. argeo
. ria
. util
. Element
. getSingleNodeText ( sResNode
, "slc:status" , NSMap
);
170 if ( status
!= "PASSED" ){
171 status
= this . failedStatus
;
172 this . _setParentBranchAsFailed ( resId
);
174 status
= this . passedStatus
;
176 model
. setColumnData ( resId
, 1 , status
);
179 addedPaths
[ crtPath
] = newId
;
180 currentParentId
= newId
;
183 this . _refineLeaves ( this . tree
, 0 );
184 this . add ( this . tree
, { flex
: 1 });
186 var columnModel
= this . tree
. getTableColumnModel ();
187 var resize
= columnModel
. getBehavior ();
188 resize
. set ( 0 , { width
: 250 , minWidth
: 250 });
189 resize
. set ( 1 , { width
: 55 });
190 resize
. set ( 2 , { width
: "1*" });
191 resize
. set ( 3 , { width
: 150 });
192 columnModel
. setDataCellRenderer ( 1 , new org
. argeo
. slc
. ria
. StatusCellRenderer ());
194 this . tree
. getSelectionManager (). getSelectionModel (). addListener ( "changeSelection" , function ( e
){
195 var viewSelection
= this . getView (). getViewSelection ();
196 viewSelection
. clear ();
197 var nodes
= this . tree
. getDataModel (). getSelectedNodes ();
199 viewSelection
. addNode ( nodes
[ 0 ]);
200 this . getView (). setViewSelection ( viewSelection
);
204 var contextMenu
= org
. argeo
. ria
. event
. CommandsManager
. getInstance (). createMenuFromIds ([ "close" ]);
205 this . tree
. setContextMenu ( contextMenu
);
210 * Goes up the parents recursively to set a whole tree branch in "failed" mode.
211 * @param id {Integer} The id of the child node.
213 _setParentBranchAsFailed : function ( id
){
214 var model
= this . tree
. getDataModel ();
215 while ( id
!= null && id
!= 0 ){
216 var node
= this . tree
. nodeGet ( id
);
217 id
= node
. parentNodeId
;
218 if ( id
!= null && id
!= 0 ){
219 model
. setColumnData ( id
, 1 , this . failedStatus
);
220 this . tree
. nodeSetOpened ( id
, true );
226 * Recursively make sur the last children are of qx.ui.treevirtual.SimpleTreeDataModel.Type.LEAF type.
228 * @param tree {qx.ui.treevirtual.TreeVirtual} The main tree of the applet.
229 * @param nodeId {Integer} Current node id.
231 _refineLeaves : function ( tree
, nodeId
){
232 var node
= tree
. nodeGet ( nodeId
);
233 if ( node
. children
&& node
. children
. length
){
234 for ( var i
= 0 ; i
< node
. children
. length
; i
++){
235 this . _refineLeaves ( tree
, node
. children
[ i
]);
238 node
. type
= qx
. ui
. treevirtual
. SimpleTreeDataModel
. Type
. LEAF
;
243 * Alternatively to the createXmlGui, create a simple HtmlElement and append the query responseText.
244 * Not used but sample.
245 * @param responseText {String} Html code to display.
247 createHtmlGui : function ( responseText
){
248 var htmlElement
= new qx
. ui
. embed
. Html ( responseText
);
249 htmlElement
. setOverflowX ( "auto" );
250 htmlElement
. setOverflowY ( "auto" );
251 this . add ( htmlElement
, { flex
: 1 });