forked from tykayn/funky-framadate-front
set choices and toggle votes in votestack
This commit is contained in:
parent
620a7b99fa
commit
f1e6b5955e
@ -1,4 +1,10 @@
|
||||
export class Vote {
|
||||
public choice_id: number;
|
||||
public value: string; // valeur de réponse
|
||||
|
||||
constructor(choice_id?) {
|
||||
if (choice_id) {
|
||||
this.choice_id = choice_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import { UserService } from './user.service';
|
||||
import { UuidService } from './uuid.service';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { environment } from '../../../environments/environment';
|
||||
import { StorageService } from './storage.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
@ -24,6 +25,7 @@ export class PollService implements Resolve<Poll> {
|
||||
private http: HttpClient,
|
||||
private router: Router,
|
||||
private apiService: ApiService,
|
||||
private storageService: StorageService,
|
||||
private userService: UserService,
|
||||
private uuidService: UuidService,
|
||||
private toastService: ToastService
|
||||
@ -86,6 +88,8 @@ export class PollService implements Resolve<Poll> {
|
||||
}
|
||||
|
||||
public updateCurrentPoll(poll: Poll): void {
|
||||
this.storageService.setChoicesForVoteStack(poll.choices);
|
||||
|
||||
console.log('poll', poll);
|
||||
this._poll.next(poll);
|
||||
}
|
||||
|
@ -4,6 +4,8 @@ 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';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
@ -20,4 +22,24 @@ export class StorageService {
|
||||
|
||||
@LocalStorage()
|
||||
public vote_stack: Stack = new Stack();
|
||||
|
||||
setChoicesForVoteStack(choices_list: Choice[]) {
|
||||
this.vote_stack.votes = [];
|
||||
|
||||
for (let choice of choices_list) {
|
||||
this.vote_stack.votes.push(new Vote(choice.id));
|
||||
}
|
||||
}
|
||||
|
||||
toggleAnswer(choice_id: number, value: string) {
|
||||
for (let vote of this.vote_stack.votes) {
|
||||
if (vote.choice_id == choice_id) {
|
||||
if (vote.value) {
|
||||
vote.value = '';
|
||||
} else {
|
||||
vote.value = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
<section class="loading_poll" *ngIf="fetching"></section>
|
||||
<section class="poll_loaded padded" *ngIf="!fetching && poll">
|
||||
<!-- infos locales storage-->
|
||||
mon pseudo : {{ storageService.vote_stack.pseudo }}
|
||||
<div class="well debug">
|
||||
<!-- infos locales storage-->
|
||||
debug: {{ storageService.vote_stack | json }}
|
||||
</div>
|
||||
|
||||
<!-- messages-->
|
||||
|
||||
|
@ -24,7 +24,7 @@
|
||||
</div>
|
||||
<div class="column is-narrow">
|
||||
<div class="buttons has-addons is-right">
|
||||
<button class="button is-white">
|
||||
<button class="button is-white" (click)="toggleAnswer(choice.id, 'yes')">
|
||||
<img class="image is-24x24" src="../../../assets/img/icon_voter_YES.svg" />
|
||||
|
||||
<span class="counter" *ngIf="choice[answerEnum.YES].count * 1 > 0">
|
||||
|
@ -6,6 +6,7 @@ import { Choice } from '../../../core/models/choice.model';
|
||||
import { Poll } from '../../../core/models/poll.model';
|
||||
import { ModalService } from '../../../core/services/modal.service';
|
||||
import { ChoiceDetailsComponent } from '../../../shared/components/choice-details/choice-details.component';
|
||||
import { StorageService } from '../../../core/services/storage.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-poll-results-compact',
|
||||
@ -16,7 +17,7 @@ export class PollResultsCompactComponent implements OnInit {
|
||||
@Input() public poll: Poll;
|
||||
public answerEnum = Answer;
|
||||
|
||||
constructor(private modalService: ModalService) {}
|
||||
constructor(private modalService: ModalService, private storageService: StorageService) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
console.log('this.poll', this.poll);
|
||||
@ -26,4 +27,8 @@ export class PollResultsCompactComponent implements OnInit {
|
||||
const config: MatDialogConfig<any> = { data: choice };
|
||||
this.modalService.openModal<ChoiceDetailsComponent, Choice>(ChoiceDetailsComponent, config);
|
||||
}
|
||||
|
||||
toggleAnswer(choice_id: number, value: string) {
|
||||
this.storageService.toggleAnswer(choice_id, value);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user