From 09ff4be2f6a9ba6dc45f737e4058e9a854841506 Mon Sep 17 00:00:00 2001 From: Tykayn Date: Tue, 8 Jun 2021 14:30:05 +0200 Subject: [PATCH] remove logs on upgrade vote stack --- src/app/core/models/owner.model.ts | 3 +- src/app/core/services/poll.service.ts | 42 +++++++++---------- src/app/core/services/storage.service.ts | 26 +++++++++--- .../consultation/consultation.component.ts | 2 +- .../choice-item/choice-button.component.scss | 1 + src/environments/endpoints.ts | 12 +++--- src/environments/environment.ts | 3 +- 7 files changed, 53 insertions(+), 36 deletions(-) diff --git a/src/app/core/models/owner.model.ts b/src/app/core/models/owner.model.ts index d17bbe20..693d3398 100644 --- a/src/app/core/models/owner.model.ts +++ b/src/app/core/models/owner.model.ts @@ -7,6 +7,7 @@ export class Owner { public email: string = '_nonexistent_contact@cipherbliss.com', public polls: Poll[] = [], public role?: UserRole, - public modifier_token?: string + public modifier_token?: string, + public created_at?: string ) {} } diff --git a/src/app/core/services/poll.service.ts b/src/app/core/services/poll.service.ts index c7f0ffc9..f4269c7d 100644 --- a/src/app/core/services/poll.service.ts +++ b/src/app/core/services/poll.service.ts @@ -62,11 +62,12 @@ export class PollService implements Resolve { } } - getAllAvailablePolls() { + /** + * get all polls + */ + getAllAvailablePolls(): void { const baseHref = environment.api.version.apiV1.baseHref; - console.log('getAllAvailablePolls baseHref', baseHref); const headers = ApiService.makeHeaders(); - console.log('getAllAvailablePolls headers', headers); try { this.http.get(`${baseHref}/poll`, headers).subscribe((res: Observable) => { console.log('getAllAvailablePolls res', res); @@ -77,16 +78,15 @@ export class PollService implements Resolve { } public async loadPollBycustom_url(custom_url: string): Promise { - console.log('custom_url', custom_url); if (custom_url) { const poll: Poll | undefined = await this.apiService.getPollByCustomUrl(custom_url); - console.log('loadPollBycustom_urlResponse', poll); if (poll) { this.updateCurrentPoll(poll); this.titleService.setTitle(`☑️ ${poll.title} - ${environment.appTitle}`); } else { this.toastService.display(`sondage ${custom_url} non trouvé`); + this.router.navigate(['page-not-found']); } } else { this.toastService.display(`sondage sans custom url : ${custom_url}`); @@ -94,11 +94,18 @@ export class PollService implements Resolve { } public async loadPollBycustom_urlWithPasswordHash(custom_url: string, hash: string): Promise { - console.log('custom_url', custom_url); if (custom_url) { const poll: Poll | undefined = await this.apiService.getPollByCustomUrlWithHash(custom_url, hash); - console.log({ loadPollBycustom_urlResponse: poll }); - this.updateCurrentPoll(poll); + + if (poll) { + this.updateCurrentPoll(poll); + this.titleService.setTitle(`☑️ ${poll.title} - ${environment.appTitle}`); + } else { + this.toastService.display(`sondage ${custom_url} non trouvé`); + this.router.navigate(['page-not-found']); + } + } else { + this.toastService.display(`sondage sans custom url : ${custom_url}`); } } @@ -107,17 +114,18 @@ export class PollService implements Resolve { * @param poll */ public updateCurrentPoll(poll: Poll): void { - console.log('update poll with: ', poll); + console.log('this.storageService.vote_stack.id', this.storageService.vote_stack.id); - if (!this.storageService.vote_stack.id || this.storageService.vote_stack.poll_custom_url !== poll.custom_url) { + 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); } this.toastService.display('sondage bien mis à jour', 'success'); - - console.log('poll', poll); this._poll.next(poll); } @@ -126,7 +134,6 @@ export class PollService implements Resolve { * @param poll */ makecustom_url(poll: Poll): string { - console.log('config', poll); let str = ''; const creation_date = new Date(poll.creation_date); str = @@ -163,10 +170,6 @@ export class PollService implements Resolve { } public saveParticipation(choice: Choice, user: Owner, response: Answer): void { - const currentPoll = this._poll.getValue(); - currentPoll.choices.find((c) => c.name === choice.name)?.updateParticipation(user, response); - this.updateCurrentPoll(currentPoll); - this.apiService.createParticipation(currentPoll.custom_url, choice.name, user.pseudo, response); this.toastService.display('Votre participation au sondage a été enregistrée.'); } @@ -196,8 +199,6 @@ export class PollService implements Resolve { const pollKeys = Object.keys(newpoll); const formFields = Object.keys(form.value); - - console.log('pollKeys, formFields', pollKeys, formFields); newpoll.allowed_answers = ['yes']; for (const pk of pollKeys) { @@ -227,9 +228,6 @@ export class PollService implements Resolve { newpoll.choices = Object.assign([], this.storageService.choices); newpoll.dateChoices = Object.assign([], this.storageService.dateChoices); newpoll.timeSlices = Object.assign([], this.storageService.timeSlices); - - console.log('this.storageService.timeSlices', this.storageService.timeSlices, newpoll.timeSlices); - return newpoll; } diff --git a/src/app/core/services/storage.service.ts b/src/app/core/services/storage.service.ts index b7ce3863..ad601437 100644 --- a/src/app/core/services/storage.service.ts +++ b/src/app/core/services/storage.service.ts @@ -60,10 +60,15 @@ export class StorageService { } } + /** + * set default choices for the vote stack from the poll choices objects + * @param choices_list + */ setChoicesForVoteStack(choices_list: Choice[]) { // text choices if (!this.vote_stack.id) { - this.vote_stack.votes = []; + this.vote_stack = new Stack(); + for (const choice of choices_list) { if (environment.autofill) { console.log('autofill au hasard des votes à ce sondage'); @@ -77,8 +82,12 @@ export class StorageService { } } + /** + * look for a choice in the stored vote stack and change it answer + * @param choice_id + * @param value + */ toggleAnswer(choice_id: number, value: string) { - console.log('this.vote_stack', this.vote_stack); for (const vote of this.vote_stack.votes) { if (vote.choice_id == choice_id) { if (vote.value == value) { @@ -90,6 +99,11 @@ export class StorageService { } } + /** + * check for the value of a choice in the stored vote stack + * @param choice_id + * @param value + */ choiceHasAnswerOfValue(choice_id: number, value: any) { for (const vote of this.vote_stack.votes) { if (vote.choice_id == choice_id) { @@ -116,11 +130,13 @@ export class StorageService { }); } + /** + * update vote stack from the backend + * @param resp + */ mapVotes(resp) { - console.log('data', resp.data); - console.log('this.vote_stack', this.vote_stack); + console.log('mapVotes resp.data', resp.data); this.vote_stack.owner = resp.data.owner; this.vote_stack.id = resp.data.id; - console.log('this.vote_stack', this.vote_stack); } } diff --git a/src/app/features/consultation/consultation.component.ts b/src/app/features/consultation/consultation.component.ts index 793987f2..424a1f78 100644 --- a/src/app/features/consultation/consultation.component.ts +++ b/src/app/features/consultation/consultation.component.ts @@ -98,7 +98,7 @@ export class ConsultationComponent implements OnInit, OnDestroy { .sendUpdateVoteStack(vote_stack) .then((resp) => { console.log('sendUpdateVoteStack updated resp', resp); - // this.storeVoteStackAndReloadPoll(resp); + this.storeVoteStackAndReloadPoll(resp); this.toastService.display('vote bien mis à jour', 'success'); }) .catch(handlingError); diff --git a/src/app/shared/components/choice-item/choice-button.component.scss b/src/app/shared/components/choice-item/choice-button.component.scss index 7de75312..5ece0216 100644 --- a/src/app/shared/components/choice-item/choice-button.component.scss +++ b/src/app/shared/components/choice-item/choice-button.component.scss @@ -9,4 +9,5 @@ &:active { border-color: #6c99ff; } + margin-left: 1ch; } diff --git a/src/environments/endpoints.ts b/src/environments/endpoints.ts index 95051473..0aab18dd 100644 --- a/src/environments/endpoints.ts +++ b/src/environments/endpoints.ts @@ -1,13 +1,13 @@ export const backendApiUrlsInDev = { - local: 'http://tktest.lan/api/v1', - remote: 'http://tktest.lan/api/v1', - // local: 'http://localhost:8000/api/v1', - // remote: 'http://localhost:8000/api/v1', + // local: 'http://tktest.lan/api/v1', + // remote: 'http://tktest.lan/api/v1', + local: 'https://localhost:8000/api/v1', + remote: 'https://localhost:8000/api/v1', // remote: 'https://framadate-api.cipherbliss.com/api/v1', }; export const apiV1 = { - // baseHref: 'http://localhost:8000/api/v1', - baseHref: 'http://tktest.lan/api/v1', + baseHref: 'https://localhost:8000/api/v1', + // baseHref: 'http://tktest.lan/api/v1', // baseHref: 'https://framadate-api.cipherbliss.com/api/v1', api_new_poll: '/poll/', api_get_poll: '/poll/{id}', diff --git a/src/environments/environment.ts b/src/environments/environment.ts index 1b0d0a64..b8823387 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -11,7 +11,8 @@ export const environment = { frontDomain: 'http://127.0.0.1:4200', production: false, display_routes: true, - autofill: true, + // autofill: true, + autofill: false, showDemoWarning: true, autoSendNewPoll: false, interval_days_default: 7,