<commit_before>/*
 #
 # Copyright (c) 2016 nexB Inc. and others. All rights reserved.
 # http://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 fs = require('fs');


$(document).ready(function () {
    // Create default values for all of the data and ui classes
    let aboutCodeDB = new AboutCodeDB();
    let nodeView = new AboutCodeNodeView("#node-view", aboutCodeDB);

    // These classes are only created once, otherwise DataTables will complain
    const cluesTable = new AboutCodeDataTable("#clues-table", aboutCodeDB);
    const componentsTable = new ComponentDataTable("#components-table", aboutCodeDB);

    // TODO: Move this into its own file
    // Create and setup the jstree, and the click-event logic
    const jstree = $("#jstree").jstree(
        {
            "core": {
                "data": function (currentDirectory, callback) {
                    aboutCodeDB
                        .findAllJSTree({
                            where: {
                                parent: currentDirectory.id
                            }
                        })
                        .then((children) => {
                            callback.call(this, children)
                        });
                }
            },
            "types": {
                "directory": {
                    "icon": "glyphicon glyphicon-folder-close"
                },
                "file": {
                    "icon": "glyphicon glyphicon-file"
                }
            },
            "plugins": [ "types","sort" ],
            'sort': function (a, b) {
                a1 = this.get_node(a);
                b1 = this.get_node(b);
                if (a1.type == b1.type) {
                    return a1.text.localeCompare(b1.text, 'en-US-u-kf-upper');
                }
                else {
                    return (a1.type === 'directory') ? -1 : 1;
                }
            }
        })
        .on('open_node.jstree', function (evt, data) {
            data.instance.set_icon(
                data.node,
                'glyphicon glyphicon-folder-open');
        })
        .on('close_node.jstree', function (evt, data) {
            data.instance.set_icon(
                data.node,
                'glyphicon glyphicon-folder-close');
        })
        // Get the node id when selected
        .on('select_node.jstree', function (evt, data) {<commit_msg>Add edit component feature to jstree #80<commit_after>/*
 #
 # Copyright (c) 2016 nexB Inc. and others. All rights reserved.
 # http://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 fs = require('fs');


$(document).ready(function () {
    // Create default values for all of the data and ui classes
    let aboutCodeDB = new AboutCodeDB();
    let nodeView = new AboutCodeNodeView("#node-view", aboutCodeDB);

    // These classes are only created once, otherwise DataTables will complain
    const cluesTable = new AboutCodeDataTable("#clues-table", aboutCodeDB);
    const componentsTable = new ComponentDataTable("#components-table", aboutCodeDB);

    // TODO: Move this into its own file
    // Create and setup the jstree, and the click-event logic
    const jstree = $("#jstree").jstree(
        {
            "core": {
                "data": function (currentDirectory, callback) {
                    aboutCodeDB
                        .findAllJSTree({
                            where: {
                                parent: currentDirectory.id
                            }
                        })
                        .then((children) => {
                            callback.call(this, children)
                        });
                }
            },
            "types": {
                "directory": {
                    "icon": "glyphicon glyphicon-folder-close"
                },
                "file": {
                    "icon": "glyphicon glyphicon-file"
                }
            },
            "plugins": [ "types", "sort", "contextmenu"],
            "sort": function (a, b) {
                a1 = this.get_node(a);
                b1 = this.get_node(b);
                if (a1.type == b1.type) {
                    return a1.text.localeCompare(b1.text, 'en-US-u-kf-upper');
                }
                else {
                    return (a1.type === 'directory') ? -1 : 1;
                }
            },
            "contextmenu" : {
                "items": function (node) {
                    return {
                        "edit_component": {
                            "label": "Edit Component",
                            "action": function () {
                                onNodeClick(node)
                            }
                        }
                    };
                }
            }
        })
        .on('open_node.jstree', function (evt, data) {
            data.instance.set_icon(
                data.node,
                'glyphicon glyphicon-folder-open');
        })
        .on('close_node.jstree', function (evt, data) {
            data.instance.set_icon(
                data.node,
                'glyphicon glyphicon-folder-close');
        })
        // Get the node id when selected
        .on('select_node.jstree', function (evt, data) {
{'fraction_non_alphanumeric': 0.10375173691523853, 'fraction_numerical': 0.00555812876331635, 'mean_word_length': 1.4556482183472328, 'pattern_counts': {'":': 21, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '5285407', 'n_tokens_mistral': 1700, 'n_tokens_neox': 1603, 'n_words': 488}