62589: Exclude owning collection + redirect to first tab after mapping + page reload fix

This commit is contained in:
Kristof De Langhe
2019-09-10 16:29:15 +02:00
parent 7fe0db7d7c
commit 02b007a0f6
5 changed files with 46 additions and 13 deletions

View File

@@ -5,8 +5,8 @@
<p [innerHTML]="'collection.item-mapper.collection' | translate:{ name: (collectionRD$ | async)?.payload?.name }" id="collection-name"></p> <p [innerHTML]="'collection.item-mapper.collection' | translate:{ name: (collectionRD$ | async)?.payload?.name }" id="collection-name"></p>
<p>{{'collection.item-mapper.description' | translate}}</p> <p>{{'collection.item-mapper.description' | translate}}</p>
<ngb-tabset (tabChange)="tabChange($event)" [destroyOnHide]="true"> <ngb-tabset (tabChange)="tabChange($event)" [destroyOnHide]="true" #tabs="ngbTabset">
<ngb-tab title="{{'collection.item-mapper.tabs.browse' | translate}}"> <ngb-tab title="{{'collection.item-mapper.tabs.browse' | translate}}" id="browseTab">
<ng-template ngbTabContent> <ng-template ngbTabContent>
<div class="mt-2"> <div class="mt-2">
<ds-item-select class="mt-2" <ds-item-select class="mt-2"
@@ -19,7 +19,7 @@
</div> </div>
</ng-template> </ng-template>
</ngb-tab> </ngb-tab>
<ngb-tab title="{{'collection.item-mapper.tabs.map' | translate}}"> <ngb-tab title="{{'collection.item-mapper.tabs.map' | translate}}" id="mapTab">
<ng-template ngbTabContent> <ng-template ngbTabContent>
<div class="row mt-2"> <div class="row mt-2">
<div class="col-12 col-lg-6"> <div class="col-12 col-lg-6">

View File

@@ -1,6 +1,6 @@
import { combineLatest as observableCombineLatest, Observable } from 'rxjs'; 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 { fadeIn, fadeInOut } from '../../shared/animations/fade';
import { ActivatedRoute, Router } from '@angular/router'; import { ActivatedRoute, Router } from '@angular/router';
import { RemoteData } from '../../core/data/remote-data'; 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 { 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 * The collection to map items to
*/ */
@@ -180,8 +186,9 @@ export class CollectionItemMapperComponent implements OnInit {
this.notificationsService.error(head, content); 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.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');
}
} }

View File

@@ -5,8 +5,8 @@
<p [innerHTML]="'item.edit.item-mapper.item' | translate:{ name: (itemRD$ | async)?.payload?.name }" id="item-name"></p> <p [innerHTML]="'item.edit.item-mapper.item' | translate:{ name: (itemRD$ | async)?.payload?.name }" id="item-name"></p>
<p>{{'item.edit.item-mapper.description' | translate}}</p> <p>{{'item.edit.item-mapper.description' | translate}}</p>
<ngb-tabset (tabChange)="tabChange($event)" [destroyOnHide]="true"> <ngb-tabset (tabChange)="tabChange($event)" [destroyOnHide]="true" #tabs="ngbTabset">
<ngb-tab title="{{'item.edit.item-mapper.tabs.browse' | translate}}"> <ngb-tab title="{{'item.edit.item-mapper.tabs.browse' | translate}}" id="browseTab">
<ng-template ngbTabContent> <ng-template ngbTabContent>
<div class="mt-2"> <div class="mt-2">
<ds-collection-select class="mt-2" <ds-collection-select class="mt-2"
@@ -18,7 +18,7 @@
</div> </div>
</ng-template> </ng-template>
</ngb-tab> </ngb-tab>
<ngb-tab title="{{'item.edit.item-mapper.tabs.map' | translate}}"> <ngb-tab title="{{'item.edit.item-mapper.tabs.map' | translate}}" id="mapTab">
<ng-template ngbTabContent> <ng-template ngbTabContent>
<div class="row mt-2"> <div class="row mt-2">
<div class="col-12 col-lg-6"> <div class="col-12 col-lg-6">

View File

@@ -1,6 +1,6 @@
import { combineLatest as observableCombineLatest, Observable } from 'rxjs'; 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 { fadeIn, fadeInOut } from '../../../shared/animations/fade';
import { PaginatedSearchOptions } from '../../../+search-page/paginated-search-options.model'; import { PaginatedSearchOptions } from '../../../+search-page/paginated-search-options.model';
import { RemoteData } from '../../../core/data/remote-data'; import { RemoteData } from '../../../core/data/remote-data';
@@ -34,6 +34,13 @@ import { BehaviorSubject } from 'rxjs/internal/BehaviorSubject';
* Component for mapping collections to an item * Component for mapping collections to an item
*/ */
export class ItemCollectionMapperComponent implements OnInit { 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 * The item to map to collections
*/ */
@@ -92,14 +99,18 @@ export class ItemCollectionMapperComponent implements OnInit {
switchMap((item: Item) => this.itemDataService.getMappedCollections(item.id)) switchMap((item: Item) => this.itemDataService.getMappedCollections(item.id))
); );
const owningCollectionRD$ = this.itemRD$.pipe(
switchMap((itemRD: RemoteData<Item>) => itemRD.payload.owningCollection)
);
const itemCollectionsAndOptions$ = observableCombineLatest( const itemCollectionsAndOptions$ = observableCombineLatest(
this.itemCollectionsRD$, this.itemCollectionsRD$,
owningCollectionRD$,
this.searchOptions$ this.searchOptions$
); );
this.mappedCollectionsRD$ = itemCollectionsAndOptions$.pipe( this.mappedCollectionsRD$ = itemCollectionsAndOptions$.pipe(
switchMap(([itemCollectionsRD, searchOptions]) => { switchMap(([itemCollectionsRD, owningCollectionRD, searchOptions]) => {
return this.searchService.search(Object.assign(new PaginatedSearchOptions(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 dsoType: DSpaceObjectType.COLLECTION
})); }));
}), }),
@@ -190,8 +201,9 @@ export class ItemCollectionMapperComponent implements OnInit {
this.notificationsService.error(head, content); 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.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');
}
} }

View File

@@ -1,6 +1,6 @@
<ng-container *ngVar="(dsoRD$ | async) as collectionsRD"> <ng-container *ngVar="(dsoRD$ | async) as collectionsRD">
<ds-pagination <ds-pagination
*ngIf="collectionsRD?.payload?.totalElements > 0" *ngIf="collectionsRD?.payload?.totalElements > 0 || collectionsRD?.payload?.page?.length > 0"
[paginationOptions]="paginationOptions" [paginationOptions]="paginationOptions"
[sortOptions]="sortOptions" [sortOptions]="sortOptions"
[pageInfoState]="collectionsRD?.payload" [pageInfoState]="collectionsRD?.payload"