SearchResultsWidget.js 11 KB

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