diff --git a/.gitignore b/.gitignore index 5ddfb87d..6d8bc87b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,9 @@ .idea/ */__pycache__ + +front/app-back/ +front/app-back2/ +front/app-back3/ +front/app-back4/ +front/paper-dashboard-angular-2.4.0/ +front/app/note_modules diff --git a/back/app/core/routes.py b/back/app/core/routes.py index 853b103e..38345838 100644 --- a/back/app/core/routes.py +++ b/back/app/core/routes.py @@ -38,7 +38,7 @@ def get_crud_router(model, model_create, model_read, model_update): async def create(item: model_create) -> dict: await item.validate_foreign_key() o = await model(**item.dict()).create() - return {"message": "{} added successfully".format(model.__name__), "id": o} + return {"message": "{} added successfully".format(model.__name__), "id": o.id} @router.get("/{id}", response_description="{} record retrieved".format(model.__name__)) async def read_id(id: PydanticObjectId) -> model_read: diff --git a/front/app/src/common/crud/card/card.component.ts b/front/app/src/common/crud/card/card.component.ts index c81f80fd..40bd5c50 100644 --- a/front/app/src/common/crud/card/card.component.ts +++ b/front/app/src/common/crud/card/card.component.ts @@ -2,9 +2,9 @@ import {Component, Input, OnInit} from '@angular/core'; import { FormGroup } from '@angular/forms'; import { FormlyFieldConfig } from '@ngx-formly/core' import { FormlyJsonschema } from '@ngx-formly/core/json-schema'; +import { Router } from '@angular/router'; import { CrudService } from '../crud.service' -import {ParamMap} from "@angular/router"; import {BehaviorSubject} from "rxjs"; export interface Model { @@ -32,11 +32,9 @@ export class CardComponent implements OnInit { } constructor(private crudService: CrudService, - private formlyJsonschema: FormlyJsonschema - ) { - - - } + private formlyJsonschema: FormlyJsonschema, + private router: Router + ) { } ngOnInit(): void { this._loading$.next(true); @@ -54,7 +52,7 @@ export class CardComponent implements OnInit { if (this.resource_id !== null) { this.crudService.get(this.resource_id!).subscribe((model: any) => { this.model = model - }) + }); this._loading$.next(false); } @@ -62,10 +60,17 @@ export class CardComponent implements OnInit { onSubmit(model: any) { this._loading$.next(true); - this.crudService.update(model).subscribe((model: any) => { - this.model = model - this._loading$.next(false); - }) + if (this.resource_id !== null) { + this.crudService.update(model).subscribe((model: any) => { + this.model = model; + this._loading$.next(false); + }); + } else { + this.crudService.create(model).subscribe((response: any) => { + this._loading$.next(false); + this.router.navigateByUrl('/entities/' + response.id); + }); + } console.log(model); } } diff --git a/front/app/src/common/crud/crud.service.ts b/front/app/src/common/crud/crud.service.ts index 893482c4..3fd5f60e 100644 --- a/front/app/src/common/crud/crud.service.ts +++ b/front/app/src/common/crud/crud.service.ts @@ -35,4 +35,11 @@ export class CrudService { model ); } + + public create(model: any) { + return this.http.post<{ menu: [{}] }>( + `/api/v1/entity/`, + model + ); + } }