<commit_before>/*
 * This file is part of Cockpit.
 *
 * Copyright (C) 2013 Red Hat, Inc.
 *
 * Cockpit is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * Cockpit is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with Cockpit; If not, see <http://www.gnu.org/licenses/>.
 */

var $cockpit = $cockpit || { };

(function($, $cockpit, cockpit_pages) {

var docker_clients = { };

function resource_debug() {
    if ($cockpit.debugging == "all" || $cockpit.debugging == "resource")
        console.debug.apply(console, arguments);
}

function docker_debug() {
    if ($cockpit.debugging == "all" || $cockpit.debugging == "docker")
        console.debug.apply(console, arguments);
}

function get_docker_client(machine) {
    if (!machine)
        machine = cockpit_get_page_param ("machine", "server");
    if (!docker_clients[machine])
        docker_clients[machine] = new DockerClient (machine);
    return docker_clients[machine];
}

function cockpit_quote_cmdline (cmds) {
    function quote(arg) {
        return arg.replace(/\\/g, '\\\\').replace(/ /g, '\\ ');
    }
    return cmds? cmds.map(quote).join(' ') : "";
}

function cockpit_unquote_cmdline (string) {
    function shift(str) {
        return string.replace(/\\ /g, '\u0001').replace(/\\\\/g, '\u0002');
    }
    function unshift(str) {
        return str.replace(/\u0001/g, ' ').replace(/\u0002/g, '\\');
    }

    return shift(string).split(' ').map(unshift);
}

function cockpit_render_container_name (name) {
    if (name.length > 0 && name[0] == "/")
        return name.slice(1);
    else
        return name;
}

function cockpit_render_container_state (state) {
    if (state.Running)
        return F(_("Up since %{StartedAt}"), state);
    else
        return F(_("Exited %{ExitCode}"), state);
}

function multi_line(strings) {
    return strings.map(cockpit_esc).join('<br/>');
}

function insert_table_sorted(table, row) {
    var key = $(row).text();
    var rows = $(table).find("tbody tr");
    for (var j = 0; j < rows.length; j++) {
        if ($(rows[j]).text().localeCompare(key) > 0) {
            $(row).insertBefore(rows[j]);
            row = null;
            break;
        }
    }
    if (row !== null)
        $(table).find("tbody").append(row);
}

PageContainers.prototype = {
    _init: function() {
        this.id = "containers";
    },

    getTitle: function() {
        return C_("page-title", "Containers");
    },

    enter: function(first_visit) {
        var self = this;

        if (first_visit) {
            this.container_filter_btn =
                cockpit_select_btn($.proxy(this, "filter"),
                                   [ { title: _("All"),                 choice: 'all',  is_default: true },
                                     { title: _("Running"),             choice: 'running' }
                                   ]);
            $('#containers-containers .panel-heading span').append(this.container_filter_btn);
        }

        var client = get_docker_client();
        if (client != this.client) {
            if (this.client)
                this.client.off('.containers');
            if (this.cpu_plot)
                this.cpu_plot.stop();
            if (this.mem_plot)
                this.mem_plot.stop();

            var reds = [ "#5c080c",
                         "#970911",
                         "#ce0e15",
                         "#ef2930",
                         "#f36166",
                         "#f7999c",
                         "#fbd1d2"
                       ];

            var blues = [ "#004778",
                          "#006bb4",
                          "#008ff0",
                          "#2daaff",
                          "#69c2ff",
                          "#a5daff",
                          "#e1f3ff"
                        ];

            this.client = client;

            function highlight_container_row(event, id) {
                $('#containers-containers tr').removeClass('highlight');
                $('#' + id).addClass('highlight');
            }

            this.cpu_plot = client.setup_cgroups_plot ('#containers-cpu-graph', 4, blues);
            $(this.cpu_plot).on('update-total', function (event, total) {
                $('#containers-cpu-text').text(total+"%");
            });
            $(this.cpu_plot).on('highlight', highlight_container_row);

            this.mem_plot = client.setup_cgroups_plot ('#containers-mem-graph', 0, reds);
            $(this.mem_plot).on('update-total', function (event, total) {
                $('#containers-mem-text').text(cockpit_format_bytes_pow2 (total));
            });
            $(this.mem_plot).on('highlight', highlight_container_row);

            $('#containers-containers table tbody tr').remove();
            $('#containers-images table tbody tr').remove();<commit_msg>web: Use blue for both container graphs.<commit_after>/*
 * This file is part of Cockpit.
 *
 * Copyright (C) 2013 Red Hat, Inc.
 *
 * Cockpit is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * Cockpit is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with Cockpit; If not, see <http://www.gnu.org/licenses/>.
 */

var $cockpit = $cockpit || { };

(function($, $cockpit, cockpit_pages) {

var docker_clients = { };

function resource_debug() {
    if ($cockpit.debugging == "all" || $cockpit.debugging == "resource")
        console.debug.apply(console, arguments);
}

function docker_debug() {
    if ($cockpit.debugging == "all" || $cockpit.debugging == "docker")
        console.debug.apply(console, arguments);
}

function get_docker_client(machine) {
    if (!machine)
        machine = cockpit_get_page_param ("machine", "server");
    if (!docker_clients[machine])
        docker_clients[machine] = new DockerClient (machine);
    return docker_clients[machine];
}

function cockpit_quote_cmdline (cmds) {
    function quote(arg) {
        return arg.replace(/\\/g, '\\\\').replace(/ /g, '\\ ');
    }
    return cmds? cmds.map(quote).join(' ') : "";
}

function cockpit_unquote_cmdline (string) {
    function shift(str) {
        return string.replace(/\\ /g, '\u0001').replace(/\\\\/g, '\u0002');
    }
    function unshift(str) {
        return str.replace(/\u0001/g, ' ').replace(/\u0002/g, '\\');
    }

    return shift(string).split(' ').map(unshift);
}

function cockpit_render_container_name (name) {
    if (name.length > 0 && name[0] == "/")
        return name.slice(1);
    else
        return name;
}

function cockpit_render_container_state (state) {
    if (state.Running)
        return F(_("Up since %{StartedAt}"), state);
    else
        return F(_("Exited %{ExitCode}"), state);
}

function multi_line(strings) {
    return strings.map(cockpit_esc).join('<br/>');
}

function insert_table_sorted(table, row) {
    var key = $(row).text();
    var rows = $(table).find("tbody tr");
    for (var j = 0; j < rows.length; j++) {
        if ($(rows[j]).text().localeCompare(key) > 0) {
            $(row).insertBefore(rows[j]);
            row = null;
            break;
        }
    }
    if (row !== null)
        $(table).find("tbody").append(row);
}

PageContainers.prototype = {
    _init: function() {
        this.id = "containers";
    },

    getTitle: function() {
        return C_("page-title", "Containers");
    },

    enter: function(first_visit) {
        var self = this;

        if (first_visit) {
            this.container_filter_btn =
                cockpit_select_btn($.proxy(this, "filter"),
                                   [ { title: _("All"),                 choice: 'all',  is_default: true },
                                     { title: _("Running"),             choice: 'running' }
                                   ]);
            $('#containers-containers .panel-heading span').append(this.container_filter_btn);
        }

        var client = get_docker_client();
        if (client != this.client) {
            if (this.client)
                this.client.off('.containers');
            if (this.cpu_plot)
                this.cpu_plot.stop();
            if (this.mem_plot)
                this.mem_plot.stop();

            var reds = [ "#250304",
                         "#5c080c",
                         "#970911",
                         "#ce0e15",
                         "#ef2930",
                         "#f36166",
                         "#f7999c",
                         "#fbd1d2"
                       ];

            var blues = [ "#00243c",
                          "#004778",
                          "#006bb4",
                          "#008ff0",
                          "#2daaff",
                          "#69c2ff",
                          "#a5daff",
                          "#e1f3ff"
                        ];

            this.client = client;

            function highlight_container_row(event, id) {
                $('#containers-containers tr').removeClass('highlight');
                $('#' + id).addClass('highlight');
            }

            this.cpu_plot = client.setup_cgroups_plot ('#containers-cpu-graph', 4, blues.concat(blues));
            $(this.cpu_plot).on('update-total', function (event, total) {
                $('#containers-cpu-text').text(total+"%");
            });
            $(this.cpu_plot).on('highlight', highlight_container_row);

            this.mem_plot = client.setup_cgroups_plot ('#containers-mem-graph', 0, blues.concat(blues));
            $(this.mem_plot).on('update-total', function (event, total) {
                $('#containers-mem-text').text(cockpit_format_bytes_pow2 (total));
            });
            $(this.mem_plot).on('highlight', highlight_container_row);

            $('#containers-containers table tbody tr').remove();
            $('#containers-images table tbody tr').remove();
{'fraction_non_alphanumeric': 0.14598676237531463, 'fraction_numerical': 0.015754637829775334, 'mean_word_length': 1.9049553208773355, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2612528', 'n_tokens_mistral': 3219, 'n_tokens_neox': 3031, 'n_words': 707}