mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-21 17:12:43 +00:00
feat: separate prettier from eslint
This commit is contained in:
committed by
Thea Schöbl
parent
939fb6ef0f
commit
a88d000ccd
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018-2021 StApps
|
||||
* Copyright (C) 2023 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
@@ -13,11 +13,7 @@
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {Injectable} from '@angular/core';
|
||||
import {
|
||||
DaiaAvailabilityResponse,
|
||||
DaiaHolding,
|
||||
DaiaService,
|
||||
} from './protocol/response';
|
||||
import {DaiaAvailabilityResponse, DaiaHolding, DaiaService} from './protocol/response';
|
||||
import {StorageProvider} from '../storage/storage.provider';
|
||||
import {HttpClient, HttpHeaders} from '@angular/common/http';
|
||||
import {ConfigProvider} from '../config/config.provider';
|
||||
@@ -66,18 +62,13 @@ export class DaiaDataProvider {
|
||||
) {
|
||||
this.storageProvider = storageProvider;
|
||||
this.httpClient = httpClient;
|
||||
this.clientHeaders = this.clientHeaders.set(
|
||||
'Content-Type',
|
||||
'application/json',
|
||||
);
|
||||
this.clientHeaders = this.clientHeaders.set('Content-Type', 'application/json');
|
||||
}
|
||||
|
||||
async getAvailability(id: string): Promise<DaiaHolding[] | undefined> {
|
||||
if (typeof this.daiaServiceUrl === 'undefined') {
|
||||
try {
|
||||
const features = this.configProvider.getValue(
|
||||
'features',
|
||||
) as SCFeatureConfiguration;
|
||||
const features = this.configProvider.getValue('features') as SCFeatureConfiguration;
|
||||
if (features.extern?.daia?.url) {
|
||||
this.daiaServiceUrl = features.extern?.daia?.url;
|
||||
} else {
|
||||
@@ -110,11 +101,11 @@ export class DaiaDataProvider {
|
||||
document.item.map(element => {
|
||||
try {
|
||||
const {
|
||||
department: {
|
||||
id: departmentId,
|
||||
content: departmentLabel,
|
||||
href: departmentLink,
|
||||
} = {id: 'noDep', content: '', href: ''},
|
||||
department: {id: departmentId, content: departmentLabel, href: departmentLink} = {
|
||||
id: 'noDep',
|
||||
content: '',
|
||||
href: '',
|
||||
},
|
||||
label,
|
||||
about,
|
||||
available,
|
||||
@@ -122,22 +113,13 @@ export class DaiaDataProvider {
|
||||
chronology,
|
||||
unavailable,
|
||||
} = element;
|
||||
const holdingStatus = this.holdingHasStatus(
|
||||
available || [],
|
||||
)
|
||||
? this.getHoldingStatus(
|
||||
available || [],
|
||||
unavailable || [],
|
||||
)
|
||||
const holdingStatus = this.holdingHasStatus(available || [])
|
||||
? this.getHoldingStatus(available || [], unavailable || [])
|
||||
: undefined;
|
||||
|
||||
const dueDate =
|
||||
holdingStatus === 'checked_out'
|
||||
? (
|
||||
unavailable.find(
|
||||
item => item.service === 'loan',
|
||||
) as DaiaService
|
||||
).expected
|
||||
? (unavailable.find(item => item.service === 'loan') as DaiaService).expected
|
||||
: undefined;
|
||||
|
||||
holdings.push({
|
||||
@@ -152,31 +134,22 @@ export class DaiaDataProvider {
|
||||
dueDate: dueDate,
|
||||
online:
|
||||
Array.isArray(available) &&
|
||||
typeof available.find(
|
||||
item => item.service === 'remote',
|
||||
) !== 'undefined',
|
||||
typeof available.find(item => item.service === 'remote') !== 'undefined',
|
||||
available:
|
||||
(Array.isArray(available) &&
|
||||
available.find(item =>
|
||||
['openaccess', 'loan', 'presentation'].includes(
|
||||
item.service,
|
||||
),
|
||||
['openaccess', 'loan', 'presentation'].includes(item.service),
|
||||
)) ||
|
||||
undefined,
|
||||
unavailable:
|
||||
(Array.isArray(unavailable) &&
|
||||
unavailable.find(
|
||||
item => item.service === 'loan',
|
||||
)) ||
|
||||
(Array.isArray(unavailable) && unavailable.find(item => item.service === 'loan')) ||
|
||||
undefined,
|
||||
storage,
|
||||
about,
|
||||
holdings: chronology?.about,
|
||||
open:
|
||||
(Array.isArray(available) &&
|
||||
available.some(
|
||||
item => item.service === 'openaccess',
|
||||
)) ||
|
||||
available.some(item => item.service === 'openaccess')) ||
|
||||
undefined,
|
||||
});
|
||||
} catch {
|
||||
@@ -204,34 +177,24 @@ export class DaiaDataProvider {
|
||||
return;
|
||||
}
|
||||
const resourceLink = holding.available?.href;
|
||||
return open
|
||||
? resourceLink
|
||||
: `${this.hebisProxyUrl}${encodeURIComponent(resourceLink as string)}`;
|
||||
return open ? resourceLink : `${this.hebisProxyUrl}${encodeURIComponent(resourceLink as string)}`;
|
||||
}
|
||||
|
||||
holdingHasStatus(available: DaiaService[]): boolean {
|
||||
return !available.some(item => item.service === 'remote');
|
||||
}
|
||||
|
||||
getHoldingStatus(
|
||||
available: DaiaService[],
|
||||
unavailable: DaiaService[],
|
||||
): DaiaHolding['status'] {
|
||||
getHoldingStatus(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',
|
||||
),
|
||||
unavailable: unavailable.findIndex(item => item.service === 'presentation'),
|
||||
};
|
||||
|
||||
if (
|
||||
loan.unavailable !== -1 &&
|
||||
typeof unavailable[loan.unavailable].expected !== 'undefined'
|
||||
) {
|
||||
if (loan.unavailable !== -1 && typeof unavailable[loan.unavailable].expected !== 'undefined') {
|
||||
return 'checked_out';
|
||||
}
|
||||
|
||||
@@ -260,9 +223,7 @@ export class DaiaDataProvider {
|
||||
available[loan.available].limitations?.some(limitation =>
|
||||
['ExternalLoan'].includes(limitation.id),
|
||||
)) ||
|
||||
(loan.available === -1 &&
|
||||
presentation.available !== -1 &&
|
||||
presentation.unavailable === -1)
|
||||
(loan.available === -1 && presentation.available !== -1 && presentation.unavailable === -1)
|
||||
)
|
||||
return 'library_only';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user