QuerySetQueryWidget.js 19 KB

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