front end version 2 de framadate, un gestionnaire de sondage
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
funky-framadate-front/src/app/core/services/storage.service.ts

88 lines
2.2 KiB

import { Injectable } from '@angular/core';
import { LocalStorage } from 'ngx-webstorage';
import { Language } from '../enums/language.enum';
import { Theme } from '../enums/theme.enum';
import { Stack } from '../models/stack.model';
import { Choice } from '../models/choice.model';
import { Vote } from '../models/vote.model';
import { environment } from '../../../environments/environment';
import {
basicSlicesOfDay,
DateChoice,
moreTimeOfDay,
otherDefaultDates,
TimeSlices,
} from '../../../../mocks/old-stuff/config/defaultConfigs';
import { Poll } from '../models/poll.model';
import { Owner } from '../models/owner.model';
@Injectable({
providedIn: 'root',
})
export class StorageService {
@LocalStorage()
public theme: Theme;
@LocalStorage()
public language: Language;
@LocalStorage()
public userPolls: Poll[] = [];
@LocalStorage()
public dateList: DateChoice[] = otherDefaultDates;
@LocalStorage()
public timeSlices: TimeSlices[] = basicSlicesOfDay;
@LocalStorage()
public vote_stack: Stack = new Stack();
constructor() {
if (environment.autofill) {
this.userPolls.push(new Poll(new Owner(), 'Démo: Anniversaire de tonton Patrick', 'aujourdhui-ou-demain'));
this.userPolls.push(new Poll(new Owner(), 'Démo: Atelier cuisine du quartier', 'aujourdhui-ou-demain'));
this.userPolls.push(
new Poll(new Owner(), 'Démo: Réunion du département des chatons', 'aujourdhui-ou-demain')
);
}
}
setChoicesForVoteStack(choices_list: Choice[]) {
this.vote_stack.votes = [];
// text choices
for (const choice of choices_list) {
if (environment.autofill) {
this.vote_stack.votes.push(new Vote(choice.id, 'yes'));
} else {
this.vote_stack.votes.push(new Vote(choice.id));
}
}
}
toggleAnswer(choice_id: number, value: string) {
console.log('this.vote_stack', this.vote_stack);
for (const vote of this.vote_stack.votes) {
if (vote.choice_id == choice_id) {
if (vote.value == value) {
vote.value = '';
} else {
vote.value = value;
}
}
}
}
choiceHasAnswerOfValue(choice_id: number, value: any) {
for (const vote of this.vote_stack.votes) {
if (vote.choice_id == choice_id) {
if (vote.value == value) {
return true;
}
}
}
return false;
}
}