ECLPlaygroundResultsWidget.js 5.3 KB

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