ResultsWidget.js 6.0 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/dom",
  20. "dijit/_TemplatedMixin",
  21. "dijit/_WidgetsInTemplateMixin",
  22. "dijit/registry",
  23. "hpcc/_TabContainerWidget",
  24. "hpcc/ESPWorkunit",
  25. "dojo/text!../templates/ResultsWidget.html",
  26. "dijit/layout/TabContainer"
  27. ], function (declare, lang, dom,
  28. _TemplatedMixin, _WidgetsInTemplateMixin, registry,
  29. _TabContainerWidget, ESPWorkunit,
  30. template) {
  31. return declare("ResultsWidget", [_TabContainerWidget, _TemplatedMixin, _WidgetsInTemplateMixin], {
  32. templateString: template,
  33. baseClass: "ResultsWidget",
  34. //borderContainer: null,
  35. tabContainer: null,
  36. tabMap: [],
  37. selectedTab: null,
  38. onErrorClick: function (line, col) {
  39. },
  40. initTab: function () {
  41. var currSel = this.getSelectedChild();
  42. if (currSel && !currSel.initalized) {
  43. currSel.init(currSel.params);
  44. }
  45. },
  46. ensurePane: function (id, params) {
  47. var retVal = this.tabMap[id];
  48. if (!retVal) {
  49. if (lang.exists("Name", params) && lang.exists("Cluster", params)) {
  50. retVal = new LFDetailsWidget({
  51. id: id,
  52. title: params.Name,
  53. params: params
  54. });
  55. } else if (lang.exists("Wuid", params) && lang.exists("exceptions", params)) {
  56. retVal = new InfoGridWidget({
  57. id: id,
  58. title: "Errors/Warnings",
  59. params: params
  60. });
  61. } else if (lang.exists("result", params)) {
  62. retVal = new ResultWidget({
  63. id: id,
  64. title: params.result.Name,
  65. params: params
  66. });
  67. }
  68. this.tabMap[id] = retVal;
  69. this.addChild(retVal);
  70. }
  71. return retVal;
  72. },
  73. init: function (params) {
  74. if (this.initalized)
  75. return;
  76. this.initalized = true;
  77. if (params.Wuid) {
  78. this.wu = new ESPWorkunit({
  79. Wuid: params.Wuid
  80. });
  81. var monitorCount = 4;
  82. var context = this;
  83. this.wu.monitor(function () {
  84. if (context.wu.isComplete() || ++monitorCount % 5 == 0) {
  85. context.wu.getInfo({
  86. onGetWUExceptions: function (exceptions) {
  87. if (params.ShowErrors && exceptions.length) {
  88. context.ensurePane(context.id + "_exceptions", {
  89. Wuid: params.Wuid,
  90. onErrorClick: context.onErrorClick,
  91. exceptions: exceptions
  92. });
  93. context.initTab();
  94. }
  95. },
  96. onGetSourceFiles: function (sourceFiles) {
  97. if (params.SourceFiles) {
  98. for (var i = 0; i < sourceFiles.length; ++i) {
  99. var tab = context.ensurePane(context.id + "_logicalFile" + i, {
  100. Name: sourceFiles[i].Name,
  101. Cluster: sourceFiles[i].FileCluster
  102. });
  103. if (i == 0) {
  104. context.initTab();
  105. }
  106. }
  107. }
  108. },
  109. onGetResults: function (results) {
  110. if (!params.SourceFiles) {
  111. for (var i = 0; i < results.length; ++i) {
  112. var tab = context.ensurePane(context.id + "_result" + i, {
  113. result: results[i]
  114. });
  115. if (i == 0) {
  116. context.initTab();
  117. }
  118. }
  119. }
  120. }
  121. });
  122. var currSel = context.getSelectedChild();
  123. if (currSel) {
  124. currSel.refresh();
  125. }
  126. }
  127. });
  128. }
  129. },
  130. clear: function () {
  131. this.removeAllChildren();
  132. this.tabMap = [];
  133. this.selectedTab = null;
  134. },
  135. refresh: function (wu) {
  136. if (this.workunit != wu) {
  137. this.clear();
  138. this.workunit = wu;
  139. this.init({
  140. Wuid: wu.Wuid,
  141. ShowErrors: true
  142. });
  143. }
  144. }
  145. });
  146. });