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.
74 lines
1.7 KiB
74 lines
1.7 KiB
/*
|
|
* Squidex Headless CMS
|
|
*
|
|
* @license
|
|
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
|
|
*/
|
|
|
|
import { ChangeDetectionStrategy, Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
|
|
import { FormBuilder } from '@angular/forms';
|
|
|
|
import {
|
|
AnnotateAssetForm,
|
|
AssetDto,
|
|
AssetsState
|
|
} from '@app/shared/internal';
|
|
|
|
@Component({
|
|
selector: 'sqx-asset-dialog',
|
|
styleUrls: ['./asset-dialog.component.scss'],
|
|
templateUrl: './asset-dialog.component.html',
|
|
changeDetection: ChangeDetectionStrategy.OnPush
|
|
})
|
|
export class AssetDialogComponent implements OnInit {
|
|
@Output()
|
|
public complete = new EventEmitter();
|
|
|
|
@Input()
|
|
public asset: AssetDto;
|
|
|
|
@Input()
|
|
public allTags: ReadonlyArray<string>;
|
|
|
|
public isEditable = false;
|
|
|
|
public annotateForm = new AnnotateAssetForm(this.formBuilder);
|
|
|
|
constructor(
|
|
private readonly assetsState: AssetsState,
|
|
private readonly formBuilder: FormBuilder
|
|
) {
|
|
}
|
|
|
|
public ngOnInit() {
|
|
this.isEditable = this.asset.canUpdate;
|
|
|
|
this.annotateForm.load(this.asset);
|
|
this.annotateForm.setEnabled(this.isEditable);
|
|
}
|
|
|
|
public generateSlug() {
|
|
this.annotateForm.generateSlug(this.asset);
|
|
}
|
|
|
|
public emitComplete() {
|
|
this.complete.emit();
|
|
}
|
|
|
|
public annotateAsset() {
|
|
if (!this.isEditable) {
|
|
return;
|
|
}
|
|
|
|
const value = this.annotateForm.submit(this.asset);
|
|
|
|
if (value) {
|
|
this.assetsState.updateAsset(this.asset, value)
|
|
.subscribe(() => {
|
|
this.emitComplete();
|
|
}, error => {
|
|
this.annotateForm.submitFailed(error);
|
|
});
|
|
}
|
|
}
|
|
}
|