<commit_before>/*
    Copyright (c) 2016 VMware, Inc. All Rights Reserved.
    Licensed 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.
*/
(function() {
  
  'use strict';
  
  angular
    .module('harbor.user')
    .directive('toggleAdmin', toggleAdmin);
   
  ToggleAdminController.$inject = ['$scope', 'ToggleAdminService', '$filter', 'trFilter'];
  
  function ToggleAdminController($scope, ToggleAdminService, $filter, trFilter) {
    var vm = this;
    
    vm.isAdmin = (vm.hasAdminRole === 1);
    vm.enabled = vm.isAdmin ? 0 : 1;
    vm.toggle = toggle;
    vm.editable = (vm.currentUser.user_id !== Number(vm.userId));
    
    function toggle() {
      ToggleAdminService(vm.userId, vm.enabled)
        .success(toggleAdminSuccess)
        .error(toggleAdminFailed);        
    }    
    
    function toggleStatus() {
      vm.isAdmin = !vm.isAdmin;
      vm.enabled = vm.isAdmin ? 0 : 1;
    }
    
    function toggleAdminSuccess(data, status) {
      console.log('Toggled userId:' + vm.userId + ' to admin:' + vm.isAdmin);
      toggleStatus();
    }

    function toggleAdminFailed(data, status) {
      console.log('Failed to toggle admin:' + data);
      toggleStatus();
      $scope.$emit('modalTitle', $filter('tr')('error'));
      $scope.$emit('modalMessage', $filter('tr')('failed_to_toggle_admin'));
      $scope.$emit('raiseError', true);
    }    
  }
  
  function toggleAdmin() {
    var directive = {
      'restrict': 'E',
      'templateUrl': '/static/resources/js/components/user/toggle-admin.directive.html',
      'scope': {
        'hasAdminRole': '=',
        'userId': '@',
        'currentUser': '='
      },
      'link': link,
      'controller': ToggleAdminController,
      'controllerAs': 'vm',
      'bindToController': true
    };
    return directive;
    
    function link(scope, element, attrs, ctrl) {
      
    }
  }
  
})();
<commit_msg>Updates for changing admin options.<commit_after>/*
    Copyright (c) 2016 VMware, Inc. All Rights Reserved.
    Licensed 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.
*/
(function() {
  
  'use strict';
  
  angular
    .module('harbor.user')
    .directive('toggleAdmin', toggleAdmin);
   
  ToggleAdminController.$inject = ['$scope', 'ToggleAdminService', '$filter', 'trFilter'];
  
  function ToggleAdminController($scope, ToggleAdminService, $filter, trFilter) {
    var vm = this;
    
    vm.isAdmin = (vm.hasAdminRole === 1);
    vm.toggle = toggle;
    vm.editable = (vm.currentUser.user_id !== Number(vm.userId));
    
    function toggle() {
      ToggleAdminService(vm.userId, vm.isAdmin ? 0 : 1)
        .success(toggleAdminSuccess)
        .error(toggleAdminFailed);        
    }    
     
    function toggleAdminSuccess(data, status) {
      console.log('Toggled userId:' + vm.userId + ' to admin:' + vm.isAdmin);
      vm.isAdmin = !vm.isAdmin;
    }

    function toggleAdminFailed(data, status) {
      console.log('Failed to toggle admin:' + data);
      vm.isAdmin = !vm.isAdmin;
      $scope.$emit('modalTitle', $filter('tr')('error'));
      $scope.$emit('modalMessage', $filter('tr')('failed_to_toggle_admin'));
      $scope.$emit('raiseError', true);
    }    
  }
  
  function toggleAdmin() {
    var directive = {
      'restrict': 'E',
      'templateUrl': '/static/resources/js/components/user/toggle-admin.directive.html',
      'scope': {
        'hasAdminRole': '=',
        'userId': '@',
        'currentUser': '='
      },
      'link': link,
      'controller': ToggleAdminController,
      'controllerAs': 'vm',
      'bindToController': true
    };
    return directive;
    
    function link(scope, element, attrs, ctrl) {
      
    }
  }
  
})();

{'fraction_non_alphanumeric': 0.13152312261349172, 'fraction_numerical': 0.005091217649554518, 'mean_word_length': 2.7096774193548385, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4670827', 'n_tokens_mistral': 1394, 'n_tokens_neox': 1385, 'n_words': 366}