mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-08 10:34:15 +00:00
59695: Refactored getFirstItemFor
This commit is contained in:
@@ -39,7 +39,7 @@ describe('BrowseByDatePageComponent', () => {
|
|||||||
const mockBrowseService = {
|
const mockBrowseService = {
|
||||||
getBrowseEntriesFor: (options: BrowseEntrySearchOptions) => toRemoteData([]),
|
getBrowseEntriesFor: (options: BrowseEntrySearchOptions) => toRemoteData([]),
|
||||||
getBrowseItemsFor: (value: string, options: BrowseEntrySearchOptions) => toRemoteData([firstItem]),
|
getBrowseItemsFor: (value: string, options: BrowseEntrySearchOptions) => toRemoteData([firstItem]),
|
||||||
getFirstItemFor: () => toRemoteData([firstItem])
|
getFirstItemFor: () => observableOf(new RemoteData(false, false, true, undefined, firstItem))
|
||||||
};
|
};
|
||||||
|
|
||||||
const mockDsoService = {
|
const mockDsoService = {
|
||||||
|
@@ -75,10 +75,10 @@ export class BrowseByDatePageComponent extends BrowseByMetadataPageComponent {
|
|||||||
*/
|
*/
|
||||||
updateStartsWithOptions(definition: string, metadataField: string, scope?: string) {
|
updateStartsWithOptions(definition: string, metadataField: string, scope?: string) {
|
||||||
this.subs.push(
|
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;
|
let lowerLimit = this.config.browseBy.defaultLowerLimit;
|
||||||
if (firstItemRD.payload.page.length > 0) {
|
if (hasValue(firstItemRD.payload)) {
|
||||||
const date = firstItemRD.payload.page[0].findMetadata(metadataField);
|
const date = firstItemRD.payload.findMetadata(metadataField);
|
||||||
if (hasValue(date) && hasValue(+date.split('-')[0])) {
|
if (hasValue(date) && hasValue(+date.split('-')[0])) {
|
||||||
lowerLimit = +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 { HALEndpointService } from '../shared/hal-endpoint.service';
|
||||||
import {
|
import {
|
||||||
configureRequest,
|
configureRequest,
|
||||||
filterSuccessfulResponses, getBrowseDefinitionLinks,
|
filterSuccessfulResponses, getBrowseDefinitionLinks, getFirstOccurrence,
|
||||||
getRemoteDataPayload,
|
getRemoteDataPayload,
|
||||||
getRequestFromSelflink,
|
getRequestFromSelflink,
|
||||||
getResponseFromSelflink
|
getResponseFromSelflink
|
||||||
@@ -170,7 +170,7 @@ export class BrowseService {
|
|||||||
* @param definition
|
* @param definition
|
||||||
* @param scope
|
* @param scope
|
||||||
*/
|
*/
|
||||||
getFirstItemFor(definition: string, scope?: string): Observable<RemoteData<PaginatedList<Item>>> {
|
getFirstItemFor(definition: string, scope?: string): Observable<RemoteData<Item>> {
|
||||||
return this.getBrowseDefinitions().pipe(
|
return this.getBrowseDefinitions().pipe(
|
||||||
getBrowseDefinitionLinks(definition),
|
getBrowseDefinitionLinks(definition),
|
||||||
hasValueOperator(),
|
hasValueOperator(),
|
||||||
@@ -188,7 +188,8 @@ export class BrowseService {
|
|||||||
}
|
}
|
||||||
return href;
|
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