convert date list on poll creation

This commit is contained in:
Tykayn 2021-11-22 10:09:50 +01:00 committed by tykayn
parent 71b9fff475
commit 2e8a1aa12b
3 changed files with 28 additions and 13 deletions

View File

@ -47,6 +47,7 @@ export class PollService implements Resolve<Poll> {
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<Poll> {
/**
* 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<Poll> {
console.log('converted', converted);
this.calendar = converted;
return;
return converted;
}
patchFormWithPoll(poll: Poll) {
@ -745,10 +746,21 @@ export class PollService implements Resolve<Poll> {
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);

View File

@ -2,7 +2,7 @@
<app-stepper [step_current]="3" [step_max]="pollService.step_max"></app-stepper>
<app-errors-list [form]="pollService.form"></app-errors-list>
<!-- choix spécialement pour les dates-->
<div class="calendar" *ngIf="mode_calendar">
<div class="calendar" *ngIf="pollService.mode_calendar">
<p-calendar
[(ngModel)]="pollService.calendar"
firstDayOfWeek="1"
@ -16,16 +16,18 @@
></p-calendar>
</div>
<div class="text-date-list" *ngIf="!mode_calendar">
<div class="text-date-list" *ngIf="!pollService.mode_calendar">
<app-day-list
[form]="pollService.form"
[hasSeveralHours]="pollService.form.value.hasSeveralHours"
></app-day-list>
</div>
<button class="button" (click)="changeDateInputMode()" [ngClass]="{ 'is-primary': !mode_calendar }">
<span *ngIf="mode_calendar"> <i class="fa fa-pencil"></i> Saisir les dates manuellement </span>
<span *ngIf="!mode_calendar"> <i class="fa fa-calendar-o"></i> Saisir les dates dans le calendrier </span>
<button class="button" (click)="changeDateInputMode()" [ngClass]="{ 'is-primary': !pollService.mode_calendar }">
<span *ngIf="pollService.mode_calendar"> <i class="fa fa-pencil"></i> Saisir les dates manuellement </span>
<span *ngIf="!pollService.mode_calendar">
<i class="fa fa-calendar-o"></i> Saisir les dates dans le calendrier
</span>
</button>
</div>
<div class="columns">
@ -88,7 +90,7 @@
type="text"
id="timeChoices_{{ id }}"
/>
<button (click)="time.timeList.splice(id, 1)" class="btn btn-warning">
<button (click)="pollService.timeList.splice(id, 1)" class="btn btn-warning">
<i class="fa fa-times" aria-hidden="true"></i>
</button>
</div>

View File

@ -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;
}
}