DFUQueryWidget.js 21 KB

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