fix issues regarding item and collection mappings

This commit is contained in:
Art Lowel
2021-01-13 17:56:07 +01:00
committed by Marie Verdonck
parent dbfab94a47
commit 8efbaebc9c
3 changed files with 49 additions and 38 deletions

View File

@@ -7,11 +7,12 @@ import { ActivatedRoute, Router } from '@angular/router';
import { RemoteData } from '../../core/data/remote-data'; import { RemoteData } from '../../core/data/remote-data';
import { Collection } from '../../core/shared/collection.model'; import { Collection } from '../../core/shared/collection.model';
import { PaginatedList } from '../../core/data/paginated-list.model'; import { PaginatedList } from '../../core/data/paginated-list.model';
import { filter, map, startWith, switchMap, take } from 'rxjs/operators'; import { map, startWith, switchMap, take } from 'rxjs/operators';
import { import {
getRemoteDataPayload, getRemoteDataPayload,
getFirstSucceededRemoteData, getFirstSucceededRemoteData,
toDSpaceObjectListRD toDSpaceObjectListRD,
getFirstCompletedRemoteData, getAllSucceededRemoteData
} from '../../core/shared/operators'; } from '../../core/shared/operators';
import { DSpaceObject } from '../../core/shared/dspace-object.model'; import { DSpaceObject } from '../../core/shared/dspace-object.model';
import { DSpaceObjectType } from '../../core/shared/dspace-object-type.model'; import { DSpaceObjectType } from '../../core/shared/dspace-object-type.model';
@@ -20,7 +21,7 @@ import { NotificationsService } from '../../shared/notifications/notifications.s
import { ItemDataService } from '../../core/data/item-data.service'; import { ItemDataService } from '../../core/data/item-data.service';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { CollectionDataService } from '../../core/data/collection-data.service'; import { CollectionDataService } from '../../core/data/collection-data.service';
import { hasValue, isNotEmpty } from '../../shared/empty.util'; import { isNotEmpty } from '../../shared/empty.util';
import { SEARCH_CONFIG_SERVICE } from '../../+my-dspace-page/my-dspace-page.component'; import { SEARCH_CONFIG_SERVICE } from '../../+my-dspace-page/my-dspace-page.component';
import { SearchConfigurationService } from '../../core/shared/search/search-configuration.service'; import { SearchConfigurationService } from '../../core/shared/search/search-configuration.service';
import { PaginatedSearchOptions } from '../../shared/search/paginated-search-options.model'; import { PaginatedSearchOptions } from '../../shared/search/paginated-search-options.model';
@@ -53,7 +54,7 @@ export class CollectionItemMapperComponent implements OnInit {
* A view on the tabset element * A view on the tabset element
* Used to switch tabs programmatically * Used to switch tabs programmatically
*/ */
@ViewChild('tabs') tabs; @ViewChild('tabs', {static: false}) tabs;
/** /**
* The collection to map items to * The collection to map items to
@@ -108,13 +109,12 @@ export class CollectionItemMapperComponent implements OnInit {
} }
ngOnInit(): void { ngOnInit(): void {
this.collectionRD$ = this.route.data.pipe( this.collectionRD$ = this.route.parent.data.pipe(
take(1), map((data) => data.dso as RemoteData<Collection>),
map((data) => data.dso), getFirstSucceededRemoteData()
); );
this.collectionName$ = this.collectionRD$.pipe( this.collectionName$ = this.collectionRD$.pipe(
filter((rd: RemoteData<Collection>) => hasValue(rd)),
map((rd: RemoteData<Collection>) => { map((rd: RemoteData<Collection>) => {
return this.dsoNameService.getName(rd.payload); return this.dsoNameService.getName(rd.payload);
}) })
@@ -136,17 +136,18 @@ export class CollectionItemMapperComponent implements OnInit {
); );
this.collectionItemsRD$ = collectionAndOptions$.pipe( this.collectionItemsRD$ = collectionAndOptions$.pipe(
switchMap(([collectionRD, options, shouldUpdate]) => { switchMap(([collectionRD, options, shouldUpdate]) => {
if (shouldUpdate) { if (shouldUpdate === true) {
this.shouldUpdate$.next(false); this.shouldUpdate$.next(false);
} }
return this.itemDataService.findAllByHref(collectionRD.payload._links.mappedItems.href, Object.assign(options, { return this.itemDataService.findAllByHref(collectionRD.payload._links.mappedItems.href, Object.assign(options, {
sort: this.defaultSortOptions sort: this.defaultSortOptions
}),!shouldUpdate, true, followLink('owningCollection')); }),!shouldUpdate, false, followLink('owningCollection')).pipe(
getAllSucceededRemoteData()
)
}) })
); );
this.mappedItemsRD$ = collectionAndOptions$.pipe( this.mappedItemsRD$ = collectionAndOptions$.pipe(
switchMap(([collectionRD, options, shouldUpdate]) => { switchMap(([collectionRD, options, shouldUpdate]) => {
if (shouldUpdate) {
return this.searchService.search(Object.assign(new PaginatedSearchOptions(options), { return this.searchService.search(Object.assign(new PaginatedSearchOptions(options), {
query: this.buildQuery(collectionRD.payload.id, options.query), query: this.buildQuery(collectionRD.payload.id, options.query),
scope: undefined, scope: undefined,
@@ -156,7 +157,6 @@ export class CollectionItemMapperComponent implements OnInit {
toDSpaceObjectListRD(), toDSpaceObjectListRD(),
startWith(undefined) startWith(undefined)
); );
}
}) })
); );
} }
@@ -171,8 +171,17 @@ export class CollectionItemMapperComponent implements OnInit {
getFirstSucceededRemoteData(), getFirstSucceededRemoteData(),
map((collectionRD: RemoteData<Collection>) => collectionRD.payload), map((collectionRD: RemoteData<Collection>) => collectionRD.payload),
switchMap((collection: Collection) => switchMap((collection: Collection) =>
observableCombineLatest(ids.map((id: string) => observableCombineLatest(ids.map((id: string) => {
remove ? this.itemDataService.removeMappingFromCollection(id, collection.id) : this.itemDataService.mapToCollection(id, collection._links.self.href) if (remove) {
return this.itemDataService.removeMappingFromCollection(id, collection.id).pipe(
getFirstCompletedRemoteData()
);
} else {
return this.itemDataService.mapToCollection(id, collection._links.self.href).pipe(
getFirstCompletedRemoteData()
);
}
}
)) ))
) )
); );
@@ -200,6 +209,7 @@ export class CollectionItemMapperComponent implements OnInit {
successMessages.subscribe(([head, content]) => { successMessages.subscribe(([head, content]) => {
this.notificationsService.success(head, content); this.notificationsService.success(head, content);
}); });
this.shouldUpdate$.next(true);
} }
if (unsuccessful.length > 0) { if (unsuccessful.length > 0) {
const unsuccessMessages = observableCombineLatest( const unsuccessMessages = observableCombineLatest(
@@ -211,8 +221,6 @@ export class CollectionItemMapperComponent implements OnInit {
this.notificationsService.error(head, content); this.notificationsService.error(head, content);
}); });
} }
// Force an update on all lists and switch back to the first tab
this.shouldUpdate$.next(true);
this.switchToFirstTab(); this.switchToFirstTab();
}); });
} }

View File

@@ -9,7 +9,6 @@ import { CreateCollectionPageGuard } from './create-collection-page/create-colle
import { DeleteCollectionPageComponent } from './delete-collection-page/delete-collection-page.component'; import { DeleteCollectionPageComponent } from './delete-collection-page/delete-collection-page.component';
import { EditItemTemplatePageComponent } from './edit-item-template-page/edit-item-template-page.component'; import { EditItemTemplatePageComponent } from './edit-item-template-page/edit-item-template-page.component';
import { ItemTemplatePageResolver } from './edit-item-template-page/item-template-page.resolver'; import { ItemTemplatePageResolver } from './edit-item-template-page/item-template-page.resolver';
import { CollectionItemMapperComponent } from './collection-item-mapper/collection-item-mapper.component';
import { CollectionBreadcrumbResolver } from '../core/breadcrumbs/collection-breadcrumb.resolver'; import { CollectionBreadcrumbResolver } from '../core/breadcrumbs/collection-breadcrumb.resolver';
import { DSOBreadcrumbsService } from '../core/breadcrumbs/dso-breadcrumbs.service'; import { DSOBreadcrumbsService } from '../core/breadcrumbs/dso-breadcrumbs.service';
import { LinkService } from '../core/cache/builders/link.service'; import { LinkService } from '../core/cache/builders/link.service';
@@ -65,12 +64,6 @@ import { LinkMenuItemModel } from '../shared/menu/menu-item/models/link.model';
path: '', path: '',
component: CollectionPageComponent, component: CollectionPageComponent,
pathMatch: 'full', pathMatch: 'full',
},
{
path: '/edit/mapper',
component: CollectionItemMapperComponent,
pathMatch: 'full',
canActivate: [AuthenticatedGuard]
} }
], ],
data: { data: {

View File

@@ -13,7 +13,7 @@ import {
getRemoteDataPayload, getRemoteDataPayload,
getFirstSucceededRemoteData, getFirstSucceededRemoteData,
toDSpaceObjectListRD, toDSpaceObjectListRD,
getAllSucceededRemoteData getAllSucceededRemoteData, getFirstCompletedRemoteData
} from '../../../core/shared/operators'; } from '../../../core/shared/operators';
import { ActivatedRoute, Router } from '@angular/router'; import { ActivatedRoute, Router } from '@angular/router';
import { filter, map, startWith, switchMap, take } from 'rxjs/operators'; import { filter, map, startWith, switchMap, take } from 'rxjs/operators';
@@ -135,7 +135,8 @@ export class ItemCollectionMapperComponent implements OnInit {
const owningCollectionRD$ = this.itemRD$.pipe( const owningCollectionRD$ = this.itemRD$.pipe(
getFirstSucceededRemoteDataPayload(), getFirstSucceededRemoteDataPayload(),
switchMap((item: Item) => this.collectionDataService.findOwningCollectionFor(item)) switchMap((item: Item) => this.collectionDataService.findOwningCollectionFor(item)),
getAllSucceededRemoteData(),
); );
const itemCollectionsAndOptions$ = observableCombineLatest( const itemCollectionsAndOptions$ = observableCombineLatest(
this.itemCollectionsRD$, this.itemCollectionsRD$,
@@ -175,7 +176,12 @@ export class ItemCollectionMapperComponent implements OnInit {
// Map the item to the collections found in ids, excluding the collections the item is already mapped to // Map the item to the collections found in ids, excluding the collections the item is already mapped to
const responses$ = itemIdAndExcludingIds$.pipe( const responses$ = itemIdAndExcludingIds$.pipe(
switchMap(([itemId, excludingIds]) => observableCombineLatest(this.filterIds(ids, excludingIds).map((id: string) => this.itemDataService.mapToCollection(itemId, id)))) switchMap(([itemId, excludingIds]) =>
observableCombineLatest(
this.filterIds(ids, excludingIds).map((id: string) =>
this.itemDataService.mapToCollection(itemId, id).pipe(getFirstCompletedRemoteData())
))
)
); );
this.showNotifications(responses$, 'item.edit.item-mapper.notifications.add'); this.showNotifications(responses$, 'item.edit.item-mapper.notifications.add');
@@ -189,7 +195,11 @@ export class ItemCollectionMapperComponent implements OnInit {
const responses$ = this.itemRD$.pipe( const responses$ = this.itemRD$.pipe(
getFirstSucceededRemoteData(), getFirstSucceededRemoteData(),
map((itemRD: RemoteData<Item>) => itemRD.payload.id), map((itemRD: RemoteData<Item>) => itemRD.payload.id),
switchMap((itemId: string) => observableCombineLatest(ids.map((id: string) => this.itemDataService.removeMappingFromCollection(itemId, id)))) switchMap((itemId: string) => observableCombineLatest(
ids.map((id: string) =>
this.itemDataService.removeMappingFromCollection(itemId, id).pipe(getFirstCompletedRemoteData())
))
)
); );
this.showNotifications(responses$, 'item.edit.item-mapper.notifications.remove'); this.showNotifications(responses$, 'item.edit.item-mapper.notifications.remove');