mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-21 17:12:43 +00:00
fix: daia availability
This commit is contained in:
committed by
Rainer Killinger
parent
b38a96996a
commit
13cee2d426
@@ -14,10 +14,9 @@
|
||||
*/
|
||||
import {Injectable} from '@angular/core';
|
||||
import {
|
||||
SCDaiaAvailabilityResponse,
|
||||
SCDaiaHolding,
|
||||
SCDaiaService,
|
||||
SCDaiaSimpleContent,
|
||||
DaiaAvailabilityResponse,
|
||||
DaiaHolding,
|
||||
DaiaService,
|
||||
} from './protocol/response';
|
||||
import {StorageProvider} from '../storage/storage.provider';
|
||||
import {HttpClient, HttpHeaders} from '@angular/common/http';
|
||||
@@ -73,7 +72,7 @@ export class DaiaDataProvider {
|
||||
);
|
||||
}
|
||||
|
||||
async getAvailability(id: string): Promise<SCDaiaHolding[] | undefined> {
|
||||
async getAvailability(id: string): Promise<DaiaHolding[] | undefined> {
|
||||
if (typeof this.daiaServiceUrl === 'undefined') {
|
||||
try {
|
||||
const features = this.configProvider.getValue(
|
||||
@@ -99,12 +98,12 @@ export class DaiaDataProvider {
|
||||
|
||||
return new Promise(resolve =>
|
||||
this.httpClient
|
||||
.get<SCDaiaAvailabilityResponse>(this.daiaServiceUrl as string, {
|
||||
.get<DaiaAvailabilityResponse>(this.daiaServiceUrl as string, {
|
||||
params: {id, lang: this.translateService.currentLang},
|
||||
})
|
||||
.subscribe(
|
||||
(response: SCDaiaAvailabilityResponse) => {
|
||||
const holdings: SCDaiaHolding[] = [];
|
||||
(response: DaiaAvailabilityResponse) => {
|
||||
const holdings: DaiaHolding[] = [];
|
||||
if (response && Array.isArray(response.document)) {
|
||||
response.document.map(document => {
|
||||
Array.isArray(document.item) &&
|
||||
@@ -120,62 +119,60 @@ export class DaiaDataProvider {
|
||||
about,
|
||||
available,
|
||||
storage,
|
||||
chronology,
|
||||
unavailable,
|
||||
} = element;
|
||||
const holdingIndex = holdings.findIndex(
|
||||
holding => holding.id === departmentId,
|
||||
);
|
||||
const holdingStatus = this.holdingHasStatus(
|
||||
available || [],
|
||||
)
|
||||
? this.getHoldingStatus(
|
||||
available || [],
|
||||
unavailable || [],
|
||||
)
|
||||
: undefined;
|
||||
|
||||
if (holdingIndex === -1) {
|
||||
const holdingStatus = this.holdingHasStatus(
|
||||
available || [],
|
||||
)
|
||||
? this.getHoldingStatus(
|
||||
available || [],
|
||||
unavailable || [],
|
||||
)
|
||||
: undefined;
|
||||
|
||||
const dueDate =
|
||||
holdingStatus === 'checked_out'
|
||||
? (
|
||||
unavailable.find(
|
||||
item => item.service === 'loan',
|
||||
) as SCDaiaService
|
||||
).expected
|
||||
: undefined;
|
||||
|
||||
holdings.push({
|
||||
id: departmentId,
|
||||
label: departmentLabel,
|
||||
href: departmentLink,
|
||||
signature: label,
|
||||
status: holdingStatus,
|
||||
dueDate: dueDate,
|
||||
online:
|
||||
Array.isArray(available) &&
|
||||
typeof available.find(
|
||||
item => item.service === 'remote',
|
||||
) !== 'undefined',
|
||||
available:
|
||||
(Array.isArray(available) &&
|
||||
(available.find(
|
||||
item => item.service === 'openaccess',
|
||||
) ||
|
||||
available.find(
|
||||
item => item.service === 'loan',
|
||||
))) ||
|
||||
undefined,
|
||||
unavailable:
|
||||
(Array.isArray(unavailable) &&
|
||||
const dueDate =
|
||||
holdingStatus === 'checked_out'
|
||||
? (
|
||||
unavailable.find(
|
||||
item => item.service === 'loan',
|
||||
)) ||
|
||||
undefined,
|
||||
storage,
|
||||
about,
|
||||
});
|
||||
}
|
||||
) as DaiaService
|
||||
).expected
|
||||
: undefined;
|
||||
|
||||
holdings.push({
|
||||
id: element.id,
|
||||
department: {
|
||||
id: departmentId,
|
||||
content: departmentLabel,
|
||||
href: departmentLink,
|
||||
},
|
||||
signature: label,
|
||||
status: holdingStatus,
|
||||
dueDate: dueDate,
|
||||
online:
|
||||
Array.isArray(available) &&
|
||||
typeof available.find(
|
||||
item => item.service === 'remote',
|
||||
) !== 'undefined',
|
||||
available:
|
||||
(Array.isArray(available) &&
|
||||
available.find(item =>
|
||||
['openaccess', 'loan', 'presentation'].includes(
|
||||
item.service,
|
||||
),
|
||||
)) ||
|
||||
undefined,
|
||||
unavailable:
|
||||
(Array.isArray(unavailable) &&
|
||||
unavailable.find(
|
||||
item => item.service === 'loan',
|
||||
)) ||
|
||||
undefined,
|
||||
storage,
|
||||
about,
|
||||
holdings: chronology?.about,
|
||||
});
|
||||
} catch {
|
||||
// No element available
|
||||
}
|
||||
@@ -194,7 +191,7 @@ export class DaiaDataProvider {
|
||||
);
|
||||
}
|
||||
|
||||
getHoldingLink(holding: SCDaiaHolding) {
|
||||
getHoldingLink(holding: DaiaHolding) {
|
||||
if (typeof this.hebisProxyUrl === 'undefined') {
|
||||
this.logger.error('HeBIS proxy url undefined');
|
||||
|
||||
@@ -212,18 +209,25 @@ export class DaiaDataProvider {
|
||||
return `${this.hebisProxyUrl}${resourceLink}`;
|
||||
}
|
||||
|
||||
holdingHasStatus(available: SCDaiaService[]): boolean {
|
||||
holdingHasStatus(available: DaiaService[]): boolean {
|
||||
return !available.some(item => item.service === 'remote');
|
||||
}
|
||||
|
||||
getHoldingStatus(
|
||||
available: SCDaiaService[],
|
||||
unavailable: SCDaiaService[],
|
||||
): SCDaiaHolding['status'] {
|
||||
available: DaiaService[],
|
||||
unavailable: DaiaService[],
|
||||
): DaiaHolding['status'] {
|
||||
const loan: {available: number; unavailable: number} = {
|
||||
available: available.findIndex(item => item.service === 'loan'),
|
||||
unavailable: unavailable.findIndex(item => item.service === 'loan'),
|
||||
};
|
||||
const presentation: {available: number; unavailable: number} = {
|
||||
available: available.findIndex(item => item.service === 'presentation'),
|
||||
unavailable: unavailable.findIndex(
|
||||
item => item.service === 'presentation',
|
||||
),
|
||||
};
|
||||
|
||||
if (
|
||||
loan.unavailable !== -1 &&
|
||||
typeof unavailable[loan.unavailable].expected !== 'undefined'
|
||||
@@ -249,16 +253,16 @@ export class DaiaDataProvider {
|
||||
|
||||
if (
|
||||
(loan.unavailable !== -1 &&
|
||||
(!Array.isArray(unavailable[loan.unavailable].limitations) ||
|
||||
(unavailable[loan.unavailable].limitations as SCDaiaSimpleContent[])
|
||||
.length === 0 ||
|
||||
unavailable[loan.unavailable].limitations?.some(limitation =>
|
||||
['OnlyInHouse'].includes(limitation.id),
|
||||
))) ||
|
||||
unavailable[loan.unavailable].limitations?.some(limitation =>
|
||||
['OnlyInHouse'].includes(limitation.id),
|
||||
)) ||
|
||||
(loan.available !== -1 &&
|
||||
available[loan.available].limitations?.some(limitation =>
|
||||
['ExternalLoan'].includes(limitation.id),
|
||||
))
|
||||
)) ||
|
||||
(loan.available === -1 &&
|
||||
presentation.available !== -1 &&
|
||||
presentation.unavailable === -1)
|
||||
)
|
||||
return 'library_only';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user