ResultsWidget.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. "hpcc/ResultWidget",
  26. "hpcc/LFDetailsWidget",
  27. "dojo/text!../templates/ResultsWidget.html",
  28. "dijit/layout/TabContainer"
  29. ], function (declare, lang, dom,
  30. _TemplatedMixin, _WidgetsInTemplateMixin, registry,
  31. _TabContainerWidget, ESPWorkunit, ResultWidget, LFDetailsWidget,
  32. template) {
  33. return declare("ResultsWidget", [_TabContainerWidget, _TemplatedMixin, _WidgetsInTemplateMixin], {
  34. templateString: template,
  35. baseClass: "ResultsWidget",
  36. //borderContainer: null,
  37. tabMap: [],
  38. selectedTab: null,
  39. TabPosition: "bottom",
  40. onErrorClick: function (line, col) {
  41. },
  42. initTab: function () {
  43. var currSel = this.getSelectedChild();
  44. if (currSel && !currSel.initalized) {
  45. currSel.init(currSel.params);
  46. }
  47. },
  48. ensurePane: function (id, params) {
  49. var retVal = this.tabMap[id];
  50. if (!retVal) {
  51. if (lang.exists("Name", params) && lang.exists("Cluster", params)) {
  52. retVal = new LFDetailsWidget.fixCircularDependency({
  53. id: id,
  54. title: params.Name,
  55. params: params
  56. });
  57. } else if (lang.exists("Wuid", params) && lang.exists("exceptions", params)) {
  58. retVal = new InfoGridWidget({
  59. id: id,
  60. title: "Errors/Warnings",
  61. params: params
  62. });
  63. } else if (lang.exists("result", params)) {
  64. retVal = new ResultWidget({
  65. id: id,
  66. title: params.result.Name,
  67. params: params
  68. });
  69. }
  70. this.tabMap[id] = retVal;
  71. this.addChild(retVal);
  72. }
  73. return retVal;
  74. },
  75. init: function (params) {
  76. if (this.initalized)
  77. return;
  78. this.initalized = true;
  79. if (params.Wuid) {
  80. this.wu = ESPWorkunit.Get(params.Wuid);
  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. this.initalized = false;
  135. },
  136. refresh: function (wu) {
  137. if (this.workunit != wu) {
  138. this.clear();
  139. this.workunit = wu;
  140. this.init({
  141. Wuid: wu.Wuid,
  142. ShowErrors: true
  143. });
  144. }
  145. }
  146. });
  147. });