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.9 KiB
67 lines
1.9 KiB
/*
|
|
* Squidex Headless CMS
|
|
*
|
|
* @license
|
|
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
|
|
*/
|
|
|
|
import { Component, Input, OnChanges } from '@angular/core';
|
|
import { AppsState, EditSchemaScriptsForm, SchemaCompletions, SchemaDto, SchemasService, SchemasState } from '@app/shared';
|
|
import { EMPTY, Observable } from 'rxjs';
|
|
|
|
@Component({
|
|
selector: 'sqx-schema-scripts-form',
|
|
styleUrls: ['./schema-scripts-form.component.scss'],
|
|
templateUrl: './schema-scripts-form.component.html',
|
|
})
|
|
export class SchemaScriptsFormComponent implements OnChanges {
|
|
@Input()
|
|
public schema: SchemaDto;
|
|
|
|
public schemaScript = 'query';
|
|
public schemaCompletions: Observable<SchemaCompletions> = EMPTY;
|
|
|
|
public editForm = new EditSchemaScriptsForm();
|
|
|
|
public isEditable = false;
|
|
|
|
constructor(
|
|
private readonly appsState: AppsState,
|
|
private readonly schemasState: SchemasState,
|
|
private readonly schemasService: SchemasService,
|
|
) {
|
|
}
|
|
|
|
public ngOnChanges() {
|
|
this.isEditable = this.schema.canUpdateScripts;
|
|
|
|
this.editForm.load(this.schema.scripts);
|
|
this.editForm.setEnabled(this.isEditable);
|
|
|
|
this.schemaCompletions = this.schemasService.getCompletions(this.appsState.appName, this.schema.name);
|
|
}
|
|
|
|
public selectField(field: string) {
|
|
this.schemaScript = field;
|
|
}
|
|
|
|
public saveSchema() {
|
|
if (!this.isEditable) {
|
|
return;
|
|
}
|
|
|
|
const value = this.editForm.submit();
|
|
|
|
if (value) {
|
|
this.schemasState.configureScripts(this.schema, value)
|
|
.subscribe({
|
|
next: () => {
|
|
this.editForm.submitCompleted({ noReset: true });
|
|
},
|
|
error: error => {
|
|
this.editForm.submitFailed(error);
|
|
},
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|