SearchResultsWidget.js 12 KB

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