Commits

Art Lowel authored ad4e8eeb8c5
refactored items, bundles and bitstreams, test builders
No tags

src/app/+item-page/edit-item-page/item-collection-mapper/item-collection-mapper.component.ts

Modified
1 1 import { combineLatest as observableCombineLatest, Observable } from 'rxjs';
2 2
3 3 import { ChangeDetectionStrategy, Component, OnInit, ViewChild } from '@angular/core';
4 +import { CollectionDataService } from '../../../core/data/collection-data.service';
4 5 import { fadeIn, fadeInOut } from '../../../shared/animations/fade';
5 6 import { RemoteData } from '../../../core/data/remote-data';
6 7 import { PaginatedList } from '../../../core/data/paginated-list';
7 8 import { Collection } from '../../../core/shared/collection.model';
8 9 import { Item } from '../../../core/shared/item.model';
9 -import { getRemoteDataPayload, getSucceededRemoteData, toDSpaceObjectListRD } from '../../../core/shared/operators';
10 +import {
11 + getFirstSucceededRemoteDataPayload,
12 + getRemoteDataPayload,
13 + getSucceededRemoteData,
14 + toDSpaceObjectListRD
15 +} from '../../../core/shared/operators';
10 16 import { ActivatedRoute, Router } from '@angular/router';
11 17 import { map, startWith, switchMap, take } from 'rxjs/operators';
12 18 import { ItemDataService } from '../../../core/data/item-data.service';
13 19 import { TranslateService } from '@ngx-translate/core';
14 20 import { NotificationsService } from '../../../shared/notifications/notifications.service';
15 21 import { DSpaceObjectType } from '../../../core/shared/dspace-object-type.model';
16 22 import { isNotEmpty } from '../../../shared/empty.util';
17 23 import { RestResponse } from '../../../core/cache/response.models';
18 24 import { BehaviorSubject } from 'rxjs/internal/BehaviorSubject';
19 25 import { PaginatedSearchOptions } from '../../../shared/search/paginated-search-options.model';
74 80 * As soon as at least one search has been performed, we display the search results
75 81 */
76 82 performedSearch = false;
77 83
78 84 constructor(private route: ActivatedRoute,
79 85 private router: Router,
80 86 private searchConfigService: SearchConfigurationService,
81 87 private searchService: SearchService,
82 88 private notificationsService: NotificationsService,
83 89 private itemDataService: ItemDataService,
90 + private collectionDataService: CollectionDataService,
84 91 private translateService: TranslateService) {
85 92 }
86 93
87 94 ngOnInit(): void {
88 95 this.itemRD$ = this.route.data.pipe(map((data) => data.item)).pipe(getSucceededRemoteData()) as Observable<RemoteData<Item>>;
89 96 this.searchOptions$ = this.searchConfigService.paginatedSearchOptions;
90 97 this.loadCollectionLists();
91 98 }
92 99
93 100 /**
99 106 this.itemCollectionsRD$ = observableCombineLatest(this.itemRD$, this.shouldUpdate$).pipe(
100 107 map(([itemRD, shouldUpdate]) => {
101 108 if (shouldUpdate) {
102 109 return itemRD.payload
103 110 }
104 111 }),
105 112 switchMap((item: Item) => this.itemDataService.getMappedCollections(item.id))
106 113 );
107 114
108 115 const owningCollectionRD$ = this.itemRD$.pipe(
109 - switchMap((itemRD: RemoteData<Item>) => itemRD.payload.owningCollection)
116 + getFirstSucceededRemoteDataPayload(),
117 + switchMap((item: Item) => this.collectionDataService.findOwningCollectionFor(item))
110 118 );
111 119 const itemCollectionsAndOptions$ = observableCombineLatest(
112 120 this.itemCollectionsRD$,
113 121 owningCollectionRD$,
114 122 this.searchOptions$
115 123 );
116 124 this.mappedCollectionsRD$ = itemCollectionsAndOptions$.pipe(
117 125 switchMap(([itemCollectionsRD, owningCollectionRD, searchOptions]) => {
118 126 return this.searchService.search(Object.assign(new PaginatedSearchOptions(searchOptions), {
119 127 query: this.buildQuery([...itemCollectionsRD.payload.page, owningCollectionRD.payload], searchOptions.query),

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut