<commit_before>﻿(function (ng, app) {
    app.config(['$stateProvider', '$urlRouterProvider', function ($stateProvider, $urlRouterProvider) {
        $stateProvider.state('it-system.edit', {
            url: '/edit/{id:[0-9]+}',
            templateUrl: 'app/components/it-system/edit/it-system-edit.view.html',
            controller: 'system.EditCtrl',
            resolve: {
                itSystem: ['$http', '$stateParams', function ($http, $stateParams) {
                    return $http.get("api/itsystem/" + $stateParams.id)
                        .then(function (result) {
                            return result.data.response;
                        });
                }],
                user: [
                    'userService', function (userService) {
                        return userService.getUser();
                    }
                ],
                hasWriteAccess: ['$http', '$stateParams', 'user', function ($http, $stateParams, user) {
                    return $http.get("api/itsystem/" + $stateParams.id + "?hasWriteAccess=true&organizationId=" + user.currentOrganizationId)
                        .then(function (result) {
                            return result.data.response;
                        });
                }],
                userAccessRights: ['$http', '$stateParams', function ($http, $stateParams) {
                    return $http.get("api/itsystem/" + $stateParams.id +"/accessrights")
                        .then(function (result) {
                            return result.data.response;
                        });
                }]
            }
        });
    }]);

    app.controller('system.EditCtrl',
        [
            '$rootScope', '$scope', 'itSystem', 'user', 'hasWriteAccess', '$state', 'notify', '$http', '_','userAccessRights',
            function ($rootScope, $scope, itSystem, user, hasWriteAccess, $state, notify, $http, _, userAccessRights) {
                
                $scope.hasWriteAccess = hasWriteAccess;

                if (userAccessRights.canDelete) {
                    if (!$rootScope.page.subnav.buttons.some(x => x.text === "Slet IT System")) {
                        $rootScope.page.subnav.buttons.push({ func: removeSystem, text: 'Slet IT System', style: 'btn-danger', showWhen: 'it-system.edit' });
                    }
                }
                else
                {
                    _.remove($rootScope.page.subnav.buttons, function (o) {
                        return o.text === "Slet IT System";
                    });
                }
                if (userAccessRights.canEdit) {
                    _.remove($rootScope.page.subnav.buttons, function (o) {
                        return o.text === "Deaktivér IT System";
                    });
                    _.remove($rootScope.page.subnav.buttons, function (o) {
                        return o.text === "Aktivér IT System";
                    });

                    if (userAccessRights.canEdit) {
                        if (!itSystem.disabled) {
                            $rootScope.page.subnav.buttons.push(
                                { func: disableSystem, text: 'Deaktivér IT System', style: 'btn-danger', showWhen: 'it-system.edit' }
                            );
                        } else {
                            $rootScope.page.subnav.buttons.push(
                                { func: enableSystem, text: 'Aktivér IT System', style: 'btn-success', showWhen: 'it-system.edit' }
                            );
                        }<commit_msg>comment regarding hasWriteAccess vs. userAccessRights<commit_after>﻿(function (ng, app) {
    app.config(['$stateProvider', '$urlRouterProvider', function ($stateProvider, $urlRouterProvider) {
        $stateProvider.state('it-system.edit', {
            url: '/edit/{id:[0-9]+}',
            templateUrl: 'app/components/it-system/edit/it-system-edit.view.html',
            controller: 'system.EditCtrl',
            resolve: {
                itSystem: ['$http', '$stateParams', function ($http, $stateParams) {
                    return $http.get("api/itsystem/" + $stateParams.id)
                        .then(function (result) {
                            return result.data.response;
                        });
                }],
                user: [
                    'userService', function (userService) {
                        return userService.getUser();
                    }
                ],
                hasWriteAccess: ['$http', '$stateParams', 'user', function ($http, $stateParams, user) {
                    return $http.get("api/itsystem/" + $stateParams.id + "?hasWriteAccess=true&organizationId=" + user.currentOrganizationId)
                        .then(function (result) {
                            return result.data.response;
                        });
                }],
                userAccessRights: ['$http', '$stateParams', function ($http, $stateParams) {
                    return $http.get("api/itsystem/" + $stateParams.id +"/accessrights")
                        .then(function (result) {
                            return result.data.response;
                        });
                }]
            }
        });
    }]);

    app.controller('system.EditCtrl',
        [
            '$rootScope', '$scope', 'itSystem', 'user', 'hasWriteAccess', '$state', 'notify', '$http', '_','userAccessRights',
            function ($rootScope, $scope, itSystem, user, hasWriteAccess, $state, notify, $http, _, userAccessRights) {
                
                //TODO for MBK - har du set den der? -> Hvilken indflydelse har den nu hvor der er de nye access rights? Den går igen på de andre tabs. Selve værdien er det samme som den fra canEdit, da den også kalder AllowModify
                //TODO: Overvej om de to GetAccessRights metoder skal ned i GenericApiController. De kalder ned i generisk funktionalitet i forvejen. Samtidig bør vi have to forskellige DTO'er tilpasset hhv. "Må jeg" med/uden entity
                $scope.hasWriteAccess = hasWriteAccess;

                if (userAccessRights.canDelete) {
                    if (!$rootScope.page.subnav.buttons.some(x => x.text === "Slet IT System")) {
                        $rootScope.page.subnav.buttons.push({ func: removeSystem, text: 'Slet IT System', style: 'btn-danger', showWhen: 'it-system.edit' });
                    }
                }
                else
                {
                    _.remove($rootScope.page.subnav.buttons, function (o) {
                        return o.text === "Slet IT System";
                    });
                }
                if (userAccessRights.canEdit) {
                    _.remove($rootScope.page.subnav.buttons, function (o) {
                        return o.text === "Deaktivér IT System";
                    });
                    _.remove($rootScope.page.subnav.buttons, function (o) {
                        return o.text === "Aktivér IT System";
                    });

                    if (userAccessRights.canEdit) {
                        if (!itSystem.disabled) {
                            $rootScope.page.subnav.buttons.push(
                                { func: disableSystem, text: 'Deaktivér IT System', style: 'btn-danger', showWhen: 'it-system.edit' }
                            );
                        } else {
                            $rootScope.page.subnav.buttons.push(
                                { func: enableSystem, text: 'Aktivér IT System', style: 'btn-success', showWhen: 'it-system.edit' }
                            );
                        }
{'fraction_non_alphanumeric': 0.12571726656233698, 'fraction_numerical': 0.0005216484089723526, 'mean_word_length': 1.3538980969920196, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3525286', 'n_tokens_mistral': 2007, 'n_tokens_neox': 1884, 'n_words': 399}