<commit_before>spacialistApp.controller('treeCtrl', ['$scope', 'scopeService', 'httpPostFactory', 'httpPostPromise', 'httpGetFactory', 'httpGetPromise', 'Upload', '$timeout', '$uibModal', '$sce', function($scope, scopeService, httpPostFactory, httpPostPromise, httpGetFactory, httpGetPromise, Upload, $timeout, $uibModal) {
    var getLanguages = function() {
        httpGetFactory('api/get/languages', function(callback) {
            for(var i=0; i<callback.length; i++) {
                var lg = callback[i];
                $scope.possibleLanguages.push({
                    langShort: lg.short_name,
                    langName: lg.display_name,
                    id: lg.id
                });
            }
            $scope.selectedPrefLabelLanguage = $scope.possibleLanguages[0];
            $scope.selectedAltLabelLanguage = $scope.possibleLanguages[0];
            $scope.preferredLanguage = $scope.possibleLanguages[0];
        });
    };

    $scope.searchResults = {};
    $scope.rdfTree = {};
    $scope.roots = {
        clone: {},
        master: {}
    };
    $scope.completeTree = {};
    $scope.enableDragDrop = false;
    $scope.enableEditing = false;
    $scope.enableExportDragDrop = false;
    $scope.newPrefLabelText = {
        text: ""
    };
    $scope.newAltLabelText = {
        text: ""
    };
    $scope.matchingBroaderConcepts = [];
    $scope.matchingNarrowerConcepts = [];
    $scope.possibleLanguages = [];
    getLanguages();

    var dropped = function(event, isExportTree) {
        var oldParent = event.source.nodesScope.$modelValue;
        var newParent = event.dest.nodesScope.$modelValue;
        var isFromAnotherTree = false;
        if(typeof event.source.cloneModel !== 'undefined') {
            isFromAnotherTree = true;
            event.source.nodeScope.$modelValue = event.source.cloneModel;
        }
        var elem = event.source.nodeScope.$modelValue;
        var isExport = 'master';
        if((isFromAnotherTree && !isExportTree) || isExportTree) isExport = 'clone';
        if(isFromAnotherTree) {
            elem.is_top_concept = 'f';
            var id = -1;
            if(typeof newParent == 'undefined' || newParent.id == -1) {
                elem.is_top_concept = 't';
                elem.broader_id = -1;
            } else {
                id = newParent.id;
            }
            var src = isExportTree ? 'clone' : 'master';
            var formData = new FormData();
            formData.append('id', elem.id);
            formData.append('new_broader', id);
            formData.append('src', src);
            formData.append('is_top_concept', elem.is_top_concept == 't');
            var promise = httpPostPromise.getData('api/copy', formData);
            promise.then(function(data) {
                console.log(data.toSource());
                $scope.completeTree[isExport].push(elem);
                $scope.rdfTree[isExport].push(elem);
            });
        }
        var outerPromise = updateRelation(elem.id, oldParent.id, newParent.id, isExportTree);
        outerPromise.then(function(concepts) {
            for(var k in concepts.concepts) {
                if(concepts.concepts.hasOwnProperty(k)) {
                    $scope.roots[isExport][k] = concepts.concepts[k];
                }
            }
            $scope.conceptNames = concepts.conceptNames.slice();
        });
    };

    $scope.treeOptions = {
        dropped: function(event) {
            dropped(event, false);
        }
    };

    $scope.exportTreeOptions = {
        dropped: function(event) {
            dropped(event, true);
        }
    };

    var getTreeType = function(isExport) {
        return (typeof isExport === 'undefined' || isExport != 'clone') ? 'master' : 'clone';
    };

    $scope.addConcept = function(name, concept, lang, isExport) {
        isExport = getTreeType(isExport);
        if(typeof $scope.currentModal !== 'undefined') $scope.currentModal.close('ok');
        var projName = (isExport == 'master') ? 'intern' : '<user-project>';
        var scheme = "https://spacialist.escience.uni-tuebingen.de/schemata#newScheme";
        var isTC = false;
        var reclevel = 0;
        var id = -1;
        if(typeof concept == 'undefined') {
            isTC = true;
        } else {
            reclevel = parseInt(concept.reclevel) + 1;
            id = concept.id;
        }
        var promise = addConcept(scheme, id, isTC, name, projName, lang.id, isExport);
        promise.then(function(retElem) {
            var newId = retElem.newId;
            var newElem = {
                id: newId,
                concept_url: retElem.url,
                concept_scheme: scheme,
                is_top_concept: isTC,
                label: name,
                intree: isExport,
                reclevel: reclevel,
                hasChildren: false
            };
            if(id > 0) {
                newElem.broader_id = id;
                concept.children.push(newElem);
            } else {
                $scope.rdfTree[isExport].push(newElem);
                $scope.completeTree[isExport].push(newElem);
            }
        });
    };

    var addPromisedConcept = function(name, concept, lang, isExport) {
        isExport = getTreeType(isExport);
        $scope.addConcept(name, concept, lang.id, isExport);
        return $timeout(function(){}, 50);
    };<commit_msg>set 'hasChildren' attribute after adding a child node<commit_after>spacialistApp.controller('treeCtrl', ['$scope', 'scopeService', 'httpPostFactory', 'httpPostPromise', 'httpGetFactory', 'httpGetPromise', 'Upload', '$timeout', '$uibModal', '$sce', function($scope, scopeService, httpPostFactory, httpPostPromise, httpGetFactory, httpGetPromise, Upload, $timeout, $uibModal) {
    var getLanguages = function() {
        httpGetFactory('api/get/languages', function(callback) {
            for(var i=0; i<callback.length; i++) {
                var lg = callback[i];
                $scope.possibleLanguages.push({
                    langShort: lg.short_name,
                    langName: lg.display_name,
                    id: lg.id
                });
            }
            $scope.selectedPrefLabelLanguage = $scope.possibleLanguages[0];
            $scope.selectedAltLabelLanguage = $scope.possibleLanguages[0];
            $scope.preferredLanguage = $scope.possibleLanguages[0];
        });
    };

    $scope.searchResults = {};
    $scope.rdfTree = {};
    $scope.roots = {
        clone: {},
        master: {}
    };
    $scope.completeTree = {};
    $scope.enableDragDrop = false;
    $scope.enableEditing = false;
    $scope.enableExportDragDrop = false;
    $scope.newPrefLabelText = {
        text: ""
    };
    $scope.newAltLabelText = {
        text: ""
    };
    $scope.matchingBroaderConcepts = [];
    $scope.matchingNarrowerConcepts = [];
    $scope.possibleLanguages = [];
    getLanguages();

    var dropped = function(event, isExportTree) {
        var oldParent = event.source.nodesScope.$modelValue;
        var newParent = event.dest.nodesScope.$modelValue;
        var isFromAnotherTree = false;
        if(typeof event.source.cloneModel !== 'undefined') {
            isFromAnotherTree = true;
            event.source.nodeScope.$modelValue = event.source.cloneModel;
        }
        var elem = event.source.nodeScope.$modelValue;
        var isExport = 'master';
        if((isFromAnotherTree && !isExportTree) || isExportTree) isExport = 'clone';
        if(isFromAnotherTree) {
            elem.is_top_concept = 'f';
            var id = -1;
            if(typeof newParent == 'undefined' || newParent.id == -1) {
                elem.is_top_concept = 't';
                elem.broader_id = -1;
            } else {
                id = newParent.id;
            }
            var src = isExportTree ? 'clone' : 'master';
            var formData = new FormData();
            formData.append('id', elem.id);
            formData.append('new_broader', id);
            formData.append('src', src);
            formData.append('is_top_concept', elem.is_top_concept == 't');
            var promise = httpPostPromise.getData('api/copy', formData);
            promise.then(function(data) {
                console.log(data.toSource());
                $scope.completeTree[isExport].push(elem);
                $scope.rdfTree[isExport].push(elem);
            });
        }
        var outerPromise = updateRelation(elem.id, oldParent.id, newParent.id, isExportTree);
        outerPromise.then(function(concepts) {
            for(var k in concepts.concepts) {
                if(concepts.concepts.hasOwnProperty(k)) {
                    $scope.roots[isExport][k] = concepts.concepts[k];
                }
            }
            $scope.conceptNames = concepts.conceptNames.slice();
        });
    };

    $scope.treeOptions = {
        dropped: function(event) {
            dropped(event, false);
        }
    };

    $scope.exportTreeOptions = {
        dropped: function(event) {
            dropped(event, true);
        }
    };

    var getTreeType = function(isExport) {
        return (typeof isExport === 'undefined' || isExport != 'clone') ? 'master' : 'clone';
    };

    $scope.addConcept = function(name, concept, lang, isExport) {
        isExport = getTreeType(isExport);
        if(typeof $scope.currentModal !== 'undefined') $scope.currentModal.close('ok');
        var projName = (isExport == 'master') ? 'intern' : '<user-project>';
        var scheme = "https://spacialist.escience.uni-tuebingen.de/schemata#newScheme";
        var isTC = false;
        var reclevel = 0;
        var id = -1;
        if(typeof concept == 'undefined') {
            isTC = true;
        } else {
            reclevel = parseInt(concept.reclevel) + 1;
            id = concept.id;
        }
        var promise = addConcept(scheme, id, isTC, name, projName, lang.id, isExport);
        promise.then(function(retElem) {
            var newId = retElem.newId;
            var newElem = {
                id: newId,
                concept_url: retElem.url,
                concept_scheme: scheme,
                is_top_concept: isTC,
                label: name,
                intree: isExport,
                reclevel: reclevel,
                hasChildren: false
            };
            if(id > 0) {
                newElem.broader_id = id;
                concept.children.push(newElem);
                if(!concept.hasChildren) concept.hasChildren = true;
            } else {
                $scope.rdfTree[isExport].push(newElem);
                $scope.completeTree[isExport].push(newElem);
            }
        });
    };

    var addPromisedConcept = function(name, concept, lang, isExport) {
        isExport = getTreeType(isExport);
        $scope.addConcept(name, concept, lang.id, isExport);
        return $timeout(function(){}, 50);
    };
{'fraction_non_alphanumeric': 0.12975699220541037, 'fraction_numerical': 0.002384227418615314, 'mean_word_length': 1.9427954668105774, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, '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': '201843', 'n_tokens_mistral': 3199, 'n_tokens_neox': 3090, 'n_words': 552}