mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-08 02:24:11 +00:00
add findByParent method to ComColDataService
This commit is contained in:

committed by
Marie Verdonck

parent
aed4db6289
commit
adfe881a81
@@ -1,6 +1,6 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
|
||||||
import { distinctUntilChanged, filter, map, take } from 'rxjs/operators';
|
import { distinctUntilChanged, filter, map, switchMap, take } from 'rxjs/operators';
|
||||||
import { Store } from '@ngrx/store';
|
import { Store } from '@ngrx/store';
|
||||||
|
|
||||||
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
|
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
|
||||||
@@ -136,4 +136,10 @@ export class CollectionDataService extends ComColDataService<Collection> {
|
|||||||
return this.rdbService.buildList(href$);
|
return this.rdbService.buildList(href$);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected getFindByParentHref(parentUUID: string): Observable<string> {
|
||||||
|
return this.halService.getEndpoint('communities').pipe(
|
||||||
|
switchMap((communityEndpointHref: string) =>
|
||||||
|
this.halService.getEndpoint('collections', `${communityEndpointHref}/${parentUUID}`)),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,15 @@
|
|||||||
import { distinctUntilChanged, filter, map, mergeMap, share, take, tap } from 'rxjs/operators';
|
import {
|
||||||
|
distinctUntilChanged,
|
||||||
|
filter, first,
|
||||||
|
map,
|
||||||
|
mergeMap,
|
||||||
|
share,
|
||||||
|
switchMap,
|
||||||
|
take,
|
||||||
|
tap
|
||||||
|
} from 'rxjs/operators';
|
||||||
import { merge as observableMerge, Observable, throwError as observableThrowError } from 'rxjs';
|
import { merge as observableMerge, Observable, throwError as observableThrowError } from 'rxjs';
|
||||||
import { isEmpty, isNotEmpty } from '../../shared/empty.util';
|
import { hasValue, isEmpty, isNotEmpty } from '../../shared/empty.util';
|
||||||
import { NormalizedCommunity } from '../cache/models/normalized-community.model';
|
import { NormalizedCommunity } from '../cache/models/normalized-community.model';
|
||||||
import { ObjectCacheService } from '../cache/object-cache.service';
|
import { ObjectCacheService } from '../cache/object-cache.service';
|
||||||
import { CommunityDataService } from './community-data.service';
|
import { CommunityDataService } from './community-data.service';
|
||||||
@@ -60,7 +69,11 @@ export abstract class ComColDataService<T extends CacheableObject> extends DataS
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public findByParentCommunity(parentUUID: string): Observable<RemoteData<PaginatedList<T>>> {
|
protected abstract getFindByParentHref(parentUUID: string): Observable<string>;
|
||||||
this.halService.getEndpoint(`communities/${parentUUID}/collections`)
|
|
||||||
|
public findByParent(parentUUID: string, options: FindListOptions = {}): Observable<RemoteData<PaginatedList<T>>> {
|
||||||
|
const href$ = this.buildHrefFromFindOptions(this.getFindByParentHref(parentUUID), [], options);
|
||||||
|
return this.findList(href$, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { filter, take } from 'rxjs/operators';
|
import { filter, switchMap, take } from 'rxjs/operators';
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
|
||||||
import { Store } from '@ngrx/store';
|
import { Store } from '@ngrx/store';
|
||||||
@@ -9,7 +9,7 @@ import { Community } from '../shared/community.model';
|
|||||||
import { ComColDataService } from './comcol-data.service';
|
import { ComColDataService } from './comcol-data.service';
|
||||||
import { RequestService } from './request.service';
|
import { RequestService } from './request.service';
|
||||||
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
||||||
import { FindListOptions, FindAllRequest } from './request.models';
|
import { FindListOptions, FindListRequest } from './request.models';
|
||||||
import { RemoteData } from './remote-data';
|
import { RemoteData } from './remote-data';
|
||||||
import { hasValue } from '../../shared/empty.util';
|
import { hasValue } from '../../shared/empty.util';
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
@@ -50,7 +50,7 @@ export class CommunityDataService extends ComColDataService<Community> {
|
|||||||
filter((href: string) => hasValue(href)),
|
filter((href: string) => hasValue(href)),
|
||||||
take(1))
|
take(1))
|
||||||
.subscribe((href: string) => {
|
.subscribe((href: string) => {
|
||||||
const request = new FindAllRequest(this.requestService.generateRequestId(), href, options);
|
const request = new FindListRequest(this.requestService.generateRequestId(), href, options);
|
||||||
this.requestService.configure(request);
|
this.requestService.configure(request);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -64,10 +64,18 @@ export class CommunityDataService extends ComColDataService<Community> {
|
|||||||
filter((href: string) => hasValue(href)),
|
filter((href: string) => hasValue(href)),
|
||||||
take(1))
|
take(1))
|
||||||
.subscribe((href: string) => {
|
.subscribe((href: string) => {
|
||||||
const request = new FindAllRequest(this.requestService.generateRequestId(), href, options);
|
const request = new FindListRequest(this.requestService.generateRequestId(), href, options);
|
||||||
this.requestService.configure(request);
|
this.requestService.configure(request);
|
||||||
});
|
});
|
||||||
|
|
||||||
return this.rdbService.buildList<Community>(hrefObs) as Observable<RemoteData<PaginatedList<Community>>>;
|
return this.rdbService.buildList<Community>(hrefObs) as Observable<RemoteData<PaginatedList<Community>>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected getFindByParentHref(parentUUID: string): Observable<string> {
|
||||||
|
return this.halService.getEndpoint(this.linkPath).pipe(
|
||||||
|
switchMap((communityEndpointHref: string) =>
|
||||||
|
this.halService.getEndpoint('subcommunities', `${communityEndpointHref}/${parentUUID}`))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -15,7 +15,7 @@ import {
|
|||||||
CreateRequest,
|
CreateRequest,
|
||||||
DeleteByIDRequest,
|
DeleteByIDRequest,
|
||||||
FindListOptions,
|
FindListOptions,
|
||||||
FindAllRequest,
|
FindListRequest,
|
||||||
FindByIDRequest,
|
FindByIDRequest,
|
||||||
GetRequest
|
GetRequest
|
||||||
} from './request.models';
|
} from './request.models';
|
||||||
@@ -133,7 +133,7 @@ export abstract class DataService<T extends CacheableObject> {
|
|||||||
hrefObs.pipe(
|
hrefObs.pipe(
|
||||||
first((href: string) => hasValue(href)))
|
first((href: string) => hasValue(href)))
|
||||||
.subscribe((href: string) => {
|
.subscribe((href: string) => {
|
||||||
const request = new FindAllRequest(this.requestService.generateRequestId(), href, options);
|
const request = new FindListRequest(this.requestService.generateRequestId(), href, options);
|
||||||
if (hasValue(this.responseMsToLive)) {
|
if (hasValue(this.responseMsToLive)) {
|
||||||
request.responseMsToLive = this.responseMsToLive;
|
request.responseMsToLive = this.responseMsToLive;
|
||||||
}
|
}
|
||||||
@@ -191,7 +191,7 @@ export abstract class DataService<T extends CacheableObject> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make a new FindAllRequest with given search method
|
* Make a new FindListRequest with given search method
|
||||||
*
|
*
|
||||||
* @param searchMethod The search method for the object
|
* @param searchMethod The search method for the object
|
||||||
* @param options The [[FindListOptions]] object
|
* @param options The [[FindListOptions]] object
|
||||||
@@ -205,7 +205,7 @@ export abstract class DataService<T extends CacheableObject> {
|
|||||||
hrefObs.pipe(
|
hrefObs.pipe(
|
||||||
first((href: string) => hasValue(href)))
|
first((href: string) => hasValue(href)))
|
||||||
.subscribe((href: string) => {
|
.subscribe((href: string) => {
|
||||||
const request = new FindAllRequest(this.requestService.generateRequestId(), href, options);
|
const request = new FindListRequest(this.requestService.generateRequestId(), href, options);
|
||||||
request.responseMsToLive = 10 * 1000;
|
request.responseMsToLive = 10 * 1000;
|
||||||
this.requestService.configure(request);
|
this.requestService.configure(request);
|
||||||
});
|
});
|
||||||
|
@@ -147,7 +147,7 @@ export class FindListOptions {
|
|||||||
startsWith?: string;
|
startsWith?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class FindAllRequest extends GetRequest {
|
export class FindListRequest extends GetRequest {
|
||||||
constructor(
|
constructor(
|
||||||
uuid: string,
|
uuid: string,
|
||||||
href: string,
|
href: string,
|
||||||
|
Reference in New Issue
Block a user