update vote in frontend

This commit is contained in:
Tykayn 2021-06-08 10:41:46 +02:00 committed by tykayn
parent 5ce3984dc9
commit 5c290ea968
5 changed files with 32 additions and 19 deletions

View File

@ -81,7 +81,7 @@ export class PollService implements Resolve<Poll> {
if (custom_url) {
const poll: Poll | undefined = await this.apiService.getPollByCustomUrl(custom_url);
console.log({ loadPollBycustom_urlResponse: poll });
console.log('loadPollBycustom_urlResponse', poll);
if (poll) {
this.updateCurrentPoll(poll);
this.titleService.setTitle(`☑️ ${poll.title} - ${environment.appTitle}`);
@ -109,7 +109,11 @@ export class PollService implements Resolve<Poll> {
public updateCurrentPoll(poll: Poll): void {
console.log('update poll with: ', poll);
this.storageService.setChoicesForVoteStack(poll.choices);
if (!this.storageService.vote_stack.id || this.storageService.vote_stack.poll_custom_url !== poll.custom_url) {
console.log('set base choices', poll.choices);
// set the choices only the first time the poll loads
this.storageService.setChoicesForVoteStack(poll.choices);
}
this.toastService.display('sondage bien mis à jour', 'success');

View File

@ -119,12 +119,8 @@ export class StorageService {
mapVotes(resp) {
console.log('data', resp.data);
console.log('this.vote_stack', this.vote_stack);
this.vote_stack.votes = [];
this.vote_stack.owner = resp.data.owner;
this.vote_stack.id = resp.data.id;
for (const vote of resp.data.votes) {
this.vote_stack.votes.push(vote);
}
console.log('this.vote_stack', this.vote_stack);
}
}

View File

@ -86,6 +86,17 @@
Detailed
</button>
</div>
<div class="pseudo-land">
<label for="vote_pseudo_vote_stack">
Votre pseudo:
</label>
<input
type="text"
id="vote_pseudo_vote_stack"
placeholder="votre pseudo"
[(ngModel)]="storageService.vote_stack.pseudo"
/>
</div>
<app-poll-results-compact *ngIf="isCompactMode" [poll]="poll"></app-poll-results-compact>
<app-poll-results-detailed *ngIf="!isCompactMode" [poll]="poll"></app-poll-results-detailed>
</div>

View File

@ -85,21 +85,23 @@ export class ConsultationComponent implements OnInit, OnDestroy {
/**
* update existing vote stack
* @param vote_stack
* @param Stack
*/
updateVoteStack(): void {
const vote_stack = this.storageService.vote_stack;
vote_stack.poll_custom_url = this.poll.custom_url;
console.log('updateVoteStack vote_stack', vote_stack);
// const handlingError = this.api.handleError;
console.log('updateVoteStack vote_stack.votes', vote_stack.votes.length, vote_stack.votes);
const handlingError = this.api.ousideHandleError;
this.api.sendUpdateVoteStack(vote_stack).then((resp) => {
console.log('sendUpdateVoteStack resp', resp);
this.storeVoteStackAndReloadPoll(resp);
this.toastService.display('vote bien mis à jour', 'success');
});
// .catch(handlingError);
this.api
.sendUpdateVoteStack(vote_stack)
.then((resp) => {
console.log('sendUpdateVoteStack updated resp', resp);
// this.storeVoteStackAndReloadPoll(resp);
this.toastService.display('vote bien mis à jour', 'success');
})
.catch(handlingError);
}
/**

View File

@ -1,13 +1,13 @@
export const backendApiUrlsInDev = {
local: 'http://tktest.lan/api/v1',
// remote: 'http://tktest.lan/api/v1',
remote: 'http://tktest.lan/api/v1',
// local: 'http://localhost:8000/api/v1',
remote: 'http://localhost:8000/api/v1',
// remote: 'http://localhost:8000/api/v1',
// remote: 'https://framadate-api.cipherbliss.com/api/v1',
};
export const apiV1 = {
baseHref: 'http://localhost:8000/api/v1',
// baseHref: 'http://tktest.lan/api/v1',
// baseHref: 'http://localhost:8000/api/v1',
baseHref: 'http://tktest.lan/api/v1',
// baseHref: 'https://framadate-api.cipherbliss.com/api/v1',
api_new_poll: '/poll/',
api_get_poll: '/poll/{id}',