]>
git.argeo.org Git - gpl/argeo-slc.git/blob - server/org.argeo.slc.ria/src/argeo-ria-lib/slc/class/org/argeo/slc/ria/BatchView.js
6a7f50b8e2efc7f24aee4fa1591d859863e23475
2 * Applet for the batch manager
4 qx
.Class
.define("org.argeo.slc.ria.BatchView",
6 extend
: qx
.ui
.container
.Composite
,
7 implement
: [org
.argeo
.ria
.components
.IView
],
12 * The commands definition Map that will be automatically added and wired to the menubar and toolbar.
13 * See {@link org.argeo.ria.event.CommandsManager#definitions} for the keys to use for defining commands.
18 label
: "Execute Batch",
19 icon
: "resource/slc/media-playback-start.png",
24 callback : function(e
) {
25 if (this.getBatchAgentId()) {
26 this.executeBatchOnAgent(this.getBatchAgentId());
33 label : "Auto edit on Add",
34 icon : "resource/slc/document-open.png",
38 toggleInitialState : true,
41 callback : function(event) {
42 var state = event.getTarget().getUserData("slc.command.toggleState");
43 this.setAutoOpen(state);
47 "editexecutionspecs" : {
48 label : "Edit Execution Specs",
49 icon : "resource/slc/document-open.png",
54 callback : function(e) {
55 var sel = this.list.getSortedSelection();
56 var spec = sel[0].getUserData("batchEntrySpec");
57 if (spec.hasEditableValues()) {
58 var specEditor = new org.argeo.slc.ria.execution.SpecEditor(spec);
59 specEditor.attachAndShow();
62 selectionChange : function(viewId, selection) {
63 if (viewId != "batch:list")
65 this.setEnabled(false);
66 if ((selection && selection.length == 1)) {
67 var selectedItemSpec = selection[0].getUserData("batchEntrySpec");
68 if (selectedItemSpec.hasEditableValues()) {
69 this.setEnabled(true);
77 label
: "Remove from batch",
78 icon
: "resource/slc/edit-delete.png",
83 callback : function(e
) {
84 var sel
= this.list
.getSortedSelection();
85 var modal
= new org
.argeo
.ria
.components
.Modal("Confirm", null);
86 modal
.addConfirm("Are you sure you want to remove<br> the selected test"
87 + (sel
.length
> 1 ? "s" : "")
88 + " from the Batch?");
89 modal
.addListener("ok", function() {
90 for (var i
= 0; i
< sel
.length
; i
++) {
91 this.list
.remove(sel
[i
]);
93 if (!this.list
.hasChildren()) {
94 this.setBatchAgentId(null);
97 modal
.attachAndShow();
99 selectionChange : function(viewId
, selection
) {
100 if (viewId
!= "batch:list")
102 this.setEnabled(false);
103 if ((selection
&& selection
.length
> 0))
104 this.setEnabled(true);
109 label
: "Clear batch",
110 icon
: "resource/slc/user-trash-full.png",
115 callback : function(e
) {
116 if(!this.list
.hasChildren()) return;
117 this.list
.selectAll();
118 this.getCommands()["removefrombatch"].command
.execute();
120 selectionChange : function(viewId
, selection
) {
131 check
:"org.argeo.ria.components.ViewSelection"
133 instanceId
: {init
:""},
134 instanceLabel
: {init
:""},
136 * A boolean registering whether the SpecEditor must autoOpen or not
137 * when a spec is added to the Batch.
147 event
: "changeBatchAgentId"
151 construct : function(){
152 this.base(arguments
);
153 this.setLayout(new qx
.ui
.layout
.Dock());
158 * The implementation should contain the GUI initialisation.
159 * This is the role of the manager to actually add the graphical component to the pane,
160 * so it's not necessary to do it here.
161 * @param viewPane {org.argeo.ria.components.ViewPane} The pane manager
162 * @param data {Mixed} Any object or data passed by the initiator of the view
165 init : function(viewPane
, data
){
166 this.setView(viewPane
);
167 this.setViewSelection(new org
.argeo
.ria
.components
.ViewSelection(viewPane
.getViewId()));
168 this._emptyAgentString
= "Empty Batch (Drop scripts here)";
169 this._crtAgentString
= "Batch Execution on Agent ";
173 * The implementation should contain the real data loading (i.o. query...)
177 this._createLayout();
178 this.getView().setViewTitle(this._emptyAgentString
);
179 //this.getView().setViewTitle("");
183 * Creates the main applet layout.
185 _createLayout : function() {
186 this.listPane
= new qx
.ui
.container
.Composite(new qx
.ui
.layout
.Dock());
187 this.addListener("changeBatchAgentId", function(event
) {
188 var value
= event
.getData();
190 this.getView().setViewTitle(this._emptyAgentString
);
192 var selectorView
= org
.argeo
.ria
.components
.ViewsManager
.getInstance().getViewPaneById("selector").getContent();
194 var agentsMap
= selectorView
.getAgentsMap();
195 this.getView().setViewTitle(this._crtAgentString
+ "'" + agentsMap
[value
] + "'");
200 var indicator
= new qx
.ui
.core
.Widget();
201 indicator
.setDecorator(new qx
.ui
.decoration
.Single().set({
202 top
: [1, "solid", "#33508D"]
204 indicator
.setHeight(0);
205 indicator
.setOpacity(0.5);
206 indicator
.setZIndex(100);
207 indicator
.setLayoutProperties({
211 org
.argeo
.ria
.Application
.INSTANCE
.getRoot().add(indicator
);
213 this.list
= new qx
.ui
.form
.List();
214 this.list
.setDecorator(null);
215 this.list
.setSelectionMode("multi");
216 this.list
.setDroppable(true);
217 this.list
.setDraggable(true);
218 this.list
.setContextMenu(org
.argeo
.ria
.event
.CommandsManager
219 .getInstance().createMenuFromIds(["removefrombatch"]));
221 this.list
.addListener("dragstart", function(e
) {
222 e
.addType(["items"]);
223 e
.addAction(["move"]);
225 this.list
.addListener("dragend", function(e
) {
226 indicator
.setDomPosition(-1000, -1000);
228 this.list
.addListener("dragover", function(e
) {
229 var orig
= e
.getOriginalTarget();
230 var origCoords
= orig
.getContainerLocation();
231 indicator
.setWidth(orig
.getBounds().width
);
232 indicator
.setDomPosition(origCoords
.left
,
235 this.list
.addListener("drag", function(e
) {
236 var orig
= e
.getOriginalTarget();
237 var origCoords
= orig
.getContainerLocation();
238 indicator
.setWidth(orig
.getBounds().width
);
239 indicator
.setDomPosition(origCoords
.left
,
243 this.list
.addListener("drop", function(e
) {
244 var target
= e
.getRelatedTarget();
245 var afterItem
= e
.getOriginalTarget();
246 indicator
.setDomPosition(-1000, -1000);
247 if (afterItem
.classname
!= "qx.ui.form.ListItem")
250 target
= this.list
.getSortedSelection()[0];
251 this.addFlowToBatch(target
, afterItem
);
253 org
.argeo
.ria
.event
.CommandsManager
.getInstance().executeCommand("addtobatch");
256 this.listPane
.add(this.list
, {
260 this.list
.addListener("changeSelection", function(e
) {
261 var viewSelection
= this.getViewSelection();
262 viewSelection
.setViewId("batch:list");
263 viewSelection
.clear();
264 var listSel
= this.list
.getSortedSelection();
265 for (var i
= 0; i
< listSel
.length
; i
++) {
266 viewSelection
.addNode(listSel
[i
]);
270 this.dropDecorator
= new qx
.ui
.decoration
.Background();
271 this.dropDecorator
.set({
272 backgroundImage
: "resource/slc/drophere.gif",
273 backgroundRepeat
: "no-repeat"
277 listChangeListener = function() {
278 var command
= org
.argeo
.ria
.event
.CommandsManager
.getInstance()
279 .getCommandById("submitform");
280 command
.setEnabled(this.list
.hasChildren());
281 var command2
= org
.argeo
.ria
.event
.CommandsManager
.getInstance()
282 .getCommandById("clearbatch");
283 command2
.setEnabled(this.list
.hasChildren());
284 this.list
.setDecorator((this.list
.hasChildren()?null:this.dropDecorator
));
286 this.list
.addListener("addItem", listChangeListener
, this);
287 this.list
.addListener("removeItem", listChangeListener
, this);
289 this.list
.setDecorator(this.dropDecorator
);
291 this.add(this.listPane
);
296 * Adds a given ExecutionFlow to the batch
299 * {mixed} The dropped target, can be a TreeFile (add) or a
300 * ListItem (reorder).
302 * {qx.ui.form.ListItem} Optional list item : if set, the
303 * flow will be added as a new list item positionned after
305 * @param skipAutoOpen
306 * {boolean} Whether the formular should open or not.
308 addFlowToBatch : function(target
, after
, skipAutoOpen
) {
309 if (target
&& target
.classname
== "qx.ui.form.ListItem") {
312 if (after
== "first")
313 this.list
.addAt(target
, 0);
315 this.list
.addAfter(target
, after
);
320 if (qx
.Class
.isSubClassOf(qx
.Class
.getByName(target
.classname
),
321 qx
.ui
.tree
.TreeFolder
)) {
322 var allChildren
= target
.getItems(true);
323 for (var i
= 0; i
< allChildren
.length
; i
++) {
324 if (allChildren
[i
].getUserData("executionFlow")) {
326 this.addFlowToBatch(allChildren
[i
], null, true);
335 // Check agent Uuid against current batch agent Id.
336 var agentUuid
= target
.getUserData("agentUuid");
337 if (!this.getBatchAgentId()) {
338 this.setBatchAgentId(agentUuid
);
339 } else if (this.getBatchAgentId() != agentUuid
) {
340 this.error("Batch can contain tests only of the same agent!");
341 throw new Error("Batch can contain tests only of the same agent!");
344 var executionModule
= target
.getUserData("executionModule");
345 var executionFlow
= target
.getUserData("executionFlow");
346 var batchEntry
= new org
.argeo
.slc
.ria
.execution
.BatchEntrySpec(
347 executionModule
, executionFlow
);
348 var label
= batchEntry
.getLabel();
349 var icon
= target
.getIcon() || "resource/slc/office-document.png";
350 var item
= new qx
.ui
.form
.ListItem(label
, icon
);
352 item.addListener("dblclick", function(e) {
353 this.getCommands()["editexecutionspecs"].command
357 item
.setUserData("batchEntrySpec", batchEntry
);
358 item
.setPaddingTop(1);
359 item
.setPaddingBottom(2);
361 if (after
== "first")
362 this.list
.addAt(item
, 0);
364 this.list
.addAfter(item
, after
);
368 this.list
.select(item
);
370 if (this.getAutoOpen() && !skipAutoOpen) {
371 this.getCommands()["editexecutionspecs"].command.execute();
377 * Called at execution
380 * {String} The id of the target agent
382 executeBatchOnAgent : function(agentUuid
) {
383 var selection
= this.list
.getChildren();
384 if (!selection
.length
)
386 var slcExecMessage
= new org
.argeo
.slc
.ria
.execution
.Message();
387 for (var i
= 0; i
< selection
.length
; i
++) {
388 var batchEntrySpec
= selection
[i
].getUserData("batchEntrySpec");
389 slcExecMessage
.addBatchEntrySpec(batchEntrySpec
);
391 var req
= org
.argeo
.slc
.ria
.SlcApi
.getNewSlcExecutionService(
392 agentUuid
, slcExecMessage
.toXml());
394 // Force logs refresh right now!
395 qx
.event
.Timer
.once(function() {
396 var command
= org
.argeo
.ria
.event
.CommandsManager
397 .getInstance().getCommandById("reloadlogs");
404 clearBatchForAgentId : function(agentId
){
405 if(this.getBatchAgentId() == agentId
){
406 this.list
.removeAll();
407 this.setBatchAgentId(null);
412 * Whether this component is already contained in a scroller (return false) or not (return true).
415 addScroll : function(){return false;},
417 * Called at destruction time
418 * Perform all the clean operations (stopping polling queries, etc.)
420 close : function(){return true;}