<commit_before>var AD = require('AppDev');
var $ = require('jquery');

// Create a class that represents the contacts table
var ContactTable = $.ModelTable('AppDev.UI.ContactTable', {
    setup: function() {
        AD.PropertyStore.setDefault('sort_order', this.sortFields.map(function(field) { return field.field; }));
        this.indexedSortFields = $.indexArray(this.sortFields, 'field');
        $.ModelTable.addGroupProcessor('firstLetter', function(key) {
            return key ? key[0].toUpperCase() : key;
        });
        $.ModelTable.addGroupProcessor('year', function(key) {
            return AD.Models.Year.cache.getById(key).getLabel();
        });
    },
    
    sortFields: [
        {field: 'campus_label', label: 'campus'},
        {field: 'contact_firstName', label: 'firstName', groupProcessor: 'firstLetter'},
        {field: 'contact_lastName', label: 'lastName', groupProcessor: 'firstLetter'},
        {field: 'year_id', label: 'year', groupProcessor: 'year'}
    ]
}, {
    init: function(options) {
        var group = this.options.group;
        
        // The group filter must be setup before the ModelTable is initialized 
        this.groupFilter = null;
        if (group) {
            this.groupFilter = group.attr('group_filter');
        }
        
        this._super({
            $window: this.options.$window,
            Model: AD.Models.Contact,
            selectable: true,
            editable: true,
            grouped: true,
            sorted: true,
            sortOrder: AD.PropertyStore.get('sort_order')
        });
        
        if (group) {
            this.smartBind(group, 'group_filter', function() {
                // When the group filter is updated, refresh the table contents
                this.groupFilter = group.attr('group_filter');
                this.refresh();
            });
        }
        
        this.smartBind(AD.Models.ContactStep, '*', this.refresh);

        // When the sort order is updated, refresh the contacts list
        this.smartBind(AD.PropertyStore, 'sort_order', function(event, sortOrder) {
            this.setSortOrder(sortOrder);
        });
    },
    
    // Create and return a table view row that represents the contact
    createRow: function(contact) {
        // Create a table view row that represents this contact
        var row = Ti.UI.createTableViewRow({
            height: 50
        });
        
        // Create the contact name label
        var nameRowHeight = 25;
        var nameFont = {fontWeight: 'bold', fontSize: 20};
        var nameLabel = Ti.UI.createLabel({
            left: AD.UI.padding,
            top: 0,
            width: Ti.UI.SIZE,
            height: nameRowHeight,
            text: '', // will be set by 'update'
            font: nameFont
        });
        row.add(nameLabel);
        // Create the contact year label
        var yearLabel = Ti.UI.createLabel({
            right: AD.UI.padding,
            top: 0,
            width: Ti.UI.SIZE,
            height: nameRowHeight,
            text: '', // will be set by 'update'
            textAlign: 'right',
            font: AD.UI.Fonts.medium
        });
        row.add(yearLabel);
        
        // Create the last step taken row which consists of the step name and date
        var dateWidth = 80;
        var lastUpdateStepLabel = Ti.UI.createLabel({
            left: AD.UI.padding,
            right: AD.UI.padding * 2 + dateWidth,
            top: nameRowHeight,
            height: Ti.UI.SIZE,
            text: '', // will be set by 'update'
            color: 'gray',
            font: AD.UI.Fonts.mediumSmall
        });
        row.add(lastUpdateStepLabel);
        var lastUpdateDateLabel = Ti.UI.createLabel({
            right: AD.UI.padding,
            top: nameRowHeight,
            width: dateWidth,
            height: Ti.UI.SIZE,
            text: '', // will be set by 'update'<commit_msg>Properly ellipsize step names on Android<commit_after>var AD = require('AppDev');
var $ = require('jquery');

// Create a class that represents the contacts table
var ContactTable = $.ModelTable('AppDev.UI.ContactTable', {
    setup: function() {
        AD.PropertyStore.setDefault('sort_order', this.sortFields.map(function(field) { return field.field; }));
        this.indexedSortFields = $.indexArray(this.sortFields, 'field');
        $.ModelTable.addGroupProcessor('firstLetter', function(key) {
            return key ? key[0].toUpperCase() : key;
        });
        $.ModelTable.addGroupProcessor('year', function(key) {
            return AD.Models.Year.cache.getById(key).getLabel();
        });
    },
    
    sortFields: [
        {field: 'campus_label', label: 'campus'},
        {field: 'contact_firstName', label: 'firstName', groupProcessor: 'firstLetter'},
        {field: 'contact_lastName', label: 'lastName', groupProcessor: 'firstLetter'},
        {field: 'year_id', label: 'year', groupProcessor: 'year'}
    ]
}, {
    init: function(options) {
        var group = this.options.group;
        
        // The group filter must be setup before the ModelTable is initialized 
        this.groupFilter = null;
        if (group) {
            this.groupFilter = group.attr('group_filter');
        }
        
        this._super({
            $window: this.options.$window,
            Model: AD.Models.Contact,
            selectable: true,
            editable: true,
            grouped: true,
            sorted: true,
            sortOrder: AD.PropertyStore.get('sort_order')
        });
        
        if (group) {
            this.smartBind(group, 'group_filter', function() {
                // When the group filter is updated, refresh the table contents
                this.groupFilter = group.attr('group_filter');
                this.refresh();
            });
        }
        
        this.smartBind(AD.Models.ContactStep, '*', this.refresh);

        // When the sort order is updated, refresh the contacts list
        this.smartBind(AD.PropertyStore, 'sort_order', function(event, sortOrder) {
            this.setSortOrder(sortOrder);
        });
    },
    
    // Create and return a table view row that represents the contact
    createRow: function(contact) {
        // Create a table view row that represents this contact
        var row = Ti.UI.createTableViewRow({
            height: 50
        });
        
        // Create the contact name label
        var nameRowHeight = 25;
        var nameFont = {fontWeight: 'bold', fontSize: 20};
        var nameLabel = Ti.UI.createLabel({
            left: AD.UI.padding,
            top: 0,
            width: Ti.UI.SIZE,
            height: nameRowHeight,
            text: '', // will be set by 'update'
            font: nameFont
        });
        row.add(nameLabel);
        // Create the contact year label
        var yearLabel = Ti.UI.createLabel({
            right: AD.UI.padding,
            top: 0,
            width: Ti.UI.SIZE,
            height: nameRowHeight,
            text: '', // will be set by 'update'
            textAlign: 'right',
            font: AD.UI.Fonts.medium
        });
        row.add(yearLabel);
        
        // Create the last step taken row which consists of the step name and date
        var dateWidth = 80;
        var lastUpdateStepLabel = Ti.UI.createLabel({
            left: AD.UI.padding,
            right: AD.UI.padding * 2 + dateWidth,
            top: nameRowHeight,
            width: Ti.UI.FILL,
            height: Ti.UI.SIZE,
            text: '', // will be set by 'update'
            wordWrap: false,
            ellipsize: true,
            color: 'gray',
            font: AD.UI.Fonts.mediumSmall
        });
        row.add(lastUpdateStepLabel);
        var lastUpdateDateLabel = Ti.UI.createLabel({
            right: AD.UI.padding,
            top: nameRowHeight,
            width: dateWidth,
            height: Ti.UI.SIZE,
            text: '', // will be set by 'update'
{'fraction_non_alphanumeric': 0.11738148984198646, 'fraction_numerical': 0.0030097817908201654, 'mean_word_length': 1.7962833099579243, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5504281', 'n_tokens_mistral': 2182, 'n_tokens_neox': 2145, 'n_words': 562}