forked from hazza/dspace-angular
55693: Intermediate Commit
This commit is contained in:
@@ -16,6 +16,8 @@ import { DSpaceObject } from '../../core/shared/dspace-object.model';
|
||||
import { DSpaceObjectType } from '../../core/shared/dspace-object-type.model';
|
||||
import { SortDirection, SortOptions } from '../../core/cache/models/sort-options.model';
|
||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||
import { ItemDataService } from '../../core/data/item-data.service';
|
||||
import { forkJoin } from 'rxjs/observable/forkJoin';
|
||||
|
||||
@Component({
|
||||
selector: 'ds-collection-item-mapper',
|
||||
@@ -40,7 +42,8 @@ export class CollectionItemMapperComponent implements OnInit {
|
||||
private router: Router,
|
||||
private searchConfigService: SearchConfigurationService,
|
||||
private searchService: SearchService,
|
||||
private notificationsService: NotificationsService) {
|
||||
private notificationsService: NotificationsService,
|
||||
private itemDataService: ItemDataService) {
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
@@ -72,6 +75,13 @@ export class CollectionItemMapperComponent implements OnInit {
|
||||
}
|
||||
|
||||
mapItems(ids: string[]) {
|
||||
const responses = this.collectionRD$.pipe(
|
||||
map((collectionRD: RemoteData<Collection>) => collectionRD.payload),
|
||||
flatMap((collection: Collection) => forkJoin(ids.map((id: string) => this.itemDataService.mapToCollection(id, collection.id))))
|
||||
);
|
||||
|
||||
responses.subscribe((value) => console.log(value));
|
||||
|
||||
this.collectionRD$.subscribe((collectionRD: RemoteData<Collection>) => {
|
||||
this.notificationsService.success('Mapping completed', `Successfully mapped ${ids.length} items to collection "${collectionRD.payload.name}".`);
|
||||
});
|
||||
|
@@ -3,7 +3,7 @@ import { Inject, Injectable } from '@angular/core';
|
||||
import { Store } from '@ngrx/store';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import { GLOBAL_CONFIG, GlobalConfig } from '../../../config';
|
||||
import { isEmpty, isNotEmpty } from '../../shared/empty.util';
|
||||
import { isEmpty, isNotEmpty, isNotEmptyOperator } from '../../shared/empty.util';
|
||||
import { BrowseService } from '../browse/browse.service';
|
||||
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
|
||||
import { NormalizedItem } from '../cache/models/normalized-item.model';
|
||||
@@ -15,7 +15,11 @@ import { URLCombiner } from '../url-combiner/url-combiner';
|
||||
import { DataService } from './data.service';
|
||||
import { RequestService } from './request.service';
|
||||
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
||||
import { FindAllOptions } from './request.models';
|
||||
import { FindAllOptions, PostRequest, RestRequest } from './request.models';
|
||||
import { distinctUntilChanged, map } from 'rxjs/operators';
|
||||
import { configureRequest, getResponseFromSelflink } from '../shared/operators';
|
||||
import { ResponseCacheEntry } from '../cache/response-cache.reducer';
|
||||
import { RestResponse } from '../cache/response-cache.models';
|
||||
|
||||
@Injectable()
|
||||
export class ItemDataService extends DataService<NormalizedItem, Item> {
|
||||
@@ -48,4 +52,26 @@ export class ItemDataService extends DataService<NormalizedItem, Item> {
|
||||
.distinctUntilChanged();
|
||||
}
|
||||
|
||||
public getMappingCollectionsEndpoint(itemId: string, collectionId?: string): Observable<string> {
|
||||
return this.halService.getEndpoint(this.linkPath).pipe(
|
||||
map((endpoint: string) => this.getFindByIDHref(endpoint, itemId)),
|
||||
map((endpoint: string) => `${endpoint}/mappingCollections${collectionId ? `/${collectionId}` : ''}`)
|
||||
);
|
||||
}
|
||||
|
||||
public mapToCollection(itemId: string, collectionId: string): Observable<RestResponse> {
|
||||
const request$ = this.getMappingCollectionsEndpoint(itemId, collectionId).pipe(
|
||||
isNotEmptyOperator(),
|
||||
distinctUntilChanged(),
|
||||
map((endpointURL: string) => new PostRequest(this.requestService.generateRequestId(), endpointURL)),
|
||||
configureRequest(this.requestService)
|
||||
);
|
||||
|
||||
return request$.pipe(
|
||||
map((request: RestRequest) => request.href),
|
||||
getResponseFromSelflink(this.responseCache),
|
||||
map((responseCacheEntry: ResponseCacheEntry) => responseCacheEntry.response)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user