ResultsWidget.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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/ResultsWidget",
  22. "dojo/_base/array",
  23. "dojo/on",
  24. "dijit/layout/ContentPane",
  25. "dgrid/OnDemandGrid",
  26. "dgrid/Keyboard",
  27. "dgrid/Selection",
  28. "dgrid/selector",
  29. "dgrid/extensions/ColumnResizer",
  30. "dgrid/extensions/DijitRegistry",
  31. "hpcc/GridDetailsWidget",
  32. "hpcc/ESPRequest",
  33. "hpcc/ESPWorkunit",
  34. "hpcc/ResultWidget",
  35. "hpcc/LFDetailsWidget",
  36. "hpcc/SFDetailsWidget",
  37. "hpcc/ESPUtil"
  38. ], function (declare, lang, i18n, nlsCommon, nlsSpecific, arrayUtil, on,
  39. ContentPane,
  40. OnDemandGrid, Keyboard, Selection, selector, ColumnResizer, DijitRegistry,
  41. GridDetailsWidget, ESPRequest, ESPWorkunit, ResultWidget, LFDetailsWidget, SFDetailsWidget, ESPUtil) {
  42. return declare("ResultsWidget", [GridDetailsWidget], {
  43. i18n: lang.mixin(nlsCommon, nlsSpecific),
  44. gridTitle: nlsSpecific.title,
  45. idProperty: "Sequence",
  46. wu: null,
  47. _onRowDblClickFile: function (row) {
  48. var tab = this.ensurePane(row, {
  49. logicalFile: true
  50. });
  51. this.selectChild(tab);
  52. },
  53. _onRowDblClickView: function (row, viewName) {
  54. var tab = this.ensurePane(row, {
  55. resultView: true,
  56. viewName: viewName
  57. });
  58. this.selectChild(tab);
  59. },
  60. init: function (params) {
  61. if (this.inherited(arguments))
  62. return;
  63. if (params.Wuid) {
  64. this.wu = ESPWorkunit.Get(params.Wuid);
  65. var monitorCount = 4;
  66. var context = this;
  67. this.wu.monitor(function () {
  68. if (context.wu.isComplete() || ++monitorCount % 5 == 0) {
  69. context.refreshGrid();
  70. }
  71. });
  72. }
  73. this._refreshActionState();
  74. },
  75. createGrid: function (domID) {
  76. var retVal = new declare([OnDemandGrid, Keyboard, Selection, ColumnResizer, DijitRegistry, ESPUtil.GridHelper])({
  77. allowSelectAll: true,
  78. deselectOnRefresh: false,
  79. store: this.store,
  80. columns: {
  81. col1: selector({
  82. width: 27,
  83. selectorType: 'checkbox'
  84. }),
  85. Name: {
  86. label: this.i18n.Name, width: 180, sortable: true,
  87. formatter: function (Name, idx) {
  88. return "<a href='#' rowIndex=" + idx + " class='" + context.id + "ResultClick'>" + Name + "</a>";
  89. }
  90. },
  91. FileName: {
  92. label: this.i18n.FileName, sortable: true,
  93. formatter: function (FileName, idx) {
  94. return "<a href='#' rowIndex=" + idx + " class='" + context.id + "FileClick'>" + FileName + "</a>";
  95. }
  96. },
  97. Value: {
  98. label: this.i18n.Value,
  99. width: 360,
  100. sortable: true
  101. },
  102. ResultViews: {
  103. label: this.i18n.Views, sortable: true,
  104. formatter: function (ResultViews, idx) {
  105. var retVal = "";
  106. arrayUtil.forEach(ResultViews, function (item, idx) {
  107. retVal += "<a href='#' viewName=" + encodeURIComponent(item) + " class='" + context.id + "ViewClick'>" + item + "</a>&nbsp;";
  108. });
  109. return retVal;
  110. }
  111. }
  112. }
  113. }, domID);
  114. var context = this;
  115. on(document, "." + this.id + "ResultClick:click", function (evt) {
  116. if (context._onRowDblClick) {
  117. var row = context.grid.row(evt).data;
  118. context._onRowDblClick(row);
  119. }
  120. });
  121. on(document, "." + this.id + "FileClick:click", function (evt) {
  122. if (context._onRowDblClick) {
  123. var row = context.grid.row(evt).data;
  124. context._onRowDblClickFile(row);
  125. }
  126. });
  127. on(document, "." + this.id + "ViewClick:click", function (evt) {
  128. if (context._onRowDblClick) {
  129. var row = context.grid.row(evt).data;
  130. context._onRowDblClickView(row, evt.srcElement.getAttribute("viewName"));
  131. }
  132. });
  133. return retVal;
  134. },
  135. getDetailID: function (row, params) {
  136. if (row.FileName && params && params.logicalFile) {
  137. return this.id + "_" + "File" + row[this.idProperty];
  138. } else if (params && params.resultView && params.viewName) {
  139. return this.id + "_" + params.viewName + row[this.idProperty];
  140. }
  141. return this.inherited(arguments);
  142. },
  143. createDetail: function (id, row, params) {
  144. if (row.FileName && params && params.logicalFile) {
  145. return new LFDetailsWidget.fixCircularDependency({
  146. id: id,
  147. title: "[F] " + row.Name,
  148. closable: true,
  149. hpcc: {
  150. type: "LFDetailsWidget",
  151. params: {
  152. Name: row.FileName
  153. }
  154. }
  155. });
  156. } else if (params && params.resultView && params.viewName) {
  157. return new ContentPane({
  158. id: id,
  159. title: row.Name + " [" + decodeURIComponent(params.viewName) + "]",
  160. closable: true,
  161. content: dojo.create("iframe", {
  162. src: ESPRequest.getBaseURL("WsWorkunits") + "/WUResultView?Wuid=" + row.Wuid + "&ResultName=" + row.Name + "&ViewName=" + params.viewName,
  163. style: "border: 0; width: 100%; height: 100%"
  164. }),
  165. hpcc: {
  166. type: "ContentPane",
  167. params: {
  168. Name: row.Name,
  169. viewName: params.viewName
  170. }
  171. },
  172. noRefresh: true
  173. });
  174. } else {
  175. return new ResultWidget({
  176. id: id,
  177. title: row.Name,
  178. closable: true,
  179. style: "padding: 0px; overflow: hidden",
  180. hpcc: {
  181. type: "ResultWidget",
  182. params: {
  183. Wuid: row.Wuid,
  184. Sequence: row.Sequence
  185. }
  186. }
  187. });
  188. }
  189. },
  190. refreshGrid: function (args) {
  191. var context = this;
  192. this.wu.getInfo({
  193. onGetResults: function (results) {
  194. context.store.setData(results);
  195. context.grid.refresh();
  196. }
  197. });
  198. }
  199. });
  200. });