diff --git a/src/app/core/components/header/header.component.html b/src/app/core/components/header/header.component.html index 8010fc3d..8a419e57 100644 --- a/src/app/core/components/header/header.component.html +++ b/src/app/core/components/header/header.component.html @@ -98,7 +98,7 @@ diff --git a/src/app/core/models/stack.model.ts b/src/app/core/models/stack.model.ts index ba44ea15..4d7610e3 100644 --- a/src/app/core/models/stack.model.ts +++ b/src/app/core/models/stack.model.ts @@ -4,6 +4,7 @@ import { Owner } from './owner.model'; export class Stack { public id: number; public poll_custom_url: string; + public pass_hash: string; public pseudo = 'Choque Nourrice'; public comment = 'Le beau commentaire de Choque Nourrice'; public owner: Owner = new Owner(); diff --git a/src/app/core/services/api.service.ts b/src/app/core/services/api.service.ts index 362470fb..94196174 100644 --- a/src/app/core/services/api.service.ts +++ b/src/app/core/services/api.service.ts @@ -93,20 +93,15 @@ export class ApiService { * @param vote_stack */ public sendNewVoteStackOfPoll(vote_stack: Stack): Promise { - // api_new_vote_stack POST ANY ANY /api/v1/poll/{id}/answer - - console.log('vote_stack', vote_stack); - console.log('this.baseHref', this.baseHref); - const headers = ApiService.makeHeaders(vote_stack); - console.log('headers', headers); + // const headers = ApiService.makeHeaders(vote_stack); const url = `${this.baseHref}/vote-stack/`; - const axiosconf = { - url, - method: 'POST', - body: vote_stack, - headers, - }; + // const axiosconf = { + // url, + // method: 'POST', + // body: vote_stack, + // headers, + // }; return this.axiosInstance.post(url, vote_stack); } diff --git a/src/app/core/services/poll.service.ts b/src/app/core/services/poll.service.ts index 42e55394..5114b7c8 100644 --- a/src/app/core/services/poll.service.ts +++ b/src/app/core/services/poll.service.ts @@ -24,6 +24,7 @@ import { Vote } from '../models/vote.model'; export class PollService implements Resolve { _poll: BehaviorSubject = new BehaviorSubject(undefined); public readonly poll: Observable = this._poll.asObservable(); + public pass_hash: string; constructor( private http: HttpClient, @@ -54,10 +55,17 @@ export class PollService implements Resolve { !this._poll.getValue().custom_url || this._poll.getValue().custom_url !== wantedcustom_url ) { - await this.loadPollBycustom_url(wantedcustom_url); + if (this.pass_hash) { + this.storageService.vote_stack.pass_hash = this.pass_hash; + await this.loadPollBycustom_urlWithPasswordHash(wantedcustom_url, this.pass_hash); + } else { + await this.loadPollBycustom_url(wantedcustom_url); + } } - if (this._poll.getValue()) { - return this._poll.getValue(); + const loadedPoll = this._poll.getValue(); + if (loadedPoll) { + this.storageService.vote_stack.poll_custom_url = loadedPoll.custom_url; + return loadedPoll; } else { this.router.navigate(['page-not-found']); return; @@ -104,7 +112,7 @@ export class PollService implements Resolve { this.titleService.setTitle(`☑️ ${poll.title} - ${environment.appTitle}`); } else { this.toastService.display(`sondage ${custom_url} non trouvé`); - // this.router.navigate(['page-not-found']); + this.router.navigate(['page-not-found']); } } else { this.toastService.display(`sondage sans custom url : ${custom_url}`); @@ -120,8 +128,12 @@ export class PollService implements Resolve { if (!this.storageService.vote_stack.id || this.storageService.vote_stack.poll_custom_url !== poll.custom_url) { console.log('set base choices', poll.choices); - // set the choices only the first time the poll loads - this.storageService.setChoicesForVoteStack(poll.choices); + // set the choices only the first time the poll loads, or if we changed the poll + console.log( + 'this.storageService.vote_stack.poll_custom_url', + this.storageService.vote_stack.poll_custom_url + ); + // this.storageService.setChoicesForVoteStack(poll.choices); } this.toastService.display('sondage bien mis à jour', 'success'); diff --git a/src/app/core/services/storage.service.ts b/src/app/core/services/storage.service.ts index 397026c9..c173c8f0 100644 --- a/src/app/core/services/storage.service.ts +++ b/src/app/core/services/storage.service.ts @@ -65,7 +65,8 @@ export class StorageService { * @param choices_list */ setChoicesForVoteStack(choices_list: Choice[]) { - // text choices + // change only if the poll custom_url changed or if there is no stack id for this poll + if (!this.vote_stack.id) { this.vote_stack = new Stack(); diff --git a/src/app/features/consultation/consultation-routing.module.ts b/src/app/features/consultation/consultation-routing.module.ts index 8bba5525..b1f36c89 100644 --- a/src/app/features/consultation/consultation-routing.module.ts +++ b/src/app/features/consultation/consultation-routing.module.ts @@ -6,7 +6,6 @@ import { WipTodoComponent } from '../../shared/components/ui/wip-todo/wip-todo.c const routes: Routes = [ { path: 'secure/:pass_hash', component: ConsultationComponent }, - { path: '', component: ConsultationComponent, diff --git a/src/app/features/consultation/consultation.component.html b/src/app/features/consultation/consultation.component.html index ac34e85c..a74a9cbd 100644 --- a/src/app/features/consultation/consultation.component.html +++ b/src/app/features/consultation/consultation.component.html @@ -1,4 +1,3 @@ -
@@ -116,6 +115,9 @@ aucun vote pour le moment +
+ +