mirror of
https://framagit.org/framasoft/framadate/funky-framadate-front.git
synced 2023-08-25 13:53:14 +02:00
⚡ update vote list after vote creation
This commit is contained in:
parent
123a0b1c80
commit
06cf447529
@ -237,4 +237,4 @@ export const mockPoll3 = {
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"comments": mockComments
|
"comments": mockComments
|
||||||
}
|
};
|
||||||
|
@ -12,7 +12,7 @@ import {ActivatedRoute} from "@angular/router";
|
|||||||
})
|
})
|
||||||
export class PollDisplayComponent extends BaseComponent implements OnInit {
|
export class PollDisplayComponent extends BaseComponent implements OnInit {
|
||||||
|
|
||||||
private pollConfigFetched = mockPoll3;
|
private pollConfigFetched;
|
||||||
private comments = mockComments;
|
private comments = mockComments;
|
||||||
|
|
||||||
constructor(public config: ConfigService,
|
constructor(public config: ConfigService,
|
||||||
@ -21,6 +21,8 @@ export class PollDisplayComponent extends BaseComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
|
this.pollConfigFetched = this.config.currentPoll;
|
||||||
|
|
||||||
// fetch poll with its ID or slug.
|
// fetch poll with its ID or slug.
|
||||||
const id = this.activeRoute.snapshot.params.poll;
|
const id = this.activeRoute.snapshot.params.poll;
|
||||||
if (id) {
|
if (id) {
|
||||||
@ -28,7 +30,7 @@ export class PollDisplayComponent extends BaseComponent implements OnInit {
|
|||||||
// store it in the poll property here
|
// store it in the poll property here
|
||||||
this.config.getPollById(id).subscribe(
|
this.config.getPollById(id).subscribe(
|
||||||
(res: any) => {
|
(res: any) => {
|
||||||
this.pollConfigFetched = res;
|
this.config.currentPoll = res;
|
||||||
}, (e) => {
|
}, (e) => {
|
||||||
// handle need for a password
|
// handle need for a password
|
||||||
this.config.handleError(e)
|
this.config.handleError(e)
|
||||||
|
@ -4,6 +4,7 @@ import {HttpClient, HttpHeaders} from "@angular/common/http";
|
|||||||
import {environment} from "../../environments/environment";
|
import {environment} from "../../environments/environment";
|
||||||
import {ConfirmationService, MessageService} from 'primeng/api';
|
import {ConfirmationService, MessageService} from 'primeng/api';
|
||||||
import {Router} from "@angular/router";
|
import {Router} from "@angular/router";
|
||||||
|
import {mockPoll3} from "../config/mocks/mock-poll3";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* le service transverse à chaque page qui permet de syncroniser la configuration de sondage souhaitée
|
* le service transverse à chaque page qui permet de syncroniser la configuration de sondage souhaitée
|
||||||
@ -13,6 +14,7 @@ import {Router} from "@angular/router";
|
|||||||
})
|
})
|
||||||
export class ConfigService extends PollConfig {
|
export class ConfigService extends PollConfig {
|
||||||
|
|
||||||
|
currentPoll: any = mockPoll3;
|
||||||
loading: boolean = false;
|
loading: boolean = false;
|
||||||
baseHref: any = environment.baseApiHref;
|
baseHref: any = environment.baseApiHref;
|
||||||
|
|
||||||
@ -307,8 +309,7 @@ export class ConfigService extends PollConfig {
|
|||||||
.subscribe((res: any) => {
|
.subscribe((res: any) => {
|
||||||
|
|
||||||
this.messageService.add({severity: 'success', summary: 'Vote ajouté'});
|
this.messageService.add({severity: 'success', summary: 'Vote ajouté'});
|
||||||
alert("succès!");
|
this.currentPoll = res;
|
||||||
this.myPolls = res;
|
|
||||||
}, (e) => {
|
}, (e) => {
|
||||||
this.handleError(e)
|
this.handleError(e)
|
||||||
}
|
}
|
||||||
@ -327,7 +328,7 @@ export class ConfigService extends PollConfig {
|
|||||||
this.makeHeaders())
|
this.makeHeaders())
|
||||||
.subscribe((res: any) => {
|
.subscribe((res: any) => {
|
||||||
this.messageService.add({severity: 'success', summary: 'Vote mis à jour'});
|
this.messageService.add({severity: 'success', summary: 'Vote mis à jour'});
|
||||||
this.myPolls = res;
|
this.currentPoll = res;
|
||||||
}, (e) => {
|
}, (e) => {
|
||||||
this.handleError(e)
|
this.handleError(e)
|
||||||
}
|
}
|
||||||
@ -340,10 +341,11 @@ export class ConfigService extends PollConfig {
|
|||||||
* @param comment
|
* @param comment
|
||||||
*/
|
*/
|
||||||
addComment(comment?: any) {
|
addComment(comment?: any) {
|
||||||
if (!comment) {
|
if (!comment && this.myComment) {
|
||||||
comment = {
|
comment = {
|
||||||
pseudo: this.myName,
|
name: this.myName,
|
||||||
comment: this.myComment,
|
date: new Date(),
|
||||||
|
text: this.myComment,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.http.post(
|
this.http.post(
|
||||||
@ -358,8 +360,10 @@ export class ConfigService extends PollConfig {
|
|||||||
});
|
});
|
||||||
// empty comment after success
|
// empty comment after success
|
||||||
this.myComment = '';
|
this.myComment = '';
|
||||||
|
this.currentPoll.comments.push(comment);
|
||||||
}, (e) => {
|
}, (e) => {
|
||||||
this.handleError(e)
|
this.handleError(e);
|
||||||
|
this.currentPoll.comments.push(comment);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -463,7 +467,7 @@ export class ConfigService extends PollConfig {
|
|||||||
severity: 'success',
|
severity: 'success',
|
||||||
summary: 'Sondage mis à jour',
|
summary: 'Sondage mis à jour',
|
||||||
});
|
});
|
||||||
this.myPolls = res;
|
this.currentPoll = res;
|
||||||
}, (e) => {
|
}, (e) => {
|
||||||
this.handleError(e)
|
this.handleError(e)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user