<commit_before>import './allUsers.tpl.jade'

Template.allUsers.helpers

	userCount: -> Meteor.users.find({}, fields: _id: 1).count()

Template.allUsers.onCreated -> Tracker.afterFlush => @autorun =>

	users = Template.currentData().users
	rows = []
	columns = [
		{ name: 'id', title: '#', breakpoints: '', filterable: false }
		{ name: 'username', title: 'Username' , breakpoints: '' }
		{ name: 'name', title: 'Name', breakpoints: '' }
		{ name: 'email', title: 'E-Mail' , breakpoints: '' }
		{ name: 'action', title: 'Action' , breakpoints: '' }
		{ name: 'projects', visible: false }
	]

	for user, index in users
		projects = []

		for group in Object.keys user.roles
			projects.push group + '=' + user.roles[group]

		rows.push
			id: index + 1
			username: user.username
			action: '<a class="impersonate" data-id="' + user._id + '" data-lang="' + user.profile.language + '" href>Impersonate...</a>'
			name: user.profile.firstname + ' ' + user.profile.lastname
			email: user.profile.email
			projects: projects.join(';')

	$('#userTable').html('').footable
		columns: columns
		rows: rows
		paging: enabled: false
		sorting: enabled: true
		paging:
			enabled: true
			size: 15
		filtering:
			enabled: true
			delay: 400
			placeholder: 'Search...'

Template.allUsers.events

	'click .impersonate': (e) ->
		userId = $(e.target).attr('data-id')
		userLang = $(e.target).attr('data-lang')

		Meteor.call 'getImpersonateToken', userId, (e, token) ->
			Accounts.callLoginMethod methodArguments: [ impToken: token ]

			FlowRouter.go 'home', language: userLang
<commit_msg>add showProjects button<commit_after>import './allUsers.tpl.jade'

Template.allUsers.helpers

	userCount: -> Meteor.users.find({}, fields: _id: 1).count()

Template.allUsers.onCreated -> Tracker.afterFlush => @autorun =>

	users = Template.currentData().users
	rows = []
	columns = [
		{ name: 'id', title: '#', breakpoints: '', filterable: false }
		{ name: 'username', title: 'Username' , breakpoints: '' }
		{ name: 'name', title: 'Name', breakpoints: '' }
		{ name: 'email', title: 'E-Mail' , breakpoints: '' }
		{ name: 'action', title: 'Action' , breakpoints: '' }
		{ name: 'projects', visible: false }
	]

	for user, index in users
		projects = []

		for group in Object.keys user.roles
			projects.push group + '=' + user.roles[group]

		rows.push
			id: index + 1
			username: user.username
			name: user.profile.firstname + ' ' + user.profile.lastname
			email: user.profile.email
			action: '<a class="impersonate" data-id="' + user._id + '" data-lang="' + user.profile.language + '" href>Impersonate...</a> | <a class="showProjects" data-id="' + user._id + '" href>Show projects...</a>'
			projects: projects.join(';')

	$('#userTable').html('').footable
		columns: columns
		rows: rows
		paging: enabled: false
		sorting: enabled: true
		paging:
			enabled: true
			size: 15
		filtering:
			enabled: true
			delay: 400
			placeholder: 'Search...'

Template.allUsers.events

	'click .impersonate': (e) ->
		userId = $(e.target).attr('data-id')
		userLang = $(e.target).attr('data-lang')

		Meteor.call 'getImpersonateToken', userId, (e, token) ->
			Accounts.callLoginMethod methodArguments: [ impToken: token ]

			FlowRouter.go 'home', language: userLang

	'click .showProjects': (e) ->
		userId = $(e.target).attr('data-id')
		projectIds = []

		for role in Permissions.member
			roleProjectIds = Roles.getGroupsForUser(userId, role).join(',')

			if roleProjectIds then projectIds.push roleProjectIds

		$('#projectTable .footable-filtering button').click()
		$('#projectTable .footable-filtering input[type="text"]').val projectIds.join(',')
		$('#projectTable .footable-filtering button').click()

{'fraction_non_alphanumeric': 0.17635921017040843, 'fraction_numerical': 0.0037868542061130646, 'mean_word_length': 3.8657894736842104, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 22, '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': '5442603', 'n_tokens_mistral': 1359, 'n_tokens_neox': 1231, 'n_words': 284}