<commit_before>import {Command} from '@grid/core/command';
import {PersistenceService} from '@grid/core/persistence/persistence.service';
import {stringifyFactory} from '@grid/core/services/';

export function PersistencePanelController(mdPanelRef) {
	const model = this.model;
	const storageKey = this.storageKey;
	const persistenceService = new PersistenceService(model);

	this.items = [];
	model.persistence()
		.storage
		.getItem(storageKey)
		.then(items => {
			this.items = items || [];

			this.title = persistenceService.stringify(persistenceService.save());
		});

	this.close = () => mdPanelRef.close();

	this.cancel = new Command({
		execute: this.close
	});

	this.submit = new Command({
		execute: () => {
			this.items.push({
				title: this.title,
				modified: Date.now(),
				model: persistenceService.save(),
				isDefault: false
			});

			model.persistence()
				.storage
				.setItem(storageKey, this.items);

			this.title = '';
		},
		canExecute: () => !!this.title && !this.items.some(item => item.title === this.title)
	});

	this.edit = new Command({
		execute: item => {
			item.modified = Date.now();
			model.persistence()
				.storage
				.setItem(storageKey, this.items);
		}
	});

	this.load = new Command({
		execute: item => persistenceService.load(item.model)
	});

	this.remove = new Command({
		execute: item => {
			const index = this.items.indexOf(item);
			if (index >= 0) {
				this.items.splice(index, 1);

				model.persistence()
					.storage
					.setItem(storageKey, this.items);
			}
		}
	});

	this.setDefault = new Command({
		canExecute: item => !item.isDefault,<commit_msg>possibility to switch off default<commit_after>import {Command} from '@grid/core/command';
import {PersistenceService} from '@grid/core/persistence/persistence.service';
import {stringifyFactory} from '@grid/core/services/';

export function PersistencePanelController(mdPanelRef) {
	const model = this.model;
	const storageKey = this.storageKey;
	const persistenceService = new PersistenceService(model);

	this.items = [];
	model.persistence()
		.storage
		.getItem(storageKey)
		.then(items => {
			this.items = items || [];

			this.title = persistenceService.stringify(persistenceService.save());
		});

	this.close = () => mdPanelRef.close();

	this.cancel = new Command({
		execute: this.close
	});

	this.submit = new Command({
		execute: () => {
			this.items.push({
				title: this.title,
				modified: Date.now(),
				model: persistenceService.save(),
				isDefault: false
			});

			model.persistence()
				.storage
				.setItem(storageKey, this.items);

			this.title = '';
		},
		canExecute: () => !!this.title && !this.items.some(item => item.title === this.title)
	});

	this.edit = new Command({
		execute: item => {
			item.modified = Date.now();
			model.persistence()
				.storage
				.setItem(storageKey, this.items);
		}
	});

	this.load = new Command({
		execute: item => persistenceService.load(item.model)
	});

	this.remove = new Command({
		execute: item => {
			const index = this.items.indexOf(item);
			if (index >= 0) {
				this.items.splice(index, 1);

				model.persistence()
					.storage
					.setItem(storageKey, this.items);
			}
		}
	});

	this.setDefault = new Command({
{'fraction_non_alphanumeric': 0.1606425702811245, 'fraction_numerical': 0.001235712079085573, 'mean_word_length': 3.547752808988764, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5516940', 'n_tokens_mistral': 1188, 'n_tokens_neox': 1020, 'n_words': 208}