<commit_before>// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program 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 General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
define([
    'jquery',
    'utils/init',
    'utils/base',
    'utils/error',
    'utils/request',
    'utils/tables',
    'sprintf'
], function($, i, b, e, r, t, p) {
    'use strict';
    var searchFilter = null,
        pageLen = null,
        bootsTable = null,
        dateRange = 14,
        eDiv,
        rowURLFmt,
        hrefFmt,
        bootAllUrl;

    eDiv = '<div class="pull-center"><h4>%s</h4></div>';
    rowURLFmt = '/boot/%(board)s/job/%(job)s/kernel/%(kernel)s' +
        '/defconfig/%(defconfig_full)s/lab/%(lab_name)s/';
    bootAllUrl = '/boot/all/%s';
    hrefFmt = '<a class="table-link" href="%s">%s</a>';

    function getBootsFail() {
        b.replaceById('table-loading', p.sprintf(eDiv, 'Error loading data.'));
    }

    function getBootsDone(response) {
        var results = response.result,
            len = results.length,
            tableDiv,
            columns;

        if (len === 0) {
            tableDiv = b.checkElement('table-div');
            b.replaceById(
                tableDiv[0], p.sprintf(eDiv, 'No boots data available.'));
        } else {
            columns = [
                {
                    'data': '_id',
                    'visible': false,
                    'searchable': false,
                    'orderable': false
                },
                {
                    'data': 'job',
                    'title': 'Tree &dash; Branch',
                    'type': 'string',
                    'className': 'tree-column',
                    'render': function(data, type, object) {
                        var display,
                            hrefData,
                            branch = object.git_branch;

                        hrefData = data;
                        if (branch !== null && branch !== undefined) {
                            hrefData = data + '&nbsp;&dash;&nbsp;<small>' +
                                branch + '</small>';
                        }
                        display = p.sprintf(
                            hrefFmt, p.sprintf(bootAllUrl, data), hrefData);

                        return display;
                    }
                },
                {
                    'data': 'kernel',
                    'title': 'Kernel',
                    'type': 'string',
                    'className': 'kernel-column',
                    'render': function(data, type, object) {
                        var display = '<span rel="tooltip" ' +
                            'data-toggle="tooltip" title="' + data + '">' +
                            '<a class="table-link" href="/boot/all/job/' +
                            object.job + '/kernel/' + data + '/">' + data +
                            '</a></span>';
                        return display;
                    }
                },
                {
                    'data': 'board',
                    'title': 'Board Model',
                    'type': 'string',
                    'className': 'board-column',
                    'render': function(data, type, object) {
                        var display = '<span rel="tooltip" ' +
                            'data-toggle="tooltip" title="' + data + '">' +
                            '<a class="table-link" href="/boot/' + data +
                            '/job/' + object.job + '/kernel/' +
                            object.kernel + '/">' + data + '</a></span>';
                        return display;
                    }
                },
                {
                    'data': 'defconfig_full',
                    'title': 'Defconfig',
                    'className': 'defconfig-column',
                    'render': function(data, type, object) {
                        var display = null,
                            href = null,
                            board = object.board,
                            job = object.job,
                            kernel = object.kernel;

                        href = '/boot/' + board + '/job/' + job + '/kernel/' +
                            kernel + '/defconfig/' + data + '/';
                        display = '<span rel="tooltip" ' +
                            'data-toggle="tooltip" ' +
                            'title="' + data + '">' +
                            '<a class="table-link" href="' + href + '">' +
                            data + '</a></span>';
                        return display;
                    }
                },
                {
                    'data': 'arch',
                    'title': 'Arch.',
                    'type': 'string'
                },
                {
                    'data': 'lab_name',
                    'title': 'Lab Name',
                    'className': 'lab-column',
                    'render': function(data) {
                        return '<small>' + data + '</small>';
                    }
                },
                {
                    'data': 'created_on',
                    'title': 'Date',
                    'type': 'date',
                    'className': 'date-column pull-center',
                    'render': function(data) {
                        var created = new Date(data.$date);
                        return created.getCustomISODate();
                    }
                },
                {
                    'data': 'status',
                    'title': 'Status',
                    'type': 'string',
                    'className': 'pull-center',
                    'render': function(data) {
                        var displ;
                        switch (data) {
                            case 'PASS':
                                displ = '<span rel="tooltip" ' +
                                    'data-toggle="tooltip"' +
                                    'title="Boot completed">' +
                                    '<span class="label label-success">' +
                                    '<i class="fa fa-check"></i></span></span>';
                                break;
                            case 'FAIL':
                                displ = '<span rel="tooltip" ' +
                                    'data-toggle="tooltip"' +
                                    'title="Boot failed">' +
                                    '<span class="label label-danger">' +
                                    '<i class="fa fa-exclamation-triangle">' +
                                    '</i></span></span>';
                                break;
                            case 'OFFLINE':
                                displ = '<span rel="tooltip"' +
                                    'data-toggle="tooltip"' +
                                    'title="Board offline"' +
                                    '<span class="label label-info">' +
                                    '<i class="fa fa-power-off">' +
                                    '</i></span></span>';
                                break;
                            default:
                                displ = '<span rel="tooltip" ' +
                                    'data-toggle="tooltip"' +
                                    'title="Unknown status">' +
                                    '<span class="label label-warning">' +
                                    '<i class="fa fa-question">' +
                                    '</i></span></span>';
                                break;<commit_msg>Clean up code on all boots view.<commit_after>// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program 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 General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
define([
    'jquery',
    'utils/init',
    'utils/base',
    'utils/error',
    'utils/request',
    'utils/tables',
    'sprintf'
], function($, i, b, e, r, t, p) {
    'use strict';
    var searchFilter = null,
        pageLen = null,
        bootsTable = null,
        dateRange = 14,
        eDiv,
        rowURLFmt,
        hrefFmt,
        bootAllUrl,
        bootAllJKUrl,
        bootBoardJKUrl,
        bootDefconfigUrl,
        tooltipFmt,
        successLabel,
        failLabel,
        offlineLabel,
        unknownLabel;

    eDiv = '<div class="pull-center"><h4>%s</h4></div>';
    rowURLFmt = '/boot/%(board)s/job/%(job)s/kernel/%(kernel)s' +
        '/defconfig/%(defconfig_full)s/lab/%(lab_name)s/';
    bootAllUrl = '/boot/all/job/%s/';
    bootAllJKUrl = '/boot/all/job/%s/kernel/%s/';
    bootBoardJKUrl = '/boot/%s/job/%s/kernel/%s/';
    bootDefconfigUrl = '/boot/%s/job/%s/kernel/%s/defconfig/%s/';
    hrefFmt = '<a class="table-link" href="%s">%s</a>';
    tooltipFmt = '<span rel="tooltip" data-toggle="tooltip" ' +
        'title="%s">%s</span>';
    successLabel = '<span rel="tooltip" data-toggle="tooltip" ' +
        'title="Boot completed"><span class="label label-success">' +
        '<i class="fa fa-check"></i></span></span>';
    failLabel = '<span rel="tooltip" data-toggle="tooltip"' +
        'title="Boot failed"> <span class="label label-danger">' +
        '<i class="fa fa-exclamation-triangle"></i></span></span>';
    offlineLabel = '<span rel="tooltip" data-toggle="tooltip"' +
        'title="Board offline" <span class="label label-info">' +
        '<i class="fa fa-power-off"></i></span></span>';
    unknownLabel = '<span rel="tooltip" data-toggle="tooltip"' +
        'title="Unknown status"><span class="label label-warning">' +
        '<i class="fa fa-question"></i></span></span>';

    function getBootsFail() {
        b.replaceById('table-loading', p.sprintf(eDiv, 'Error loading data.'));
    }

    function getBootsDone(response) {
        var results = response.result,
            len = results.length,
            tableDiv,
            columns;

        if (len === 0) {
            tableDiv = b.checkElement('table-div');
            b.replaceById(
                tableDiv[0], p.sprintf(eDiv, 'No boots data available.'));
        } else {
            columns = [
                {
                    'data': '_id',
                    'visible': false,
                    'searchable': false,
                    'orderable': false
                },
                {
                    'data': 'job',
                    'title': 'Tree &dash; Branch',
                    'type': 'string',
                    'className': 'tree-column',
                    'render': function(data, type, object) {
                        var display,
                            hrefData,
                            tTitle,
                            branch = object.git_branch;

                        hrefData = data;
                        tTitle = data;
                        if (branch !== null && branch !== undefined) {
                            tTitle = data + '&nbsp;&dash;&nbsp;' + branch;
                            hrefData = data + '&nbsp;&dash;&nbsp;<small>' +
                                branch + '</small>';
                        }
                        display = p.sprintf(
                            tooltipFmt,
                            tTitle,
                            p.sprintf(
                                hrefFmt,
                                p.sprintf(bootAllUrl, data), hrefData)
                        );

                        return display;
                    }
                },
                {
                    'data': 'kernel',
                    'title': 'Kernel',
                    'type': 'string',
                    'className': 'kernel-column',
                    'render': function(data, type, object) {
                        var display = p.sprintf(
                            tooltipFmt,
                            data,
                            p.sprintf(
                                hrefFmt,
                                p.sprintf(bootAllJKUrl, object.job, data),
                                data)
                        );
                        return display;
                    }
                },
                {
                    'data': 'board',
                    'title': 'Board Model',
                    'type': 'string',
                    'className': 'board-column',
                    'render': function(data, type, object) {
                        var display = p.sprintf(
                            tooltipFmt,
                            data,
                            p.sprintf(
                                hrefFmt,
                                p.sprintf(
                                    bootBoardJKUrl,
                                    data,
                                    object.job,
                                    object.kernel),
                                data
                            )
                        );
                        return display;
                    }
                },
                {
                    'data': 'defconfig_full',
                    'title': 'Defconfig',
                    'className': 'defconfig-column',
                    'render': function(data, type, object) {
                        var display = null,
                            href = null,
                            board = object.board,
                            job = object.job,
                            kernel = object.kernel;

                        href = p.sprintf(
                            bootDefconfigUrl, board, job, kernel, data);
                        display = p.sprintf(
                            tooltipFmt,
                            data,
                            p.sprintf(hrefFmt, href, data)
                        );
                        return display;
                    }
                },
                {
                    'data': 'arch',
                    'title': 'Arch.',
                    'type': 'string'
                },
                {
                    'data': 'lab_name',
                    'title': 'Lab Name',
                    'className': 'lab-column',
                    'render': function(data) {
                        return '<small>' + data + '</small>';
                    }
                },
                {
                    'data': 'created_on',
                    'title': 'Date',
                    'type': 'date',
                    'className': 'date-column pull-center',
                    'render': function(data) {
                        var created = new Date(data.$date);
                        return created.getCustomISODate();
                    }
                },
                {
                    'data': 'status',
                    'title': 'Status',
                    'type': 'string',
                    'className': 'pull-center',
                    'render': function(data) {
                        var displ;
                        switch (data) {
                            case 'PASS':
                                displ = successLabel;
                                break;
                            case 'FAIL':
                                displ = failLabel;
                                break;
                            case 'OFFLINE':
                                displ = offlineLabel;
                                break;
                            default:
                                displ = unknownLabel;
                                break;
{'fraction_non_alphanumeric': 0.1212029893924783, 'fraction_numerical': 0.0008437801350048216, 'mean_word_length': 0.9078992756122801, 'pattern_counts': {'":': 0, '<': 87, '<?xml version=': 0, '>': 85, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 23, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6951043', 'n_tokens_mistral': 3970, 'n_tokens_neox': 3749, 'n_words': 894}