<commit_before>var Fangorn = require('fangorn');

var FileRenderer = require('../filerenderer.js');
var FileRevisions = require('../fileRevisions.js');

if (window.contextVars.renderURL !== undefined) {
    FileRenderer.start(window.contextVars.renderURL, '#fileRendered');
}

new FileRevisions(
    '#fileRevisions',
    window.contextVars.node,
    window.contextVars.file,
    window.contextVars.currentUser.canEdit
);

$(document).ready(function() {
    // Treebeard Files view
    $.ajax({
        url: nodeApiUrl + 'files/grid/'
    })
        .done(function (data) {
            var fangornOpts = {
                divID: 'grid',
                filesData: data.data,
                uploads: false,
                showFilter: false,
                title: undefined,
                hideColumnTitles: true,
                columnTitles: function () {
                    return [{
                        title: 'Name',
                        width: '100%'
                    }];
                },
                ontogglefolder : function (tree){
                    Fangorn.DefaultOptions.ontogglefolder.call(this, tree);
                    var containerHeight = this.select('#tb-tbody').height();
                    this.options.showTotal = Math.floor(containerHeight / this.options.rowHeight) + 1;
                    this.redraw();
                },
                lazyLoadOnLoad: function(tree) {
                    Fangorn.DefaultOptions.lazyLoadOnLoad.call(this, tree);
                    var tb = this;
                    var node = tree.parent();
                    for (var i=0; i < tree.children.length; i++) {
                        var child = tree.children[i];
                        if (child.data.kind === 'file' && window.contextVars.node.id === node.data.nodeID && child.data.name === window.contextVars.file.name && child.data.provider === window.contextVars.file.provider) {
                            tb.currentFileId = child.id;
                        }
                    }

                    if (tb.currentFileId) {
                        var index = tb.returnIndex(tb.currentFileId);
                        if (tb.visibleIndexes.indexOf(index) !== -1 ) {
                            var visibleIndex = tb.showRange.indexOf(index);
                            // show item if it is not in the visible range
                            if (visibleIndex ===  -1 || visibleIndex > tb.showRange.length - 2 ) {
                                var scrollTo = tb.visibleIndexes.indexOf(index) * tb.options.rowHeight;
                                $('#tb-tbody').scrollTop(scrollTo);
                           }
                       }
                    }
                },
                resolveRows: function (item) {
                    var selectClass = '';
                    var node = item.parent().parent();
                    if (item.data.kind === 'file' && window.contextVars.node.id === node.data.nodeID && item.data.name === window.contextVars.file.name && item.data.provider === window.contextVars.file.provider) {
                        selectClass = 'fangorn-hover';
                    }

                    var defaultColumns = [
                        {
                            data: 'name',
                            folderIcons: true,
                            filter: true,
                            css: selectClass,
                            custom: Fangorn.DefaultColumns._fangornTitleColumn
                        }
                    ];

                    if (item.parentID) {
                        item.data.permissions = item.data.permissions || item.parent().data.permissions;
                        if (item.data.kind === 'folder') {
                            item.data.accept = item.data.accept || item.parent().data.accept;
                        }
                    }

                    if (item.data.tmpID) {
                        defaultColumns = [
                            {
                                data: 'name',  // Data field name<commit_msg>Scroll if tb.visibleIndexes(index) > tb.showRange.length - 2<commit_after>var Fangorn = require('fangorn');

var FileRenderer = require('../filerenderer.js');
var FileRevisions = require('../fileRevisions.js');

if (window.contextVars.renderURL !== undefined) {
    FileRenderer.start(window.contextVars.renderURL, '#fileRendered');
}

new FileRevisions(
    '#fileRevisions',
    window.contextVars.node,
    window.contextVars.file,
    window.contextVars.currentUser.canEdit
);

$(document).ready(function() {
    // Treebeard Files view
    $.ajax({
        url: nodeApiUrl + 'files/grid/'
    })
        .done(function (data) {
            var fangornOpts = {
                divID: 'grid',
                filesData: data.data,
                uploads: false,
                showFilter: false,
                title: undefined,
                hideColumnTitles: true,
                columnTitles: function () {
                    return [{
                        title: 'Name',
                        width: '100%'
                    }];
                },
                ontogglefolder : function (tree){
                    Fangorn.DefaultOptions.ontogglefolder.call(this, tree);
                    var containerHeight = this.select('#tb-tbody').height();
                    this.options.showTotal = Math.floor(containerHeight / this.options.rowHeight) + 1;
                    this.redraw();
                },
                lazyLoadOnLoad: function(tree) {
                    Fangorn.DefaultOptions.lazyLoadOnLoad.call(this, tree);
                    var tb = this;
                    var node = tree.parent();
                    for (var i=0; i < tree.children.length; i++) {
                        var child = tree.children[i];
                        if (child.data.kind === 'file' && window.contextVars.node.id === node.data.nodeID && child.data.name === window.contextVars.file.name && child.data.provider === window.contextVars.file.provider) {
                            tb.currentFileId = child.id;
                        }
                    }

                    if (tb.currentFileId) {
                        var index = tb.returnIndex(tb.currentFileId);
                        var visibleIndex = tb.visibleIndexes.indexOf(index);
                        if (visibleIndex !== -1 && visibleIndex > tb.showRange.length - 2) {
                            var scrollTo = visibleIndex * tb.options.rowHeight;
                            $('#tb-tbody').scrollTop(scrollTo);
                        }
                    }
                },
                resolveRows: function (item) {
                    var selectClass = '';
                    var node = item.parent().parent();
                    if (item.data.kind === 'file' && window.contextVars.node.id === node.data.nodeID && item.data.name === window.contextVars.file.name && item.data.provider === window.contextVars.file.provider) {
                        selectClass = 'fangorn-hover';
                    }

                    var defaultColumns = [
                        {
                            data: 'name',
                            folderIcons: true,
                            filter: true,
                            css: selectClass,
                            custom: Fangorn.DefaultColumns._fangornTitleColumn
                        }
                    ];

                    if (item.parentID) {
                        item.data.permissions = item.data.permissions || item.parent().data.permissions;
                        if (item.data.kind === 'folder') {
                            item.data.accept = item.data.accept || item.parent().data.accept;
                        }
                    }

                    if (item.data.tmpID) {
                        defaultColumns = [
                            {
                                data: 'name',  // Data field name
{'fraction_non_alphanumeric': 0.11141678129298486, 'fraction_numerical': 0.0020007502813555083, 'mean_word_length': 1.1592872570194384, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4811853', 'n_tokens_mistral': 1986, 'n_tokens_neox': 1893, 'n_words': 342}