SearchResultsWidget.js 11 KB

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