<commit_before>Meteor.subscribe('things');
Meteor.subscribe('thingfields');


/* THINGS */

Template.list_things_table.helpers({
    thingfields: function() {
        return Thingfields.find({}, { sort: { form_order: 1 }});
    },
    things: function() {
	// set Session of table order for sorting purposes
	return Things.find({}, { sort: { Date: -1 }});
    },
    thingValue: function() {
	var label = Template.parentData().label;
	var dtype = Template.parentData().dtype;
	var data = Template.parentData(1)[label];
	var value;
	switch(dtype) {
	case 'Date':
	    value = moment(data).format();
	    break;
	case 'Decimal':
            value = parseFloat(data);
            break;
        case 'Number':
            value = Math.round(parseFloat(data));
            break;
        default:
	    value = data;
	}
	return value;
    }
});

Template.list_things_table.events({
    'click tbody tr': function(e) {
	e.preventDefault();
	setEditThing(this._id);
    }
});

Template.new_thing.helpers({
    thingfields: function() {<commit_msg>Sort things table by clicking the column head; resolves #3<commit_after>Meteor.subscribe('things');
Meteor.subscribe('thingfields');


/* THINGS */
var list_thing_table_sort = {};

var setThingListSort = function(field) {
    var sort = list_thing_table_sort[field._id];
    var newSort = (sort == 1) ? -1 : 1;
    list_thing_table_sort[field._id] = newSort;
    var sortValue = {};
    sortValue[field.label] = newSort;
    Session.set('activeThingListSort', sortValue);
};

var getThingListSort = function() {
    return Session.get('activeThingListSort') || { Date: -1 };
};

Template.list_things_table.helpers({
    thingfields: function() {
        return Thingfields.find({}, { sort: { form_order: 1 }});
    },
    things: function() {
	return Things.find({}, { sort: getThingListSort() });
    },
    thingValue: function() {
	var label = Template.parentData().label;
	var dtype = Template.parentData().dtype;
	var data = Template.parentData(1)[label];
	var value;
	switch(dtype) {
	case 'Date':
	    value = moment(data).format();
	    break;
	case 'Decimal':
            value = parseFloat(data);
            break;
        case 'Number':
            value = Math.round(parseFloat(data));
            break;
        default:
	    value = data;
	}
	return value;
    }
});

Template.list_things_table.events({
    'click thead th': function(e) {
	e.preventDefault();
	setThingListSort(this);
    },
    'click tbody tr': function(e) {
	e.preventDefault();
	setEditThing(this._id);
    }
});

Template.new_thing.helpers({
    thingfields: function() {
{'fraction_non_alphanumeric': 0.15236629472874183, 'fraction_numerical': 0.003847633705271258, 'mean_word_length': 3.1533546325878596, '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': '1013686', 'n_tokens_mistral': 847, 'n_tokens_neox': 832, 'n_words': 175}