]>
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
0574296710dd1943a28b6835353d59ea005593ae
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",
21 * The commands definition Map that will be automatically added and wired to the menubar and toolbar.
22 * See {@link org.argeo.ria.event.CommandsManager#definitions} for the keys to use for defining commands.
27 label
: "Execute Batch",
28 icon
: "org.argeo.slc.ria/media-playback-start.png",
33 callback : function(e
) {
34 if (this.getBatchAgentId()) {
35 this.executeBatchOnAgent(this.getBatchAgentId());
42 label : "Auto edit on Add",
43 icon : "org.argeo.slc.ria/document-open.png",
47 toggleInitialState : true,
50 callback : function(event) {
51 var state = event.getTarget().getUserData("slc.command.toggleState");
52 this.setAutoOpen(state);
56 "editexecutionspecs" : {
57 label : "Edit Execution Specs",
58 icon : "org.argeo.slc.ria/document-open.png",
63 callback : function(e) {
64 var sel = this.list.getSortedSelection();
65 var spec = sel[0].getUserData("batchEntrySpec");
66 if (spec.hasEditableValues()) {
67 var specEditor = new org.argeo.slc.ria.execution.SpecEditor(spec);
68 specEditor.attachAndShow();
71 selectionChange : function(viewId, selection) {
72 if (viewId != "batch:list")
74 this.setEnabled(false);
75 if ((selection && selection.length == 1)) {
76 var selectedItemSpec = selection[0].getUserData("batchEntrySpec");
77 if (selectedItemSpec.hasEditableValues()) {
78 this.setEnabled(true);
86 label
: "Remove from batch",
87 icon
: "org.argeo.slc.ria/edit-delete.png",
92 callback : function(e
) {
93 var sel
= this.list
.getSortedSelection();
94 var confirmPref
= this.getRiaPreferenceValue("slc.batch.delete.confirm");
95 this.debug(confirmPref
);
96 var execution = function() {
97 for (var i
= 0; i
< sel
.length
; i
++) {
98 this.list
.remove(sel
[i
]);
100 if (!this.list
.hasChildren()) {
101 this.setBatchAgentId(null);
105 var modal
= new org
.argeo
.ria
.components
.Modal("Confirm", null);
106 modal
.addConfirm("Are you sure you want to remove<br> the selected test"
107 + (sel
.length
> 1 ? "s" : "")
108 + " from the Batch?");
109 modal
.addListener("ok", execution
, this);
110 modal
.attachAndShow();
112 execution
= qx
.lang
.Function
.bind(execution
, this);
116 selectionChange : function(viewId
, selection
) {
117 if (viewId
!= "batch:list")
119 this.setEnabled(false);
120 if ((selection
&& selection
.length
> 0))
121 this.setEnabled(true);
126 label
: "Clear batch",
127 icon
: "org.argeo.slc.ria/user-trash-full.png",
132 callback : function(e
) {
133 if(!this.list
.hasChildren()) return;
134 this.list
.selectAll();
135 this.getCommands()["removefrombatch"].command
.execute();
137 selectionChange : function(viewId
, selection
) {
148 check
:"org.argeo.ria.components.ViewSelection"
150 instanceId
: {init
:""},
151 instanceLabel
: {init
:""},
153 * A boolean registering whether the SpecEditor must autoOpen or not
154 * when a spec is added to the Batch.
164 event
: "changeBatchAgentId"
168 construct : function(){
169 this.base(arguments
);
170 this.setLayout(new qx
.ui
.layout
.Dock());
175 * The implementation should contain the GUI initialisation.
176 * This is the role of the manager to actually add the graphical component to the pane,
177 * so it's not necessary to do it here.
178 * @param viewPane {org.argeo.ria.components.ViewPane} The pane manager
179 * @param data {Mixed} Any object or data passed by the initiator of the view
182 init : function(viewPane
, data
){
183 this.setView(viewPane
);
184 this.setViewSelection(new org
.argeo
.ria
.components
.ViewSelection(viewPane
.getViewId()));
185 this._emptyAgentString
= "Empty Batch (Drop scripts here)";
186 this._crtAgentString
= "Batch Execution on Agent ";
190 * The implementation should contain the real data loading (i.o. query...)
194 this._createLayout();
195 this.getView().setViewTitle(this._emptyAgentString
);
196 //this.getView().setViewTitle("");
200 * Creates the main applet layout.
202 _createLayout : function() {
203 this.listPane
= new qx
.ui
.container
.Composite(new qx
.ui
.layout
.Dock());
204 this.addListener("changeBatchAgentId", function(event
) {
205 var value
= event
.getData();
207 this.getView().setViewTitle(this._emptyAgentString
);
209 var selectorView
= org
.argeo
.ria
.components
.ViewsManager
.getInstance().getViewPaneById("selector").getContent();
211 var agentsMap
= selectorView
.getAgentsMap();
212 this.getView().setViewTitle(this._crtAgentString
+ "'" + agentsMap
[value
] + "'");
217 var indicator
= new qx
.ui
.core
.Widget();
218 indicator
.setDecorator(new qx
.ui
.decoration
.Single().set({
219 top
: [1, "solid", "#33508D"]
221 indicator
.setHeight(0);
222 indicator
.setOpacity(0.5);
223 indicator
.setZIndex(100);
224 indicator
.setLayoutProperties({
228 org
.argeo
.ria
.Application
.INSTANCE
.getRoot().add(indicator
);
230 this.list
= new qx
.ui
.form
.List();
231 this.list
.setDecorator(null);
232 this.list
.setSelectionMode("multi");
233 this.list
.setDroppable(true);
234 this.list
.setDraggable(true);
235 this.list
.setContextMenu(org
.argeo
.ria
.event
.CommandsManager
236 .getInstance().createMenuFromIds(["removefrombatch"]));
238 this.list
.addListener("dragstart", function(e
) {
239 e
.addType(["items"]);
240 e
.addAction(["move"]);
242 this.list
.addListener("dragend", function(e
) {
243 indicator
.setDomPosition(-1000, -1000);
245 this.list
.addListener("dragover", function(e
) {
246 var orig
= e
.getOriginalTarget();
247 var origCoords
= orig
.getContainerLocation();
248 indicator
.setWidth(orig
.getBounds().width
);
249 indicator
.setDomPosition(origCoords
.left
,
252 this.list
.addListener("drag", function(e
) {
253 var orig
= e
.getOriginalTarget();
254 var origCoords
= orig
.getContainerLocation();
255 indicator
.setWidth(orig
.getBounds().width
);
256 indicator
.setDomPosition(origCoords
.left
,
260 this.list
.addListener("drop", function(e
) {
261 var target
= e
.getRelatedTarget();
262 var afterItem
= e
.getOriginalTarget();
263 indicator
.setDomPosition(-1000, -1000);
264 if (afterItem
.classname
!= "qx.ui.form.ListItem")
267 target
= this.list
.getSortedSelection()[0];
268 this.addFlowToBatch(target
, afterItem
);
270 org
.argeo
.ria
.event
.CommandsManager
.getInstance().executeCommand("addtobatch");
273 this.listPane
.add(this.list
, {
277 this.list
.addListener("changeSelection", function(e
) {
278 var viewSelection
= this.getViewSelection();
279 viewSelection
.setViewId("batch:list");
280 viewSelection
.clear();
281 var listSel
= this.list
.getSortedSelection();
282 for (var i
= 0; i
< listSel
.length
; i
++) {
283 viewSelection
.addNode(listSel
[i
]);
287 this.dropDecorator
= new qx
.ui
.decoration
.Background();
288 this.dropDecorator
.set({
289 backgroundImage
: "org.argeo.slc.ria/drophere.gif",
290 backgroundRepeat
: "no-repeat"
294 listChangeListener = function() {
295 var command
= org
.argeo
.ria
.event
.CommandsManager
.getInstance()
296 .getCommandById("submitform");
297 command
.setEnabled(this.list
.hasChildren());
298 var command2
= org
.argeo
.ria
.event
.CommandsManager
.getInstance()
299 .getCommandById("clearbatch");
300 command2
.setEnabled(this.list
.hasChildren());
301 this.list
.setDecorator((this.list
.hasChildren()?null:this.dropDecorator
));
303 this.list
.addListener("addItem", listChangeListener
, this);
304 this.list
.addListener("removeItem", listChangeListener
, this);
306 this.list
.setDecorator(this.dropDecorator
);
308 this.add(this.listPane
);
313 * Adds a given ExecutionFlow to the batch
316 * {mixed} The dropped target, can be a TreeFile (add) or a
317 * ListItem (reorder).
319 * {qx.ui.form.ListItem} Optional list item : if set, the
320 * flow will be added as a new list item positionned after
322 * @param skipAutoOpen
323 * {boolean} Whether the formular should open or not.
325 addFlowToBatch : function(target
, after
, skipAutoOpen
) {
326 if (target
&& target
.classname
== "qx.ui.form.ListItem") {
329 if (after
== "first")
330 this.list
.addAt(target
, 0);
332 this.list
.addAfter(target
, after
);
337 if (qx
.Class
.isSubClassOf(qx
.Class
.getByName(target
.classname
),
338 qx
.ui
.tree
.TreeFolder
)) {
339 var allChildren
= target
.getItems(true);
340 for (var i
= 0; i
< allChildren
.length
; i
++) {
341 if (allChildren
[i
].getUserData("executionFlow")) {
343 this.addFlowToBatch(allChildren
[i
], null, true);
352 // Check agent Uuid against current batch agent Id.
353 var agentUuid
= target
.getUserData("agentUuid");
354 if (!this.getBatchAgentId()) {
355 this.setBatchAgentId(agentUuid
);
356 } else if (this.getBatchAgentId() != agentUuid
) {
357 this.error("Batch can contain tests only of the same agent!");
358 throw new Error("Batch can contain tests only of the same agent!");
361 var executionModule
= target
.getUserData("executionModule");
362 var executionFlow
= target
.getUserData("executionFlow");
363 var batchEntry
= new org
.argeo
.slc
.ria
.execution
.BatchEntrySpec(
364 executionModule
, executionFlow
);
365 var label
= batchEntry
.getLabel();
366 var icon
= target
.getIcon() || "org.argeo.slc.ria/office-document.png";
367 var item
= new qx
.ui
.form
.ListItem(label
, icon
);
369 item.addListener("dblclick", function(e) {
370 this.getCommands()["editexecutionspecs"].command
374 item
.setUserData("batchEntrySpec", batchEntry
);
375 item
.setPaddingTop(1);
376 item
.setPaddingBottom(2);
378 if (after
== "first")
379 this.list
.addAt(item
, 0);
381 this.list
.addAfter(item
, after
);
385 this.list
.select(item
);
387 if (this.getAutoOpen() && !skipAutoOpen) {
388 this.getCommands()["editexecutionspecs"].command.execute();
394 * Called at execution
397 * {String} The id of the target agent
399 executeBatchOnAgent : function(agentUuid
) {
400 var selection
= this.list
.getChildren();
401 if (!selection
.length
)
403 var slcExecMessage
= new org
.argeo
.slc
.ria
.execution
.Message();
404 for (var i
= 0; i
< selection
.length
; i
++) {
405 var batchEntrySpec
= selection
[i
].getUserData("batchEntrySpec");
406 slcExecMessage
.addBatchEntrySpec(batchEntrySpec
);
409 var xmlMessage
= slcExecMessage
.toXml();
410 var req
= org
.argeo
.slc
.ria
.SlcApi
.getNewSlcExecutionService(
411 agentUuid
, xmlMessage
);
413 // Force logs refresh right now!
414 qx
.event
.Timer
.once(function() {
415 var command
= org
.argeo
.ria
.event
.CommandsManager
416 .getInstance().getCommandById("reloadlogs");
426 clearBatchForAgentId : function(agentId
){
427 if(this.getBatchAgentId() == agentId
){
428 this.list
.removeAll();
429 this.setBatchAgentId(null);
434 * Whether this component is already contained in a scroller (return false) or not (return true).
437 addScroll : function(){return false;},
439 * Called at destruction time
440 * Perform all the clean operations (stopping polling queries, etc.)
442 close : function(){return true;}