QuerySetQueryWidget.js 19 KB

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