QuerySetQueryWidget.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. /*##############################################################################
  2. # HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. ############################################################################## */
  16. define([
  17. "dojo/_base/declare",
  18. "dojo/_base/lang",
  19. "dojo/i18n",
  20. "dojo/i18n!./nls/hpcc",
  21. "dojo/dom",
  22. "dojo/dom-form",
  23. "dojo/request/iframe",
  24. "dojo/_base/array",
  25. "dojo/on",
  26. "dijit/registry",
  27. "dijit/Menu",
  28. "dijit/MenuItem",
  29. "dijit/MenuSeparator",
  30. "dijit/PopupMenuItem",
  31. "dgrid/Grid",
  32. "dgrid/Keyboard",
  33. "dgrid/Selection",
  34. "dgrid/selector",
  35. "dgrid/extensions/ColumnResizer",
  36. "dgrid/extensions/DijitRegistry",
  37. "dgrid/extensions/Pagination",
  38. "hpcc/_TabContainerWidget",
  39. "hpcc/ESPBase",
  40. "hpcc/ESPWorkunit",
  41. "hpcc/ESPLogicalFile",
  42. "hpcc/TargetSelectWidget",
  43. "hpcc/QuerySetDetailsWidget",
  44. "hpcc/WsWorkunits",
  45. "hpcc/ESPQuery",
  46. "hpcc/ESPUtil",
  47. "dojo/text!../templates/QuerySetQueryWidget.html",
  48. "dijit/layout/BorderContainer",
  49. "dijit/layout/TabContainer",
  50. "dijit/layout/ContentPane",
  51. "dijit/Toolbar",
  52. "dijit/form/Form",
  53. "dijit/form/Button",
  54. "dijit/form/CheckBox",
  55. "dijit/ToolbarSeparator",
  56. "dijit/form/TextBox",
  57. "dijit/Dialog",
  58. "dijit/form/DropDownButton",
  59. "dijit/TooltipDialog",
  60. "hpcc/TableContainer"
  61. ], function (declare, lang, i18n, nlsHPCC, dom, domForm, iframe, arrayUtil, on,
  62. registry, Menu, MenuItem, MenuSeparator, PopupMenuItem,
  63. Grid, Keyboard, Selection, selector, ColumnResizer, DijitRegistry, Pagination,
  64. _TabContainerWidget, ESPBase, ESPWorkunit, ESPLogicalFile, TargetSelectWidget, QuerySetDetailsWidget, WsWorkunits, ESPQuery, ESPUtil,
  65. template) {
  66. return declare("QuerySetQueryWidget", [_TabContainerWidget], {
  67. templateString: template,
  68. baseClass: "QuerySetQueryWidget",
  69. i18n: nlsHPCC,
  70. borderContainer: null,
  71. queriesTab: null,
  72. querySetGrid: null,
  73. clusterTargetSelect: null,
  74. initalized: false,
  75. loaded: false,
  76. buildRendering: function (args) {
  77. this.inherited(arguments);
  78. },
  79. postCreate: function (args) {
  80. this.inherited(arguments);
  81. this.queriesTab = registry.byId(this.id + "_PublishedQueries");
  82. this.clusterTargetSelect = registry.byId(this.id + "ClusterTargetSelect");
  83. this.borderContainer = registry.byId(this.id + "BorderContainer");
  84. },
  85. startup: function (args) {
  86. this.inherited(arguments);
  87. this.initContextMenu();
  88. },
  89. resize: function (args) {
  90. this.inherited(arguments);
  91. this.borderContainer.resize();
  92. },
  93. layout: function (args) {
  94. this.inherited(arguments);
  95. },
  96. destroy: function (args) {
  97. this.inherited(arguments);
  98. },
  99. init: function (params) {
  100. if (this.inherited(arguments))
  101. return;
  102. var context = this;
  103. var firstCall = true;
  104. this.clusterTargetSelect.init({
  105. Targets: true,
  106. includeBlank: true,
  107. Target: params.Cluster,
  108. });
  109. this.initQuerySetGrid();
  110. this.selectChild(this.queriesTab, true);
  111. },
  112. initTab: function () {
  113. var currSel = this.getSelectedChild();
  114. if (currSel && !currSel.initalized) {
  115. if (currSel.id == this.queriesTab.id) {
  116. } else {
  117. currSel.init(currSel.hpcc.params);
  118. }
  119. }
  120. },
  121. addMenuItem: function (menu, details) {
  122. var menuItem = new MenuItem(details);
  123. menu.addChild(menuItem);
  124. return menuItem;
  125. },
  126. initContextMenu: function ( ) {
  127. var context = this;
  128. var pMenu = new Menu({
  129. targetNodeIds: [this.id + "QuerySetGrid"]
  130. });
  131. this.menuOpen = this.addMenuItem(pMenu, {
  132. label: this.i18n.Open,
  133. onClick: function () { context._onOpen(); }
  134. });
  135. this.menuDelete = this.addMenuItem(pMenu, {
  136. label: this.i18n.Delete,
  137. onClick: function () { context._onDelete(); }
  138. });
  139. pMenu.addChild(new MenuSeparator());
  140. this.menuUnsuspend = this.addMenuItem(pMenu, {
  141. label: this.i18n.Unsuspend,
  142. onClick: function () { context._onUnsuspend(); }
  143. });
  144. this.menuSuspend= this.addMenuItem(pMenu, {
  145. label: this.i18n.Suspend,
  146. onClick: function () { context._onSuspend(); }
  147. });
  148. pMenu.addChild(new MenuSeparator());
  149. this.menuActivate = this.addMenuItem(pMenu, {
  150. label: this.i18n.Activate,
  151. onClick: function () { context._onActivate(); }
  152. });
  153. this.menuDeactivate = this.addMenuItem(pMenu, {
  154. label: this.i18n.Deactivate,
  155. onClick: function () { context._onDeactivate(); }
  156. });
  157. pMenu.addChild(new MenuSeparator());
  158. {
  159. var pSubMenu = new Menu();
  160. /*
  161. this.menuFilterCluster = this.addMenuItem(pSubMenu, {
  162. onClick: function (args) {
  163. context.clearFilter();
  164. registry.byId(context.id + "ClusterTargetSelect").set("value", context.menuFilterCluster.get("hpcc_value"));
  165. context._onFilterApply();
  166. }
  167. });*/
  168. this.menuFilterSuspend = this.addMenuItem(pSubMenu, {
  169. onClick: function (args) {
  170. context.clearFilter();
  171. registry.byId(context.id + "Suspended").set("value", context.menuFilterSuspend.get("hpcc_value"));
  172. context._onFilterApply();
  173. }
  174. });
  175. pSubMenu.addChild(new MenuSeparator());
  176. this.menuFilterClearFilter = this.addMenuItem(pSubMenu, {
  177. label: this.i18n.Clear,
  178. onClick: function () {
  179. context._onFilterClear();
  180. }
  181. });
  182. pMenu.addChild(new PopupMenuItem({
  183. label: this.i18n.Filter,
  184. popup: pSubMenu
  185. }));
  186. }
  187. pMenu.startup();
  188. },
  189. /*Not Applicable*/
  190. _onRowContextMenu: function (item, colField, mystring) {
  191. this.menuFilterSuspend.set("disabled", false);
  192. //this.menuFilterCluster.set("disabled", false);
  193. //this.menuFilterUnsuspend.set("disabled", false);
  194. //this.menuFilterActive.set("disabled", false);
  195. //this.menuFilterDeactive.set("disabled", false);
  196. if (item) {
  197. /*this.menuFilterCluster.set("label", "Cluster: " + item.QuerySetName);
  198. this.menuFilterCluster.set("hpcc_value", item.QuerySetName);*/
  199. this.menuFilterSuspend.set("label", this.i18n.Suspend + ": " + item.Suspended);
  200. this.menuFilterSuspend.set("hpcc_value", item.Suspended);
  201. /*
  202. this.menuFilterUnsuspend.set("label", "Unsuspend: " + item.Suspend);
  203. this.menuFilterUnsuspend.set("hpcc_value", item.Suspend);
  204. this.menuFilterActive.set("label", "Active: " + item.Active);
  205. this.menuFilterActive.set("hpcc_value", item.Active);
  206. this.menuFilterDeactivate.set("label", "Deactivate: " + item.Active);
  207. this.menuFilterDeactivate.set("hpcc_value", item.Active);
  208. }
  209. if (item.Cluster == "") {
  210. this.menuFilterCluster.set("disabled", true);
  211. this.menuFilterCluster.set("label", "Cluster: " + "N/A");
  212. }*/
  213. if (item.Suspend == "") {
  214. this.menuFilterSuspend.set("disabled", true);
  215. this.menuFilterSuspend.set("label", this.i18n.Suspend + ": " + this.i18n.NA);
  216. }
  217. /*
  218. if (item.Suspend == true) {
  219. this.menuFilterUnsuspend.set("disabled", false);
  220. this.menuFilterUnsuspend.set("label", "Unsuspend: " + "N/A");
  221. }
  222. if (item.Active == false) {
  223. this.menuFilterActive.set("disabled", true);
  224. this.menuFilterActive.set("label", "Active: " + "N/A");
  225. }
  226. if (item.Active == true) {
  227. this.menuFilterState.set("disabled", false);
  228. this.menuFilterState.set("label", "Deactivate: " + "N/A");*/
  229. }
  230. },
  231. initQuerySetGrid: function (params) {
  232. var context = this;
  233. var store = ESPQuery.CreateQueryStore();
  234. this.querySetGrid = new declare([Grid, Pagination, Selection, ColumnResizer, Keyboard, DijitRegistry, ESPUtil.GridHelper])({
  235. allowSelectAll: true,
  236. deselectOnRefresh: false,
  237. store: store,
  238. query: this.getFilter(),
  239. sort: [{ attribute: "Id" }],
  240. rowsPerPage: 50,
  241. pagingLinks: 1,
  242. pagingTextBox: true,
  243. firstLastArrows: true,
  244. pageSizeOptions: [25, 50, 100],
  245. columns: {
  246. col1: selector({
  247. width: 27,
  248. selectorType: 'checkbox'
  249. }),
  250. Suspended: {
  251. renderHeaderCell: function (node) {
  252. node.innerHTML = "<img src='/esp/files/img/suspended.png'>";
  253. },
  254. width: 20,
  255. sortable: false,
  256. formatter: function (suspended) {
  257. if (suspended == true) {
  258. return ("<img src='/esp/files/img/suspended.png'>");
  259. }
  260. return "";
  261. }
  262. },
  263. Activated: {
  264. renderHeaderCell: function (node) {
  265. node.innerHTML = "<img src='/esp/files/img/active.png'>";
  266. },
  267. width: 20,
  268. sortable: false,
  269. formatter: function (activated) {
  270. if (activated == true) {
  271. return ("<img src='/esp/files/img/active.png'>");
  272. }
  273. return "";
  274. }
  275. },
  276. ErrorCount: {
  277. renderHeaderCell: function (node) {
  278. node.innerHTML = "<img src='/esp/files/img/errwarn.png'>";
  279. },
  280. width: 20,
  281. sortable: false,
  282. formatter: function (error) {
  283. if (error > 0) {
  284. return ("<img src='/esp/files/img/errwarn.png'>");
  285. }
  286. return "";
  287. }
  288. },
  289. Id: {
  290. width: 220,
  291. label: this.i18n.ID,
  292. formatter: function (Id, idx) {
  293. return "<a href='#' rowIndex=" + idx + " class='" + context.id + "WuidClick'>" + Id + "</a>";
  294. }
  295. },
  296. Name: {
  297. width: 180,
  298. label: this.i18n.Name
  299. },
  300. QuerySetId:{
  301. width: 180,
  302. label: this.i18n.Target,
  303. sortable: false
  304. },
  305. Wuid: {
  306. width: 180,
  307. label: this.i18n.WUID
  308. },
  309. Dll: {
  310. width: 180,
  311. label: this.i18n.Dll
  312. },
  313. Priority: {
  314. width: 100,
  315. label: this.i18n.Priority,
  316. sortable: false
  317. },
  318. IsLibrary: {
  319. width: 100,
  320. label: this.i18n.IsLibrary,
  321. sortable: false
  322. },
  323. PublishedBy: {
  324. width: 180,
  325. label: this.i18n.PublishedBy
  326. },
  327. },
  328. },
  329. this.id + "QuerySetGrid");
  330. //this.querySetGrid.set("noDataMessage", "<span class='dojoxGridNoData'>" + this.i18n.noDataMessage + "</span>");
  331. on(document, "." + context.id + "WuidClick:click", function (evt) {
  332. if (context._onRowDblClick) {
  333. var item = context.querySetGrid.row(evt).data;
  334. context._onRowDblClick(item);
  335. }
  336. });
  337. this.querySetGrid.on(".dgrid-row:dblclick", function (evt) {
  338. if (context._onRowDblClick) {
  339. var item = context.querySetGrid.row(evt).data;
  340. context._onRowDblClick(item);
  341. }
  342. });
  343. this.querySetGrid.on(".dgrid-row:contextmenu", function (evt) {
  344. if (context._onRowContextMenu) {
  345. var item = context.querySetGrid.row(evt).data;
  346. var cell = context.querySetGrid.cell(evt);
  347. var colField = cell.column.field;
  348. var mystring = "item." + colField;
  349. context._onRowContextMenu(item, colField, mystring);
  350. }
  351. });
  352. this.querySetGrid.onSelectionChanged(function (event) {
  353. context.refreshActionState();
  354. });
  355. this.querySetGrid.onContentChanged(function (event) {
  356. context.refreshActionState();
  357. });
  358. this.querySetGrid.startup();
  359. this.refreshActionState();
  360. },
  361. refreshActionState: function () {
  362. var selection = this.querySetGrid.getSelected();
  363. var hasSelection = false;
  364. var isSuspended = false;
  365. var isNotSuspended = false;
  366. for (var i = 0; i < selection.length; ++i) {
  367. hasSelection = true;
  368. if (selection[i].Suspended != true) {
  369. isSuspended = true;
  370. } else {
  371. isNotSuspended = true;
  372. }
  373. }
  374. registry.byId(this.id + "Delete").set("disabled", !hasSelection);
  375. registry.byId(this.id + "unSuspend").set("disabled", !isNotSuspended);
  376. registry.byId(this.id + "onSuspend").set("disabled", !isSuspended);
  377. registry.byId(this.id + "Activate").set("disabled", !hasSelection);
  378. registry.byId(this.id + "Deactivate").set("disabled", !hasSelection);
  379. registry.byId(this.id + "Open").set("disabled", !hasSelection);
  380. },
  381. _onRefresh: function (params) {
  382. this.refreshGrid();
  383. },
  384. _onFilterClear: function(event) {
  385. this.clearFilter();
  386. this.refreshGrid();
  387. },
  388. clearFilter: function () {
  389. arrayUtil.forEach(registry.byId(this.id + "FilterForm").getDescendants(), function (item, idx) {
  390. item.set('value', null);
  391. });
  392. },
  393. _onFilterApply: function(){
  394. this.querySetGrid.set("query", this.getFilter());
  395. },
  396. _onDelete:function(){
  397. if (confirm(this.i18n.DeleteSelectedQueries)) {
  398. var context = this;
  399. WsWorkunits.WUQuerysetQueryAction(this.querySetGrid.getSelected(), "Delete").then(function (response) {
  400. context.refreshGrid(true);
  401. });
  402. }
  403. },
  404. refreshGrid: function (clearSelection) {
  405. this.querySetGrid.set("query", this.getFilter());
  406. if (clearSelection) {
  407. this.workunitsGrid.clearSelection();
  408. }
  409. },
  410. _onSuspend: function(){
  411. var context = this;
  412. WsWorkunits.WUQuerysetQueryAction(this.querySetGrid.getSelected(), "Suspend").then(function (response) {
  413. context.refreshGrid();
  414. });
  415. },
  416. _onUnsuspend: function (){
  417. var context = this;
  418. WsWorkunits.WUQuerysetQueryAction(this.querySetGrid.getSelected(), "Unsuspend").then(function (response) {
  419. context.refreshGrid();
  420. });
  421. },
  422. _onActivate: function(){
  423. var context = this;
  424. WsWorkunits.WUQuerysetQueryAction(this.querySetGrid.getSelected(), "Activate").then(function (response) {
  425. context.refreshGrid();
  426. });
  427. },
  428. _onDeactivate: function(){
  429. var context = this;
  430. WsWorkunits.WUQuerysetQueryAction(this.querySetGrid.getSelected(), "Deactivate").then(function (response) {
  431. context.refreshGrid();
  432. });
  433. },
  434. _onOpen: function(){
  435. var selections = this.querySetGrid.getSelected();
  436. var firstTab = null;
  437. for (var i = selections.length - 1; i >= 0; --i) {
  438. var tab = this.ensurePane(this.id + "_" + selections[i].Id, selections[i]);
  439. if (i == 0) {
  440. firstTab = tab;
  441. }
  442. }
  443. if (firstTab) {
  444. this.selectChild(firstTab);
  445. }
  446. },
  447. _onRowDblClick: function (item) {
  448. var wuTab = this.ensurePane(this.id + "_" + item.Id, item);
  449. this.selectChild(wuTab);
  450. },
  451. getFilter: function(){
  452. var context = this;
  453. var retVal = domForm.toObject(this.id + "FilterForm");
  454. return retVal;
  455. },
  456. ensurePane: function (id, params) {
  457. id = id.split(".").join("x");
  458. var retVal = registry.byId(id);
  459. if (!retVal) {
  460. var context = this;
  461. retVal = new QuerySetDetailsWidget({
  462. id: id,
  463. title: params.Id,
  464. closable: true,
  465. hpcc: {
  466. type: "QuerySetDetailsWidget",
  467. params: params
  468. }
  469. });
  470. this.addChild(retVal, 1);
  471. }
  472. return retVal;
  473. }
  474. });
  475. });