ECLPlaygroundResultsWidget.js 6.0 KB

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