DFUQueryWidget.js 24 KB

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