|
|
|
@ -285,19 +285,21 @@ export class ConfigService extends PollConfig {
|
|
|
|
|
*/
|
|
|
|
|
createPollFromConfig(config: any) {
|
|
|
|
|
this.loading = true;
|
|
|
|
|
console.log('config', config)
|
|
|
|
|
return this.http.post(`${this.baseHref}/poll`,
|
|
|
|
|
config,
|
|
|
|
|
this.makeHeaders())
|
|
|
|
|
.subscribe((res: any) => {
|
|
|
|
|
// redirect to the page to administrate the new poll
|
|
|
|
|
this.messageService.add({severity: 'success', summary: 'Sondage Créé',});
|
|
|
|
|
this.currentPoll = res;
|
|
|
|
|
this.pollId = res.pollId;
|
|
|
|
|
this.currentPoll = res.data;
|
|
|
|
|
this.currentPoll.admin_key = res.admin_key;
|
|
|
|
|
this.pollId = res.data.id;
|
|
|
|
|
this.loading = false;
|
|
|
|
|
if (!this.myPolls) {
|
|
|
|
|
this.myPolls = [];
|
|
|
|
|
}
|
|
|
|
|
this.myPolls.push(config);
|
|
|
|
|
this.myPolls.push(res);
|
|
|
|
|
this.router.navigate(['step/end']);
|
|
|
|
|
// TODO save new poll to localstorage
|
|
|
|
|
// reset all fields in current config
|
|
|
|
@ -336,14 +338,19 @@ export class ConfigService extends PollConfig {
|
|
|
|
|
votes: this.convertChoicesAnsweredToSend(this.currentPoll.choices),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
console.log('voteStack', voteStack)
|
|
|
|
|
this.myVoteStack = voteStack;
|
|
|
|
|
|
|
|
|
|
this.http.post(
|
|
|
|
|
`${this.baseHref}/poll/${this.currentPoll.id}/vote`,
|
|
|
|
|
`${this.baseHref}/poll/${this.pollId}/vote`,
|
|
|
|
|
voteStack,
|
|
|
|
|
this.makeHeaders())
|
|
|
|
|
.subscribe((res: any) => {
|
|
|
|
|
|
|
|
|
|
this.messageService.add({severity: 'success', summary: 'Vote ajouté'});
|
|
|
|
|
|
|
|
|
|
// save modifier token
|
|
|
|
|
voteStack['modifier_token'] = res.modifier_token;
|
|
|
|
|
voteStack['id'] = res.vote_stack.id;
|
|
|
|
|
this.currentPoll = res;
|
|
|
|
|
}, (e) => {
|
|
|
|
|
this.handleError(e)
|
|
|
|
@ -356,9 +363,15 @@ export class ConfigService extends PollConfig {
|
|
|
|
|
* /api/v1/poll/{id}/vote
|
|
|
|
|
* @param voteStack
|
|
|
|
|
*/
|
|
|
|
|
updateVote(voteStack: any) {
|
|
|
|
|
updateVote(voteStack?: any) {
|
|
|
|
|
if (!this.myVoteStack) {
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
voteStack = this.myVoteStack;
|
|
|
|
|
}
|
|
|
|
|
this.http.put(
|
|
|
|
|
`${this.baseHref}/vote-stack/${voteStack.id}`,
|
|
|
|
|
`${this.baseHref}/vote-stack/${voteStack.id}/token/${voteStack.modifierToken}`,
|
|
|
|
|
voteStack,
|
|
|
|
|
this.makeHeaders())
|
|
|
|
|
.subscribe((res: any) => {
|
|
|
|
|