GraphsWidget.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 = new ESPWorkunit({
  65. Wuid: params.Wuid
  66. });
  67. var monitorCount = 4;
  68. var context = this;
  69. this.wu.monitor(function () {
  70. if (context.wu.isComplete() || ++monitorCount % 5 == 0) {
  71. context.wu.getInfo({
  72. onGetGraphs: function (graphs) {
  73. for (var i = 0; i < graphs.length; ++i) {
  74. context.ensurePane(context.id + "_graph" + i, {
  75. graph: graphs[i]
  76. });
  77. if (i == 0) {
  78. context.initTab();
  79. }
  80. }
  81. }
  82. });
  83. }
  84. });
  85. }
  86. }
  87. });
  88. });