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.
80 lines
1.9 KiB
80 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 { FormBuilder } from '@angular/forms';
|
|
|
|
import {
|
|
AddPreviewUrlForm,
|
|
ConfigurePreviewUrlsForm,
|
|
SchemaDetailsDto,
|
|
SchemasState
|
|
} from '@app/shared';
|
|
|
|
@Component({
|
|
selector: 'sqx-schema-preview-urls-form',
|
|
styleUrls: ['./schema-preview-urls-form.component.scss'],
|
|
templateUrl: './schema-preview-urls-form.component.html'
|
|
})
|
|
export class SchemaPreviewUrlsFormComponent implements OnChanges {
|
|
@Input()
|
|
public schema: SchemaDetailsDto;
|
|
|
|
public addForm = new AddPreviewUrlForm(this.formBuilder);
|
|
|
|
public editForm = new ConfigurePreviewUrlsForm(this.formBuilder);
|
|
|
|
public isEditable = false;
|
|
|
|
constructor(
|
|
private readonly formBuilder: FormBuilder,
|
|
private readonly schemasState: SchemasState
|
|
) {
|
|
}
|
|
|
|
public ngOnChanges() {
|
|
this.isEditable = this.schema.canUpdateUrls;
|
|
|
|
this.editForm.load(this.schema);
|
|
this.editForm.setEnabled(this.isEditable);
|
|
}
|
|
|
|
public cancelAdd() {
|
|
this.addForm.submitCompleted();
|
|
}
|
|
|
|
public add() {
|
|
if (!this.isEditable) {
|
|
return;
|
|
}
|
|
|
|
const value = this.addForm.submit();
|
|
|
|
if (value) {
|
|
this.editForm.add(value);
|
|
|
|
this.cancelAdd();
|
|
}
|
|
}
|
|
|
|
public saveSchema() {
|
|
if (!this.isEditable) {
|
|
return;
|
|
}
|
|
|
|
const value = this.editForm.submit();
|
|
|
|
if (value) {
|
|
this.schemasState.configurePreviewUrls(this.schema, value)
|
|
.subscribe(update => {
|
|
this.editForm.submitCompleted({ noReset: true });
|
|
}, error => {
|
|
this.editForm.submitFailed(error);
|
|
});
|
|
}
|
|
}
|
|
}
|