<commit_before>(function() {
    // Get application context
    var app = Sammy.apps['#main'];
    var store = app.store;

    /**
     * Services
     *
     */

    // All services status
    app.get('#/services', function (c) {
        c.api('GET', '/services', {}, function(data) {
            var data2 = {
                services: []
            };
            $.each(data, function(k, v) {
                v.name = k;
                if (v.last_state_change == 'unknown')
                {
                    v.last_state_change = 0;
                }
                data2.services.push(v);
            });

            data2.services.sort(function (a, b) {
                if (a.name > b.name) {
                    return 1;
                }
                else if (a.name < b.name) {
                    return -1;
                }
                return 0;
            });

            c.view('service/service_list', data2);
        });
    });

    // Status & actions for a service
    app.get('#/services/:service', function (c) {
        c.api('GET', '/services/'+ c.params['service'], {}, function(data) {
        c.api('GET', '/services/'+ c.params['service'] +'/log', {number: 50}, function(data_log) {

            data.name = c.params['service'];
            if (data.last_state_change == 'unknown')
            {
                data.last_state_change = 0;
            }

            data.logs = [];
            $.each(data_log, function(k, v) {
                data.logs.push({filename: k, filecontent: v.join('\n')});
            });

            // Sort logs by filename, put the journalctl/systemd log on top
            data.logs.sort(function(a,b) { return a.filename === "journalctl" ? -1 : b.filename === "journalctl" ? 1 : a.filename < b.filename ? -1 : a.filename > b.filename ? 1 : 0; });

            c.view('service/service_info', data, function() {

                // Don't allow user to stop critical services from the webadmin
                $('button[data-action="stop"]').each(function() {

                    var critical = ['nginx', 'ssh', 'slapd', 'yunohost-api'];
                    var service = $(this).data('service');

                    if (critical.indexOf(service) >= 0)
                    {
                        $(this).hide();
                    }
                });

                // Configure behavior for enable/disable and start/stop buttons
                $('button[data-action="start"], button[data-action="restart"], button[data-action="stop"]').on('click', function() {

                    var service = $(this).data('service');
                    var action = $(this).data('action');

                    c.confirm(y18n.t("services"), y18n.t('confirm_service_' + action, [service]), function(){

                        if (action == "start")
                        {
                            var method = "PUT";
                            var url = "/services/" + service;
                        }
                        else if (action == "restart")
                        {
                            var method = "PUT";
                            var url = "/services/" + service + "/restart";
                        }
                        else
                        {
                            var method = "DELETE";
                            var url = "/services/" + service;
                        }
                        c.api(method, url, {}, function() { c.refresh(); });
                    });
                });

                // Configure behavior for enable/disable and start/stop buttons
                $('button[data-action="share"]').on('click', function() {

                    c.showLoader();

                    // Send to paste.yunohost.org
                    $.ajax({
                        type: "POST",
                        url: 'https://paste.yunohost.org/documents',
                        data: $("#logs").text(),
                    })
                    .success(function(data, textStatus, jqXHR) {
                        window.open('https://paste.yunohost.org/' + data.key, '_blank');
                    })
                    .fail(function() {
                        c.flash('fail', y18n.t('paste_error'));
                    })
                    .always(function(){
                        c.hideLoader();
                    });
                });
            });
        });
        });
    });

    // Service log
    app.get('#/services/:service/log', function (c) {
        var params = {
            number: 50
        };
        c.api('GET', '/services/'+ c.params['service'] +'/log', params, function(data) { // ?
            data2 = { 'logs': [], 'name': c.params['service'] };
            $.each(data, function(k, v) {
                data2.logs.push({filename: k, filecontent: v.join('\n')});
            });

            c.view('service/service_log', data2);
        });
    });

})();
<commit_msg>Stupid typo breaking yunopaste for service logs<commit_after>(function() {
    // Get application context
    var app = Sammy.apps['#main'];
    var store = app.store;

    /**
     * Services
     *
     */

    // All services status
    app.get('#/services', function (c) {
        c.api('GET', '/services', {}, function(data) {
            var data2 = {
                services: []
            };
            $.each(data, function(k, v) {
                v.name = k;
                if (v.last_state_change == 'unknown')
                {
                    v.last_state_change = 0;
                }
                data2.services.push(v);
            });

            data2.services.sort(function (a, b) {
                if (a.name > b.name) {
                    return 1;
                }
                else if (a.name < b.name) {
                    return -1;
                }
                return 0;
            });

            c.view('service/service_list', data2);
        });
    });

    // Status & actions for a service
    app.get('#/services/:service', function (c) {
        c.api('GET', '/services/'+ c.params['service'], {}, function(data) {
        c.api('GET', '/services/'+ c.params['service'] +'/log', {number: 50}, function(data_log) {

            data.name = c.params['service'];
            if (data.last_state_change == 'unknown')
            {
                data.last_state_change = 0;
            }

            data.logs = [];
            $.each(data_log, function(k, v) {
                data.logs.push({filename: k, filecontent: v.join('\n')});
            });

            // Sort logs by filename, put the journalctl/systemd log on top
            data.logs.sort(function(a,b) { return a.filename === "journalctl" ? -1 : b.filename === "journalctl" ? 1 : a.filename < b.filename ? -1 : a.filename > b.filename ? 1 : 0; });

            c.view('service/service_info', data, function() {

                // Don't allow user to stop critical services from the webadmin
                $('button[data-action="stop"]').each(function() {

                    var critical = ['nginx', 'ssh', 'slapd', 'yunohost-api'];
                    var service = $(this).data('service');

                    if (critical.indexOf(service) >= 0)
                    {
                        $(this).hide();
                    }
                });

                // Configure behavior for enable/disable and start/stop buttons
                $('button[data-action="start"], button[data-action="restart"], button[data-action="stop"]').on('click', function() {

                    var service = $(this).data('service');
                    var action = $(this).data('action');

                    c.confirm(y18n.t("services"), y18n.t('confirm_service_' + action, [service]), function(){

                        if (action == "start")
                        {
                            var method = "PUT";
                            var url = "/services/" + service;
                        }
                        else if (action == "restart")
                        {
                            var method = "PUT";
                            var url = "/services/" + service + "/restart";
                        }
                        else
                        {
                            var method = "DELETE";
                            var url = "/services/" + service;
                        }
                        c.api(method, url, {}, function() { c.refresh(); });
                    });
                });

                // Configure behavior for enable/disable and start/stop buttons
                $('button[data-action="share"]').on('click', function() {

                    c.showLoader();

                    // Send to paste.yunohost.org
                    $.ajax({
                        type: "POST",
                        url: 'https://paste.yunohost.org/documents',
                        data: $("#logs").text(),
                    })
                    .done(function(data, textStatus, jqXHR) {
                        window.open('https://paste.yunohost.org/' + data.key, '_blank');
                    })
                    .fail(function() {
                        c.flash('fail', y18n.t('paste_error'));
                    })
                    .always(function(){
                        c.hideLoader();
                    });
                });
            });
        });
        });
    });

    // Service log
    app.get('#/services/:service/log', function (c) {
        var params = {
            number: 50
        };
        c.api('GET', '/services/'+ c.params['service'] +'/log', params, function(data) { // ?
            data2 = { 'logs': [], 'name': c.params['service'] };
            $.each(data, function(k, v) {
                data2.logs.push({filename: k, filecontent: v.join('\n')});
            });

            c.view('service/service_log', data2);
        });
    });

})();

{'fraction_non_alphanumeric': 0.15401584277549382, 'fraction_numerical': 0.005615160934523212, 'mean_word_length': 1.1082223631367576, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4809941', 'n_tokens_mistral': 2696, 'n_tokens_neox': 2493, 'n_words': 512}