123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337 |
- /*##############################################################################
- # 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/WsWorkunits",
- "hpcc/WUDetailsWidget",
- "dojo/text!../templates/WUQueryWidget.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,
- WsWorkunits, WUDetailsWidget,
- template) {
- return declare("WUQueryWidget", [_LayoutWidget, _TemplatedMixin, _WidgetsInTemplateMixin], {
- templateString: template,
- baseClass: "WUQueryWidget",
- 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: "/WsWorkunits/WUQuery",
- 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].Wuid, {
- Wuid: selections[i].Wuid
- });
- }
- },
- _onDelete: function (event) {
- if (confirm('Delete selected workunits?')) {
- var context = this;
- WsWorkunits.WUAction(this.workunitsGrid.selection.getSelected(), "Delete", {
- load: function (response) {
- context.workunitsGrid.rowSelectCell.toggleAllSelection(false);
- context.refreshGrid(response);
- }
- });
- }
- },
- _onSetToFailed: function (event) {
- var context = this;
- WsWorkunits.WUAction(this.workunitsGrid.selection.getSelected(), "SetToFailed", {
- load: function (response) {
- context.refreshGrid(response);
- }
- });
- },
- _onProtect: function (event) {
- var context = this;
- WsWorkunits.WUAction(this.workunitsGrid.selection.getSelected(), "Protect", {
- load: function (response) {
- context.refreshGrid(response);
- }
- });
- },
- _onUnprotect: function (event) {
- var context = this;
- WsWorkunits.WUAction(this.workunitsGrid.selection.getSelected(), "Unprotect", {
- load: function (response) {
- context.refreshGrid(response);
- }
- });
- },
- _onReschedule: function (event) {
- },
- _onDeschedule: function (event) {
- },
- _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) {
- if (params.Wuid) {
- }
- },
- initWorkunitsGrid: function() {
- this.workunitsGrid.setStructure([
- {
- name: "P",
- field: "Protected",
- width: "20px",
- formatter: function (protected) {
- if (protected == true) {
- return "P";
- }
- return "";
- }
- },
- { name: "Wuid", field: "Wuid", width: "12" },
- { name: "Owner", field: "Owner", width: "8" },
- { name: "Job Name", field: "Jobname", width: "16" },
- { name: "Cluster", field: "Cluster", width: "8" },
- { name: "Roxie Cluster", field: "RoxieCluster", width: "8" },
- { name: "State", field: "State", width: "8" },
- { name: "Total Thor Time", field: "TotalThorTime", width: "8" }
- ]);
- var store = new WsWorkunits.WUQuery();
- 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 Wuid = this.store.getValue(item, "Wuid");
- context.onRowDblClick(Wuid);
- }
- }, 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].Protected && selection[i].Protected != "0") {
- hasProtected = true;
- } else {
- hasNotProtected = true;
- }
- if (selection[i] && selection[i].StateID && selection[i].StateID == "4") {
- 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);
- registry.byId(this.id + "Reschedule").set("disabled", true); //TODO
- registry.byId(this.id + "Deschedule").set("disabled", true); //TODO
- },
- ensurePane: function (id, params) {
- var retVal = this.tabMap[id];
- if (!retVal) {
- var context = this;
- retVal = new WUDetailsWidget({
- id: 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 (wuid) {
- var wuTab = this.ensurePane(wuid, {
- Wuid: wuid
- });
- this.tabContainer.selectChild(wuTab);
- }
- });
- });
|