+
{{metadata.metadataField}}
@@ -31,7 +31,7 @@
diff --git a/src/app/item-page/edit-item-page/virtual-metadata/virtual-metadata.component.ts b/src/app/item-page/edit-item-page/virtual-metadata/virtual-metadata.component.ts
index 11c9a291f86..e8f42c8fc0c 100644
--- a/src/app/item-page/edit-item-page/virtual-metadata/virtual-metadata.component.ts
+++ b/src/app/item-page/edit-item-page/virtual-metadata/virtual-metadata.component.ts
@@ -8,11 +8,17 @@ import {
EventEmitter,
Inject,
Input,
+ OnChanges,
+ OnDestroy,
OnInit,
Output,
} from '@angular/core';
import { TranslateModule } from '@ngx-translate/core';
-import { Observable } from 'rxjs';
+import {
+ BehaviorSubject,
+ Observable,
+ Subscription,
+} from 'rxjs';
import {
APP_CONFIG,
@@ -21,9 +27,18 @@ import {
import { ObjectUpdatesService } from '../../../core/data/object-updates/object-updates.service';
import { Item } from '../../../core/shared/item.model';
import { MetadataValue } from '../../../core/shared/metadata.models';
+import { hasValue } from '../../../shared/empty.util';
import { ListableObjectComponentLoaderComponent } from '../../../shared/object-collection/shared/listable-object/listable-object-component-loader.component';
import { VarDirective } from '../../../shared/utils/var.directive';
+interface ItemDTO {
+
+ item: Item;
+
+ isSelectedVirtualMetadataItem$: Observable
;
+
+}
+
@Component({
selector: 'ds-virtual-metadata',
templateUrl: './virtual-metadata.component.html',
@@ -42,7 +57,7 @@ import { VarDirective } from '../../../shared/utils/var.directive';
* The component is shown when a relationship is marked to be deleted.
* Each item has a checkbox to indicate whether its virtual metadata should be saved as real metadata.
*/
-export class VirtualMetadataComponent implements OnInit {
+export class VirtualMetadataComponent implements OnInit, OnChanges, OnDestroy {
/**
* The current url of this page
@@ -83,9 +98,9 @@ export class VirtualMetadataComponent implements OnInit {
/**
* Get an array of the left and the right item of the relationship to be deleted.
*/
- get items() {
- return [this.leftItem, this.rightItem];
- }
+ itemDTOs$: BehaviorSubject = new BehaviorSubject([]);
+
+ subs: Subscription[] = [];
public virtualMetadata: Map = new Map();
@@ -137,14 +152,33 @@ export class VirtualMetadataComponent implements OnInit {
/**
* Prevent unnecessary rerendering so fields don't lose focus
*/
- trackItem(index, item: Item) {
- return item && item.uuid;
+ trackItemDTO(index, itemDTO: ItemDTO): string {
+ return itemDTO?.item?.uuid;
}
ngOnInit(): void {
- this.items.forEach((item) => {
- this.virtualMetadata.set(item.uuid, this.getVirtualMetadata(item));
- });
+ this.subs.push(this.itemDTOs$.subscribe((itemDTOs: ItemDTO[]) => {
+ itemDTOs.forEach((itemDTO: ItemDTO) => this.virtualMetadata.set(itemDTO.item.uuid, this.getVirtualMetadata(itemDTO.item)));
+ }));
+ }
+
+ ngOnChanges(): void {
+ if (hasValue(this.leftItem) && hasValue(this.rightItem)) {
+ this.itemDTOs$.next([
+ {
+ item: this.leftItem,
+ isSelectedVirtualMetadataItem$: this.isSelectedVirtualMetadataItem(this.leftItem),
+ },
+ {
+ item: this.rightItem,
+ isSelectedVirtualMetadataItem$: this.isSelectedVirtualMetadataItem(this.rightItem),
+ },
+ ]);
+ }
+ }
+
+ ngOnDestroy(): void {
+ this.subs.forEach((sub: Subscription) => sub.unsubscribe());
}
}