GraphsWidget.js 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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/GraphPageWidget",
  26. "dojo/text!../templates/GraphsWidget.html",
  27. "dijit/layout/TabContainer"
  28. ], function (declare, lang, dom,
  29. _TemplatedMixin, _WidgetsInTemplateMixin, registry,
  30. _TabContainerWidget, ESPWorkunit, GraphPageWidget,
  31. template) {
  32. return declare("GraphsWidget", [_TabContainerWidget, _TemplatedMixin, _WidgetsInTemplateMixin], {
  33. templateString: template,
  34. baseClass: "GraphsWidget",
  35. tabMap: [],
  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, params) {
  45. var retVal = this.tabMap[id];
  46. if (!retVal) {
  47. if (lang.exists("graph", params)) {
  48. retVal = new GraphPageWidget({
  49. id: id,
  50. Wuid: this.wu.Wuid,
  51. GraphName: params.graph.Name,
  52. title: params.graph.Name
  53. });
  54. }
  55. this.tabMap[id] = retVal;
  56. this.addChild(retVal);
  57. }
  58. },
  59. init: function (params) {
  60. if (this.initalized)
  61. return;
  62. this.initalized = true;
  63. if (params.Wuid) {
  64. this.wu = ESPWorkunit.Get(params.Wuid);
  65. var monitorCount = 4;
  66. var context = this;
  67. this.wu.monitor(function () {
  68. if (context.wu.isComplete() || ++monitorCount % 5 == 0) {
  69. context.wu.getInfo({
  70. onGetGraphs: function (graphs) {
  71. for (var i = 0; i < graphs.length; ++i) {
  72. context.ensurePane(context.id + "_graph" + i, {
  73. graph: graphs[i]
  74. });
  75. if (i == 0) {
  76. context.initTab();
  77. }
  78. }
  79. }
  80. });
  81. }
  82. });
  83. }
  84. }
  85. });
  86. });