123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353 |
- /*##############################################################################
- # HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
- #
- # Licensed under the Apache License, Version 2.0 (the "License");
- # you may not use this file except in compliance with the License.
- # You may obtain a copy of the License at
- #
- # http://www.apache.org/licenses/LICENSE-2.0
- #
- # Unless required by applicable law or agreed to in writing, software
- # distributed under the License is distributed on an "AS IS" BASIS,
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- # See the License for the specific language governing permissions and
- # limitations under the License.
- ############################################################################## */
- define([
- "dojo/_base/declare",
- "dojo/dom",
- "dojo/data/ObjectStore",
- "dojo/date",
- "dojo/on",
- "dijit/layout/_LayoutWidget",
- "dijit/_TemplatedMixin",
- "dijit/_WidgetsInTemplateMixin",
- "dijit/registry",
- "dojox/grid/EnhancedGrid",
- "dojox/grid/enhanced/plugins/Pagination",
- "dojox/grid/enhanced/plugins/IndirectSelection",
- "hpcc/FileSpray",
- "hpcc/DFUWUDetailsWidget",
- "dojo/text!../templates/GetDFUWorkunitsWidget.html",
- "dijit/layout/BorderContainer",
- "dijit/layout/TabContainer",
- "dijit/layout/ContentPane",
- "dijit/form/Textarea",
- "dijit/form/DateTextBox",
- "dijit/form/TimeTextBox",
- "dijit/form/Button",
- "dijit/form/Select",
- "dijit/Toolbar",
- "dijit/TooltipDialog"
- ], function (declare, dom, ObjectStore, date, on,
- _LayoutWidget, _TemplatedMixin, _WidgetsInTemplateMixin, registry,
- EnhancedGrid, Pagination, IndirectSelection,
- FileSpray, DFUWUDetailsWidget,
- template) {
- return declare("GetDFUWorkunitsWidget", [_LayoutWidget, _TemplatedMixin, _WidgetsInTemplateMixin], {
- templateString: template,
- baseClass: "GetDFUWorkunitsWidget",
- borderContainer: null,
- tabContainer: null,
- workunitsGrid: null,
- legacyPane: null,
- legacyPaneLoaded: false,
- tabMap: [],
- buildRendering: function (args) {
- this.inherited(arguments);
- },
- postCreate: function (args) {
- this.inherited(arguments);
- this.borderContainer = registry.byId(this.id + "BorderContainer");
- this.tabContainer = registry.byId(this.id + "TabContainer");
- this.workunitsGrid = registry.byId(this.id + "WorkunitsGrid");
- this.legacyPane = registry.byId(this.id + "Legacy");
- var context = this;
- this.tabContainer.watch("selectedChildWidget", function (name, oval, nval) {
- if (nval.id == context.id + "Workunits") {
- } else if (nval.id == context.id + "Legacy") {
- if (!context.legacyPaneLoaded) {
- context.legacyPaneLoaded = true;
- context.legacyPane.set("content", dojo.create("iframe", {
- src: "/FileSpray/GetDFUWorkunits",
- style: "border: 0; width: 100%; height: 100%"
- }));
- }
- } else {
- if (!nval.initalized) {
- nval.init(nval.params);
- }
- }
- context.selectedTab = nval;
- });
- },
- startup: function (args) {
- this.inherited(arguments);
- this.refreshActionState();
- this.initWorkunitsGrid();
- },
- resize: function (args) {
- this.inherited(arguments);
- this.borderContainer.resize();
- },
- layout: function (args) {
- this.inherited(arguments);
- },
- destroy: function (args) {
- this.inherited(arguments);
- },
- // Hitched actions ---
- _onOpen: function (event) {
- var selections = this.workunitsGrid.selection.getSelected();
- for (var i = selections.length - 1; i >= 0; --i) {
- this.ensurePane(selections[i].ID, {
- Wuid: selections[i].ID
- });
- }
- },
- _onDelete: function (event) {
- if (confirm('Delete selected workunits?')) {
- var context = this;
- FileSpray.WUAction(this.workunitsGrid.selection.getSelected(), "Delete", {
- load: function (response) {
- context.workunitsGrid.rowSelectCell.toggleAllSelection(false);
- context.refreshGrid(response);
- }
- });
- }
- },
- _onSetToFailed: function (event) {
- var context = this;
- FileSpray.WUAction(this.workunitsGrid.selection.getSelected(), "SetToFailed", {
- load: function (response) {
- context.refreshGrid(response);
- }
- });
- },
- _onProtect: function (event) {
- var context = this;
- FileSpray.WUAction(this.workunitsGrid.selection.getSelected(), "Protect", {
- load: function (response) {
- context.refreshGrid(response);
- }
- });
- },
- _onUnprotect: function (event) {
- var context = this;
- FileSpray.WUAction(this.workunitsGrid.selection.getSelected(), "Unprotect", {
- load: function (response) {
- context.refreshGrid(response);
- }
- });
- },
- _onFilterApply: function (event) {
- this.workunitsGrid.rowSelectCell.toggleAllSelection(false);
- this.refreshGrid();
- },
- _onFilterClear: function(event) {
- this.workunitsGrid.rowSelectCell.toggleAllSelection(false);
- dom.byId(this.id + "Owner").value = "";
- dom.byId(this.id + "Jobname").value = "";
- dom.byId(this.id + "Cluster").value = "";
- dom.byId(this.id + "State").value = "";
- dom.byId(this.id + "ECL").value = "";
- dom.byId(this.id + "LogicalFile").value = "";
- dom.byId(this.id + "LogicalFileSearchType").value = "";
- dom.byId(this.id + "FromDate").value = "";
- dom.byId(this.id + "FromTime").value = "";
- dom.byId(this.id + "ToDate").value = "";
- dom.byId(this.id + "LastNDays").value = "";
- this.refreshGrid();
- },
- getFilter: function () {
- var retVal = {
- Owner: dom.byId(this.id + "Owner").value,
- Jobname: dom.byId(this.id + "Jobname").value,
- Cluster: dom.byId(this.id + "Cluster").value,
- State: dom.byId(this.id + "State").value,
- ECL: dom.byId(this.id + "ECL").value,
- LogicalFile: dom.byId(this.id + "LogicalFile").value,
- LogicalFileSearchType: registry.byId(this.id + "LogicalFileSearchType").get("value"),
- StartDate: this.getISOString("FromDate", "FromTime"),
- EndDate: this.getISOString("ToDate", "ToTime"),
- LastNDays: dom.byId(this.id + "LastNDays").value
- };
- if (retVal.StartDate != "" && retVal.EndDate != "") {
- retVal["DateRB"] = "0";
- } else if (retVal.LastNDays != "") {
- retVal["DateRB"] = "0";
- var now = new Date();
- retVal.StartDate = date.add(now, "day", dom.byId(this.id + "LastNDays").value * -1).toISOString();
- retVal.EndDate = now.toISOString();
- }
- return retVal;
- },
- getISOString: function (dateField, timeField) {
- var d = registry.byId(this.id + dateField).attr("value");
- var t = registry.byId(this.id + timeField).attr("value");
- if (d) {
- if (t) {
- d.setHours(t.getHours());
- d.setMinutes(t.getMinutes());
- d.setSeconds(t.getSeconds());
- }
- return d.toISOString();
- }
- return "";
- },
- // Implementation ---
- init: function (params) {
- },
- initWorkunitsGrid: function() {
- this.workunitsGrid.setStructure([
- {
- name: "P",
- field: "isProtected",
- width: "20px",
- formatter: function (_protected) {
- if (_protected == true) {
- return "P";
- }
- return "";
- }
- },
- { name: "ID", field: "ID", width: "12" },
- {
- name: "Type",
- field: "Command",
- width: "8",
- formatter: function (command) {
- switch (command) {
- case 1: return "Copy";
- case 2: return "Remove";
- case 3: return "Move";
- case 4: return "Rename";
- case 5: return "Replicate";
- case 6: return "Spray";
- case 7: return "Despray";
- case 8: return "Add";
- case 9: return "Transfer";
- case 10: return "Save Map";
- case 11: return "Add Group";
- case 12: return "Server";
- case 13: return "Monitor";
- case 14: return "Copy Merge";
- case 15: return "Super Copy";
- }
- return "Unknown";
- }
- },
- { name: "Owner", field: "Owner", width: "8" },
- { name: "Job Name", field: "JobName", width: "16" },
- { name: "Cluster", field: "ClusterName", width: "8" },
- { name: "State", field: "StateMessage", width: "8" },
- { name: "% Complete", field: "PercentDone", width: "8" }
- ]);
- var store = new FileSpray.GetDFUWorkunits();
- var objStore = new ObjectStore({ objectStore: store });
- this.workunitsGrid.setStore(objStore);
- this.workunitsGrid.setQuery(this.getFilter());
- var context = this;
- this.workunitsGrid.on("RowDblClick", function (evt) {
- if (context.onRowDblClick) {
- var idx = evt.rowIndex;
- var item = this.getItem(idx);
- var id = this.store.getValue(item, "ID");
- context.onRowDblClick(id);
- }
- }, true);
- dojo.connect(this.workunitsGrid.selection, 'onSelected', function (idx) {
- context.refreshActionState();
- });
- dojo.connect(this.workunitsGrid.selection, 'onDeselected', function (idx) {
- context.refreshActionState();
- });
- this.workunitsGrid.startup();
- },
- refreshGrid: function (args) {
- this.workunitsGrid.setQuery(this.getFilter());
- var context = this;
- setTimeout(function () {
- context.refreshActionState()
- }, 200);
- },
- refreshActionState: function () {
- var selection = this.workunitsGrid.selection.getSelected();
- var hasSelection = false;
- var hasProtected = false;
- var hasNotProtected = false;
- var hasFailed = false;
- var hasNotFailed = false;
- for (var i = 0; i < selection.length; ++i) {
- hasSelection = true;
- if (selection[i] && selection[i].isProtected && selection[i].isProtected != "0") {
- hasProtected = true;
- } else {
- hasNotProtected = true;
- }
- if (selection[i] && selection[i].State && selection[i].State == "5") {
- hasFailed = true;
- } else {
- hasNotFailed = true;
- }
- }
- registry.byId(this.id + "Open").set("disabled", !hasSelection);
- registry.byId(this.id + "Delete").set("disabled", !hasNotProtected);
- registry.byId(this.id + "SetToFailed").set("disabled", !hasNotProtected);
- registry.byId(this.id + "Protect").set("disabled", !hasNotProtected);
- registry.byId(this.id + "Unprotect").set("disabled", !hasProtected);
- },
- ensurePane: function (id, params) {
- var retVal = this.tabMap[id];
- if (!retVal) {
- var context = this;
- retVal = new DFUWUDetailsWidget({
- Wuid: id,
- title: id,
- closable: true,
- onClose: function () {
- delete context.tabMap[id];
- return true;
- },
- params: params
- });
- this.tabMap[id] = retVal;
- this.tabContainer.addChild(retVal, 2);
- }
- return retVal;
- },
- onRowDblClick: function (id) {
- var wuTab = this.ensurePane(id, {
- Wuid: id
- });
- this.tabContainer.selectChild(wuTab);
- }
- });
- });
|