http://git-wip-us.apache.org/repos/asf/ambari/blob/e83bf1bd/ambari-admin/src/main/resources/ui/admin-web/app/assets/fonts/Roboto-Regular-webfont.ttf ---------------------------------------------------------------------- diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/assets/fonts/Roboto-Regular-webfont.ttf b/ambari-admin/src/main/resources/ui/admin-web/app/assets/fonts/Roboto-Regular-webfont.ttf new file mode 100644 index 0000000..305f0d5 Binary files /dev/null and b/ambari-admin/src/main/resources/ui/admin-web/app/assets/fonts/Roboto-Regular-webfont.ttf differ
http://git-wip-us.apache.org/repos/asf/ambari/blob/e83bf1bd/ambari-admin/src/main/resources/ui/admin-web/app/assets/fonts/Roboto-Regular-webfont.woff ---------------------------------------------------------------------- diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/assets/fonts/Roboto-Regular-webfont.woff b/ambari-admin/src/main/resources/ui/admin-web/app/assets/fonts/Roboto-Regular-webfont.woff new file mode 100644 index 0000000..ac7452a Binary files /dev/null and b/ambari-admin/src/main/resources/ui/admin-web/app/assets/fonts/Roboto-Regular-webfont.woff differ http://git-wip-us.apache.org/repos/asf/ambari/blob/e83bf1bd/ambari-admin/src/main/resources/ui/admin-web/app/index.html ---------------------------------------------------------------------- diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/index.html b/ambari-admin/src/main/resources/ui/admin-web/app/index.html index 52e41f6..bf033e6 100644 --- a/ambari-admin/src/main/resources/ui/admin-web/app/index.html +++ b/ambari-admin/src/main/resources/ui/admin-web/app/index.html @@ -44,53 +44,47 @@ <p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p> <![endif]--> -<div id="top-nav" ng-controller="MainCtrl"> - <header class="navbar navbar-static-top navbar-inverse"> - <div class="navbar-inner"> - <div class="container"> - <a href="{{fromSiteRoot('/#/main/dashboard')}}" class="logo"><img src="/img/ambari-logo.png" alt="{{'common.apacheAmbari' | translate}}" title="{{'common.apacheAmbari' | translate}}" data-qa="ambari-logo"></a> - <a href="{{fromSiteRoot('/#/main/dashboard')}}" class="brand" title="{{'common.apacheAmbari' | translate}}" data-qa="ambari-title">{{'common.ambari' | translate}}</a> - <ul class="nav navbar-nav navbar-right"> - <li> - <div class="btn-group navbar-views-dropdown" dropdown is-open="viewsdropdown.isopen" ng-mouseover="viewsdropdown.isopen=true" ng-mouseout="viewsdropdown.isopen=false"> - <a href="{{fromSiteRoot('/#/main/views')}}" ng-click="gotoViewsDashboard()" class="dropdown-toggle"><i class="fa fa-th"></i></a> - <ul class="dropdown-menu" role="menu"> - <li ng-repeat="instance in viewInstances"><a href="{{fromSiteRoot('/#/main/views/' + instance.viewUrl)}}" target="_blank">{{instance.label}}</a></li> - <li ng-show="!viewInstances.length" class="disabled"><a>{{'common.noViews' | translate}}</a></li> - </ul> - </div> - </li> - <li> - <div class="btn-group" dropdown is-open="status.isopen"> - <button type="button" class="btn btn-default dropdown-toggle navbar-btn" ng-disabled="disabled"> - <i class="fa fa-user"></i> {{currentUser}} <span class="caret"></span> - </button> - <ul class="dropdown-menu" role="menu"> - <li><a href ng-click="about()">{{'common.about' | translate}}</a></li> - <li class="divider"></li> - <li><a href ng-click="signOut()">{{'common.signOut' | translate}}</a></li> - </ul> - </div> - </li> - </ul> - </div> - </div> - </header> -</div> +<div id="wrapper" ng-controller="AppCtrl"> + <div ng-include="'views/sideNav.html'" ng-controller="SideNavCtrl"></div> -<div class="container"> - <div class="row"> - <div class="col-sm-3"> - <div ng-include="'views/leftNavbar.html'" ng-controller="NavbarCtrl"></div> + <div id="main"> + <div id="top-nav"> + <nav class="navbar navbar-default navbar-static-top"> + <div class="container"> + <div class="navbar-header navbar-nav"> + <ol class="breadcrumb"> + <li ng-repeat="breadcrumb in breadcrumbs" ng-class="$last && 'active'">{{breadcrumb}}</li> + </ol> + </div> + <ul class="nav navbar-nav navbar-right"> + <li> + <p class="navbar-text">{{cluster.Clusters.cluster_name}}</p> + </li> + <li class="dropdown"> + <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" ng-disabled="disabled"> + <i class="fa fa-user"></i> {{currentUser}} <span class="caret"></span> + </a> + <ul class="dropdown-menu"> + <li><a href ng-click="about()">{{'common.about' | translate}}</a></li> + <li role="separator" class="divider"></li> + <li><a href ng-click="signOut()">{{'common.signOut' | translate}}</a></li> + </ul> + </li> + </ul> + </div> + </nav> </div> - <div class="col-sm-9"> - <ng-view></ng-view> + <div class="container main-container"> + <div class="row"> + <div class="col-sm-12"> + <ng-view></ng-view> + </div> + </div> </div> </div> </div> - <!-- build:js scripts/vendor.js --> <!-- bower:js --> <script src="bower_components/jquery/dist/jquery.js"></script> @@ -119,6 +113,7 @@ <script src="bower_components/bootstrap/js/scrollspy.js"></script> <script src="bower_components/bootstrap/js/collapse.js"></script> <script src="bower_components/bootstrap/js/tab.js"></script> +<script src="scripts/theme/bootstrap-ambari.js"></script> <!-- endbuild --> @@ -126,26 +121,25 @@ <script src="scripts/app.js"></script> <script src="scripts/routes.js"></script> <script src="scripts/i18n.config.js"></script> -<script src="scripts/controllers/mainCtrl.js"></script> -<script src="scripts/controllers/NavbarCtrl.js"></script> +<script src="scripts/controllers/clusters/ClusterInformationCtrl.js"></script> +<script src="scripts/controllers/AppCtrl.js"></script> +<script src="scripts/controllers/SideNavCtrl.js"></script> <script src="scripts/controllers/authentication/AuthenticationMainCtrl.js"></script> <script src="scripts/controllers/loginActivities/LoginActivitiesMainCtrl.js"></script> <script src="scripts/controllers/loginActivities/LoginMessageMainCtrl.js"></script> <script src="scripts/controllers/loginActivities/HomeDirectoryCtrl.js"></script> -<script src="scripts/controllers/users/UsersCreateCtrl.js"></script> -<script src="scripts/controllers/users/UsersListCtrl.js"></script> -<script src="scripts/controllers/users/UsersShowCtrl.js"></script> -<script src="scripts/controllers/groups/GroupsListCtrl.js"></script> -<script src="scripts/controllers/groups/GroupsCreateCtrl.js"></script> -<script src="scripts/controllers/groups/GroupsEditCtrl.js"></script> +<script src="scripts/controllers/userManagement/UserManagementCtrl.js"></script> +<script src="scripts/controllers/userManagement/UserCreateCtrl.js"></script> +<script src="scripts/controllers/userManagement/UsersListCtrl.js"></script> +<script src="scripts/controllers/userManagement/UserEditCtrl.js"></script> +<script src="scripts/controllers/userManagement/GroupsListCtrl.js"></script> +<script src="scripts/controllers/userManagement/GroupCreateCtrl.js"></script> +<script src="scripts/controllers/userManagement/GroupEditCtrl.js"></script> <script src="scripts/controllers/ambariViews/ViewsListCtrl.js"></script> <script src="scripts/controllers/ambariViews/ViewsEditCtrl.js"></script> <script src="scripts/controllers/ambariViews/ViewUrlCtrl.js"></script> <script src="scripts/controllers/ambariViews/ViewUrlEditCtrl.js"></script> <script src="scripts/controllers/ambariViews/CreateViewInstanceCtrl.js"></script> -<script src="scripts/controllers/clusters/ClustersManageAccessCtrl.js"></script> -<script src="scripts/controllers/clusters/UserAccessListCtrl.js"></script> -<script src="scripts/controllers/clusters/ExportBlueprintCtrl.js"></script> <script src="scripts/controllers/stackVersions/StackVersionsCreateCtrl.js"></script> <script src="scripts/controllers/stackVersions/StackVersionsListCtrl.js"></script> <script src="scripts/controllers/stackVersions/StackVersionsEditCtrl.js"></script> @@ -159,7 +153,6 @@ <script src="scripts/services/Utility.js"></script> <script src="scripts/services/UserConstants.js"></script> <script src="scripts/services/User.js"></script> -<script src="scripts/services/GroupConstants.js"></script> <script src="scripts/services/Group.js"></script> <script src="scripts/services/RemoteCluster.js"></script> <script src="scripts/services/View.js"></script> http://git-wip-us.apache.org/repos/asf/ambari/blob/e83bf1bd/ambari-admin/src/main/resources/ui/admin-web/app/scripts/app.js ---------------------------------------------------------------------- diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/app.js b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/app.js index 80e2813..225eb12 100644 --- a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/app.js +++ b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/app.js @@ -33,7 +33,8 @@ angular.module('ambariAdminConsole', [ isLDAPConfigurationSupported: false, isLoginActivitiesSupported: false, maxStackTraceLength: 1000, - errorStorageSize: 500000 + errorStorageSize: 500000, + minRowsToShowPagination: 10 }) .config(['RestangularProvider', '$httpProvider', '$provide', 'Settings', function(RestangularProvider, $httpProvider, $provide, Settings) { // Config Ajax-module http://git-wip-us.apache.org/repos/asf/ambari/blob/e83bf1bd/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/AppCtrl.js ---------------------------------------------------------------------- diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/AppCtrl.js b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/AppCtrl.js new file mode 100644 index 0000000..eb9a9b0 --- /dev/null +++ b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/AppCtrl.js @@ -0,0 +1,177 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +'use strict'; + +angular.module('ambariAdminConsole') +.controller('AppCtrl',['$scope','$rootScope', '$route', '$window','Auth', 'Alert', '$modal', 'Cluster', '$translate', '$http', 'Settings', 'Utility', '$q', function($scope, $rootScope, $route, $window, Auth, Alert, $modal, Cluster, $translate, $http, Settings, Utility, $q) { + var $t = $translate.instant; + $scope.signOut = function () { + Auth.signout().finally(function () { + $window.location.pathname = Settings.siteRoot; + }); + }; + + //todo replace with breadcrumb service + $scope.$watch(function () { + return $route.current; + }, function (value) { + var breadcrumbs = [$t('common.admin')]; + if (value && value.$$route && value.$$route.label) { + breadcrumbs.push(value.$$route.label); + } + $scope.breadcrumbs = breadcrumbs; + }); + + + $scope.ambariVersion = null; + $rootScope.supports = {}; + $rootScope.authDataLoad = $q.defer(); + + Utility.getUserPref('user-pref-' + Auth.getCurrentUser() + '-supports').then(function (data) { + $rootScope.supports = data.data ? data.data : {}; + }); + + $http.get(Settings.baseUrl + '/users/' + Auth.getCurrentUser() + '/authorizations?fields=*') + .then(function (data) { + var auth = !!data.data && !!data.data.items ? data.data.items.map(function (a) { + return a.AuthorizationInfo.authorization_id; + }) : [], + canPersistData = auth.indexOf('CLUSTER.MANAGE_USER_PERSISTED_DATA') > -1; + $rootScope.authDataLoad.resolve(canPersistData); + if (auth.indexOf('AMBARI.RENAME_CLUSTER') == -1) { + $window.location = $rootScope.fromSiteRoot("/#/main/dashboard"); + } + }); + + $scope.about = function () { + var ambariVersion = $scope.ambariVersion; + var modalInstance = $modal.open({ + templateUrl: 'views/modals/AboutModal.html', + controller: ['$scope', function ($scope) { + $scope.ok = function () { + modalInstance.close(); + }; + $scope.ambariVersion = ambariVersion; + }] + }); + }; + + $scope.currentUser = Auth.getCurrentUser(); + + $scope.cluster = null; + $scope.isLoaded = null; + + function loadAmbariVersion() { + Cluster.getAmbariVersion().then(function (version) { + $scope.ambariVersion = version; + }); + } + + function loadClusterData() { + Cluster.getStatus().then(function (cluster) { + $rootScope.cluster = cluster; + $scope.cluster = cluster; + $scope.isLoaded = true; + if (cluster && cluster.Clusters.provisioning_state === 'INIT') { + setTimeout(loadClusterData, 1000); + } + }).catch(function (data) { + Alert.error($t('common.alerts.cannotLoadClusterStatus'), data.statusText); + }); + } + + loadClusterData(); + loadAmbariVersion(); + + $scope.startInactiveTimeoutMonitoring = function (timeout) { + var TIME_OUT = timeout; + var active = true; + var lastActiveTime = Date.now(); + + var keepActive = function () { + if (active) { + lastActiveTime = Date.now(); + } + }; + + $(window).bind('mousemove', keepActive); + $(window).bind('keypress', keepActive); + $(window).bind('click', keepActive); + + var checkActiveness = function () { + var remainTime = TIME_OUT - (Date.now() - lastActiveTime); + if (remainTime < 0) { + active = false; + $(window).unbind('mousemove', keepActive); + $(window).unbind('keypress', keepActive); + $(window).unbind('click', keepActive); + clearInterval($rootScope.userActivityTimeoutInterval); + $scope.signOut(); + } else if (remainTime < 60000 && !$rootScope.timeoutModal) { + $rootScope.timeoutModal = $modal.open({ + templateUrl: 'views/modals/TimeoutWarning.html', + backdrop: false, + controller: ['$scope', 'Auth', function ($scope, Auth) { + $scope.remainTime = 60; + $scope.title = $t('main.autoLogOut'); + $scope.primaryText = $t('main.controls.remainLoggedIn'); + $scope.secondaryText = $t('main.controls.logOut'); + $scope.remain = function () { + $rootScope.timeoutModal.close(); + delete $rootScope.timeoutModal; + }; + $scope.logout = function () { + $rootScope.timeoutModal.close(); + delete $rootScope.timeoutModal; + Auth.signout().finally(function () { + $window.location.pathname = Settings.siteRoot; + }); + }; + $scope.countDown = function () { + $scope.remainTime--; + $scope.$apply(); + if ($scope.remainTime == 0) { + Auth.signout().finally(function () { + $window.location.pathname = Settings.siteRoot; + }); + } + }; + setInterval($scope.countDown, 1000); + }] + }); + } + }; + $rootScope.userActivityTimeoutInterval = window.setInterval(checkActiveness, 1000); + }; + + // Send noop requests every 10 seconds just to keep backend session alive + $scope.startNoopPolling = function () { + $rootScope.noopPollingInterval = setInterval(Cluster.getAmbariTimeout, 10000); + }; + + if (!$rootScope.userActivityTimeoutInterval) { + Cluster.getAmbariTimeout().then(function (timeout) { + $rootScope.userTimeout = Number(timeout) * 1000; + if ($rootScope.userTimeout > 0) + $scope.startInactiveTimeoutMonitoring($rootScope.userTimeout); + }); + } + if (!$rootScope.noopPollingInterval) { + $scope.startNoopPolling(); + } +}]); http://git-wip-us.apache.org/repos/asf/ambari/blob/e83bf1bd/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/NavbarCtrl.js ---------------------------------------------------------------------- diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/NavbarCtrl.js b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/NavbarCtrl.js deleted file mode 100644 index cbf38e8..0000000 --- a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/NavbarCtrl.js +++ /dev/null @@ -1,106 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -'use strict'; - -angular.module('ambariAdminConsole') -.controller('NavbarCtrl',['$scope', 'Cluster', '$location', 'Alert', 'ROUTES', 'ConfirmationModal', '$rootScope', 'Stack', '$translate', 'Settings', function($scope, Cluster, $location, Alert, ROUTES, ConfirmationModal, $rootScope, Stack, $translate, Settings) { - var $t = $translate.instant; - $scope.cluster = null; - $scope.totalRepos = 0; - $scope.editCluster = { - name : '', - editingName : false - }; - $scope.settings = Settings; - - function loadClusterData() { - Cluster.getStatus().then(function (cluster) { - $scope.cluster = cluster; - Stack.allRepos({version: '', - cluster: { - options: [], - current: null - }}, {}).then(function (repos) { - $scope.totalRepos = repos.itemTotal; - }); - if (cluster && cluster.Clusters.provisioning_state === 'INIT') { - setTimeout(loadClusterData, 1000); - } - }).catch(function (data) { - Alert.error($t('common.alerts.cannotLoadClusterStatus'), data.statusText); - }); - } - loadClusterData(); - - $scope.toggleEditName = function($event) { - if ($event && $event.keyCode !== 27) { - // 27 = Escape key - return false; - } - - $scope.editCluster.name = $scope.cluster.Clusters.cluster_name; - $scope.editCluster.editingName = !$scope.editCluster.editingName; - }; - - $scope.clusterDisplayName = function () { - var name=""; - if($scope.cluster && $scope.cluster.Clusters) - { - name = $scope.cluster.Clusters.cluster_name; - } - return name.length > 13 ? name.substr(0, 13) + "..." : name; - }; - - $scope.confirmClusterNameChange = function() { - ConfirmationModal.show( - $t('common.clusterNameChangeConfirmation.title'), - $t('common.clusterNameChangeConfirmation.message', { - clusterName: $scope.editCluster.name - }) - ) - .then(function() { - $scope.saveClusterName(); - }).catch(function() { - // user clicked cancel - $scope.toggleEditName(); - }); - }; - - $scope.saveClusterName = function() { - var oldClusterName = $scope.cluster.Clusters.cluster_name, - newClusterName = $scope.editCluster.name; - - Cluster.editName(oldClusterName, newClusterName).then(function(data) { - $scope.cluster.Clusters.cluster_name = newClusterName; - Alert.success($t('common.alerts.clusterRenamed', {clusterName: newClusterName})); - }).catch(function(data) { - Alert.error($t('common.alerts.cannotRenameCluster', {clusterName: newClusterName}), data.data.message); - }); - - $scope.toggleEditName(); - }; - - $scope.isActive = function(path) { - var route = ROUTES; - angular.forEach(path.split('.'), function(routeObj) { - route = route[routeObj]; - }); - var r = new RegExp( route.url.replace(/(:\w+)/, '\\w+')); - return r.test($location.path()); - }; -}]); http://git-wip-us.apache.org/repos/asf/ambari/blob/e83bf1bd/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/SideNavCtrl.js ---------------------------------------------------------------------- diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/SideNavCtrl.js b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/SideNavCtrl.js new file mode 100644 index 0000000..558d110 --- /dev/null +++ b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/SideNavCtrl.js @@ -0,0 +1,68 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +'use strict'; + +angular.module('ambariAdminConsole') +.controller('SideNavCtrl', ['$scope', '$location', 'ROUTES', '$rootScope', 'Stack', 'Settings', function($scope, $location, ROUTES, $rootScope, Stack, Settings) { + $scope.totalRepos = 0; + $scope.settings = Settings; + + $scope.$watch(function() { + return $rootScope.cluster; + }, function() { + $scope.cluster = $rootScope.cluster; + }, true); + + function loadRepos() { + Stack.allRepos({version: '', + cluster: { + options: [], + current: null + }}, {}).then(function (repos) { + $scope.totalRepos = repos.itemTotal; + }); + } + + function initNavigationBar () { + $('body').on('DOMNodeInserted', '.navigation-bar', function() { + $('.navigation-bar').navigationBar({ + fitHeight: true, + collapseNavBarClass: 'fa-angle-double-left', + expandNavBarClass: 'fa-angle-double-right' + }); + //initTooltips(); + $('body').off('DOMNodeInserted', '.navigation-bar'); + }); + } + + function initTooltips () { + $('[rel="tooltip"]').tooltip(); + } + + initNavigationBar(); + loadRepos(); + + $scope.isActive = function(path) { + var route = ROUTES; + angular.forEach(path.split('.'), function(routeObj) { + route = route[routeObj]; + }); + var r = new RegExp( route.url.replace(/(:\w+)/, '\\w+')); + return r.test($location.path()); + }; +}]); http://git-wip-us.apache.org/repos/asf/ambari/blob/e83bf1bd/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/ambariViews/CreateViewInstanceCtrl.js ---------------------------------------------------------------------- diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/ambariViews/CreateViewInstanceCtrl.js b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/ambariViews/CreateViewInstanceCtrl.js index 94b8cc1..1199313 100644 --- a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/ambariViews/CreateViewInstanceCtrl.js +++ b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/ambariViews/CreateViewInstanceCtrl.js @@ -18,263 +18,247 @@ 'use strict'; angular.module('ambariAdminConsole') -.controller('CreateViewInstanceCtrl',['$scope', 'View','RemoteCluster' , 'Alert', 'Cluster', '$routeParams', '$location', 'UnsavedDialog', '$translate', function($scope, View, RemoteCluster, Alert, Cluster, $routeParams, $location, UnsavedDialog, $translate) { +.controller('CreateViewInstanceCtrl', +['$scope', 'View','RemoteCluster' , 'Alert', 'Cluster', '$routeParams', '$location', 'UnsavedDialog', '$translate', '$modalInstance', 'views', 'instanceClone', '$q', +function($scope, View, RemoteCluster, Alert, Cluster, $routeParams, $location, UnsavedDialog, $translate, $modalInstance, views, instanceClone, $q) { + var $t = $translate.instant; + var viewToVersionMap = {}; + var instances = {}; $scope.form = {}; - $scope.constants = { - props: $t('views.properties') + $scope.nameValidationPattern = /^\s*\w*\s*$/; + $scope.isLoading = false; + $scope.clusterType = 'LOCAL_AMBARI'; // LOCAL_AMBARI, REMOTE_AMBARI, NONE + $scope.views = views; + $scope.instanceClone = instanceClone; + $scope.viewOptions = []; + $scope.versionOptions = []; + $scope.localClusters = []; + $scope.remoteClusters = []; + $scope.clusterOptions = []; + $scope.fieldsWithErrors = []; + $scope.isInstanceExists = false; + $scope.clusterConfigurable = false; + $scope.clusterSettingsCount = 0; + $scope.nonClusterSettingsCount = 0; + $scope.instanceTemplate = null; + $scope.formData = { + view: null, + version: null, + instanceName: '', + displayName: '', + description: '', + clusterName: null, + visible: true, + settings: [] }; - $scope.isClone = $routeParams.instanceId ? true : false; - var targetUrl = ''; - - function loadMeta(){ - View.getMeta($routeParams.viewId, $scope.version).then(function(data) { - var viewVersion = data.data, - parameters; - - $scope.view = viewVersion; - parameters = viewVersion.ViewVersionInfo.parameters; - angular.forEach(parameters, function (item) { - item.value = item['defaultValue']; - item.clusterConfig = !!item.clusterConfig; - item.displayName = item.name.replace(/\./g, '\.\u200B'); - item.clusterConfig ? $scope.numberOfClusterConfigs++ : $scope.numberOfSettingConfigs++; - }); - - $scope.clusterConfigurable = viewVersion.ViewVersionInfo.cluster_configurable; - $scope.clusterConfigurableErrorMsg = $scope.clusterConfigurable ? "" : $t('views.alerts.cannotUseOption'); - - $scope.instance = { - view_name: viewVersion.ViewVersionInfo.view_name, - version: viewVersion.ViewVersionInfo.version, - instance_name: '', - label: '', - visible: true, - icon_path: '', - icon64_path: '', - properties: parameters, - description: '', - clusterType: 'NONE' - }; + $scope.updateVersionOptions = function () { + if (viewToVersionMap[$scope.formData.view.value]) { + $scope.versionOptions = viewToVersionMap[$scope.formData.view.value]; + $scope.formData.version = $scope.versionOptions[0]; + $scope.updateSettingsList(); + } + }; - //if cloning view instance, then get the instance data and populate settings and properties - if($scope.isClone) { - View.getInstance($routeParams.viewId, $routeParams.version, $routeParams.instanceId) - .then(function(instance) { - $scope.instanceClone = instance; - $scope.instance.version = instance.ViewInstanceInfo.version; - $scope.version = instance.ViewInstanceInfo.version; - $scope.instance.instance_name = instance.ViewInstanceInfo.instance_name + $t('common.copy'); - $scope.instance.label = instance.ViewInstanceInfo.label + $t('common.copy'); - $scope.instance.visible = instance.ViewInstanceInfo.visible; - $scope.instance.description = instance.ViewInstanceInfo.description; - $scope.instance.clusterType=instance.ViewInstanceInfo.cluster_type; - - initConfigurations(parameters); - }) - .catch(function(data) { - Alert.error($t('views.alerts.cannotLoadInstanceInfo'), data.data.message); + $scope.updateSettingsList = function() { + $scope.formData.settings = []; + $scope.clusterSettingsCount = 0; + $scope.nonClusterSettingsCount = 0; + $scope.instanceTemplate = null; + angular.forEach($scope.views, function(view) { + if (view.view_name === $scope.formData.view.value) { + angular.forEach(view.versionsList, function(version) { + if (version.ViewVersionInfo.version === $scope.formData.version.value) { + $scope.formData.settings = version.ViewVersionInfo.parameters.map(function(param) { + param.value = param['defaultValue']; + param.clusterConfig = Boolean(param.clusterConfig); + param.displayName = param.name.replace(/\./g, '\.\u200B'); + $scope.clusterSettingsCount += param.clusterConfig; + $scope.nonClusterSettingsCount += !param.clusterConfig; + return param; + }); + $scope.clusterConfigurable = version.ViewVersionInfo.cluster_configurable; + } }); } - - loadClusters(); - loadRemoteClusters(); - }); - } - - function initConfigurations(parameters) { - var configuration = angular.copy($scope.instanceClone.ViewInstanceInfo.properties); - - //iterate through the view parameters and get the values from the instance being cloned - for (var i = 0; i < parameters.length; i++) { - parameters[i].value = configuration[parameters[i].name]; - parameters[i].clusterConfig = !!parameters[i].clusterConfig; - } - } - - $scope.$watch(function(scope) { - return scope.version; - }, function(version) { - if( version ){ - loadMeta(); - } - }); + }; - $scope.enableLocalCluster = function () { - if($scope.errorKeys.length > 0) { - $scope.errorKeys.forEach( function (key) { - try { - $scope.form.instanceCreateForm[key].validationError = false; - $scope.form.instanceCreateForm[key].validationMessage = ''; - } catch (e) { - console.log($t('views.alerts.unableToResetErrorMessage', {key: key})); - } - }); - $scope.errorKeys = []; + $scope.switchClusterType = function(clusterType) { + $scope.clusterType = clusterType; + if (clusterType === 'LOCAL_AMBARI') { + $scope.clusterOptions = $scope.localClusters; + resetErrors(); + } else if (clusterType === 'REMOTE_AMBARI') { + $scope.clusterOptions = $scope.remoteClusters; + resetErrors(); + } else { + $scope.clusterOptions = []; } + $scope.formData.clusterName = $scope.clusterOptions[0]; }; - // $scope.view = viewVersion; - $scope.isAdvancedClosed = true; - $scope.instanceExists = false; - $scope.errorKeys = []; - - $scope.clusterConfigurable = false; - $scope.clusterConfigurableErrorMsg = ""; - $scope.clusters = []; - $scope.remoteClusters = []; - $scope.noLocalClusterAvailible = true; - $scope.noRemoteClusterAvailible = true; - $scope.cluster = null; - $scope.data = {}; - $scope.data.remoteCluster = null; - $scope.numberOfClusterConfigs = 0; - $scope.numberOfSettingConfigs = 0; - - function loadClusters() { - Cluster.getAllClusters().then(function (clusters) { - if(clusters.length >0){ - clusters.forEach(function(cluster) { - $scope.clusters.push({ - "name" : cluster.Clusters.cluster_name, - "id" : cluster.Clusters.cluster_id - }) - }); - $scope.noLocalClusterAvailible = false; - //do not set to default Local Cluster configuration when cloning instance - if($scope.clusterConfigurable && !$scope.isClone){ - $scope.instance.clusterType = "LOCAL_AMBARI"; - } - }else{ - $scope.clusters.push($t('common.noClusters')); - } - $scope.cluster = $scope.clusters[0]; - }); - } - - function loadRemoteClusters() { - RemoteCluster.listAll().then(function (clusters) { - if(clusters.length >0){ - clusters.forEach(function(cluster) { - $scope.remoteClusters.push({ - "name" : cluster.ClusterInfo.name, - "id" : cluster.ClusterInfo.cluster_id - }) - }); - $scope.noRemoteClusterAvailible = false; - }else{ - $scope.remoteClusters.push($t('common.noClusters')); - } - $scope.data.remoteCluster = $scope.remoteClusters[0]; - }); - } - - - $scope.versions = []; - $scope.version = null; - - View.getVersions($routeParams.viewId).then(function(versions) { - $scope.versions = versions; - $scope.version = $scope.versions[$scope.versions.length-1]; - }); - - - $scope.nameValidationPattern = /^\s*\w*\s*$/; - - $scope.save = function() { - if (!$scope.form.instanceCreateForm.isSaving) { + $scope.save = function () { + var instanceName = $scope.form.instanceCreateForm.instanceName.$viewValue; $scope.form.instanceCreateForm.submitted = true; - if($scope.form.instanceCreateForm.$valid){ - $scope.form.instanceCreateForm.isSaving = true; - - switch($scope.instance.clusterType) { - case 'LOCAL_AMBARI': - console.log($scope.cluster); - $scope.instance.clusterId = $scope.cluster.id; - break; - case 'REMOTE_AMBARI': - console.log($scope.data.remoteCluster); - $scope.instance.clusterId = $scope.data.remoteCluster.id; - - break; - default: - $scope.instance.clusterId = null; - } - console.log($scope.instance.clusterId); - View.createInstance($scope.instance) - .then(function(data) { - Alert.success($t('views.alerts.instanceCreated', {instanceName: $scope.instance.instance_name})); - $scope.form.instanceCreateForm.$setPristine(); - if( targetUrl ){ - $location.path(targetUrl); - } else { - $location.path('/views/' + $scope.instance.view_name + '/versions/' + $scope.instance.version + '/instances/' + $scope.instance.instance_name + '/edit'); - } - $scope.form.instanceCreateForm.isSaving = false; - $scope.$root.$emit('instancesUpdate'); + if ($scope.form.instanceCreateForm.$valid) { + View.createInstance({ + instance_name: instanceName, + label: $scope.form.instanceCreateForm.displayName.$viewValue, + visible: $scope.form.instanceCreateForm.visible.$viewValue, + icon_path: '', + icon64_path: '', + description: $scope.form.instanceCreateForm.description.$viewValue, + view_name: $scope.form.instanceCreateForm.view.$viewValue.value, + version: $scope.form.instanceCreateForm.version.$viewValue.value, + properties: $scope.formData.settings, + clusterId: $scope.formData.clusterName ? $scope.formData.clusterName.id : null, + clusterType: $scope.clusterType + }) + .then(function () { + $modalInstance.dismiss('created'); + Alert.success($t('views.alerts.instanceCreated', {instanceName: instanceName})); + $location.path('/views/' + $scope.form.instanceCreateForm.view.$viewValue.value + + '/versions/' + $scope.form.instanceCreateForm.version.$viewValue.value + + '/instances/' + instanceName + '/edit'); }) .catch(function (data) { var errorMessage = data.message; - var showGeneralError = true; - if (data.status >= 400 && $scope.instance.clusterType == 'NONE') { + if (data.status >= 400) { try { var errorObject = JSON.parse(errorMessage); errorMessage = errorObject.detail; angular.forEach(errorObject.propertyResults, function (item, key) { $scope.form.instanceCreateForm[key].validationError = !item.valid; if (!item.valid) { - showGeneralError = false; $scope.form.instanceCreateForm[key].validationMessage = item.detail; - $scope.errorKeys.push(key); + $scope.fieldsWithErrors.push(key); } }); - if (showGeneralError) { - $scope.form.instanceCreateForm.generalValidationError = errorMessage; - } } catch (e) { - console.error($t('views.alerts.unableToParseError', {message: data.message})); + console.warn(data.message, e); } } Alert.error($t('views.alerts.cannotCreateInstance'), errorMessage); - $scope.form.instanceCreateForm.isSaving = false; }); - } } }; - $scope.cancel = function() { - $scope.form.instanceCreateForm.$setPristine(); - $location.path('/views'); + $scope.cancel = function () { + unsavedChangesCheck(); }; - $scope.$on('$locationChangeStart', function(event, __targetUrl) { - if( $scope.form.instanceCreateForm.$dirty ){ - UnsavedDialog().then(function(action) { - targetUrl = __targetUrl.split('#').pop(); - switch(action){ + $scope.checkIfInstanceExist = function() { + $scope.isInstanceExists = Boolean(instances[$scope.formData.instanceName]); + }; + + function resetErrors() { + $scope.fieldsWithErrors.forEach(function(field) { + $scope.form.instanceCreateForm[field].validationError = false; + $scope.form.instanceCreateForm[field].validationMessage = ''; + }); + $scope.fieldsWithErrors = []; + } + + function initViewAndVersionSelect () { + $scope.viewOptions = []; + angular.forEach($scope.views, function(view) { + $scope.viewOptions.push({ + label: view.view_name, + value: view.view_name + }); + viewToVersionMap[view.view_name] = view.versionsList.map(function(version) { + angular.forEach(version.instances, function(instance) { + instances[instance.ViewInstanceInfo.instance_name] = true; + }); + return { + label: version.ViewVersionInfo.version, + value: version.ViewVersionInfo.version + } + }); + }); + $scope.formData.view = $scope.viewOptions[0]; + $scope.updateVersionOptions(); + } + + function loadClusters() { + return Cluster.getAllClusters().then(function (clusters) { + clusters.forEach(function (cluster) { + $scope.localClusters.push({ + label: cluster.Clusters.cluster_name, + value: cluster.Clusters.cluster_name, + id: cluster.Clusters.cluster_id + }); + }); + }); + } + + function loadRemoteClusters() { + return RemoteCluster.listAll().then(function (clusters) { + clusters.forEach(function (cluster) { + $scope.remoteClusters.push({ + label: cluster.ClusterInfo.name, + value: cluster.ClusterInfo.name, + id: cluster.ClusterInfo.cluster_id + }); + }); + }); + } + + function loadFormData () { + $scope.isLoading = true; + initViewAndVersionSelect(); + $q.all(loadClusters(), loadRemoteClusters()).then(function() { + $scope.isLoading = false; + $scope.switchClusterType('LOCAL_AMBARI'); + copyCloneInstanceInfo(); + }); + } + + function copyCloneInstanceInfo() { + if ($scope.instanceClone) { + $scope.formData.view = $scope.viewOptions.filter(function(option) { + return option.value === $scope.instanceClone.view_name; + })[0]; + $scope.updateVersionOptions(); + $scope.formData.version = $scope.versionOptions.filter(function(option) { + return option.value === $scope.instanceClone.version; + })[0]; + $scope.formData.instanceName = $scope.instanceClone.instance_name + $t('common.copy'); + $scope.formData.displayName = $scope.instanceClone.label + $t('common.copy'); + $scope.formData.description = $scope.instanceClone.description; + $scope.formData.visible = $scope.instanceClone.visible; + $scope.switchClusterType($scope.instanceClone.cluster_type); + $scope.updateSettingsList(); + $scope.formData.settings.forEach(function (setting) { + if ($scope.instanceClone.properties[setting.name]) { + setting.value = $scope.instanceClone.properties[setting.name]; + } + }); + } + } + + function unsavedChangesCheck() { + if ($scope.form.instanceCreateForm.$dirty) { + UnsavedDialog().then(function (action) { + switch (action) { case 'save': $scope.save(); break; case 'discard': - $scope.form.instanceCreateForm.$setPristine(); - $location.path(targetUrl); + $modalInstance.close('discard'); break; case 'cancel': - targetUrl = ''; break; } }); - event.preventDefault(); + } else { + $modalInstance.close('discard'); } - }); - - - - - + } + loadFormData(); }]); http://git-wip-us.apache.org/repos/asf/ambari/blob/e83bf1bd/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/ambariViews/ViewsListCtrl.js ---------------------------------------------------------------------- diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/ambariViews/ViewsListCtrl.js b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/ambariViews/ViewsListCtrl.js index 4e7bae3..8b37dca 100644 --- a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/ambariViews/ViewsListCtrl.js +++ b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/ambariViews/ViewsListCtrl.js @@ -18,272 +18,193 @@ 'use strict'; angular.module('ambariAdminConsole') -.controller('ViewsListCtrl',['$scope', 'View','$modal', 'Alert', 'ConfirmationModal', '$location', '$translate', function($scope, View, $modal, Alert, ConfirmationModal, $location, $translate) { - var deferredList = [], - $t = $translate.instant; - $scope.isLoadingViews = false; - $scope.isLoadingUrls = false; - $scope.constants = { - unable: $t('views.alerts.unableToCreate'), - views: $t('common.views').toLowerCase() - }; - $scope.$on('$locationChangeStart', function() { - deferredList.forEach(function(def) { - def.reject(); - }) - }); - - $scope.createUrlDisabled = false; +.controller('ViewsListCtrl',['$scope', 'View','$modal', 'Alert', 'ConfirmationModal', '$translate', 'Settings', function($scope, View, $modal, Alert, ConfirmationModal, $translate, Settings) { + var $t = $translate.instant; + var VIEWS_VERSION_STATUS_TIMEOUT = 5000; + $scope.isLoading = false; + $scope.minInstanceForPagination = Settings.minRowsToShowPagination; - function checkViewVersionStatus(view, versionObj, versionNumber){ + function checkViewVersionStatus(view, versionObj, versionNumber) { var deferred = View.checkViewVersionStatus(view.view_name, versionNumber); - deferredList.push(deferred); - deferred.promise.then(function(status) { - deferredList.splice(deferredList.indexOf(deferred), 1); - if (status !== 'DEPLOYED' && status !== 'ERROR') { - checkViewVersionStatus(view, versionObj, versionNumber); + deferred.promise.then(function (status) { + if (versionNeedStatusUpdate(status)) { + setTimeout(function() { + checkViewVersionStatus(view, versionObj, versionNumber); + }, VIEWS_VERSION_STATUS_TIMEOUT); } else { - $scope.$evalAsync(function() { - versionObj.status = status; - angular.forEach(view.versions, function(version) { - if(version.status === 'DEPLOYED'){ - view.canCreateInstance = true; - } - }) - }); + versionObj.status = status; + angular.forEach(view.versions, function (version) { + if (version.status === 'DEPLOYED') { + view.canCreateInstance = true; + } + }) } }); } - function loadViews(){ - $scope.isLoadingViews = true; - View.all().then(function(views) { - $scope.isLoadingViews = false; + function versionNeedStatusUpdate(status) { + return status !== 'DEPLOYED' && status !== 'ERROR'; + } + + function loadViews() { + $scope.isLoading = true; + View.all().then(function (views) { + $scope.isLoading = false; $scope.views = views; - $scope.getFilteredViews(); - angular.forEach(views, function(view) { - angular.forEach(view.versions, function(versionObj, versionNumber) { - if (versionObj.status !== 'DEPLOYED' || versionObj.status !== 'ERROR'){ + $scope.instances = []; + angular.forEach(views, function (view) { + angular.forEach(view.versions, function (versionObj, versionNumber) { + if (versionNeedStatusUpdate(versionObj.status)) { checkViewVersionStatus(view, versionObj, versionNumber); } }); - }) - }).catch(function(data) { + angular.forEach(view.instances, function (instance) { + instance.ViewInstanceInfo.short_url_name = instance.ViewInstanceInfo.short_url_name || ''; + instance.ViewInstanceInfo.short_url = instance.ViewInstanceInfo.short_url || ''; + instance.ViewInstanceInfo.versionObj = view.versions[instance.ViewInstanceInfo.version] || {}; + $scope.instances.push(instance.ViewInstanceInfo); + }); + }); + initTypeFilter(); + $scope.filterInstances(); + }).catch(function (data) { Alert.error($t('views.alerts.cannotLoadViews'), data.data.message); }); } - loadViews(); + function initTypeFilter() { + var uniqTypes = $.unique($scope.instances.map(function(instance) { + return instance.view_name; + })); + $scope.typeFilterOptions = [ { label: $t('common.all'), value: '*'} ] + .concat(uniqTypes.map(function(type) { + return { + label: type, + value: type + }; + })); + $scope.instanceTypeFilter = $scope.typeFilterOptions[0]; + } - $scope.createInstance = function(view) { - var modalInstance = $modal.open({ - templateUrl: 'views/ambariViews/modals/create.html', - size: 'lg', - controller: 'CreateViewInstanceCtrl', - resolve: { - viewVersion: function(){ - return view.versionsList[ view.versionsList.length-1]; + function showInstancesOnPage() { + var startIndex = ($scope.currentPage - 1) * $scope.instancesPerPage + 1; + var endIndex = $scope.currentPage * $scope.instancesPerPage; + var showedCount = 0; + var filteredCount = 0; + + angular.forEach($scope.instances, function(instance) { + instance.isShowed = false; + if (instance.isFiltered) { + filteredCount++; + if (filteredCount >= startIndex && filteredCount <= endIndex) { + instance.isShowed = true; + showedCount++; } } }); + $scope.tableInfo.showed = showedCount; + } - modalInstance.result.then(loadViews); - }; - - $scope.viewsFilter = ''; - $scope.filteredViews = []; - $scope.getFilteredViews = function(views) { - var result = []; - var filter = $scope.viewsFilter.toLowerCase(); - if(!filter){ // if no filter return all views - result = $scope.views.map(function(view) { - view.isOpened = false; - return view; - }); - } else { - result = $scope.views.map(function(view) { - view.isOpened = true; - if(view.view_name.toLowerCase().indexOf(filter) >= 0){ - return view; // if filter matched with view name -- return whole view - } else { - var instances = []; - angular.forEach(view.instances, function(instance) { - if(instance.ViewInstanceInfo.label.toLowerCase().indexOf(filter) >= 0){ - instances.push(instance); - } - }); - if( instances.length ){ // If inside view exists instances with matched filter - show only this instances - var v = angular.copy(view); - v.instances = instances; - return v; - } - } - }).filter(function(view) { - return !!view; // Remove 'undefined' - }); - } - $scope.filteredViews = result; - }; - - $scope.gotoCreate = function(viewName, isAllowed) { - if(isAllowed){ - $location.path('/views/'+viewName+'/new'); - } - }; - - $scope.deleteInstance = function(instance) { - ConfirmationModal.show( - $t('common.delete', { - term: $t('views.viewInstance') - }), - $t('common.deleteConfirmation', { - instanceType: $t('views.viewInstance'), - instanceName: instance.ViewInstanceInfo.label - }) - ).then(function() { - View.deleteInstance(instance.ViewInstanceInfo.view_name, instance.ViewInstanceInfo.version, instance.ViewInstanceInfo.instance_name) - .then(function() { - loadViews(); - }) - .catch(function(data) { - Alert.error($t('views.alerts.cannotDeleteInstance'), data.data.message); - }); - }); - }; - - $scope.reloadViews = function () { - loadViews(); - }; - - /** - * Url listing - */ - - $scope.loadedUrls = []; - $scope.urlsPerPage = 10; + $scope.views = []; + $scope.instances = []; + $scope.instancesPerPage = 10; $scope.currentPage = 1; - $scope.totalUrls = 1; - $scope.urlNameFilter = ''; - $scope.urlSuffixfilter = ''; - $scope.maxVisiblePages=20; + $scope.instanceNameFilter = ''; + $scope.instanceUrlFilter = ''; + $scope.maxVisiblePages = 10; + $scope.isNotEmptyFilter = true; + $scope.instanceTypeFilter = ''; $scope.tableInfo = { - total: 0, + filtered: 0, showed: 0 }; - $scope.isNotEmptyFilter = true; - - - $scope.pageChanged = function() { - $scope.listViewUrls(); - }; + loadViews(); - $scope.urlsPerPageChanged = function() { + $scope.filterInstances = function() { + var filteredCount = 0; + angular.forEach($scope.instances, function(instance) { + if ($scope.instanceNameFilter && instance.short_url_name.indexOf($scope.instanceNameFilter) === -1) { + return instance.isFiltered = false; + } + if ($scope.instanceUrlFilter && ('/main/view/'+ instance.view_name + '/' + instance.short_url).indexOf($scope.instanceUrlFilter) === -1) { + return instance.isFiltered = false; + } + if ($scope.instanceTypeFilter.value !== '*' && instance.view_name.indexOf($scope.instanceTypeFilter.value) === -1) { + return instance.isFiltered = false; + } + filteredCount++; + instance.isFiltered = true; + }); + $scope.tableInfo.filtered = filteredCount; $scope.resetPagination(); }; + $scope.pageChanged = function() { + showInstancesOnPage(); + }; $scope.resetPagination = function() { $scope.currentPage = 1; - $scope.listViewUrls(); + showInstancesOnPage(); }; - - $scope.getVersions = function(instances) { - var names = []; - - instances.map(function(view){ - var name = view.view_name; - names.push(name); - }); - - var output = [], - keys = []; - - angular.forEach(names, function(item) { - var key = item; - if(keys.indexOf(key) === -1) { - keys.push(key); - output.push(item); - } - }); - return output; - }; - - - $scope.clearFilters = function () { - $scope.urlNameFilter = ''; - $scope.urlSuffixfilter = ''; + $scope.instanceNameFilter = ''; + $scope.instanceUrlFilter = ''; $scope.instanceTypeFilter = $scope.typeFilterOptions[0]; $scope.resetPagination(); }; - - $scope.$watch( - function (scope) { - return Boolean(scope.urlNameFilter || scope.urlSuffixfilter || (scope.instanceTypeFilter && scope.instanceTypeFilter.value !== '*')); - }, - function (newValue, oldValue, scope) { - scope.isNotEmptyFilter = newValue; - } + function (scope) { + return Boolean(scope.instanceNameFilter || scope.instanceUrlFilter || (scope.instanceTypeFilter && scope.instanceTypeFilter.value !== '*')); + }, + function (newValue, oldValue, scope) { + scope.isNotEmptyFilter = newValue; + } ); - - - - $scope.listViewUrls = function(){ - $scope.isLoadingUrls = true; - View.allUrls({ - currentPage: $scope.currentPage, - urlsPerPage: $scope.urlsPerPage, - searchString: $scope.urlNameFilter, - suffixSearch: $scope.urlSuffixfilter, - instanceType: $scope.instanceTypeFilter?$scope.instanceTypeFilter.value:'*' - }).then(function(urls) { - $scope.isLoadingUrls = false; - $scope.urls = urls; - $scope.ViewNameFilterOptions = urls.items.map(function(url){ - return url.ViewUrlInfo.view_instance_common_name; - }); - - $scope.totalUrls = urls.itemTotal; - $scope.tableInfo.showed = urls.items.length; - $scope.tableInfo.total = urls.itemTotal; - - // get all view instances to enable/disable creation if empty - - }).catch(function(data) { - Alert.error($t('views.alerts.cannotLoadViewUrls'), data.message); - }); + $scope.cloneInstance = function(instanceClone) { + $scope.createInstance(instanceClone); }; - - $scope.initViewUrls = function(){ - $scope.listViewUrls(); - View.getAllVisibleInstance().then(function(instances){ - // if no instances then disable the create button - if(!instances.length){ - $scope.createUrlDisabled = true; - } else { - $scope.typeFilterOptions = [{ label: $t('common.all'), value: '*'}] - .concat($scope.getVersions(instances).map(function(key) { - return { - label: key, - value: key - }; - })); - - $scope.instanceTypeFilter = $scope.typeFilterOptions[0]; - } - - }).catch(function(data) { - // Make the create button enabled, and swallow the error - $scope.createUrlDisabled = false; + $scope.createInstance = function (instanceClone) { + var modalInstance = $modal.open({ + templateUrl: 'views/ambariViews/modals/create.html', + controller: 'CreateViewInstanceCtrl', + resolve: { + views: function() { + return $scope.views; + }, + instanceClone: function() { + return instanceClone; + } + }, + backdrop: 'static' }); + modalInstance.result.then(loadViews); }; -}]); \ No newline at end of file + $scope.deleteInstance = function (instance) { + ConfirmationModal.show( + $t('common.delete', { + term: $t('views.viewInstance') + }), + $t('common.deleteConfirmation', { + instanceType: $t('views.viewInstance'), + instanceName: instance.label + }) + ).then(function () { + View.deleteInstance(instance.view_name, instance.version, instance.instance_name) + .then(function () { + loadViews(); + }) + .catch(function (data) { + Alert.error($t('views.alerts.cannotDeleteInstance'), data.data.message); + }); + }); + }; +}]); http://git-wip-us.apache.org/repos/asf/ambari/blob/e83bf1bd/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/clusters/ClusterInformationCtrl.js ---------------------------------------------------------------------- diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/clusters/ClusterInformationCtrl.js b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/clusters/ClusterInformationCtrl.js new file mode 100644 index 0000000..059f399 --- /dev/null +++ b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/clusters/ClusterInformationCtrl.js @@ -0,0 +1,106 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +'use strict'; + +angular.module('ambariAdminConsole') +.controller('ClusterInformationCtrl', +['$scope', '$http', '$location', 'Cluster', '$routeParams', '$translate', '$rootScope', 'ConfirmationModal', 'Alert', +function($scope, $http, $location, Cluster, $routeParams, $translate, $rootScope, ConfirmationModal, Alert) { + var $t = $translate.instant; + $scope.isDataLoaded = false; + $scope.edit = { + clusterName: null + }; + $scope.isClusterNameEdited = false; + + $scope.$watch(function() { + return $rootScope.cluster; + }, function() { + $scope.cluster = $rootScope.cluster; + if ($scope.cluster) { + $scope.edit.clusterName = $scope.cluster.Clusters.cluster_name; + $scope.getBlueprint(); + } + }, true); + + $scope.getBlueprint = function () { + Cluster.getBlueprint({ + clusterName: $scope.cluster.Clusters.cluster_name + }).then(function (data) { + console.debug($t('exportBlueprint.dataLoaded'), data); + $scope.isDataLoaded = true; + var response = JSON.stringify(data, null, 4), + lt = /</g, + gt = />/g, + ap = /'/g, + ic = /"/g; + $scope.blueprint = response ? response.toString().replace(lt, "<").replace(gt, ">").replace(ap, "'").replace(ic, '"') : ""; + }); + }; + + $scope.downloadBlueprint = function () { + if (window.navigator.msSaveOrOpenBlob) { + var blob = new Blob([decodeURIComponent(encodeURI($scope.blueprint))], { + type: "text/csv;charset=utf-8;" + }); + navigator.msSaveBlob(blob, 'blueprint.json'); + } else { + var a = document.createElement('a'); + a.href = 'data:attachment/csv;charset=utf-8,' + encodeURI($scope.blueprint); + a.target = '_blank'; + a.download = 'blueprint.json'; + document.body.appendChild(a); + a.click(); + } + }; + + $scope.toggleSaveButton = function() { + var value = $scope.edit.clusterName; + $scope.isClusterNameEdited = (value !== null && $scope.cluster.Clusters.cluster_name !== value); + }; + + $scope.confirmClusterNameChange = function() { + ConfirmationModal.show( + $t('common.clusterNameChangeConfirmation.title'), + $t('common.clusterNameChangeConfirmation.message', { + clusterName: $scope.edit.clusterName + }) + ) + .then(function () { + $scope.saveClusterName(); + }).catch(function () { + // user clicked cancel + $scope.edit.clusterName = $scope.cluster.Clusters.cluster_name; + $scope.toggleSaveButton(); + }); + }; + + $scope.saveClusterName = function() { + var oldClusterName = $scope.cluster.Clusters.cluster_name, + newClusterName = $scope.edit.clusterName; + + Cluster.editName(oldClusterName, newClusterName).then(function(data) { + $scope.cluster.Clusters.cluster_name = newClusterName; + $scope.edit.clusterName = newClusterName; + $scope.toggleSaveButton(); + Alert.success($t('common.alerts.clusterRenamed', {clusterName: newClusterName})); + }).catch(function(data) { + Alert.error($t('common.alerts.cannotRenameCluster', {clusterName: newClusterName}), data.data.message); + }); + }; +}]); http://git-wip-us.apache.org/repos/asf/ambari/blob/e83bf1bd/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/clusters/ClustersManageAccessCtrl.js ---------------------------------------------------------------------- diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/clusters/ClustersManageAccessCtrl.js b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/clusters/ClustersManageAccessCtrl.js deleted file mode 100644 index 3a9ad67..0000000 --- a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/clusters/ClustersManageAccessCtrl.js +++ /dev/null @@ -1,97 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -'use strict'; - -angular.module('ambariAdminConsole') -.controller('ClustersManageAccessCtrl', ['$scope', '$location', 'Cluster', '$routeParams', 'Alert', 'PermissionLoader', 'PermissionSaver', '$translate', 'RoleDetailsModal', '$timeout', function($scope, $location, Cluster, $routeParams, Alert, PermissionLoader, PermissionSaver, $translate, RoleDetailsModal, $timeout) { - var $t = $translate.instant; - $scope.getConstant = function (key) { - return $t(key).toLowerCase(); - }; - $scope.identity = angular.identity; - function reloadClusterData(){ - PermissionLoader.getClusterPermissions({ - clusterId: $routeParams.id - }).then(function(permissions) { - // Refresh data for rendering - $scope.permissionsEdit = permissions; - $scope.permissions = angular.copy(permissions); - //"$scope.isDataLoaded" should be set to true on initial load after "$scope.permissionsEdit" watcher - $timeout(function() { - $scope.isDataLoaded = true; - }); - var orderedRoles = Cluster.orderedRoles; - var pms = []; - for (var key=0;key<orderedRoles.length;key++) { - pms.push($scope.permissions[orderedRoles[key]]); - } - $scope.permissions = pms; - }) - .catch(function(data) { - Alert.error($t('clusters.alerts.cannotLoadClusterData'), data.data.message); - }); - } - - $scope.isDataLoaded = false; - reloadClusterData(); - $scope.isEditMode = false; - $scope.permissions = {}; - $scope.clusterName = $routeParams.id; - - - $scope.toggleEditMode = function() { - $scope.isEditMode = !$scope.isEditMode; - }; - - $scope.cancel = function() { - $scope.isEditMode = false; - $scope.permissionsEdit = angular.copy($scope.permissions); // Reset textedit areaes - }; - - $scope.save = function() { - PermissionSaver.saveClusterPermissions( - $scope.permissionsEdit, - { - clusterId: $routeParams.id - } - ).then(reloadClusterData) - .catch(function(data) { - Alert.error($t('common.alerts.cannotSavePermissions'), data.data.message); - reloadClusterData(); - }); - $scope.isEditMode = false; - }; - - $scope.$watch(function() { - return $scope.permissionsEdit; - }, function(newValue) { - if (newValue && $scope.isDataLoaded) { - $scope.save(); - } - }, true); - - $scope.switchToList = function() { - $location.url('/clusters/' + $routeParams.id + '/userAccessList'); - }; - - $scope.showHelpPage = function() { - Cluster.getRolesWithAuthorizations().then(function(roles) { - RoleDetailsModal.show(roles); - }); - }; -}]); http://git-wip-us.apache.org/repos/asf/ambari/blob/e83bf1bd/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/clusters/ExportBlueprintCtrl.js ---------------------------------------------------------------------- diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/clusters/ExportBlueprintCtrl.js b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/clusters/ExportBlueprintCtrl.js deleted file mode 100644 index 6b74b40..0000000 --- a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/clusters/ExportBlueprintCtrl.js +++ /dev/null @@ -1,58 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -'use strict'; - -angular.module('ambariAdminConsole') -.controller('ExportBlueprintCtrl', ['$scope', '$http', '$location', 'Cluster', '$routeParams', '$translate', function($scope, $http, $location, Cluster, $routeParams, $translate) { - var $t = $translate.instant; - $scope.identity = angular.identity; - - $scope.isDataLoaded = false; - $scope.clusterName = $routeParams.id; - - $scope.getBlueprint = function() { - Cluster.getBlueprint({ - clusterName: $scope.clusterName - }).then(function(data) { - console.debug($t('exportBlueprint.dataLoaded'), data); - $scope.isDataLoaded = true; - var response = JSON.stringify(data, null, 4), - lt = /</g, - gt = />/g, - ap = /'/g, - ic = /"/g; - $scope.blueprint = response ? response.toString().replace(lt, "<").replace(gt, ">").replace(ap, "'").replace(ic, '"') : ""; - }); - }; - - $scope.downloadBlueprint = function() { - if (window.navigator.msSaveOrOpenBlob) { - var blob = new Blob([decodeURIComponent(encodeURI($scope.blueprint))], { - type: "text/csv;charset=utf-8;" - }); - navigator.msSaveBlob(blob, 'blueprint.json'); - } else { - var a = document.createElement('a'); - a.href = 'data:attachment/csv;charset=utf-8,' + encodeURI($scope.blueprint); - a.target = '_blank'; - a.download = 'blueprint.json'; - document.body.appendChild(a); - a.click(); - } - }; -}]); http://git-wip-us.apache.org/repos/asf/ambari/blob/e83bf1bd/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/clusters/UserAccessListCtrl.js ---------------------------------------------------------------------- diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/clusters/UserAccessListCtrl.js b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/clusters/UserAccessListCtrl.js deleted file mode 100644 index 9e83b91..0000000 --- a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/clusters/UserAccessListCtrl.js +++ /dev/null @@ -1,351 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -'use strict'; - -angular.module('ambariAdminConsole') -.controller('UserAccessListCtrl',['$scope', '$location', 'Cluster', '$modal', '$rootScope', '$routeParams', 'PermissionSaver', 'Alert', '$translate', 'RoleDetailsModal', -function($scope, $location, Cluster, $modal, $rootScope, $routeParams, PermissionSaver, Alert, $translate, RoleDetailsModal) { - var $t = $translate.instant; - $scope.constants = { - users: $t('common.users').toLowerCase(), - groups: $t('common.groups').toLowerCase() - }; - $scope.users = []; - $scope.usersPerPage = 10; - $scope.currentPage = 1; - $scope.totalUsers = 1; - $scope.currentNameFilter = ''; - $scope.maxVisiblePages = 20; - $scope.roles = []; - $scope.clusterId = $routeParams.id; - $scope.tableInfo = { - total: 0, - showed: 0, - filtered: 0 - }; - $scope.isNotEmptyFilter = true; - $scope.NONE_ROLE = { - "permission_label" : $t('common.none'), - "permission_name" : "CLUSTER.NONE" - }; - $scope.ALL_ROLE = { - "permission_label" : $t('common.all'), - "permission_name" : "" - }; - $scope.AMBARI_ADMIN_ROLE = { - "permission_label" : $t('users.roles.ambariAdmin'), - "permission_name" : "AMBARI.ADMINISTRATOR" - }; - - $scope.pageChanged = function() { - $scope.loadUsers(); - }; - $scope.usersPerPageChanges = function() { - $scope.resetPagination(); - }; - - $scope.loadUsers = function(){ - Cluster.getPrivilegesWithFilters({ - nameFilter: $scope.currentNameFilter, - typeFilter: $scope.currentTypeFilter, - roleFilter: $scope.currentRoleFilter, - currentPage: $scope.currentPage, - usersPerPage: $scope.usersPerPage - }).then(function(data) { - $scope.totalUsers = data.itemTotal; - $scope.users = data.items.map(function (user) { - var privilege = $scope.pickEffectivePrivilege(user.privileges); - // Redefine principal_name and principal type in case of None - privilege.principal_name = user.Users? user.Users.user_name : user.Groups.group_name; - if (privilege.permission_label === $t('users.roles.none')) { - privilege.principal_type = user.Users ? 'USER' : 'GROUP'; - } - var name = encodeURIComponent(privilege.principal_name); - privilege.encoded_name = name; - privilege.original_perm = privilege.permission_name; - privilege.url = user.Users? ('users/' + name) : ('groups/' + name + '/edit'); - privilege.editable = Cluster.ineditableRoles.indexOf(privilege.permission_name) == -1; - return privilege; - }); - $scope.tableInfo.total = data.itemTotal; - $scope.tableInfo.showed = data.items.length; - }); - }; - - $scope.pickEffectivePrivilege = function(privileges) { - if (privileges && privileges.length > 1) { - return privileges.reduce(function(prev, cur) { - var prevIndex = $scope.getRoleRank(prev.PrivilegeInfo.permission_name); - var curIndex = $scope.getRoleRank(cur.PrivilegeInfo.permission_name) - return (prevIndex < curIndex) ? prev : cur; - }).PrivilegeInfo; - } else if (privileges && privileges.length == 1 && privileges[0].PrivilegeInfo.permission_name !== "VIEW.USER") { - return privileges[0].PrivilegeInfo; - } else { - return angular.copy($scope.NONE_ROLE); - } - }; - - $scope.loadRoles = function() { - Cluster.getPermissions().then(function(data) { - $scope.roles = data.map(function(item) { - return item.PermissionInfo; - }); - // [All, Administrator, ...roles..., None] - $scope.roles.unshift(angular.copy($scope.AMBARI_ADMIN_ROLE)); - $scope.roles.unshift(angular.copy($scope.ALL_ROLE)); - $scope.roles.push(angular.copy($scope.NONE_ROLE)); - - // create filter select list - $scope.roleFilterOptions = angular.copy($scope.roles); - $scope.roleFilterOptions.pop(); // filter does not support None - $scope.roleFilterOptions = $scope.roleFilterOptions.map(function(o) { - return {label: o.permission_label, value: o.permission_name}; - }); - $scope.currentRoleFilter = $scope.roleFilterOptions[0]; - - // create value select list - $scope.roleValueOptions = angular.copy($scope.roles) - $scope.roleValueOptions.shift(); // value change does not support all/administrator - $scope.roleValueOptions.shift(); - }); - }; - - $scope.getRoleRank = function(permission_name) { - var orderedRoles = Cluster.orderedRoles.concat(['VIEW.USER','CLUSTER.NONE']); - var index = orderedRoles.indexOf(permission_name); - return index; - }; - - $scope.save = function(user) { - var fromNone = (user.original_perm === $scope.NONE_ROLE.permission_name); - if (fromNone) { - $scope.addPrivilege(user); - return; - } - - if ($scope.isUserActive) { - Cluster.getPrivilegesForResource({ - nameFilter : user.user_name, - typeFilter : $scope.currentTypeFilter - }).then(function(data) { - var arrayOfPrivileges = data.items[0].privileges; - var privilegesOfTypeUser = []; - var privilegesOfTypeGroup = []; - for (var i = 0; i < arrayOfPrivileges.length; i++) { - if(arrayOfPrivileges[i].PrivilegeInfo.permission_name != "VIEW.USER") { - if(arrayOfPrivileges[i].PrivilegeInfo.principal_type === "GROUP"){ - privilegesOfTypeGroup.push(arrayOfPrivileges[i]); - } else { - privilegesOfTypeUser.push(arrayOfPrivileges[i].PrivilegeInfo); - } - } - } - - var effectivePrivilege = $scope.pickEffectivePrivilege(arrayOfPrivileges); - var effectivePrivilegeFromGroups = $scope.pickEffectivePrivilege(privilegesOfTypeGroup); - user.principal_type = 'USER'; - user.original_perm = effectivePrivilege.permission_name; - user.editable = (Cluster.ineditableRoles.indexOf(effectivePrivilege.permission_name) === -1); - - var userIndex = $scope.getRoleRank(user.permission_name); - var groupIndex = $scope.getRoleRank(effectivePrivilegeFromGroups.permission_name); - - // Process when it's NONE privilege or higher than current effective group privilege - if (userIndex <= groupIndex || user.permission_name == $scope.NONE_ROLE.permission_name) { - var privilege_ids = privilegesOfTypeUser.filter(function(privilegeOfTypeUser) { - return privilegeOfTypeUser.principal_type !== 'ROLE'; - }).map(function (privilegeOfTypeUser) { - return privilegeOfTypeUser.privilege_id; - }); - - // Purge existing user level privileges if there is any - if(privilege_ids.length !== 0) { - Cluster.deleteMultiplePrivileges( - $routeParams.id, - privilege_ids - ) - .then(function() { - $scope.addPrivilege(user); - }); - } else { - $scope.addPrivilege(user); - } - } else { - Alert.error($t('common.alerts.cannotSavePermissions'), - $t('users.alerts.usersEffectivePrivilege', {user_name : user.user_name}) - ); - $scope.loadUsers(); - } - }); - } else { - Cluster.getPrivilegesForResource({ - nameFilter : user.group_name, - typeFilter : $scope.currentTypeFilter - }).then(function(data) { - var arrayOfPrivileges = data.items[0].privileges; - var privilegesOfTypeGroup = []; - var privilege = $scope.pickEffectivePrivilege(arrayOfPrivileges); - user.principal_type = 'GROUP'; - user.original_perm = privilege.permission_name; - user.editable = (Cluster.ineditableRoles.indexOf(privilege.permission_name) === -1); - - arrayOfPrivileges.forEach(function(privilegeOfTypeGroup) { - if(privilegeOfTypeGroup.PrivilegeInfo.permission_name != "VIEW.USER") { - if (privilegeOfTypeGroup.PrivilegeInfo.principal_type === "GROUP") { - privilegesOfTypeGroup.push(privilegeOfTypeGroup.PrivilegeInfo); - } - } - }); - - var privilege_ids = []; - privilegesOfTypeGroup.forEach(function(privilegeOfTypeGroup) { - privilege_ids.push(privilegeOfTypeGroup.privilege_id); - }); - - //delete all privileges of type GROUP, if they exist - //then add the privilege for the group, after which the group displays the effective privilege - if(privilege_ids.length !== 0) { - Cluster.deleteMultiplePrivileges( - $routeParams.id, - privilege_ids - ) - .then(function() { - $scope.addPrivilege(user); - }); - } else { - $scope.addPrivilege(user); - } - }); - } - }; - - $scope.cancel = function(user) { - user.permission_name = user.original_perm; - }; - - $scope.addPrivilege = function(user) { - var changeToNone = user.permission_name == $scope.NONE_ROLE.permission_name; - if (changeToNone) { - if ($scope.isUserActive) { - Alert.success($t('users.alerts.roleChangedToNone', { - user_name : user.user_name - })); - } else { - $scope.showSuccess(user); - } - $scope.loadUsers(); - return; - } - Cluster.createPrivileges( - { - clusterId: $routeParams.id - }, - [{PrivilegeInfo: { - permission_name: user.permission_name, - principal_name: user.principal_name, - principal_type: user.principal_type - }}] - ).then(function() { - $scope.showSuccess(user); - $scope.loadUsers(); - }) - .catch(function(data) { - Alert.error($t('common.alerts.cannotSavePermissions'), data.data.message); - $scope.loadUsers(); - }); - }; - - $scope.showSuccess = function(user) { - Alert.success($t('users.alerts.roleChanged', { - name: user.principal_name, - role: $scope.roles.filter(function(r){ - return r.permission_name == user.permission_name} - )[0].permission_label - })); - }; - - $scope.resetPagination = function() { - $scope.currentPage = 1; - $scope.loadUsers(); - }; - $scope.currentRoleFilter = { label:$t('common.all'), value: '' }; - - - $scope.typeFilterOptions = [ - {label: $t('common.user'), value: 'USER'}, - {label: $t('common.group'), value: 'GROUP'} - ]; - - $scope.isUserActive = true; - - $scope.currentTypeFilter = $scope.typeFilterOptions[0]; - - $scope.switchToUser = function() { - if (!$scope.isUserActive) { - $scope.currentTypeFilter = $scope.typeFilterOptions[0]; - $scope.isUserActive = true; - $scope.resetPagination(); - } - }; - - $scope.switchToGroup = function() { - if ($scope.isUserActive) { - $scope.currentTypeFilter = $scope.typeFilterOptions[1]; - $scope.isUserActive = false; - $scope.resetPagination(); - } - }; - - $scope.clearFilters = function() { - $scope.currentNameFilter = ''; - $scope.currentRoleFilter = $scope.roleFilterOptions[0]; - $scope.resetPagination(); - }; - - $scope.loadRoles(); - $scope.loadUsers(); - - $scope.$watch( - function (scope) { - return Boolean(scope.currentNameFilter || (scope.currentRoleFilter && scope.currentRoleFilter.value)); - }, - function (newValue, oldValue, scope) { - scope.isNotEmptyFilter = newValue; - } - ); - - $rootScope.$watch(function(scope) { - return scope.LDAPSynced; - }, function(LDAPSynced) { - if(LDAPSynced === true){ - $rootScope.LDAPSynced = false; - $scope.loadUsers(); - } - }); - - $scope.switchToBlock = function() { - $location.url('/clusters/' + $routeParams.id + '/manageAccess'); - }; - - $scope.showHelpPage = function() { - Cluster.getRolesWithAuthorizations().then(function(roles) { - RoleDetailsModal.show(roles); - }); - }; -}]); http://git-wip-us.apache.org/repos/asf/ambari/blob/e83bf1bd/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/groups/GroupsCreateCtrl.js ---------------------------------------------------------------------- diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/groups/GroupsCreateCtrl.js b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/groups/GroupsCreateCtrl.js deleted file mode 100644 index 67743a0..0000000 --- a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/groups/GroupsCreateCtrl.js +++ /dev/null @@ -1,65 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -'use strict'; - -angular.module('ambariAdminConsole') -.controller('GroupsCreateCtrl',['$scope', 'Group', '$location', 'Alert', 'UnsavedDialog', '$translate', function($scope, Group, $location, Alert, UnsavedDialog, $translate) { - var $t = $translate.instant; - $scope.group = new Group(); - var targetUrl = '/groups'; - - $scope.createGroup = function() { - $scope.form.submitted = true; - if ($scope.form.$valid){ - $scope.group.save().then(function() { - Alert.success($t('groups.alerts.groupCreated', {groupName: $scope.group.group_name})); - $scope.form.$setPristine(); - $location.path(targetUrl); - }) - .catch(function(data) { - Alert.error($t('groups.alerts.groupCreationError'), data.data.message); - }); - } - }; - - $scope.cancel = function() { - $scope.form.$setPristine(); - $location.path('/groups'); - }; - - $scope.$on('$locationChangeStart', function(event, __targetUrl) { - if( $scope.form.$dirty ){ - UnsavedDialog().then(function(action) { - targetUrl = __targetUrl.split('#').pop(); - switch(action){ - case 'save': - $scope.createGroup(); - break; - case 'discard': - $scope.form.$setPristine(); - $location.path(targetUrl); - break; - case 'cancel': - targetUrl = '/groups'; - break; - } - }); - event.preventDefault(); - } - }); -}]); \ No newline at end of file
