diff --git a/src/app/core/models/poll.model.ts b/src/app/core/models/poll.model.ts index 198a7eda..358b3acc 100644 --- a/src/app/core/models/poll.model.ts +++ b/src/app/core/models/poll.model.ts @@ -20,6 +20,7 @@ export class Poll { public kind: string; public description?: string; + public password?: string; public expiracy_date?: string; @@ -32,6 +33,7 @@ export class Poll { public is_archived?: boolean; public is_zero_knowledge?: boolean = false; public allow_comments?: boolean = true; + public allowComments?: boolean = true; public has_several_hours?: boolean = false; public allowSeveralHours?: boolean; @@ -41,8 +43,9 @@ export class Poll { public max_score?: number; public max_count_of_answers?: number = 150; + public maxCountOfAnswers?: number = 150; - public configuration: PollConfiguration = new PollConfiguration(); + // public configuration: PollConfiguration = new PollConfiguration(); public comments: Comment[] = []; diff --git a/src/app/core/services/poll.service.ts b/src/app/core/services/poll.service.ts index daeb7811..73163d38 100644 --- a/src/app/core/services/poll.service.ts +++ b/src/app/core/services/poll.service.ts @@ -14,7 +14,6 @@ import { HttpClient } from '@angular/common/http'; import { environment } from '../../../environments/environment'; import { StorageService } from './storage.service'; import { Title } from '@angular/platform-browser'; -import { TimeSlices } from '../../../../mocks/old-stuff/config/defaultConfigs'; @Injectable({ providedIn: 'root', @@ -93,6 +92,7 @@ export class PollService implements Resolve { } } } + public async loadPollBycustom_urlWithPasswordHash(custom_url: string, hash: string): Promise { console.log('custom_url', custom_url); if (custom_url) { @@ -107,9 +107,6 @@ export class PollService implements Resolve { * @param poll */ public updateCurrentPoll(poll: Poll): void { - if (poll.kind == 'date') { - poll.choices = this.parseDateChoices(poll.choices); - } this.storageService.setChoicesForVoteStack(poll.choices); this.toastService.display('sondage bien mis à jour', 'success'); @@ -120,21 +117,22 @@ export class PollService implements Resolve { /** * make a uniq custom_url for the current poll creation - * @param config + * @param poll */ - makecustom_url(config: Poll): string { - console.log('config', config); + makecustom_url(poll: Poll): string { + console.log('config', poll); let str = ''; + const creation_date = new Date(poll.creation_date); str = - config.configuration.dateCreated.getFullYear() + + creation_date.getFullYear() + '_' + - (config.configuration.dateCreated.getMonth() + 1) + + (creation_date.getMonth() + 1) + '_' + - config.configuration.dateCreated.getDate() + + creation_date.getDate() + '_' + - config.owner.pseudo + + poll.owner.pseudo + '_' + - config.title; + poll.title; str = str.replace(/^\s+|\s+$/g, ''); // trim str = str.toLowerCase(); @@ -205,11 +203,21 @@ export class PollService implements Resolve { const pollKeys = Object.keys(newpoll); const formFields = Object.keys(form.value); - for (const fieldOfForm of formFields) { - if (pollKeys.indexOf(fieldOfForm) !== -1) { - newpoll[fieldOfForm] = form.value[fieldOfForm]; + console.log('pollKeys, formFields', pollKeys, formFields); + + for (const pk of pollKeys) { + if (formFields.indexOf(pk) !== -1) { + newpoll[pk] = form.value[pk]; + } else { + console.log('manque pollKey', pk); } } + newpoll.description = form.value.description; + newpoll.max_count_of_answers = form.value.allowComments; + newpoll.maxCountOfAnswers = form.value.maxCountOfAnswers; + newpoll.password = form.value.password; + newpoll.kind = form.value.kind; + newpoll.allow_comments = form.value.allowComments; newpoll.dateChoices = this.storageService.dateList; newpoll.timeSlices = this.storageService.timeSlices; @@ -217,20 +225,26 @@ export class PollService implements Resolve { return newpoll; } - /** - * regrouper les jours et périodes de temps - * @param choices - */ - public parseDateChoices(choices: Choice[]) { - console.log('choices before', choices); - return choices; + public getAdministrationUrl(): string { + let url = ''; + if (this._poll && this._poll.getValue) { + const polltemp = this._poll.getValue(); + if (polltemp) { + url = `${environment.frontDomain}#/poll/admin/${polltemp.admin_key}`; + } + } + return url; } - public getAdministrationUrl(): string { - return `${environment.frontDomain}#/poll/admin/${this._poll.getValue().admin_key}`; - } public getParticipationUrl(): string { + let url = ''; + if (this._poll && this._poll.getValue) { + const polltemp = this._poll.getValue(); + if (polltemp) { + url = `${environment.frontDomain}#/poll/${polltemp.custom_url}/consultation`; + } + } // TODO handle pass access - return `${environment.frontDomain}#/poll/${this._poll.getValue().custom_url}/consultation`; + return url; } } diff --git a/src/app/core/services/storage.service.ts b/src/app/core/services/storage.service.ts index 7017dc94..c37997db 100644 --- a/src/app/core/services/storage.service.ts +++ b/src/app/core/services/storage.service.ts @@ -72,10 +72,4 @@ export class StorageService { } return false; } - - parseDateChoices(datechoices) { - const choices: Choice[] = []; - - return choices; - } } diff --git a/src/app/features/administration/form/base-config/base-config.component.html b/src/app/features/administration/form/base-config/base-config.component.html index d1884a65..a898a25d 100644 --- a/src/app/features/administration/form/base-config/base-config.component.html +++ b/src/app/features/administration/form/base-config/base-config.component.html @@ -63,6 +63,8 @@
+ custom url: + {{ form.value.custom_url }}
diff --git a/src/app/features/administration/form/form.component.ts b/src/app/features/administration/form/form.component.ts index 20955fbb..eb229f61 100644 --- a/src/app/features/administration/form/form.component.ts +++ b/src/app/features/administration/form/form.component.ts @@ -115,13 +115,16 @@ export class FormComponent implements OnInit { isAboutDate: true, // hasSeveralHours: true, kind: 'date', + password: '', whoCanChangeAnswers: 'everybody', isProtectedByPassword: false, isOwnerNotifiedByEmailOnNewVote: false, isOwnerNotifiedByEmailOnNewComment: false, isMaybeAnswerAvailable: false, areResultsPublic: true, + allowComments: true, expiresDaysDelay: 60, + maxCountOfAnswers: 150, comments: [], choices: [ { diff --git a/src/app/features/consultation/consultation.component.ts b/src/app/features/consultation/consultation.component.ts index d3478eff..e449a74e 100644 --- a/src/app/features/consultation/consultation.component.ts +++ b/src/app/features/consultation/consultation.component.ts @@ -99,7 +99,6 @@ export class ConsultationComponent implements OnInit, OnDestroy { if (resp) { const response: Promise = this.api.getPollByCustomUrl(this.poll.custom_url); response.then((res: Poll | undefined) => { - res.choices = this.pollService.parseDateChoices(res.choices); this.pollService._poll.next(res); }); } else {