<commit_before>export default class PersonsEditController {
    constructor($scope, GLOBALS, $q, $location, $routeParams, NgTableParams, $window, AuthService, PagedPersons, PersonService,
                PersonPersister, MessageManager, Countries, MemberStates, PersonCategoryService) {

        $scope.debug = GLOBALS.DEBUG;
        $scope.busy = false;
        $scope.masterdata = {};
        $scope.isClubAdmin = AuthService.isClubAdmin();
        $scope.requiredFlagsFilterList = [
            'HasGliderInstructorLicence',
            'HasGliderPilotLicence',
            'HasGliderTraineeLicence',
            'HasMotorPilotLicence',
            'HasMotorInstructorLicence',
            'HasTowPilotLicence'
        ];
        $scope.requiredFlagsFilter = {};
        $scope.toggleRequiredFlagFilter = (flag) => {
            let previousValue = $scope.requiredFlagsFilter[flag];
            $scope.requiredFlagsFilter = {};
            $scope.requiredFlagsFilter[flag] = !previousValue;
            $scope.tableParams.reload();
        };
        $scope.resetRequiredFlagsFilters = () => {
            $scope.requiredFlagsFilter = {};
            $scope.tableParams.reload();
        };


        function loadPerson() {
            let deferred = $q.defer();
            if ($routeParams.id === 'new') {
                deferred.resolve({
                    CanUpdateRecord: true
                });
                return deferred.promise;
            }
            return PersonPersister.get({id: $routeParams.id}).$promise;
        }

        $scope.newPerson = function () {
            $location.path('/masterdata/persons/new');
        };
        $scope.editPerson = function (person) {
            $location.path('/masterdata/persons/' + person.PersonId);
        };

        if ($routeParams.id !== undefined) {
            $scope.busy = true;
            $q
                .all([
                    Countries.query().$promise.then(function (result) {
                        $scope.masterdata.countries = result;
                    }),
                    MemberStates.query().$promise.then(function (result) {
                        $scope.masterdata.memberStates = result;
                    }),
                    PersonCategoryService.loadPersonCategories().then((result) => {
                        $scope.masterdata.personCategories = result;
                    })
                ])
                .then(loadPerson)
                .then((person) => {
                    $scope.person = person;
                })
                .finally(function () {
                    $scope.busy = false;
                });
        } else {
            $scope.tableParams = new NgTableParams({
                filter: {},
                sorting: {
                    Lastname: 'asc',
                    Firstname: 'asc'
                },
                count: 100
            }, {
                counts: [],
                getData: function (params) {
                    $scope.busy = true;
                    let pageSize = params.count();
                    let pageStart = (params.page() - 1) * pageSize;

                    let filter = Object.assign({}, $scope.tableParams.filter(), $scope.requiredFlagsFilter);

                    return PagedPersons.getPersons(filter, $scope.tableParams.sorting(), pageStart, pageSize)
                        .then((result) => {
                            $scope.busy = false;
                            params.total(result.TotalRows);

                            return result.Items;
                        })
                        .finally(() => {
                            $scope.busy = false;
                        });<commit_msg>#159 find selected person categories after reloading persisted person<commit_after>export default class PersonsEditController {
    constructor($scope, GLOBALS, $q, $location, $routeParams, NgTableParams, $window, AuthService, PagedPersons, PersonService,
                PersonPersister, MessageManager, Countries, MemberStates, PersonCategoryService) {

        $scope.debug = GLOBALS.DEBUG;
        $scope.busy = false;
        $scope.masterdata = {};
        $scope.isClubAdmin = AuthService.isClubAdmin();
        $scope.requiredFlagsFilterList = [
            'HasGliderInstructorLicence',
            'HasGliderPilotLicence',
            'HasGliderTraineeLicence',
            'HasMotorPilotLicence',
            'HasMotorInstructorLicence',
            'HasTowPilotLicence'
        ];
        $scope.requiredFlagsFilter = {};
        $scope.toggleRequiredFlagFilter = (flag) => {
            let previousValue = $scope.requiredFlagsFilter[flag];
            $scope.requiredFlagsFilter = {};
            $scope.requiredFlagsFilter[flag] = !previousValue;
            $scope.tableParams.reload();
        };
        $scope.resetRequiredFlagsFilters = () => {
            $scope.requiredFlagsFilter = {};
            $scope.tableParams.reload();
        };


        function loadPerson() {
            let deferred = $q.defer();
            if ($routeParams.id === 'new') {
                deferred.resolve({
                    CanUpdateRecord: true
                });
                return deferred.promise;
            }
            return PersonPersister.get({id: $routeParams.id}).$promise;
        }

        $scope.newPerson = function () {
            $location.path('/masterdata/persons/new');
        };
        $scope.editPerson = function (person) {
            $location.path('/masterdata/persons/' + person.PersonId);
        };

        if ($routeParams.id !== undefined) {
            $scope.busy = true;
            $q
                .all([
                    Countries.query().$promise.then(function (result) {
                        $scope.masterdata.countries = result;
                    }),
                    MemberStates.query().$promise.then(function (result) {
                        $scope.masterdata.memberStates = result;
                    }),
                    PersonCategoryService.loadPersonCategories().then((result) => {
                        $scope.masterdata.personCategories = result;
                    })
                ])
                .then(loadPerson)
                .then((person) => {
                    $scope.person = person;
                    person.ClubRelatedPersonDetails.PersonCategoryIds.forEach(personCategoryId => {
                        let categoryNode = $scope.masterdata.personCategories.find(category => category.PersonCategoryId === personCategoryId);
                        if(!!categoryNode) {
                            categoryNode.selected = true;
                        }
                    })
                })
                .finally(function () {
                    $scope.busy = false;
                });
        } else {
            $scope.tableParams = new NgTableParams({
                filter: {},
                sorting: {
                    Lastname: 'asc',
                    Firstname: 'asc'
                },
                count: 100
            }, {
                counts: [],
                getData: function (params) {
                    $scope.busy = true;
                    let pageSize = params.count();
                    let pageStart = (params.page() - 1) * pageSize;

                    let filter = Object.assign({}, $scope.tableParams.filter(), $scope.requiredFlagsFilter);

                    return PagedPersons.getPersons(filter, $scope.tableParams.sorting(), pageStart, pageSize)
                        .then((result) => {
                            $scope.busy = false;
                            params.total(result.TotalRows);

                            return result.Items;
                        })
                        .finally(() => {
                            $scope.busy = false;
                        });
{'fraction_non_alphanumeric': 0.11180045581159788, 'fraction_numerical': 0.001392757660167131, 'mean_word_length': 1.3349098433343187, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '7652142', 'n_tokens_mistral': 1988, 'n_tokens_neox': 1848, 'n_words': 297}