<commit_before>Alloy.Globals.extendsBaseUIController($, arguments[0]);

var collections = [], collapsibleSections = {};

$.$view.addEventListener("click", function(e) {
	e.cancelBubble = true;
	if (e.deleteRow === true) {
		$.table.deleteRow(e.index);
	} else if (e.expandSection === true) {
		exports.expandSection(e.index, e.sectionRowId);
	} else if (e.collapseSection === true) {
		exports.collapseSection(e.index, e.sectionRowId);
	} else if (e.addRowToSection) {
		var section = collapsibleSections[e.sectionRowId];
		var rowModel, collection;
		for (var i = 0; i < section.collections.length; i++) {
			rowModel = section.collections[i].get(e.addRowToSection);
			if (rowModel) {
				collection = section.collections[i];
				break;
			}
		}
		addRowToSection(rowModel, collection, e.index);
	}
});

function addRowToSection(rowModel, collection, index) {
	var rowViewController = Alloy.createController(rowModel.config.rowView, {
		$model : rowModel,
		$collection : collection
	});
	var row = Ti.UI.createTableViewRow();
	rowViewController.setParent(row);
	if (rowViewController.$attrs.hasDetail || rowViewController.$view.hasDetail) {
		collapsibleSections[rowModel.xGet("id")] = {
			parentRowController : rowViewController,
			collections : []
		};
	}
	if (index) {
		$.table.insertRowAfter(index, row);
	} else {
		$.table.appendRow(row);
	}
}

function addRow(rowModel, collection) {
	addRowToSection(rowModel, collection);
}

exports.expandSection = function(rowIndex, sectionRowId) {
	var index = rowIndex;
	var parentController = collapsibleSections[sectionRowId].parentRowController;
	var collections = parentController.getDetailCollections();
	for (var i = 0; i < collections.length; i++) {
		for (var j = 0; j < collections[i].length; j++) {
			addRowToSection(collections[i].at(j), collections[i], index);
			index++;
		}
		collapsibleSections[sectionRowId].collections.push(collections[i]);
	}
}

exports.collapseSection = function(rowIndex, sectionRowId) {
	var index = rowIndex + 1;
	var collections = collapsibleSections[sectionRowId].collections;
	for (var c = 0; c < collections.length; c++) {
		for (var i = 0; i < collections[c].length; i++) {
			$.table.deleteRow(index);
		}
	}
	collapsibleSections[sectionRowId].collections = [];
}

exports.addCollection = function(collection) {
	console.info("xTableView adding collection " + collection.length);
	collections.push(collection);

	collection.map(function(row) {
		addRow(row, collection);
	});
	collection.on("add", addRow);
}
var clearCollections = function() {<commit_msg>fxied bug in collapse collapsible<commit_after>Alloy.Globals.extendsBaseUIController($, arguments[0]);

var collections = [], collapsibleSections = {};

$.$view.addEventListener("click", function(e) {
	e.cancelBubble = true;
	if (e.deleteRow === true) {
		$.table.deleteRow(e.index);
	} else if (e.expandSection === true) {
		exports.expandSection(e.index, e.sectionRowId);
	} else if (e.collapseSection === true) {
		exports.collapseSection(e.index, e.sectionRowId);
	} else if (e.addRowToSection) {
		var section = collapsibleSections[e.sectionRowId];
		var rowModel, collection;
		for (var i = 0; i < section.collections.length; i++) {
			rowModel = section.collections[i].get(e.addRowToSection);
			if (rowModel) {
				collection = section.collections[i];
				break;
			}
		}
		addRowToSection(rowModel, collection, e.index);
	}
});

function addRowToSection(rowModel, collection, index) {
	var rowViewController = Alloy.createController(rowModel.config.rowView, {
		$model : rowModel,
		$collection : collection
	});
	var row = Ti.UI.createTableViewRow();
	rowViewController.setParent(row);
	if (rowViewController.$attrs.hasDetail || rowViewController.$view.hasDetail) {
		collapsibleSections[rowModel.xGet("id")] = {
			parentRowController : rowViewController,
			collections : []
		};
	}
	
	if (index === undefined) {
		$.table.insertRowAfter(index, row);
	} else {
		$.table.appendRow(row);
	}
}

function addRow(rowModel, collection) {
	addRowToSection(rowModel, collection);
}

exports.expandSection = function(rowIndex, sectionRowId) {
	var index = rowIndex;
	var parentController = collapsibleSections[sectionRowId].parentRowController;
	var collections = parentController.getDetailCollections();
	for (var i = 0; i < collections.length; i++) {
		for (var j = 0; j < collections[i].length; j++) {
			addRowToSection(collections[i].at(j), collections[i], index);
			index++;
		}
		collapsibleSections[sectionRowId].collections.push(collections[i]);
	}
}

exports.collapseSection = function(rowIndex, sectionRowId) {
	var index = rowIndex + 1;
	var collections = collapsibleSections[sectionRowId].collections;
	for (var c = 0; c < collections.length; c++) {
		for (var i = 0; i < collections[c].length; i++) {
			var rowId = collections[c].at(i).get("id");
			if(collapsibleSections[rowId]){
				exports.collapseSection(index, rowId);
			}
			$.table.deleteRow(index);
		}
	}
	collapsibleSections[sectionRowId].collections = [];
}

exports.addCollection = function(collection) {
	console.info("xTableView adding collection " + collection.length);
	collections.push(collection);

	collection.map(function(row) {
		addRow(row, collection);
	});
	collection.on("add", addRow);
}
var clearCollections = function() {
{'fraction_non_alphanumeric': 0.1482183472327521, 'fraction_numerical': 0.00265352539802881, 'mean_word_length': 5.086505190311419, 'pattern_counts': {'":': 0, '<': 13, '<?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': '4671434', 'n_tokens_mistral': 1846, 'n_tokens_neox': 1728, 'n_words': 323}