ECLPlaygroundResultsWidget.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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/ECLPlaygroundResultsWidget.html",
  28. "dijit/layout/TabContainer"
  29. ], function (declare, lang, dom,
  30. _TemplatedMixin, _WidgetsInTemplateMixin, registry,
  31. _TabContainerWidget, ESPWorkunit, ResultWidget, LFDetailsWidget,
  32. template) {
  33. return declare("ECLPlaygroundResultsWidget", [_TabContainerWidget, _TemplatedMixin, _WidgetsInTemplateMixin], {
  34. templateString: template,
  35. baseClass: "ECLPlaygroundResultsWidget",
  36. selectedTab: null,
  37. TabPosition: "bottom",
  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 = registry.byId(id);
  48. if (!retVal) {
  49. if (lang.exists("Name", params) && lang.exists("Cluster", params)) {
  50. retVal = new LFDetailsWidget.fixCircularDependency({
  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.addChild(retVal);
  69. }
  70. return retVal;
  71. },
  72. init: function (params) {
  73. if (this.initalized)
  74. return;
  75. this.initalized = true;
  76. if (params.Wuid) {
  77. this.wu = ESPWorkunit.Get(params.Wuid);
  78. var monitorCount = 4;
  79. var context = this;
  80. this.wu.monitor(function () {
  81. if (context.wu.isComplete() || ++monitorCount % 5 == 0) {
  82. context.wu.getInfo({
  83. onGetWUExceptions: function (exceptions) {
  84. if (params.ShowErrors && exceptions.length) {
  85. context.ensurePane(context.id + "_exceptions", {
  86. Wuid: params.Wuid,
  87. onErrorClick: context.onErrorClick,
  88. exceptions: exceptions
  89. });
  90. context.initTab();
  91. }
  92. },
  93. onGetSourceFiles: function (sourceFiles) {
  94. if (params.SourceFiles) {
  95. for (var i = 0; i < sourceFiles.length; ++i) {
  96. var tab = context.ensurePane(context.id + "_logicalFile" + i, {
  97. Name: sourceFiles[i].Name,
  98. Cluster: sourceFiles[i].FileCluster
  99. });
  100. if (i == 0) {
  101. context.initTab();
  102. }
  103. }
  104. }
  105. },
  106. onGetResults: function (results) {
  107. if (!params.SourceFiles) {
  108. for (var i = 0; i < results.length; ++i) {
  109. var tab = context.ensurePane(context.id + "_result" + i, {
  110. result: results[i]
  111. });
  112. if (i == 0) {
  113. context.initTab();
  114. }
  115. }
  116. }
  117. }
  118. });
  119. var currSel = context.getSelectedChild();
  120. if (currSel && currSel.refresh) {
  121. currSel.refresh();
  122. }
  123. }
  124. });
  125. }
  126. },
  127. clear: function () {
  128. this.removeAllChildren();
  129. this.selectedTab = null;
  130. this.initalized = false;
  131. },
  132. refresh: function (wu) {
  133. if (this.workunit != wu) {
  134. this.clear();
  135. this.workunit = wu;
  136. this.init({
  137. Wuid: wu.Wuid,
  138. ShowErrors: true
  139. });
  140. }
  141. }
  142. });
  143. });