From f8568eb9102668521556b40eacc89ee8b639db09 Mon Sep 17 00:00:00 2001 From: Baptiste Lemoine Date: Mon, 20 Jan 2020 15:23:26 +0100 Subject: [PATCH] launch creation from resume page --- src/app/pages/resume/resume.component.html | 14 ++++++++++++-- src/app/pages/resume/resume.component.ts | 12 +++++++----- src/app/services/config.service.ts | 18 ++++++++++++------ 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src/app/pages/resume/resume.component.html b/src/app/pages/resume/resume.component.html index 1d8b9acf..70589446 100644 --- a/src/app/pages/resume/resume.component.html +++ b/src/app/pages/resume/resume.component.html @@ -30,10 +30,20 @@ +
diff --git a/src/app/pages/resume/resume.component.ts b/src/app/pages/resume/resume.component.ts index aad88b0e..ad7579ba 100644 --- a/src/app/pages/resume/resume.component.ts +++ b/src/app/pages/resume/resume.component.ts @@ -1,19 +1,21 @@ -import {Component, OnInit} from '@angular/core'; +import {Component} from '@angular/core'; import {BaseComponent} from '../base-page/base.component'; import {ConfigService} from '../../services/config.service'; +import {Router} from "@angular/router"; @Component({ selector: 'framadate-resume', templateUrl: './resume.component.html', styleUrls: ['./resume.component.scss'] }) -export class ResumeComponent extends BaseComponent implements OnInit { +export class ResumeComponent extends BaseComponent { - constructor(public config: ConfigService) { + constructor(public config: ConfigService, + private router: Router) { super(config); } - ngOnInit() { + submitCreationAndGoToEnd() { + this.config.createPoll(); } - } diff --git a/src/app/services/config.service.ts b/src/app/services/config.service.ts index 319a4239..5bad3f1b 100644 --- a/src/app/services/config.service.ts +++ b/src/app/services/config.service.ts @@ -254,17 +254,20 @@ export class ConfigService extends PollConfig { /** - * action of the form + * launch creation call to the api */ createPoll() { - // alert('envoi de formulaire pour création de sondage en XHR à faire'); - this.http.get(`${this.baseHref}/`, this.makeHeaders()) + this.loading = true; + + return this.http.get(`${this.baseHref}/`, this.makeHeaders()) .subscribe((res) => { this.createPollFromConfig(this.getPollConfig()) }, - this.handleError + (e) => { + this.handleError(e) + } ) - ; + ; } @@ -274,13 +277,16 @@ export class ConfigService extends PollConfig { * @param config */ createPollFromConfig(config: any) { - this.http.post(`${this.baseHref}/poll`, + this.loading= true; + return this.http.post(`${this.baseHref}/poll`, this.makeHeaders({config: config})) .subscribe((res: any) => { // redirect to the page to administrate the new poll this.messageService.add({severity: 'success', summary: 'Sondage Créé',}); this.selectedPoll = res; this.pollId = res.pollId; + this.loading = false; + this.router.navigate(['step/end']); }, (e) => { this.handleError(e) }