-
diff --git a/front/app/src/common/crud/crud.module.ts b/front/app/src/common/crud/crud.module.ts
index 91b61043..bfa5d5fa 100644
--- a/front/app/src/common/crud/crud.module.ts
+++ b/front/app/src/common/crud/crud.module.ts
@@ -1,8 +1,6 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
-//import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
-
import { HttpClientModule } from "@angular/common/http";
import { FormsModule, ReactiveFormsModule} from '@angular/forms';
@@ -11,17 +9,23 @@ import { FormlyBootstrapModule } from '@ngx-formly/bootstrap';
import { CardComponent } from './card/card.component';
import { ListComponent } from './list/list.component';
-import { ObjectTypeComponent } from "./object.type";
-import {ApiService, CrudService} from "./crud.service";
-import {NgbModule} from "@ng-bootstrap/ng-bootstrap";
-import {JsonschemasService} from "./jsonschemas.service";
+import { ArrayTypeComponent } from "./types/array.type";
+import { ObjectTypeComponent } from "./types/object.type";
+import { DatetimeTypeComponent } from "./types/datetime.type";
+import { ApiService, CrudService } from "./crud.service";
+import { NgbModule} from "@ng-bootstrap/ng-bootstrap";
+import { JsonschemasService } from "./jsonschemas.service";
+import { MultiSchemaTypeComponent } from "./types/multischema.type";
@NgModule({
declarations: [
CardComponent,
ListComponent,
- ObjectTypeComponent
+ ObjectTypeComponent,
+ DatetimeTypeComponent,
+ ArrayTypeComponent,
+ MultiSchemaTypeComponent
],
providers: [ JsonschemasService, ApiService, CrudService ],
imports: [
@@ -34,6 +38,9 @@ import {JsonschemasService} from "./jsonschemas.service";
FormlyModule.forRoot({
types: [
{ name: 'object', component: ObjectTypeComponent },
+ { name: 'datetime', component: DatetimeTypeComponent },
+ { name: 'array', component: ArrayTypeComponent },
+ { name: 'multischema', component: MultiSchemaTypeComponent },
]
}),
FormlyBootstrapModule
diff --git a/front/app/src/common/crud/jsonschemas.service.ts b/front/app/src/common/crud/jsonschemas.service.ts
index e9ae9c3c..e35d6021 100644
--- a/front/app/src/common/crud/jsonschemas.service.ts
+++ b/front/app/src/common/crud/jsonschemas.service.ts
@@ -32,15 +32,35 @@ export class JsonschemasService {
for (let prop_name in resource.properties) {
let prop = resource.properties[prop_name];
- if (this.is_reference(prop)) {
- let subresourceName = this.get_reference_name(prop);
- resource.components.schemas[subresourceName] = this.buildResource(subresourceName);
+ if (prop_name === '_id') {
+ delete resource.properties[prop_name]
+ } else if (this.is_reference(prop)) {
+ this.resolveReference(resource, prop);
+ } else if (prop.hasOwnProperty('oneOf')) {
+ for (let i in prop.oneOf) {
+ this.resolveReference(resource, prop.oneOf[i]);
+ }
+ } else if (prop.hasOwnProperty('items') && this.is_reference(prop.items)) {
+ this.resolveReference(resource, prop.items);
+ } else if (prop.format === 'date-time') {
+ prop.type = "datetime";
}
}
return resource;
}
+ resolveReference(resource: any, prop_reference: any) {
+ let subresourceName = this.get_reference_name(prop_reference);
+ let subresource = this.buildResource(subresourceName);
+ resource.components.schemas[subresourceName] = subresource;
+ for (let subsubresourceName in subresource.components.schemas) {
+ if (! resource.components.schemas.hasOwnProperty(subsubresourceName)) {
+ resource.components.schemas[subsubresourceName] = subresource.components.schemas[subsubresourceName];
+ }
+ }
+ }
+
getCreateResource(resourceName: string): Observable {
return new Observable((observer) => {
this.getSchemas().subscribe(() => {
@@ -75,6 +95,10 @@ export class JsonschemasService {
return prop.hasOwnProperty('$ref');
}
+ private is_union(prop: any) {
+ return prop.hasOwnProperty('oneOf');
+ }
+
private get_reference_name(prop: any) {
return prop['$ref'].substring(prop['$ref'].lastIndexOf('/')+1);
}
diff --git a/front/app/src/common/crud/types/array.type.ts b/front/app/src/common/crud/types/array.type.ts
new file mode 100644
index 00000000..5b10ac60
--- /dev/null
+++ b/front/app/src/common/crud/types/array.type.ts
@@ -0,0 +1,36 @@
+import { Component } from '@angular/core';
+import { FieldArrayType } from '@ngx-formly/core';
+
+@Component({
+ selector: 'formly-array-type',
+ template: `
+
+
+
{{ props.description }}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ `,
+})
+export class ArrayTypeComponent extends FieldArrayType {
+ constructor() {
+ super();
+ }
+}
+
+
+/** Copyright 2021 Formly. All Rights Reserved.
+ Use of this source code is governed by an MIT-style license that
+ can be found in the LICENSE file at https://github.com/ngx-formly/ngx-formly/blob/main/LICENSE */
\ No newline at end of file
diff --git a/front/app/src/common/crud/types/datetime.type.ts b/front/app/src/common/crud/types/datetime.type.ts
new file mode 100644
index 00000000..b7900879
--- /dev/null
+++ b/front/app/src/common/crud/types/datetime.type.ts
@@ -0,0 +1,89 @@
+
+import { Component, ElementRef, OnInit, ViewChild} from '@angular/core';
+import { formatDate } from "@angular/common";
+import { NgbDateStruct, NgbTimeStruct } from '@ng-bootstrap/ng-bootstrap';
+import { FieldType, FieldTypeConfig } from '@ngx-formly/core';
+
+
+@Component({
+ selector: 'app-form-datepicker-type',
+ template: `
+
+
+ `,
+})
+export class MultiSchemaTypeComponent extends FieldType implements OnInit {
+ ngOnInit() {
+ let f = this.field
+ f.fieldGroup![0].props!.options!.forEach(function (option) {
+ option.label = f.fieldGroup![1].fieldGroup![option.value].props!.label;
+ f.fieldGroup![1].fieldGroup![option.value].props!.label = "";
+ });
+
+ f.fieldGroup![1].fieldGroup!.forEach(function (field) {
+ //field.fieldGroup![0].hide = true;
+ });
+
+ }
+}
+
+
+/** Copyright 2021 Formly. All Rights Reserved.
+ Use of this source code is governed by an MIT-style license that
+ can be found in the LICENSE file at https://github.com/ngx-formly/ngx-formly/blob/main/LICENSE */
diff --git a/front/app/src/common/crud/object.type.ts b/front/app/src/common/crud/types/object.type.ts
similarity index 100%
rename from front/app/src/common/crud/object.type.ts
rename to front/app/src/common/crud/types/object.type.ts