mirror of
https://framagit.org/framasoft/framadate/funky-framadate-front.git
synced 2023-08-25 13:53:14 +02:00
⚡ convert date list on poll creation
This commit is contained in:
parent
71b9fff475
commit
2e8a1aa12b
@ -47,6 +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 mode_calendar = false;
|
||||||
public calendar: Date[] = [new Date()];
|
public calendar: Date[] = [new Date()];
|
||||||
public disabled_dates: 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
|
* convert the DateChoices to an arrray of Dates for calendar picker
|
||||||
*/
|
*/
|
||||||
convertTextToCalendar() {
|
convertTextToCalendar(): Date[] {
|
||||||
console.log('convert text to calendar', this.dateChoiceList);
|
console.log('convert text to calendar', this.dateChoiceList);
|
||||||
let converted = [];
|
let converted = [];
|
||||||
for (let someDateChoice of this.dateChoiceList) {
|
for (let someDateChoice of this.dateChoiceList) {
|
||||||
@ -693,7 +694,7 @@ export class PollService implements Resolve<Poll> {
|
|||||||
|
|
||||||
console.log('converted', converted);
|
console.log('converted', converted);
|
||||||
this.calendar = converted;
|
this.calendar = converted;
|
||||||
return;
|
return converted;
|
||||||
}
|
}
|
||||||
|
|
||||||
patchFormWithPoll(poll: Poll) {
|
patchFormWithPoll(poll: Poll) {
|
||||||
@ -745,10 +746,21 @@ export class PollService implements Resolve<Poll> {
|
|||||||
newpoll.allow_comments = form.value.allowComments;
|
newpoll.allow_comments = form.value.allowComments;
|
||||||
// merge choices from storage
|
// merge choices from storage
|
||||||
if (form.value.isAboutDate) {
|
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);
|
console.log('this.calendar', this.calendar);
|
||||||
|
|
||||||
for (let elem of this.calendar) {
|
for (let elem of convertedDates) {
|
||||||
console.log('elem', elem);
|
console.log('elem', elem);
|
||||||
let converted_day = this.DateUtilitiesService.convertDateToDateChoiceObject(elem);
|
let converted_day = this.DateUtilitiesService.convertDateToDateChoiceObject(elem);
|
||||||
newpoll.dateChoices.push(converted_day);
|
newpoll.dateChoices.push(converted_day);
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
<app-stepper [step_current]="3" [step_max]="pollService.step_max"></app-stepper>
|
<app-stepper [step_current]="3" [step_max]="pollService.step_max"></app-stepper>
|
||||||
<app-errors-list [form]="pollService.form"></app-errors-list>
|
<app-errors-list [form]="pollService.form"></app-errors-list>
|
||||||
<!-- choix spécialement pour les dates-->
|
<!-- choix spécialement pour les dates-->
|
||||||
<div class="calendar" *ngIf="mode_calendar">
|
<div class="calendar" *ngIf="pollService.mode_calendar">
|
||||||
<p-calendar
|
<p-calendar
|
||||||
[(ngModel)]="pollService.calendar"
|
[(ngModel)]="pollService.calendar"
|
||||||
firstDayOfWeek="1"
|
firstDayOfWeek="1"
|
||||||
@ -16,16 +16,18 @@
|
|||||||
></p-calendar>
|
></p-calendar>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="text-date-list" *ngIf="!mode_calendar">
|
<div class="text-date-list" *ngIf="!pollService.mode_calendar">
|
||||||
<app-day-list
|
<app-day-list
|
||||||
[form]="pollService.form"
|
[form]="pollService.form"
|
||||||
[hasSeveralHours]="pollService.form.value.hasSeveralHours"
|
[hasSeveralHours]="pollService.form.value.hasSeveralHours"
|
||||||
></app-day-list>
|
></app-day-list>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button class="button" (click)="changeDateInputMode()" [ngClass]="{ 'is-primary': !mode_calendar }">
|
<button class="button" (click)="changeDateInputMode()" [ngClass]="{ 'is-primary': !pollService.mode_calendar }">
|
||||||
<span *ngIf="mode_calendar"> <i class="fa fa-pencil"></i> Saisir les dates manuellement </span>
|
<span *ngIf="pollService.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>
|
<span *ngIf="!pollService.mode_calendar">
|
||||||
|
<i class="fa fa-calendar-o"></i> Saisir les dates dans le calendrier
|
||||||
|
</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="columns">
|
<div class="columns">
|
||||||
@ -88,7 +90,7 @@
|
|||||||
type="text"
|
type="text"
|
||||||
id="timeChoices_{{ id }}"
|
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>
|
<i class="fa fa-times" aria-hidden="true"></i>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
@ -12,7 +12,6 @@ export class StepThreeComponent implements OnInit {
|
|||||||
step_max: any;
|
step_max: any;
|
||||||
@Input()
|
@Input()
|
||||||
form: any;
|
form: any;
|
||||||
public mode_calendar = false;
|
|
||||||
|
|
||||||
constructor(public pollService: PollService) {
|
constructor(public pollService: PollService) {
|
||||||
this.pollService.step_current = 3;
|
this.pollService.step_current = 3;
|
||||||
@ -25,8 +24,10 @@ export class StepThreeComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
changeDateInputMode() {
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user