<commit_before>/**
 * @name ProjectAdminController
 * @desc Controller for the project-admin view
 */

(function() {
    'use strict';

    angular.module('cometApp')
           .controller('ProjectAdminController', ProjectAdminController);

        ProjectAdminController.$inject = ['$log',
                                          '$rootScope',
                                          '$state',
                                          'ngToast',
                                          'constraints',
                                          'dialogService',
                                          'projectService',
                                          'user',
                                          'project',
                                          'tab'];

        function ProjectAdminController ( $log,
                                          $rootScope,
                                          $state,
                                          ngToast,
                                          constraints,
                                          dialogService,
                                          projectService,
                                          user,
                                          project,
                                          tab) {

          var vm = this;
          vm.project = project;
          vm.validationErrors = null;
          vm.invites = [];
          vm.invitesLimitReached = false;
          vm.membersPerProjectPerStep = constraints.membersPerProjectPerStep;

          // tabs
          vm.tabsState = {};
          vm.onTabSelected = onTabSelected;

          // update info
          vm.update = update;

          // invite / delete members
          vm.deleteMember = deleteMember;
          vm.isCurrentUser = isCurrentUser;
          vm.addInvite = addInvite;
          vm.removeInvite = removeInvite;
          vm.inviteMembers = inviteMembers;

          //close project
          vm.imSure = false;
          vm.closeProject = closeProject;

          activate();

          /**
           * @name activate
           * @desc controller activation logic
          */
          function activate () {
            if (!angular.isUndefined(tab)) {
              //vm.defaultTab = tab;
              vm.tabsState['tab' + tab] = true;
            }
          }

          /**
           * @name update
           * @desc project update logic
          */
          function update () {
            projectService.update(vm.project).error(function(data) {
              vm.validationErrors = $rootScope.helpers.loadServerErrors(data);
              if (vm.validationErrors === null) {
                ngToast.danger('Ocurrió un error al consultar al servidor.');
              }
            }).then(function() {
                var msg = 'El proyecto "' + vm.project.name +
                          '" ha sido editado exitosamente.';
                var dlg = dialogService.showModalAlert('Administrar proyecto', msg);
                dlg.result.then(function () {
                  $state.go('dashboard.project-list');
                });
            });
          }

          /**
           * @name deleteMember
           * @desc deletes selected members from project
          */
          function deleteMember (member) {
              var msg = '¿Esta seguro que desea eliminar el participante?';
              var dlg = dialogService.showModalConfirm('Administrar proyecto', msg);
              dlg.result.then(function () {    
                projectService
                  .deleteMember(vm.project.id, member).error(function(data) {
                    vm.validationErrors = $rootScope.helpers.loadServerErrors(data);
                    if (vm.validationErrors === null) {
                      ngToast.danger('Ocurrió un error al consultar al servidor.');
                    }
                  })
                  .then(function () {
                    var index = vm.project.members.indexOf(member);
                    vm.project.members.splice(index, 1);
                    ngToast.success('El participante ha sido eliminado.');     
                  });
              });
          }

          /**
           * @name isCurrentUser
           * @desc returns if the member is the current logged in user
          */
          function isCurrentUser(member) {
            return member.email === user.email;
          }

          /**
           * @name addInvite
           * @desc adds an invite to the list of invites
          */<commit_msg>Revert "FIx para bug al eliminar participante de proyecto"<commit_after>/**
 * @name ProjectAdminController
 * @desc Controller for the project-admin view
 */

(function() {
    'use strict';

    angular.module('cometApp')
           .controller('ProjectAdminController', ProjectAdminController);

        ProjectAdminController.$inject = ['$log',
                                          '$rootScope',
                                          '$state',
                                          'ngToast',
                                          'constraints',
                                          'dialogService',
                                          'projectService',
                                          'user',
                                          'project',
                                          'tab'];

        function ProjectAdminController ( $log,
                                          $rootScope,
                                          $state,
                                          ngToast,
                                          constraints,
                                          dialogService,
                                          projectService,
                                          user,
                                          project,
                                          tab) {

          var vm = this;
          vm.project = project;
          vm.validationErrors = null;
          vm.invites = [];
          vm.invitesLimitReached = false;
          vm.membersPerProjectPerStep = constraints.membersPerProjectPerStep;

          // tabs
          vm.tabsState = {};
          vm.onTabSelected = onTabSelected;

          // update info
          vm.update = update;

          // invite / delete members
          vm.deleteMember = deleteMember;
          vm.isCurrentUser = isCurrentUser;
          vm.addInvite = addInvite;
          vm.removeInvite = removeInvite;
          vm.inviteMembers = inviteMembers;

          //close project
          vm.imSure = false;
          vm.closeProject = closeProject;

          activate();

          /**
           * @name activate
           * @desc controller activation logic
          */
          function activate () {
            if (!angular.isUndefined(tab)) {
              //vm.defaultTab = tab;
              vm.tabsState['tab' + tab] = true;
            }
          }

          /**
           * @name update
           * @desc project update logic
          */
          function update () {
            projectService.update(vm.project).error(function(data) {
              vm.validationErrors = $rootScope.helpers.loadServerErrors(data);
              if (vm.validationErrors === null) {
                ngToast.danger('Ocurrió un error al consultar al servidor.');
              }
            }).then(function() {
                var msg = 'El proyecto "' + vm.project.name +
                          '" ha sido editado exitosamente.';
                var dlg = dialogService.showModalAlert('Administrar proyecto', msg);
                dlg.result.then(function () {
                  $state.go('dashboard.project-list');
                });
            });
          }

          /**
           * @name deleteMember
           * @desc deletes selected members from project
          */
          function deleteMember (member) {
            projectService.deleteMember(vm.project.id, member).error(function(data) {
              vm.validationErrors = $rootScope.helpers.loadServerErrors(data);
              if (vm.validationErrors === null) {
                ngToast.danger('Ocurrió un error al consultar al servidor.');
              }
            }).then(function() {
              var msg = '¿Esta seguro que desea eliminar el participante?';
              var dlg = dialogService.showModalConfirm('Administrar proyecto', msg);
              dlg.result.then(function () {
                var index = vm.project.members.indexOf(member);
                vm.project.members.splice(index, 1);
                ngToast.success('El participante ha sido eliminado.');
              });
            });
          }

          /**
           * @name isCurrentUser
           * @desc returns if the member is the current logged in user
          */
          function isCurrentUser(member) {
            return member.email === user.email;
          }

          /**
           * @name addInvite
           * @desc adds an invite to the list of invites
          */
{'fraction_non_alphanumeric': 0.08975631271363987, 'fraction_numerical': 0.00022053148086889404, 'mean_word_length': 1.0423328079261427, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 72, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3621095', 'n_tokens_mistral': 1951, 'n_tokens_neox': 1895, 'n_words': 431}