LZBrowseWidget.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  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-class",
  23. "dojo/dom-form",
  24. "dojo/request/iframe",
  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. "dgrid/OnDemandGrid",
  34. "dgrid/tree",
  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/FileSpray",
  43. "hpcc/ESPUtil",
  44. "hpcc/ESPRequest",
  45. "hpcc/ESPDFUWorkunit",
  46. "hpcc/HexViewWidget",
  47. "hpcc/DFUWUDetailsWidget",
  48. "hpcc/TargetSelectWidget",
  49. "dojo/text!../templates/LZBrowseWidget.html",
  50. "dijit/layout/BorderContainer",
  51. "dijit/layout/TabContainer",
  52. "dijit/layout/ContentPane",
  53. "dijit/form/Form",
  54. "dijit/form/Textarea",
  55. "dijit/form/DateTextBox",
  56. "dijit/form/TimeTextBox",
  57. "dijit/form/Button",
  58. "dijit/form/RadioButton",
  59. "dijit/form/Select",
  60. "dijit/Toolbar",
  61. "dijit/ToolbarSeparator",
  62. "dijit/TooltipDialog",
  63. "dijit/form/DropDownButton",
  64. "dojox/layout/TableContainer",
  65. "dojox/form/Uploader",
  66. "dojox/form/uploader/FileList"
  67. ], function (declare, lang, arrayUtil, dom, domAttr, domClass, domForm, iframe, date, on,
  68. registry, Dialog, Menu, MenuItem, MenuSeparator, PopupMenuItem,
  69. OnDemandGrid, tree, Keyboard, Selection, selector, ColumnResizer, DijitRegistry, Pagination,
  70. _TabContainerWidget, FileSpray, ESPUtil, ESPRequest, ESPDFUWorkunit, HexViewWidget, DFUWUDetailsWidget, TargetSelectWidget,
  71. template) {
  72. return declare("LZBrowseWidget", [_TabContainerWidget, ESPUtil.FormHelper], {
  73. templateString: template,
  74. baseClass: "LZBrowseWidget",
  75. landingZonesTab: null,
  76. landingZonesGrid: null,
  77. tabMap: [],
  78. validateDialog: null,
  79. postCreate: function (args) {
  80. this.inherited(arguments);
  81. this.landingZonesTab = registry.byId(this.id + "_LandingZones");
  82. this.uploader = registry.byId(this.id + "Upload");
  83. this.uploadFileList = registry.byId(this.id + "UploadFileList");
  84. this.uploadFileList.uploaderId = this.id + "Upload";
  85. this.sprayFixedDestinationSelect = registry.byId(this.id + "SprayFixedDestination");
  86. this.sprayVariableDestinationSelect = registry.byId(this.id + "SprayVariableDestination");
  87. this.sprayXmlDestinationSelect = registry.byId(this.id + "SprayXmlDestinationSelect");
  88. this.dropZoneSelect = registry.byId(this.id + "DropZoneTargetSelect");
  89. this.fileListDialog = registry.byId(this.id + "FileListDialog");
  90. var context = this;
  91. this.connect(this.uploader, "onComplete", function () {
  92. context.fileListDialog.hide();
  93. context.refreshGrid();
  94. });
  95. // Workaround for HPCC-9414 --->
  96. this.connect(this.uploader, "onError", function (msg, e) {
  97. if (msg === "Error parsing server result:") {
  98. context.fileListDialog.hide();
  99. context.refreshGrid();
  100. }
  101. });
  102. // <--- Workaround for HPCC-9414
  103. },
  104. startup: function (args) {
  105. this.inherited(arguments);
  106. },
  107. getTitle: function () {
  108. return "Landing Zones";
  109. },
  110. _handleResponse: function (wuidQualifier, response) {
  111. if (lang.exists(wuidQualifier, response)) {
  112. var wu = ESPDFUWorkunit.Get(lang.getObject(wuidQualifier, false, response));
  113. wu.startMonitor(true);
  114. var tab = this.ensurePane("dfu", this.id + "_" + wu.ID, wu.ID, {
  115. Wuid: wu.ID
  116. });
  117. if (tab) {
  118. this.selectChild(tab);
  119. }
  120. }
  121. },
  122. // Hitched actions ---
  123. _onRefresh: function (event) {
  124. this.refreshGrid();
  125. },
  126. _onUpload: function (event) {
  127. this.uploadFileList.hideProgress();
  128. this.fileListDialog.show();
  129. },
  130. _onDownload: function (event) {
  131. var context = this;
  132. arrayUtil.forEach(this.landingZonesGrid.getSelected(), function (item, idx) {
  133. var downloadIframeName = "downloadIframe_" + item.calculatedID;
  134. var frame = iframe.create(downloadIframeName);
  135. var url = ESPRequest.getBaseURL("FileSpray") + "/DownloadFile?Name=" + encodeURIComponent(item.partialPath) + "&NetAddress=" + item.DropZone.NetAddress + "&Path=" + encodeURIComponent(item.DropZone.Path) + "&OS=" + item.DropZone.OS;
  136. iframe.setSrc(frame, url, true);
  137. });
  138. },
  139. _onDelete: function (event) {
  140. if (confirm('Delete selected files?')) {
  141. var context = this;
  142. arrayUtil.forEach(this.landingZonesGrid.getSelected(), function(item, idx) {
  143. FileSpray.DeleteDropZoneFile({
  144. request:{
  145. NetAddress: item.DropZone.NetAddress,
  146. Path: item.DropZone.Path,
  147. OS: item.DropZone.OS,
  148. Names: item.partialPath
  149. },
  150. load: function (response) {
  151. context.refreshGrid();
  152. }
  153. });
  154. });
  155. }
  156. },
  157. _onHexPreview: function (event) {
  158. var selections = this.landingZonesGrid.getSelected();
  159. var firstTab = null;
  160. var context = this;
  161. arrayUtil.forEach(selections, function (item, idx) {
  162. var tab = context.ensurePane("hex", context.id + "_" + item.calculatedID, item.displayName, {
  163. logicalFile: item.getLogicalFile()
  164. });
  165. if (firstTab === null) {
  166. firstTab = tab;
  167. }
  168. });
  169. if (firstTab) {
  170. this.selectChild(firstTab);
  171. }
  172. },
  173. _onUploadSubmit: function (event) {
  174. this.uploader.set("uploadUrl", this.uploadUrl);
  175. this.uploader.upload();
  176. },
  177. _onUploadCancel: function (event) {
  178. registry.byId(this.id + "FileListDialog").hide();
  179. },
  180. _onSprayFixed: function (event) {
  181. var context = this;
  182. var selections = this.landingZonesGrid.getSelected();
  183. var context = this;
  184. arrayUtil.forEach(selections, function (item, idx) {
  185. var formData = domForm.toObject(context.id + "SprayFixedDialog");
  186. lang.mixin(formData, {
  187. sourceIP: item.DropZone.NetAddress,
  188. sourcePath: item.fullPath
  189. });
  190. FileSpray.SprayFixed({
  191. request: formData
  192. }).then(function (response) {
  193. context._handleResponse("SprayFixedResponse.wuid", response);
  194. })
  195. });
  196. registry.byId(this.id + "SprayFixedDropDown").closeDropDown();
  197. },
  198. _onSprayFixedCancel: function (event) {
  199. registry.byId(this.id + "SprayFixedDropDown").closeDropDown();
  200. },
  201. _onSprayVariable: function(event) {
  202. var context = this;
  203. var selections = this.landingZonesGrid.getSelected();
  204. var context = this;
  205. arrayUtil.forEach(selections, function (item, idx) {
  206. var formData = domForm.toObject(context.id + "SprayVariableDialog");
  207. lang.mixin(formData, {
  208. sourceIP: item.DropZone.NetAddress,
  209. sourcePath: item.DropZone.fullPath
  210. });
  211. FileSpray.SprayVariable({
  212. request: formData
  213. }).then(function (response) {
  214. context._handleResponse("SprayResponse.wuid", response);
  215. });
  216. });
  217. registry.byId(this.id + "SprayVariableDropDown").closeDropDown();
  218. },
  219. _onSprayVariableCancel: function (event) {
  220. registry.byId(this.id + "SprayVariableDropDown").closeDropDown();
  221. },
  222. _onSprayXml: function(event) {
  223. var context = this;
  224. var selections = this.landingZonesGrid.getSelected();
  225. var context = this;
  226. arrayUtil.forEach(selections, function (item, idx) {
  227. var formData = domForm.toObject(context.id + "SprayXmlDialog");
  228. lang.mixin(formData, {
  229. sourceIP: item.DropZone.NetAddress,
  230. sourcePath: item.DropZone.fullPath
  231. });
  232. FileSpray.SprayVariable({
  233. request: formData
  234. }).then(function (response) {
  235. context._handleResponse("SprayResponse.wuid", response);
  236. });
  237. });
  238. registry.byId(this.id + "SprayXmlDropDown").closeDropDown();
  239. },
  240. _onSprayXmlCancel: function (event) {
  241. registry.byId(this.id + "SprayXmlDropDown").closeDropDown();
  242. },
  243. _onRowDblClick: function (wuid) {
  244. var wuTab = this.ensurePane(this.id + "_" + wuid, {
  245. Wuid: wuid
  246. });
  247. this.selectChild(wuTab);
  248. },
  249. _onRowContextMenu: function (item, colField, mystring) {
  250. },
  251. // Implementation ---
  252. init: function (params) {
  253. if (this.inherited(arguments))
  254. return;
  255. this.initLandingZonesGrid();
  256. this.selectChild(this.landingZonesTab, true);
  257. var context = this;
  258. this.sprayFixedDestinationSelect.init({
  259. Groups: true
  260. });
  261. this.sprayVariableDestinationSelect.init({
  262. Groups: true
  263. });
  264. this.sprayXmlDestinationSelect.init({
  265. Groups: true
  266. });
  267. this.dropZoneSelect.init({
  268. DropZones: true,
  269. callback: function (value, item) {
  270. context.uploadUrl = "/FileSpray/UploadFile.json?upload_&rawxml_=1&NetAddress=" + item.machine.Netaddress + "&OS=" + item.machine.OS + "&Path=" + item.machine.Directory;
  271. }
  272. });
  273. },
  274. initTab: function () {
  275. var currSel = this.getSelectedChild();
  276. if (currSel && !currSel.initalized) {
  277. if (currSel.id == this.landingZonesTab.id) {
  278. } else {
  279. if (!currSel.initalized) {
  280. currSel.init(currSel.params);
  281. }
  282. }
  283. }
  284. },
  285. addMenuItem: function (menu, details) {
  286. var menuItem = new MenuItem(details);
  287. menu.addChild(menuItem);
  288. return menuItem;
  289. },
  290. initLandingZonesGrid: function () {
  291. var store = new FileSpray.CreateLandingZonesStore();
  292. this.landingZonesGrid = new declare([OnDemandGrid, Keyboard, Selection, ColumnResizer, DijitRegistry, ESPUtil.GridHelper])({
  293. allowSelectAll: true,
  294. deselectOnRefresh: false,
  295. store: store,
  296. columns: {
  297. col1: selector({
  298. width: 27,
  299. selectorType: 'checkbox',
  300. disabled: function (item) {
  301. if (item.type) {
  302. switch (item.type) {
  303. case "dropzone":
  304. case "folder":
  305. return true;
  306. }
  307. }
  308. return false;
  309. }
  310. }),
  311. displayName: tree({
  312. label: "Name",
  313. collapseOnRefresh: true,
  314. formatter: function (name, row) {
  315. var img = "../files/img/";
  316. if (row.isDir === undefined) {
  317. img += "server.png";
  318. } else if (row.isDir) {
  319. img += "folder.png";
  320. } else {
  321. img += "file.png";
  322. }
  323. return "<img src='" + img + "'/>&nbsp;" + name;
  324. }
  325. }),
  326. filesize: { label: "Size", width: 108 },
  327. modifiedtime: { label: "Date", width: 180 }
  328. },
  329. getSelected: function () {
  330. var retVal = [];
  331. var store = FileSpray.CreateFileListStore();
  332. for (key in this.selection) {
  333. retVal.push(store.get(key));
  334. }
  335. return retVal;
  336. }
  337. }, this.id + "LandingZonesGrid");
  338. this.landingZonesGrid.set("noDataMessage", "<span>Zero Files (Upload Some Files).</span>");
  339. var context = this;
  340. on(document, ".WuidClick:click", function (evt) {
  341. if (context._onRowDblClick) {
  342. var item = context.landingZonesGrid.row(evt).data;
  343. context._onRowDblClick(item.Wuid);
  344. }
  345. });
  346. this.landingZonesGrid.on(".dgrid-row:dblclick", function (evt) {
  347. if (context._onRowDblClick) {
  348. var item = context.landingZonesGrid.row(evt).data;
  349. context._onRowDblClick(item.Wuid);
  350. }
  351. });
  352. this.landingZonesGrid.on(".dgrid-row:contextmenu", function (evt) {
  353. if (context._onRowContextMenu) {
  354. var item = context.landingZonesGrid.row(evt).data;
  355. var cell = context.landingZonesGrid.cell(evt);
  356. var colField = cell.column.field;
  357. var mystring = "item." + colField;
  358. context._onRowContextMenu(item, colField, mystring);
  359. }
  360. });
  361. this.landingZonesGrid.onSelectionChanged(function (event) {
  362. context.refreshActionState();
  363. });
  364. this.landingZonesGrid.onContentChanged(function (object, removedFrom, insertedInto) {
  365. context.refreshActionState();
  366. });
  367. this.landingZonesGrid.startup();
  368. this.refreshActionState();
  369. },
  370. refreshGrid: function (args) {
  371. this.landingZonesGrid.set("query", {
  372. id: "*"
  373. });
  374. },
  375. refreshActionState: function () {
  376. var selection = this.landingZonesGrid.getSelected();
  377. var hasSelection = selection.length;
  378. registry.byId(this.id + "HexPreview").set("disabled", !hasSelection);
  379. registry.byId(this.id + "Download").set("disabled", !hasSelection);
  380. registry.byId(this.id + "Delete").set("disabled", !hasSelection);
  381. registry.byId(this.id + "SprayFixedDropDown").set("disabled", !hasSelection);
  382. registry.byId(this.id + "SprayVariableDropDown").set("disabled", !hasSelection);
  383. registry.byId(this.id + "SprayXmlDropDown").set("disabled", !hasSelection);
  384. },
  385. ensurePane: function (type, id, title, params) {
  386. var retVal = registry.byId(id);
  387. if (!retVal) {
  388. var context = this;
  389. switch (type) {
  390. case "hex":
  391. retVal = new HexViewWidget({
  392. id: id,
  393. title: title,
  394. closable: true,
  395. params: params
  396. });
  397. break;
  398. case "dfu":
  399. retVal = new DFUWUDetailsWidget.fixCircularDependency({
  400. id: id,
  401. title: title,
  402. closable: true,
  403. params: params
  404. });
  405. break;
  406. }
  407. if (retVal) {
  408. this.addChild(retVal);
  409. }
  410. }
  411. return retVal;
  412. }
  413. });
  414. });