<commit_before>angular
.module('private.scenarist.coscenarists.directives', [
    "wegas.directives.search.users"
])
.directive('scenaristCoscenaristsIndex', function(ScenariosModel){
  return {
    templateUrl: 'app/private/scenarist/coscenarists/tmpl/coscenarists-index.html',
    controller : function($scope, $stateParams, $sce) {
        var ctrl = this;
        $scope.scenarios = [];
        $scope.scenario = {};

        ctrl.updateScenario = function() {
                // Searching for current scenario
                ScenariosModel.getScenario($stateParams.scenarioId).then(function(response) {
                    if (response.isErroneous()) {
                        response.flash();
                    } else {
                        $scope.scenario = response.data;

                        // Loading permissions
                        ScenariosModel.getPermissions($stateParams.scenarioId).then(function(response) {
                            if (response.isErroneous()) {
                                response.flash();
                            } else {
                                $scope.permissions = response.data;
                            }
                        });
                    }

                });
        };

        ctrl.updateScenario();
    }
};
})
.directive('scenaristCoscenaristsAdd', function(ScenariosModel, UsersModel) {
    return {
        templateUrl: 'app/private/scenarist/coscenarists/tmpl/coscenarists-add.html',
        scope: false,
        require: "^scenaristCoscenaristsIndex",
        link : function(scope, element, attrs, parentCtrl) {

            scope.$watch(function() {
                return parentCtrl.scenario
            } , function(n,o) {
                scope.scenario = n;
            });

            scope.restrictRoles = ["Administrator", "Scenarist"];

            scope.callbackSearchUser = function(selection) {
                scope.selected_user = selection;
                scope.addNewCoscenarist();
            }

            scope.addNewCoscenarist = function() {
                if (scope.selected_user.id) {
                    ScenariosModel.updatePermissions(scope.scenario.id,
                        scope.selected_user.id, true,false,false).then(function (response) {
                            if (response.isErroneous()) {
                                response.flash();
                            } else {
                                parentCtrl.updateScenario();
                            }
                    });
                }
            };
        }
    };
})
.directive('scenaristCoscenaristsList', function(ScenariosModel) {
    return {
        templateUrl: 'app/private/scenarist/coscenarists/tmpl/coscenarists-list.html',
        scope: false,
        require: "^scenaristCoscenaristsIndex",
        link : function(scope, element, attrs, parentCtrl) {
            scope.$watch(function() {
                return parentCtrl.permissions
            }, function(newPermissions, permissions) {
                scope.permissions = newPermissions;
            });

            scope.removeUser = function (scenarioId, userId) {
                ScenariosModel.deletePermissions(scenarioId, userId).then(function(response) {
                    if (response.isErroneous()) {
                        response.flash();
                    } else {
                        var index = scope.permissions.indexOf(this.permission);
                        scope.permissions.splice(index,1);
                    }
                });
            }

        },
    };
})

.directive('scenaristCoscenaristsUserPermissions', function(ScenariosModel) {
    return {
        templateUrl: 'app/private/scenarist/coscenarists/tmpl/coscenarists-user-permissions.html',
        scope: false,
        require: "^scenaristCoscenaristsIndex",<commit_msg>- Improving coscenarist<commit_after>angular
.module('private.scenarist.coscenarists.directives', [
    "wegas.directives.search.users"
])
.directive('scenaristCoscenaristsIndex', function(ScenariosModel){
  return {
    templateUrl: 'app/private/scenarist/coscenarists/tmpl/coscenarists-index.html',
    controller : function($scope, $stateParams, $sce) {
        var ctrl = this;
        $scope.scenarios = [];
        $scope.scenario = {};

        ctrl.updateScenario = function() {
                // Searching for current scenario
                ScenariosModel.getScenario($stateParams.scenarioId).then(function(response) {
                    if (response.isErroneous()) {
                        response.flash();
                    } else {
                        $scope.scenario = response.data;

                        // Loading permissions
                        ScenariosModel.getPermissions($stateParams.scenarioId).then(function(response) {
                            if (response.isErroneous()) {
                                response.flash();
                            } else {
                                $scope.permissions = response.data;
                            }
                        });
                    }

                });
        };

        ctrl.updateScenario();
    }
};
})
.directive('scenaristCoscenaristsAdd', function(ScenariosModel, UsersModel) {
    return {
        templateUrl: 'app/private/scenarist/coscenarists/tmpl/coscenarists-add.html',
        scope: {
            scenario: '='
        },
        require: "^scenaristCoscenaristsIndex",
        link : function(scope, element, attrs, parentCtrl) {

            scope.restrictRoles = ["Administrator", "Scenarist"];

            scope.callbackSearchUser = function(selection) {
                scope.selected_user = selection;
                scope.addNewCoscenarist();
            }

            scope.addNewCoscenarist = function() {
                if (scope.selected_user.id) {
                    ScenariosModel.updatePermissions(scope.$parent.scenario.id,
                        scope.selected_user.id, true,false,false).then(function (response) {
                            if (response.isErroneous()) {
                                response.flash();
                            } else {
                                parentCtrl.updateScenario();
                            }
                    });
                }
            };
        }
    };
})
.directive('scenaristCoscenaristsList', function(ScenariosModel) {
    return {
        templateUrl: 'app/private/scenarist/coscenarists/tmpl/coscenarists-list.html',
        scope: false,
        require: "^scenaristCoscenaristsIndex",
        link : function(scope, element, attrs, parentCtrl) {
            scope.$watch(function() {
                return parentCtrl.permissions
            }, function(newPermissions, permissions) {
                scope.permissions = newPermissions;
            });

            scope.removeUser = function (scenarioId, userId) {
                ScenariosModel.deletePermissions(scenarioId, userId).then(function(response) {
                    if (response.isErroneous()) {
                        response.flash();
                    } else {
                        var index = _.findIndex(scope.permissions, function (p) {
                            return p.user.id == userId;
                        });
                        if (index > -1) {
                            scope.permissions.splice(index,1);
                        }
                    }
                });
            }

        },
    };
})

.directive('scenaristCoscenaristsUserPermissions', function(ScenariosModel) {
    return {
        templateUrl: 'app/private/scenarist/coscenarists/tmpl/coscenarists-user-permissions.html',
        scope: false,
        require: "^scenaristCoscenaristsIndex",
{'fraction_non_alphanumeric': 0.10529699151452816, 'fraction_numerical': 0.0003857032656209823, 'mean_word_length': 1.4726636999364273, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1115568', 'n_tokens_mistral': 2070, 'n_tokens_neox': 1994, 'n_words': 255}