<commit_before>Ext.define('devilry.student.browseperiods.PeriodGrid', {
    extend: 'Ext.grid.Panel',
    alias: 'widget.student-browseperiods-periodgrid',

    requires: [
        'devilry.apps.student.simplified.SimplifiedPeriod',
        'devilry.apps.student.simplified.SimplifiedRelatedStudentKeyValue'
    ],
    
    constructor: function(config) {
        this.createStore();
        this.createRelatedStudentKeyValueStore();
        this.studentkeyvalue_store.load({
            scope: this,
            callback: function(records, op) {
                if(op.success) {
                    this.labelsGroupedByPeriod = this._groupLabelsByPeriod();
                    this.store.load();
                } else {
                    Ext.MessageBox.alert('Failed to load a resource. Please try to reload the page.');
                }
            },
        });
        this.callParent([config]);
    },

    cellTpl: Ext.create('Ext.XTemplate',
        '<div>{period.parentnode__short_name}.{period.short_name}</div>',
        '<ul class="labels-list">',
        '    <tpl for="labels">',
        '       <li class="label-{label}">{label}</li>',
        '    </tpl>',
        '</ul>'
    ),

    createStore: function() {
        this.store = Ext.create('Ext.data.Store', {
            model: 'devilry.apps.student.simplified.SimplifiedPeriod',
            remoteFilter: false,
            remoteSort: false,
            autoSync: true
        });
        this.store.proxy.setDevilryOrderby(['parentnode__short_name', '-start_time']);
        this.store.pageSize = 100000;
    },

    createRelatedStudentKeyValueStore: function() {
        this.studentkeyvalue_store = Ext.create('Ext.data.Store', {
            model: 'devilry.apps.student.simplified.SimplifiedRelatedStudentKeyValue',
            remoteFilter: false,
            remoteSort: false,
            autoSync: true
        });
        this.studentkeyvalue_store.proxy.setDevilryFilters([{
            field: 'application',
            comp: 'exact',
            value: 'devilry.statistics.Labels'
        }]);
        this.studentkeyvalue_store.pageSize = 100000;
    },
    
    initComponent: function() {
        Ext.apply(this, {
            cls: 'selectable-grid',
            columns: [{
                header: gettext('Subject'),
                dataIndex: 'parentnode__short_name',
                flex: 1,
                renderer: function(value, m, record) {
                    return this.cellTpl.apply({
                        period: record.data,
                        labels: this.labelsGroupedByPeriod[record.get('id')]
                    });
                }
            }]
        });
        this.callParent(arguments);
    },

    _groupLabelsByPeriod: function() {
        var labelsGroupedByPeriod = {};
        for(labelRecordIndex in this.studentkeyvalue_store.data.items) {
            var labelRecord = this.studentkeyvalue_store.getAt(labelRecordIndex);
            var periodid = labelRecord.get('relatedstudent__period');
            if(!labelsGroupedByPeriod[periodid]) {
                labelsGroupedByPeriod[periodid] = [];
            }
            labelsGroupedByPeriod[periodid].push({label: labelRecord.get('key')});
        }
        return labelsGroupedByPeriod;
    }<commit_msg>apps.student...PeriodGrid: Group by period long_name.<commit_after>Ext.define('devilry.student.browseperiods.PeriodGrid', {
    extend: 'Ext.grid.Panel',
    alias: 'widget.student-browseperiods-periodgrid',

    requires: [
        'devilry.apps.student.simplified.SimplifiedPeriod',
        'devilry.apps.student.simplified.SimplifiedRelatedStudentKeyValue'
    ],

    
    constructor: function(config) {
        this.createStore();
        this.createRelatedStudentKeyValueStore();
        this.studentkeyvalue_store.load({
            scope: this,
            callback: function(records, op) {
                if(op.success) {
                    this.labelsGroupedByPeriod = this._groupLabelsByPeriod();
                    this.store.load();
                } else {
                    Ext.MessageBox.alert('Failed to load a resource. Please try to reload the page.');
                }
            },
        });
        this.callParent([config]);
    },

    cellTpl: Ext.create('Ext.XTemplate',
        '<div>{period.parentnode__short_name}.{period.short_name}</div>',
        '<ul class="labels-list">',
        '    <tpl for="labels">',
        '       <li class="label-{label}">{label}</li>',
        '    </tpl>',
        '</ul>'
    ),

    createStore: function() {
        this.store = Ext.create('Ext.data.Store', {
            model: 'devilry.apps.student.simplified.SimplifiedPeriod',
            remoteFilter: false,
            remoteSort: false,
            autoSync: true,
            groupField: 'long_name',
            remoteGroup: false
        });
        this.store.proxy.setDevilryOrderby(['-start_time']);
        //this.store.proxy.setDevilryOrderby(['parentnode__short_name', '-start_time']);
        this.store.pageSize = 100000;
    },

    createRelatedStudentKeyValueStore: function() {
        this.studentkeyvalue_store = Ext.create('Ext.data.Store', {
            model: 'devilry.apps.student.simplified.SimplifiedRelatedStudentKeyValue',
            remoteFilter: false,
            remoteSort: false,
            autoSync: true
        });
        this.studentkeyvalue_store.proxy.setDevilryFilters([{
            field: 'application',
            comp: 'exact',
            value: 'devilry.statistics.Labels'
        }]);
        this.studentkeyvalue_store.pageSize = 100000;
    },
    
    initComponent: function() {
        Ext.apply(this, {
            columns: [{
                header: gettext('Subject'),
                dataIndex: 'parentnode__short_name',
                flex: 1,
                sortable: false,
                menuDisabled: true,
                renderer: function(value, m, record) {
                    return this.cellTpl.apply({
                        period: record.data,
                        labels: this.labelsGroupedByPeriod[record.get('id')]
                    });
                }
            }],
            features: [{
                ftype: 'grouping',
                groupHeaderTpl: '{name}'
            }]
        });
        this.callParent(arguments);
    },

    _groupLabelsByPeriod: function() {
        var labelsGroupedByPeriod = {};
        for(labelRecordIndex in this.studentkeyvalue_store.data.items) {
            var labelRecord = this.studentkeyvalue_store.getAt(labelRecordIndex);
            var periodid = labelRecord.get('relatedstudent__period');
            if(!labelsGroupedByPeriod[periodid]) {
                labelsGroupedByPeriod[periodid] = [];
            }
            labelsGroupedByPeriod[periodid].push({label: labelRecord.get('key')});
        }
        return labelsGroupedByPeriod;
    }
{'fraction_non_alphanumeric': 0.12241653418124006, 'fraction_numerical': 0.0037577684636508164, 'mean_word_length': 1.859504132231405, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, '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': '5567742', 'n_tokens_mistral': 1946, 'n_tokens_neox': 1861, 'n_words': 266}