From 406bf71b9229329b2f17b5760739ff8a38427a86 Mon Sep 17 00:00:00 2001 From: Tykayn Date: Thu, 20 May 2021 12:51:25 +0200 Subject: [PATCH] random autofill on view page of a poll --- src/app/core/models/stack.model.ts | 6 +++--- src/app/core/services/storage.service.ts | 12 ++++++++++-- .../poll-results-compact.component.html | 10 +++++----- .../poll-results-compact.component.ts | 4 ++++ .../choice-item/choice-button.component.html | 2 +- .../choice-item/choice-button.component.scss | 12 ++++++++++++ 6 files changed, 35 insertions(+), 11 deletions(-) diff --git a/src/app/core/models/stack.model.ts b/src/app/core/models/stack.model.ts index 81c0d5a7..8d9c02c7 100644 --- a/src/app/core/models/stack.model.ts +++ b/src/app/core/models/stack.model.ts @@ -3,8 +3,8 @@ import { Owner } from './owner.model'; export class Stack { public id: number; - public pseudo: string = 'Choque Nourrice'; - public comment: string = 'Le beau commentaire de Choque Nourrice'; + public pseudo = 'Choque Nourrice'; + public comment = 'Le beau commentaire de Choque Nourrice'; public owner: Owner = new Owner(); - public votes: Vote[]; + public votes: Vote[] = []; } diff --git a/src/app/core/services/storage.service.ts b/src/app/core/services/storage.service.ts index d8ddcdd5..53955ceb 100644 --- a/src/app/core/services/storage.service.ts +++ b/src/app/core/services/storage.service.ts @@ -18,6 +18,7 @@ import { import { Poll } from '../models/poll.model'; import { Owner } from '../models/owner.model'; import { DateUtilitiesService } from './date.utilities.service'; +import { ToastService } from './toast.service'; @Injectable({ providedIn: 'root', @@ -44,8 +45,13 @@ export class StorageService { @LocalStorage() public choices: Choice[] = []; - constructor(public dateUtilities: DateUtilitiesService) { + constructor( + public dateUtilities: DateUtilitiesService, + + private toastService: ToastService + ) { if (environment.autofill) { + this.toastService.display('autofill des sondages utilisateur'); 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( @@ -64,7 +70,9 @@ export class StorageService { // text choices for (const choice of choices_list) { if (environment.autofill) { - this.vote_stack.votes.push(new Vote(choice.id, 'yes')); + this.toastService.display('autofill au hasard des votes à ce sondage'); + const defaultvalue = Math.random() > 0.75 ? 'yes' : ''; + this.vote_stack.votes.push(new Vote(choice.id, defaultvalue)); } else { this.vote_stack.votes.push(new Vote(choice.id)); } diff --git a/src/app/features/consultation/poll-results-compact/poll-results-compact.component.html b/src/app/features/consultation/poll-results-compact/poll-results-compact.component.html index 73b87c07..e028368b 100644 --- a/src/app/features/consultation/poll-results-compact/poll-results-compact.component.html +++ b/src/app/features/consultation/poll-results-compact/poll-results-compact.component.html @@ -2,9 +2,9 @@

- {{ group.date_string }} + {{ showAsDate(group.date_string) | date: 'fullDate':'Europe/Paris':'fr_FR' }}

-
+
- + + +
diff --git a/src/app/features/consultation/poll-results-compact/poll-results-compact.component.ts b/src/app/features/consultation/poll-results-compact/poll-results-compact.component.ts index d370f441..6df66375 100644 --- a/src/app/features/consultation/poll-results-compact/poll-results-compact.component.ts +++ b/src/app/features/consultation/poll-results-compact/poll-results-compact.component.ts @@ -31,4 +31,8 @@ export class PollResultsCompactComponent implements OnInit { toggleAnswer(choice_id: number, value: string) { this.storageService.toggleAnswer(choice_id, value); } + + showAsDate(date_string: string) { + return new Date(date_string); + } } diff --git a/src/app/shared/components/choice-item/choice-button.component.html b/src/app/shared/components/choice-item/choice-button.component.html index 314d4401..cad21d00 100644 --- a/src/app/shared/components/choice-item/choice-button.component.html +++ b/src/app/shared/components/choice-item/choice-button.component.html @@ -1,5 +1,5 @@