From 5f555136cf149f98e54b9b9fd1fcb548a7b89937 Mon Sep 17 00:00:00 2001 From: Tykayn Date: Thu, 18 Nov 2021 12:51:59 +0100 Subject: [PATCH] landing link on consultation, check allowed answers --- .../consultation-landing.component.html | 12 ++- .../consultation-landing.component.ts | 74 ++++++++++++++++++- .../consultation-routing.module.ts | 9 ++- .../poll-results-compact.component.html | 21 +++++- .../poll-results-detailed.component.html | 19 ++++- src/app/routes-framadate.ts | 1 - src/environments/environment.prod.ts | 10 +-- src/environments/environment.ts | 6 +- 8 files changed, 126 insertions(+), 26 deletions(-) diff --git a/src/app/features/consultation/consultation-landing/consultation-landing.component.html b/src/app/features/consultation/consultation-landing/consultation-landing.component.html index 929c7c57..e9545747 100644 --- a/src/app/features/consultation/consultation-landing/consultation-landing.component.html +++ b/src/app/features/consultation/consultation-landing/consultation-landing.component.html @@ -1,24 +1,22 @@ -
-

- vous invite à participer à son sondage -

+
+

{{ pollService._poll.getValue().creatorPseudo }} vous invite à participer à son sondage

{{ pollService._poll.getValue().title }}

- Si l’administrateur du sondage a ajouter une description elle sera affiché ici. + {{ pollService._poll.getValue().description }}

Fin du sondage le - 14/11/2021 + {{ pollService._poll.getValue().expiracy_date | date }}

diff --git a/src/app/features/consultation/consultation-landing/consultation-landing.component.ts b/src/app/features/consultation/consultation-landing/consultation-landing.component.ts index 6a31c7e3..c7fd6d35 100644 --- a/src/app/features/consultation/consultation-landing/consultation-landing.component.ts +++ b/src/app/features/consultation/consultation-landing/consultation-landing.component.ts @@ -1,5 +1,13 @@ import { Component, OnInit } from '@angular/core'; import { PollService } from '../../../core/services/poll.service'; +import { Poll } from '../../../core/models/poll.model'; +import { Subscription } from 'rxjs'; +import { ActivatedRoute, ParamMap, Router } from '@angular/router'; +import { PollUtilitiesService } from '../../../core/services/poll.utilities.service'; +import { StorageService } from '../../../core/services/storage.service'; +import { ApiService } from '../../../core/services/api.service'; +import { DateService } from '../../../core/services/date.service'; +import { ToastService } from '../../../core/services/toast.service'; @Component({ selector: 'app-consultation-landing', @@ -7,7 +15,69 @@ import { PollService } from '../../../core/services/poll.service'; styleUrls: ['./consultation-landing.component.scss'], }) export class ConsultationLandingComponent implements OnInit { - constructor(public pollService: PollService) {} + public poll: Poll; + public pollSlug: string; + public pass_hash: string; + public fetching = true; + public isArchived: boolean; + public isAdmin: boolean; - ngOnInit(): void {} + private routeSubscription: Subscription; + window: any; + + constructor( + private router: Router, + private utils: PollUtilitiesService, + private _Activatedroute: ActivatedRoute, + public storageService: StorageService, + public api: ApiService, + public pollService: PollService, + public dateService: DateService, + public toastService: ToastService + ) {} + + /** + * fetch poll data on init + */ + ngOnInit(): void { + console.log('constultation de poll'); + this.pollService.poll.subscribe((newpoll: Poll) => { + this.poll = newpoll; + if (newpoll) { + this.isArchived = new Date(newpoll.expiracy_date) < new Date(); + this.poll.is_archived = this.isArchived; + this.isAdmin = this.poll.admin_key !== null; + this.poll.choices_grouped.map((elem) => (elem.subSetToYes = false)); + } + }); + + this._Activatedroute.paramMap.subscribe((params: ParamMap) => { + console.log('params _Activatedroute', params); + this.pollSlug = params.get('custom_url'); + this.pass_hash = params.get('pass_hash'); + + console.log('this.pass_hash ', this.pass_hash); + if (this.pass_hash) { + this.pollService.loadPollByCustomUrlWithPasswordHash(this.pollSlug, this.pass_hash).then((resp) => { + console.log('loadPollByCustomUrlWithPasswordHash resp', resp); + this.fetching = false; + this.storageService.vote_stack.id = null; + this.storageService.setChoicesForVoteStack(this.pollService._poll.getValue().choices); + }); + } else { + this.pollService.loadPollByCustomUrl(this.pollSlug).then((resp) => { + console.log('loadPollByCustomUrl resp', resp); + this.fetching = false; + this.storageService.vote_stack.id = null; + this.storageService.setChoicesForVoteStack(this.pollService._poll.getValue().choices); + }); + } + }); + } + + ngOnDestroy(): void { + if (this.routeSubscription) { + this.routeSubscription.unsubscribe(); + } + } } diff --git a/src/app/features/consultation/consultation-routing.module.ts b/src/app/features/consultation/consultation-routing.module.ts index 72568688..ed4d6798 100644 --- a/src/app/features/consultation/consultation-routing.module.ts +++ b/src/app/features/consultation/consultation-routing.module.ts @@ -7,22 +7,23 @@ import { PasswordPromptComponent } from './password/password-prompt/password-pro import { ConsultationLandingComponent } from './consultation-landing/consultation-landing.component'; import { SuccessComponent } from './success/success.component'; import { ConsultationUserComponent } from './consultation-user/consultation-user.component'; +import { PageNotFoundComponent } from '../../shared/components/page-not-found/page-not-found.component'; const routes: Routes = [ { path: '', component: ConsultationLandingComponent, - children: [], }, - + { path: 'simple', component: ConsultationComponent }, { path: 'secure/:pass_hash', component: ConsultationComponent }, { path: 'prompt', component: PasswordPromptComponent }, - { path: 'simple', component: WipTodoComponent }, { path: 'table', component: WipTodoComponent }, - { path: 'user-info', component: ConsultationUserComponent }, { path: 'success', component: SuccessComponent }, + { path: 'page-not-found', component: PageNotFoundComponent }, + { path: '**', redirectTo: 'page-not-found', pathMatch: 'full' }, ]; + @NgModule({ imports: [RouterModule.forChild(routes)], exports: [RouterModule], 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 38ba8d5d..1eaca5cc 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 @@ -31,9 +31,24 @@
- - - + + +
diff --git a/src/app/features/consultation/poll-results-detailed/poll-results-detailed.component.html b/src/app/features/consultation/poll-results-detailed/poll-results-detailed.component.html index 905fffa8..89a91a0a 100644 --- a/src/app/features/consultation/poll-results-detailed/poll-results-detailed.component.html +++ b/src/app/features/consultation/poll-results-detailed/poll-results-detailed.component.html @@ -49,7 +49,24 @@
- + + + diff --git a/src/app/routes-framadate.ts b/src/app/routes-framadate.ts index f2d7d619..51383ddf 100644 --- a/src/app/routes-framadate.ts +++ b/src/app/routes-framadate.ts @@ -24,7 +24,6 @@ export const routes: Routes = [ { path: 'poll/:custom_url/consultation', loadChildren: () => import('./features/consultation/consultation.module').then((m) => m.ConsultationModule), - // resolve: { poll: PollService }, }, { path: 'success', diff --git a/src/environments/environment.prod.ts b/src/environments/environment.prod.ts index 646996e4..7d8c1949 100644 --- a/src/environments/environment.prod.ts +++ b/src/environments/environment.prod.ts @@ -14,17 +14,17 @@ const apiV1 = { export const environment = { frontDomain: 'https://framadate-api.cipherbliss.com', production: true, - display_routes: true, - showDemoWarning: true, + display_routes: false, + showDemoWarning: false, autofill_creation: true, - autofill_participation: true, + autofill_participation: false, advanced_options_display: false, autoSendNewPoll: false, interval_days_default: 7, showStepperShortcuts: true, expiresDaysDelay: 60, - maxCountOfAnswers: 150, - appTitle: 'FramaDate Funky', + maxCountOfAnswers: 300, + appTitle: 'FramaDate', appVersion: '2.1.0', appLogo: 'assets/img/logo.png', api: { diff --git a/src/environments/environment.ts b/src/environments/environment.ts index 84964537..a8192321 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -10,13 +10,13 @@ endpoints.baseHref = apiV1.baseHref; export const environment = { frontDomain: 'http://127.0.0.1:4200', production: false, - display_routes: true, // demo paths to test polls - autofill_creation: true, + display_routes: false, // demo paths to test polls + autofill_creation: false, advanced_options_display: false, autofill_participation: false, showDemoWarning: false, autoSendNewPoll: false, - showStepperShortcuts: true, + showStepperShortcuts: false, interval_days_default: 7, expiresDaysDelay: 60, maxCountOfAnswers: 300,