forked from tykayn/funky-framadate-front
add to local polls after creation, update poll
This commit is contained in:
parent
a969b30a03
commit
10177d793b
@ -109,6 +109,8 @@ export class PollService implements Resolve<Poll> {
|
||||
* @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');
|
||||
|
@ -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);
|
||||
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.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');
|
||||
}
|
||||
|
@ -4,3 +4,8 @@ button {
|
||||
margin-bottom: 1ch;
|
||||
margin-right: 1ch;
|
||||
}
|
||||
a {
|
||||
max-width: 20em;
|
||||
overflow: auto;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user