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. TabPosition: "bottom",
  36. tabMap: [],
  37. onErrorClick: function (line, col) {
  38. },
  39. initTab: function () {
  40. var currSel = this.getSelectedChild();
  41. if (currSel && !currSel.initalized) {
  42. currSel.init(currSel.params);
  43. }
  44. },
  45. ensurePane: function (id, params) {
  46. var retVal = this.tabMap[id];
  47. if (!retVal) {
  48. if (lang.exists("graph", params)) {
  49. retVal = new GraphPageWidget({
  50. id: id,
  51. Wuid: this.wu.Wuid,
  52. GraphName: params.graph.Name,
  53. title: params.graph.Name
  54. });
  55. }
  56. this.tabMap[id] = retVal;
  57. this.addChild(retVal);
  58. }
  59. return retVal;
  60. },
  61. init: function (params) {
  62. if (this.initalized)
  63. return;
  64. this.initalized = true;
  65. if (params.Wuid) {
  66. this.wu = ESPWorkunit.Get(params.Wuid);
  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. });