ResultsWidget.js 7.9 KB

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