|
|
@ -5,142 +5,132 @@ |
|
|
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved. |
|
|
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved. |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
import { Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core'; |
|
|
|
|
|
import { FormBuilder } from '@angular/forms'; |
|
|
|
|
|
import { onErrorResumeNext } from 'rxjs/operators'; |
|
|
|
|
|
|
|
|
import { |
|
|
import { |
|
|
Component, |
|
|
AddFieldForm, |
|
|
ElementRef, |
|
|
AppPatternDto, |
|
|
EventEmitter, |
|
|
createProperties, |
|
|
Input, |
|
|
EditFieldForm, |
|
|
OnInit, |
|
|
FieldDto, |
|
|
Output, |
|
|
fieldTypes, |
|
|
ViewChild |
|
|
ImmutableArray, |
|
|
} from "@angular/core"; |
|
|
PatternsState, |
|
|
import { FormBuilder } from "@angular/forms"; |
|
|
RootFieldDto, |
|
|
import { |
|
|
SchemaDetailsDto, |
|
|
AddFieldForm, |
|
|
SchemasState, |
|
|
AppPatternDto, |
|
|
Types, |
|
|
createProperties, |
|
|
UpdateFieldDto |
|
|
EditFieldForm, |
|
|
} from '@app/shared'; |
|
|
FieldDto, |
|
|
|
|
|
fieldTypes, |
|
|
|
|
|
ImmutableArray, |
|
|
|
|
|
PatternsState, |
|
|
|
|
|
RootFieldDto, |
|
|
|
|
|
SchemaDetailsDto, |
|
|
|
|
|
SchemasState, |
|
|
|
|
|
Types, |
|
|
|
|
|
UpdateFieldDto |
|
|
|
|
|
} from "@app/shared"; |
|
|
|
|
|
import { onErrorResumeNext } from "rxjs/operators"; |
|
|
|
|
|
|
|
|
|
|
|
@Component({ |
|
|
@Component({ |
|
|
selector: "sqx-field-wizard", |
|
|
selector: 'sqx-field-wizard', |
|
|
styleUrls: ["./field-wizard.component.scss"], |
|
|
styleUrls: ['./field-wizard.component.scss'], |
|
|
templateUrl: "./field-wizard.component.html" |
|
|
templateUrl: './field-wizard.component.html' |
|
|
}) |
|
|
}) |
|
|
export class FieldWizardComponent implements OnInit { |
|
|
export class FieldWizardComponent implements OnInit { |
|
|
@ViewChild("nameInput") |
|
|
@ViewChild('nameInput') |
|
|
public nameInput: ElementRef; |
|
|
public nameInput: ElementRef; |
|
|
|
|
|
|
|
|
@Input() |
|
|
@Input() |
|
|
public schema: SchemaDetailsDto; |
|
|
public schema: SchemaDetailsDto; |
|
|
|
|
|
|
|
|
@Input() |
|
|
@Input() |
|
|
public parent: RootFieldDto; |
|
|
public parent: RootFieldDto; |
|
|
|
|
|
|
|
|
@Output() |
|
|
@Output() |
|
|
public completed = new EventEmitter(); |
|
|
public completed = new EventEmitter(); |
|
|
|
|
|
|
|
|
public fieldTypes = fieldTypes; |
|
|
public fieldTypes = fieldTypes; |
|
|
|
|
|
|
|
|
public addFieldForm = new AddFieldForm(this.formBuilder); |
|
|
public addFieldForm = new AddFieldForm(this.formBuilder); |
|
|
public editForm = new EditFieldForm(this.formBuilder); |
|
|
public editForm = new EditFieldForm(this.formBuilder); |
|
|
public field: FieldDto; |
|
|
public field: FieldDto; |
|
|
public isEditing = false; |
|
|
public isEditing = false; |
|
|
public selectedTab = 0; |
|
|
public selectedTab = 0; |
|
|
public patterns: ImmutableArray<AppPatternDto>; |
|
|
public patterns: ImmutableArray<AppPatternDto>; |
|
|
|
|
|
|
|
|
public step = 1; |
|
|
constructor( |
|
|
|
|
|
private readonly formBuilder: FormBuilder, |
|
|
|
|
|
private readonly schemasState: SchemasState, |
|
|
|
|
|
public readonly patternsState: PatternsState |
|
|
|
|
|
) {} |
|
|
|
|
|
|
|
|
constructor( |
|
|
public ngOnInit() { |
|
|
private readonly formBuilder: FormBuilder, |
|
|
if (this.parent) { |
|
|
private readonly schemasState: SchemasState, |
|
|
this.fieldTypes = this.fieldTypes.filter(x => x.type !== 'Array'); |
|
|
public readonly patternsState: PatternsState |
|
|
} |
|
|
) {} |
|
|
this.patternsState |
|
|
|
|
|
.load() |
|
|
|
|
|
.pipe(onErrorResumeNext()) |
|
|
|
|
|
.subscribe(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public ngOnInit() { |
|
|
public complete() { |
|
|
if (this.parent) { |
|
|
this.completed.emit(); |
|
|
this.fieldTypes = this.fieldTypes.filter(x => x.type !== "Array"); |
|
|
|
|
|
} |
|
|
} |
|
|
this.patternsState |
|
|
|
|
|
.load() |
|
|
public addField(next: boolean, edit: boolean) { |
|
|
.pipe(onErrorResumeNext()) |
|
|
const value = this.addFieldForm.submit(); |
|
|
.subscribe(); |
|
|
|
|
|
} |
|
|
if (value) { |
|
|
|
|
|
this.schemasState.addField(this.schema, value, this.parent).subscribe( |
|
|
public complete() { |
|
|
dto => { |
|
|
this.completed.emit(); |
|
|
this.field = dto; |
|
|
} |
|
|
this.addFieldForm.submitCompleted({ type: fieldTypes[0].type }); |
|
|
|
|
|
|
|
|
public addField(next: boolean, edit: boolean) { |
|
|
if (next) { |
|
|
const value = this.addFieldForm.submit(); |
|
|
if (Types.isFunction(this.nameInput.nativeElement.focus)) { |
|
|
|
|
|
this.nameInput.nativeElement.focus(); |
|
|
if (value) { |
|
|
} |
|
|
this.schemasState.addField(this.schema, value, this.parent).subscribe( |
|
|
} else if (edit) { |
|
|
dto => { |
|
|
this.selectTab(0); |
|
|
this.field = dto; |
|
|
this.isEditing = true; |
|
|
this.addFieldForm.submitCompleted({ type: fieldTypes[0].type }); |
|
|
} else { |
|
|
|
|
|
this.complete(); |
|
|
if (next) { |
|
|
} |
|
|
if (Types.isFunction(this.nameInput.nativeElement.focus)) { |
|
|
}, |
|
|
this.nameInput.nativeElement.focus(); |
|
|
error => { |
|
|
} |
|
|
this.addFieldForm.submitFailed(error); |
|
|
} else if (edit) { |
|
|
} |
|
|
this.selectTab(0); |
|
|
); |
|
|
this.step++; |
|
|
|
|
|
} else { |
|
|
|
|
|
this.complete(); |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
error => { |
|
|
|
|
|
this.addFieldForm.submitFailed(error); |
|
|
|
|
|
} |
|
|
} |
|
|
); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public selectTab(tab: number) { |
|
|
public selectTab(tab: number) { |
|
|
this.selectedTab = tab; |
|
|
this.selectedTab = tab; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public save(addNew: boolean) { |
|
|
public save(addNew: boolean) { |
|
|
const value = this.editForm.submit(); |
|
|
const value = this.editForm.submit(); |
|
|
|
|
|
|
|
|
if (value) { |
|
|
if (value) { |
|
|
const properties = createProperties( |
|
|
const properties = createProperties( |
|
|
this.field.properties['fieldType'], |
|
|
this.field.properties["fieldType"], |
|
|
value |
|
|
value |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
this.schemasState |
|
|
this.schemasState |
|
|
.updateField( |
|
|
.updateField( |
|
|
this.schema, |
|
|
this.schema, |
|
|
this.field as RootFieldDto, |
|
|
this.field as RootFieldDto, |
|
|
new UpdateFieldDto(properties) |
|
|
new UpdateFieldDto(properties) |
|
|
) |
|
|
) |
|
|
.subscribe( |
|
|
.subscribe( |
|
|
() => { |
|
|
() => { |
|
|
this.editForm.submitCompleted(); |
|
|
this.isEditing = false; |
|
|
if (addNew) { |
|
|
this.editForm.submitCompleted(); |
|
|
this.isEditing = false; |
|
|
if (addNew) { |
|
|
} else { |
|
|
this.step--; |
|
|
this.complete(); |
|
|
} else { |
|
|
} |
|
|
this.complete(); |
|
|
}, |
|
|
} |
|
|
error => { |
|
|
}, |
|
|
this.editForm.submitFailed(error); |
|
|
error => { |
|
|
} |
|
|
this.editForm.submitFailed(error); |
|
|
); |
|
|
} |
|
|
} |
|
|
); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|