]>
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
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
],
8 include
: [org
.argeo
.ria
.session
.MPrefHolder
],
11 "slc.batch.delete.confirm" : {
12 label
: "Confirm on batch deletion",
16 "slc.batch.autoclear" : {
17 label
: "Autoclear batch on execution",
26 * The commands definition Map that will be automatically added and wired to the menubar and toolbar.
27 * See {@link org.argeo.ria.event.CommandsManager#definitions} for the keys to use for defining commands.
32 label
: "Execute Batch",
33 icon
: "org.argeo.slc.ria/media-playback-start.png",
38 callback : function(e
) {
39 var batchAgentId
= this.getBatchAgentId();
43 var prefName
= "slc.batch.autoclear";
44 var prefValue
= this.getRiaPreferenceValue(prefName
);
45 if(prefValue
!== null && prefValue
=== true){
46 this.executeBatchOnAgent(batchAgentId
, true);
48 this.executeBatchOnAgent(batchAgentId
, false);
51 var modal
= new org
.argeo
.ria
.components
.Modal("Clear?", null);
52 modal
.addYesNoReminder("Do you want to clear the batch automatically after execution?", prefName
);
53 modal
.addListener("cancel", function(e
){
54 this.executeBatchOnAgent(batchAgentId
, false);
56 modal
.addListener("ok", function(e
){
57 this.executeBatchOnAgent(batchAgentId
, true);
59 modal
.attachAndShow();
65 label : "Auto edit on Add",
66 icon : "org.argeo.slc.ria/document-open.png",
70 toggleInitialState : true,
73 callback : function(event) {
74 var state = event.getTarget().getUserData("slc.command.toggleState");
75 this.setAutoOpen(state);
79 "editexecutionspecs" : {
80 label : "Edit Execution Specs",
81 icon : "org.argeo.slc.ria/document-open.png",
86 callback : function(e) {
87 var sel = this.list.getSortedSelection();
88 var spec = sel[0].getUserData("batchEntrySpec");
89 if (spec.hasEditableValues()) {
90 var specEditor = new org.argeo.slc.ria.execution.SpecEditor(spec);
91 specEditor.attachAndShow();
94 selectionChange : function(viewId, selection) {
95 if (viewId != "batch:list")
97 this.setEnabled(false);
98 if ((selection && selection.length == 1)) {
99 var selectedItemSpec = selection[0].getUserData("batchEntrySpec");
100 if (selectedItemSpec.hasEditableValues()) {
101 this.setEnabled(true);
108 "removefrombatch" : {
109 label
: "Remove from batch",
110 icon
: "org.argeo.slc.ria/edit-delete.png",
115 callback : function(e
) {
116 var sel
= this.list
.getSortedSelection();
117 var confirmPref
= this.getRiaPreferenceValue("slc.batch.delete.confirm");
118 var execution = function() {
119 for (var i
= 0; i
< sel
.length
; i
++) {
120 this.list
.remove(sel
[i
]);
122 if (!this.list
.hasChildren()) {
123 this.setBatchAgentId(null);
127 var modal
= new org
.argeo
.ria
.components
.Modal("Confirm", null);
128 modal
.addConfirm("Are you sure you want to remove<br> the selected test"
129 + (sel
.length
> 1 ? "s" : "")
130 + " from the Batch?");
131 modal
.addListener("ok", execution
, this);
132 modal
.attachAndShow();
134 execution
= qx
.lang
.Function
.bind(execution
, this);
138 selectionChange : function(viewId
, selection
) {
139 if (viewId
!= "batch:list")
141 this.setEnabled(false);
142 if ((selection
&& selection
.length
> 0))
143 this.setEnabled(true);
148 label
: "Clear batch",
149 icon
: "org.argeo.slc.ria/user-trash-full.png",
154 callback : function(e
) {
155 if(!this.list
.hasChildren()) return;
156 this.list
.selectAll();
157 this.getCommands()["removefrombatch"].command
.execute();
159 selectionChange : function(viewId
, selection
) {
170 check
:"org.argeo.ria.components.ViewSelection"
172 instanceId
: {init
:""},
173 instanceLabel
: {init
:""},
175 * A boolean registering whether the SpecEditor must autoOpen or not
176 * when a spec is added to the Batch.
186 event
: "changeBatchAgentId"
190 construct : function(){
191 this.base(arguments
);
192 this.setLayout(new qx
.ui
.layout
.Dock());
197 * The implementation should contain the GUI initialisation.
198 * This is the role of the manager to actually add the graphical component to the pane,
199 * so it's not necessary to do it here.
200 * @param viewPane {org.argeo.ria.components.ViewPane} The pane manager
201 * @param data {Mixed} Any object or data passed by the initiator of the view
204 init : function(viewPane
, data
){
205 this.setView(viewPane
);
206 this.setViewSelection(new org
.argeo
.ria
.components
.ViewSelection(viewPane
.getViewId()));
207 this._emptyAgentString
= "Empty Batch (Drop scripts here)";
208 this._crtAgentString
= "Batch Execution on Agent ";
212 * The implementation should contain the real data loading (i.o. query...)
216 this._createLayout();
217 this.getView().setViewTitle(this._emptyAgentString
);
218 //this.getView().setViewTitle("");
222 * Creates the main applet layout.
224 _createLayout : function() {
225 this.listPane
= new qx
.ui
.container
.Composite(new qx
.ui
.layout
.Dock());
226 this.addListener("changeBatchAgentId", function(event
) {
227 var value
= event
.getData();
229 this.getView().setViewTitle(this._emptyAgentString
);
231 var selectorView
= org
.argeo
.ria
.components
.ViewsManager
.getInstance().getViewPaneById("selector").getContent();
233 var agentsMap
= selectorView
.getAgentsMap();
234 this.getView().setViewTitle(this._crtAgentString
+ "'" + agentsMap
[value
] + "'");
239 var indicator
= new qx
.ui
.core
.Widget();
240 indicator
.setDecorator(new qx
.ui
.decoration
.Single().set({
241 top
: [1, "solid", "#33508D"]
243 indicator
.setHeight(0);
244 indicator
.setOpacity(0.5);
245 indicator
.setZIndex(100);
246 indicator
.setLayoutProperties({
250 org
.argeo
.ria
.Application
.INSTANCE
.getRoot().add(indicator
);
252 this.list
= new qx
.ui
.form
.List();
253 this.list
.setDecorator(null);
254 this.list
.setSelectionMode("multi");
255 this.list
.setDroppable(true);
256 this.list
.setDraggable(true);
257 this.list
.setContextMenu(org
.argeo
.ria
.event
.CommandsManager
258 .getInstance().createMenuFromIds(["removefrombatch"]));
260 this.list
.addListener("dragstart", function(e
) {
261 e
.addType(["items"]);
262 e
.addAction(["move"]);
264 this.list
.addListener("dragend", function(e
) {
265 indicator
.setDomPosition(-1000, -1000);
267 this.list
.addListener("dragover", function(e
) {
268 var orig
= e
.getOriginalTarget();
269 var origCoords
= orig
.getContainerLocation();
270 indicator
.setWidth(orig
.getBounds().width
);
271 indicator
.setDomPosition(origCoords
.left
,
274 this.list
.addListener("drag", function(e
) {
275 var orig
= e
.getOriginalTarget();
276 var origCoords
= orig
.getContainerLocation();
277 indicator
.setWidth(orig
.getBounds().width
);
278 indicator
.setDomPosition(origCoords
.left
,
282 this.list
.addListener("drop", function(e
) {
283 var target
= e
.getRelatedTarget();
284 var afterItem
= e
.getOriginalTarget();
285 indicator
.setDomPosition(-1000, -1000);
286 if (afterItem
.classname
!= "qx.ui.form.ListItem")
289 target
= this.list
.getSortedSelection()[0];
290 this.addFlowToBatch(target
, afterItem
);
292 org
.argeo
.ria
.event
.CommandsManager
.getInstance().executeCommand("addtobatch");
295 this.listPane
.add(this.list
, {
299 this.list
.addListener("changeSelection", function(e
) {
300 var viewSelection
= this.getViewSelection();
301 viewSelection
.setViewId("batch:list");
302 viewSelection
.clear();
303 var listSel
= this.list
.getSortedSelection();
304 for (var i
= 0; i
< listSel
.length
; i
++) {
305 viewSelection
.addNode(listSel
[i
]);
309 this.dropDecorator
= new qx
.ui
.decoration
.Background();
310 this.dropDecorator
.set({
311 backgroundImage
: "org.argeo.slc.ria/drophere.gif",
312 backgroundRepeat
: "no-repeat"
316 listChangeListener = function() {
317 var command
= org
.argeo
.ria
.event
.CommandsManager
.getInstance()
318 .getCommandById("submitform");
319 command
.setEnabled(this.list
.hasChildren());
320 var command2
= org
.argeo
.ria
.event
.CommandsManager
.getInstance()
321 .getCommandById("clearbatch");
322 command2
.setEnabled(this.list
.hasChildren());
323 this.list
.setDecorator((this.list
.hasChildren()?null:this.dropDecorator
));
325 this.list
.addListener("addItem", listChangeListener
, this);
326 this.list
.addListener("removeItem", listChangeListener
, this);
328 this.list
.setDecorator(this.dropDecorator
);
330 this.add(this.listPane
);
335 * Adds a given ExecutionFlow to the batch
338 * {mixed} The dropped target, can be a TreeFile (add) or a
339 * ListItem (reorder).
341 * {qx.ui.form.ListItem} Optional list item : if set, the
342 * flow will be added as a new list item positionned after
344 * @param skipAutoOpen
345 * {boolean} Whether the formular should open or not.
347 addFlowToBatch : function(target
, after
, skipAutoOpen
) {
348 if (target
&& target
.classname
== "qx.ui.form.ListItem") {
351 if (after
== "first")
352 this.list
.addAt(target
, 0);
354 this.list
.addAfter(target
, after
);
359 if (qx
.Class
.isSubClassOf(qx
.Class
.getByName(target
.classname
),
360 qx
.ui
.tree
.TreeFolder
)) {
361 var allChildren
= target
.getItems(true);
362 for (var i
= 0; i
< allChildren
.length
; i
++) {
363 if (allChildren
[i
].getUserData("executionFlow")) {
365 this.addFlowToBatch(allChildren
[i
], null, true);
374 // Check agent Uuid against current batch agent Id.
375 var agentUuid
= target
.getUserData("agentUuid");
376 if (!this.getBatchAgentId()) {
377 this.setBatchAgentId(agentUuid
);
378 } else if (this.getBatchAgentId() != agentUuid
) {
379 this.error("Batch can contain tests only of the same agent!");
380 throw new Error("Batch can contain tests only of the same agent!");
383 var executionModule
= target
.getUserData("executionModule");
384 var executionFlow
= target
.getUserData("executionFlow");
385 var batchEntry
= new org
.argeo
.slc
.ria
.execution
.BatchEntrySpec(
386 executionModule
, executionFlow
);
388 this.appendBatchEntrySpec(batchEntry
, target
.getIcon(), after
);
391 appendBatchEntrySpec: function(batchEntrySpec
, icon
, after
){
393 var item
= new qx
.ui
.form
.ListItem(batchEntrySpec
.getLabel(), icon
|| "org.argeo.slc.ria/system.png");
394 item
.setUserData("batchEntrySpec", batchEntrySpec
);
395 item
.setPaddingTop(1);
396 item
.setPaddingBottom(2);
398 if (after
== "first")
399 this.list
.addAt(item
, 0);
401 this.list
.addAfter(item
, after
);
405 this.list
.setSelection([item
]);
410 * Called at execution
413 * {String} The id of the target agent
415 executeBatchOnAgent : function(agentUuid
, clearBatch
) {
416 var selection
= this.list
.getChildren();
417 if (!selection
.length
)
420 var agentsMap
= org
.argeo
.ria
.components
.ViewsManager
.getInstance().getViewPaneById("selector").getContent().getAgentsMap();
421 var host
= agentsMap
[agentUuid
];
422 var slcExecMessage
= new org
.argeo
.slc
.ria
.execution
.Message();
423 slcExecMessage
.setHost(host
);
424 for (var i
= 0; i
< selection
.length
; i
++) {
425 var batchEntrySpec
= selection
[i
].getUserData("batchEntrySpec");
426 slcExecMessage
.addBatchEntrySpec(batchEntrySpec
);
429 var xmlMessage
= slcExecMessage
.toXml();
430 if(!window
.xmlExecStub
){
431 window
.xmlExecStub
= {};
433 window
.xmlExecStub
[slcExecMessage
.getUuid()] = qx
.xml
.Document
.fromString(xmlMessage
);
434 var req
= org
.argeo
.slc
.ria
.SlcApi
.getNewSlcExecutionService(
435 agentUuid
, xmlMessage
);
437 // Force logs refresh right now!
438 qx
.event
.Timer
.once(function() {
439 var command
= org
.argeo
.ria
.event
.CommandsManager
440 .getInstance().getCommandById("reloadlogs");
446 req
.addListener("completed", function(e
){
447 this.list
.removeAll();
448 this.setBatchAgentId(null);
456 clearBatchForAgentId : function(agentId
){
457 if(this.getBatchAgentId() == agentId
){
458 this.list
.removeAll();
459 this.setBatchAgentId(null);
464 * Whether this component is already contained in a scroller (return false) or not (return true).
467 addScroll : function(){return false;},
469 * Called at destruction time
470 * Perform all the clean operations (stopping polling queries, etc.)
472 close : function(){return true;}