mainCtrl.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. 'use strict';
  19. angular.module('ambariAdminConsole')
  20. .controller('MainCtrl',['$scope', '$window','Auth', 'Alert', '$modal', 'Cluster', 'View', function($scope, $window, Auth, Alert, $modal, Cluster, View) {
  21. $scope.signOut = function() {
  22. var data = JSON.parse(localStorage.ambari);
  23. delete data.app.authenticated;
  24. delete data.app.loginName;
  25. delete data.app.user;
  26. localStorage.ambari = JSON.stringify(data);
  27. $window.location.pathname = '';
  28. $scope.hello = "hello";
  29. Auth.signout();
  30. };
  31. $scope.about = function() {
  32. var modalInstance = $modal.open({
  33. templateUrl:'views/modals/AboutModal.html',
  34. controller: ['$scope', function($scope) {
  35. $scope.ok = function() {
  36. modalInstance.close();
  37. };
  38. }]
  39. });
  40. };
  41. $scope.currentUser = Auth.getCurrentUser();
  42. $scope.cluster = null;
  43. $scope.isLoaded = null;
  44. function loadClusterData(){
  45. Cluster.getStatus().then(function(cluster) {
  46. $scope.cluster = cluster;
  47. $scope.isLoaded = true;
  48. if(cluster && cluster.Clusters.provisioning_state === 'INIT'){
  49. setTimeout(loadClusterData, 1000);
  50. }
  51. }).catch(function(data) {
  52. Alert.error('Cannot load cluster status', data.statusText);
  53. });
  54. }
  55. loadClusterData();
  56. $scope.viewInstances = [];
  57. View.getAllVisibleInstance().then(function(instances) {
  58. $scope.viewInstances = instances;
  59. });
  60. $scope.gotoViewsDashboard =function() {
  61. window.location = '/#/main/views';
  62. };
  63. }]);