<commit_before>/* global angular */
(function () {
    angular
        .module('users')
        .component('scientillaUserDetails', {
            controller: controller,
            templateUrl: 'partials/scientilla-user-details.html',
            controllerAs: 'vm',
            bindings: {
                userId: '<'
            }
        });

    controller.$inject = [
        'Restangular',
        'researchEntityService',
        'ResearchEntitiesService',
        'UsersService',
        'GroupsService',
        'documentListSections',
        'accomplishmentListSections',
        'AuthService',
        '$scope',
        '$controller'
    ];

    function controller(Restangular, researchEntityService, ResearchEntitiesService, UsersService, GroupsService, documentListSections, accomplishmentListSections, AuthService, $scope, $controller) {
        const vm = this;
        angular.extend(vm, $controller('SummaryInterfaceController', {$scope: $scope}));
        angular.extend(vm, $controller('TabsController', {$scope: $scope}));

        vm.documentListSections = documentListSections;
        vm.accomplishmentListSections = accomplishmentListSections;
        vm.loggedUser = AuthService.user;

        vm.activeTabIndex = 0;

        const tabIdentifiers = [
            {
                index: 0,
                slug: 'profile'
            }, {
                index: 1,
                slug: 'groups'
            }, {
                index: 2,
                slug: 'documents'
            }, {
                index: 3,
                slug: 'accomplishments'
            }, {
                index: 4,
                slug: 'documents-overview',
                tabName: 'overview',
                getData: getData
            }, {
                index: 5,
                slug: 'bibliometric-charts',
                tabName: 'metrics',
                getData: getData
            }
        ];

        vm.isActiveMember = (user, group) => {
            const groupMembership = user.groupMemberships
                .find(groupMembership => groupMembership.group === group.id);

            if (groupMembership) {
                return groupMembership.active;
            }

            return true;
        };

        vm.getTypeTitle = GroupsService.getTypeTitle;

        /* jshint ignore:start */
        vm.$onInit = async () => {

            vm.user = await UsersService.getUser(vm.userId);
            const groupIds = vm.user.memberships.map(g => g.id);
            console.log(groupIds);
            vm.institute = await GroupsService.getConnectedGroups(groupIds);
            vm.types = _.groupBy(vm.institute.childGroups, 'type');

            vm.initializeTabs(tabIdentifiers);
        };

        vm.getGroupTypes = (group) => {
            return _.groupBy(group.childGroups, 'type');
        };

        async function getData() {
            return await vm.getChartsData(vm.user);
        }
        /* jshint ignore:end */
    }

})();<commit_msg>Update active membership of group<commit_after>/* global angular */
(function () {
    angular
        .module('users')
        .component('scientillaUserDetails', {
            controller: controller,
            templateUrl: 'partials/scientilla-user-details.html',
            controllerAs: 'vm',
            bindings: {
                userId: '<'
            }
        });

    controller.$inject = [
        'Restangular',
        'researchEntityService',
        'ResearchEntitiesService',
        'UsersService',
        'GroupsService',
        'documentListSections',
        'accomplishmentListSections',
        'AuthService',
        '$scope',
        '$controller'
    ];

    function controller(Restangular, researchEntityService, ResearchEntitiesService, UsersService, GroupsService, documentListSections, accomplishmentListSections, AuthService, $scope, $controller) {
        const vm = this;
        angular.extend(vm, $controller('SummaryInterfaceController', {$scope: $scope}));
        angular.extend(vm, $controller('TabsController', {$scope: $scope}));

        vm.documentListSections = documentListSections;
        vm.accomplishmentListSections = accomplishmentListSections;
        vm.loggedUser = AuthService.user;

        vm.activeTabIndex = 0;
        vm.types = [];

        let allMemberships = [];

        const tabIdentifiers = [
            {
                index: 0,
                slug: 'profile'
            }, {
                index: 1,
                slug: 'groups'
            }, {
                index: 2,
                slug: 'documents'
            }, {
                index: 3,
                slug: 'accomplishments'
            }, {
                index: 4,
                slug: 'documents-overview',
                tabName: 'overview',
                getData: getData
            }, {
                index: 5,
                slug: 'bibliometric-charts',
                tabName: 'metrics',
                getData: getData
            }
        ];

        vm.getTypeTitle = GroupsService.getTypeTitle;

        /* jshint ignore:start */
        vm.isActiveMember = (user, group) => {
            const membership = allMemberships.find(m => m.user === user.id && m.group === group.id);
            if (membership) {
                return membership.active;
            }
            return false;
        };

        vm.$onInit = async () => {
            allMemberships = await researchEntityService.getAllMemberships();
            vm.user = await UsersService.getUser(vm.userId);
            const groupIds = vm.user.memberships.map(g => g.id);
            vm.institute = await GroupsService.getConnectedGroups(groupIds);

            if (groupIds.length > 1) {
                vm.types = _.groupBy(vm.institute.childGroups, 'type');
            }

            vm.initializeTabs(tabIdentifiers);
        };

        vm.getGroupTypes = (group) => {
            return _.groupBy(group.childGroups, 'type');
        };

        async function getData() {
            return await vm.getChartsData(vm.user);
        }
        /* jshint ignore:end */
    }

})();
{'fraction_non_alphanumeric': 0.11366976972072514, 'fraction_numerical': 0.002449779519843214, 'mean_word_length': 1.614859094790777, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 14, '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': '1788594', 'n_tokens_mistral': 1666, 'n_tokens_neox': 1558, 'n_words': 291}