From 02b007a0f6d246fee831f851d8feb78934e322ed Mon Sep 17 00:00:00 2001 From: Kristof De Langhe Date: Tue, 10 Sep 2019 16:29:15 +0200 Subject: [PATCH] 62589: Exclude owning collection + redirect to first tab after mapping + page reload fix --- .../collection-item-mapper.component.html | 6 ++--- .../collection-item-mapper.component.ts | 18 +++++++++++-- .../item-collection-mapper.component.html | 6 ++--- .../item-collection-mapper.component.ts | 27 ++++++++++++++++--- .../collection-select.component.html | 2 +- 5 files changed, 46 insertions(+), 13 deletions(-) diff --git a/src/app/+collection-page/collection-item-mapper/collection-item-mapper.component.html b/src/app/+collection-page/collection-item-mapper/collection-item-mapper.component.html index 9b7216c92a..9e9f9fd8e1 100644 --- a/src/app/+collection-page/collection-item-mapper/collection-item-mapper.component.html +++ b/src/app/+collection-page/collection-item-mapper/collection-item-mapper.component.html @@ -5,8 +5,8 @@

{{'collection.item-mapper.description' | translate}}

- - + +
- +
diff --git a/src/app/+collection-page/collection-item-mapper/collection-item-mapper.component.ts b/src/app/+collection-page/collection-item-mapper/collection-item-mapper.component.ts index 554696c63f..059bd098d4 100644 --- a/src/app/+collection-page/collection-item-mapper/collection-item-mapper.component.ts +++ b/src/app/+collection-page/collection-item-mapper/collection-item-mapper.component.ts @@ -1,6 +1,6 @@ import { combineLatest as observableCombineLatest, Observable } from 'rxjs'; -import { ChangeDetectionStrategy, Component, Inject, OnInit } from '@angular/core'; +import { ChangeDetectionStrategy, Component, Inject, OnInit, ViewChild } from '@angular/core'; import { fadeIn, fadeInOut } from '../../shared/animations/fade'; import { ActivatedRoute, Router } from '@angular/router'; import { RemoteData } from '../../core/data/remote-data'; @@ -44,6 +44,12 @@ import { SEARCH_CONFIG_SERVICE } from '../../+my-dspace-page/my-dspace-page.comp */ export class CollectionItemMapperComponent implements OnInit { + /** + * A view on the tabset element + * Used to switch tabs programmatically + */ + @ViewChild('tabs') tabs; + /** * The collection to map items to */ @@ -180,8 +186,9 @@ export class CollectionItemMapperComponent implements OnInit { this.notificationsService.error(head, content); }); } - // Force an update on all lists + // Force an update on all lists and switch back to the first tab this.shouldUpdate$.next(true); + this.switchToFirstTab(); }); } @@ -228,4 +235,11 @@ export class CollectionItemMapperComponent implements OnInit { } } + /** + * Switch the view to focus on the first tab + */ + switchToFirstTab() { + this.tabs.select('browseTab'); + } + } diff --git a/src/app/+item-page/edit-item-page/item-collection-mapper/item-collection-mapper.component.html b/src/app/+item-page/edit-item-page/item-collection-mapper/item-collection-mapper.component.html index 55619bdc96..97cbb27871 100644 --- a/src/app/+item-page/edit-item-page/item-collection-mapper/item-collection-mapper.component.html +++ b/src/app/+item-page/edit-item-page/item-collection-mapper/item-collection-mapper.component.html @@ -5,8 +5,8 @@

{{'item.edit.item-mapper.description' | translate}}

- - + +
- +
diff --git a/src/app/+item-page/edit-item-page/item-collection-mapper/item-collection-mapper.component.ts b/src/app/+item-page/edit-item-page/item-collection-mapper/item-collection-mapper.component.ts index 803083c428..3a85a75659 100644 --- a/src/app/+item-page/edit-item-page/item-collection-mapper/item-collection-mapper.component.ts +++ b/src/app/+item-page/edit-item-page/item-collection-mapper/item-collection-mapper.component.ts @@ -1,6 +1,6 @@ import { combineLatest as observableCombineLatest, Observable } from 'rxjs'; -import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core'; +import { ChangeDetectionStrategy, Component, OnInit, ViewChild } from '@angular/core'; import { fadeIn, fadeInOut } from '../../../shared/animations/fade'; import { PaginatedSearchOptions } from '../../../+search-page/paginated-search-options.model'; import { RemoteData } from '../../../core/data/remote-data'; @@ -34,6 +34,13 @@ import { BehaviorSubject } from 'rxjs/internal/BehaviorSubject'; * Component for mapping collections to an item */ export class ItemCollectionMapperComponent implements OnInit { + + /** + * A view on the tabset element + * Used to switch tabs programmatically + */ + @ViewChild('tabs') tabs; + /** * The item to map to collections */ @@ -92,14 +99,18 @@ export class ItemCollectionMapperComponent implements OnInit { switchMap((item: Item) => this.itemDataService.getMappedCollections(item.id)) ); + const owningCollectionRD$ = this.itemRD$.pipe( + switchMap((itemRD: RemoteData) => itemRD.payload.owningCollection) + ); const itemCollectionsAndOptions$ = observableCombineLatest( this.itemCollectionsRD$, + owningCollectionRD$, this.searchOptions$ ); this.mappedCollectionsRD$ = itemCollectionsAndOptions$.pipe( - switchMap(([itemCollectionsRD, searchOptions]) => { + switchMap(([itemCollectionsRD, owningCollectionRD, searchOptions]) => { return this.searchService.search(Object.assign(new PaginatedSearchOptions(searchOptions), { - query: this.buildQuery(itemCollectionsRD.payload.page, searchOptions.query), + query: this.buildQuery([...itemCollectionsRD.payload.page, owningCollectionRD.payload], searchOptions.query), dsoType: DSpaceObjectType.COLLECTION })); }), @@ -190,8 +201,9 @@ export class ItemCollectionMapperComponent implements OnInit { this.notificationsService.error(head, content); }); } - // Force an update on all lists + // Force an update on all lists and switch back to the first tab this.shouldUpdate$.next(true); + this.switchToFirstTab(); }); } @@ -251,4 +263,11 @@ export class ItemCollectionMapperComponent implements OnInit { } } + /** + * Switch the view to focus on the first tab + */ + switchToFirstTab() { + this.tabs.select('browseTab'); + } + } diff --git a/src/app/shared/object-select/collection-select/collection-select.component.html b/src/app/shared/object-select/collection-select/collection-select.component.html index 5a1c98fcf5..e7c20d268c 100644 --- a/src/app/shared/object-select/collection-select/collection-select.component.html +++ b/src/app/shared/object-select/collection-select/collection-select.component.html @@ -1,6 +1,6 @@