GraphsWidget.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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/layout/_LayoutWidget",
  21. "dijit/_TemplatedMixin",
  22. "dijit/_WidgetsInTemplateMixin",
  23. "dijit/registry",
  24. "hpcc/ESPWorkunit",
  25. "hpcc/GraphPageWidget",
  26. "dojo/text!../templates/GraphsWidget.html",
  27. "dijit/layout/TabContainer"
  28. ], function (declare, lang, dom,
  29. _LayoutWidget, _TemplatedMixin, _WidgetsInTemplateMixin, registry,
  30. ESPWorkunit, GraphPageWidget,
  31. template) {
  32. return declare("GraphsWidget", [_LayoutWidget, _TemplatedMixin, _WidgetsInTemplateMixin], {
  33. templateString: template,
  34. baseClass: "GraphsWidget",
  35. //borderContainer: null,
  36. tabContainer: null,
  37. tabMap: [],
  38. selectedTab: null,
  39. buildRendering: function (args) {
  40. this.inherited(arguments);
  41. },
  42. postCreate: function (args) {
  43. this.inherited(arguments);
  44. this._initControls();
  45. },
  46. startup: function (args) {
  47. this.inherited(arguments);
  48. },
  49. resize: function (args) {
  50. this.inherited(arguments);
  51. this.tabContainer.resize();
  52. },
  53. layout: function (args) {
  54. this.inherited(arguments);
  55. },
  56. // Implementation ---
  57. onErrorClick: function (line, col) {
  58. },
  59. _initControls: function () {
  60. var context = this;
  61. this.tabContainer = registry.byId(this.id + "TabContainer");
  62. var context = this;
  63. this.tabContainer.watch("selectedChildWidget", function (name, oval, nval) {
  64. if (!nval.initalized) {
  65. nval.init(nval.params);
  66. }
  67. context.selectedTab = nval;
  68. });
  69. },
  70. ensurePane: function (id, params) {
  71. var retVal = this.tabMap[id];
  72. if (!retVal) {
  73. if (lang.exists("graph", params)) {
  74. retVal = new GraphPageWidget({
  75. id: id,
  76. Wuid: this.wu.Wuid,
  77. GraphName: params.graph.Name,
  78. title: params.graph.Name
  79. });
  80. }
  81. this.tabMap[id] = retVal;
  82. this.tabContainer.addChild(retVal);
  83. }
  84. },
  85. init: function (params) {
  86. if (params.Wuid) {
  87. this.wu = new ESPWorkunit({
  88. Wuid: params.Wuid
  89. });
  90. var monitorCount = 4;
  91. var context = this;
  92. this.wu.monitor(function () {
  93. if (context.wu.isComplete() || ++monitorCount % 5 == 0) {
  94. context.wu.getInfo({
  95. onGetGraphs: function (graphs) {
  96. for (var i = 0; i < graphs.length; ++i) {
  97. context.ensurePane(context.id + "graph_" + i, {
  98. graph: graphs[i]
  99. });
  100. }
  101. }
  102. });
  103. }
  104. });
  105. }
  106. }
  107. });
  108. });