2018-02-28 12:41:06 +01:00
|
|
|
import { Component, OnInit } from '@angular/core';
|
|
|
|
import {Settings} from './settings';
|
|
|
|
import {Phrase} from './phrase';
|
|
|
|
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
|
|
|
|
import {ConfigurationService} from '../configuration.service';
|
2018-03-17 14:05:55 +01:00
|
|
|
import {ActivatedRoute, Router} from '@angular/router';
|
2018-02-28 12:41:06 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-settings',
|
|
|
|
templateUrl: './settings.component.html',
|
|
|
|
styleUrls: ['./settings.component.css']
|
|
|
|
})
|
|
|
|
export class SettingsComponent implements OnInit {
|
|
|
|
|
2018-03-22 22:32:33 +01:00
|
|
|
public sliderValue = 0;
|
|
|
|
public sliderConfig: any = {
|
|
|
|
connect: [true, false],
|
|
|
|
tooltips: [ true ],
|
|
|
|
step: 1,
|
|
|
|
range: {
|
|
|
|
min: 1,
|
|
|
|
max: 20
|
|
|
|
},
|
|
|
|
pips: {
|
|
|
|
mode: 'count',
|
|
|
|
density: 5,
|
|
|
|
values: 5,
|
|
|
|
stepped: true
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
public customRulesOpen = false;
|
2018-02-28 12:41:06 +01:00
|
|
|
|
|
|
|
public positivePhrasesArray: Array<Phrase> = [];
|
|
|
|
public negativePhrasesArray: Array<Phrase> = [];
|
|
|
|
public positiveSelectedRow = -1;
|
|
|
|
public negativeSelectedRow = -1;
|
|
|
|
|
|
|
|
positivePhraseForm: FormGroup;
|
|
|
|
negativePhraseForm: FormGroup;
|
|
|
|
|
|
|
|
public settings: Settings;
|
|
|
|
|
2018-03-22 22:32:33 +01:00
|
|
|
constructor(private formBuilder: FormBuilder,
|
|
|
|
private route: ActivatedRoute,
|
|
|
|
private router: Router,
|
|
|
|
private configurationService: ConfigurationService) {
|
|
|
|
}
|
2018-02-28 12:41:06 +01:00
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
this.positivePhraseForm = this.formBuilder.group({
|
|
|
|
phrase: [null, Validators.required],
|
|
|
|
weight: [null, [Validators.required, Validators.min(0), Validators.max(100)]],
|
|
|
|
});
|
|
|
|
this.negativePhraseForm = this.formBuilder.group({
|
|
|
|
phrase: [null, Validators.required],
|
|
|
|
weight: [null, [Validators.required, Validators.min(0), Validators.max(100)]],
|
|
|
|
});
|
|
|
|
this.settings = {
|
|
|
|
docname: localStorage.getItem('docname'),
|
|
|
|
docsnumber: Number.parseInt(localStorage.getItem('docsnumber')),
|
|
|
|
profileid: localStorage.getItem('profileid'),
|
|
|
|
poswords: localStorage.getItem('poswords'),
|
|
|
|
negwords: localStorage.getItem('negwords'),
|
|
|
|
contextprev: Number.parseInt(localStorage.getItem('contextprev')),
|
|
|
|
contextnext: Number.parseInt(localStorage.getItem('contextnext')),
|
|
|
|
wordssplitnum: Number.parseInt(localStorage.getItem('wordssplitnum')),
|
|
|
|
punctuation: Number.parseInt(localStorage.getItem('punctuation')),
|
|
|
|
stopwords: Number.parseInt(localStorage.getItem('stopwords')),
|
2018-03-22 22:32:33 +01:00
|
|
|
lowercase: Number.parseInt(localStorage.getItem('lowercase')),
|
2018-02-28 12:41:06 +01:00
|
|
|
};
|
|
|
|
// show positive phrases
|
|
|
|
this.positivePhrasesArray.length = 0;
|
2018-03-10 18:32:45 +01:00
|
|
|
const posphrases = JSON.parse(localStorage.getItem('poswords'));
|
|
|
|
for (let key in posphrases) {
|
|
|
|
if (key) {
|
2018-02-28 12:41:06 +01:00
|
|
|
const content = new Phrase();
|
|
|
|
content.phrase = key;
|
2018-03-10 18:32:45 +01:00
|
|
|
content.weight = posphrases[key];
|
2018-02-28 12:41:06 +01:00
|
|
|
this.positivePhrasesArray.push(content);
|
|
|
|
}
|
2018-03-10 18:32:45 +01:00
|
|
|
}
|
2018-02-28 12:41:06 +01:00
|
|
|
// show negative phrases
|
|
|
|
this.negativePhrasesArray.length = 0;
|
2018-03-10 18:32:45 +01:00
|
|
|
const negphrases = JSON.parse(localStorage.getItem('negwords'));
|
|
|
|
for (let key in negphrases) {
|
|
|
|
if (key) {
|
2018-02-28 12:41:06 +01:00
|
|
|
const content = new Phrase();
|
|
|
|
content.phrase = key;
|
2018-03-10 18:32:45 +01:00
|
|
|
content.weight = negphrases[key];
|
|
|
|
this.positivePhrasesArray.push(content);
|
2018-02-28 12:41:06 +01:00
|
|
|
}
|
2018-03-10 18:32:45 +01:00
|
|
|
}
|
2018-02-28 12:41:06 +01:00
|
|
|
}
|
|
|
|
|
2018-03-22 22:32:33 +01:00
|
|
|
onSliderChange(value: number): void {
|
|
|
|
value = value + 1;
|
|
|
|
localStorage.setItem('wordssplitnum', value.toString());
|
|
|
|
this.settings.wordssplitnum = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
advancedCheckboxChange() {
|
|
|
|
if (this.customRulesOpen) {
|
|
|
|
this.customRulesOpen = false;
|
|
|
|
} else {
|
|
|
|
this.customRulesOpen = true;
|
|
|
|
}
|
2018-02-28 12:41:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
phraseSubmit(positive: boolean): void {
|
|
|
|
const phrase = new Phrase();
|
|
|
|
if (positive) {
|
|
|
|
phrase.phrase = this.positivePhraseForm.get('phrase').value;
|
|
|
|
phrase.weight = this.positivePhraseForm.get('weight').value;
|
|
|
|
this.positivePhrasesArray.push(phrase);
|
|
|
|
this.positivePhraseForm.reset();
|
|
|
|
} else {
|
|
|
|
phrase.phrase = this.negativePhraseForm.get('phrase').value;
|
|
|
|
phrase.weight = this.negativePhraseForm.get('weight').value;
|
|
|
|
this.negativePhrasesArray.push(phrase);
|
|
|
|
this.negativePhraseForm.reset();
|
|
|
|
}
|
|
|
|
this.phrasesChanged(positive);
|
|
|
|
}
|
|
|
|
|
|
|
|
bulkPutPrhases(phrases: string, positive: boolean): void {
|
|
|
|
if (positive) {
|
|
|
|
localStorage.setItem('poswords', phrases);
|
|
|
|
this.positivePhrasesArray.length = 0;
|
2018-03-10 18:32:45 +01:00
|
|
|
const posphrases = JSON.parse(localStorage.getItem('poswords'));
|
|
|
|
for (let key in posphrases) {
|
|
|
|
if (key) {
|
2018-02-28 12:41:06 +01:00
|
|
|
const content = new Phrase();
|
|
|
|
content.phrase = key;
|
2018-03-10 18:32:45 +01:00
|
|
|
content.weight = posphrases[key];
|
2018-02-28 12:41:06 +01:00
|
|
|
this.positivePhrasesArray.push(content);
|
|
|
|
}
|
2018-03-10 18:32:45 +01:00
|
|
|
}
|
2018-02-28 12:41:06 +01:00
|
|
|
} else {
|
|
|
|
localStorage.setItem('negwords', phrases);
|
|
|
|
this.negativePhrasesArray.length = 0;
|
2018-03-10 18:32:45 +01:00
|
|
|
const negphrases = JSON.parse(localStorage.getItem('negwords'));
|
|
|
|
for (let key in negphrases) {
|
|
|
|
if (key) {
|
2018-02-28 12:41:06 +01:00
|
|
|
const content = new Phrase();
|
|
|
|
content.phrase = key;
|
2018-03-10 18:32:45 +01:00
|
|
|
content.weight = negphrases[key];
|
|
|
|
this.positivePhrasesArray.push(content);
|
2018-02-28 12:41:06 +01:00
|
|
|
}
|
2018-03-10 18:32:45 +01:00
|
|
|
}
|
2018-02-28 12:41:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
deletePhrase(index, positive: boolean): void {
|
|
|
|
if (positive) {
|
|
|
|
this.positivePhrasesArray.splice(index, 1);
|
|
|
|
} else {
|
|
|
|
this.negativePhrasesArray.splice(index, 1);
|
|
|
|
}
|
|
|
|
this.phrasesChanged(positive);
|
|
|
|
}
|
|
|
|
|
|
|
|
selectPhraseRow(row: number, positive: boolean) {
|
|
|
|
if (positive) {
|
|
|
|
this.positiveSelectedRow = row;
|
|
|
|
} else {
|
|
|
|
this.negativeSelectedRow = row;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unselectPhraseRow(positive: boolean) {
|
|
|
|
if (positive) {
|
|
|
|
this.positiveSelectedRow = -1;
|
|
|
|
} else {
|
|
|
|
this.negativeSelectedRow = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
phrasesChanged(positive: boolean): void {
|
|
|
|
const hashmap = {};
|
|
|
|
if (positive) {
|
|
|
|
this.positivePhrasesArray.forEach(function(element) {
|
|
|
|
hashmap[element.phrase] = element.weight;
|
|
|
|
});
|
|
|
|
localStorage.setItem('poswords', JSON.stringify(hashmap));
|
|
|
|
} else {
|
|
|
|
this.negativePhrasesArray.forEach(function(element) {
|
|
|
|
hashmap[element.phrase] = element.weight;
|
|
|
|
});
|
|
|
|
localStorage.setItem('negwords', JSON.stringify(hashmap));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
contextprevChange(value): void {
|
|
|
|
if (value < 0 || value > 20) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
localStorage.setItem('contextprev', value);
|
2018-03-02 11:07:03 +01:00
|
|
|
this.getSettingsFromLocalStorage();
|
2018-02-28 12:41:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
contextnextChange(value): void {
|
|
|
|
if (value < 0 || value > 20) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
localStorage.setItem('contextnext', value);
|
2018-03-02 11:07:03 +01:00
|
|
|
this.getSettingsFromLocalStorage();
|
2018-02-28 12:41:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
wordssplitnumChange(value): void {
|
|
|
|
if (value < 0 || value > 10) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
localStorage.setItem('wordssplitnum', value);
|
2018-03-14 14:40:43 +01:00
|
|
|
this.settings.wordssplitnum = value;
|
2018-02-28 12:41:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
stopwordsCheckBoxChange(value: boolean): void {
|
|
|
|
localStorage.setItem('stopwords', value ? '1' : '0');
|
2018-03-14 14:40:43 +01:00
|
|
|
this.settings.stopwords = value ? 1 : 0;
|
2018-02-28 12:41:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
punctuationCheckBoxChange(value: boolean): void {
|
|
|
|
localStorage.setItem('punctuation', value ? '1' : '0');
|
2018-03-14 14:40:43 +01:00
|
|
|
this.settings.punctuation = value ? 1 : 0;
|
2018-02-28 12:41:06 +01:00
|
|
|
}
|
|
|
|
|
2018-03-22 22:32:33 +01:00
|
|
|
lowercaseCheckBoxChange(value: boolean): void {
|
|
|
|
localStorage.setItem('lowercase', value ? '1' : '0');
|
|
|
|
this.settings.lowercase = value ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
getSettingsFromLocalStorage(): Settings {
|
|
|
|
return this.settings = {
|
|
|
|
docname: localStorage.getItem('docname'),
|
|
|
|
docsnumber: Number.parseInt(localStorage.getItem('docsnumber')),
|
|
|
|
profileid: localStorage.getItem('profileid'),
|
|
|
|
poswords: localStorage.getItem('poswords'),
|
|
|
|
negwords: localStorage.getItem('negwords'),
|
|
|
|
contextprev: Number.parseInt(localStorage.getItem('contextprev')),
|
|
|
|
contextnext: Number.parseInt(localStorage.getItem('contextnext')),
|
|
|
|
wordssplitnum: Number.parseInt(localStorage.getItem('wordssplitnum')),
|
|
|
|
punctuation: Number.parseInt(localStorage.getItem('punctuation')),
|
|
|
|
stopwords: Number.parseInt(localStorage.getItem('stopwords')),
|
|
|
|
lowercase: Number.parseInt(localStorage.getItem('lowercase')),
|
|
|
|
};
|
2018-02-28 12:41:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
saveProfile(): void {
|
|
|
|
this.configurationService.saveProfileParameters(this.getSettingsFromLocalStorage())
|
2018-03-19 13:44:18 +01:00
|
|
|
.subscribe(() => this.router.navigate(['../save-profile'], {relativeTo: this.route, queryParamsHandling: 'preserve'}));
|
2018-02-28 12:41:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|