+++ /dev/null
-/**\r
- * Applet for the batch manager\r
- */\r
-qx.Class.define("org.argeo.slc.ria.BatchView",\r
-{\r
- extend : qx.ui.container.Composite,\r
- implement : [org.argeo.ria.components.IView], \r
- include : [org.argeo.ria.session.MPrefHolder],\r
- statics : {\r
- riaPreferences : {\r
- "slc.batch.delete.confirm" : {\r
- label : "Confirm on batch deletion",\r
- type : "boolean",\r
- defaultValue : true\r
- },\r
- "slc.batch.autoclear" : {\r
- label : "Autoclear batch on execution",\r
- type : "boolean",\r
- defaultValue : false\r
- },\r
- "slc.batch.autoOpenLog" : {\r
- label : "Auto open log on execution",\r
- type : "boolean",\r
- defaultValue : true \r
- }\r
- }\r
- },\r
- properties : \r
- {\r
- /**\r
- * The commands definition Map that will be automatically added and wired to the menubar and toolbar.\r
- * See {@link org.argeo.ria.event.CommandsManager#definitions} for the keys to use for defining commands.\r
- */\r
- commands : {\r
- init : {\r
- "submitform" : {\r
- label : "Execute Batch",\r
- icon : "org/argeo/slc/ria/media-playback-start.png",\r
- shortcut : null,\r
- enabled : false,\r
- menu : "Launcher",\r
- toolbar : "batch",\r
- callback : function(e) {\r
- var batchAgentId = this.getBatchAgentId();\r
- if (!batchAgentId) {\r
- return; \r
- }\r
- var prefName = "slc.batch.autoclear";\r
- var prefValue = this.getRiaPreferenceValue(prefName);\r
- if(( prefValue !== null && prefValue === true ) || this.getForceClearPreference()){\r
- this.executeBatchOnAgent(batchAgentId, true); \r
- }else{\r
- this.executeBatchOnAgent(batchAgentId, false);\r
- }\r
- this.setForceClearPreference(false);\r
- return;\r
- },\r
- command : null\r
- },\r
- "removefrombatch" : {\r
- label : "Remove from batch",\r
- icon : "org/argeo/slc/ria/edit-delete.png",\r
- shortcut : null,\r
- enabled : false,\r
- menu : "Launcher",\r
- toolbar : "batch",\r
- callback : function(e) {\r
- var sel = this.list.getSortedSelection();\r
- var confirmPref = this.getRiaPreferenceValue("slc.batch.delete.confirm"); \r
- var execution = function() {\r
- for (var i = 0; i < sel.length; i++) {\r
- this.list.remove(sel[i]);\r
- }\r
- if (!this.list.hasChildren()) {\r
- this.setBatchAgentId(null);\r
- }\r
- }\r
- if(confirmPref){\r
- var modal = new org.argeo.ria.components.Modal("Confirm", null);\r
- modal.addConfirm("Are you sure you want to remove<br> the selected test"\r
- + (sel.length > 1 ? "s" : "")\r
- + " from the Batch?");\r
- modal.addListener("ok", execution, this);\r
- modal.attachAndShow();\r
- }else{\r
- execution = qx.lang.Function.bind(execution, this);\r
- execution();\r
- }\r
- },\r
- selectionChange : function(viewId, selection) {\r
- if (viewId != "batch:list")\r
- return;\r
- this.setEnabled(false);\r
- if ((selection && selection.length > 0))\r
- this.setEnabled(true);\r
- },\r
- command : null\r
- },\r
- "clearbatch" : {\r
- label : "Clear batch",\r
- icon : "org/argeo/slc/ria/user-trash-full.png",\r
- shortcut : null,\r
- enabled : true,\r
- menu : "Launcher",\r
- toolbar : "batch",\r
- callback : function(e) {\r
- if(!this.list.hasChildren()) return;\r
- this.list.selectAll();\r
- this.getCommands()["removefrombatch"].command.execute();\r
- },\r
- selectionChange : function(viewId, selection) {\r
- },\r
- command : null\r
- } \r
- }\r
- },\r
- view : {\r
- init : null\r
- }, \r
- viewSelection : {\r
- nullable:false, \r
- check:"org.argeo.ria.components.ViewSelection"\r
- },\r
- instanceId : {init:""},\r
- instanceLabel : {init:""},\r
- /**\r
- * A boolean registering whether the SpecEditor must autoOpen or not\r
- * when a spec is added to the Batch.\r
- */\r
- autoOpen : {\r
- init : true,\r
- check : "Boolean"\r
- },\r
- batchAgentId : {\r
- init : null,\r
- nullable : true,\r
- check : "String",\r
- event : "changeBatchAgentId"\r
- },\r
- forceClearPreference : {\r
- init : false,\r
- check : "Boolean"\r
- }\r
- },\r
- \r
- construct : function(){\r
- this.base(arguments);\r
- this.setLayout(new qx.ui.layout.Dock()); \r
- },\r
- \r
- members : {\r
- /**\r
- * The implementation should contain the GUI initialisation.\r
- * This is the role of the manager to actually add the graphical component to the pane, \r
- * so it's not necessary to do it here. \r
- * @param viewPane {org.argeo.ria.components.ViewPane} The pane manager\r
- * @param data {Mixed} Any object or data passed by the initiator of the view\r
- * @return {Boolean}\r
- */\r
- init : function(viewPane, data){\r
- this.setView(viewPane); \r
- this.setViewSelection(new org.argeo.ria.components.ViewSelection(viewPane.getViewId())); \r
- this._emptyAgentString = "Empty Batch (Drop scripts here)";\r
- this._crtAgentString = "Batch Execution on Agent ";\r
- \r
- },\r
- /**\r
- * The implementation should contain the real data loading (i.o. query...)\r
- * @return {Boolean}\r
- */\r
- load : function(){\r
- this._createLayout();\r
- this.getView().setViewTitle(this._emptyAgentString);\r
- //this.getView().setViewTitle("");\r
- },\r
- \r
- /**\r
- * Creates the main applet layout.\r
- */\r
- _createLayout : function() {\r
- this.listPane = new qx.ui.container.Composite(new qx.ui.layout.Dock());\r
- this.addListener("changeBatchAgentId", function(event) {\r
- var value = event.getData();\r
- if (value == null) {\r
- this.getView().setViewTitle(this._emptyAgentString);\r
- } else {\r
- var selectorView = org.argeo.ria.components.ViewsManager.getInstance().getViewPaneById("selector").getContent();\r
- if(selectorView){\r
- var agentsMap = selectorView.getAgentsMap();\r
- this.getView().setViewTitle(this._crtAgentString + "'" + agentsMap[value] + "'");\r
- }\r
- }\r
- }, this);\r
- \r
- var indicator = new qx.ui.core.Widget();\r
- indicator.setDecorator(new qx.ui.decoration.Single().set({\r
- top : [1, "solid", "#33508D"]\r
- }));\r
- indicator.setHeight(0);\r
- indicator.setOpacity(0.5);\r
- indicator.setZIndex(100);\r
- indicator.setLayoutProperties({\r
- left : -1000,\r
- top : -1000\r
- });\r
- org.argeo.ria.Application.INSTANCE.getRoot().add(indicator);\r
-\r
- this.list = new qx.ui.form.List();\r
- this.list.setDecorator(null);\r
- this.list.setSelectionMode("multi");\r
- this.list.setDroppable(true);\r
- this.list.setDraggable(true);\r
- this.list.setContextMenu(org.argeo.ria.event.CommandsManager\r
- .getInstance().createMenuFromIds(["removefrombatch"]));\r
-\r
- this.list.addListener("dragstart", function(e) {\r
- e.addType(["items"]);\r
- e.addAction(["move"]);\r
- }, this);\r
- this.list.addListener("dragend", function(e) {\r
- indicator.setDomPosition(-1000, -1000);\r
- });\r
- this.list.addListener("dragover", function(e) {\r
- var orig = e.getOriginalTarget();\r
- var origCoords = orig.getContainerLocation();\r
- indicator.setWidth(orig.getBounds().width);\r
- indicator.setDomPosition(origCoords.left,\r
- origCoords.bottom);\r
- });\r
- this.list.addListener("drag", function(e) {\r
- var orig = e.getOriginalTarget();\r
- var origCoords = orig.getContainerLocation();\r
- indicator.setWidth(orig.getBounds().width);\r
- indicator.setDomPosition(origCoords.left,\r
- origCoords.bottom);\r
- });\r
-\r
- this.list.addListener("drop", function(e) {\r
- var target = e.getRelatedTarget();\r
- var afterItem = e.getOriginalTarget();\r
- indicator.setDomPosition(-1000, -1000);\r
- if (afterItem.classname != "qx.ui.form.ListItem")\r
- afterItem = null;\r
- if (!target) {\r
- target = this.list.getSortedSelection()[0];\r
- this.addFlowToBatch(target, afterItem);\r
- } else {\r
- org.argeo.ria.event.CommandsManager.getInstance().executeCommand("addtobatch");\r
- }\r
- }, this);\r
- this.listPane.add(this.list, {\r
- edge : "center"\r
- });\r
-\r
- this.list.addListener("changeSelection", function(e) {\r
- var viewSelection = this.getViewSelection();\r
- viewSelection.setViewId("batch:list");\r
- viewSelection.clear();\r
- var listSel = this.list.getSortedSelection();\r
- for (var i = 0; i < listSel.length; i++) {\r
- viewSelection.addNode(listSel[i]);\r
- }\r
- }, this);\r
-\r
- this.dropDecorator = new qx.ui.decoration.Background(); \r
- this.dropDecorator.set({\r
- backgroundImage : "org/argeo/slc/ria/drophere.gif",\r
- backgroundRepeat : "no-repeat"\r
- });\r
-\r
- \r
- listChangeListener = function() {\r
- var command = org.argeo.ria.event.CommandsManager.getInstance()\r
- .getCommandById("submitform");\r
- command.setEnabled(this.list.hasChildren());\r
- var command2 = org.argeo.ria.event.CommandsManager.getInstance()\r
- .getCommandById("clearbatch");\r
- command2.setEnabled(this.list.hasChildren());\r
- this.list.setDecorator((this.list.hasChildren()?null:this.dropDecorator));\r
- };\r
- this.list.addListener("addItem", listChangeListener, this);\r
- this.list.addListener("removeItem", listChangeListener, this);\r
- \r
- this.list.setDecorator(this.dropDecorator);\r
- \r
- this.add(this.listPane);\r
- }, \r
- \r
- \r
- /**\r
- * Adds a given ExecutionFlow to the batch\r
- * \r
- * @param target\r
- * {mixed} The dropped target, can be a TreeFile (add) or a\r
- * ListItem (reorder).\r
- * @param after\r
- * {qx.ui.form.ListItem} Optional list item : if set, the\r
- * flow will be added as a new list item positionned after\r
- * this one.\r
- * @param skipAutoOpen\r
- * {boolean} Whether the formular should open or not.\r
- */\r
- addFlowToBatch : function(target, after, skipAutoOpen) {\r
- if (target && target.classname == "qx.ui.form.ListItem") {\r
- if (!after)\r
- return;\r
- if (after == "first")\r
- this.list.addAt(target, 0);\r
- else\r
- this.list.addAfter(target, after);\r
- return;\r
- }\r
-\r
- // Folder case\r
- if (qx.Class.isSubClassOf(qx.Class.getByName(target.classname),\r
- qx.ui.tree.TreeFolder)) {\r
- var allChildren = target.getItems(true);\r
- for (var i = 0; i < allChildren.length; i++) {\r
- if (allChildren[i].getUserData("executionFlow")) {\r
- try{\r
- this.addFlowToBatch(allChildren[i], null, true);\r
- }catch(e){\r
- return;\r
- }\r
- }\r
- }\r
- return;\r
- }\r
-\r
- // Check agent Uuid against current batch agent Id.\r
- var agentUuid = target.getUserData("agentUuid");\r
- if (!this.getBatchAgentId()) {\r
- this.setBatchAgentId(agentUuid);\r
- } else if (this.getBatchAgentId() != agentUuid) {\r
- this.error("Batch can contain tests only of the same agent!"); \r
- throw new Error("Batch can contain tests only of the same agent!");\r
- }\r
-\r
- var executionModule = target.getUserData("executionModule");\r
- var executionFlow = target.getUserData("executionFlow");\r
- var batchEntry = new org.argeo.slc.ria.execution.BatchEntrySpec(\r
- executionModule, executionFlow);\r
-\r
- this.appendBatchEntrySpec(batchEntry, target.getIcon(), after); \r
- },\r
- \r
- appendBatchEntrySpec: function(batchEntrySpec, icon, after){\r
- \r
- var item = new qx.ui.form.ListItem(batchEntrySpec.getLabel(), icon || "org/argeo/slc/ria/system.png");\r
- item.setUserData("batchEntrySpec", batchEntrySpec);\r
- item.setPaddingTop(1);\r
- item.setPaddingBottom(2);\r
- if (after) {\r
- if (after == "first")\r
- this.list.addAt(item, 0);\r
- else\r
- this.list.addAfter(item, after);\r
- } else {\r
- this.list.add(item);\r
- }\r
- this.list.setSelection([item]);\r
- \r
- },\r
-\r
- /**\r
- * Called at execution\r
- * \r
- * @param agentUuid\r
- * {String} The id of the target agent\r
- */\r
- executeBatchOnAgent : function(agentUuid, clearBatch) {\r
- var selection = this.list.getChildren();\r
- if (!selection.length)\r
- return;\r
- // Get Host\r
- var agentsMap = org.argeo.ria.components.ViewsManager.getInstance().getViewPaneById("selector").getContent().getAgentsMap();\r
- var host = agentsMap[agentUuid];\r
- var slcExecMessage = new org.argeo.slc.ria.execution.Message();\r
- slcExecMessage.setHost(host);\r
- var execUuid = slcExecMessage.getUuid();\r
- for (var i = 0; i < selection.length; i++) {\r
- var batchEntrySpec = selection[i].getUserData("batchEntrySpec");\r
- slcExecMessage.addBatchEntrySpec(batchEntrySpec);\r
- }\r
- try{\r
- var xmlMessage = slcExecMessage.toXml();\r
- var req = org.argeo.slc.ria.SlcApi.getNewSlcExecutionService(\r
- agentUuid, xmlMessage);\r
- req.addListener("completed", function(response){\r
- var loggerView = org.argeo.ria.components.ViewsManager.getInstance().getViewPaneById("main").getContent();\r
- loggerView.reloadLogger();\r
- if(this.getRiaPreferenceValue("slc.batch.autoOpenLog")){\r
- loggerView.openDetail([0,host,execUuid,0]);\r
- }\r
- }, this);\r
- req.send();\r
- if(clearBatch){\r
- req.addListener("completed", function(e){\r
- this.list.removeAll();\r
- this.setBatchAgentId(null);\r
- }, this);\r
- } \r
- }catch(e){\r
- this.error(e); \r
- }\r
- },\r
- \r
- clearBatchForAgentId : function(agentId){\r
- if(this.getBatchAgentId() == agentId){\r
- this.list.removeAll(); \r
- this.setBatchAgentId(null);\r
- }\r
- },\r
- \r
- /**\r
- * Whether this component is already contained in a scroller (return false) or not (return true).\r
- * @return {Boolean}\r
- */\r
- addScroll : function(){return false;},\r
- /**\r
- * Called at destruction time\r
- * Perform all the clean operations (stopping polling queries, etc.) \r
- */\r
- close : function(){return true;}\r
- }\r
- \r
-\r
-});
\ No newline at end of file