diff --git a/src/app/core/models/owner.model.ts b/src/app/core/models/owner.model.ts index 693d3398..580afd49 100644 --- a/src/app/core/models/owner.model.ts +++ b/src/app/core/models/owner.model.ts @@ -6,8 +6,8 @@ export class Owner { public pseudo: string = 'pseudo', public email: string = '_nonexistent_contact@cipherbliss.com', public polls: Poll[] = [], - public role?: UserRole, - public modifier_token?: string, - public created_at?: string + public role: UserRole = UserRole.ADMIN, + public modifier_token: string = '', + public created_at: string = new Date().toISOString() ) {} } diff --git a/src/app/core/services/date.utilities.service.ts b/src/app/core/services/date.utilities.service.ts index 0f5a52a2..e6519eb2 100644 --- a/src/app/core/services/date.utilities.service.ts +++ b/src/app/core/services/date.utilities.service.ts @@ -100,8 +100,6 @@ export class DateUtilitiesService { const ladate2 = this.addDaysToDate(1, today); const ladate3 = this.addDaysToDate(2, today); const ladate4 = this.addDaysToDate(3, today); - const ladate5 = this.addDaysToDate(4, today); - const ladate6 = this.addDaysToDate(5, today); return [ { @@ -124,16 +122,6 @@ export class DateUtilitiesService { timeSlices: Object.create(defaultTimeOfDay), date_object: ladate4, }, - { - literal: this.formateDateToInputStringNg(ladate5), - timeSlices: Object.create(defaultTimeOfDay), - date_object: ladate5, - }, - { - literal: this.formateDateToInputStringNg(ladate6), - timeSlices: Object.create(defaultTimeOfDay), - date_object: ladate6, - }, ]; } } diff --git a/src/app/core/services/poll.service.ts b/src/app/core/services/poll.service.ts index e9ab0e1e..71fa9219 100644 --- a/src/app/core/services/poll.service.ts +++ b/src/app/core/services/poll.service.ts @@ -47,7 +47,7 @@ export class PollService implements Resolve { public showDateInterval = false; public allowSeveralHours = false; public richTextMode = false; - public calendar: any; + public calendar: any = [new Date()]; constructor( private http: HttpClient, @@ -64,11 +64,18 @@ export class PollService implements Resolve { private fb: FormBuilder ) { this.createFormGroup(); + + this.calendar = [ + this.DateUtilitiesService.addDaysToDate(1, new Date()), + this.DateUtilitiesService.addDaysToDate(2, new Date()), + this.DateUtilitiesService.addDaysToDate(3, new Date()), + ]; if (environment.autofill_creation) { this.setDemoValues(); this.toastService.display('auto fill de création fait'); - } else { - this.calendar = [new Date()]; + } + if (environment.autoSendNewPoll) { + this.createPoll(); } } @@ -80,11 +87,6 @@ export class PollService implements Resolve { this.addChoice('raisin'); this.addChoice('abricot'); - this.calendar = [ - this.DateUtilitiesService.addDaysToDate(1, new Date()), - this.DateUtilitiesService.addDaysToDate(2, new Date()), - this.DateUtilitiesService.addDaysToDate(3, new Date()), - ]; this.form.patchValue({ title: 'mon titre', description: 'répondez SVP <3 ! *-* ', @@ -145,6 +147,26 @@ export class PollService implements Resolve { return form; } + public patchFormDefaultValues() { + this.form.patchValue({ + title: 'mon titre de sondage', + description: '', + custom_url: this.uuidService.getUUID(), + creatorPseudo: '', + creatorEmail: '', + isAboutDate: true, + whoModifiesAnswers: 'everybody', + whoCanChangeAnswers: 'everybody', + isProtectedByPassword: false, + richTextMode: false, + areResultsPublic: true, + expiracyNumberOfDays: 60, + maxCountOfAnswers: 300, + voterEmailList: '', + password: '', + }); + } + public updateSlug(): void { console.log('this.form.value', this.form.value); this.form.patchValue({ custom_url: this.makeSlug(this.form) }); @@ -355,8 +377,9 @@ export class PollService implements Resolve { } public createPoll(): void { + this.toastService.display('sending...'); console.log('this.form', this.form); - const newpoll = this.newPollFromForm(this.form); + const newpoll = this.newPollFromForm(); this.apiService.createPoll(newpoll).then((resp) => { console.log('poll created resp', resp); console.log('TODO fill admin_key'); @@ -409,6 +432,7 @@ export class PollService implements Resolve { initFormDefault(showDemoValues = true): void { this.form = this.createFormGroup(); + this.patchFormDefaultValues(); this.setDefaultDatesForInterval(); if (showDemoValues) { @@ -544,10 +568,12 @@ export class PollService implements Resolve { public getParticipationUrlFromForm(): string { return `${environment.frontDomain}#/poll/${this.form.value.custom_url}/consultation`; } + public getAdministrationUrlFromForm(): string { // admin_key is filled after creation return `${environment.frontDomain}#/admin/${this.admin_key}/consultation`; } + public getParticipationUrl(): string { // http://localhost:4200/#/poll/dessin-anime/consultation @@ -567,6 +593,7 @@ export class PollService implements Resolve { // TODO handle pass access return url; } + public getAdministrationUrl(): string { // http://localhost:4200/#/admin/9S75b70ECXI5J5xDc058d3H40H9r2CHfO0Kj8T02EK2U8rY8fYTn-eS659j2Dhp794Oa6R1b9V70e3WGaE30iD9h45zwdm76C85SWB4LcUCrc7e0Ncc0 @@ -597,6 +624,7 @@ export class PollService implements Resolve { }); } } + /** * find an existing vote in vote_stack from its choice_id * @param choice_id @@ -609,6 +637,7 @@ export class PollService implements Resolve { } }); } + convertCalendarDatesToChoices(array_dates) { return array_dates; } @@ -617,7 +646,9 @@ export class PollService implements Resolve { * @description convert to API version 1 data transition object * @param form */ - newPollFromForm(form: any): Poll { + newPollFromForm(): Poll { + let form = this.form; + console.log('this.form.value', this.form.value); const newOwner = this.storageService.vote_stack.owner; const newpoll = new Poll(newOwner, form.value.custom_url, form.value.title); @@ -626,6 +657,7 @@ export class PollService implements Resolve { const formFields = Object.keys(form.value); newpoll.allowed_answers = []; + // comparer les champs de formulaire avec le DTO de création de sondage for (const pk of pollKeys) { if (formFields.indexOf(pk) !== -1) { const field = form.value[pk]; @@ -646,18 +678,29 @@ export class PollService implements Resolve { } newpoll.description = form.value.description; newpoll.has_several_hours = form.value.hasSeveralHours; - newpoll.hasSeveralHours = form.value.hasSeveralHours; - newpoll.max_count_of_answers = form.value.allowComments; + newpoll.max_count_of_answers = form.value.maxCountOfAnswers; newpoll.maxCountOfAnswers = form.value.maxCountOfAnswers; newpoll.password = form.value.password; - newpoll.kind = form.value.kind; + newpoll.kind = form.value.isAboutDate ? 'date' : 'classic'; newpoll.allow_comments = form.value.allowComments; // merge choices from storage - if (form.value.kind === 'date') { + if (form.value.isAboutDate) { // convert calendar picker dates + console.log('this.calendar', this.calendar); + + for (let elem of this.calendar) { + console.log('elem', elem); + let converted_day = { + literal: this.DateUtilitiesService.formateDateToInputStringNg(elem), + timeSlices: [], + date_object: elem, + }; + newpoll.dateChoices.push(converted_day); + } + console.log('newpoll.dateChoices', newpoll.dateChoices); } 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); console.log('newpoll', newpoll); return newpoll; diff --git a/src/app/features/administration/form/steps/step-four/step-four.component.ts b/src/app/features/administration/form/steps/step-four/step-four.component.ts index ad497bd0..20d1e7c3 100644 --- a/src/app/features/administration/form/steps/step-four/step-four.component.ts +++ b/src/app/features/administration/form/steps/step-four/step-four.component.ts @@ -1,6 +1,7 @@ import { Component, Input, OnInit } from '@angular/core'; import { PollService } from '../../../../../core/services/poll.service'; import { ApiService } from '../../../../../core/services/api.service'; +import { environment } from '../../../../../../environments/environment'; @Component({ selector: 'app-step-four', @@ -9,7 +10,7 @@ import { ApiService } from '../../../../../core/services/api.service'; }) export class StepFourComponent implements OnInit { urlPrefix: any; - advancedDisplayEnabled: boolean = true; + advancedDisplayEnabled: boolean = environment.advanced_options_display; @Input() step_max: any; @Input() diff --git a/src/environments/environment.prod.ts b/src/environments/environment.prod.ts index 06cc98cd..7be35465 100644 --- a/src/environments/environment.prod.ts +++ b/src/environments/environment.prod.ts @@ -18,6 +18,7 @@ export const environment = { showDemoWarning: true, autofill_creation: true, autofill_participation: true, + advanced_options_display: false, autoSendNewPoll: false, interval_days_default: 7, expiresDaysDelay: 60, diff --git a/src/environments/environment.ts b/src/environments/environment.ts index c52cbea7..b7b112db 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -12,10 +12,11 @@ export const environment = { production: false, display_routes: false, // demo paths to test polls autofill_creation: true, + advanced_options_display: false, autofill_participation: true, // autofill: false, showDemoWarning: false, - autoSendNewPoll: false, + autoSendNewPoll: true, interval_days_default: 7, expiresDaysDelay: 60, maxCountOfAnswers: 150,