123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508 |
- /*##############################################################################
- # 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/dom",
- "dojo/dom-form",
- "dojo/request/iframe",
- "dojo/_base/array",
- "dojo/on",
- "dijit/registry",
- "dijit/Menu",
- "dijit/MenuItem",
- "dijit/MenuSeparator",
- "dijit/PopupMenuItem",
- "dgrid/Grid",
- "dgrid/Keyboard",
- "dgrid/Selection",
- "dgrid/selector",
- "dgrid/extensions/ColumnResizer",
- "dgrid/extensions/DijitRegistry",
- "dgrid/extensions/Pagination",
- "hpcc/_TabContainerWidget",
- "hpcc/ESPBase",
- "hpcc/ESPWorkunit",
- "hpcc/ESPLogicalFile",
- "hpcc/TargetSelectWidget",
- "hpcc/QuerySetDetailsWidget",
- "hpcc/WsWorkunits",
- "hpcc/ESPQuery",
- "hpcc/ESPUtil",
- "dojo/text!../templates/QuerySetQueryWidget.html",
- "dijit/layout/BorderContainer",
- "dijit/layout/TabContainer",
- "dijit/layout/ContentPane",
- "dijit/Toolbar",
- "dijit/form/Form",
- "dijit/form/Button",
- "dijit/form/CheckBox",
- "dijit/ToolbarSeparator",
- "dijit/form/TextBox",
- "dijit/Dialog",
- "dijit/form/DropDownButton",
- "dijit/TooltipDialog",
- "dojox/layout/TableContainer"
- ], function (declare, lang, dom, domForm, iframe, arrayUtil, on,
- registry, Menu, MenuItem, MenuSeparator, PopupMenuItem,
- Grid, Keyboard, Selection, selector, ColumnResizer, DijitRegistry, Pagination,
- _TabContainerWidget, ESPBase, ESPWorkunit, ESPLogicalFile, TargetSelectWidget, QuerySetDetailsWidget, WsWorkunits, ESPQuery, ESPUtil,
- template) {
- return declare("QuerySetQueryWidget", [_TabContainerWidget], {
- templateString: template,
- baseClass: "QuerySetQueryWidget",
- borderContainer: null,
- queriesTab: null,
- querySetGrid: null,
- clusterTargetSelect: null,
- initalized: false,
- loaded: false,
- buildRendering: function (args) {
- this.inherited(arguments);
- },
- postCreate: function (args) {
- this.inherited(arguments);
- this.queriesTab = registry.byId(this.id + "_Queries");
- this.clusterTargetSelect = registry.byId(this.id + "ClusterTargetSelect");
- this.borderContainer = registry.byId(this.id + "BorderContainer");
- },
- startup: function (args) {
- this.inherited(arguments);
- this.initContextMenu();
- },
- resize: function (args) {
- this.inherited(arguments);
- this.borderContainer.resize();
- },
- layout: function (args) {
- this.inherited(arguments);
- },
- destroy: function (args) {
- this.inherited(arguments);
- },
- init: function (params) {
- if (this.inherited(arguments))
- return;
- var context = this;
- var firstCall = true;
- this.clusterTargetSelect.init({
- Targets: true,
- includeBlank: true,
- Target: params.Cluster,
- });
- this.initQuerySetGrid();
- this.selectChild(this.queriesTab, true);
- },
- initTab: function () {
- var currSel = this.getSelectedChild();
- if (currSel && !currSel.initalized) {
- if (currSel.id == this.queriesTab.id) {
- } else {
- currSel.init(currSel.hpcc.params);
- }
- }
- },
- addMenuItem: function (menu, details) {
- var menuItem = new MenuItem(details);
- menu.addChild(menuItem);
- return menuItem;
- },
- initContextMenu: function ( ) {
- var context = this;
- var pMenu = new Menu({
- targetNodeIds: [this.id + "QuerySetGrid"]
- });
- this.menuOpen = this.addMenuItem(pMenu, {
- label: "Open",
- onClick: function () { context._onOpen(); }
- });
- this.menuDelete = this.addMenuItem(pMenu, {
- label: "Delete",
- onClick: function () { context._onDelete(); }
- });
- pMenu.addChild(new MenuSeparator());
- this.menuUnsuspend = this.addMenuItem(pMenu, {
- label: "Unsuspend",
- onClick: function () { context._onUnsuspend(); }
- });
- this.menuSuspend= this.addMenuItem(pMenu, {
- label: "Suspend",
- onClick: function () { context._onSuspend(); }
- });
- pMenu.addChild(new MenuSeparator());
- this.menuActivate = this.addMenuItem(pMenu, {
- label: "Activate",
- onClick: function () { context._onActivate(); }
- });
- this.menuDeactivate = this.addMenuItem(pMenu, {
- label: "Deactivate",
- onClick: function () { context._onDeactivate(); }
- });
- pMenu.addChild(new MenuSeparator());
- {
- var pSubMenu = new Menu();
- /*
- this.menuFilterCluster = this.addMenuItem(pSubMenu, {
- onClick: function (args) {
- context.clearFilter();
- registry.byId(context.id + "ClusterTargetSelect").set("value", context.menuFilterCluster.get("hpcc_value"));
- context._onFilterApply();
- }
- });*/
- this.menuFilterSuspend = this.addMenuItem(pSubMenu, {
- onClick: function (args) {
- context.clearFilter();
- registry.byId(context.id + "Suspended").set("value", context.menuFilterSuspend.get("hpcc_value"));
- context._onFilterApply();
- }
- });
- pSubMenu.addChild(new MenuSeparator());
- this.menuFilterClearFilter = this.addMenuItem(pSubMenu, {
- label: "Clear",
- onClick: function () {
- context._onFilterClear();
- }
- });
- pMenu.addChild(new PopupMenuItem({
- label: "Filter",
- popup: pSubMenu
- }));
- }
- pMenu.startup();
- },
- /*Not Applicable*/
- _onRowContextMenu: function (item, colField, mystring) {
- this.menuFilterSuspend.set("disabled", false);
- //this.menuFilterCluster.set("disabled", false);
- //this.menuFilterUnsuspend.set("disabled", false);
- //this.menuFilterActive.set("disabled", false);
- //this.menuFilterDeactive.set("disabled", false);
- if (item) {
- /*this.menuFilterCluster.set("label", "Cluster: " + item.QuerySetName);
- this.menuFilterCluster.set("hpcc_value", item.QuerySetName);*/
- this.menuFilterSuspend.set("label", "Suspend: " + item.Suspended);
- this.menuFilterSuspend.set("hpcc_value", item.Suspended);
- /*
- this.menuFilterUnsuspend.set("label", "Unsuspend: " + item.Suspend);
- this.menuFilterUnsuspend.set("hpcc_value", item.Suspend);
- this.menuFilterActive.set("label", "Active: " + item.Active);
- this.menuFilterActive.set("hpcc_value", item.Active);
- this.menuFilterDeactivate.set("label", "Deactivate: " + item.Active);
- this.menuFilterDeactivate.set("hpcc_value", item.Active);
- }
- if (item.Cluster == "") {
- this.menuFilterCluster.set("disabled", true);
- this.menuFilterCluster.set("label", "Cluster: " + "N/A");
- }*/
- if (item.Suspend == "") {
- this.menuFilterSuspend.set("disabled", true);
- this.menuFilterSuspend.set("label", "Suspend: " + "N/A");
- }
- /*
- if (item.Suspend == true) {
- this.menuFilterUnsuspend.set("disabled", false);
- this.menuFilterUnsuspend.set("label", "Unsuspend: " + "N/A");
- }
- if (item.Active == false) {
- this.menuFilterActive.set("disabled", true);
- this.menuFilterActive.set("label", "Active: " + "N/A");
- }
- if (item.Active == true) {
- this.menuFilterState.set("disabled", false);
- this.menuFilterState.set("label", "Deactivate: " + "N/A");*/
- }
- },
- initQuerySetGrid: function (params) {
- var context = this;
- var store = ESPQuery.CreateQueryStore();
- this.querySetGrid = new declare([Grid, Pagination, Selection, ColumnResizer, Keyboard, DijitRegistry, ESPUtil.GridHelper])({
- allowSelectAll: true,
- deselectOnRefresh: false,
- store: store,
- query: this.getFilter(),
- sort: [{ attribute: "Id" }],
- rowsPerPage: 50,
- pagingLinks: 1,
- pagingTextBox: true,
- firstLastArrows: true,
- pageSizeOptions: [25, 50, 100],
- columns: {
- col1: selector({
- width: 27,
- selectorType: 'checkbox'
- }),
- Suspended: {
- renderHeaderCell: function (node) {
- node.innerHTML = "<img src='../files/img/suspended.png'>";
- },
- width: 20,
- sortable: false,
- formatter: function (suspended) {
- if (suspended == true) {
- return ("<img src='../files/img/suspended.png'>");
- }
- return "";
- }
- },
- Activated: {
- renderHeaderCell: function (node) {
- node.innerHTML = "<img src='../files/img/active.png'>";
- },
- width: 20,
- sortable: false,
- formatter: function (activated) {
- if (activated == true) {
- return ("<img src='../files/img/active.png'>");
- }
- return "";
- }
- },
- ErrorCount: {
- renderHeaderCell: function (node) {
- node.innerHTML = "<img src='../files/img/error.png'>";
- },
- width: 20,
- sortable: false,
- formatter: function (error) {
- if (error > 0) {
- return ("<img src='../files/img/error.png'>");
- }
- return "";
- }
- },
- Id: {
- width: 220,
- label: "Id",
- formatter: function (Id, idx) {
- return "<a href='#' rowIndex=" + idx + " class='" + context.id + "WuidClick'>" + Id + "</a>";
- }
- },
- Name: {
- width: 180,
- label: "Name"
- },
- QuerySetId:{
- width: 180,
- label: "Target",
- sortable: false
- },
- Wuid: {
- width: 180,
- label: "Wuid"
- },
- Dll: {
- width: 180,
- label: "Dll"
- },
- Priority: {
- width: 100,
- label: "Priority",
- sortable: false
- },
- IsLibrary: {
- width: 100,
- label: "Is Library",
- sortable: false
- },
- PublishedBy: {
- width: 180,
- label: "Published By"
- },
- },
- },
- this.id + "QuerySetGrid");
- //this.querySetGrid.set("noDataMessage", "<span class='dojoxGridNoData'>Zero Workunits (check filter).</span>");
- on(document, "." + context.id + "WuidClick:click", function (evt) {
- if (context._onRowDblClick) {
- var item = context.querySetGrid.row(evt).data;
- context._onRowDblClick(item);
- }
- });
- this.querySetGrid.on(".dgrid-row:dblclick", function (evt) {
- if (context._onRowDblClick) {
- var item = context.querySetGrid.row(evt).data;
- context._onRowDblClick(item);
- }
- });
- this.querySetGrid.on(".dgrid-row:contextmenu", function (evt) {
- if (context._onRowContextMenu) {
- var item = context.querySetGrid.row(evt).data;
- var cell = context.querySetGrid.cell(evt);
- var colField = cell.column.field;
- var mystring = "item." + colField;
- context._onRowContextMenu(item, colField, mystring);
- }
- });
- this.querySetGrid.onSelectionChanged(function (event) {
- context.refreshActionState();
- });
- this.querySetGrid.onContentChanged(function (event) {
- context.refreshActionState();
- });
- this.querySetGrid.startup();
- this.refreshActionState();
- },
- refreshActionState: function () {
- var selection = this.querySetGrid.getSelected();
- var hasSelection = false;
- var isSuspended = false;
- var isNotSuspended = false;
- for (var i = 0; i < selection.length; ++i) {
- hasSelection = true;
- if (selection[i].Suspended != true) {
- isSuspended = true;
- } else {
- isNotSuspended = true;
- }
- }
- registry.byId(this.id + "Delete").set("disabled", !hasSelection);
- registry.byId(this.id + "unSuspend").set("disabled", !isNotSuspended);
- registry.byId(this.id + "onSuspend").set("disabled", !isSuspended);
- registry.byId(this.id + "Activate").set("disabled", !hasSelection);
- registry.byId(this.id + "Deactivate").set("disabled", !hasSelection);
- registry.byId(this.id + "Open").set("disabled", !hasSelection);
- },
- _onRefresh: function (params) {
- this.refreshGrid();
- },
- _onFilterClear: function(event) {
- this.clearFilter();
- this.refreshGrid();
- },
- clearFilter: function () {
- arrayUtil.forEach(registry.byId(this.id + "FilterForm").getDescendants(), function (item, idx) {
- item.set('value', null);
- });
- },
- _onFilterApply: function(){
- this.querySetGrid.set("query", this.getFilter());
- },
- _onDelete:function(){
- if (confirm('Delete Selected Queries?')) {
- var context = this;
- WsWorkunits.WUQuerysetQueryAction(this.querySetGrid.getSelected(), "Delete").then(function (response) {
- context.refreshGrid();
- });
- }
- },
- refreshGrid: function (args) {
- this.querySetGrid.set("query", this.getFilter());
- },
- _onSuspend: function(){
- var context = this;
- WsWorkunits.WUQuerysetQueryAction(this.querySetGrid.getSelected(), "Suspend").then(function (response) {
- context.refreshGrid();
- });
- },
- _onUnsuspend: function (){
- var context = this;
- WsWorkunits.WUQuerysetQueryAction(this.querySetGrid.getSelected(), "Unsuspend").then(function (response) {
- context.refreshGrid();
- });
- },
- _onActivate: function(){
- var context = this;
- WsWorkunits.WUQuerysetQueryAction(this.querySetGrid.getSelected(), "Activate").then(function (response) {
- context.refreshGrid();
- });
- },
- _onDeactivate: function(){
- var context = this;
- WsWorkunits.WUQuerysetQueryAction(this.querySetGrid.getSelected(), "Deactivate").then(function (response) {
- context.refreshGrid();
- });
- },
- _onOpen: function(){
- var selections = this.querySetGrid.getSelected();
- var firstTab = null;
- for (var i = selections.length - 1; i >= 0; --i) {
- var tab = this.ensurePane(this.id + "_" + selections[i].Id, selections[i]);
- if (i == 0) {
- firstTab = tab;
- }
- }
- if (firstTab) {
- this.selectChild(firstTab);
- }
- },
- _onRowDblClick: function (item) {
- var wuTab = this.ensurePane(this.id + "_" + item.Id, item);
- this.selectChild(wuTab);
- },
- getFilter: function(){
- var context = this;
- var retVal = domForm.toObject(this.id + "FilterForm");
- return retVal;
- },
- ensurePane: function (id, params) {
- id = id.split(".").join("x");
- var retVal = registry.byId(id);
- if (!retVal) {
- var context = this;
- retVal = new QuerySetDetailsWidget({
- id: id,
- title: params.Id,
- closable: true,
- hpcc: {
- type: "QuerySetDetailsWidget",
- params: params
- }
- });
- this.addChild(retVal, 1);
- }
- return retVal;
- }
- });
- });
|