Ethetic modification of lists and foreign keys

This commit is contained in:
2023-02-07 17:08:06 +01:00
parent 0ca57b4e22
commit 09138a3602
4 changed files with 24 additions and 20 deletions

View File

@@ -16,6 +16,7 @@ import { DateTypeComponent } from "./types/date.type";
import { ApiService, CrudService } from "./crud.service"; import { ApiService, CrudService } from "./crud.service";
import { CrudFormlyJsonschemaService } from "./crud-formly-jsonschema.service"; import { CrudFormlyJsonschemaService } from "./crud-formly-jsonschema.service";
import { NgbModule} from "@ng-bootstrap/ng-bootstrap"; import { NgbModule} from "@ng-bootstrap/ng-bootstrap";
import { allIcons, NgxBootstrapIconsModule } from "ngx-bootstrap-icons";
import { JsonschemasService } from "./jsonschemas.service"; import { JsonschemasService } from "./jsonschemas.service";
import { MultiSchemaTypeComponent } from "./types/multischema.type"; import { MultiSchemaTypeComponent } from "./types/multischema.type";
import { ForeignkeyTypeComponent } from "./types/foreignkey.type"; import { ForeignkeyTypeComponent } from "./types/foreignkey.type";
@@ -49,6 +50,7 @@ import { DictionaryService } from "./types/dictionary.service";
HttpClientModule, HttpClientModule,
FormsModule, FormsModule,
NgbModule, NgbModule,
NgxBootstrapIconsModule.pick(allIcons),
//BrowserAnimationsModule, //BrowserAnimationsModule,
ReactiveFormsModule, ReactiveFormsModule,
FormlyModule.forRoot({ FormlyModule.forRoot({

View File

@@ -38,7 +38,7 @@ export class JsonschemasService {
delete resource.properties[prop_name] delete resource.properties[prop_name]
} else if (this.is_reference(prop)) { } else if (this.is_reference(prop)) {
this.resolveReference(resource, prop); this.resolveReference(resource, prop);
} else if (prop.hasOwnProperty('oneOf')) { } else if (this.is_union(prop)) {
for (let i in prop.oneOf) { for (let i in prop.oneOf) {
this.resolveReference(resource, prop.oneOf[i]); this.resolveReference(resource, prop.oneOf[i]);
} }

View File

@@ -7,36 +7,38 @@ import { FieldArrayType } from '@ngx-formly/core';
<div> <div>
<label *ngIf="props.label" class="form-label">{{ props.label }}</label> <label *ngIf="props.label" class="form-label">{{ props.label }}</label>
<p *ngIf="props.description">{{ props.description }}</p> <p *ngIf="props.description">{{ props.description }}</p>
<div class="alert alert-danger" role="alert" *ngIf="showError && formControl.errors"> <div class="alert alert-danger" role="alert" *ngIf="showError && formControl.errors">
<formly-validation-message [field]="field"></formly-validation-message> <formly-validation-message [field]="field"></formly-validation-message>
</div> </div>
<div class="row"> <div class="row row-cols-1 row-cols-md-{{this.itemsPerRow}} g-1">
<div *ngFor="let entry of field.fieldGroup; let i = index" class="card {{this.colSm}}"> <div *ngFor="let entry of field.fieldGroup; let i = index" class="col">
<div class="card-header"> <div class="card">
<div *ngIf="props['numbered']" class="float-start"> <div class="card-header">
<strong>{{ i + 1 }}</strong> <div *ngIf="props['numbered']" class="float-start">
<strong>{{ i + 1 }}</strong>
</div>
<div class="float-end">
<button class="btn btn-primary btn-sm" [attr.disabled]="i == 0 ? 'disabled' : null" type="button" (click)="move(i, i-1)"><i-bs name="caret-up-fill"></i-bs></button>
<button class="btn btn-primary btn-sm" [attr.disabled]="i == this.field.fieldGroup!.length-1 ? 'disabled' : null" type="button" (click)="move(i, i+1)"><i-bs name="caret-down-fill"></i-bs></button>
<button class="btn btn-danger btn-sm" [attr.disabled]="field.props!['removable'] === false ? 'disabled' : null" type="button" (click)="remove(i)"><i-bs name="x-octagon-fill"></i-bs></button>
</div>
</div>
<div class="card-body">
<formly-field class="col" [field]="entry"></formly-field>
</div>
</div> </div>
<div class="float-end">
<button class="btn btn-primary btn-sm" [attr.disabled]="i == 0 ? 'disabled' : null" type="button" (click)="move(i, i-1)">UP</button>
<button class="btn btn-primary btn-sm" [attr.disabled]="i == this.field.fieldGroup!.length-1 ? 'disabled' : null" type="button" (click)="move(i, i+1)">DOWN</button>
<button class="btn btn-danger btn-sm" [attr.disabled]="field.props!['removable'] === false ? 'disabled' : null" type="button" (click)="remove(i)">-</button>
</div>
</div>
<div class="card-body">
<formly-field class="col" [field]="entry"></formly-field>
</div> </div>
</div> </div>
</div> <button class="btn btn-success col-sm-12" type="button" (click)="add()"><i-bs name="plus-square-fill"></i-bs></button>
<button class="btn btn-success col-sm-12" type="button" (click)="add()">+</button>
</div> </div>
`, `,
}) })
export class ArrayTypeComponent extends FieldArrayType implements OnInit { export class ArrayTypeComponent extends FieldArrayType implements OnInit {
colSm: string = "col-sm-6" colSm: string = "col-sm-6"
itemsPerRow = 2;
ngOnInit() { ngOnInit() {
if (this.field.props.hasOwnProperty('items-per-row')) { if (this.field.props.hasOwnProperty('items-per-row')) {
this.colSm = `col-sm-${12 / this.field.props['items-per-row']}` this.itemsPerRow = this.field.props['items-per-row']
} }
} }

View File

@@ -43,10 +43,10 @@ import {DictionaryService} from "./dictionary.service";
readonly="readonly" readonly="readonly"
/> />
<div class="input-group-append"> <div class="input-group-append">
<button class="btn btn-info" type="button" (click)="see(foreignModal)"><span class="cil-zoom btn-icon"></span>See</button> <button class="btn btn-info" type="button" (click)="see(foreignModal)"><span class="cil-zoom btn-icon"></span><i-bs name="zoom-in"></i-bs></button>
</div> </div>
<div class="input-group-append"> <div class="input-group-append">
<button class="btn btn-danger" type="button" (click)="remove()"><span class="cil-x btn-icon mr-2"></span>Remove</button> <button class="btn btn-danger" type="button" (click)="remove()"><span class="cil-x btn-icon mr-2"></span><i-bs name="eraser-fill"></i-bs></button>
</div> </div>
</div> </div>
<formly-form *ngIf="this.hasValue() && this.displayedFields" [form]="this.foreignForm" [fields]="this.foreignFields" [model]="this.foreignModel"></formly-form> <formly-form *ngIf="this.hasValue() && this.displayedFields" [form]="this.foreignForm" [fields]="this.foreignFields" [model]="this.foreignModel"></formly-form>