mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
1.7 KiB
67 lines
1.7 KiB
/*
|
|
* Squidex Headless CMS
|
|
*
|
|
* @license
|
|
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
|
|
*/
|
|
|
|
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
|
|
import { FormBuilder } from '@angular/forms';
|
|
import { ApiUrlConfig, AppsState, CreateSchemaForm, SchemaDto, SchemasState } from '@app/shared';
|
|
|
|
@Component({
|
|
selector: 'sqx-schema-form',
|
|
styleUrls: ['./schema-form.component.scss'],
|
|
templateUrl: './schema-form.component.html'
|
|
})
|
|
export class SchemaFormComponent implements OnInit {
|
|
@Output()
|
|
public complete = new EventEmitter<SchemaDto>();
|
|
|
|
@Output()
|
|
public cancel = new EventEmitter();
|
|
|
|
@Input()
|
|
public import: any;
|
|
|
|
public createForm = new CreateSchemaForm(this.formBuilder);
|
|
|
|
public showImport = false;
|
|
|
|
constructor(
|
|
public readonly apiUrl: ApiUrlConfig,
|
|
public readonly appsState: AppsState,
|
|
private readonly formBuilder: FormBuilder,
|
|
private readonly schemasState: SchemasState
|
|
) {
|
|
}
|
|
|
|
public ngOnInit() {
|
|
this.createForm.load({ ...this.import, name: '' });
|
|
|
|
this.showImport = !!this.import;
|
|
}
|
|
|
|
public toggleImport() {
|
|
this.showImport = !this.showImport;
|
|
|
|
return false;
|
|
}
|
|
|
|
public emitComplete(value: SchemaDto) {
|
|
this.complete.emit(value);
|
|
}
|
|
|
|
public createSchema() {
|
|
const value = this.createForm.submit();
|
|
|
|
if (value) {
|
|
this.schemasState.create(value)
|
|
.subscribe(dto => {
|
|
this.emitComplete(dto);
|
|
}, error => {
|
|
this.createForm.submitFailed(error);
|
|
});
|
|
}
|
|
}
|
|
}
|