mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-10 19:43:04 +00:00
59695: Refactored getFirstItemFor
This commit is contained in:
@@ -39,7 +39,7 @@ describe('BrowseByDatePageComponent', () => {
|
||||
const mockBrowseService = {
|
||||
getBrowseEntriesFor: (options: BrowseEntrySearchOptions) => toRemoteData([]),
|
||||
getBrowseItemsFor: (value: string, options: BrowseEntrySearchOptions) => toRemoteData([firstItem]),
|
||||
getFirstItemFor: () => toRemoteData([firstItem])
|
||||
getFirstItemFor: () => observableOf(new RemoteData(false, false, true, undefined, firstItem))
|
||||
};
|
||||
|
||||
const mockDsoService = {
|
||||
|
@@ -75,10 +75,10 @@ export class BrowseByDatePageComponent extends BrowseByMetadataPageComponent {
|
||||
*/
|
||||
updateStartsWithOptions(definition: string, metadataField: string, scope?: string) {
|
||||
this.subs.push(
|
||||
this.browseService.getFirstItemFor(definition, scope).subscribe((firstItemRD: RemoteData<PaginatedList<Item>>) => {
|
||||
this.browseService.getFirstItemFor(definition, scope).subscribe((firstItemRD: RemoteData<Item>) => {
|
||||
let lowerLimit = this.config.browseBy.defaultLowerLimit;
|
||||
if (firstItemRD.payload.page.length > 0) {
|
||||
const date = firstItemRD.payload.page[0].findMetadata(metadataField);
|
||||
if (hasValue(firstItemRD.payload)) {
|
||||
const date = firstItemRD.payload.findMetadata(metadataField);
|
||||
if (hasValue(date) && hasValue(+date.split('-')[0])) {
|
||||
lowerLimit = +date.split('-')[0];
|
||||
}
|
||||
|
@@ -26,7 +26,7 @@ import { BrowseEntry } from '../shared/browse-entry.model';
|
||||
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
||||
import {
|
||||
configureRequest,
|
||||
filterSuccessfulResponses, getBrowseDefinitionLinks,
|
||||
filterSuccessfulResponses, getBrowseDefinitionLinks, getFirstOccurrence,
|
||||
getRemoteDataPayload,
|
||||
getRequestFromSelflink,
|
||||
getResponseFromSelflink
|
||||
@@ -170,7 +170,7 @@ export class BrowseService {
|
||||
* @param definition
|
||||
* @param scope
|
||||
*/
|
||||
getFirstItemFor(definition: string, scope?: string): Observable<RemoteData<PaginatedList<Item>>> {
|
||||
getFirstItemFor(definition: string, scope?: string): Observable<RemoteData<Item>> {
|
||||
return this.getBrowseDefinitions().pipe(
|
||||
getBrowseDefinitionLinks(definition),
|
||||
hasValueOperator(),
|
||||
@@ -188,7 +188,8 @@ export class BrowseService {
|
||||
}
|
||||
return href;
|
||||
}),
|
||||
getBrowseItemsFor(this.requestService, this.responseCache, this.rdb)
|
||||
getBrowseItemsFor(this.requestService, this.responseCache, this.rdb),
|
||||
getFirstOccurrence()
|
||||
);
|
||||
}
|
||||
|
||||
|
@@ -88,3 +88,12 @@ export const getBrowseDefinitionLinks = (definitionID: string) =>
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
/**
|
||||
* Get the first occurrence of an object within a paginated list
|
||||
*/
|
||||
export const getFirstOccurrence = () =>
|
||||
<T extends DSpaceObject>(source: Observable<RemoteData<PaginatedList<T>>>): Observable<RemoteData<T>> =>
|
||||
source.pipe(
|
||||
map((rd) => Object.assign(rd, { payload: rd.payload.page.length > 0 ? rd.payload.page[0] : undefined }))
|
||||
);
|
||||
|
Reference in New Issue
Block a user