mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-09 11:03:05 +00:00
add/remove subscriptions for name variants on init/destroy
This commit is contained in:
@@ -52,6 +52,7 @@ import { MetadataFieldWrapperComponent } from './field-components/metadata-field
|
|||||||
RelatedItemsComponent,
|
RelatedItemsComponent,
|
||||||
ItemComponent,
|
ItemComponent,
|
||||||
GenericItemPageFieldComponent,
|
GenericItemPageFieldComponent,
|
||||||
|
MetadataRepresentationListComponent,
|
||||||
RelatedEntitiesSearchComponent
|
RelatedEntitiesSearchComponent
|
||||||
],
|
],
|
||||||
exports: [
|
exports: [
|
||||||
@@ -61,6 +62,7 @@ import { MetadataFieldWrapperComponent } from './field-components/metadata-field
|
|||||||
GenericItemPageFieldComponent,
|
GenericItemPageFieldComponent,
|
||||||
RelatedEntitiesSearchComponent,
|
RelatedEntitiesSearchComponent,
|
||||||
RelatedItemsComponent,
|
RelatedItemsComponent,
|
||||||
|
MetadataRepresentationListComponent,
|
||||||
ItemPageTitleFieldComponent
|
ItemPageTitleFieldComponent
|
||||||
],
|
],
|
||||||
entryComponents: [
|
entryComponents: [
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { Component, NgZone, OnInit } from '@angular/core';
|
import { Component, NgZone, OnDestroy, OnInit } from '@angular/core';
|
||||||
import { combineLatest, Observable, Subscription } from 'rxjs';
|
import { combineLatest, Observable, Subscription } from 'rxjs';
|
||||||
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
|
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
|
||||||
import { hasValue } from '../../../../empty.util';
|
import { hasValue } from '../../../../empty.util';
|
||||||
@@ -33,7 +33,7 @@ import { MetadataValue } from '../../../../../core/shared/metadata.models';
|
|||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
export class DsDynamicLookupRelationModalComponent implements OnInit {
|
export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy {
|
||||||
label: string;
|
label: string;
|
||||||
relationshipOptions: RelationshipOptions;
|
relationshipOptions: RelationshipOptions;
|
||||||
listId: string;
|
listId: string;
|
||||||
@@ -57,7 +57,12 @@ export class DsDynamicLookupRelationModalComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.selection$ = this.selectableListService.getSelectableList(this.listId).pipe(map((listState: SelectableListState) => hasValue(listState) && hasValue(listState.selection) ? listState.selection : []));
|
this.selection$ = this.selectableListService
|
||||||
|
.getSelectableList(this.listId)
|
||||||
|
.pipe(map((listState: SelectableListState) => hasValue(listState) && hasValue(listState.selection) ? listState.selection : []));
|
||||||
|
this.selection$.subscribe((selection) =>
|
||||||
|
selection.map((s: SearchResult<Item>) => this.addNameVariantSubscription(s))
|
||||||
|
);
|
||||||
if (this.relationshipOptions.nameVariants) {
|
if (this.relationshipOptions.nameVariants) {
|
||||||
this.context = Context.Workspace;
|
this.context = Context.Workspace;
|
||||||
}
|
}
|
||||||
@@ -89,7 +94,6 @@ export class DsDynamicLookupRelationModalComponent implements OnInit {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
obs
|
obs
|
||||||
.subscribe((obs: any[]) => {
|
.subscribe((obs: any[]) => {
|
||||||
return obs.forEach((object: any) => {
|
return obs.forEach((object: any) => {
|
||||||
@@ -100,6 +104,13 @@ export class DsDynamicLookupRelationModalComponent implements OnInit {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addNameVariantSubscription(sri: SearchResult<Item>) {
|
||||||
|
const nameVariant$ = this.relationshipService.getNameVariant(this.listId, sri.indexableObject.uuid);
|
||||||
|
this.subMap[sri.indexableObject.uuid] = nameVariant$.pipe(switchMap((nameVariant: string) =>
|
||||||
|
this.relationshipService.updateNameVariant(this.item, sri.indexableObject, this.relationshipOptions.relationshipType, nameVariant)
|
||||||
|
)).subscribe()
|
||||||
|
}
|
||||||
|
|
||||||
deselect(...selectableObjects: SearchResult<Item>[]) {
|
deselect(...selectableObjects: SearchResult<Item>[]) {
|
||||||
this.zone.runOutsideAngular(
|
this.zone.runOutsideAngular(
|
||||||
() => selectableObjects.forEach((object) => {
|
() => selectableObjects.forEach((object) => {
|
||||||
@@ -110,33 +121,6 @@ export class DsDynamicLookupRelationModalComponent implements OnInit {
|
|||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
// subscriptions = new Map<string, Subscription>();
|
|
||||||
//
|
|
||||||
// addSelectSubscription(itemSR: SearchResult<Item>) {
|
|
||||||
// const nameVariant$ = this.relationshipService.getNameVariant(this.listId, itemSR.indexableObject.uuid).pipe(hasValueOperator());
|
|
||||||
// const subscription = nameVariant$
|
|
||||||
// .pipe(
|
|
||||||
// switchMap((nameVariant: string) => {
|
|
||||||
// return this.relationshipService.getRelationshipByItemsAndLabel(this.item, itemSR.indexableObject, this.relationshipOptions.relationshipType)
|
|
||||||
// .pipe(map((relationship: Relationship) => Object.assign(new Relationship(), relationship, { leftwardValue: nameVariant })))
|
|
||||||
// }),
|
|
||||||
// switchMap((updatedRelation: Relationship) => this.relationshipService.update(updatedRelation))
|
|
||||||
// )
|
|
||||||
// .subscribe();
|
|
||||||
// this.subscriptions.set(itemSR.indexableObject.uuid, subscription);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// removeSelectSubscription(itemSR: SearchResult<Item>) {
|
|
||||||
// this.subscriptions.get(itemSR.indexableObject.uuid).unsubscribe();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// ngOnDestroy() {
|
|
||||||
// let sub;
|
|
||||||
// while (sub = this.subscriptions.values().next(), !sub.done) {
|
|
||||||
// sub.unsubscribe();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
setExistingNameVariants() {
|
setExistingNameVariants() {
|
||||||
const virtualMDs$: Observable<MetadataValue[]> = this.item.allMetadata(this.metadataFields).filter((mdValue) => mdValue.isVirtual);
|
const virtualMDs$: Observable<MetadataValue[]> = this.item.allMetadata(this.metadataFields).filter((mdValue) => mdValue.isVirtual);
|
||||||
|
|
||||||
@@ -166,4 +150,9 @@ export class DsDynamicLookupRelationModalComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ngOnDestroy() {
|
||||||
|
Object.values(this.subMap).forEach((subscription) => subscription.unsubscribe());
|
||||||
|
}
|
||||||
}
|
}
|
@@ -20,7 +20,6 @@ import { getSucceededRemoteData } from '../../../../../../core/shared/operators'
|
|||||||
import { RouteService } from '../../../../../../core/services/route.service';
|
import { RouteService } from '../../../../../../core/services/route.service';
|
||||||
import { CollectionElementLinkType } from '../../../../../object-collection/collection-element-link.type';
|
import { CollectionElementLinkType } from '../../../../../object-collection/collection-element-link.type';
|
||||||
import { Context } from '../../../../../../core/shared/context.model';
|
import { Context } from '../../../../../../core/shared/context.model';
|
||||||
import { relationship } from '../../../../../../core/cache/builders/build-decorators';
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-dynamic-lookup-relation-search-tab',
|
selector: 'ds-dynamic-lookup-relation-search-tab',
|
||||||
@@ -152,8 +151,7 @@ export class DsDynamicLookupRelationSearchTabComponent implements OnInit, OnDest
|
|||||||
}
|
}
|
||||||
|
|
||||||
ngOnDestroy(): void {
|
ngOnDestroy(): void {
|
||||||
if (hasValue(this.subscription)
|
if (hasValue(this.subscription)) {
|
||||||
) {
|
|
||||||
this.subscription.unsubscribe();
|
this.subscription.unsubscribe();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -321,7 +321,6 @@ const COMPONENTS = [
|
|||||||
ItemSelectComponent,
|
ItemSelectComponent,
|
||||||
CollectionSelectComponent,
|
CollectionSelectComponent,
|
||||||
MetadataRepresentationLoaderComponent,
|
MetadataRepresentationLoaderComponent,
|
||||||
MetadataRepresentationListComponent,
|
|
||||||
];
|
];
|
||||||
|
|
||||||
const ENTRY_COMPONENTS = [
|
const ENTRY_COMPONENTS = [
|
||||||
|
Reference in New Issue
Block a user