62589: Provider and POST item-collection mapping fix

This commit is contained in:
Kristof De Langhe
2019-05-29 11:44:34 +02:00
parent 28fe62f918
commit df730efbd0
3 changed files with 28 additions and 12 deletions

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, Inject, OnInit } 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';
@@ -21,6 +21,7 @@ import { CollectionDataService } from '../../core/data/collection-data.service';
import { isNotEmpty } from '../../shared/empty.util'; import { isNotEmpty } from '../../shared/empty.util';
import { RestResponse } from '../../core/cache/response.models'; import { RestResponse } from '../../core/cache/response.models';
import { BehaviorSubject } from 'rxjs/internal/BehaviorSubject'; import { BehaviorSubject } from 'rxjs/internal/BehaviorSubject';
import { SEARCH_CONFIG_SERVICE } from '../../+my-dspace-page/my-dspace-page.component';
@Component({ @Component({
selector: 'ds-collection-item-mapper', selector: 'ds-collection-item-mapper',
@@ -30,6 +31,12 @@ import { BehaviorSubject } from 'rxjs/internal/BehaviorSubject';
animations: [ animations: [
fadeIn, fadeIn,
fadeInOut fadeInOut
],
providers: [
{
provide: SEARCH_CONFIG_SERVICE,
useClass: SearchConfigurationService
}
] ]
}) })
/** /**
@@ -73,7 +80,7 @@ export class CollectionItemMapperComponent implements OnInit {
constructor(private route: ActivatedRoute, constructor(private route: ActivatedRoute,
private router: Router, private router: Router,
private searchConfigService: SearchConfigurationService, @Inject(SEARCH_CONFIG_SERVICE) private searchConfigService: SearchConfigurationService,
private searchService: SearchService, private searchService: SearchService,
private notificationsService: NotificationsService, private notificationsService: NotificationsService,
private itemDataService: ItemDataService, private itemDataService: ItemDataService,
@@ -130,10 +137,10 @@ export class CollectionItemMapperComponent implements OnInit {
mapItems(ids: string[], remove?: boolean) { mapItems(ids: string[], remove?: boolean) {
const responses$ = this.collectionRD$.pipe( const responses$ = this.collectionRD$.pipe(
getSucceededRemoteData(), getSucceededRemoteData(),
map((collectionRD: RemoteData<Collection>) => collectionRD.payload.id), map((collectionRD: RemoteData<Collection>) => collectionRD.payload),
switchMap((collectionId: string) => switchMap((collection: Collection) =>
observableCombineLatest(ids.map((id: string) => observableCombineLatest(ids.map((id: string) =>
remove ? this.itemDataService.removeMappingFromCollection(id, collectionId) : this.itemDataService.mapToCollection(id, collectionId) remove ? this.itemDataService.removeMappingFromCollection(id, collection.id) : this.itemDataService.mapToCollection(id, collection.self)
)) ))
) )
); );

View File

@@ -11,6 +11,7 @@ import { EditCollectionPageComponent } from './edit-collection-page/edit-collect
import { DeleteCollectionPageComponent } from './delete-collection-page/delete-collection-page.component'; import { DeleteCollectionPageComponent } from './delete-collection-page/delete-collection-page.component';
import { SearchService } from '../+search-page/search-service/search.service'; import { SearchService } from '../+search-page/search-service/search.service';
import { CollectionItemMapperComponent } from './collection-item-mapper/collection-item-mapper.component'; import { CollectionItemMapperComponent } from './collection-item-mapper/collection-item-mapper.component';
import { SearchFixedFilterService } from '../+search-page/search-filters/search-filter/search-fixed-filter.service';
@NgModule({ @NgModule({
imports: [ imports: [
@@ -27,7 +28,8 @@ import { CollectionItemMapperComponent } from './collection-item-mapper/collecti
CollectionItemMapperComponent CollectionItemMapperComponent
], ],
providers: [ providers: [
SearchService SearchService,
SearchFixedFilterService
] ]
}) })
export class CollectionPageModule { export class CollectionPageModule {

View File

@@ -23,7 +23,7 @@ import {
import { ObjectCacheService } from '../cache/object-cache.service'; import { ObjectCacheService } from '../cache/object-cache.service';
import { NotificationsService } from '../../shared/notifications/notifications.service'; import { NotificationsService } from '../../shared/notifications/notifications.service';
import { DSOChangeAnalyzer } from './dso-change-analyzer.service'; import { DSOChangeAnalyzer } from './dso-change-analyzer.service';
import { HttpClient } from '@angular/common/http'; import { HttpClient, HttpHeaders } from '@angular/common/http';
import { NormalizedObjectBuildService } from '../cache/builders/normalized-object-build.service'; import { NormalizedObjectBuildService } from '../cache/builders/normalized-object-build.service';
import { import {
configureRequest, configureRequest,
@@ -36,6 +36,7 @@ import { GenericSuccessResponse, RestResponse } from '../cache/response.models';
import { RemoteData } from './remote-data'; import { RemoteData } from './remote-data';
import { PaginatedList } from './paginated-list'; import { PaginatedList } from './paginated-list';
import { Collection } from '../shared/collection.model'; import { Collection } from '../shared/collection.model';
import { HttpOptions } from '../dspace-rest-v2/dspace-rest-v2.service';
@Injectable() @Injectable()
export class ItemDataService extends DataService<Item> { export class ItemDataService extends DataService<Item> {
@@ -104,14 +105,20 @@ export class ItemDataService extends DataService<Item> {
/** /**
* Maps an item to a collection * Maps an item to a collection
* @param itemId The item's id * @param itemId The item's id
* @param collectionId The collection's id * @param collectionHref The collection's self link
*/ */
public mapToCollection(itemId: string, collectionId: string): Observable<RestResponse> { public mapToCollection(itemId: string, collectionHref: string): Observable<RestResponse> {
return this.getMappingCollectionsEndpoint(itemId, collectionId).pipe( return this.getMappingCollectionsEndpoint(itemId).pipe(
isNotEmptyOperator(), isNotEmptyOperator(),
distinctUntilChanged(), distinctUntilChanged(),
map((endpointURL: string) => new PostRequest(this.requestService.generateRequestId(), endpointURL)), map((endpointURL: string) => {
const options: HttpOptions = Object.create({});
let headers = new HttpHeaders();
headers = headers.append('Content-Type', 'text/uri-list');
options.headers = headers;
return new PostRequest(this.requestService.generateRequestId(), endpointURL, collectionHref, options);
}),
configureRequest(this.requestService), configureRequest(this.requestService),
switchMap((request: RestRequest) => this.requestService.getByUUID(request.uuid)), switchMap((request: RestRequest) => this.requestService.getByUUID(request.uuid)),
getResponseFromEntry() getResponseFromEntry()