NavbarCtrl.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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('NavbarCtrl',['$scope', 'Cluster', '$location', 'uiAlert', 'ROUTES', 'LDAP', 'ConfirmationModal', '$rootScope', function($scope, Cluster, $location, uiAlert, ROUTES, LDAP, ConfirmationModal, $rootScope) {
  21. $scope.cluster = null;
  22. $scope.editCluster = {
  23. name : '',
  24. editingName : false
  25. };
  26. Cluster.getStatus().then(function(cluster) {
  27. $scope.cluster = cluster;
  28. }).catch(function(data) {
  29. uiAlert.danger(data.status, data.message);
  30. });
  31. $scope.toggleEditName = function($event) {
  32. if ($event && $event.keyCode !== 27) {
  33. // 27 = Escape key
  34. return false;
  35. }
  36. $scope.editCluster.name = $scope.cluster.Clusters.cluster_name;
  37. $scope.editCluster.editingName = !$scope.editCluster.editingName;
  38. };
  39. $scope.confirmClusterNameChange = function() {
  40. ConfirmationModal.show('Confirm Cluster Name Change', 'Are you sure you want to change the cluster name to ' + $scope.editCluster.name + '?')
  41. .then(function() {
  42. $scope.saveClusterName();
  43. }).catch(function() {
  44. // user clicked cancel
  45. $scope.toggleEditName();
  46. });
  47. };
  48. $scope.saveClusterName = function() {
  49. var oldClusterName = $scope.cluster.Clusters.cluster_name,
  50. newClusterName = $scope.editCluster.name;
  51. Cluster.editName(oldClusterName, newClusterName).then(function(data) {
  52. $scope.cluster.Clusters.cluster_name = newClusterName;
  53. uiAlert.success('Success', 'The cluster has been renamed to ' + newClusterName + '.');
  54. }).catch(function(data) {
  55. uiAlert.danger(data.data.status, data.data.message);
  56. });
  57. $scope.toggleEditName();
  58. };
  59. $scope.isActive = function(path) {
  60. var route = ROUTES;
  61. angular.forEach(path.split('.'), function(routeObj) {
  62. route = route[routeObj];
  63. });
  64. var r = new RegExp( route.url.replace(/(:\w+)/, '\\w+'));
  65. return r.test($location.path());
  66. };
  67. $scope.isLDAPConfigured = false;
  68. $scope.ldapData = {};
  69. LDAP.get().then(function(data) {
  70. $scope.ldapData = data.data;
  71. $scope.isLDAPConfigured = data.data['LDAP']['configured'];
  72. });
  73. $scope.syncLDAP = function() {
  74. ConfirmationModal.show('Sync LDAP', 'Are you sure you want to sync LDAP?').then(function() {
  75. LDAP.sync($scope.ldapData['LDAP'].groups, $scope.ldapData['LDAP'].users).then(function() {
  76. uiAlert.success('LDAP synced successful');
  77. $rootScope.$evalAsync(function() {
  78. $rootScope.LDAPSynced = true;
  79. });
  80. }).catch(function(data) {
  81. uiAlert.danger(data.data.status, data.data.message);
  82. });
  83. });
  84. };
  85. }]);