From 2e8a1aa12b29dda84a6102f90f058e9e67c65da0 Mon Sep 17 00:00:00 2001 From: Tykayn Date: Mon, 22 Nov 2021 10:09:50 +0100 Subject: [PATCH] :zap: convert date list on poll creation --- src/app/core/services/poll.service.ts | 20 +++++++++++++++---- .../step-three/step-three.component.html | 14 +++++++------ .../steps/step-three/step-three.component.ts | 7 ++++--- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/src/app/core/services/poll.service.ts b/src/app/core/services/poll.service.ts index ed9ba9ab..f36a1339 100644 --- a/src/app/core/services/poll.service.ts +++ b/src/app/core/services/poll.service.ts @@ -47,6 +47,7 @@ export class PollService implements Resolve { public showDateInterval = false; public allowSeveralHours = false; public richTextMode = false; + public mode_calendar = false; public calendar: Date[] = [new Date()]; public disabled_dates: Date[] = []; @@ -679,7 +680,7 @@ export class PollService implements Resolve { /** * convert the DateChoices to an arrray of Dates for calendar picker */ - convertTextToCalendar() { + convertTextToCalendar(): Date[] { console.log('convert text to calendar', this.dateChoiceList); let converted = []; for (let someDateChoice of this.dateChoiceList) { @@ -693,7 +694,7 @@ export class PollService implements Resolve { console.log('converted', converted); this.calendar = converted; - return; + return converted; } patchFormWithPoll(poll: Poll) { @@ -745,10 +746,21 @@ export class PollService implements Resolve { newpoll.allow_comments = form.value.allowComments; // merge choices from storage if (form.value.isAboutDate) { - // convert calendar picker dates + // first we convert calendar picker dates. + // we want a list of date object, and we want the kind of dates who was lastly edited by the user + // depending on the manual or datepicker mode, we need to get a converted list of dates + let convertedDates = []; + if (this.mode_calendar) { + // mode calendar date picker, we take the list of date objects in calendar property + convertedDates = this.calendar; + } else { + // mode text, we convert to calendar list, and take that list + convertedDates = this.convertTextToCalendar(); + } + console.log('this.calendar', this.calendar); - for (let elem of this.calendar) { + for (let elem of convertedDates) { console.log('elem', elem); let converted_day = this.DateUtilitiesService.convertDateToDateChoiceObject(elem); newpoll.dateChoices.push(converted_day); diff --git a/src/app/features/administration/form/steps/step-three/step-three.component.html b/src/app/features/administration/form/steps/step-three/step-three.component.html index 4ccb5947..c16264f4 100644 --- a/src/app/features/administration/form/steps/step-three/step-three.component.html +++ b/src/app/features/administration/form/steps/step-three/step-three.component.html @@ -2,7 +2,7 @@ -
+
-
+
-
@@ -88,7 +90,7 @@ type="text" id="timeChoices_{{ id }}" /> -
diff --git a/src/app/features/administration/form/steps/step-three/step-three.component.ts b/src/app/features/administration/form/steps/step-three/step-three.component.ts index 516af21a..aa5c04e5 100644 --- a/src/app/features/administration/form/steps/step-three/step-three.component.ts +++ b/src/app/features/administration/form/steps/step-three/step-three.component.ts @@ -12,7 +12,6 @@ export class StepThreeComponent implements OnInit { step_max: any; @Input() form: any; - public mode_calendar = false; constructor(public pollService: PollService) { this.pollService.step_current = 3; @@ -25,8 +24,10 @@ export class StepThreeComponent implements OnInit { } changeDateInputMode() { - this.mode_calendar ? this.pollService.convertCalendarToText() : this.pollService.convertTextToCalendar(); + this.pollService.mode_calendar + ? this.pollService.convertCalendarToText() + : this.pollService.convertTextToCalendar(); - this.mode_calendar = !this.mode_calendar; + this.pollService.mode_calendar = !this.pollService.mode_calendar; } }