<commit_before>/*globals jscolor, i18nDefaultQuery */
import toastr from 'toastr';
const TempSettings = new Mongo.Collection(null);

RocketChat.TempSettings = TempSettings;

const getDefaultSetting = function(settingId) {
	return RocketChat.settings.collectionPrivate.findOne({
		_id: settingId
	});
};

const setFieldValue = function(settingId, value, type, editor) {
	const input = $('.page-settings').find(`[name="${ settingId }"]`);
	switch (type) {
		case 'boolean':
			return $('.page-settings').find(`[name="${ settingId }"][value="${ Number(value) }"]`).prop('checked', true).change();
		case 'code':
			return input.next()[0].CodeMirror.setValue(value);
		case 'color':
			input.parents('.horizontal').find('select[name="color-editor"]').val(editor).change();
			input.val(value).change();
			if (editor === 'color') {
				return new jscolor(input); //eslint-disable-line
			}
			break;
		default:
			return input.val(value).change();
	}
};

Template.admin.onCreated(function() {
	if (RocketChat.settings.cachedCollectionPrivate == null) {
		RocketChat.settings.cachedCollectionPrivate = new RocketChat.CachedCollection({
			name: 'private-settings',
			eventType: 'onLogged'
		});
		RocketChat.settings.collectionPrivate = RocketChat.settings.cachedCollectionPrivate.collection;
		RocketChat.settings.cachedCollectionPrivate.init();
	}
	this.selectedRooms = new ReactiveVar({});
	return RocketChat.settings.collectionPrivate.find().observe({
		added: (data) => {
			const selectedRooms = this.selectedRooms.get();
			if (data.type === 'roomPick') {
				selectedRooms[data._id] = data.value;
				this.selectedRooms.set(selectedRooms);
			}
			return TempSettings.insert(data);
		},
		changed: (data) => {
			const selectedRooms = this.selectedRooms.get();
			if (data.type === 'roomPick') {
				selectedRooms[data._id] = data.value;
				this.selectedRooms.set(selectedRooms);
			}
			return TempSettings.update(data._id, data);
		},
		removed: (data) => {
			const selectedRooms = this.selectedRooms.get();
			if (data.type === 'roomPick') {
				delete selectedRooms[data._id];
				this.selectedRooms.set(selectedRooms);
			}
			return TempSettings.remove(data._id);
		}
	});
});

Template.admin.onDestroyed(function() {
	return TempSettings.remove({});
});

Template.admin.helpers({
	languages() {
		const languages = TAPi18n.getLanguages();

		let result = Object.keys(languages).forEach(key => {
			const language = languages[key];
			return _.extend(language, { key });
		});<commit_msg>fix .map<commit_after>/*globals jscolor, i18nDefaultQuery */
import toastr from 'toastr';
const TempSettings = new Mongo.Collection(null);

RocketChat.TempSettings = TempSettings;

const getDefaultSetting = function(settingId) {
	return RocketChat.settings.collectionPrivate.findOne({
		_id: settingId
	});
};

const setFieldValue = function(settingId, value, type, editor) {
	const input = $('.page-settings').find(`[name="${ settingId }"]`);
	switch (type) {
		case 'boolean':
			return $('.page-settings').find(`[name="${ settingId }"][value="${ Number(value) }"]`).prop('checked', true).change();
		case 'code':
			return input.next()[0].CodeMirror.setValue(value);
		case 'color':
			input.parents('.horizontal').find('select[name="color-editor"]').val(editor).change();
			input.val(value).change();
			if (editor === 'color') {
				return new jscolor(input); //eslint-disable-line
			}
			break;
		default:
			return input.val(value).change();
	}
};

Template.admin.onCreated(function() {
	if (RocketChat.settings.cachedCollectionPrivate == null) {
		RocketChat.settings.cachedCollectionPrivate = new RocketChat.CachedCollection({
			name: 'private-settings',
			eventType: 'onLogged'
		});
		RocketChat.settings.collectionPrivate = RocketChat.settings.cachedCollectionPrivate.collection;
		RocketChat.settings.cachedCollectionPrivate.init();
	}
	this.selectedRooms = new ReactiveVar({});
	return RocketChat.settings.collectionPrivate.find().observe({
		added: (data) => {
			const selectedRooms = this.selectedRooms.get();
			if (data.type === 'roomPick') {
				selectedRooms[data._id] = data.value;
				this.selectedRooms.set(selectedRooms);
			}
			return TempSettings.insert(data);
		},
		changed: (data) => {
			const selectedRooms = this.selectedRooms.get();
			if (data.type === 'roomPick') {
				selectedRooms[data._id] = data.value;
				this.selectedRooms.set(selectedRooms);
			}
			return TempSettings.update(data._id, data);
		},
		removed: (data) => {
			const selectedRooms = this.selectedRooms.get();
			if (data.type === 'roomPick') {
				delete selectedRooms[data._id];
				this.selectedRooms.set(selectedRooms);
			}
			return TempSettings.remove(data._id);
		}
	});
});

Template.admin.onDestroyed(function() {
	return TempSettings.remove({});
});

Template.admin.helpers({
	languages() {
		const languages = TAPi18n.getLanguages();

		let result = Object.keys(languages).map(key => {
			const language = languages[key];
			return _.extend(language, { key });
		});
{'fraction_non_alphanumeric': 0.16690042075736325, 'fraction_numerical': 0.002003606491685033, 'mean_word_length': 4.679180887372014, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '3215921', 'n_tokens_mistral': 1777, 'n_tokens_neox': 1588, 'n_words': 273}