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.
68 lines
1.8 KiB
68 lines
1.8 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 {
|
|
DialogService,
|
|
SchemaDetailsDto,
|
|
SchemasState,
|
|
SynchronizeSchemaForm
|
|
} from '@app/shared';
|
|
|
|
@Component({
|
|
selector: 'sqx-schema-export-form',
|
|
styleUrls: ['./schema-export-form.component.scss'],
|
|
templateUrl: './schema-export-form.component.html'
|
|
})
|
|
export class SchemaExportFormComponent implements OnChanges {
|
|
@Input()
|
|
public schema: SchemaDetailsDto;
|
|
|
|
public synchronizeForm = new SynchronizeSchemaForm(this.formBuilder);
|
|
|
|
public isEditable = false;
|
|
|
|
constructor(
|
|
private readonly dialogs: DialogService,
|
|
private readonly formBuilder: FormBuilder,
|
|
private readonly schemasState: SchemasState
|
|
) {
|
|
}
|
|
|
|
public ngOnChanges() {
|
|
this.isEditable = this.schema.canUpdateScripts;
|
|
|
|
this.synchronizeForm.form.get('json')!.setValue(this.schema.export());
|
|
}
|
|
|
|
public synchronize() {
|
|
if (!this.isEditable) {
|
|
return;
|
|
}
|
|
|
|
const value = this.synchronizeForm.submit();
|
|
|
|
if (value) {
|
|
const request = {
|
|
...value.json,
|
|
noFieldDeletion: !value.fieldsDelete,
|
|
noFieldRecreation: !value.fieldsDelete
|
|
};
|
|
|
|
this.schemasState.synchronize(this.schema, request)
|
|
.subscribe(() => {
|
|
this.dialogs.notifyInfo('Schema synchronized successfully.');
|
|
|
|
this.synchronizeForm.submitCompleted({ noReset: true });
|
|
}, error => {
|
|
this.synchronizeForm.submitFailed(error);
|
|
});
|
|
}
|
|
}
|
|
}
|