add administration key after creation

This commit is contained in:
Baptiste Lemoine 2020-01-23 15:08:52 +01:00
parent 01bddc842d
commit 7bc53e198d
4 changed files with 39 additions and 45 deletions

View File

@ -31,6 +31,7 @@ export class PollConfig {
myName: string = 'mon pseudo';
myComment: string = 'wouah trop bien framadate!';
isAdmin: boolean = true;
myVoteStack: any;
myEmail: string = "tktest@tktest.com";
myPolls: any = [];// list of retrieved polls from the backend api
// date specific poll, we have the choice to setup different hours (timeList) for all possible dates (dateList), or use the same hours for all dates

View File

@ -46,52 +46,25 @@
{{config.currentPoll.choices.length}} choix,
</div >
</div >
<div
*ngIf='config.isAdmin'
class='col-xs-6 admin-actions' >
<button
class='btn btn--primary btn--outline btn--full'
(click)='config.todo()' >
<i class='fa fa-pencil' ></i >
Je veux modifier le vote de quelqu'un
</button >
<button
(click)='config.deleteComments()'
class='btn btn--danger btn--outline' >
<i class='fa fa-comments-o' ></i >
Supprimer tous les commentaires
</button >
<button
(click)='config.deleteVotes()'
class='btn btn--danger btn--outline' >
<i class='fa fa-stack' ></i >
Supprimer tous les votes
</button >
<button
(click)='config.deletePoll()'
class='btn btn--danger btn--outline' >
<i class='fa fa-trash' ></i >
Supprimer ce sondage entièrement
</button >
<button
(click)='config.checkIfSlugIsUniqueInDatabase()'
class='btn btn--primary btn--outline' >
<i class='fa fa-file-text' ></i >
vérifier la disponibilité de l'url personnalisée
</button >
</div >
</div >
</div >
<section class="name" >
<label for="name" >Votre nom :</label >
<label for="name" >
<i class='fa fa-user' ></i >
Votre nom :</label >
<input
type="text"
name="name"
id="name"
[(ngModel)]="config.myName" >
<input
type="text"
name="name"
id="email"
[(ngModel)]="config.myEmail" >
<i class='fa fa-envelope' ></i >
</section >
<div
*ngIf='config.currentPoll'
@ -106,9 +79,16 @@
</div >
<button
class='btn btn--primary btn-block'
(click)='config.addVote()' >
(click)='config.addVote()'
*ngIf='!config.myVoteStack || !config.myVoteStack.id' >
<i class='fa fa-paper-plane' ></i > Envoyer
</button >
<button
class='btn btn--primary btn-block'
(click)='config.updateVote(config.myVoteStack)'
*ngIf='config.myVoteStack && config.myVoteStack.id' >
<i class='fa fa-pencil' ></i > Mettre à jour
</button >
<hr >
<div id='graph' >

View File

@ -44,7 +44,7 @@ export class PollDisplayComponent extends BaseComponent implements OnInit {
// store it in the poll property here
this.config.getPollById(id).subscribe(
(res: any) => {
console.log('res', res)
console.log('res', res);
this.config.currentPoll = res;
this.config.loading = false;

View File

@ -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) => {