mirror of
https://framagit.org/framasoft/framadate/funky-framadate-front.git
synced 2023-08-25 13:53:14 +02:00
convert to date string for inputs
This commit is contained in:
parent
706fd28698
commit
0f4aac7e81
@ -2,7 +2,7 @@ export interface DateChoice {
|
|||||||
literal: string;
|
literal: string;
|
||||||
timeSlices: TimeSlices[];
|
timeSlices: TimeSlices[];
|
||||||
date_object: Date;
|
date_object: Date;
|
||||||
date_input: String;
|
date_input: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TimeSlices {
|
export interface TimeSlices {
|
||||||
|
@ -109,9 +109,9 @@ export class DateUtilitiesService {
|
|||||||
const ladate4 = this.addDaysToDate(3, today);
|
const ladate4 = this.addDaysToDate(3, today);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
this.convertToDateChoiceObject(ladate2),
|
this.convertDateToDateChoiceObject(ladate2),
|
||||||
this.convertToDateChoiceObject(ladate3),
|
this.convertDateToDateChoiceObject(ladate3),
|
||||||
this.convertToDateChoiceObject(ladate4),
|
this.convertDateToDateChoiceObject(ladate4),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,12 +119,16 @@ export class DateUtilitiesService {
|
|||||||
* convert a date to a DateChoice
|
* convert a date to a DateChoice
|
||||||
* @param date
|
* @param date
|
||||||
*/
|
*/
|
||||||
convertToDateChoiceObject(date: Date): DateChoice {
|
convertDateToDateChoiceObject(date: Date): DateChoice {
|
||||||
|
let isUnder10 = date.getDate() < 10;
|
||||||
|
let day = isUnder10 ? `0${date.getDate()}` : date.getDate();
|
||||||
|
// get month is based on 0, so yeah
|
||||||
|
let input = `${date.getFullYear()}-${date.getMonth() + 1}-${day}`;
|
||||||
return {
|
return {
|
||||||
literal: this.formateDateToInputStringNg(date),
|
literal: this.formateDateToInputStringNg(date),
|
||||||
timeSlices: Object.create(defaultTimeOfDay),
|
timeSlices: Object.create(defaultTimeOfDay),
|
||||||
date_object: date,
|
date_object: date,
|
||||||
date_input: `${date.getFullYear()}-${date.getMonth()}-${date.getDay()}`,
|
date_input: input,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -667,7 +667,7 @@ export class PollService implements Resolve<Poll> {
|
|||||||
convertCalendarToText() {
|
convertCalendarToText() {
|
||||||
let converted = [];
|
let converted = [];
|
||||||
for (let someDate of this.calendar) {
|
for (let someDate of this.calendar) {
|
||||||
converted.push(this.DateUtilitiesService.convertToDateChoiceObject(someDate));
|
converted.push(this.DateUtilitiesService.convertDateToDateChoiceObject(someDate));
|
||||||
}
|
}
|
||||||
this.dateChoiceList = converted;
|
this.dateChoiceList = converted;
|
||||||
|
|
||||||
@ -678,11 +678,18 @@ 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() {
|
||||||
|
console.log('convert text to calendar', this.dateChoiceList);
|
||||||
let converted = [];
|
let converted = [];
|
||||||
for (let someDateChoice of this.dateChoiceList) {
|
for (let someDateChoice of this.dateChoiceList) {
|
||||||
converted.push(someDateChoice.date_object);
|
let dateObj = new Date(someDateChoice.date_input);
|
||||||
|
console.log('dateObj', dateObj);
|
||||||
|
// check that date is not part of the disabled dates
|
||||||
|
if (this.disabled_dates.indexOf(dateObj) === -1) {
|
||||||
|
converted.push(dateObj);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('converted', converted);
|
||||||
this.calendar = converted;
|
this.calendar = converted;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -741,7 +748,7 @@ export class PollService implements Resolve<Poll> {
|
|||||||
|
|
||||||
for (let elem of this.calendar) {
|
for (let elem of this.calendar) {
|
||||||
console.log('elem', elem);
|
console.log('elem', elem);
|
||||||
let converted_day = this.DateUtilitiesService.convertToDateChoiceObject(elem);
|
let converted_day = this.DateUtilitiesService.convertDateToDateChoiceObject(elem);
|
||||||
newpoll.dateChoices.push(converted_day);
|
newpoll.dateChoices.push(converted_day);
|
||||||
}
|
}
|
||||||
console.log('newpoll.dateChoices', newpoll.dateChoices);
|
console.log('newpoll.dateChoices', newpoll.dateChoices);
|
||||||
|
@ -98,11 +98,7 @@
|
|||||||
<app-shortcuts-help *ngIf="display"></app-shortcuts-help>
|
<app-shortcuts-help *ngIf="display"></app-shortcuts-help>
|
||||||
<br />
|
<br />
|
||||||
<br />
|
<br />
|
||||||
<app-day-list
|
<app-day-list [form]="form" [hasSeveralHours]="form.value.hasSeveralHours"></app-day-list>
|
||||||
[form]="form"
|
|
||||||
[dateChoices]="dateChoices"
|
|
||||||
[hasSeveralHours]="form.value.hasSeveralHours"
|
|
||||||
></app-day-list>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -27,18 +27,11 @@
|
|||||||
{{ choice.date_object | date: 'E':'Europe/Paris':'fr_FR' }}
|
{{ choice.date_object | date: 'E':'Europe/Paris':'fr_FR' }}
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
{{ choice.date_input | date }}
|
|
||||||
<pre>
|
|
||||||
|
|
||||||
{{ choice.date_object | json }}
|
|
||||||
</pre
|
|
||||||
>
|
|
||||||
<input
|
<input
|
||||||
[(ngModel)]="choice.date_input"
|
[(ngModel)]="choice.date_input"
|
||||||
class="date-choice-item"
|
class="date-choice-item"
|
||||||
name="dateChoices_{{ id }}"
|
name="dateChoices_{{ id }}"
|
||||||
id="dateChoices_{{ id }}"
|
id="dateChoices_{{ id }}"
|
||||||
useValueAsDate
|
|
||||||
type="date"
|
type="date"
|
||||||
/>
|
/>
|
||||||
<button (click)="dateChoices.splice(id, 1)" class="btn btn-warning">
|
<button (click)="dateChoices.splice(id, 1)" class="btn btn-warning">
|
||||||
|
@ -18,8 +18,7 @@ import { DateUtilitiesService } from '../../../../../../core/services/date.utili
|
|||||||
export class DayListComponent {
|
export class DayListComponent {
|
||||||
@Input()
|
@Input()
|
||||||
form: FormGroup;
|
form: FormGroup;
|
||||||
@Input()
|
public dateChoices: DateChoice[] = [];
|
||||||
public dateChoices: Array<DateChoice> = [];
|
|
||||||
@Input()
|
@Input()
|
||||||
public hasSeveralHours: boolean;
|
public hasSeveralHours: boolean;
|
||||||
timeList: any;
|
timeList: any;
|
||||||
@ -34,7 +33,7 @@ export class DayListComponent {
|
|||||||
@Inject(DOCUMENT) private document: any,
|
@Inject(DOCUMENT) private document: any,
|
||||||
private storageService: StorageService
|
private storageService: StorageService
|
||||||
) {
|
) {
|
||||||
// this.setDemoTextChoices();
|
this.dateChoices = this.pollService.dateChoiceList;
|
||||||
}
|
}
|
||||||
|
|
||||||
reinitChoices(): void {
|
reinitChoices(): void {
|
||||||
@ -130,11 +129,7 @@ export class DayListComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
addChoice(optionalLabel = ''): void {
|
addChoice(optionalLabel = ''): void {
|
||||||
this.pollService.dateChoiceList.push({
|
this.pollService.dateChoiceList.push(this.dateUtilitiesService.convertDateToDateChoiceObject(new Date()));
|
||||||
literal: '',
|
|
||||||
timeSlices: [],
|
|
||||||
date_object: new Date(),
|
|
||||||
});
|
|
||||||
|
|
||||||
this.focusOnChoice(this.storageService.dateChoices.length - 1);
|
this.focusOnChoice(this.storageService.dateChoices.length - 1);
|
||||||
}
|
}
|
||||||
@ -153,10 +148,6 @@ export class DayListComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
openKeyboardShortcutsModal() {
|
|
||||||
this.display = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
isWeekendDay(date_object: Date) {
|
isWeekendDay(date_object: Date) {
|
||||||
if (date_object) {
|
if (date_object) {
|
||||||
const day = date_object.getDay();
|
const day = date_object.getDay();
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
<div class="text-date-list" *ngIf="!mode_calendar">
|
<div class="text-date-list" *ngIf="!mode_calendar">
|
||||||
<app-day-list
|
<app-day-list
|
||||||
[form]="pollService.form"
|
[form]="pollService.form"
|
||||||
[dateChoices]="pollService.dateChoiceList"
|
|
||||||
[hasSeveralHours]="pollService.form.value.hasSeveralHours"
|
[hasSeveralHours]="pollService.form.value.hasSeveralHours"
|
||||||
></app-day-list>
|
></app-day-list>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user