<commit_before>'use strict';

function paramSelected(value) {
    var selected = getParameterByName('selected');
    var treeBase = getParameterByName('treeBase');
    // fix probably wrong uri with tree base instead without
    if (selected) {
        selected = selected.replace(treeBase, '')
        var fixedUrl = updateURLParameter(window.location.href, 'selected', selected);
        // update url
        window.history.replaceState(undefined, undefined, fixedUrl);
    }

    if (value === undefined || value === '') {
        console.log('info', treeBase + selected);
        return treeBase + selected;
    }

    var newUrl;
    if (!selected || selected === null) {
        newUrl = window.location.href + '&selected=' + value.replace(treeBase, '');
    } else {
        newUrl = updateURLParameter(window.location.href, 'selected', value.replace(treeBase, ''));
    }

    // update url
    window.history.replaceState(undefined, undefined, newUrl);
    selected = getParameterByName('selected');

    return treeBase + selected;
}

var autoExpandToAndSelectPath = paramSelected();

function goHome() {
    window.location.href = settings.homeUrl;
}

function findNodesByUrl(searchUrl) {
    var nodes = [];
    var jstree = $('#tree').jstree();
    function recurse(nodeId) {
        var node = jstree.get_node(nodeId)
        if (node.data) {
            if (node.data.url === searchUrl) {
                nodes.push(node);
                return;
            }
            if (searchUrl.indexOf(node.data.url) !== 0) {
                return;
            }
        }
        node.children.forEach(recurse);
    }
    recurse('#');
    return nodes;
}

function gotoResource() {
    autoExpandToAndSelectPath = $('#nameOfResourceToSearch').val();
    var jstree = $('#tree').jstree();
    jstree.refresh();
    $('#dialogSearchResource').dialog('close');
}

function createResource() {
    var relPath = $('#nameOfResourceToCreate').val();
    if (!relPath) {
        $('#nameOfResourceToCreate').effect('highlight', {color: '#F88'}, 200);
        return;
    }
    var basePath = $('#nameOfResourceToCreateBaseUrl').text();
    var url = basePath + relPath;
    $.ajax({
        url: url,
        type: 'PUT',
        data: '{}'
    }).then(function () {
        var affectedParentNodes = findNodesByUrl(basePath);
        autoExpandToAndSelectPath = url;
        var jstree = $('#tree').jstree();
        jstree.deselect_all();
        affectedParentNodes.forEach(function(node) {
            node.data.childrenNames = null;
            jstree.refresh_node(node);
        });
        // jstree.refresh_node(basePath);
        $('#dialogCreateResource').parent().effect('highlight', {color: '#8F8'}, 200);
    });
}

function deleteResource() {
    var url = $('#nameOfResourceToDelete').text();
    $.ajax({
        url: url,
        type: 'DELETE'
    }).then(function () {
        var jstree = $('#tree').jstree();
        var affectedNodes = findNodesByUrl(url);
        affectedNodes.forEach(function (node) {
            jstree.delete_node(node);
            var parentNode = jstree.get_node(node.parent);
            parentNode.data.childrenNames = null;
            jstree.refresh_node(parentNode);
        });
        $('#dialogDeleteResource').dialog('close');
    });
}

function getParameterByName(name) {
    var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
    if (results==null){
       return null;
    }
    else{
       return decodeURI(results[1]) || '/';
    }
}

function updateURLParameter(url, param, paramVal){
    var newAdditionalURL = "";
    var tempArray = url.split("?");
    var baseURL = tempArray[0];
    var additionalURL = tempArray[1];
    var temp = "";
    if (additionalURL) {
        tempArray = additionalURL.split("&");
        for (var i=0; i<tempArray.length; i++){
            if(tempArray[i].split('=')[0] != param){
                newAdditionalURL += temp + tempArray[i];
                temp = "&";
            }<commit_msg>code improvements<commit_after>'use strict';

function paramSelected(value) {
    var selected = getParameterByName('selected');
    var treeBase = getParameterByName('treeBase');
    // fix probably wrong uri with tree base instead without
    if (selected) {
        selected = selected.replace(treeBase, '')
        var fixedUrl = updateURLParameter(window.location.href, 'selected', selected);
        // update url
        window.history.replaceState(undefined, undefined, fixedUrl);
    }

    if (value === undefined || value === '') {
        return treeBase + selected;
    }

    var newUrl;
    if (!selected || selected === null) {
        newUrl = window.location.href + '&selected=' + value.replace(treeBase, '');
    } else {
        newUrl = updateURLParameter(window.location.href, 'selected', value.replace(treeBase, ''));
    }

    // update url
    window.history.replaceState(undefined, undefined, newUrl);

    return treeBase + getParameterByName('selected');
}

var autoExpandToAndSelectPath = paramSelected();

function goHome() {
    window.location.href = settings.homeUrl;
}

function findNodesByUrl(searchUrl) {
    var nodes = [];
    var jstree = $('#tree').jstree();
    function recurse(nodeId) {
        var node = jstree.get_node(nodeId)
        if (node.data) {
            if (node.data.url === searchUrl) {
                nodes.push(node);
                return;
            }
            if (searchUrl.indexOf(node.data.url) !== 0) {
                return;
            }
        }
        node.children.forEach(recurse);
    }
    recurse('#');
    return nodes;
}

function gotoResource() {
    autoExpandToAndSelectPath = $('#nameOfResourceToSearch').val();
    var jstree = $('#tree').jstree();
    jstree.refresh();
    $('#dialogSearchResource').dialog('close');
}

function createResource() {
    var relPath = $('#nameOfResourceToCreate').val();
    if (!relPath) {
        $('#nameOfResourceToCreate').effect('highlight', {color: '#F88'}, 200);
        return;
    }
    var basePath = $('#nameOfResourceToCreateBaseUrl').text();
    var url = basePath + relPath;
    $.ajax({
        url: url,
        type: 'PUT',
        data: '{}'
    }).then(function () {
        var affectedParentNodes = findNodesByUrl(basePath);
        autoExpandToAndSelectPath = url;
        var jstree = $('#tree').jstree();
        jstree.deselect_all();
        affectedParentNodes.forEach(function(node) {
            node.data.childrenNames = null;
            jstree.refresh_node(node);
        });
        // jstree.refresh_node(basePath);
        $('#dialogCreateResource').parent().effect('highlight', {color: '#8F8'}, 200);
    });
}

function deleteResource() {
    var url = $('#nameOfResourceToDelete').text();
    $.ajax({
        url: url,
        type: 'DELETE'
    }).then(function () {
        var jstree = $('#tree').jstree();
        var affectedNodes = findNodesByUrl(url);
        affectedNodes.forEach(function (node) {
            jstree.delete_node(node);
            var parentNode = jstree.get_node(node.parent);
            parentNode.data.childrenNames = null;
            jstree.refresh_node(parentNode);
        });
        $('#dialogDeleteResource').dialog('close');
    });
}

// return one parameter by name
function getParameterByName(name) {
    var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
    if (results==null){
       return null;
    }
    else{
       return decodeURI(results[1]) || '/';
    }
}

// update one parameter in an url
function updateURLParameter(url, param, paramVal){
    var newAdditionalURL = "";
    var tempArray = url.split("?");
    var baseURL = tempArray[0];
    var additionalURL = tempArray[1];
    var temp = "";
    if (additionalURL) {
        tempArray = additionalURL.split("&");
        for (var i=0; i<tempArray.length; i++){
            if(tempArray[i].split('=')[0] != param){
                newAdditionalURL += temp + tempArray[i];
                temp = "&";
            }
{'fraction_non_alphanumeric': 0.15545330182813083, 'fraction_numerical': 0.003979604526800149, 'mean_word_length': 2.5442926399294845, 'pattern_counts': {'":': 0, '<': 5, '<?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': '3571002', 'n_tokens_mistral': 2360, 'n_tokens_neox': 2324, 'n_words': 465}