diff --git a/src/app/core/services/poll.service.ts b/src/app/core/services/poll.service.ts index 220e87b7..2f4cb5a1 100644 --- a/src/app/core/services/poll.service.ts +++ b/src/app/core/services/poll.service.ts @@ -109,6 +109,8 @@ export class PollService implements Resolve { * @param poll */ public updateCurrentPoll(poll: Poll): void { + console.log('update poll with: ', poll); + this.storageService.setChoicesForVoteStack(poll.choices); this.toastService.display('sondage bien mis à jour', 'success'); diff --git a/src/app/features/administration/form/form.component.ts b/src/app/features/administration/form/form.component.ts index b4806b3c..c965cb69 100644 --- a/src/app/features/administration/form/form.component.ts +++ b/src/app/features/administration/form/form.component.ts @@ -9,6 +9,8 @@ import { DOCUMENT } from '@angular/common'; import { Router } from '@angular/router'; import { environment } from '../../../../environments/environment'; import { PollUtilitiesService } from '../../../core/services/poll.utilities.service'; +import { Subscription } from 'rxjs'; +import { StorageService } from '../../../core/services/storage.service'; @Component({ selector: 'app-admin-form', @@ -24,13 +26,13 @@ export class FormComponent implements OnInit { public show_debug_data = false; public currentStep = 'base'; public steps = ['base', 'choices', 'advanced']; - constructor( private fb: FormBuilder, private cd: ChangeDetectorRef, private pollUtilitiesService: PollUtilitiesService, private toastService: ToastService, private pollService: PollService, + private storageService: StorageService, public apiService: ApiService, private router: Router, @Inject(DOCUMENT) private document: any @@ -163,20 +165,32 @@ export class FormComponent implements OnInit { if (!environment.production) { this.toastService.display('mode dev : envoi du form sans validation'); - this.apiService.createPoll(newpoll).then((resp) => { - console.log('resp', resp); - router.navigate(['success']); - }); + this.apiService.createPoll(newpoll).then( + (resp: any) => { + this.pollService.updateCurrentPoll(resp.data.poll); + this.storageService.userPolls.push(resp.data.poll); + this.storageService.vote_stack.owner.polls.push(resp.data.poll); + this.toastService.display('sauvegarde du nouveau sondage réussie'); + router.navigate(['success']); + }, + (err) => { + this.toastService.display('erreur lors de la sauvegarde'); + } + ); } else { if (this.form.valid) { - console.log('Le sondage est correctement rempli, prêt à enregistrer.'); - const newpoll = this.pollService.newPollFromForm(this.form); - this.apiService.createPoll(newpoll).then((resp) => { - console.log('resp', resp); - router.navigate(['poll', this.form.value.custom_url, 'consultation']); - - this.toastService.display('sauvegarde du nouveau sondage réussie'); - }); + this.apiService.createPoll(newpoll).then( + (resp: any) => { + this.pollService.updateCurrentPoll(resp.data.poll); + this.storageService.userPolls.push(resp.data.poll); + this.storageService.vote_stack.owner.polls.push(resp.data.poll); + this.toastService.display('sauvegarde du nouveau sondage réussie'); + router.navigate(['success']); + }, + (err) => { + this.toastService.display('erreur lors de la sauvegarde'); + } + ); } else { this.toastService.display('invalid form'); } diff --git a/src/app/features/administration/success/success.component.scss b/src/app/features/administration/success/success.component.scss index 0327ad09..319fa325 100644 --- a/src/app/features/administration/success/success.component.scss +++ b/src/app/features/administration/success/success.component.scss @@ -4,3 +4,8 @@ button { margin-bottom: 1ch; margin-right: 1ch; } +a { + max-width: 20em; + overflow: auto; + text-overflow: ellipsis; +}