<commit_before>'use strict';

angular.module('algorea')
.controller('chapterController', [
    '$rootScope', '$scope', 'itemService', '$state', '$i18next', '$uibModal', '$sce', '$timeout', '$interval', '$http', 'loginService', 'pathService', 'tabsService',
    function ($rootScope, $scope, itemService, $state, $i18next, $uibModal, $sce, $timeout, $interval, $http, loginService, pathService, tabsService) {
        $scope.itemService = itemService;
        $scope.tabsService = tabsService;
        $scope.models = models;
        $scope.tab = 'content';

        $scope.links = {};
        $scope.showMore = {};

        $scope.sortableOptions = {
            handle: '.drag-ctrl',
            stop: function(event, ui) {
                recalculateItemsOrder();
            }
        }

        $scope.setupSync = function() {
            if($scope.getEditMode() != 'edit') { return; }
            // sync does not work without this
            if(!SyncQueue.requests) { SyncQueue.requests = {}; }
            SyncQueue.requests.algorea = {
                admin: true
            };
        }

        var user = null;
        loginService.getLoginData(function(res) {
            user = res;
        })

        tabsService.resetTabs($scope.getEditMode && $scope.getEditMode() == 'edit');
        tabsService.addTab({id: 'content', title: 'chapterEditor_content', order: 0});

        // common
        $scope.availableLocales = ModelsManager.getRecords('languages');
        // TODO :: Why is that happening?
        if($scope.availableLocales[0]) { delete $scope.availableLocales[0]; }

        function refresh() {
            $scope.allowReorder = !$scope.item.bFixedRanks;
            $scope.items = itemService.getChildren($scope.item);
            $scope.item_strings = $scope.item.strings[0];
            $scope.item_strings_compare = null;
            if($scope.getEditMode() == 'edit' && $scope.item.sRepositoryPath) {
                tabsService.addTab({id: 'repository', title: 'chapterEditor_repository', order: 200});
            }
            $scope.setupSync();
            $scope.itemItems = {};
            angular.forEach($scope.item.children, function(itemItem) {
                $scope.itemItems[itemItem.child.ID] = itemItem;
            });
        }
        refresh();

        function getItemItem(item) {
            // Get the item_item between the current item and the argument
            var item_item = null;
            angular.forEach(item.parents, function(ii) {
                if(ii.idItemParent == $scope.item.ID) {
                    item_item = ii;
                }
            });
            return item_item;
        }


        $scope.$on('algorea.reloadTabs', function(event) {
            refresh();
        });
        $scope.$on('algorea.reloadView', function(event, view) {
            if(view == 'right') {
                refresh();
            }
        });


        $scope.getItemIcon = itemService.getItemIcon;

        $scope.getChildSref = function(item) {
            return pathService.getSref($scope.panel, typeof $scope.depth != 'undefined' ? $scope.depth + 1 : 0, $scope.pathParams, '-' + item.ID);
        };

        // children items

        function createItem(sType, sTitle) {
            var item = ModelsManager.createRecord("items");
            item.bOwnerAccess = true;
            item.sType = sType;
            ModelsManager.insertRecord("items", item);

            var groupItem = ModelsManager.createRecord("groups_items");
            groupItem.idItem = item.ID;
            groupItem.idGroup = user.idGroupSelf;
            var accessStartDate = new Date();
            accessStartDate.setDate(accessStartDate.getDate() - 1);<commit_msg>chapterController: Fix getChanged disappearing during merge<commit_after>'use strict';

angular.module('algorea')
.controller('chapterController', [
    '$rootScope', '$scope', 'itemService', '$state', '$i18next', '$uibModal', '$sce', '$timeout', '$interval', '$http', 'loginService', 'pathService', 'tabsService',
    function ($rootScope, $scope, itemService, $state, $i18next, $uibModal, $sce, $timeout, $interval, $http, loginService, pathService, tabsService) {
        $scope.itemService = itemService;
        $scope.tabsService = tabsService;
        $scope.models = models;
        $scope.tab = 'content';

        $scope.links = {};
        $scope.showMore = {};

        $scope.sortableOptions = {
            handle: '.drag-ctrl',
            stop: function(event, ui) {
                recalculateItemsOrder();
            }
        }

        $scope.setupSync = function() {
            if($scope.getEditMode() != 'edit') { return; }
            // sync does not work without this
            if(!SyncQueue.requests) { SyncQueue.requests = {}; }
            SyncQueue.requests.algorea = {
                admin: true
            };
        }

        var user = null;
        loginService.getLoginData(function(res) {
            user = res;
        })

        tabsService.resetTabs($scope.getEditMode && $scope.getEditMode() == 'edit');
        tabsService.addTab({id: 'content', title: 'chapterEditor_content', order: 0});

        // common
        $scope.availableLocales = ModelsManager.getRecords('languages');
        // TODO :: Why is that happening?
        if($scope.availableLocales[0]) { delete $scope.availableLocales[0]; }

        function refresh() {
            $scope.allowReorder = !$scope.item.bFixedRanks;
            $scope.items = itemService.getChildren($scope.item);
            $scope.item_strings = $scope.item.strings[0];
            $scope.item_strings_compare = null;
            if($scope.getEditMode() == 'edit' && $scope.item.sRepositoryPath) {
                tabsService.addTab({id: 'repository', title: 'chapterEditor_repository', order: 200});
            }
            $scope.setupSync();
            $scope.itemItems = {};
            angular.forEach($scope.item.children, function(itemItem) {
                $scope.itemItems[itemItem.child.ID] = itemItem;
            });
        }
        refresh();

        function getItemItem(item) {
            // Get the item_item between the current item and the argument
            var item_item = null;
            angular.forEach(item.parents, function(ii) {
                if(ii.idItemParent == $scope.item.ID) {
                    item_item = ii;
                }
            });
            return item_item;
        }


        $scope.$on('algorea.reloadTabs', function(event) {
            refresh();
        });
        $scope.$on('algorea.reloadView', function(event, view) {
            if(view == 'right') {
                refresh();
            }
        });


        $scope.getItemIcon = itemService.getItemIcon;

        $scope.getChildSref = function(item) {
            return pathService.getSref($scope.panel, typeof $scope.depth != 'undefined' ? $scope.depth + 1 : 0, $scope.pathParams, '-' + item.ID);
        };

        $scope.setChanged = function(itemItem) {
            ModelsManager.updated('items_items', itemItem.ID);
        }

        // children items

        function createItem(sType, sTitle) {
            var item = ModelsManager.createRecord("items");
            item.bOwnerAccess = true;
            item.sType = sType;
            ModelsManager.insertRecord("items", item);

            var groupItem = ModelsManager.createRecord("groups_items");
            groupItem.idItem = item.ID;
            groupItem.idGroup = user.idGroupSelf;
            var accessStartDate = new Date();
            accessStartDate.setDate(accessStartDate.getDate() - 1);
{'fraction_non_alphanumeric': 0.13781336133350833, 'fraction_numerical': 0.0036750229688935557, 'mean_word_length': 2.029821073558648, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3690064', 'n_tokens_mistral': 2156, 'n_tokens_neox': 2055, 'n_words': 386}