SearchResultsWidget.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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/on",
  21. "dojo/promise/all",
  22. "dijit/form/Button",
  23. "dojox/widget/Standby",
  24. "dgrid/OnDemandGrid",
  25. "dgrid/Keyboard",
  26. "dgrid/Selection",
  27. "dgrid/selector",
  28. "dgrid/extensions/ColumnResizer",
  29. "dgrid/extensions/DijitRegistry",
  30. "hpcc/GridDetailsWidget",
  31. "hpcc/WsWorkunits",
  32. "hpcc/FileSpray",
  33. "hpcc/WsDfu",
  34. "hpcc/WUDetailsWidget",
  35. "hpcc/DFUWUDetailsWidget",
  36. "hpcc/LFDetailsWidget",
  37. "hpcc/SFDetailsWidget",
  38. "hpcc/ESPUtil"
  39. ], function (declare, lang, arrayUtil, on, all,
  40. Button,
  41. Standby,
  42. OnDemandGrid, Keyboard, Selection, selector, ColumnResizer, DijitRegistry,
  43. GridDetailsWidget, WsWorkunits, FileSpray, WsDfu, WUDetailsWidget, DFUWUDetailsWidget, LFDetailsWidget, SFDetailsWidget, ESPUtil) {
  44. return declare("SearchResultsWidget", [GridDetailsWidget], {
  45. gridTitle: "Search Results",
  46. idProperty: "id",
  47. doSearch: function (searchText) {
  48. this.params = {
  49. searchText: searchText
  50. };
  51. this.searchText = searchText;
  52. this.selectChild(this.gridTab);
  53. this.refreshGrid();
  54. },
  55. init: function (params) {
  56. if (this.inherited(arguments))
  57. return;
  58. if (params.searchText) {
  59. this.doSearch(params.searchText);
  60. }
  61. this._refreshActionState();
  62. },
  63. getTitle: function () {
  64. return "Results Widget";
  65. },
  66. createGrid: function (domID) {
  67. var context = this;
  68. var retVal = new declare([OnDemandGrid, Keyboard, Selection, ColumnResizer, DijitRegistry, ESPUtil.GridHelper])({
  69. allowSelectAll: true,
  70. deselectOnRefresh: false,
  71. store: this.store,
  72. loadingMessage: "Loading data...",
  73. noDataMessage: "No results found.",
  74. columns: {
  75. col1: selector({ width: 27, selectorType: 'checkbox' }),
  76. Type: { label: "What", width: 108, sortable: true },
  77. Reason: { label: "Where", width: 108, sortable: true },
  78. Summary: {
  79. label: "Who", sortable: true,
  80. formatter: function (summary, idx) {
  81. return "<a href='#' rowIndex=" + idx + " class='" + context.id + "SearchResultClick'>" + summary + "</a>";
  82. }
  83. }
  84. }
  85. }, domID);
  86. var context = this;
  87. on(document, "." + this.id + "SearchResultClick:click", function (evt) {
  88. if (context._onRowDblClick) {
  89. var row = retVal.row(evt).data;
  90. context._onRowDblClick(row);
  91. }
  92. });
  93. this.standby = new Standby({ target: domID });
  94. document.body.appendChild(this.standby.domNode);
  95. this.standby.startup();
  96. return retVal;
  97. },
  98. createDetail: function (id, row, params) {
  99. switch (row._type) {
  100. case "Wuid":
  101. return new WUDetailsWidget({
  102. id: id,
  103. title: row.Summary,
  104. closable: true,
  105. hpcc: {
  106. params: {
  107. Wuid: row._wuid
  108. }
  109. }
  110. });
  111. break;
  112. case "DFUWuid":
  113. return new DFUWUDetailsWidget.fixCircularDependency({
  114. id: id,
  115. title: row.Summary,
  116. closable: true,
  117. hpcc: {
  118. params: {
  119. Wuid: row._wuid
  120. }
  121. }
  122. });
  123. break;
  124. case "LogicalFile":
  125. if (row.isSuperfile) {
  126. return new SFDetailsWidget.fixCircularDependency({
  127. id: id,
  128. title: row.Summary,
  129. closable: true,
  130. hpcc: {
  131. params: {
  132. Name: row._name
  133. }
  134. }
  135. });
  136. } else {
  137. return new LFDetailsWidget.fixCircularDependency({
  138. id: id,
  139. title: row.Summary,
  140. closable: true,
  141. hpcc: {
  142. params: {
  143. Name: row._name
  144. }
  145. }
  146. });
  147. }
  148. break;
  149. default:
  150. break;
  151. }
  152. return null;
  153. },
  154. loadWUQueryResponse: function(prefix, response) {
  155. var workunits = lang.getObject("WUQueryResponse.Workunits.ECLWorkunit", false, response)
  156. if (workunits) {
  157. var idPrefix = prefix.split(" ").join("_");
  158. var context = this;
  159. arrayUtil.forEach(workunits, function (item, idx) {
  160. context.store.add({
  161. id: "WsWorkunitsWUQuery" + idPrefix + idx,
  162. Type: "ECL Workunit",
  163. Reason: prefix,
  164. Summary: item.Wuid,
  165. _type: "Wuid",
  166. _wuid: item.Wuid
  167. });
  168. });
  169. return workunits.length;
  170. }
  171. return 0;
  172. },
  173. loadGetDFUWorkunitsResponse: function (prefix, response) {
  174. var workunits = lang.getObject("GetDFUWorkunitsResponse.results.DFUWorkunit", false, response)
  175. if (workunits) {
  176. var idPrefix = prefix.split(" ").join("_");
  177. var context = this;
  178. arrayUtil.forEach(workunits, function (item, idx) {
  179. context.store.add({
  180. id: "FileSprayGetDFUWorkunits" + idPrefix + idx,
  181. Type: "DFU Workunit",
  182. Reason: prefix,
  183. Summary: item.ID,
  184. _type: "DFUWuid",
  185. _wuid: item.ID
  186. });
  187. });
  188. return workunits.length;
  189. }
  190. return 0;
  191. },
  192. loadGetDFUWorkunitResponse: function (prefix, response) {
  193. var workunit = lang.getObject("GetDFUWorkunitResponse.result", false, response)
  194. if (workunit) {
  195. var idPrefix = prefix.split(" ").join("_");
  196. this.store.add({
  197. id: "FileSprayGetDFUWorkunits" + idPrefix + idx,
  198. Type: "DFU Workunit",
  199. Reason: prefix,
  200. Summary: workunit.ID,
  201. _type: "DFUWuid",
  202. _wuid: workunit.ID
  203. });
  204. return 1;
  205. }
  206. return 0;
  207. },
  208. loadDFUQueryResponse: function (prefix, response) {
  209. var items = lang.getObject("DFUQueryResponse.DFULogicalFiles.DFULogicalFile", false, response)
  210. if (items) {
  211. var idPrefix = prefix.split(" ").join("_");
  212. var context = this;
  213. arrayUtil.forEach(items, function (item, idx) {
  214. context.store.add({
  215. id: "WsDfuDFUQuery" + idPrefix + idx,
  216. Type: "Logical File",
  217. Reason: prefix,
  218. Summary: item.Name,
  219. _type: "LogicalFile",
  220. _name: item.Name
  221. });
  222. });
  223. return items.length;
  224. }
  225. return 0;
  226. },
  227. refreshGrid: function (args) {
  228. this.store.setData([]);
  229. this.grid.refresh();
  230. if (this.searchText) {
  231. this.standby.show();
  232. var context = this;
  233. // ECL WU ---
  234. all([
  235. WsWorkunits.WUQuery({ request: { Wuid: this.searchText }, suppressExceptionToaster: true }).then(function (response) {
  236. context.loadWUQueryResponse("Wuid", response);
  237. }),
  238. WsWorkunits.WUQuery({ request: { Jobname: "*" + this.searchText + "*" } }).then(function (response) {
  239. context.loadWUQueryResponse("Job Name", response);
  240. }),
  241. WsWorkunits.WUQuery({ request: { Owner: this.searchText } }).then(function (response) {
  242. context.loadWUQueryResponse("Owner", response);
  243. }),
  244. WsWorkunits.WUQuery({ request: { ECL: this.searchText } }).then(function (response) {
  245. context.loadWUQueryResponse("ECL", response);
  246. }),
  247. // DFU WU ---
  248. FileSpray.GetDFUWorkunit({ request: { wuid: this.searchText }, suppressExceptionToaster: true }).then(function (response) {
  249. context.loadGetDFUWorkunitResponse("Wuid", response);
  250. }),
  251. FileSpray.GetDFUWorkunits({ request: { Jobname: "*" + this.searchText + "*" } }).then(function (response) {
  252. context.loadGetDFUWorkunitsResponse("Job Name", response);
  253. }),
  254. FileSpray.GetDFUWorkunits({ request: { Owner: this.searchText } }).then(function (response) {
  255. context.loadGetDFUWorkunitsResponse("Owner", response);
  256. }),
  257. // Logical Files ---
  258. WsDfu.DFUQuery({ request: { LogicalName: "*" + this.searchText + "*" } }).then(function (response) {
  259. context.loadDFUQueryResponse("Logical Name", response);
  260. }),
  261. WsDfu.DFUQuery({ request: { Description: "*" + this.searchText + "*" } }).then(function (response) {
  262. context.loadDFUQueryResponse("Description", response);
  263. }),
  264. WsDfu.DFUQuery({ request: { Owner: this.searchText } }).then(function (response) {
  265. context.loadDFUQueryResponse("Owner", response);
  266. })
  267. ]).then(function (results) {
  268. context.standby.hide();
  269. }, function (error) {
  270. context.standby.hide();
  271. });
  272. }
  273. },
  274. refreshActionState: function (selection) {
  275. this.inherited(arguments);
  276. }
  277. });
  278. });