mirror of
https://framagit.org/framasoft/framadate/funky-framadate-front.git
synced 2023-08-25 13:53:14 +02:00
use pollservice proxy to create poll and store the result in storage service
This commit is contained in:
parent
6796d6e39f
commit
fc1859719a
@ -3,7 +3,7 @@ import { RouterModule } from '@angular/router';
|
|||||||
import { routes } from './routes-framadate';
|
import { routes } from './routes-framadate';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
imports: [RouterModule.forRoot(routes, { useHash: true, enableTracing: true })],
|
imports: [RouterModule.forRoot(routes, { useHash: true })],
|
||||||
exports: [RouterModule],
|
exports: [RouterModule],
|
||||||
})
|
})
|
||||||
export class AppRoutingModule {}
|
export class AppRoutingModule {}
|
||||||
|
@ -80,9 +80,13 @@ export class ApiService {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param poll
|
||||||
|
*/
|
||||||
public async createPoll(poll: PollDTO): Promise<Subscription> {
|
public async createPoll(poll: PollDTO): Promise<Subscription> {
|
||||||
// this.loaderService.setStatus(true);
|
// this.loaderService.setStatus(true);
|
||||||
console.log('createPoll config', poll);
|
console.log('apiservice createPoll config', poll);
|
||||||
return this.axiosInstance.post(
|
return this.axiosInstance.post(
|
||||||
`${this.baseHref}${currentApiRoutes['api_new_poll']}`,
|
`${this.baseHref}${currentApiRoutes['api_new_poll']}`,
|
||||||
poll,
|
poll,
|
||||||
|
@ -89,7 +89,7 @@ export class PollService implements Resolve<Poll> {
|
|||||||
this.addChoice('abricot');
|
this.addChoice('abricot');
|
||||||
|
|
||||||
this.form.patchValue({
|
this.form.patchValue({
|
||||||
title: 'mon titre',
|
title: 'mon titre de sondage du ' + this.DateUtilitiesService.formateDateToInputStringNg(new Date()),
|
||||||
description: 'répondez SVP <3 ! *-* ',
|
description: 'répondez SVP <3 ! *-* ',
|
||||||
custom_url: this.uuidService.getUUID(),
|
custom_url: this.uuidService.getUUID(),
|
||||||
creatorPseudo: 'Chuck Norris',
|
creatorPseudo: 'Chuck Norris',
|
||||||
@ -115,7 +115,7 @@ export class PollService implements Resolve<Poll> {
|
|||||||
public createFormGroup() {
|
public createFormGroup() {
|
||||||
let minlengthValidation = environment.production ? 12 : 0;
|
let minlengthValidation = environment.production ? 12 : 0;
|
||||||
let form = this.fb.group({
|
let form = this.fb.group({
|
||||||
title: ['', [Validators.required, Validators.minLength(minlengthValidation)]],
|
title: ['mon titre de sondage', [Validators.required, Validators.minLength(minlengthValidation)]],
|
||||||
creatorPseudo: ['', [Validators.required]],
|
creatorPseudo: ['', [Validators.required]],
|
||||||
created_at: [new Date(), [Validators.required]],
|
created_at: [new Date(), [Validators.required]],
|
||||||
creatorEmail: ['', [Validators.required]],
|
creatorEmail: ['', [Validators.required]],
|
||||||
@ -385,9 +385,12 @@ export class PollService implements Resolve<Poll> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* convert form data to DTO to create a new poll, and store the admin key
|
||||||
|
*/
|
||||||
public createPoll(): Promise<any> {
|
public createPoll(): Promise<any> {
|
||||||
this.toastService.display('sending...');
|
this.toastService.display('sending...');
|
||||||
console.log('this.form', this.form);
|
console.log('createPoll this.form', this.form);
|
||||||
const newpoll = this.newPollFromForm();
|
const newpoll = this.newPollFromForm();
|
||||||
return this.apiService.createPoll(newpoll).then(
|
return this.apiService.createPoll(newpoll).then(
|
||||||
(resp: any) => {
|
(resp: any) => {
|
||||||
@ -395,8 +398,12 @@ export class PollService implements Resolve<Poll> {
|
|||||||
console.log('TODO fill admin_key');
|
console.log('TODO fill admin_key');
|
||||||
console.log('resp', resp);
|
console.log('resp', resp);
|
||||||
this.admin_key = resp.data.poll.admin_key;
|
this.admin_key = resp.data.poll.admin_key;
|
||||||
|
this.storageService.userPolls.push(resp.data.poll);
|
||||||
},
|
},
|
||||||
(error) => this.apiService.ousideHandleError(error)
|
(error) => {
|
||||||
|
this.toastService.display('BOOM, the createPoll went wrong');
|
||||||
|
this.apiService.ousideHandleError(error);
|
||||||
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ export class StorageService {
|
|||||||
|
|
||||||
constructor(public dateUtilities: DateUtilitiesService, private toastService: ToastService) {
|
constructor(public dateUtilities: DateUtilitiesService, private toastService: ToastService) {
|
||||||
if (environment.autofill_participation) {
|
if (environment.autofill_participation) {
|
||||||
this.toastService.display('autofill des sondages utilisateur');
|
// this.toastService.display('autofill des sondages utilisateur');
|
||||||
this.userPolls.push(new Poll(new Owner(), 'Démo: Anniversaire de tonton Patrick', 'aujourdhui-ou-demain'));
|
this.userPolls.push(new Poll(new Owner(), 'Démo: Anniversaire de tonton Patrick', 'aujourdhui-ou-demain'));
|
||||||
this.userPolls.push(new Poll(new Owner(), 'Démo: Atelier cuisine du quartier', 'aujourdhui-ou-demain'));
|
this.userPolls.push(new Poll(new Owner(), 'Démo: Atelier cuisine du quartier', 'aujourdhui-ou-demain'));
|
||||||
this.userPolls.push(
|
this.userPolls.push(
|
||||||
|
@ -21,8 +21,7 @@ export class StepFourComponent implements OnInit {
|
|||||||
ngOnInit(): void {}
|
ngOnInit(): void {}
|
||||||
|
|
||||||
createPoll() {
|
createPoll() {
|
||||||
let apiData = this.pollService.newPollFromForm();
|
this.pollService.createPoll().then((resp) => {
|
||||||
this.apiService.createPoll(apiData).then((resp) => {
|
|
||||||
this.router.navigate(['administration/success']);
|
this.router.navigate(['administration/success']);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ endpoints.baseHref = apiV1.baseHref;
|
|||||||
export const environment = {
|
export const environment = {
|
||||||
frontDomain: 'http://127.0.0.1:4200',
|
frontDomain: 'http://127.0.0.1:4200',
|
||||||
production: false,
|
production: false,
|
||||||
display_routes: false, // demo paths to test polls
|
display_routes: true, // demo paths to test polls
|
||||||
autofill_creation: true,
|
autofill_creation: true,
|
||||||
advanced_options_display: true,
|
advanced_options_display: true,
|
||||||
autofill_participation: true,
|
autofill_participation: true,
|
||||||
|
Loading…
Reference in New Issue
Block a user