mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
Merge pull request #1139 from atmire/w2p-78994_Issue-1103_Fix-relationship-modal-on-item-page
Fix relationship modal on item page
This commit is contained in:
@@ -18,7 +18,7 @@ import { RelationshipType } from '../../../../core/shared/item-relationships/rel
|
|||||||
import {
|
import {
|
||||||
getAllSucceededRemoteData,
|
getAllSucceededRemoteData,
|
||||||
getRemoteDataPayload,
|
getRemoteDataPayload,
|
||||||
getFirstSucceededRemoteData,
|
getFirstSucceededRemoteData, getFirstSucceededRemoteDataPayload,
|
||||||
} from '../../../../core/shared/operators';
|
} from '../../../../core/shared/operators';
|
||||||
import { ItemType } from '../../../../core/shared/item-relationships/item-type.model';
|
import { ItemType } from '../../../../core/shared/item-relationships/item-type.model';
|
||||||
import { DsDynamicLookupRelationModalComponent } from '../../../../shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/dynamic-lookup-relation-modal.component';
|
import { DsDynamicLookupRelationModalComponent } from '../../../../shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/dynamic-lookup-relation-modal.component';
|
||||||
@@ -29,6 +29,7 @@ import { SearchResult } from '../../../../shared/search/search-result.model';
|
|||||||
import { followLink } from '../../../../shared/utils/follow-link-config.model';
|
import { followLink } from '../../../../shared/utils/follow-link-config.model';
|
||||||
import { PaginatedList } from '../../../../core/data/paginated-list.model';
|
import { PaginatedList } from '../../../../core/data/paginated-list.model';
|
||||||
import { RemoteData } from '../../../../core/data/remote-data';
|
import { RemoteData } from '../../../../core/data/remote-data';
|
||||||
|
import { Collection } from '../../../../core/shared/collection.model';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-edit-relationship-list',
|
selector: 'ds-edit-relationship-list',
|
||||||
@@ -146,6 +147,11 @@ export class EditRelationshipListComponent implements OnInit {
|
|||||||
modalComp.repeatable = true;
|
modalComp.repeatable = true;
|
||||||
modalComp.listId = this.listId;
|
modalComp.listId = this.listId;
|
||||||
modalComp.item = this.item;
|
modalComp.item = this.item;
|
||||||
|
this.item.owningCollection.pipe(
|
||||||
|
getFirstSucceededRemoteDataPayload()
|
||||||
|
).subscribe((collection: Collection) => {
|
||||||
|
modalComp.collection = collection;
|
||||||
|
});
|
||||||
modalComp.select = (...selectableObjects: SearchResult<Item>[]) => {
|
modalComp.select = (...selectableObjects: SearchResult<Item>[]) => {
|
||||||
selectableObjects.forEach((searchResult) => {
|
selectableObjects.forEach((searchResult) => {
|
||||||
const relatedItem: Item = searchResult.indexableObject;
|
const relatedItem: Item = searchResult.indexableObject;
|
||||||
|
@@ -21,8 +21,6 @@ import { createPaginatedList } from '../../../../testing/utils.test';
|
|||||||
import { ExternalSourceService } from '../../../../../core/data/external-source.service';
|
import { ExternalSourceService } from '../../../../../core/data/external-source.service';
|
||||||
import { LookupRelationService } from '../../../../../core/data/lookup-relation.service';
|
import { LookupRelationService } from '../../../../../core/data/lookup-relation.service';
|
||||||
import { RemoteDataBuildService } from '../../../../../core/cache/builders/remote-data-build.service';
|
import { RemoteDataBuildService } from '../../../../../core/cache/builders/remote-data-build.service';
|
||||||
import { SubmissionService } from '../../../../../submission/submission.service';
|
|
||||||
import { SubmissionObjectDataService } from '../../../../../core/submission/submission-object-data.service';
|
|
||||||
import { WorkspaceItem } from '../../../../../core/submission/models/workspaceitem.model';
|
import { WorkspaceItem } from '../../../../../core/submission/models/workspaceitem.model';
|
||||||
import { Collection } from '../../../../../core/shared/collection.model';
|
import { Collection } from '../../../../../core/shared/collection.model';
|
||||||
|
|
||||||
@@ -46,8 +44,6 @@ describe('DsDynamicLookupRelationModalComponent', () => {
|
|||||||
let lookupRelationService;
|
let lookupRelationService;
|
||||||
let rdbService;
|
let rdbService;
|
||||||
let submissionId;
|
let submissionId;
|
||||||
let submissionService;
|
|
||||||
let submissionObjectDataService;
|
|
||||||
|
|
||||||
const externalSources = [
|
const externalSources = [
|
||||||
Object.assign(new ExternalSource(), {
|
Object.assign(new ExternalSource(), {
|
||||||
@@ -99,12 +95,6 @@ describe('DsDynamicLookupRelationModalComponent', () => {
|
|||||||
rdbService = jasmine.createSpyObj('rdbService', {
|
rdbService = jasmine.createSpyObj('rdbService', {
|
||||||
aggregate: createSuccessfulRemoteDataObject$(externalSources)
|
aggregate: createSuccessfulRemoteDataObject$(externalSources)
|
||||||
});
|
});
|
||||||
submissionService = jasmine.createSpyObj('SubmissionService', {
|
|
||||||
dispatchSave: jasmine.createSpy('dispatchSave')
|
|
||||||
});
|
|
||||||
submissionObjectDataService = jasmine.createSpyObj('SubmissionObjectDataService', {
|
|
||||||
findById: createSuccessfulRemoteDataObject$(testWSI)
|
|
||||||
});
|
|
||||||
submissionId = '1234';
|
submissionId = '1234';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,8 +119,6 @@ describe('DsDynamicLookupRelationModalComponent', () => {
|
|||||||
},
|
},
|
||||||
{ provide: RelationshipTypeService, useValue: {} },
|
{ provide: RelationshipTypeService, useValue: {} },
|
||||||
{ provide: RemoteDataBuildService, useValue: rdbService },
|
{ provide: RemoteDataBuildService, useValue: rdbService },
|
||||||
{ provide: SubmissionService, useValue: submissionService },
|
|
||||||
{ provide: SubmissionObjectDataService, useValue: submissionObjectDataService },
|
|
||||||
{
|
{
|
||||||
provide: Store, useValue: {
|
provide: Store, useValue: {
|
||||||
// tslint:disable-next-line:no-empty
|
// tslint:disable-next-line:no-empty
|
||||||
|
@@ -12,11 +12,8 @@ import { RelationshipOptions } from '../../models/relationship-options.model';
|
|||||||
import { SearchResult } from '../../../../search/search-result.model';
|
import { SearchResult } from '../../../../search/search-result.model';
|
||||||
import { Item } from '../../../../../core/shared/item.model';
|
import { Item } from '../../../../../core/shared/item.model';
|
||||||
import {
|
import {
|
||||||
getAllSucceededRemoteData,
|
AddRelationshipAction, RemoveRelationshipAction, UpdateRelationshipNameVariantAction,
|
||||||
getAllSucceededRemoteDataPayload,
|
} from './relationship.actions';
|
||||||
getRemoteDataPayload
|
|
||||||
} from '../../../../../core/shared/operators';
|
|
||||||
import { AddRelationshipAction, RemoveRelationshipAction, UpdateRelationshipNameVariantAction } from './relationship.actions';
|
|
||||||
import { RelationshipService } from '../../../../../core/data/relationship.service';
|
import { RelationshipService } from '../../../../../core/data/relationship.service';
|
||||||
import { RelationshipTypeService } from '../../../../../core/data/relationship-type.service';
|
import { RelationshipTypeService } from '../../../../../core/data/relationship-type.service';
|
||||||
import { Store } from '@ngrx/store';
|
import { Store } from '@ngrx/store';
|
||||||
@@ -27,12 +24,7 @@ import { ExternalSource } from '../../../../../core/shared/external-source.model
|
|||||||
import { ExternalSourceService } from '../../../../../core/data/external-source.service';
|
import { ExternalSourceService } from '../../../../../core/data/external-source.service';
|
||||||
import { Router } from '@angular/router';
|
import { Router } from '@angular/router';
|
||||||
import { RemoteDataBuildService } from '../../../../../core/cache/builders/remote-data-build.service';
|
import { RemoteDataBuildService } from '../../../../../core/cache/builders/remote-data-build.service';
|
||||||
import { followLink } from '../../../../utils/follow-link-config.model';
|
import { getAllSucceededRemoteDataPayload } from '../../../../../core/shared/operators';
|
||||||
import { SubmissionObject } from '../../../../../core/submission/models/submission-object.model';
|
|
||||||
import { Collection } from '../../../../../core/shared/collection.model';
|
|
||||||
import { SubmissionService } from '../../../../../submission/submission.service';
|
|
||||||
import { SubmissionObjectDataService } from '../../../../../core/submission/submission-object-data.service';
|
|
||||||
import { RemoteData } from '../../../../../core/data/remote-data';
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-dynamic-lookup-relation-modal',
|
selector: 'ds-dynamic-lookup-relation-modal',
|
||||||
@@ -122,10 +114,6 @@ export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy
|
|||||||
*/
|
*/
|
||||||
totalExternal$: Observable<number[]>;
|
totalExternal$: Observable<number[]>;
|
||||||
|
|
||||||
/**
|
|
||||||
* List of subscriptions to unsubscribe from
|
|
||||||
*/
|
|
||||||
private subs: Subscription[] = [];
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public modal: NgbActiveModal,
|
public modal: NgbActiveModal,
|
||||||
@@ -136,17 +124,14 @@ export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy
|
|||||||
private lookupRelationService: LookupRelationService,
|
private lookupRelationService: LookupRelationService,
|
||||||
private searchConfigService: SearchConfigurationService,
|
private searchConfigService: SearchConfigurationService,
|
||||||
private rdbService: RemoteDataBuildService,
|
private rdbService: RemoteDataBuildService,
|
||||||
private submissionService: SubmissionService,
|
|
||||||
private submissionObjectService: SubmissionObjectDataService,
|
|
||||||
private zone: NgZone,
|
private zone: NgZone,
|
||||||
private store: Store<AppState>,
|
private store: Store<AppState>,
|
||||||
private router: Router
|
private router: Router,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.setItem();
|
|
||||||
this.selection$ = this.selectableListService
|
this.selection$ = this.selectableListService
|
||||||
.getSelectableList(this.listId)
|
.getSelectableList(this.listId)
|
||||||
.pipe(map((listState: SelectableListState) => hasValue(listState) && hasValue(listState.selection) ? listState.selection : []));
|
.pipe(map((listState: SelectableListState) => hasValue(listState) && hasValue(listState.selection) ? listState.selection : []));
|
||||||
@@ -206,24 +191,6 @@ export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialize this.item$ based on this.model.submissionId
|
|
||||||
*/
|
|
||||||
private setItem() {
|
|
||||||
const submissionObject$ = this.submissionObjectService
|
|
||||||
.findById(this.submissionId, true, true, followLink('item'), followLink('collection')).pipe(
|
|
||||||
getAllSucceededRemoteData(),
|
|
||||||
getRemoteDataPayload()
|
|
||||||
);
|
|
||||||
|
|
||||||
const item$ = submissionObject$.pipe(switchMap((submissionObject: SubmissionObject) => (submissionObject.item as Observable<RemoteData<Item>>).pipe(getAllSucceededRemoteData(), getRemoteDataPayload())));
|
|
||||||
const collection$ = submissionObject$.pipe(switchMap((submissionObject: SubmissionObject) => (submissionObject.collection as Observable<RemoteData<Collection>>).pipe(getAllSucceededRemoteData(), getRemoteDataPayload())));
|
|
||||||
|
|
||||||
this.subs.push(item$.subscribe((item) => this.item = item));
|
|
||||||
this.subs.push(collection$.subscribe((collection) => this.collection = collection));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a subscription updating relationships with name variants
|
* Add a subscription updating relationships with name variants
|
||||||
* @param sri The search result to track name variants for
|
* @param sri The search result to track name variants for
|
||||||
@@ -279,8 +246,5 @@ export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy
|
|||||||
ngOnDestroy() {
|
ngOnDestroy() {
|
||||||
this.router.navigate([], {});
|
this.router.navigate([], {});
|
||||||
Object.values(this.subMap).forEach((subscription) => subscription.unsubscribe());
|
Object.values(this.subMap).forEach((subscription) => subscription.unsubscribe());
|
||||||
this.subs
|
|
||||||
.filter((sub) => hasValue(sub))
|
|
||||||
.forEach((sub) => sub.unsubscribe());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user