|
|
@@ -2,7 +2,13 @@ import { ChangeDetectionStrategy, Component, OnDestroy, OnInit } from '@angular/
|
|
|
import { FormBuilder, FormControl, FormGroup } from '@angular/forms';
|
|
|
import { ActivatedRoute, Router } from '@angular/router';
|
|
|
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
|
|
|
-import { Asset, BaseDetailComponent, GetAsset, LanguageCode } from '@vendure/admin-ui/core';
|
|
|
+import {
|
|
|
+ Asset,
|
|
|
+ BaseDetailComponent,
|
|
|
+ CustomFieldConfig,
|
|
|
+ GetAsset,
|
|
|
+ LanguageCode,
|
|
|
+} from '@vendure/admin-ui/core';
|
|
|
import { DataService, NotificationService, ServerConfigService } from '@vendure/admin-ui/core';
|
|
|
|
|
|
@Component({
|
|
|
@@ -13,6 +19,7 @@ import { DataService, NotificationService, ServerConfigService } from '@vendure/
|
|
|
})
|
|
|
export class AssetDetailComponent extends BaseDetailComponent<GetAsset.Asset> implements OnInit, OnDestroy {
|
|
|
detailForm = new FormGroup({});
|
|
|
+ customFields: CustomFieldConfig[];
|
|
|
|
|
|
constructor(
|
|
|
router: Router,
|
|
|
@@ -23,12 +30,16 @@ export class AssetDetailComponent extends BaseDetailComponent<GetAsset.Asset> im
|
|
|
private formBuilder: FormBuilder,
|
|
|
) {
|
|
|
super(route, router, serverConfigService, dataService);
|
|
|
+ this.customFields = this.getCustomFieldConfig('Asset');
|
|
|
}
|
|
|
|
|
|
ngOnInit() {
|
|
|
this.detailForm = new FormGroup({
|
|
|
name: new FormControl(''),
|
|
|
tags: new FormControl([]),
|
|
|
+ customFields: this.formBuilder.group(
|
|
|
+ this.customFields.reduce((hash, field) => ({ ...hash, [field.name]: '' }), {}),
|
|
|
+ ),
|
|
|
});
|
|
|
this.init();
|
|
|
}
|
|
|
@@ -49,6 +60,7 @@ export class AssetDetailComponent extends BaseDetailComponent<GetAsset.Asset> im
|
|
|
id: this.id,
|
|
|
name: this.detailForm.value.name,
|
|
|
tags: this.detailForm.value.tags,
|
|
|
+ customFields: this.detailForm.value.customFields,
|
|
|
})
|
|
|
.subscribe(
|
|
|
() => {
|
|
|
@@ -65,5 +77,17 @@ export class AssetDetailComponent extends BaseDetailComponent<GetAsset.Asset> im
|
|
|
protected setFormValues(entity: GetAsset.Asset, languageCode: LanguageCode): void {
|
|
|
this.detailForm.get('name')?.setValue(entity.name);
|
|
|
this.detailForm.get('tags')?.setValue(entity.tags);
|
|
|
+ if (this.customFields.length) {
|
|
|
+ const customFieldsGroup = this.detailForm.get('customFields') as FormGroup;
|
|
|
+
|
|
|
+ for (const fieldDef of this.customFields) {
|
|
|
+ const key = fieldDef.name;
|
|
|
+ const value = (entity as any).customFields[key];
|
|
|
+ const control = customFieldsGroup.get(key);
|
|
|
+ if (control) {
|
|
|
+ control.patchValue(value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|