<commit_before>define([
    'jquery',
    'fancytree',
    'underscore',
    'backbone',
    'app',
    'collections/navigationtree/NavigationTreeCollection',
    'views/navigationtree/NavigationTreeView'
], function($, fancytree, _, Backbone, app, NavigationTreeCollection, NavigationTreeView) {

    var NavigationTreeView = Backbone.View.extend({

        initialize: function(options) {
            _.bindAll(this, 'render', 'convertToTree', 'getNodeTitle');

            this.projectId = 0;

            if (typeof options !== typeof undefined && typeof options.draggable !== typeof undefined) {
                this.draggable = options.draggable;
            } else {
                this.draggable = false;
            }

            this.collection = new NavigationTreeCollection();
            //this.listenTo(this.collection, 'reset', this.render);

            this.$el.attr('id', 'navigation-tree');
            this.$el.attr('class', 'ui list');
        },

        events: {

        },

        getNodeTitle: function(node, parent) {
            var url = '/#/projects/' + this.projectId + '/testsuites/';
            if (parseInt(node.node_type_id) === 2) {
                url += node.node_id + '/view';
            } else {
                url += parent.node_id + '/testcases/' + node.node_id + '/view';
            }
            var title = "<a href='" + url + "'>" + node.display_name + "</a>";
            return title;
        },

        convertToTree: function(parent, children) {
            for (idx in children) {
                var child = children[idx];
                var folder = parseInt(child.node_type_id) === 3 ? false : true;
                var node = {
                    title: this.getNodeTitle(child, parent),
                    key: child.descendant,
                    folder: folder,
                    expanded: true,
                    children: [],
                    node_id: child.node_id,
                    node_type_id: child.node_type_id
                };
                parent.children.push(node);
                this.convertToTree(node, child.children);
            }
        },

        render: function() {
            console.log('Rendering navigation tree for project ID [' + this.projectId + ']');
            var self = this;
            this.collection.setProjectId(this.projectId);
            this.collection.fetch({
                reset: true,
                success: function(results) {
                    var models = self.collection.models;
                    var model = null;
                    if (models.length > 0) {
                        model = models[0].toJSON();
                    }

                    tree = [];
                    var node = {
                        title: '<a href="/#/specification">' + model.display_name + '</a>',
                        key: model.descendant,
                        folder: true,
                        expanded: true,
                        children: [],
                        node_id: model.node_id,
                        node_type_id: model.node_type_id
                    };
                    self.convertToTree(node, model.children);
                    tree.push(node);

                    var data = {
                        project_id: self.projectId
                    };

                    // enable drag and drop
                    if (self.draggable) {
                        self.$el.fancytree({
                            source: tree,
                            extensions: ["dnd"],
                            activeVisible: true, // Make sure, active nodes are visible (expanded).
                            aria: false, // Enable WAI-ARIA support.
                            autoActivate: true, // Automatically activate a node when it is focused (using keys).
                            autoCollapse: false, // Automatically collapse all siblings, when a node is expanded.
                            autoScroll: false, // Automatically scroll nodes into visible area.
                            clickFolderMode: 1, // 1:activate, 2:expand, 3:activate and expand, 4:activate (dblclick expands)
                            checkbox: false, // Show checkboxes.
                            debugLevel: 1, // 0:quiet, 1:normal, 2:debug
                            disabled: false, // Disable control
                            generateIds: false, // Generate id attributes like <span id='fancytree-id-KEY'>
                            idPrefix: "ft_", // Used to generate node id´s like <span id='fancytree-id-<key>'>.
                            icon: true, // Display node icons.
                            keyboard: true, // Support keyboard navigation.
                            keyPathSeparator: "/", // Used by node.getKeyPath() and tree.loadKeyPath().
                            minExpandLevel: 2, // 1: root node is not collapsible
                            selectMode: 1, // 1:single, 2:multi, 3:multi-hier
                            tabindex: 0, // Whole tree behaves as one single control
                            childcounter: {
                                deep: true,
                                hideZeros: true,
                                hideExpanded: true
                            },
                            focus: function(e, data) {
                                var node = data.node;
                                // Auto-activate focused node after 1 second
                                if(node.data.href){
                                    node.scheduleAction("activate", 100000);
                                }
                            },
                            blur: function(e, data) {
                                data.node.scheduleAction("cancel");
                            },
                            activate: function(e, data) {
                                if (data.draggable)
                                    return; // prevent false hits
                                var node = data.node;
                                if(node.data.href){
                                    window.open(node.data.href, node.data.target);
                                }
                            },
                            click: function(e, data) { // allow re-loads
                                var node = data.node;
                                if(node.isActive() && node.data.href){
                                    // TODO: data.tree.reactivate();
                                }
                            },
                            dnd: {
                                preventVoidMoves: true, // Prevent dropping nodes 'before self', etc.
                                preventRecursiveMoves: true, // Prevent dropping nodes on own descendants
                                autoExpandMS: 400,
                                dragStart: function(node, data) {
                                    // Defines whether this node is draggable or not
                                    // The top level project should have dnd disabled
                                    if (node.data.node_type_id == 1) { <commit_msg>Use activate and data.href instead of a link with the display name for FancyTree<commit_after>define([
    'jquery',
    'fancytree',
    'underscore',
    'backbone',
    'app',
    'collections/navigationtree/NavigationTreeCollection',
    'views/navigationtree/NavigationTreeView'
], function($, fancytree, _, Backbone, app, NavigationTreeCollection, NavigationTreeView) {

    var NavigationTreeView = Backbone.View.extend({

        initialize: function(options) {
            _.bindAll(this, 'render', 'convertToTree', 'getNodeHref');

            this.projectId = 0;

            if (typeof options !== typeof undefined && typeof options.draggable !== typeof undefined) {
                this.draggable = options.draggable;
            } else {
                this.draggable = false;
            }

            this.collection = new NavigationTreeCollection();
            //this.listenTo(this.collection, 'reset', this.render);

            this.$el.attr('id', 'navigation-tree');
            this.$el.attr('class', 'ui list');
        },

        events: {

        },

        getNodeHref: function(node, parent) {
            var url = '/#/projects/' + this.projectId + '/testsuites/';
            if (parseInt(node.node_type_id) === 2) {
                url += node.node_id + '/view';
            } else {
                url += parent.node_id + '/testcases/' + node.node_id + '/view';
            }
            //var title = "<a href='" + url + "'>" + node.display_name + "</a>";
            return url;
        },

        convertToTree: function(parent, children) {
            for (idx in children) {
                var child = children[idx];
                var folder = parseInt(child.node_type_id) === 3 ? false : true;
                var node = {
                    title: child.display_name,
                    key: child.descendant,
                    folder: folder,
                    expanded: true,
                    children: [],
                    node_id: child.node_id,
                    node_type_id: child.node_type_id,
                    href: this.getNodeHref(child, parent),
                };
                parent.children.push(node);
                this.convertToTree(node, child.children);
            }
        },

        render: function() {
            console.log('Rendering navigation tree for project ID [' + this.projectId + ']');
            var self = this;
            this.collection.setProjectId(this.projectId);
            this.collection.fetch({
                reset: true,
                success: function(results) {
                    var models = self.collection.models;
                    var model = null;
                    if (models.length > 0) {
                        model = models[0].toJSON();
                    }

                    tree = [];
                    var node = {
                        title: model.display_name,
                        key: model.descendant,
                        folder: true,
                        expanded: true,
                        children: [],
                        node_id: model.node_id,
                        node_type_id: model.node_type_id,
                        href: '/#/specification'
                    };
                    self.convertToTree(node, model.children);
                    tree.push(node);

                    var data = {
                        project_id: self.projectId
                    };

                    // enable drag and drop
                    if (self.draggable) {
                        self.$el.fancytree({
                            source: tree,
                            extensions: ["dnd"],
                            activeVisible: true, // Make sure, active nodes are visible (expanded).
                            aria: false, // Enable WAI-ARIA support.
                            autoActivate: true, // Automatically activate a node when it is focused (using keys).
                            autoCollapse: false, // Automatically collapse all siblings, when a node is expanded.
                            autoScroll: false, // Automatically scroll nodes into visible area.
                            clickFolderMode: 1, // 1:activate, 2:expand, 3:activate and expand, 4:activate (dblclick expands)
                            checkbox: false, // Show checkboxes.
                            debugLevel: 1, // 0:quiet, 1:normal, 2:debug
                            disabled: false, // Disable control
                            generateIds: false, // Generate id attributes like <span id='fancytree-id-KEY'>
                            idPrefix: "ft_", // Used to generate node id´s like <span id='fancytree-id-<key>'>.
                            icon: true, // Display node icons.
                            keyboard: true, // Support keyboard navigation.
                            keyPathSeparator: "/", // Used by node.getKeyPath() and tree.loadKeyPath().
                            minExpandLevel: 2, // 1: root node is not collapsible
                            selectMode: 1, // 1:single, 2:multi, 3:multi-hier
                            tabindex: 0, // Whole tree behaves as one single control
                            childcounter: {
                                deep: true,
                                hideZeros: true,
                                hideExpanded: true
                            },
                            focus: function(e, data) {
                                var node = data.node;
                                // Auto-activate focused node after 1 second
                                if(node.data.href){
                                    node.scheduleAction("activate", 100000);
                                }
                            },
                            blur: function(e, data) {
                                data.node.scheduleAction("cancel");
                            },
                            activate: function(e, data) {
                                if (data.draggable)
                                    return; // prevent false hits
                                var node = data.node;
                                if(node.data.href){
                                    window.location.href = node.data.href;
                                }
                            },
                            click: function(e, data) { // allow re-loads
                                var node = data.node;
                                if(node.isActive() && node.data.href){
                                    // TODO: data.tree.reactivate();
                                }
                            },
                            dnd: {
                                preventVoidMoves: true, // Prevent dropping nodes 'before self', etc.
                                preventRecursiveMoves: true, // Prevent dropping nodes on own descendants
                                autoExpandMS: 400,
                                dragStart: function(node, data) {
                                    // Defines whether this node is draggable or not
                                    // The top level project should have dnd disabled
                                    if (node.data.node_type_id == 1) { 
{'fraction_non_alphanumeric': 0.09392189218921893, 'fraction_numerical': 0.0044004400440044, 'mean_word_length': 1.00454796030871, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 30, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6982160', 'n_tokens_mistral': 3441, 'n_tokens_neox': 3191, 'n_words': 812}