diff --git a/back/app/entity/models.py b/back/app/entity/models.py index 5ee30e35..450129b6 100644 --- a/back/app/entity/models.py +++ b/back/app/entity/models.py @@ -23,10 +23,9 @@ class Individual(EntityType): props={"items-per-row": "4", "numbered": True}, title="Surnoms" ) - day_of_birth: date = Field(title='Date de naissance') + day_of_birth: date = Field(default=None, title='Date de naissance') place_of_birth: str = Field(default="", title='Lieu de naissance') - @property def label(self) -> str: if len(self.surnames) > 0: diff --git a/front/app/src/common/crud/types/date.type.ts b/front/app/src/common/crud/types/date.type.ts index c998b9e9..53b0b363 100644 --- a/front/app/src/common/crud/types/date.type.ts +++ b/front/app/src/common/crud/types/date.type.ts @@ -1,7 +1,6 @@ - -import { Component, ElementRef, OnInit, ViewChild} from '@angular/core'; +import { Component, OnInit } from '@angular/core'; import { formatDate } from "@angular/common"; -import { NgbDateStruct, NgbTimeStruct } from '@ng-bootstrap/ng-bootstrap'; +import { NgbDateStruct } from '@ng-bootstrap/ng-bootstrap'; import { FieldType, FieldTypeConfig } from '@ngx-formly/core'; @@ -15,12 +14,13 @@ import { FieldType, FieldTypeConfig } from '@ngx-formly/core'; +
- + -
- +
`, }) export class DateTypeComponent extends FieldType implements OnInit { - public date : NgbDateStruct; - public datetime : Date = new Date(); + public date : NgbDateStruct | null = null; + public datetime : Date | null = null; constructor() { super(); - this.date = this.getDateStruct(new Date()); } ngOnInit() { @@ -54,8 +52,13 @@ export class DateTypeComponent extends FieldType implements OnI } this.formControl.valueChanges.subscribe(value => { - this.datetime = new Date(value) - this.date = this.getDateStruct(this.datetime); + if (value) { + this.datetime = new Date(value); + this.date = this.getDateStruct(this.datetime); + } else { + this.datetime = null; + this.date = null; + } }) } @@ -68,12 +71,21 @@ export class DateTypeComponent extends FieldType implements OnI } changeDatetime(event: any) { - this.datetime.setFullYear(this.date.year) - this.datetime.setMonth(this.date.month - 1) - this.datetime.setDate(this.date.day) + if (this.date) { + if (!this.datetime) { + this.datetime = new Date(); + } + this.datetime.setFullYear(this.date.year) + this.datetime.setMonth(this.date.month - 1) + this.datetime.setDate(this.date.day) - this.formControl.setValue( - formatDate(this.datetime, 'YYYY-MM-dd', 'EN_US', 'CET') - ) + this.formControl.setValue( + formatDate(this.datetime, 'YYYY-MM-dd', 'EN_US', 'CET') + ) + } else { + this.datetime = null; + this.date = null; + this.formControl.setValue('') + } } } diff --git a/front/app/src/common/crud/types/datetime.type.ts b/front/app/src/common/crud/types/datetime.type.ts index a7997c46..a5b6a1ae 100644 --- a/front/app/src/common/crud/types/datetime.type.ts +++ b/front/app/src/common/crud/types/datetime.type.ts @@ -1,5 +1,4 @@ - -import { Component, ElementRef, OnInit, ViewChild} from '@angular/core'; +import { Component, OnInit } from '@angular/core'; import { formatDate } from "@angular/common"; import { NgbDateStruct, NgbTimeStruct } from '@ng-bootstrap/ng-bootstrap'; import { FieldType, FieldTypeConfig } from '@ngx-formly/core'; @@ -12,12 +11,13 @@ import { FieldType, FieldTypeConfig } from '@ngx-formly/core'; class="form-label">{{ props.label }} +
- + -
- +
`, }) export class DatetimeTypeComponent extends FieldType implements OnInit { - public time : NgbTimeStruct; - public date : NgbDateStruct; - public datetime : Date = new Date() + public time : NgbTimeStruct | null = null; + public date : NgbDateStruct | null = null; + public datetime : Date | null = null; constructor() { @@ -58,9 +57,15 @@ export class DatetimeTypeComponent extends FieldType implements } this.formControl.valueChanges.subscribe(value => { - this.datetime = new Date(value) - this.date = this.getDateStruct(this.datetime); - this.time = this.getTimeStruct(this.datetime); + if (value) { + this.datetime = new Date(value); + this.date = this.getDateStruct(this.datetime); + this.time = this.getTimeStruct(this.datetime); + } else { + this.datetime = null; + this.date = null; + this.time = null; + } }) } @@ -81,15 +86,25 @@ export class DatetimeTypeComponent extends FieldType implements } changeDatetime(event: any) { - this.datetime.setFullYear(this.date.year) - this.datetime.setMonth(this.date.month - 1) - this.datetime.setDate(this.date.day) - this.datetime.setHours(this.time.hour) - this.datetime.setMinutes(this.time.minute) - this.datetime.setSeconds(this.time.second) + if (this.date && this.time) { + if (!this.datetime) { + this.datetime = new Date(); + } + this.datetime.setFullYear(this.date.year) + this.datetime.setMonth(this.date.month - 1) + this.datetime.setDate(this.date.day) + this.datetime.setHours(this.time.hour) + this.datetime.setMinutes(this.time.minute) + this.datetime.setSeconds(this.time.second) - this.formControl.setValue( - formatDate(this.datetime, 'YYYY-MM-ddTHH:mm:ss.SSS', 'EN_US', 'CET') - ) + this.formControl.setValue( + formatDate(this.datetime, 'YYYY-MM-ddTHH:mm:ss.SSS', 'EN_US', 'CET') + ) + } else { + this.datetime = null; + this.date = null; + this.time = null; + this.formControl.setValue('') + } } }