DFUQueryWidget.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  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/DFUQueryWidget",
  22. "dojo/_base/array",
  23. "dojo/dom",
  24. "dojo/dom-attr",
  25. "dojo/dom-construct",
  26. "dojo/dom-class",
  27. "dojo/dom-form",
  28. "dojo/date",
  29. "dojo/on",
  30. "dijit/registry",
  31. "dijit/Dialog",
  32. "dijit/Menu",
  33. "dijit/MenuItem",
  34. "dijit/MenuSeparator",
  35. "dijit/PopupMenuItem",
  36. "dijit/form/Textarea",
  37. "dgrid/Grid",
  38. "dgrid/Keyboard",
  39. "dgrid/Selection",
  40. "dgrid/selector",
  41. "dgrid/extensions/ColumnResizer",
  42. "dgrid/extensions/DijitRegistry",
  43. "dgrid/extensions/Pagination",
  44. "hpcc/_TabContainerWidget",
  45. "hpcc/WsDfu",
  46. "hpcc/FileSpray",
  47. "hpcc/ESPUtil",
  48. "hpcc/ESPLogicalFile",
  49. "hpcc/ESPDFUWorkunit",
  50. "hpcc/LFDetailsWidget",
  51. "hpcc/SFDetailsWidget",
  52. "hpcc/DFUWUDetailsWidget",
  53. "hpcc/TargetSelectWidget",
  54. "hpcc/FilterDropDownWidget",
  55. "dojo/text!../templates/DFUQueryWidget.html",
  56. "dijit/layout/BorderContainer",
  57. "dijit/layout/TabContainer",
  58. "dijit/layout/ContentPane",
  59. "dijit/form/DateTextBox",
  60. "dijit/form/TimeTextBox",
  61. "dijit/form/Button",
  62. "dijit/form/DropDownButton",
  63. "dijit/form/Select",
  64. "dijit/Toolbar",
  65. "dijit/TooltipDialog",
  66. "hpcc/TableContainer"
  67. ], function (declare, lang, i18n, nlsCommon, nlsSpecific, arrayUtil, dom, domAttr, domConstruct, domClass, domForm, date, on,
  68. registry, Dialog, Menu, MenuItem, MenuSeparator, PopupMenuItem, Textarea,
  69. Grid, Keyboard, Selection, selector, ColumnResizer, DijitRegistry, Pagination,
  70. _TabContainerWidget, WsDfu, FileSpray, ESPUtil, ESPLogicalFile, ESPDFUWorkunit, LFDetailsWidget, SFDetailsWidget, DFUWUDetailsWidget, TargetSelectWidget, FilterDropDownWidget,
  71. template) {
  72. return declare("DFUQueryWidget", [_TabContainerWidget, ESPUtil.FormHelper], {
  73. templateString: template,
  74. baseClass: "DFUQueryWidget",
  75. i18n: lang.mixin(nlsCommon, nlsSpecific),
  76. addToSuperFileForm: null,
  77. desprayDialog: null,
  78. sprayFixedDialog: null,
  79. sprayVariableDialog: null,
  80. sprayXmlDialog: null,
  81. workunitsTab: null,
  82. workunitsGrid: null,
  83. filter: null,
  84. postCreate: function (args) {
  85. this.inherited(arguments);
  86. this.addToSuperFileForm = registry.byId(this.id + "AddToSuperfileForm");
  87. this.desprayDialog = registry.byId(this.id + "DesprayDialog");
  88. this.sprayFixedDialog = registry.byId(this.id + "SprayFixedDialog");
  89. this.sprayVariableDialog = registry.byId(this.id + "SprayVariableDialog");
  90. this.sprayXmlDialog = registry.byId(this.id + "SprayXmlDialog");
  91. this.workunitsTab = registry.byId(this.id + "_Workunits");
  92. this.filter = registry.byId(this.id + "Filter");
  93. this.clusterTargetSelect = registry.byId(this.id + "ClusterTargetSelect");
  94. this.desprayTargetSelect = registry.byId(this.id + "DesprayTargetSelect");
  95. this.sprayFixedDestinationSelect = registry.byId(this.id + "SprayFixedDestination");
  96. this.sprayVariableDestinationSelect = registry.byId(this.id + "SprayVariableDestination");
  97. this.sprayXmlDestinationSelect = registry.byId(this.id + "SprayXmlDestinationSelect");
  98. },
  99. startup: function (args) {
  100. this.inherited(arguments);
  101. this.initContextMenu();
  102. this.initFilter();
  103. },
  104. getTitle: function () {
  105. return this.i18n.title;
  106. },
  107. // Hitched actions ---
  108. _onRefresh: function (event) {
  109. this.refreshGrid();
  110. },
  111. _onOpen: function (event) {
  112. var selections = this.workunitsGrid.getSelected();
  113. var firstTab = null;
  114. for (var i = selections.length - 1; i >= 0; --i) {
  115. var tab = this.ensureLFPane(this.id + "_" + selections[i].Name, selections[i]);
  116. if (i == 0) {
  117. firstTab = tab;
  118. }
  119. }
  120. if (firstTab) {
  121. this.selectChild(firstTab, true);
  122. }
  123. },
  124. _onDelete: function (event) {
  125. if (confirm(this.i18n.DeleteSelectedFiles)) {
  126. var context = this;
  127. WsDfu.DFUArrayAction(this.workunitsGrid.getSelected(), this.i18n.Delete, {
  128. load: function (response) {
  129. context.refreshGrid(response);
  130. }
  131. });
  132. }
  133. },
  134. _onAddToSuperfileOk: function (event) {
  135. if (this.addToSuperFileForm.validate()) {
  136. var context = this;
  137. var formData = domForm.toObject(this.id + "AddToSuperfileForm");
  138. WsDfu.AddtoSuperfile(this.workunitsGrid.getSelected(), formData.Superfile, formData.ExistingFile, {
  139. load: function (response) {
  140. context.refreshGrid(response);
  141. }
  142. });
  143. var d = registry.byId(this.id + "AddtoDropDown");
  144. registry.byId(this.id + "AddtoDropDown").closeDropDown();
  145. }
  146. },
  147. _handleResponse: function (wuidQualifier, response) {
  148. if (lang.exists(wuidQualifier, response)) {
  149. var wu = ESPDFUWorkunit.Get(lang.getObject(wuidQualifier, false, response));
  150. wu.startMonitor(true);
  151. var tab = this.ensureDFUWUPane(this.id + "_" + wu.ID, {
  152. Wuid: wu.ID
  153. });
  154. if (tab) {
  155. this.selectChild(tab);
  156. }
  157. }
  158. },
  159. _onDesprayOk: function (event) {
  160. if (this.desprayDialog.validate()) {
  161. var context = this;
  162. arrayUtil.forEach(this.workunitsGrid.getSelected(), function (item, idx) {
  163. item.refresh().then(function (response) {
  164. var request = domForm.toObject(context.id + "DesprayDialog");
  165. request.destPath += item.Filename;
  166. item.despray({
  167. request: request
  168. }).then(function (response) {
  169. context._handleResponse("DesprayResponse.wuid", response);
  170. });
  171. });
  172. });
  173. registry.byId(this.id + "DesprayDropDown").closeDropDown();
  174. }
  175. },
  176. _onSprayFixed: function (event) {
  177. if (this.sprayFixedDialog.validate()) {
  178. var formData = domForm.toObject(this.id + "SprayFixedDialog");
  179. var context = this;
  180. FileSpray.SprayFixed({
  181. request: formData
  182. }).then(function (response) {
  183. context._handleResponse("SprayFixedResponse.wuid", response);
  184. })
  185. registry.byId(this.id + "SprayFixedDropDown").closeDropDown();
  186. }
  187. },
  188. _onSprayVariable: function (event) {
  189. if (this.sprayVariableDialog.validate()) {
  190. var context = this;
  191. var formData = domForm.toObject(this.id + "SprayVariableDialog");
  192. FileSpray.SprayVariable({
  193. request: formData
  194. }).then(function (response) {
  195. context._handleResponse("SprayResponse.wuid", response);
  196. });
  197. registry.byId(this.id + "SprayVariableDropDown").closeDropDown();
  198. }
  199. },
  200. _onSprayXml: function (event) {
  201. if (this.sprayXmlDialog.validate()) {
  202. var context = this;
  203. var formData = domForm.toObject(this.id + "SprayXmlDialog");
  204. FileSpray.SprayVariable({
  205. request: formData
  206. }).then(function (response) {
  207. context._handleResponse("SprayResponse.wuid", response);
  208. });
  209. registry.byId(this.id + "SprayXmlDropDown").closeDropDown();
  210. }
  211. },
  212. _onRowDblClick: function (item) {
  213. var wuTab = this.ensureLFPane(this.id + "_" + item.Name, item);
  214. this.selectChild(wuTab);
  215. },
  216. _onRowContextMenu: function (item, colField, mystring) {
  217. this.menuFilterOwner.set("disabled", false);
  218. this.menuFilterCluster.set("disabled", false);
  219. if (item) {
  220. this.menuFilterOwner.set("label", this.i18n.Owner + ": " + item.Owner);
  221. this.menuFilterOwner.set("hpcc_value", item.Owner);
  222. this.menuFilterCluster.set("label", this.i18n.Cluster + ": " + item.ClusterName);
  223. this.menuFilterCluster.set("hpcc_value", item.ClusterName);
  224. }
  225. if (item.Owner == "") {
  226. this.menuFilterOwner.set("disabled", true);
  227. this.menuFilterOwner.set("label", this.i18n.Owner + ": " + this.i18n.NA);
  228. }
  229. if (item.ClusterName == "") {
  230. this.menuFilterCluster.set("disabled", true);
  231. this.menuFilterCluster.set("label", this.i18n.Cluster + ": " + this.i18n.NA);
  232. }
  233. },
  234. // Implementation ---
  235. getFilter: function () {
  236. var retVal = this.filter.toObject();
  237. lang.mixin(retVal, {
  238. StartDate: this.getISOString("FromDate", "FromTime"),
  239. EndDate: this.getISOString("ToDate", "ToTime")
  240. });
  241. if (retVal.StartDate != "" && retVal.EndDate != "") {
  242. } else if (retVal.FirstN) {
  243. var now = new Date();
  244. retVal.StartDate = date.add(now, "day", retVal.LastNDays * -1).toISOString();
  245. retVal.EndDate = now.toISOString();
  246. }
  247. return retVal;
  248. },
  249. // Implementation ---
  250. init: function (params) {
  251. if (this.inherited(arguments))
  252. return;
  253. this.clusterTargetSelect.init({
  254. Groups: true,
  255. includeBlank: true
  256. });
  257. var context = this;
  258. this.desprayTargetSelect.init({
  259. DropZones: true,
  260. callback: function (value, item) {
  261. registry.byId(context.id + "DesprayTargetIPAddress").set("value", item.machine.Netaddress);
  262. registry.byId(context.id + "DesprayTargetPath").set("value", item.machine.Directory + "/");
  263. }
  264. });
  265. this.sprayFixedDestinationSelect.init({
  266. Groups: true
  267. });
  268. this.sprayVariableDestinationSelect.init({
  269. Groups: true
  270. });
  271. this.sprayXmlDestinationSelect.init({
  272. Groups: true
  273. });
  274. this.initWorkunitsGrid();
  275. this.selectChild(this.workunitsTab, true);
  276. this.filter.on("clear", function (evt) {
  277. context.refreshGrid();
  278. });
  279. this.filter.on("apply", function (evt) {
  280. context.refreshGrid();
  281. });
  282. },
  283. initTab: function() {
  284. var currSel = this.getSelectedChild();
  285. if (currSel && !currSel.initalized) {
  286. if (currSel.id == this.workunitsTab.id) {
  287. } else {
  288. if (!currSel.initalized) {
  289. currSel.init(currSel._hpccParams);
  290. }
  291. }
  292. }
  293. },
  294. addMenuItem: function (menu, details) {
  295. var menuItem = new MenuItem(details);
  296. menu.addChild(menuItem);
  297. return menuItem;
  298. },
  299. initContextMenu: function() {
  300. var context = this;
  301. var pMenu = new Menu({
  302. targetNodeIds: [this.id + "WorkunitsGrid"]
  303. });
  304. pMenu.addChild(new MenuItem({
  305. label: this.i18n.Refresh,
  306. onClick: function(args){context._onRefresh();}
  307. }));
  308. pMenu.addChild(new MenuSeparator());
  309. pMenu.addChild(new MenuItem({
  310. label: this.i18n.Open,
  311. onClick: function(args){context._onOpen();}
  312. }));
  313. pMenu.addChild(new MenuItem({
  314. label: this.i18n.Delete,
  315. onClick: function(args){context._onDelete();}
  316. }));
  317. pMenu.addChild(new MenuItem({
  318. label: this.i18n.AddToSuperfile,
  319. onClick: function(args){dijit.byId(context.id+"AddtoDropDown").openDropDown()}
  320. }));
  321. pMenu.addChild(new MenuSeparator());
  322. {
  323. var pSubMenu = new Menu();
  324. this.menuFilterOwner = this.addMenuItem(pSubMenu, {
  325. onClick: function (args) {
  326. context.filter.clear();
  327. context.filter.setValue(context.id + "Owner", context.menuFilterOwner.get("hpcc_value"));
  328. context.refreshGrid();
  329. }
  330. });
  331. this.menuFilterCluster = this.addMenuItem(pSubMenu, {
  332. onClick: function (args) {
  333. context.filter.clear();
  334. context.filter.setValue(context.id + "ClusterTargetSelect", context.menuFilterOwner.get("hpcc_value"));
  335. context.refreshGrid();
  336. }
  337. });
  338. pSubMenu.addChild(new MenuSeparator());
  339. this.menuFilterClearFilter = this.addMenuItem(pSubMenu, {
  340. label: this.i18n.Clear,
  341. onClick: function () {
  342. context.filter.clear();
  343. context.refreshGrid();
  344. }
  345. });
  346. pMenu.addChild(new PopupMenuItem({
  347. label: this.i18n.Filter,
  348. popup: pSubMenu
  349. }));
  350. }
  351. pMenu.startup();
  352. },
  353. initWorkunitsGrid: function() {
  354. var store = new ESPLogicalFile.CreateLFQueryStore();
  355. this.workunitsGrid = new declare([Grid, Pagination, Selection, ColumnResizer, Keyboard, DijitRegistry, ESPUtil.GridHelper])({
  356. allowSelectAll: true,
  357. deselectOnRefresh: false,
  358. store: store,
  359. rowsPerPage: 50,
  360. pagingLinks: 1,
  361. pagingTextBox: true,
  362. firstLastArrows: true,
  363. pageSizeOptions: [25, 50, 100],
  364. columns: {
  365. col1: selector({
  366. width: 27,
  367. selectorType: 'checkbox'
  368. }),
  369. isZipfile: {
  370. label: "C", width: 16, sortable: false,
  371. formatter: function (compressed) {
  372. if (compressed == true) {
  373. return "C";
  374. }
  375. return "";
  376. }
  377. },
  378. IsKeyFile: {
  379. label: "K", width: 16, sortable: false,
  380. formatter: function (keyfile) {
  381. if (keyfile == true) {
  382. return "K";
  383. }
  384. return "";
  385. }
  386. },
  387. isSuperfile: {
  388. label: "S", width: 16, sortable: false,
  389. formatter: function (superfile) {
  390. if (superfile == true) {
  391. return "S";
  392. }
  393. return "";
  394. }
  395. },
  396. Name: {
  397. label: this.i18n.LogicalName,
  398. formatter: function (name, idx) {
  399. return "<a href='#' rowIndex=" + idx + " class='" + context.id + "LogicalNameClick'>" + name + "</a>";
  400. }
  401. },
  402. Owner: { label: this.i18n.Owner, width: 72 },
  403. Description: { label: this.i18n.Description, width: 153 },
  404. ClusterName: { label: this.i18n.Cluster, width: 108 },
  405. RecordCount: { label: this.i18n.Records, width: 72, sortable: false },
  406. Totalsize: { label: this.i18n.Size, width: 72, sortable: false },
  407. Parts: { label: this.i18n.Parts, width: 45, sortable: false },
  408. Modified: { label: this.i18n.ModifiedUTCGMT, width: 155, sortable: false }
  409. }
  410. }, this.id + "WorkunitsGrid");
  411. this.workunitsGrid.noDataMessage = "<span class='dojoxGridNoData'>" + this.i18n.noDataMessage + "</span>";
  412. var context = this;
  413. on(document, "." + context.id + "LogicalNameClick:click", function (evt) {
  414. if (context._onRowDblClick) {
  415. var item = context.workunitsGrid.row(evt).data;
  416. context._onRowDblClick(item);
  417. }
  418. });
  419. this.workunitsGrid.on(".dgrid-row:dblclick", function (evt) {
  420. if (context._onRowDblClick) {
  421. var item = context.workunitsGrid.row(evt).data;
  422. context._onRowDblClick(item);
  423. }
  424. });
  425. this.workunitsGrid.on(".dgrid-row:contextmenu", function (evt) {
  426. if (context._onRowContextMenu) {
  427. var item = context.workunitsGrid.row(evt).data;
  428. var cell = context.workunitsGrid.cell(evt);
  429. var colField = cell.column.field;
  430. var mystring = "item." + colField;
  431. context._onRowContextMenu(item, colField, mystring);
  432. }
  433. });
  434. this.workunitsGrid.onSelectionChanged(function (event) {
  435. context.refreshActionState();
  436. });
  437. this.workunitsGrid.onContentChanged(function (object, removedFrom, insertedInto) {
  438. context.refreshActionState();
  439. });
  440. this.workunitsGrid.startup();
  441. },
  442. initFilter: function () {
  443. this.validateDialog = new Dialog({
  444. title: this.i18n.Filter,
  445. content: this.i18n.NoFilterCriteriaSpecified
  446. });
  447. },
  448. refreshGrid: function (args) {
  449. this.workunitsGrid.set("query", this.getFilter());
  450. },
  451. refreshActionState: function () {
  452. var selection = this.workunitsGrid.getSelected();
  453. var hasSelection = false;
  454. for (var i = 0; i < selection.length; ++i) {
  455. hasSelection = true;
  456. }
  457. registry.byId(this.id + "Open").set("disabled", !hasSelection);
  458. registry.byId(this.id + "Delete").set("disabled", !hasSelection);
  459. registry.byId(this.id + "AddtoDropDown").set("disabled", !hasSelection);
  460. registry.byId(this.id + "DesprayDropDown").set("disabled", !hasSelection);
  461. if (hasSelection) {
  462. var sourceDiv = dom.byId(this.id + "DesprayDialogSource");
  463. domConstruct.empty(sourceDiv);
  464. var context = this;
  465. arrayUtil.forEach(selection, function (item, idx) {
  466. domConstruct.create("div", {
  467. innerHTML: item.Name
  468. }, sourceDiv);
  469. });
  470. }
  471. },
  472. ensureDFUWUPane: function (id, params) {
  473. var retVal = registry.byId(id);
  474. if (!retVal) {
  475. var context = this;
  476. retVal = new DFUWUDetailsWidget.fixCircularDependency({
  477. id: id,
  478. title: params.Wuid,
  479. closable: true,
  480. _hpccParams: params
  481. });
  482. this.addChild(retVal, 1);
  483. }
  484. return retVal;
  485. },
  486. ensureLFPane: function (id, params) {
  487. var obj = id.split("::");
  488. id = obj.join("");
  489. obj = id.split(".");
  490. id = obj.join("");
  491. var retVal = registry.byId(id);
  492. if (!retVal) {
  493. if (params.isSuperfile) {
  494. retVal = new SFDetailsWidget.fixCircularDependency({
  495. id: id,
  496. title: params.Name,
  497. closable: true,
  498. _hpccParams: params
  499. });
  500. } else {
  501. retVal = new LFDetailsWidget.fixCircularDependency({
  502. id: id,
  503. title: params.Name,
  504. closable: true,
  505. _hpccParams: {
  506. Name: params.Name
  507. }
  508. });
  509. }
  510. this.addChild(retVal, 1);
  511. }
  512. return retVal;
  513. }
  514. });
  515. });