Repairing Date & Datetime components
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
from enum import Enum
|
from enum import Enum
|
||||||
from datetime import datetime, date
|
from datetime import datetime, date
|
||||||
from typing import List, Literal
|
from typing import List, Literal, Optional
|
||||||
|
|
||||||
from pymongo import TEXT, IndexModel
|
from pymongo import TEXT, IndexModel
|
||||||
from pydantic import Field, BaseModel, validator
|
from pydantic import Field, BaseModel, validator
|
||||||
@@ -64,8 +64,8 @@ class Institution(BaseModel):
|
|||||||
|
|
||||||
class Entity(Document):
|
class Entity(Document):
|
||||||
_id: str
|
_id: str
|
||||||
address: Indexed(str, index_type=TEXT)
|
|
||||||
entity_data: Individual | Corporation | Institution = Field(..., discriminator='type')
|
entity_data: Individual | Corporation | Institution = Field(..., discriminator='type')
|
||||||
|
address: Optional[str] = ""
|
||||||
label: str = None
|
label: str = None
|
||||||
|
|
||||||
@validator("label", always=True)
|
@validator("label", always=True)
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
import uuid
|
from typing import Optional
|
||||||
|
|
||||||
from datetime import datetime
|
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field
|
||||||
|
|
||||||
from .models import Entity, EntityType, Individual, Corporation
|
from .models import Entity, EntityType, Individual, Corporation
|
||||||
@@ -12,10 +10,10 @@ class EntityRead(Entity):
|
|||||||
|
|
||||||
|
|
||||||
class EntityCreate(Writer):
|
class EntityCreate(Writer):
|
||||||
address: str
|
|
||||||
entity_data: Individual | Corporation = Field(..., discriminator='type')
|
entity_data: Individual | Corporation = Field(..., discriminator='type')
|
||||||
|
address: Optional[str] = ""
|
||||||
|
|
||||||
|
|
||||||
class EntityUpdate(BaseModel):
|
class EntityUpdate(BaseModel):
|
||||||
address: str
|
|
||||||
entity_data: Individual | Corporation = Field(..., discriminator='type')
|
entity_data: Individual | Corporation = Field(..., discriminator='type')
|
||||||
|
address: Optional[str] = ""
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ export class CardComponent implements OnInit {
|
|||||||
if (this.isCreateForm()) {
|
if (this.isCreateForm()) {
|
||||||
this.crudService.create(this.resource!, model).subscribe((response: any) => {
|
this.crudService.create(this.resource!, model).subscribe((response: any) => {
|
||||||
this._loading$.next(false);
|
this._loading$.next(false);
|
||||||
this.router.navigateByUrl(response.id);
|
this.router.navigate([`../${response.id}`], {relativeTo: this.route});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
this.crudService.update(this.resource!, model).subscribe((model: any) => {
|
this.crudService.update(this.resource!, model).subscribe((model: any) => {
|
||||||
|
|||||||
@@ -39,16 +39,20 @@ import { FieldType, FieldTypeConfig } from '@ngx-formly/core';
|
|||||||
})
|
})
|
||||||
export class DateTypeComponent extends FieldType<FieldTypeConfig> implements OnInit
|
export class DateTypeComponent extends FieldType<FieldTypeConfig> implements OnInit
|
||||||
{
|
{
|
||||||
public time : NgbTimeStruct = { hour: 12, minute: 0, second: 0 }
|
public date : NgbDateStruct;
|
||||||
public date : NgbDateStruct = { year: 2023, month: 1, day: 9 }
|
public datetime : Date = new Date();
|
||||||
public datetime : Date = new Date()
|
|
||||||
|
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
this.date = this.getDateStruct(new Date());
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
|
if (this.formControl.value === undefined) {
|
||||||
|
this.changeDatetime({});
|
||||||
|
}
|
||||||
|
|
||||||
this.formControl.valueChanges.subscribe(value => {
|
this.formControl.valueChanges.subscribe(value => {
|
||||||
this.datetime = new Date(value)
|
this.datetime = new Date(value)
|
||||||
this.date = this.getDateStruct(this.datetime);
|
this.date = this.getDateStruct(this.datetime);
|
||||||
|
|||||||
@@ -41,16 +41,22 @@ import { FieldType, FieldTypeConfig } from '@ngx-formly/core';
|
|||||||
})
|
})
|
||||||
export class DatetimeTypeComponent extends FieldType<FieldTypeConfig> implements OnInit
|
export class DatetimeTypeComponent extends FieldType<FieldTypeConfig> implements OnInit
|
||||||
{
|
{
|
||||||
public time : NgbTimeStruct = { hour: 12, minute: 0, second: 0 }
|
public time : NgbTimeStruct;
|
||||||
public date : NgbDateStruct = { year: 2023, month: 1, day: 9 }
|
public date : NgbDateStruct;
|
||||||
public datetime : Date = new Date()
|
public datetime : Date = new Date()
|
||||||
|
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
this.time = this.getTimeStruct(new Date());
|
||||||
|
this.date = this.getDateStruct(new Date());
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
|
if (this.formControl.value === undefined) {
|
||||||
|
this.changeDatetime({});
|
||||||
|
}
|
||||||
|
|
||||||
this.formControl.valueChanges.subscribe(value => {
|
this.formControl.valueChanges.subscribe(value => {
|
||||||
this.datetime = new Date(value)
|
this.datetime = new Date(value)
|
||||||
this.date = this.getDateStruct(this.datetime);
|
this.date = this.getDateStruct(this.datetime);
|
||||||
|
|||||||
Reference in New Issue
Block a user