remove logs on upgrade vote stack

This commit is contained in:
Tykayn 2021-06-08 14:30:05 +02:00 committed by tykayn
parent 5c290ea968
commit 09ff4be2f6
7 changed files with 53 additions and 36 deletions

View File

@ -7,6 +7,7 @@ export class Owner {
public email: string = '_nonexistent_contact@cipherbliss.com', public email: string = '_nonexistent_contact@cipherbliss.com',
public polls: Poll[] = [], public polls: Poll[] = [],
public role?: UserRole, public role?: UserRole,
public modifier_token?: string public modifier_token?: string,
public created_at?: string
) {} ) {}
} }

View File

@ -62,11 +62,12 @@ export class PollService implements Resolve<Poll> {
} }
} }
getAllAvailablePolls() { /**
* get all polls
*/
getAllAvailablePolls(): void {
const baseHref = environment.api.version.apiV1.baseHref; const baseHref = environment.api.version.apiV1.baseHref;
console.log('getAllAvailablePolls baseHref', baseHref);
const headers = ApiService.makeHeaders(); const headers = ApiService.makeHeaders();
console.log('getAllAvailablePolls headers', headers);
try { try {
this.http.get(`${baseHref}/poll`, headers).subscribe((res: Observable<any>) => { this.http.get(`${baseHref}/poll`, headers).subscribe((res: Observable<any>) => {
console.log('getAllAvailablePolls res', res); console.log('getAllAvailablePolls res', res);
@ -77,16 +78,15 @@ export class PollService implements Resolve<Poll> {
} }
public async loadPollBycustom_url(custom_url: string): Promise<void> { public async loadPollBycustom_url(custom_url: string): Promise<void> {
console.log('custom_url', custom_url);
if (custom_url) { if (custom_url) {
const poll: Poll | undefined = await this.apiService.getPollByCustomUrl(custom_url); const poll: Poll | undefined = await this.apiService.getPollByCustomUrl(custom_url);
console.log('loadPollBycustom_urlResponse', poll);
if (poll) { if (poll) {
this.updateCurrentPoll(poll); this.updateCurrentPoll(poll);
this.titleService.setTitle(`☑️ ${poll.title} - ${environment.appTitle}`); this.titleService.setTitle(`☑️ ${poll.title} - ${environment.appTitle}`);
} else { } else {
this.toastService.display(`sondage ${custom_url} non trouvé`); this.toastService.display(`sondage ${custom_url} non trouvé`);
this.router.navigate(['page-not-found']);
} }
} else { } else {
this.toastService.display(`sondage sans custom url : ${custom_url}`); this.toastService.display(`sondage sans custom url : ${custom_url}`);
@ -94,11 +94,18 @@ export class PollService implements Resolve<Poll> {
} }
public async loadPollBycustom_urlWithPasswordHash(custom_url: string, hash: string): Promise<void> { public async loadPollBycustom_urlWithPasswordHash(custom_url: string, hash: string): Promise<void> {
console.log('custom_url', custom_url);
if (custom_url) { if (custom_url) {
const poll: Poll | undefined = await this.apiService.getPollByCustomUrlWithHash(custom_url, hash); const poll: Poll | undefined = await this.apiService.getPollByCustomUrlWithHash(custom_url, hash);
console.log({ loadPollBycustom_urlResponse: poll });
this.updateCurrentPoll(poll); if (poll) {
this.updateCurrentPoll(poll);
this.titleService.setTitle(`☑️ ${poll.title} - ${environment.appTitle}`);
} else {
this.toastService.display(`sondage ${custom_url} non trouvé`);
this.router.navigate(['page-not-found']);
}
} else {
this.toastService.display(`sondage sans custom url : ${custom_url}`);
} }
} }
@ -107,17 +114,18 @@ export class PollService implements Resolve<Poll> {
* @param poll * @param poll
*/ */
public updateCurrentPoll(poll: Poll): void { public updateCurrentPoll(poll: Poll): void {
console.log('update poll with: ', poll); console.log('this.storageService.vote_stack.id', this.storageService.vote_stack.id);
if (!this.storageService.vote_stack.id || this.storageService.vote_stack.poll_custom_url !== poll.custom_url) { if (
!this.storageService.vote_stack.id
// || this.storageService.vote_stack.poll_custom_url !== poll.custom_url
) {
console.log('set base choices', poll.choices); console.log('set base choices', poll.choices);
// set the choices only the first time the poll loads // set the choices only the first time the poll loads
this.storageService.setChoicesForVoteStack(poll.choices); this.storageService.setChoicesForVoteStack(poll.choices);
} }
this.toastService.display('sondage bien mis à jour', 'success'); this.toastService.display('sondage bien mis à jour', 'success');
console.log('poll', poll);
this._poll.next(poll); this._poll.next(poll);
} }
@ -126,7 +134,6 @@ export class PollService implements Resolve<Poll> {
* @param poll * @param poll
*/ */
makecustom_url(poll: Poll): string { makecustom_url(poll: Poll): string {
console.log('config', poll);
let str = ''; let str = '';
const creation_date = new Date(poll.creation_date); const creation_date = new Date(poll.creation_date);
str = str =
@ -163,10 +170,6 @@ export class PollService implements Resolve<Poll> {
} }
public saveParticipation(choice: Choice, user: Owner, response: Answer): void { public saveParticipation(choice: Choice, user: Owner, response: Answer): void {
const currentPoll = this._poll.getValue();
currentPoll.choices.find((c) => c.name === choice.name)?.updateParticipation(user, response);
this.updateCurrentPoll(currentPoll);
this.apiService.createParticipation(currentPoll.custom_url, choice.name, user.pseudo, response);
this.toastService.display('Votre participation au sondage a été enregistrée.'); this.toastService.display('Votre participation au sondage a été enregistrée.');
} }
@ -196,8 +199,6 @@ export class PollService implements Resolve<Poll> {
const pollKeys = Object.keys(newpoll); const pollKeys = Object.keys(newpoll);
const formFields = Object.keys(form.value); const formFields = Object.keys(form.value);
console.log('pollKeys, formFields', pollKeys, formFields);
newpoll.allowed_answers = ['yes']; newpoll.allowed_answers = ['yes'];
for (const pk of pollKeys) { for (const pk of pollKeys) {
@ -227,9 +228,6 @@ export class PollService implements Resolve<Poll> {
newpoll.choices = Object.assign([], this.storageService.choices); newpoll.choices = Object.assign([], this.storageService.choices);
newpoll.dateChoices = Object.assign([], this.storageService.dateChoices); newpoll.dateChoices = Object.assign([], this.storageService.dateChoices);
newpoll.timeSlices = Object.assign([], this.storageService.timeSlices); newpoll.timeSlices = Object.assign([], this.storageService.timeSlices);
console.log('this.storageService.timeSlices', this.storageService.timeSlices, newpoll.timeSlices);
return newpoll; return newpoll;
} }

View File

@ -60,10 +60,15 @@ export class StorageService {
} }
} }
/**
* set default choices for the vote stack from the poll choices objects
* @param choices_list
*/
setChoicesForVoteStack(choices_list: Choice[]) { setChoicesForVoteStack(choices_list: Choice[]) {
// text choices // text choices
if (!this.vote_stack.id) { if (!this.vote_stack.id) {
this.vote_stack.votes = []; this.vote_stack = new Stack();
for (const choice of choices_list) { for (const choice of choices_list) {
if (environment.autofill) { if (environment.autofill) {
console.log('autofill au hasard des votes à ce sondage'); console.log('autofill au hasard des votes à ce sondage');
@ -77,8 +82,12 @@ export class StorageService {
} }
} }
/**
* look for a choice in the stored vote stack and change it answer
* @param choice_id
* @param value
*/
toggleAnswer(choice_id: number, value: string) { toggleAnswer(choice_id: number, value: string) {
console.log('this.vote_stack', this.vote_stack);
for (const vote of this.vote_stack.votes) { for (const vote of this.vote_stack.votes) {
if (vote.choice_id == choice_id) { if (vote.choice_id == choice_id) {
if (vote.value == value) { if (vote.value == value) {
@ -90,6 +99,11 @@ export class StorageService {
} }
} }
/**
* check for the value of a choice in the stored vote stack
* @param choice_id
* @param value
*/
choiceHasAnswerOfValue(choice_id: number, value: any) { choiceHasAnswerOfValue(choice_id: number, value: any) {
for (const vote of this.vote_stack.votes) { for (const vote of this.vote_stack.votes) {
if (vote.choice_id == choice_id) { if (vote.choice_id == choice_id) {
@ -116,11 +130,13 @@ export class StorageService {
}); });
} }
/**
* update vote stack from the backend
* @param resp
*/
mapVotes(resp) { mapVotes(resp) {
console.log('data', resp.data); console.log('mapVotes resp.data', resp.data);
console.log('this.vote_stack', this.vote_stack);
this.vote_stack.owner = resp.data.owner; this.vote_stack.owner = resp.data.owner;
this.vote_stack.id = resp.data.id; this.vote_stack.id = resp.data.id;
console.log('this.vote_stack', this.vote_stack);
} }
} }

View File

@ -98,7 +98,7 @@ export class ConsultationComponent implements OnInit, OnDestroy {
.sendUpdateVoteStack(vote_stack) .sendUpdateVoteStack(vote_stack)
.then((resp) => { .then((resp) => {
console.log('sendUpdateVoteStack updated resp', resp); console.log('sendUpdateVoteStack updated resp', resp);
// this.storeVoteStackAndReloadPoll(resp); this.storeVoteStackAndReloadPoll(resp);
this.toastService.display('vote bien mis à jour', 'success'); this.toastService.display('vote bien mis à jour', 'success');
}) })
.catch(handlingError); .catch(handlingError);

View File

@ -9,4 +9,5 @@
&:active { &:active {
border-color: #6c99ff; border-color: #6c99ff;
} }
margin-left: 1ch;
} }

View File

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

View File

@ -11,7 +11,8 @@ export const environment = {
frontDomain: 'http://127.0.0.1:4200', frontDomain: 'http://127.0.0.1:4200',
production: false, production: false,
display_routes: true, display_routes: true,
autofill: true, // autofill: true,
autofill: false,
showDemoWarning: true, showDemoWarning: true,
autoSendNewPoll: false, autoSendNewPoll: false,
interval_days_default: 7, interval_days_default: 7,