views_controller.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. App.MainViewsController = Em.Controller.extend({
  20. name:'mainViewsController',
  21. isDataLoaded: false,
  22. ambariViews: [],
  23. dataLoading: function () {
  24. var viewsController = this;
  25. var dfd = $.Deferred();
  26. if (this.get('isDataLoaded')) {
  27. dfd.resolve(this.get('ambariViews'));
  28. } else {
  29. var interval = setInterval(function () {
  30. if (viewsController.get('isDataLoaded')) {
  31. dfd.resolve(viewsController.get('ambariViews'));
  32. clearInterval(interval);
  33. }
  34. }, 50);
  35. }
  36. return dfd.promise();
  37. },
  38. loadAmbariViews: function () {
  39. App.ajax.send({
  40. name: 'views.info',
  41. sender: this,
  42. success: 'loadAmbariViewsSuccess',
  43. error: 'loadAmbariViewsError'
  44. });
  45. },
  46. loadAmbariViewsSuccess: function (data, opt, params) {
  47. if (data.items.length) {
  48. App.ajax.send({
  49. name: 'views.instances',
  50. sender: this,
  51. success: 'loadViewInstancesSuccess',
  52. error: 'loadViewInstancesError'
  53. });
  54. } else {
  55. this.set('ambariViews', []);
  56. this.set('isDataLoaded', true);
  57. }
  58. },
  59. loadAmbariViewsError: function () {
  60. this.set('ambariViews', []);
  61. this.set('isDataLoaded', true);
  62. },
  63. loadViewInstancesSuccess: function (data, opt, params) {
  64. this.set('ambariViews', []);
  65. var instances = [];
  66. data.items.forEach(function (view) {
  67. view.versions.forEach(function (version) {
  68. version.instances.forEach(function (instance) {
  69. var current_instance = Em.Object.create({
  70. iconPath: instance.ViewInstanceInfo.icon_path || "/img/ambari-view-default.png",
  71. label: instance.ViewInstanceInfo.label || version.ViewVersionInfo.label || instance.ViewInstanceInfo.view_name,
  72. visible: instance.ViewInstanceInfo.visible || false,
  73. version: instance.ViewInstanceInfo.version,
  74. description: instance.ViewInstanceInfo.description || Em.I18n.t('views.main.instance.noDescription'),
  75. viewName: instance.ViewInstanceInfo.view_name,
  76. instanceName: instance.ViewInstanceInfo.instance_name,
  77. href: instance.ViewInstanceInfo.context_path
  78. });
  79. instances.push(current_instance);
  80. }, this);
  81. }, this);
  82. }, this);
  83. this.get('ambariViews').pushObjects(instances);
  84. this.set('isDataLoaded', true);
  85. },
  86. loadViewInstancesError: function () {
  87. this.set('ambariViews', []);
  88. this.set('isDataLoaded', true);
  89. },
  90. setView: function(event) {
  91. if(event.context){
  92. App.router.transitionTo('views.viewDetails', event.context);
  93. }
  94. }
  95. });