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

View File

@@ -23,7 +23,7 @@ import {
import { ObjectCacheService } from '../cache/object-cache.service';
import { NotificationsService } from '../../shared/notifications/notifications.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 {
configureRequest,
@@ -36,6 +36,7 @@ import { GenericSuccessResponse, RestResponse } from '../cache/response.models';
import { RemoteData } from './remote-data';
import { PaginatedList } from './paginated-list';
import { Collection } from '../shared/collection.model';
import { HttpOptions } from '../dspace-rest-v2/dspace-rest-v2.service';
@Injectable()
export class ItemDataService extends DataService<Item> {
@@ -104,14 +105,20 @@ export class ItemDataService extends DataService<Item> {
/**
* Maps an item to a collection
* @param itemId The item's id
* @param collectionId The collection's id
* @param itemId The item's id
* @param collectionHref The collection's self link
*/
public mapToCollection(itemId: string, collectionId: string): Observable<RestResponse> {
return this.getMappingCollectionsEndpoint(itemId, collectionId).pipe(
public mapToCollection(itemId: string, collectionHref: string): Observable<RestResponse> {
return this.getMappingCollectionsEndpoint(itemId).pipe(
isNotEmptyOperator(),
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),
switchMap((request: RestRequest) => this.requestService.getByUUID(request.uuid)),
getResponseFromEntry()