<commit_before>/*
 #
 # Copyright (c) 2017 nexB Inc. and others. All rights reserved.
 # https://nexb.com and https://github.com/nexB/scancode-toolkit/
 # The ScanCode software is licensed under the Apache License version 2.0.
 # AboutCode is a trademark of nexB Inc.
 #
 # You may not use this software except in compliance with the License.
 # You may obtain a copy of the License at: http://apache.org/licenses/LICENSE-2.0
 # Unless required by applicable law or agreed to in writing, software distributed
 # under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
 # CONDITIONS OF ANY KIND, either express or implied. See the License for the
 # specific language governing permissions and limitations under the License.
 #
 */

const HAS_A_VALUE =  "about_code_data_table_has_a_value";
const shell = require("electron").shell;

class AboutCodeDataTable {
    constructor(tableId, aboutCodeDB) {
        this.tableId = tableId;
        this.aboutCodeDB = aboutCodeDB;
        this.dataTable = this._createDataTable(tableId);
    }

    database(aboutCodeDB) {
        this.aboutCodeDB = aboutCodeDB;
    }

    draw() {
        return this.dataTable.draw();
    }

    rows() {
        return this.dataTable.rows();
    }

    columns(columnId) {
        return this.dataTable.columns(columnId);
    }

    reload() {
        return this.dataTable.ajax.reload();
    }

    clearColumnFilters() {
        $.each(AboutCodeDataTable.TABLE_COLUMNS, (i, column) => {
            const columnSelect = $(`select#clue-${column.name}`);
            columnSelect.val("");
            this.dataTable
                .column(`${column.name}:name`)
                .search("", false, false);
        });
    }

    setColumnFilter(columnName, value) {
        // Get the clue table column and make sure it's visible
        const column = this.dataTable.column(`${columnName}:name`);
        column.visible(true);

        // Get the column's filter select box
        const select = $(`select#clue-${columnName}`);
        select.empty().append(`<option value=""></option>`);

        // Add the chart value options and select it.
        select.append(`<option value="${value}">${value}</option>`);
        select.val(value).change();
    }

    // This function is called every time DataTables needs to be redrawn.
    // For details on the parameters https://datatables.net/manual/server-side
    _query(dataTablesInput, dataTablesCallback) {
        // Sorting and Querying of data for DataTables
        this.aboutCodeDB.db.then(() => {
            let columnIndex = dataTablesInput.order[0].column;
            let columnName = dataTablesInput.columns[columnIndex].name;
            let direction = dataTablesInput.order[0].dir === "desc" ? "DESC" : "ASC";

            // query = {
            //   where: {
            //     $and: {
            //       path: { $like: "columnSearch%" },
            //       $or: [
            //         { path: { $like: "globalSearch%" } },
            //         { copyright_statements: { $like: "globalSearch%" } },
            //         ...,
            //       ]
            //     }
            //   }
            // }
            let query = {
                where: {
                    $and: {}
                },
                // Only take the chunk of data DataTables needs
                limit: dataTablesInput.length,
                offset: dataTablesInput.start,
                order: [[columnName, direction]]
            };

            // If a column search exists, add search for that column
            for (let i = 0; i < dataTablesInput.columns.length; i++) {
                let columnSearch = dataTablesInput.columns[i].search.value;
                if (columnSearch) {<commit_msg>Fix Table View display order #134<commit_after>/*
 #
 # Copyright (c) 2017 nexB Inc. and others. All rights reserved.
 # https://nexb.com and https://github.com/nexB/scancode-toolkit/
 # The ScanCode software is licensed under the Apache License version 2.0.
 # AboutCode is a trademark of nexB Inc.
 #
 # You may not use this software except in compliance with the License.
 # You may obtain a copy of the License at: http://apache.org/licenses/LICENSE-2.0
 # Unless required by applicable law or agreed to in writing, software distributed
 # under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
 # CONDITIONS OF ANY KIND, either express or implied. See the License for the
 # specific language governing permissions and limitations under the License.
 #
 */

const HAS_A_VALUE =  "about_code_data_table_has_a_value";
const shell = require("electron").shell;

class AboutCodeDataTable {
    constructor(tableId, aboutCodeDB) {
        this.tableId = tableId;
        this.aboutCodeDB = aboutCodeDB;
        this.dataTable = this._createDataTable(tableId);
    }

    database(aboutCodeDB) {
        this.aboutCodeDB = aboutCodeDB;
    }

    draw() {
        return this.dataTable.draw();
    }

    rows() {
        return this.dataTable.rows();
    }

    columns(columnId) {
        return this.dataTable.columns(columnId);
    }

    reload() {
        return this.dataTable.ajax.reload();
    }

    clearColumnFilters() {
        $.each(AboutCodeDataTable.TABLE_COLUMNS, (i, column) => {
            const columnSelect = $(`select#clue-${column.name}`);
            columnSelect.val("");
            this.dataTable
                .column(`${column.name}:name`)
                .search("", false, false);
        });
    }

    setColumnFilter(columnName, value) {
        // Get the clue table column and make sure it's visible
        const column = this.dataTable.column(`${columnName}:name`);
        column.visible(true);

        // Get the column's filter select box
        const select = $(`select#clue-${columnName}`);
        select.empty().append(`<option value=""></option>`);

        // Add the chart value options and select it.
        select.append(`<option value="${value}">${value}</option>`);
        select.val(value).change();
    }

    // This function is called every time DataTables needs to be redrawn.
    // For details on the parameters https://datatables.net/manual/server-side
    _query(dataTablesInput, dataTablesCallback) {
        // Sorting and Querying of data for DataTables
        this.aboutCodeDB.db.then(() => {
            let columnIndex = dataTablesInput.order[0].column;
            let columnName = dataTablesInput.columns[columnIndex].name;
            let direction = dataTablesInput.order[0].dir === "desc" ? "DESC" : "ASC";

            // query = {
            //   where: {
            //     $and: {
            //       path: { $like: "columnSearch%" },
            //       $or: [
            //         { path: { $like: "globalSearch%" } },
            //         { copyright_statements: { $like: "globalSearch%" } },
            //         ...,
            //       ]
            //     }
            //   }
            // }
            let query = {
                where: {
                    $and: {}
                },
                // Only take the chunk of data DataTables needs
                limit: dataTablesInput.length,
                offset: dataTablesInput.start,
                order: `${columnName} COLLATE NOCASE ${direction}`
            };

            // If a column search exists, add search for that column
            for (let i = 0; i < dataTablesInput.columns.length; i++) {
                let columnSearch = dataTablesInput.columns[i].search.value;
                if (columnSearch) {
{'fraction_non_alphanumeric': 0.11961975178241352, 'fraction_numerical': 0.003300765777660417, 'mean_word_length': 1.9520654715510521, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 6, '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': '6702015', 'n_tokens_mistral': 2077, 'n_tokens_neox': 2005, 'n_words': 559}