75413: collection/item mapper pages as tab in edit pages

This commit is contained in:
Marie Verdonck
2021-01-07 14:10:31 +01:00
parent 17e8881380
commit dbfab94a47
8 changed files with 67 additions and 18 deletions

View File

@@ -2,7 +2,7 @@
<div class="row"> <div class="row">
<div class="col-12"> <div class="col-12">
<h2>{{'collection.edit.item-mapper.head' | translate}}</h2> <h2>{{'collection.edit.item-mapper.head' | translate}}</h2>
<p [innerHTML]="'collection.edit.item-mapper.collection' | translate:{ name: (collectionRD$ | async)?.payload?.name }" id="collection-name"></p> <p [innerHTML]="'collection.edit.item-mapper.collection' | translate:{ name: (collectionName$ |async) }" id="collection-name"></p>
<p>{{'collection.edit.item-mapper.description' | translate}}</p> <p>{{'collection.edit.item-mapper.description' | translate}}</p>
<ngb-tabset (tabChange)="tabChange($event)" [destroyOnHide]="true" #tabs="ngbTabset"> <ngb-tabset (tabChange)="tabChange($event)" [destroyOnHide]="true" #tabs="ngbTabset">

View File

@@ -1,12 +1,13 @@
import { BehaviorSubject, combineLatest as observableCombineLatest, Observable } from 'rxjs'; import { BehaviorSubject, combineLatest as observableCombineLatest, Observable } from 'rxjs';
import { ChangeDetectionStrategy, Component, Inject, OnInit, ViewChild } from '@angular/core'; import { ChangeDetectionStrategy, Component, Inject, OnInit, ViewChild } from '@angular/core';
import { DSONameService } from '../../core/breadcrumbs/dso-name.service';
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';
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 { map, startWith, switchMap, take } from 'rxjs/operators'; import { filter, map, startWith, switchMap, take } from 'rxjs/operators';
import { import {
getRemoteDataPayload, getRemoteDataPayload,
getFirstSucceededRemoteData, getFirstSucceededRemoteData,
@@ -19,7 +20,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 { isNotEmpty } from '../../shared/empty.util'; import { hasValue, 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';
@@ -58,6 +59,7 @@ export class CollectionItemMapperComponent implements OnInit {
* The collection to map items to * The collection to map items to
*/ */
collectionRD$: Observable<RemoteData<Collection>>; collectionRD$: Observable<RemoteData<Collection>>;
collectionName$: Observable<string>;
/** /**
* Search options * Search options
@@ -101,11 +103,22 @@ export class CollectionItemMapperComponent implements OnInit {
private notificationsService: NotificationsService, private notificationsService: NotificationsService,
private itemDataService: ItemDataService, private itemDataService: ItemDataService,
private collectionDataService: CollectionDataService, private collectionDataService: CollectionDataService,
private translateService: TranslateService) { private translateService: TranslateService,
private dsoNameService: DSONameService) {
} }
ngOnInit(): void { ngOnInit(): void {
this.collectionRD$ = this.route.data.pipe(map((data) => data.dso)).pipe(getFirstSucceededRemoteData()) as Observable<RemoteData<Collection>>; this.collectionRD$ = this.route.data.pipe(
take(1),
map((data) => data.dso),
);
this.collectionName$ = this.collectionRD$.pipe(
filter((rd: RemoteData<Collection>) => hasValue(rd)),
map((rd: RemoteData<Collection>) => {
return this.dsoNameService.getName(rd.payload);
})
);
this.searchOptions$ = this.searchConfigService.paginatedSearchOptions; this.searchOptions$ = this.searchConfigService.paginatedSearchOptions;
this.loadItemLists(); this.loadItemLists();
} }

View File

@@ -1,5 +1,6 @@
import { RouterModule } from '@angular/router'; import { RouterModule } from '@angular/router';
import { NgModule } from '@angular/core'; import { NgModule } from '@angular/core';
import { CollectionItemMapperComponent } from '../collection-item-mapper/collection-item-mapper.component';
import { EditCollectionPageComponent } from './edit-collection-page.component'; import { EditCollectionPageComponent } from './edit-collection-page.component';
import { CollectionMetadataComponent } from './collection-metadata/collection-metadata.component'; import { CollectionMetadataComponent } from './collection-metadata/collection-metadata.component';
import { CollectionRolesComponent } from './collection-roles/collection-roles.component'; import { CollectionRolesComponent } from './collection-roles/collection-roles.component';
@@ -86,7 +87,12 @@ import { ResourcePolicyEditComponent } from '../../shared/resource-policies/edit
data: { title: 'collection.edit.tabs.authorizations.title', showBreadcrumbs: true } data: { title: 'collection.edit.tabs.authorizations.title', showBreadcrumbs: true }
} }
] ]
} },
{
path: 'mapper',
component: CollectionItemMapperComponent,
data: { title: 'collection.edit.tabs.item-mapper.title', showBreadcrumbs: true }
},
] ]
} }
]) ])

View File

@@ -90,6 +90,11 @@ import { ItemPageWithdrawGuard } from './item-page-withdraw.guard';
path: 'versionhistory', path: 'versionhistory',
component: ItemVersionHistoryComponent, component: ItemVersionHistoryComponent,
data: { title: 'item.edit.tabs.versionhistory.title', showBreadcrumbs: true } data: { title: 'item.edit.tabs.versionhistory.title', showBreadcrumbs: true }
},
{
path: 'mapper',
component: ItemCollectionMapperComponent,
data: { title: 'item.edit.tabs.item-mapper.title', showBreadcrumbs: true }
} }
] ]
}, },

View File

@@ -2,7 +2,7 @@
<div class="row"> <div class="row">
<div class="col-12"> <div class="col-12">
<h2>{{'item.edit.item-mapper.head' | translate}}</h2> <h2>{{'item.edit.item-mapper.head' | translate}}</h2>
<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: (itemName$ | async) }" 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" #tabs="ngbTabset"> <ngb-tabset (tabChange)="tabChange($event)" [destroyOnHide]="true" #tabs="ngbTabset">

View File

@@ -7,7 +7,7 @@ import { ActivatedRoute, Router } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing'; import { RouterTestingModule } from '@angular/router/testing';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap'; import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { TranslateModule, TranslateService } from '@ngx-translate/core'; import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { of } from 'rxjs'; import { of as observableOf } from 'rxjs/internal/observable/of';
import { SortDirection, SortOptions } from '../../../core/cache/models/sort-options.model'; import { SortDirection, SortOptions } from '../../../core/cache/models/sort-options.model';
import { CollectionDataService } from '../../../core/data/collection-data.service'; import { CollectionDataService } from '../../../core/data/collection-data.service';
import { ItemDataService } from '../../../core/data/item-data.service'; import { ItemDataService } from '../../../core/data/item-data.service';
@@ -26,7 +26,6 @@ import { PaginationComponentOptions } from '../../../shared/pagination/paginatio
import { PaginationComponent } from '../../../shared/pagination/pagination.component'; import { PaginationComponent } from '../../../shared/pagination/pagination.component';
import { SearchFormComponent } from '../../../shared/search-form/search-form.component'; import { SearchFormComponent } from '../../../shared/search-form/search-form.component';
import { PaginatedSearchOptions } from '../../../shared/search/paginated-search-options.model'; import { PaginatedSearchOptions } from '../../../shared/search/paginated-search-options.model';
import { ActivatedRouteStub } from '../../../shared/testing/active-router.stub';
import { HostWindowServiceStub } from '../../../shared/testing/host-window-service.stub'; import { HostWindowServiceStub } from '../../../shared/testing/host-window-service.stub';
import { NotificationsServiceStub } from '../../../shared/testing/notifications-service.stub'; import { NotificationsServiceStub } from '../../../shared/testing/notifications-service.stub';
import { ObjectSelectServiceStub } from '../../../shared/testing/object-select-service.stub'; import { ObjectSelectServiceStub } from '../../../shared/testing/object-select-service.stub';
@@ -59,7 +58,7 @@ describe('ItemCollectionMapperComponent', () => {
name: 'test-item' name: 'test-item'
}); });
const mockItemRD: RemoteData<Item> = createSuccessfulRemoteDataObject(mockItem); const mockItemRD: RemoteData<Item> = createSuccessfulRemoteDataObject(mockItem);
const mockSearchOptions = of(new PaginatedSearchOptions({ const mockSearchOptions = observableOf(new PaginatedSearchOptions({
pagination: Object.assign(new PaginationComponentOptions(), { pagination: Object.assign(new PaginationComponentOptions(), {
id: 'search-page-configuration', id: 'search-page-configuration',
pageSize: 10, pageSize: 10,
@@ -82,7 +81,7 @@ describe('ItemCollectionMapperComponent', () => {
mapToCollection: () => createSuccessfulRemoteDataObject$({}), mapToCollection: () => createSuccessfulRemoteDataObject$({}),
removeMappingFromCollection: () => createSuccessfulRemoteDataObject$({}), removeMappingFromCollection: () => createSuccessfulRemoteDataObject$({}),
getMappedCollectionsEndpoint: () => of('rest/api/mappedCollectionsEndpoint'), getMappedCollectionsEndpoint: () => of('rest/api/mappedCollectionsEndpoint'),
getMappedCollections: () => of(mockCollectionsRD), getMappedCollections: () => observableOf(mockCollectionsRD),
/* tslint:disable:no-empty */ /* tslint:disable:no-empty */
clearMappedCollectionsRequests: () => {} clearMappedCollectionsRequests: () => {}
/* tslint:enable:no-empty */ /* tslint:enable:no-empty */
@@ -91,14 +90,20 @@ describe('ItemCollectionMapperComponent', () => {
findAllByHref: () => of(mockCollectionsRD) findAllByHref: () => of(mockCollectionsRD)
}; };
const searchServiceStub = Object.assign(new SearchServiceStub(), { const searchServiceStub = Object.assign(new SearchServiceStub(), {
search: () => of(mockCollectionsRD), search: () => observableOf(mockCollectionsRD),
/* tslint:disable:no-empty */ /* tslint:disable:no-empty */
clearDiscoveryRequests: () => {} clearDiscoveryRequests: () => {}
/* tslint:enable:no-empty */ /* tslint:enable:no-empty */
}); });
const activatedRouteStub = new ActivatedRouteStub({}, { dso: mockItemRD }); const activatedRouteStub = {
parent: {
data: observableOf({
dso: mockItemRD
})
}
};
const translateServiceStub = { const translateServiceStub = {
get: () => of('test-message of item ' + mockItem.name), get: () => observableOf('test-message of item ' + mockItem.name),
onLangChange: new EventEmitter(), onLangChange: new EventEmitter(),
onTranslationChange: new EventEmitter(), onTranslationChange: new EventEmitter(),
onDefaultLangChange: new EventEmitter() onDefaultLangChange: new EventEmitter()

View File

@@ -1,6 +1,7 @@
import { BehaviorSubject, combineLatest as observableCombineLatest, Observable } from 'rxjs'; import { BehaviorSubject, combineLatest as observableCombineLatest, Observable } from 'rxjs';
import { ChangeDetectionStrategy, Component, OnInit, ViewChild } from '@angular/core'; import { ChangeDetectionStrategy, Component, OnInit, ViewChild } from '@angular/core';
import { DSONameService } from '../../../core/breadcrumbs/dso-name.service';
import { CollectionDataService } from '../../../core/data/collection-data.service'; import { CollectionDataService } from '../../../core/data/collection-data.service';
import { fadeIn, fadeInOut } from '../../../shared/animations/fade'; import { fadeIn, fadeInOut } from '../../../shared/animations/fade';
import { RemoteData } from '../../../core/data/remote-data'; import { RemoteData } from '../../../core/data/remote-data';
@@ -15,12 +16,12 @@ import {
getAllSucceededRemoteData getAllSucceededRemoteData
} from '../../../core/shared/operators'; } from '../../../core/shared/operators';
import { ActivatedRoute, Router } from '@angular/router'; import { ActivatedRoute, Router } from '@angular/router';
import { map, startWith, switchMap, take } from 'rxjs/operators'; import { filter, map, startWith, switchMap, take } from 'rxjs/operators';
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 { NotificationsService } from '../../../shared/notifications/notifications.service'; import { NotificationsService } from '../../../shared/notifications/notifications.service';
import { DSpaceObjectType } from '../../../core/shared/dspace-object-type.model'; import { DSpaceObjectType } from '../../../core/shared/dspace-object-type.model';
import { isNotEmpty } from '../../../shared/empty.util'; import { hasValue, isNotEmpty } from '../../../shared/empty.util';
import { PaginatedSearchOptions } from '../../../shared/search/paginated-search-options.model'; import { PaginatedSearchOptions } from '../../../shared/search/paginated-search-options.model';
import { SearchConfigurationService } from '../../../core/shared/search/search-configuration.service'; import { SearchConfigurationService } from '../../../core/shared/search/search-configuration.service';
import { SearchService } from '../../../core/shared/search/search.service'; import { SearchService } from '../../../core/shared/search/search.service';
@@ -51,6 +52,7 @@ export class ItemCollectionMapperComponent implements OnInit {
* The item to map to collections * The item to map to collections
*/ */
itemRD$: Observable<RemoteData<Item>>; itemRD$: Observable<RemoteData<Item>>;
itemName$: Observable<string>;
/** /**
* Search options * Search options
@@ -88,11 +90,22 @@ export class ItemCollectionMapperComponent implements OnInit {
private notificationsService: NotificationsService, private notificationsService: NotificationsService,
private itemDataService: ItemDataService, private itemDataService: ItemDataService,
private collectionDataService: CollectionDataService, private collectionDataService: CollectionDataService,
private translateService: TranslateService) { private translateService: TranslateService,
private dsoNameService: DSONameService) {
} }
ngOnInit(): void { ngOnInit(): void {
this.itemRD$ = this.route.data.pipe(map((data) => data.dso)).pipe(getFirstSucceededRemoteData()) as Observable<RemoteData<Item>>; this.itemRD$ = this.route.parent.data.pipe(
take(1),
map((data) => data.dso),
);
this.itemName$ = this.itemRD$.pipe(
filter((rd: RemoteData<Item>) => hasValue(rd)),
map((rd: RemoteData<Item>) => {
return this.dsoNameService.getName(rd.payload);
})
);
this.searchOptions$ = this.searchConfigService.paginatedSearchOptions; this.searchOptions$ = this.searchConfigService.paginatedSearchOptions;
this.loadCollectionLists(); this.loadCollectionLists();
} }

View File

@@ -649,6 +649,10 @@
"collection.edit.tabs.mapper.head": "Item Mapper",
"collection.edit.tabs.item-mapper.title": "Collection Edit - Item Mapper",
"collection.edit.item-mapper.cancel": "Cancel", "collection.edit.item-mapper.cancel": "Cancel",
"collection.edit.item-mapper.collection": "Collection: \"<b>{{name}}</b>\"", "collection.edit.item-mapper.collection": "Collection: \"<b>{{name}}</b>\"",
@@ -1462,6 +1466,9 @@
"item.edit.breadcrumbs": "Edit Item", "item.edit.breadcrumbs": "Edit Item",
"item.edit.tabs.mapper.head": "Collection Mapper",
"item.edit.tabs.item-mapper.title": "Item Edit - Collection Mapper",
"item.edit.item-mapper.buttons.add": "Map item to selected collections", "item.edit.item-mapper.buttons.add": "Map item to selected collections",