ResultsWidget.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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/on",
  20. "dgrid/OnDemandGrid",
  21. "dgrid/Keyboard",
  22. "dgrid/Selection",
  23. "dgrid/selector",
  24. "dgrid/extensions/ColumnResizer",
  25. "dgrid/extensions/DijitRegistry",
  26. "hpcc/GridDetailsWidget",
  27. "hpcc/ESPWorkunit",
  28. "hpcc/ResultWidget",
  29. "hpcc/LFDetailsWidget",
  30. "hpcc/SFDetailsWidget",
  31. "hpcc/ESPUtil"
  32. ], function (declare, lang, on,
  33. OnDemandGrid, Keyboard, Selection, selector, ColumnResizer, DijitRegistry,
  34. GridDetailsWidget, ESPWorkunit, ResultWidget, LFDetailsWidget, SFDetailsWidget, ESPUtil) {
  35. return declare("ResultsWidget", [GridDetailsWidget], {
  36. gridTitle: "Outputs",
  37. idProperty: "Sequence",
  38. wu: null,
  39. _onRowDblClickFile: function (row) {
  40. var tab = this.ensurePane(row, {
  41. logicalFile: true
  42. });
  43. this.selectChild(tab);
  44. },
  45. init: function (params) {
  46. if (this.inherited(arguments))
  47. return;
  48. if (params.Wuid) {
  49. this.wu = ESPWorkunit.Get(params.Wuid);
  50. var monitorCount = 4;
  51. var context = this;
  52. this.wu.monitor(function () {
  53. if (context.wu.isComplete() || ++monitorCount % 5 == 0) {
  54. context.refreshGrid();
  55. }
  56. });
  57. }
  58. this._refreshActionState();
  59. },
  60. createGrid: function (domID) {
  61. var retVal = new declare([OnDemandGrid, Keyboard, Selection, ColumnResizer, DijitRegistry, ESPUtil.GridHelper])({
  62. allowSelectAll: true,
  63. deselectOnRefresh: false,
  64. store: this.store,
  65. columns: {
  66. col1: selector({
  67. width: 27,
  68. selectorType: 'checkbox'
  69. }),
  70. Name: {
  71. label: "Name", width: 180, sortable: true,
  72. formatter: function (Name, idx) {
  73. return "<a href='#' rowIndex=" + idx + " class='" + context.id + "ResultClick'>" + Name + "</a>";
  74. }
  75. },
  76. FileName: {
  77. label: "FileName", sortable: true,
  78. formatter: function (FileName, idx) {
  79. return "<a href='#' rowIndex=" + idx + " class='" + context.id + "FileClick'>" + FileName + "</a>";
  80. }
  81. },
  82. Value: { label: "Value", width: 360, sortable: true }
  83. }
  84. }, domID);
  85. var context = this;
  86. on(document, "." + this.id + "ResultClick:click", function (evt) {
  87. if (context._onRowDblClick) {
  88. var row = context.grid.row(evt).data;
  89. context._onRowDblClick(row);
  90. }
  91. });
  92. on(document, "." + this.id + "FileClick:click", function (evt) {
  93. if (context._onRowDblClick) {
  94. var row = context.grid.row(evt).data;
  95. context._onRowDblClickFile(row);
  96. }
  97. });
  98. return retVal;
  99. },
  100. getDetailID: function (row, params) {
  101. if (row.FileName && params && params.logicalFile) {
  102. return this.id + "_" + "File" + row[this.idProperty];
  103. }
  104. return this.inherited(arguments);
  105. },
  106. createDetail: function (id, row, params) {
  107. if (row.FileName && params && params.logicalFile) {
  108. return new LFDetailsWidget.fixCircularDependency({
  109. id: id,
  110. title: "[F] " + row.Name,
  111. closable: true,
  112. hpcc: {
  113. type: "LFDetailsWidget",
  114. params: {
  115. Name: row.FileName
  116. }
  117. }
  118. });
  119. } else {
  120. return new ResultWidget({
  121. id: id,
  122. title: row.Name,
  123. closable: true,
  124. style: "padding: 0px; overflow: hidden",
  125. hpcc: {
  126. type: "ResultWidget",
  127. params: {
  128. Wuid: row.Wuid,
  129. Sequence: row.Sequence
  130. }
  131. }
  132. });
  133. }
  134. },
  135. refreshGrid: function (args) {
  136. var context = this;
  137. this.wu.getInfo({
  138. onGetResults: function (results) {
  139. context.store.setData(results);
  140. context.grid.refresh();
  141. }
  142. });
  143. }
  144. });
  145. });