<commit_before>//
//  Author: <NAME> <EMAIL>
//  May 2012
//


var ew_S3BucketsTreeView = {
    model : "s3Buckets",
    path: [],
    folder: '',

    keyName: function(name)
    {
        return name.replace(/[ \/\\'":]+/g, '');
    },

    isFolder: function(item)
    {
        return !this.path.length || item.label[item.label.length - 1] == "/";
    },

    displayDetails: function(event)
    {
        var item = this.getSelected()
        if (item == null) return
        // Folder or bucket
        if (this.isFolder(item)) {
            this.path.push(item.folder);
            this.show();
            return;
        }
        // Try to show this file in popup
        this.showFile();
    },


    displayInfo : function()
    {
        var item = this.getSelected()
        if (item == null) return
        if (!this.path.length) {
            this.core.api.getS3BucketLocation(item.name);
        }
        TreeView.displayDetails.call(this);
    },

    display : function(list)
    {
        var idx = -1;
        var path = this.path.join("/") + "/";
        var nlist = [];
        for (var i in list) {
            if (list[i].name.match('log')) continue;
            var n = (this.path[0] + "/" + list[i].name).replace(/[ \/]+$/, '');
            var p = n.split("/");
            //debug(path + ":" + n + ":" + p.length + ":" + this.path.length);
            // Next level only
            if (!this.path.length || n.indexOf(path) == 0 && p.length == this.path.length + 1) {
                list[i].folder = p[p.length - 1];
                list[i].label = list[i].folder + (list[i].name[list[i].name.length - 1] == "/" ? "/" : "")
                nlist.push(list[i])
                // Select given item
                if (list[i].name == this.folder) {
                    idx = nlist.length - 1;
                }
            }
        }
        TreeView.display.call(this, nlist);
        if (idx >= 0) this.setSelected(idx);
        $("ew.s3Buckets.path").value = path;
        this.folder = '';
    },

    selectionChanged: function()
    {
    },

    menuChanged: function()
    {
        var item = this.getSelected()
        $("ew.s3Buckets.back").disabled = !this.path.length;
        $("ew.s3Buckets.edit").disabled = !this.path.length || !item || !item.bucket || item.size > 1024*1024;
        $("ew.s3Buckets.createFile").disabled = !this.path.length;
        $("ew.s3Buckets.download").disabled = !item || this.isFolder(item);
    },

    show: function()
    {
        var me = this;
        if (!this.path.length) {<commit_msg>fixed S3 navigation<commit_after>//
//  Author: <NAME> <EMAIL>
//  May 2012
//


var ew_S3BucketsTreeView = {
    model : "s3Buckets",
    path: [],
    folder: '',

    keyName: function(name)
    {
        return name.replace(/[ \/\\'":]+/g, '');
    },

    isFolder: function(item)
    {
        return !this.path.length || item.label[item.label.length - 1] == "/";
    },

    displayDetails: function(event)
    {
        var item = this.getSelected()
        if (item == null) return
        // Folder or bucket
        if (this.isFolder(item)) {
            this.path.push(item.folder);
            this.show();
            return;
        }
        // Try to show this file in popup
        this.showFile();
    },


    displayInfo : function()
    {
        var item = this.getSelected()
        if (item == null) return
        if (!this.path.length) {
            this.core.api.getS3BucketLocation(item.name);
        }
        TreeView.displayDetails.call(this);
    },

    display : function(list)
    {
        var idx = -1;
        var path = this.path.join("/") + "/";
        var nlist = [];
        var labels = {};
        for (var i in list) {
            if (!this.path.length) {
                list[i].folder = list[i].label = list[i].name;
                nlist.push(list[i]);
            } else {
                var n = this.path[0] + "/" + list[i].name;
                var p = n.split("/");
                if (n <= path || n.indexOf(path) != 0) continue;
                list[i].folder = list[i].label = p.slice(this.path.length, this.path.length + 1).join("/");
                if (p.length > this.path.length + 1) list[i].label += "/";
                // Skip subfolders
                if (labels[list[i].label]) continue;
                labels[list[i].label] = 1;
                nlist.push(list[i]);
            }
            // Select given item
            if (list[i].label == this.folder) {
                idx = nlist.length - 1;
            }
        }
        TreeView.display.call(this, nlist);
        if (idx >= 0) this.setSelected(idx);
        $("ew.s3Buckets.path").value = path;
        this.folder = '';
    },

    selectionChanged: function()
    {
    },

    menuChanged: function()
    {
        var item = this.getSelected()
        $("ew.s3Buckets.back").disabled = !this.path.length;
        $("ew.s3Buckets.edit").disabled = !this.path.length || !item || !item.bucket || item.size > 1024*1024;
        $("ew.s3Buckets.createFile").disabled = !this.path.length;
        $("ew.s3Buckets.download").disabled = !item || this.isFolder(item);
    },

    show: function()
    {
        var me = this;
        if (!this.path.length) {
{'fraction_non_alphanumeric': 0.17306960821605172, 'fraction_numerical': 0.011220996576645112, 'mean_word_length': 1.586817511067388, 'pattern_counts': {'":': 5, '<': 8, '<?xml version=': 0, '>': 12, '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': '5884821', 'n_tokens_mistral': 1744, 'n_tokens_neox': 1652, 'n_words': 316}