<commit_before>
/**
 * Panel to browse FileMeta.
 */
Ext.define('devilry.extjshelpers.assignmentgroup.FileMetaBrowserPanel', {
    extend: 'Ext.panel.Panel',
    alias: 'widget.filemetabrowserpanel',
    cls: 'widget-filemetabrowserpanel',

    config: {
        /**
         * @cfg
         * FileMeta ``Ext.data.Store``. (Required).
         * _Note_ that ``filemetastore.proxy.extraParams`` is changed by this
         * class.
         */
        filemetastore: undefined,

        
        /**
         * @cfg
         * Id of the delivery in which the filemetas belong.
         */
        deliveryid: undefined,
    },

    initComponent: function() {
        this.filemetastore.proxy.extraParams.filters = Ext.JSON.encode([
            {field: 'delivery', comp:'exact', value: this.deliveryid}
        ]);

        this.filemetastore.load();
        
        //TODO Necessary. Get undefined when referenced later
        var stored_delivery_id = this.deliveryid;

        
        Ext.apply(this, {
            items: [{
                xtype: 'grid',
                store: this.filemetastore,
                columns: [{
                    header: 'File name', flex:1, dataIndex: 'filename'
                }, {
                    header: 'Size', dataIndex: 'size'
                }],
                    listeners: {
                    itemclick: function(self, record) {
                        var url = DevilrySettings.DEVILRY_MAIN_PAGE + "/student/show-delivery/filedownload/" + record.data.id;
                        window.open(url, 'download');
                    }
                }
    
            }],

            bbar: [{
                xtype: 'button',
                text: 'Download all files (zip)',
                listeners: {
                    click: function(view, record, item) {
                        var url = DevilrySettings.DEVILRY_MAIN_PAGE + "/student/show-delivery/compressedfiledownload/" + stored_delivery_id;
                        window.open(url, 'download');
                    }
                }
            }, {
                xtype: 'button',
                text: 'Download all files (tar.gz)',
                listeners: {
                    click: function() {
                        console.log('Downloading tar.gz some time in the future');
                    }
                }
            }]
        });
        this.callParent(arguments);
    }
});<commit_msg>/extjs_classes/extjshelpers/assignmentgroup/FileMetaBrowserPanel.js Human Readable filesize format<commit_after>
/**
 * Panel to browse FileMeta.
 */
Ext.define('devilry.extjshelpers.assignmentgroup.FileMetaBrowserPanel', {
    extend: 'Ext.panel.Panel',
    alias: 'widget.filemetabrowserpanel',
    cls: 'widget-filemetabrowserpanel',

    config: {
        /**
         * @cfg
         * FileMeta ``Ext.data.Store``. (Required).
         * _Note_ that ``filemetastore.proxy.extraParams`` is changed by this
         * class.
         */
        filemetastore: undefined,

        
        /**
         * @cfg
         * Id of the delivery in which the filemetas belong.
         */
        deliveryid: undefined,
    },

    initComponent: function() {
        this.filemetastore.proxy.extraParams.filters = Ext.JSON.encode([
            {field: 'delivery', comp:'exact', value: this.deliveryid}
        ]);

        this.filemetastore.load();
        
        //TODO Necessary. Get undefined when referenced later
        var stored_delivery_id = this.deliveryid;

        
        Ext.apply(this, {
            items: [{
                xtype: 'grid',
                sortableColumns: false,
                store: this.filemetastore,
                columns: [{
                    header: 'File name',
                    menuDisabled: true,
                    flex:1, 
                    dataIndex: 'filename'
                }, {
                    header: 'Size',
                    menuDisabled: true,
                    dataIndex: 'size',
                    renderer: function(value) {
                        var units = ['Bytes', 'KBytes', 'MBytes', 'GBytes'];
                        var i = 0;
                        while(value >= 1024) {
                            value /= 1024;
                            ++i;
                        }
                        if(i < units.length) {
                            return value.toFixed() + ' ' + units[i];
                        } else {
                            return value + ' ' + units[0];
                        }
                        
                    }
                }],
                    listeners: {
                    itemclick: function(self, record) {
                        var url = DevilrySettings.DEVILRY_MAIN_PAGE + "/student/show-delivery/filedownload/" + record.data.id;
                        window.open(url, 'download');
                    }
                }
    
            }],

            bbar: [{
                xtype: 'button',
                scale: 'large',
                text: 'Download all files (.zip)',
                listeners: {
                    click: function(view, record, item) {
                        var url = DevilrySettings.DEVILRY_MAIN_PAGE + "/student/show-delivery/compressedfiledownload/" + stored_delivery_id;
                        window.open(url, 'download');
                    }
                }
            }]
            // , {
                // xtype: 'button',
                // text: 'Download all files (tar.gz)',
                // listeners: {
                    // click: function() {
                        // console.log('Downloading tar.gz some time in the future');
                    // }
                // }
            // }]
        });
        this.callParent(arguments);
    }
});
{'fraction_non_alphanumeric': 0.11088118641145026, 'fraction_numerical': 0.0020693222969477496, 'mean_word_length': 1.1339220014716704, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2503136', 'n_tokens_mistral': 1538, 'n_tokens_neox': 1433, 'n_words': 287}