From 975997b7675876f5596e34533e50d76f1c6c8809 Mon Sep 17 00:00:00 2001 From: Tykayn Date: Fri, 30 Apr 2021 14:15:21 +0200 Subject: [PATCH] splitting date choices with a separator --- src/app/core/models/poll.model.ts | 7 +++ src/app/core/services/api.service.ts | 10 --- src/app/core/services/poll.service.ts | 32 +++++++++- src/app/core/services/storage.service.ts | 7 +++ .../administration.component.ts | 4 +- .../date-select/date-select.component.html | 54 ++++++++-------- .../administration/form/form.component.html | 2 + .../success/success.component.html | 62 +++++++++++++++++-- .../success/success.component.ts | 13 +++- .../consultation/consultation.component.ts | 6 +- src/app/routes-framadate.ts | 4 +- 11 files changed, 151 insertions(+), 50 deletions(-) diff --git a/src/app/core/models/poll.model.ts b/src/app/core/models/poll.model.ts index 805662aa..7b66cc90 100644 --- a/src/app/core/models/poll.model.ts +++ b/src/app/core/models/poll.model.ts @@ -6,6 +6,11 @@ import { PollConfiguration } from './configuration.model'; import { Owner } from './owner.model'; import { DateChoice, TimeSlices } from '../../../../mocks/old-stuff/config/defaultConfigs'; +export class ChoiceGroup { + date_string: string; + choices: Choice[]; +} + export class Poll { public id = 0; @@ -42,6 +47,8 @@ export class Poll { public choices: Choice[] = []; + public choicesDateGrouped: ChoiceGroup[] = []; + public votes = []; public stacks = []; diff --git a/src/app/core/services/api.service.ts b/src/app/core/services/api.service.ts index 73dc252b..8f95aade 100644 --- a/src/app/core/services/api.service.ts +++ b/src/app/core/services/api.service.ts @@ -183,19 +183,9 @@ export class ApiService { public async getPollByCustomUrl(slug: string): Promise { try { - // TODO: this interceptor should be avoided if backends returns the good object - const adapterInterceptor: number = this.axiosInstance.interceptors.response.use( - (response: AxiosResponse): AxiosResponse => { - console.log('response', response); - return response; - } - ); - const response: AxiosResponse = await this.axiosInstance.get(`${this.pollsEndpoint}/${slug}`); console.log('fetch API : asking for poll with custom_url=' + slug, { response }); - axios.interceptors.request.eject(adapterInterceptor); - return response && response.data && !Array.isArray(response.data) ? response.data : undefined; } catch (error) { if (error.response?.status === 404) { diff --git a/src/app/core/services/poll.service.ts b/src/app/core/services/poll.service.ts index 904a4e14..85316d11 100644 --- a/src/app/core/services/poll.service.ts +++ b/src/app/core/services/poll.service.ts @@ -20,7 +20,7 @@ import { TimeSlices } from '../../../../mocks/old-stuff/config/defaultConfigs'; providedIn: 'root', }) export class PollService implements Resolve { - private _poll: BehaviorSubject = new BehaviorSubject(undefined); + _poll: BehaviorSubject = new BehaviorSubject(undefined); public readonly poll: Observable = this._poll.asObservable(); constructor( @@ -42,6 +42,8 @@ export class PollService implements Resolve { public async resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise { const segments: string[] = state.url.split('/'); const wantedcustom_url: string = segments.includes('poll') ? segments[segments.indexOf('poll') + 1] : ''; + + // FIXME should be handled by routing if (!wantedcustom_url && state.url.includes('administration')) { // creation of new poll const poll = new Poll(this.userService.getCurrentUser(), this.uuidService.getUUID(), ''); @@ -100,7 +102,14 @@ export class PollService implements Resolve { } } + /** + * update poll and parse its fields + * @param poll + */ public updateCurrentPoll(poll: Poll): void { + if (poll.kind == 'date') { + poll.choices = this.parseDateChoices(poll.choices); + } this.storageService.setChoicesForVoteStack(poll.choices); this.toastService.display('sondage bien mis à jour', 'success'); @@ -207,4 +216,25 @@ export class PollService implements Resolve { console.log('newpoll', newpoll); return newpoll; } + + public parseDateChoices(choices: Choice[]) { + const SEPARATOR_DATE_TIME_SLICE = ' >>> '; + const parsedChoices = []; + + for (const c of choices) { + const time_list = []; + const choice = { name: c.name }; + if (c.name.includes(SEPARATOR_DATE_TIME_SLICE)) { + const date_string = ''; + const time_slice = ''; + choice.name = time_slice; + } + parsedChoices.push({ + date_string: choice, + choices: c, + }); + } + console.log('parsedChoices', parsedChoices); + return []; + } } diff --git a/src/app/core/services/storage.service.ts b/src/app/core/services/storage.service.ts index d7e4e2fc..12d67cbd 100644 --- a/src/app/core/services/storage.service.ts +++ b/src/app/core/services/storage.service.ts @@ -39,6 +39,7 @@ export class StorageService { 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')); @@ -70,4 +71,10 @@ export class StorageService { } return false; } + + parseDateChoices(datechoices) { + const choices: Choice[] = []; + + return choices; + } } diff --git a/src/app/features/administration/administration.component.ts b/src/app/features/administration/administration.component.ts index 5111b2e2..720a359e 100644 --- a/src/app/features/administration/administration.component.ts +++ b/src/app/features/administration/administration.component.ts @@ -3,8 +3,6 @@ import { ActivatedRoute } from '@angular/router'; import { Subscription } from 'rxjs'; import { Poll } from '../../core/models/poll.model'; -import { ModalService } from '../../core/services/modal.service'; -import { UserService } from '../../core/services/user.service'; @Component({ selector: 'app-administration', @@ -15,7 +13,7 @@ export class AdministrationComponent implements OnInit, OnDestroy { public poll: Poll = new Poll(); private routeSubscription: Subscription; - constructor(private route: ActivatedRoute, private userService: UserService, private modalService: ModalService) {} + constructor(private route: ActivatedRoute) {} ngOnInit(): void { this.routeSubscription = this.route.data.subscribe((data: { poll: Poll }) => { diff --git a/src/app/features/administration/form/date-select/date-select.component.html b/src/app/features/administration/form/date-select/date-select.component.html index 034b2233..a7cbf852 100644 --- a/src/app/features/administration/form/date-select/date-select.component.html +++ b/src/app/features/administration/form/date-select/date-select.component.html @@ -204,34 +204,34 @@ -
- + + + + - - -
-
- -
-
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/app/features/administration/form/form.component.html b/src/app/features/administration/form/form.component.html index 50adfa27..6be19904 100644 --- a/src/app/features/administration/form/form.component.html +++ b/src/app/features/administration/form/form.component.html @@ -1,4 +1,6 @@
+ +
diff --git a/src/app/features/administration/success/success.component.html b/src/app/features/administration/success/success.component.html index cb3015cf..5c87e8e5 100644 --- a/src/app/features/administration/success/success.component.html +++ b/src/app/features/administration/success/success.component.html @@ -1,16 +1,70 @@
-

- Création de sondage réussie +

+ {{ 'resume.title' | translate }}

- Bravo! partagez le lien de votre sondage. Un récapitulatif a été envoyé à votre adresse email. + {{ 'resume.admins' | translate }}


- image succès +
+

+

+ Votre sondage « + + {{ poll.title }} + + » a bien été créé ! +

+

+ Voici les liens d’accès au sondage, conservez-les soigneusement ! (Si vous les perdez vous pourrez toujours + les recevoir par email) +

+ +

+ Pour accéder au sondage et à tous ses paramètres : + {{ poll.custom_url }} +

+ + + Voir le sondage coté administrateur·ice + +

+ Note : Le sondage sera supprimé {{ poll.default_expiracy_days_from_now }} jours après la date de sa dernière + modification. +

+
+
+

{{ 'resume.users' | translate }}

+

+ Pour accéder au sondage : + {{ poll.custom_url }} +

+ + + Voir le sondage + +
+
+

{{ 'resume.links_mail' | translate }}

+

+ Pour être sur de retrouver ces liens, nous pouvons vous les envoyer sur votre mail : + +

+ + + + Voir le sondage + +
+ +
diff --git a/src/app/features/administration/success/success.component.ts b/src/app/features/administration/success/success.component.ts index 13e175db..5d9a0d1a 100644 --- a/src/app/features/administration/success/success.component.ts +++ b/src/app/features/administration/success/success.component.ts @@ -1,4 +1,6 @@ -import { Component, OnInit } from '@angular/core'; +import { Component, Input, OnInit } from '@angular/core'; +import { PollService } from '../../../core/services/poll.service'; +import { Poll } from '../../../core/models/poll.model'; @Component({ selector: 'app-success', @@ -6,7 +8,14 @@ import { Component, OnInit } from '@angular/core'; styleUrls: ['./success.component.scss'], }) export class SuccessComponent implements OnInit { - constructor() {} + @Input() poll: Poll; + mailToRecieve: string; + + constructor(private pollService: PollService) {} ngOnInit(): void {} + + sendToEmail() { + alert('todo'); + } } diff --git a/src/app/features/consultation/consultation.component.ts b/src/app/features/consultation/consultation.component.ts index abec918a..53342e94 100644 --- a/src/app/features/consultation/consultation.component.ts +++ b/src/app/features/consultation/consultation.component.ts @@ -96,7 +96,11 @@ export class ConsultationComponent implements OnInit, OnDestroy { this.toastService.display('vote ajouté', 'success'); if (resp) { - this.api.getPollByCustomUrl(this.poll.custom_url); + const response: Promise = this.api.getPollByCustomUrl(this.poll.custom_url); + response.then((res: Poll | undefined) => { + res.choices = this.pollService.parseDateChoices(res.choices); + this.pollService._poll.next(res); + }); } else { this.toastService.display('erreur à la réception du nouveau vote', 'error'); } diff --git a/src/app/routes-framadate.ts b/src/app/routes-framadate.ts index b7c61df2..fa93c168 100644 --- a/src/app/routes-framadate.ts +++ b/src/app/routes-framadate.ts @@ -19,7 +19,7 @@ export const routes: Routes = [ path: 'administration', loadChildren: () => import('./features/administration/administration.module').then((m) => m.AdministrationModule), - // resolve: {poll: PollService}, + // resolve: { poll: PollService }, }, { path: 'poll/:custom_url/administration', @@ -30,7 +30,7 @@ export const routes: Routes = [ { path: 'poll/:custom_url/consultation', loadChildren: () => import('./features/consultation/consultation.module').then((m) => m.ConsultationModule), - // resolve: { poll: PollService }, + resolve: { poll: PollService }, }, { path: 'poll/:custom_url/participation',