2020-04-22 12:56:18 +02:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
import { LocalStorage } from 'ngx-webstorage';
|
|
|
|
|
|
|
|
import { Language } from '../enums/language.enum';
|
|
|
|
import { Theme } from '../enums/theme.enum';
|
2021-04-28 12:01:09 +02:00
|
|
|
import { Stack } from '../models/stack.model';
|
2021-04-28 12:15:49 +02:00
|
|
|
import { Choice } from '../models/choice.model';
|
|
|
|
import { Vote } from '../models/vote.model';
|
2021-04-28 14:33:41 +02:00
|
|
|
import { environment } from '../../../environments/environment';
|
2020-04-22 12:56:18 +02:00
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
providedIn: 'root',
|
|
|
|
})
|
|
|
|
export class StorageService {
|
|
|
|
@LocalStorage()
|
|
|
|
public theme: Theme;
|
|
|
|
|
|
|
|
@LocalStorage()
|
|
|
|
public language: Language;
|
|
|
|
|
|
|
|
@LocalStorage()
|
|
|
|
public userPollsIds: string[];
|
2020-05-05 18:17:12 +02:00
|
|
|
|
|
|
|
@LocalStorage()
|
2021-04-28 12:01:09 +02:00
|
|
|
public vote_stack: Stack = new Stack();
|
2021-04-28 12:15:49 +02:00
|
|
|
|
|
|
|
setChoicesForVoteStack(choices_list: Choice[]) {
|
|
|
|
this.vote_stack.votes = [];
|
|
|
|
|
|
|
|
for (let choice of choices_list) {
|
2021-04-28 14:33:41 +02:00
|
|
|
if (environment.autofill) {
|
|
|
|
this.vote_stack.votes.push(new Vote(choice.id, 'yes'));
|
|
|
|
} else {
|
|
|
|
this.vote_stack.votes.push(new Vote(choice.id));
|
|
|
|
}
|
2021-04-28 12:15:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
toggleAnswer(choice_id: number, value: string) {
|
|
|
|
for (let vote of this.vote_stack.votes) {
|
|
|
|
if (vote.choice_id == choice_id) {
|
2021-04-28 12:22:40 +02:00
|
|
|
if (vote.value == value) {
|
2021-04-28 12:15:49 +02:00
|
|
|
vote.value = '';
|
|
|
|
} else {
|
|
|
|
vote.value = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-04-28 12:22:40 +02:00
|
|
|
|
|
|
|
choiceHasAnswerOfValue(choice_id: number, value: any) {
|
|
|
|
for (let vote of this.vote_stack.votes) {
|
|
|
|
if (vote.choice_id == choice_id) {
|
|
|
|
if (vote.value == value) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2020-04-22 12:56:18 +02:00
|
|
|
}
|