SearchResultsWidget.js 11 KB

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