convert calendar dates to DTO creation

This commit is contained in:
Tykayn 2021-11-12 12:50:21 +01:00 committed by tykayn
parent 3dc7555747
commit cb971a5421
6 changed files with 66 additions and 32 deletions

View File

@ -6,8 +6,8 @@ export class Owner {
public pseudo: string = 'pseudo', public pseudo: string = 'pseudo',
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 = UserRole.ADMIN,
public modifier_token?: string, public modifier_token: string = '',
public created_at?: string public created_at: string = new Date().toISOString()
) {} ) {}
} }

View File

@ -100,8 +100,6 @@ export class DateUtilitiesService {
const ladate2 = this.addDaysToDate(1, today); const ladate2 = this.addDaysToDate(1, today);
const ladate3 = this.addDaysToDate(2, today); const ladate3 = this.addDaysToDate(2, today);
const ladate4 = this.addDaysToDate(3, today); const ladate4 = this.addDaysToDate(3, today);
const ladate5 = this.addDaysToDate(4, today);
const ladate6 = this.addDaysToDate(5, today);
return [ return [
{ {
@ -124,16 +122,6 @@ export class DateUtilitiesService {
timeSlices: Object.create(defaultTimeOfDay), timeSlices: Object.create(defaultTimeOfDay),
date_object: ladate4, 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,
},
]; ];
} }
} }

View File

@ -47,7 +47,7 @@ export class PollService implements Resolve<Poll> {
public showDateInterval = false; public showDateInterval = false;
public allowSeveralHours = false; public allowSeveralHours = false;
public richTextMode = false; public richTextMode = false;
public calendar: any; public calendar: any = [new Date()];
constructor( constructor(
private http: HttpClient, private http: HttpClient,
@ -64,11 +64,18 @@ export class PollService implements Resolve<Poll> {
private fb: FormBuilder private fb: FormBuilder
) { ) {
this.createFormGroup(); 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) { if (environment.autofill_creation) {
this.setDemoValues(); this.setDemoValues();
this.toastService.display('auto fill de création fait'); 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<Poll> {
this.addChoice('raisin'); this.addChoice('raisin');
this.addChoice('abricot'); 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({ this.form.patchValue({
title: 'mon titre', title: 'mon titre',
description: 'répondez SVP <3 ! *-* ', description: 'répondez SVP <3 ! *-* ',
@ -145,6 +147,26 @@ export class PollService implements Resolve<Poll> {
return form; 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 { public updateSlug(): void {
console.log('this.form.value', this.form.value); console.log('this.form.value', this.form.value);
this.form.patchValue({ custom_url: this.makeSlug(this.form) }); this.form.patchValue({ custom_url: this.makeSlug(this.form) });
@ -355,8 +377,9 @@ export class PollService implements Resolve<Poll> {
} }
public createPoll(): void { public createPoll(): void {
this.toastService.display('sending...');
console.log('this.form', this.form); console.log('this.form', this.form);
const newpoll = this.newPollFromForm(this.form); const newpoll = this.newPollFromForm();
this.apiService.createPoll(newpoll).then((resp) => { this.apiService.createPoll(newpoll).then((resp) => {
console.log('poll created resp', resp); console.log('poll created resp', resp);
console.log('TODO fill admin_key'); console.log('TODO fill admin_key');
@ -409,6 +432,7 @@ export class PollService implements Resolve<Poll> {
initFormDefault(showDemoValues = true): void { initFormDefault(showDemoValues = true): void {
this.form = this.createFormGroup(); this.form = this.createFormGroup();
this.patchFormDefaultValues();
this.setDefaultDatesForInterval(); this.setDefaultDatesForInterval();
if (showDemoValues) { if (showDemoValues) {
@ -544,10 +568,12 @@ export class PollService implements Resolve<Poll> {
public getParticipationUrlFromForm(): string { public getParticipationUrlFromForm(): string {
return `${environment.frontDomain}#/poll/${this.form.value.custom_url}/consultation`; return `${environment.frontDomain}#/poll/${this.form.value.custom_url}/consultation`;
} }
public getAdministrationUrlFromForm(): string { public getAdministrationUrlFromForm(): string {
// admin_key is filled after creation // admin_key is filled after creation
return `${environment.frontDomain}#/admin/${this.admin_key}/consultation`; return `${environment.frontDomain}#/admin/${this.admin_key}/consultation`;
} }
public getParticipationUrl(): string { public getParticipationUrl(): string {
// http://localhost:4200/#/poll/dessin-anime/consultation // http://localhost:4200/#/poll/dessin-anime/consultation
@ -567,6 +593,7 @@ export class PollService implements Resolve<Poll> {
// TODO handle pass access // TODO handle pass access
return url; return url;
} }
public getAdministrationUrl(): string { public getAdministrationUrl(): string {
// http://localhost:4200/#/admin/9S75b70ECXI5J5xDc058d3H40H9r2CHfO0Kj8T02EK2U8rY8fYTn-eS659j2Dhp794Oa6R1b9V70e3WGaE30iD9h45zwdm76C85SWB4LcUCrc7e0Ncc0 // http://localhost:4200/#/admin/9S75b70ECXI5J5xDc058d3H40H9r2CHfO0Kj8T02EK2U8rY8fYTn-eS659j2Dhp794Oa6R1b9V70e3WGaE30iD9h45zwdm76C85SWB4LcUCrc7e0Ncc0
@ -597,6 +624,7 @@ export class PollService implements Resolve<Poll> {
}); });
} }
} }
/** /**
* find an existing vote in vote_stack from its choice_id * find an existing vote in vote_stack from its choice_id
* @param choice_id * @param choice_id
@ -609,6 +637,7 @@ export class PollService implements Resolve<Poll> {
} }
}); });
} }
convertCalendarDatesToChoices(array_dates) { convertCalendarDatesToChoices(array_dates) {
return array_dates; return array_dates;
} }
@ -617,7 +646,9 @@ export class PollService implements Resolve<Poll> {
* @description convert to API version 1 data transition object * @description convert to API version 1 data transition object
* @param form * @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 newOwner = this.storageService.vote_stack.owner;
const newpoll = new Poll(newOwner, form.value.custom_url, form.value.title); const newpoll = new Poll(newOwner, form.value.custom_url, form.value.title);
@ -626,6 +657,7 @@ export class PollService implements Resolve<Poll> {
const formFields = Object.keys(form.value); const formFields = Object.keys(form.value);
newpoll.allowed_answers = []; newpoll.allowed_answers = [];
// comparer les champs de formulaire avec le DTO de création de sondage
for (const pk of pollKeys) { for (const pk of pollKeys) {
if (formFields.indexOf(pk) !== -1) { if (formFields.indexOf(pk) !== -1) {
const field = form.value[pk]; const field = form.value[pk];
@ -646,18 +678,29 @@ export class PollService implements Resolve<Poll> {
} }
newpoll.description = form.value.description; newpoll.description = form.value.description;
newpoll.has_several_hours = form.value.hasSeveralHours; newpoll.has_several_hours = form.value.hasSeveralHours;
newpoll.hasSeveralHours = form.value.hasSeveralHours; newpoll.max_count_of_answers = form.value.maxCountOfAnswers;
newpoll.max_count_of_answers = form.value.allowComments;
newpoll.maxCountOfAnswers = form.value.maxCountOfAnswers; newpoll.maxCountOfAnswers = form.value.maxCountOfAnswers;
newpoll.password = form.value.password; newpoll.password = form.value.password;
newpoll.kind = form.value.kind; newpoll.kind = form.value.isAboutDate ? 'date' : 'classic';
newpoll.allow_comments = form.value.allowComments; newpoll.allow_comments = form.value.allowComments;
// merge choices from storage // merge choices from storage
if (form.value.kind === 'date') { if (form.value.isAboutDate) {
// convert calendar picker dates // 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.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('newpoll', newpoll); console.log('newpoll', newpoll);
return newpoll; return newpoll;

View File

@ -1,6 +1,7 @@
import { Component, Input, OnInit } from '@angular/core'; import { Component, Input, OnInit } from '@angular/core';
import { PollService } from '../../../../../core/services/poll.service'; import { PollService } from '../../../../../core/services/poll.service';
import { ApiService } from '../../../../../core/services/api.service'; import { ApiService } from '../../../../../core/services/api.service';
import { environment } from '../../../../../../environments/environment';
@Component({ @Component({
selector: 'app-step-four', selector: 'app-step-four',
@ -9,7 +10,7 @@ import { ApiService } from '../../../../../core/services/api.service';
}) })
export class StepFourComponent implements OnInit { export class StepFourComponent implements OnInit {
urlPrefix: any; urlPrefix: any;
advancedDisplayEnabled: boolean = true; advancedDisplayEnabled: boolean = environment.advanced_options_display;
@Input() @Input()
step_max: any; step_max: any;
@Input() @Input()

View File

@ -18,6 +18,7 @@ export const environment = {
showDemoWarning: true, showDemoWarning: true,
autofill_creation: true, autofill_creation: true,
autofill_participation: true, autofill_participation: true,
advanced_options_display: false,
autoSendNewPoll: false, autoSendNewPoll: false,
interval_days_default: 7, interval_days_default: 7,
expiresDaysDelay: 60, expiresDaysDelay: 60,

View File

@ -12,10 +12,11 @@ export const environment = {
production: false, production: false,
display_routes: false, // demo paths to test polls display_routes: false, // demo paths to test polls
autofill_creation: true, autofill_creation: true,
advanced_options_display: false,
autofill_participation: true, autofill_participation: true,
// autofill: false, // autofill: false,
showDemoWarning: false, showDemoWarning: false,
autoSendNewPoll: false, autoSendNewPoll: true,
interval_days_default: 7, interval_days_default: 7,
expiresDaysDelay: 60, expiresDaysDelay: 60,
maxCountOfAnswers: 150, maxCountOfAnswers: 150,