123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471 |
- /*##############################################################################
- # 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/_base/lang",
- "dojo/i18n",
- "dojo/i18n!./nls/common",
- "dojo/i18n!./nls/ActivityWidget",
- "dojo/_base/array",
- "dojo/on",
- "dijit/registry",
- "dijit/form/Button",
- "dijit/ToolbarSeparator",
- "dgrid/OnDemandGrid",
- "dgrid/Keyboard",
- "dgrid/Selection",
- "dgrid/selector",
- "dgrid/tree",
- "dgrid/extensions/ColumnResizer",
- "dgrid/extensions/DijitRegistry",
- "hpcc/GridDetailsWidget",
- "hpcc/ESPActivity",
- "hpcc/WUDetailsWidget",
- "hpcc/DFUWUDetailsWidget",
- "hpcc/ESPUtil"
- ], function (declare, lang, i18n, nlsCommon, nlsSpecific, arrayUtil, on,
- registry, Button, ToolbarSeparator,
- OnDemandGrid, Keyboard, Selection, selector, tree, ColumnResizer, DijitRegistry,
- GridDetailsWidget, ESPActivity, WUDetailsWidget, DFUWUDetailsWidget, ESPUtil) {
- return declare("ActivityWidget", [GridDetailsWidget], {
- i18n: lang.mixin(nlsCommon, nlsSpecific),
- gridTitle: nlsSpecific.title,
- idProperty: "Wuid",
- _onPause: function (event, params) {
- arrayUtil.forEach(this.grid.getSelected(), function (item, idx) {
- if (this.activity.isInstanceOfQueue(item)) {
- var context = this;
- item.pause().then(function(response) {
- context._refreshActionState();
- });
- }
- }, this);
- },
- _onResume: function (event, params) {
- arrayUtil.forEach(this.grid.getSelected(), function (item, idx) {
- if (this.activity.isInstanceOfQueue(item)) {
- var context = this;
- item.resume().then(function (response) {
- context._refreshActionState();
- });
- }
- }, this);
- },
- _onClear: function (event, params) {
- arrayUtil.forEach(this.grid.getSelected(), function (item, idx) {
- if (this.activity.isInstanceOfQueue(item)) {
- item.clear();
- }
- }, this);
- this._onRefresh();
- },
- _onWUAbort: function (event, params) {
- arrayUtil.forEach(this.grid.getSelected(), function (item, idx) {
- if (this.activity.isInstanceOfWorkunit(item)) {
- item.abort();
- }
- }, this);
- this._onRefresh();
- },
- _onWUPriority: function (event, priority) {
- arrayUtil.forEach(this.grid.getSelected(), function (item, idx) {
- if (this.activity.isInstanceOfWorkunit(item)) {
- var queue = item.get("ESPQueue");
- if (queue) {
- queue.setPriority(item.Wuid, priority);
- }
- }
- }, this);
- this._onRefresh();
- },
- _onWUTop: function (event, params) {
- var selected = this.grid.getSelected();
- for (var i = selected.length - 1; i >= 0; --i) {
- var item = selected[i];
- if (this.activity.isInstanceOfWorkunit(item)) {
- var queue = item.get("ESPQueue");
- if (queue) {
- queue.moveTop(item.Wuid);
- }
- }
- }
- this._onRefresh();
- },
- _onWUUp: function (event, params) {
- arrayUtil.forEach(this.grid.getSelected(), function (item, idx) {
- if (this.activity.isInstanceOfWorkunit(item)) {
- var queue = item.get("ESPQueue");
- if (queue) {
- queue.moveUp(item.Wuid);
- }
- }
- }, this);
- this._onRefresh();
- },
- _onWUDown: function (event, params) {
- var selected = this.grid.getSelected();
- for (var i = selected.length - 1; i >= 0; --i) {
- var item = selected[i];
- if (this.activity.isInstanceOfWorkunit(item)) {
- var queue = item.get("ESPQueue");
- if (queue) {
- queue.moveDown(item.Wuid);
- }
- }
- }
- this._onRefresh();
- },
- _onWUBottom: function (event, params) {
- arrayUtil.forEach(this.grid.getSelected(), function (item, idx) {
- if (this.activity.isInstanceOfWorkunit(item)) {
- var queue = item.get("ESPQueue");
- if (queue) {
- queue.moveBottom(item.Wuid);
- }
- }
- }, this);
- this._onRefresh();
- },
- doSearch: function (searchText) {
- this.searchText = searchText;
- this.selectChild(this.gridTab);
- this.refreshGrid();
- },
- init: function (params) {
- if (this.inherited(arguments))
- return;
- var context = this;
- this.activity.watch("changedCount", function (item, oldValue, newValue) {
- context.grid.set("query", {});
- context._refreshActionState();
- });
- this._refreshActionState();
- },
- createGrid: function (domID) {
- var context = this;
- this.openButton = registry.byId(this.id + "Open");
- this.clusterPauseButton = new Button({
- id: this.id + "PauseButton",
- label: "Pause",
- onClick: function (event) {
- context._onPause(event);
- }
- }).placeAt(this.openButton.domNode, "before");
- this.clusterResumeButton = new Button({
- id: this.id + "ResumeButton",
- label: "Resume",
- onClick: function (event) {
- context._onResume(event);
- }
- }).placeAt(this.openButton.domNode, "before");
- this.clusterClearButton = new Button({
- id: this.id + "ClearButton",
- label: "Clear",
- onClick: function (event) {
- context._onClear(event);
- }
- }).placeAt(this.openButton.domNode, "before");
- var tmpSplitter = new ToolbarSeparator().placeAt(this.openButton.domNode, "before");
- this.wuMoveBottomButton = new Button({
- id: this.id + "MoveBottomButton",
- label: "Bottom",
- onClick: function (event) {
- context._onWUBottom(event);
- }
- }).placeAt(this.openButton.domNode, "after");
- this.wuMoveDownButton = new Button({
- id: this.id + "MoveDownButton",
- label: "Down",
- onClick: function (event) {
- context._onWUDown(event);
- }
- }).placeAt(this.openButton.domNode, "after");
- this.wuMoveUpButton = new Button({
- id: this.id + "MoveUpButton",
- label: "Up",
- onClick: function (event) {
- context._onWUUp(event);
- }
- }).placeAt(this.openButton.domNode, "after");
- this.wuMoveTopButton = new Button({
- id: this.id + "MoveTopButton",
- label: "Top",
- onClick: function (event) {
- context._onWUTop(event);
- }
- }).placeAt(this.openButton.domNode, "after");
- tmpSplitter = new ToolbarSeparator().placeAt(this.openButton.domNode, "after");
- this.wuLowPriorityButton = new Button({
- id: this.id + "LowPriorityButton",
- label: "Low",
- onClick: function (event) {
- context._onWUPriority(event, "low");
- }
- }).placeAt(this.openButton.domNode, "after");
- this.wuNormalPriorityButton = new Button({
- id: this.id + "NormalPriorityButton",
- label: "Normal",
- onClick: function (event) {
- context._onWUPriority(event, "normal");
- }
- }).placeAt(this.openButton.domNode, "after");
- this.wuHighPriorityButton = new Button({
- id: this.id + "HighPriorityButton",
- label: "High",
- onClick: function (event) {
- context._onWUPriority(event, "high");
- }
- }).placeAt(this.openButton.domNode, "after");
- tmpSplitter = new ToolbarSeparator().placeAt(this.openButton.domNode, "after");
- this.wuAbortButton = new Button({
- id: this.id + "AbortButton",
- label: "Abort",
- onClick: function (event) {
- context._onWUAbort(event);
- }
- }).placeAt(this.openButton.domNode, "after");
- this.noDataMessage = this.i18n.loadingMessage;
- this.activity = ESPActivity.Get();
- var retVal = new declare([OnDemandGrid, Keyboard, Selection, ColumnResizer, DijitRegistry, ESPUtil.GridHelper])({
- allowSelectAll: true,
- deselectOnRefresh: false,
- store: this.activity.getStore(),
- columns: {
- col1: selector({
- width: 27,
- selectorType: 'checkbox',
- sortable: false
- }),
- Priority: {
- renderHeaderCell: function (node) {
- node.innerHTML = "<img src='../files/img/priority.png'>";
- },
- width: 25,
- sortable: false,
- formatter: function (Priority) {
- switch (Priority) {
- case "high":
- return "<img src='../files/img/priority_high.png'>";
- case "low":
- return "<img src='../files/img/priority_low.png'>";
- }
- return "";
- }
- },
- DisplayName: tree({
- label: this.i18n.Target,
- width: 270,
- sortable: true,
- shouldExpand: function (row, level, previouslyExpanded) {
- return true;
- },
- formatter: function (_name, row) {
- var img;
- var name = "";
- if (context.activity.isInstanceOfQueue(row)) {
- if (row.isPaused()) {
- img += "/esp/files/img/server_paused.png";
- } else {
- img += "/esp/files/img/server.png";
- }
- name = row.getDisplayName();
- } else {
- img = row.getStateImage();
- name = "<a href='#' class='" + context.id + "WuidClick'>" + row.Wuid + "</a>";
- }
- return "<img src='" + img + "'/> " + name;
- }
- }),
- State: {
- label: this.i18n.State,
- sortable: true,
- formatter: function (state, row) {
- if (context.activity.isInstanceOfQueue(row)) {
- if (row.isPaused()) {
- return row.StatusDetails;
- }
- return "";
- }
- if (row.Duration) {
- return state + " (" + row.Duration + ")";
- } else if (row.Instance && state.indexOf(row.Instance) === -1) {
- return state + " [" + row.Instance + "]";
- }
- return state;
- }
- },
- Owner: { label: this.i18n.Owner, width: 90, sortable: true },
- Jobname: { label: this.i18n.JobName, sortable: true }
- },
- getSelected: function () {
- var retVal = [];
- for (var id in this.selection) {
- var item = context.activity.resolve(id)
- if (item) {
- retVal.push(item);
- }
- }
- return retVal;
- }
- }, domID);
- on(document, "." + this.id + "WuidClick:click", function (evt) {
- if (context._onRowDblClick) {
- var row = retVal.row(evt).data;
- context._onRowDblClick(row);
- }
- });
- return retVal;
- },
- createDetail: function (id, row, params) {
- if (this.activity.isInstanceOfQueue(row)) {
- } else if (this.activity.isInstanceOfWorkunit(row)) {
- if (row.Server === "DFUserver") {
- return new DFUWUDetailsWidget.fixCircularDependency({
- id: id,
- title: row.ID,
- closable: true,
- hpcc: {
- params: {
- Wuid: row.ID
- }
- }
- });
- }
- return new WUDetailsWidget({
- id: id,
- title: row.Wuid,
- closable: true,
- hpcc: {
- params: {
- Wuid: row.Wuid
- }
- }
- });
- }
- return null;
- },
- loadRunning: function (response) {
- var items = lang.getObject("ActivityResponse.Running", false, response)
- if (items) {
- var context = this;
- arrayUtil.forEach(items, function (item, idx) {
- context.store.add({
- id: "ActivityRunning" + idx,
- ClusterName: item.ClusterName,
- Wuid: item.Wuid,
- Owner: item.Owner,
- Jobname: item.Owner,
- Summary: item.Name + " (" + prefix + ")",
- _type: "LogicalFile",
- _name: item.Name
- });
- });
- return items.length;
- }
- return 0;
- },
- refreshGrid: function (args) {
- this.activity.refresh();
- },
- refreshActionState: function (selection) {
- var clusterSelected = false;
- var wuSelected = false;
- var clusterPausedSelected = false;
- var clusterNotPausedSelected = false;
- var clusterHasItems = false;
- var wuCanHigh = false;
- var wuCanNormal = false;
- var wuCanLow = false;
- var wuCanUp = false;
- var wuCanDown = false;
- var context = this;
- arrayUtil.forEach(selection, function (item, idx) {
- if (context.activity.isInstanceOfQueue(item)) {
- clusterSelected = true;
- if (item.isPaused()) {
- clusterPausedSelected = true;
- } else {
- clusterNotPausedSelected = true;
- }
- if (item.getChildCount()) {
- clusterHasItems = true;
- }
- } else if (context.activity.isInstanceOfWorkunit(item)) {
- wuSelected = true;
- var queue = item.get("ESPQueue");
- if (queue) {
- if (queue.canChildMoveUp(item.__hpcc_id)) {
- wuCanUp = true;
- }
- if (queue.canChildMoveDown(item.__hpcc_id)) {
- wuCanDown = true;
- }
- }
- if (item.get("Priority") !== "high") {
- wuCanHigh = true;
- }
- if (item.get("Priority") !== "normal") {
- wuCanNormal = true;
- }
- if (item.get("Priority") !== "low") {
- wuCanLow = true;
- }
- }
- });
- this.clusterPauseButton.set("disabled", !clusterNotPausedSelected);
- this.clusterResumeButton.set("disabled", !clusterPausedSelected);
- this.clusterClearButton.set("disabled", !clusterHasItems);
- this.openButton.set("disabled", !wuSelected);
- this.wuAbortButton.set("disabled", !wuSelected);
- this.wuHighPriorityButton.set("disabled", !wuCanHigh);
- this.wuNormalPriorityButton.set("disabled", !wuCanNormal);
- this.wuLowPriorityButton.set("disabled", !wuCanLow);
- this.wuMoveTopButton.set("disabled", !wuCanUp);
- this.wuMoveUpButton.set("disabled", !wuCanUp);
- this.wuMoveDownButton.set("disabled", !wuCanDown);
- this.wuMoveBottomButton.set("disabled", !wuCanDown);
- }
- });
- });
|