DFUQueryWidget.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  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. },
  273. initTab: function() {
  274. var currSel = this.getSelectedChild();
  275. if (currSel && !currSel.initalized) {
  276. if (currSel.id == this.workunitsTab.id) {
  277. } else {
  278. if (!currSel.initalized) {
  279. currSel.init(currSel._hpccParams);
  280. }
  281. }
  282. }
  283. },
  284. addMenuItem: function (menu, details) {
  285. var menuItem = new MenuItem(details);
  286. menu.addChild(menuItem);
  287. return menuItem;
  288. },
  289. initContextMenu: function() {
  290. var context = this;
  291. var pMenu = new Menu({
  292. targetNodeIds: [this.id + "WorkunitsGrid"]
  293. });
  294. pMenu.addChild(new MenuItem({
  295. label: "Refresh",
  296. onClick: function(args){context._onRefresh();}
  297. }));
  298. pMenu.addChild(new MenuSeparator());
  299. pMenu.addChild(new MenuItem({
  300. label: "Open",
  301. onClick: function(args){context._onOpen();}
  302. }));
  303. pMenu.addChild(new MenuItem({
  304. label: "Delete",
  305. onClick: function(args){context._onDelete();}
  306. }));
  307. pMenu.addChild(new MenuItem({
  308. label: "Add To Superfile",
  309. onClick: function(args){dijit.byId(context.id+"AddtoDropDown").openDropDown()}
  310. }));
  311. pMenu.addChild(new MenuSeparator());
  312. {
  313. var pSubMenu = new Menu();
  314. this.menuFilterOwner = this.addMenuItem(pSubMenu, {
  315. onClick: function (args) {
  316. context.filter.clear();
  317. context.filter.setValue(context.id + "Owner", context.menuFilterOwner.get("hpcc_value"));
  318. context.refreshGrid();
  319. }
  320. });
  321. this.menuFilterCluster = this.addMenuItem(pSubMenu, {
  322. onClick: function (args) {
  323. context.filter.clear();
  324. context.filter.setValue(context.id + "ClusterTargetSelect", context.menuFilterOwner.get("hpcc_value"));
  325. context.refreshGrid();
  326. }
  327. });
  328. pSubMenu.addChild(new MenuSeparator());
  329. this.menuFilterClearFilter = this.addMenuItem(pSubMenu, {
  330. label: "Clear",
  331. onClick: function () {
  332. context.filter.clear();
  333. context.refreshGrid();
  334. }
  335. });
  336. pMenu.addChild(new PopupMenuItem({
  337. label: "Filter",
  338. popup: pSubMenu
  339. }));
  340. }
  341. pMenu.startup();
  342. },
  343. initWorkunitsGrid: function() {
  344. var store = new ESPLogicalFile.CreateLFQueryStore();
  345. this.workunitsGrid = new declare([Grid, Pagination, Selection, ColumnResizer, Keyboard, DijitRegistry, ESPUtil.GridHelper])({
  346. allowSelectAll: true,
  347. deselectOnRefresh: false,
  348. store: store,
  349. rowsPerPage: 50,
  350. pagingLinks: 1,
  351. pagingTextBox: true,
  352. firstLastArrows: true,
  353. pageSizeOptions: [25, 50, 100],
  354. columns: {
  355. col1: selector({
  356. width: 27,
  357. selectorType: 'checkbox'
  358. }),
  359. isZipfile: {
  360. label: "C", width: 16, sortable: false,
  361. formatter: function (compressed) {
  362. if (compressed == true) {
  363. return "C";
  364. }
  365. return "";
  366. }
  367. },
  368. IsKeyFile: {
  369. label: "K", width: 16, sortable: false,
  370. formatter: function (keyfile) {
  371. if (keyfile == true) {
  372. return "K";
  373. }
  374. return "";
  375. }
  376. },
  377. isSuperfile: {
  378. label: "S", width: 16, sortable: false,
  379. formatter: function (superfile) {
  380. if (superfile == true) {
  381. return "S";
  382. }
  383. return "";
  384. }
  385. },
  386. Name: { label: "Logical Name",
  387. formatter: function (name, idx) {
  388. return "<a href='#' rowIndex=" + idx + " class='" + context.id + "LogicalNameClick'>" + name + "</a>";
  389. }
  390. },
  391. Owner: { label: "Owner", width: 72 },
  392. Description: { label: "Description", width: 153 },
  393. ClusterName: { label: "Cluster", width: 108 },
  394. RecordCount: { label: "Records", width: 72, sortable: false },
  395. Totalsize: { label: "Size", width: 72, sortable: false },
  396. Parts: { label: "Parts", width: 45, sortable: false },
  397. Modified: { label: "Modified (UTC/GMT)", width: 155, sortable: false }
  398. }
  399. }, this.id + "WorkunitsGrid");
  400. this.workunitsGrid.noDataMessage = "<span class='dojoxGridNoData'>Zero Logical Files(check filter).</span>";
  401. var context = this;
  402. on(document, "." + context.id + "LogicalNameClick:click", function (evt) {
  403. if (context._onRowDblClick) {
  404. var item = context.workunitsGrid.row(evt).data;
  405. context._onRowDblClick(item);
  406. }
  407. });
  408. this.workunitsGrid.on(".dgrid-row:dblclick", 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:contextmenu", function (evt) {
  415. if (context._onRowContextMenu) {
  416. var item = context.workunitsGrid.row(evt).data;
  417. var cell = context.workunitsGrid.cell(evt);
  418. var colField = cell.column.field;
  419. var mystring = "item." + colField;
  420. context._onRowContextMenu(item, colField, mystring);
  421. }
  422. });
  423. this.workunitsGrid.onSelectionChanged(function (event) {
  424. context.refreshActionState();
  425. });
  426. this.workunitsGrid.onContentChanged(function (object, removedFrom, insertedInto) {
  427. context.refreshActionState();
  428. });
  429. this.workunitsGrid.startup();
  430. },
  431. initFilter: function () {
  432. this.validateDialog = new Dialog({
  433. title: "Filter",
  434. content: "No filter criteria specified."
  435. });
  436. },
  437. refreshGrid: function (args) {
  438. this.workunitsGrid.set("query", this.getFilter());
  439. },
  440. refreshActionState: function () {
  441. var selection = this.workunitsGrid.getSelected();
  442. var hasSelection = false;
  443. for (var i = 0; i < selection.length; ++i) {
  444. hasSelection = true;
  445. }
  446. registry.byId(this.id + "Open").set("disabled", !hasSelection);
  447. registry.byId(this.id + "Delete").set("disabled", !hasSelection);
  448. registry.byId(this.id + "AddtoDropDown").set("disabled", !hasSelection);
  449. registry.byId(this.id + "DesprayDropDown").set("disabled", !hasSelection);
  450. if (hasSelection) {
  451. var sourceDiv = dom.byId(this.id + "DesprayDialogSource");
  452. domConstruct.empty(sourceDiv);
  453. var context = this;
  454. arrayUtil.forEach(selection, function (item, idx) {
  455. domConstruct.create("div", {
  456. innerHTML: item.Name
  457. }, sourceDiv);
  458. });
  459. }
  460. },
  461. ensureDFUWUPane: function (id, params) {
  462. var retVal = registry.byId(id);
  463. if (!retVal) {
  464. var context = this;
  465. retVal = new DFUWUDetailsWidget.fixCircularDependency({
  466. id: id,
  467. title: params.Wuid,
  468. closable: true,
  469. _hpccParams: params
  470. });
  471. this.addChild(retVal, 1);
  472. }
  473. return retVal;
  474. },
  475. ensureLFPane: function (id, params) {
  476. var obj = id.split("::");
  477. id = obj.join("");
  478. obj = id.split(".");
  479. id = obj.join("");
  480. var retVal = registry.byId(id);
  481. if (!retVal) {
  482. if (params.isSuperfile) {
  483. retVal = new SFDetailsWidget.fixCircularDependency({
  484. id: id,
  485. title: params.Name,
  486. closable: true,
  487. _hpccParams: params
  488. });
  489. } else {
  490. retVal = new LFDetailsWidget.fixCircularDependency({
  491. id: id,
  492. title: params.Name,
  493. closable: true,
  494. _hpccParams: {
  495. Name: params.Name
  496. }
  497. });
  498. }
  499. this.addChild(retVal, 1);
  500. }
  501. return retVal;
  502. }
  503. });
  504. });