mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-22 09:32:41 +00:00
fix: daia availability
This commit is contained in:
committed by
Rainer Killinger
parent
b38a96996a
commit
13cee2d426
@@ -13,7 +13,7 @@
|
|||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {groupBy, groupByProperty} from './group-by';
|
import {groupBy, groupByStable, groupByProperty} from './group-by';
|
||||||
|
|
||||||
describe('groupBy', () => {
|
describe('groupBy', () => {
|
||||||
it('should group an array by a key', () => {
|
it('should group an array by a key', () => {
|
||||||
@@ -77,6 +77,29 @@ describe('groupBy', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('groupByStable', () => {
|
||||||
|
const array = [
|
||||||
|
{id: 2, name: 'two'},
|
||||||
|
{id: 4, name: 'three'},
|
||||||
|
{id: 3, name: 'three'},
|
||||||
|
{id: 1, name: 'one'},
|
||||||
|
];
|
||||||
|
const result = groupByStable(array, it => it.name);
|
||||||
|
|
||||||
|
it('should group an array by keys', () => {
|
||||||
|
expect(result.get('one')).toEqual([{id: 1, name: 'one'}]);
|
||||||
|
expect(result.get('two')).toEqual([{id: 2, name: 'two'}]);
|
||||||
|
expect(result.get('three')).toEqual([
|
||||||
|
{id: 4, name: 'three'},
|
||||||
|
{id: 3, name: 'three'},
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should provide ordered keys', () => {
|
||||||
|
expect([...result.keys()]).toEqual(['two', 'three', 'one']);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('groupByProperty', function () {
|
describe('groupByProperty', function () {
|
||||||
it('should group by property', () => {
|
it('should group by property', () => {
|
||||||
const array = [
|
const array = [
|
||||||
|
|||||||
@@ -28,6 +28,21 @@ export function groupBy<T>(
|
|||||||
}, {});
|
}, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Group an array by a function (returns a Map, whose keys keep order info of items entry)
|
||||||
|
*/
|
||||||
|
export function groupByStable<T>(
|
||||||
|
collection: T[],
|
||||||
|
group: (item: T) => string | undefined,
|
||||||
|
): Map<string, T[]> {
|
||||||
|
return collection.reduce((accumulator: Map<string, T[]>, item) => {
|
||||||
|
const key = group(item) ?? '';
|
||||||
|
accumulator.set(key, accumulator.get(key) ?? []);
|
||||||
|
accumulator.get(key)?.push(item);
|
||||||
|
return accumulator;
|
||||||
|
}, new Map<string, T[]>());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ describe('DaiaAvailabilityComponent', () => {
|
|||||||
dataProvider.daiaServiceUrl = workingDAIAurl;
|
dataProvider.daiaServiceUrl = workingDAIAurl;
|
||||||
translateService = TestBed.inject(TranslateService);
|
translateService = TestBed.inject(TranslateService);
|
||||||
spyOn(dataProvider, 'getAvailability' as any).and.returnValue(
|
spyOn(dataProvider, 'getAvailability' as any).and.returnValue(
|
||||||
Promise.resolve(sampleThing),
|
Promise.resolve([]),
|
||||||
);
|
);
|
||||||
spyOn(
|
spyOn(
|
||||||
DaiaAvailabilityComponent.prototype,
|
DaiaAvailabilityComponent.prototype,
|
||||||
|
|||||||
@@ -20,8 +20,9 @@ import {FavoritesService} from '../../favorites/favorites.service';
|
|||||||
import {DataProvider} from '../../data/data.provider';
|
import {DataProvider} from '../../data/data.provider';
|
||||||
import {DataDetailComponent} from '../../data/detail/data-detail.component';
|
import {DataDetailComponent} from '../../data/detail/data-detail.component';
|
||||||
import {DaiaDataProvider} from '../daia-data.provider';
|
import {DaiaDataProvider} from '../daia-data.provider';
|
||||||
import {SCDaiaHolding} from '../protocol/response';
|
import {DaiaHolding} from '../protocol/response';
|
||||||
import {ModalController} from '@ionic/angular';
|
import {ModalController} from '@ionic/angular';
|
||||||
|
import {groupByStable} from '../../../_helpers/collections/group-by';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Component to display an SCThing detailed
|
* A Component to display an SCThing detailed
|
||||||
@@ -35,7 +36,9 @@ export class DaiaAvailabilityComponent
|
|||||||
extends DataDetailComponent
|
extends DataDetailComponent
|
||||||
implements OnInit
|
implements OnInit
|
||||||
{
|
{
|
||||||
holdings: SCDaiaHolding[] | undefined;
|
holdings?: DaiaHolding[];
|
||||||
|
|
||||||
|
holdingsByDepartments?: Map<DaiaHolding['department']['id'], DaiaHolding[]>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -80,7 +83,13 @@ export class DaiaAvailabilityComponent
|
|||||||
*/
|
*/
|
||||||
async getAvailability(uid: SCUuid) {
|
async getAvailability(uid: SCUuid) {
|
||||||
this.daiaDataProvider.getAvailability(uid).then(holdings => {
|
this.daiaDataProvider.getAvailability(uid).then(holdings => {
|
||||||
|
if (typeof holdings !== 'undefined') {
|
||||||
this.holdings = holdings;
|
this.holdings = holdings;
|
||||||
|
this.holdingsByDepartments = groupByStable(
|
||||||
|
holdings,
|
||||||
|
holding => holding.department.id,
|
||||||
|
);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,26 @@
|
|||||||
<ion-card>
|
<ng-container>
|
||||||
|
<ion-card>
|
||||||
<ion-card-header>
|
<ion-card-header>
|
||||||
{{ 'hebisSearch.daia.availability' | translate }}
|
{{ 'hebisSearch.daia.availability' | translate }}
|
||||||
</ion-card-header>
|
</ion-card-header>
|
||||||
<ion-card-content>
|
<ion-card-content>
|
||||||
<ng-container *ngFor="let holding of holdings">
|
<ng-container *ngIf="holdingsByDepartments">
|
||||||
|
<ng-container
|
||||||
|
*ngFor="let holdingsByDepartment of holdingsByDepartments | keyvalue"
|
||||||
|
>
|
||||||
|
<ion-label>
|
||||||
|
<stapps-external-link
|
||||||
|
*ngIf="holdingsByDepartment.value[0].department.href"
|
||||||
|
[text]="holdingsByDepartment.value[0].department.content"
|
||||||
|
[link]="holdingsByDepartment.value[0].department.href"
|
||||||
|
>
|
||||||
|
</stapps-external-link>
|
||||||
|
</ion-label>
|
||||||
|
<ng-container *ngFor="let holding of holdingsByDepartment.value">
|
||||||
<stapps-daia-holding [holding]="holding"></stapps-daia-holding>
|
<stapps-daia-holding [holding]="holding"></stapps-daia-holding>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
</ng-container>
|
||||||
|
</ng-container>
|
||||||
<ion-label *ngIf="!holdings">
|
<ion-label *ngIf="!holdings">
|
||||||
{{ 'hebisSearch.daia.unavailableAvailability' | translate }}
|
{{ 'hebisSearch.daia.unavailableAvailability' | translate }}
|
||||||
</ion-label>
|
</ion-label>
|
||||||
@@ -13,4 +28,5 @@
|
|||||||
{{ 'hebisSearch.daia.unknownAvailability' | translate }}
|
{{ 'hebisSearch.daia.unknownAvailability' | translate }}
|
||||||
</ion-label>
|
</ion-label>
|
||||||
</ion-card-content>
|
</ion-card-content>
|
||||||
</ion-card>
|
</ion-card>
|
||||||
|
</ng-container>
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {Component, Input, OnInit} from '@angular/core';
|
import {Component, Input, OnInit} from '@angular/core';
|
||||||
import {SCDaiaHolding} from '../protocol/response';
|
import {DaiaHolding} from '../protocol/response';
|
||||||
import {DaiaDataProvider} from '../daia-data.provider';
|
import {DaiaDataProvider} from '../daia-data.provider';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@@ -23,14 +23,13 @@ import {DaiaDataProvider} from '../daia-data.provider';
|
|||||||
styleUrls: ['./daia-holding.scss'],
|
styleUrls: ['./daia-holding.scss'],
|
||||||
})
|
})
|
||||||
export class DaiaHoldingComponent implements OnInit {
|
export class DaiaHoldingComponent implements OnInit {
|
||||||
@Input() holding: SCDaiaHolding;
|
@Input() holding: DaiaHolding;
|
||||||
|
|
||||||
constructor(private daiaDataProvider: DaiaDataProvider) {}
|
constructor(private daiaDataProvider: DaiaDataProvider) {}
|
||||||
|
|
||||||
resourceLink?: string;
|
resourceLink?: string;
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
console.log(this.holding);
|
|
||||||
this.resourceLink = this.daiaDataProvider.getHoldingLink(this.holding);
|
this.resourceLink = this.daiaDataProvider.getHoldingLink(this.holding);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,15 +12,6 @@
|
|||||||
~ You should have received a copy of the GNU General Public License along with
|
~ You should have received a copy of the GNU General Public License along with
|
||||||
~ this program. If not, see <https://www.gnu.org/licenses/>.
|
~ this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<ion-label>
|
|
||||||
<stapps-external-link
|
|
||||||
*ngIf="holding.label"
|
|
||||||
[text]="holding.label"
|
|
||||||
[link]="holding.href"
|
|
||||||
>
|
|
||||||
</stapps-external-link>
|
|
||||||
</ion-label>
|
|
||||||
<ion-grid>
|
<ion-grid>
|
||||||
<ion-row *ngIf="holding.storage && holding.storage.content">
|
<ion-row *ngIf="holding.storage && holding.storage.content">
|
||||||
<ion-col size="3">{{ 'hebisSearch.daia.location' | translate }}</ion-col>
|
<ion-col size="3">{{ 'hebisSearch.daia.location' | translate }}</ion-col>
|
||||||
@@ -30,6 +21,10 @@
|
|||||||
<ion-col size="3">{{ 'hebisSearch.daia.signature' | translate }}</ion-col>
|
<ion-col size="3">{{ 'hebisSearch.daia.signature' | translate }}</ion-col>
|
||||||
<ion-col size="9">{{ holding.signature }}</ion-col>
|
<ion-col size="9">{{ holding.signature }}</ion-col>
|
||||||
</ion-row>
|
</ion-row>
|
||||||
|
<ion-row *ngIf="holding.holdings">
|
||||||
|
<ion-col size="3">{{ 'hebisSearch.daia.holdings' | translate }}</ion-col>
|
||||||
|
<ion-col size="9">{{ holding.holdings }}</ion-col>
|
||||||
|
</ion-row>
|
||||||
<ion-row *ngIf="holding.about">
|
<ion-row *ngIf="holding.about">
|
||||||
<ion-col size="3">{{ 'hebisSearch.daia.comment' | translate }}</ion-col>
|
<ion-col size="3">{{ 'hebisSearch.daia.comment' | translate }}</ion-col>
|
||||||
<ion-col size="9" [innerHTML]="holding.about"></ion-col>
|
<ion-col size="9" [innerHTML]="holding.about"></ion-col>
|
||||||
@@ -69,7 +64,10 @@
|
|||||||
</ion-icon>
|
</ion-icon>
|
||||||
{{ 'hebisSearch.daia.status_states' + '.' + holding.status | translate }}
|
{{ 'hebisSearch.daia.status_states' + '.' + holding.status | translate }}
|
||||||
<stapps-external-link
|
<stapps-external-link
|
||||||
*ngIf="holding.status === 'available' && holding.available.href"
|
*ngIf="
|
||||||
|
['available', 'library_only'].indexOf(holding.status) > -1 &&
|
||||||
|
holding.available.href
|
||||||
|
"
|
||||||
[text]="'hebisSearch.daia.order' | translate"
|
[text]="'hebisSearch.daia.order' | translate"
|
||||||
[link]="holding.available.href"
|
[link]="holding.available.href"
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ ion-label a {
|
|||||||
}
|
}
|
||||||
ion-grid {
|
ion-grid {
|
||||||
padding: 0;
|
padding: 0;
|
||||||
|
margin: 5px 5px;
|
||||||
|
|
||||||
ion-row {
|
ion-row {
|
||||||
background-color: var(--ion-color-light);
|
background-color: var(--ion-color-light);
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import {LoggerConfig, LoggerModule, NGXLogger} from 'ngx-logger';
|
|||||||
import {MapModule} from '../map/map.module';
|
import {MapModule} from '../map/map.module';
|
||||||
import {HttpClientModule} from '@angular/common/http';
|
import {HttpClientModule} from '@angular/common/http';
|
||||||
import {StorageModule} from '../storage/storage.module';
|
import {StorageModule} from '../storage/storage.module';
|
||||||
import {SCDaiaHolding, SCDaiaService} from './protocol/response';
|
import {DaiaHolding, DaiaService} from './protocol/response';
|
||||||
import {Observable, of} from 'rxjs';
|
import {Observable, of} from 'rxjs';
|
||||||
import {TranslateLoader, TranslateModule} from '@ngx-translate/core';
|
import {TranslateLoader, TranslateModule} from '@ngx-translate/core';
|
||||||
|
|
||||||
@@ -69,9 +69,9 @@ describe('DaiaDataProvider', () => {
|
|||||||
});
|
});
|
||||||
describe('getResourceLink', () => {
|
describe('getResourceLink', () => {
|
||||||
it('should return undefined when available not defined', () => {
|
it('should return undefined when available not defined', () => {
|
||||||
const holding: SCDaiaHolding = {
|
const holding: DaiaHolding = {
|
||||||
|
department: {id: '', content: ''},
|
||||||
id: '',
|
id: '',
|
||||||
label: '',
|
|
||||||
online: false,
|
online: false,
|
||||||
signature: '',
|
signature: '',
|
||||||
};
|
};
|
||||||
@@ -80,16 +80,16 @@ describe('DaiaDataProvider', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should return the resource link without proxy when service is openaccess', () => {
|
it('should return the resource link without proxy when service is openaccess', () => {
|
||||||
const available: SCDaiaService = {
|
const available: DaiaService = {
|
||||||
delay: '',
|
delay: '',
|
||||||
expected: '',
|
expected: '',
|
||||||
href: 'https://some-url.com',
|
href: 'https://some-url.com',
|
||||||
limitations: [],
|
limitations: [],
|
||||||
service: 'openaccess',
|
service: 'openaccess',
|
||||||
};
|
};
|
||||||
const holding: SCDaiaHolding = {
|
const holding: DaiaHolding = {
|
||||||
|
department: {id: '', content: ''},
|
||||||
id: '',
|
id: '',
|
||||||
label: '',
|
|
||||||
online: false,
|
online: false,
|
||||||
signature: '',
|
signature: '',
|
||||||
available: available,
|
available: available,
|
||||||
@@ -99,16 +99,16 @@ describe('DaiaDataProvider', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should return the resource link with proxy when service is not openaccess', () => {
|
it('should return the resource link with proxy when service is not openaccess', () => {
|
||||||
const available: SCDaiaService = {
|
const available: DaiaService = {
|
||||||
delay: '',
|
delay: '',
|
||||||
expected: '',
|
expected: '',
|
||||||
href: 'https://some-url.com',
|
href: 'https://some-url.com',
|
||||||
limitations: [],
|
limitations: [],
|
||||||
service: 'other',
|
service: 'other',
|
||||||
};
|
};
|
||||||
const holding: SCDaiaHolding = {
|
const holding: DaiaHolding = {
|
||||||
|
department: {id: '', content: ''},
|
||||||
id: '',
|
id: '',
|
||||||
label: '',
|
|
||||||
online: false,
|
online: false,
|
||||||
signature: '',
|
signature: '',
|
||||||
available: available,
|
available: available,
|
||||||
@@ -124,51 +124,51 @@ describe('DaiaDataProvider', () => {
|
|||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
// let available, unavalable: SCDaiaService[];
|
// let available, unavalable: SCDaiaService[];
|
||||||
|
|
||||||
const checkedOut: SCDaiaService = {
|
const checkedOut: DaiaService = {
|
||||||
expected: '2022-09-01',
|
expected: '2022-09-01',
|
||||||
limitations: [],
|
limitations: [],
|
||||||
service: 'loan',
|
service: 'loan',
|
||||||
};
|
};
|
||||||
|
|
||||||
const notYetAvailableOnBuy: SCDaiaService = {
|
const notYetAvailableOnBuy: DaiaService = {
|
||||||
limitations: [{id: 'OnBuy', content: ''}],
|
limitations: [{id: 'OnBuy', content: ''}],
|
||||||
service: 'loan',
|
service: 'loan',
|
||||||
};
|
};
|
||||||
|
|
||||||
const notYetAvailableJustReturned: SCDaiaService = {
|
const notYetAvailableJustReturned: DaiaService = {
|
||||||
limitations: [{id: 'JustReturned', content: ''}],
|
limitations: [{id: 'JustReturned', content: ''}],
|
||||||
service: 'loan',
|
service: 'loan',
|
||||||
};
|
};
|
||||||
|
|
||||||
const notAvailableCopyIsMissing: SCDaiaService = {
|
const notAvailableCopyIsMissing: DaiaService = {
|
||||||
limitations: [{id: 'CopyIsMissing', content: ''}],
|
limitations: [{id: 'CopyIsMissing', content: ''}],
|
||||||
service: 'loan',
|
service: 'loan',
|
||||||
};
|
};
|
||||||
|
|
||||||
const notAvailableCanceled: SCDaiaService = {
|
const notAvailableCanceled: DaiaService = {
|
||||||
limitations: [{id: 'Canceled', content: ''}],
|
limitations: [{id: 'Canceled', content: ''}],
|
||||||
service: 'loan',
|
service: 'loan',
|
||||||
};
|
};
|
||||||
|
|
||||||
const libraryOnlyOnlyInHouse: SCDaiaService = {
|
const libraryOnlyOnlyInHouse: DaiaService = {
|
||||||
limitations: [{id: 'OnlyInHouse', content: ''}],
|
limitations: [{id: 'OnlyInHouse', content: ''}],
|
||||||
service: 'loan',
|
service: 'loan',
|
||||||
};
|
};
|
||||||
|
|
||||||
const libraryOnlyExternalLoan: SCDaiaService = {
|
const libraryOnlyExternalLoan: DaiaService = {
|
||||||
limitations: [{id: 'ExternalLoan', content: ''}],
|
limitations: [{id: 'ExternalLoan', content: ''}],
|
||||||
service: 'loan',
|
service: 'loan',
|
||||||
};
|
};
|
||||||
|
|
||||||
const libraryOnlyNoLimitations: SCDaiaService = {
|
const libraryOnlyPresentation: DaiaService = {
|
||||||
|
service: 'presentation',
|
||||||
|
};
|
||||||
|
|
||||||
|
const availableLimitationsUndefined: DaiaService = {
|
||||||
service: 'loan',
|
service: 'loan',
|
||||||
};
|
};
|
||||||
|
|
||||||
const availableLimitationsUndefined: SCDaiaService = {
|
const availableLimitationsEmpty: DaiaService = {
|
||||||
service: 'loan',
|
|
||||||
};
|
|
||||||
|
|
||||||
const availableLimitationsEmpty: SCDaiaService = {
|
|
||||||
limitations: [],
|
limitations: [],
|
||||||
service: 'loan',
|
service: 'loan',
|
||||||
};
|
};
|
||||||
@@ -205,21 +205,27 @@ describe('DaiaDataProvider', () => {
|
|||||||
daiaDataProvider.getHoldingStatus([libraryOnlyExternalLoan], []),
|
daiaDataProvider.getHoldingStatus([libraryOnlyExternalLoan], []),
|
||||||
).toEqual('library_only');
|
).toEqual('library_only');
|
||||||
expect(
|
expect(
|
||||||
daiaDataProvider.getHoldingStatus([], [libraryOnlyNoLimitations]),
|
daiaDataProvider.getHoldingStatus([libraryOnlyPresentation], []),
|
||||||
).toEqual('library_only');
|
).toEqual('library_only');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return available', () => {
|
it('should return available', () => {
|
||||||
expect(
|
expect(
|
||||||
daiaDataProvider.getHoldingStatus([availableLimitationsUndefined], []),
|
daiaDataProvider.getHoldingStatus(
|
||||||
|
[availableLimitationsUndefined, libraryOnlyPresentation],
|
||||||
|
[],
|
||||||
|
),
|
||||||
).toEqual('available');
|
).toEqual('available');
|
||||||
expect(
|
expect(
|
||||||
daiaDataProvider.getHoldingStatus([availableLimitationsEmpty], []),
|
daiaDataProvider.getHoldingStatus(
|
||||||
|
[availableLimitationsEmpty, libraryOnlyPresentation],
|
||||||
|
[],
|
||||||
|
),
|
||||||
).toEqual('available');
|
).toEqual('available');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return unknown otherwise', () => {
|
it('should return unknown otherwise', () => {
|
||||||
const withoutLoan: SCDaiaService = {
|
const withoutLoan: DaiaService = {
|
||||||
limitations: [],
|
limitations: [],
|
||||||
service: 'anything else',
|
service: 'anything else',
|
||||||
};
|
};
|
||||||
@@ -230,6 +236,12 @@ describe('DaiaDataProvider', () => {
|
|||||||
expect(daiaDataProvider.getHoldingStatus([], [withoutLoan])).toEqual(
|
expect(daiaDataProvider.getHoldingStatus([], [withoutLoan])).toEqual(
|
||||||
'unknown',
|
'unknown',
|
||||||
);
|
);
|
||||||
|
expect(
|
||||||
|
daiaDataProvider.getHoldingStatus([], [availableLimitationsUndefined]),
|
||||||
|
).toEqual('unknown');
|
||||||
|
expect(
|
||||||
|
daiaDataProvider.getHoldingStatus([], [availableLimitationsEmpty]),
|
||||||
|
).toEqual('unknown');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -14,10 +14,9 @@
|
|||||||
*/
|
*/
|
||||||
import {Injectable} from '@angular/core';
|
import {Injectable} from '@angular/core';
|
||||||
import {
|
import {
|
||||||
SCDaiaAvailabilityResponse,
|
DaiaAvailabilityResponse,
|
||||||
SCDaiaHolding,
|
DaiaHolding,
|
||||||
SCDaiaService,
|
DaiaService,
|
||||||
SCDaiaSimpleContent,
|
|
||||||
} from './protocol/response';
|
} from './protocol/response';
|
||||||
import {StorageProvider} from '../storage/storage.provider';
|
import {StorageProvider} from '../storage/storage.provider';
|
||||||
import {HttpClient, HttpHeaders} from '@angular/common/http';
|
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') {
|
if (typeof this.daiaServiceUrl === 'undefined') {
|
||||||
try {
|
try {
|
||||||
const features = this.configProvider.getValue(
|
const features = this.configProvider.getValue(
|
||||||
@@ -99,12 +98,12 @@ export class DaiaDataProvider {
|
|||||||
|
|
||||||
return new Promise(resolve =>
|
return new Promise(resolve =>
|
||||||
this.httpClient
|
this.httpClient
|
||||||
.get<SCDaiaAvailabilityResponse>(this.daiaServiceUrl as string, {
|
.get<DaiaAvailabilityResponse>(this.daiaServiceUrl as string, {
|
||||||
params: {id, lang: this.translateService.currentLang},
|
params: {id, lang: this.translateService.currentLang},
|
||||||
})
|
})
|
||||||
.subscribe(
|
.subscribe(
|
||||||
(response: SCDaiaAvailabilityResponse) => {
|
(response: DaiaAvailabilityResponse) => {
|
||||||
const holdings: SCDaiaHolding[] = [];
|
const holdings: DaiaHolding[] = [];
|
||||||
if (response && Array.isArray(response.document)) {
|
if (response && Array.isArray(response.document)) {
|
||||||
response.document.map(document => {
|
response.document.map(document => {
|
||||||
Array.isArray(document.item) &&
|
Array.isArray(document.item) &&
|
||||||
@@ -120,13 +119,9 @@ export class DaiaDataProvider {
|
|||||||
about,
|
about,
|
||||||
available,
|
available,
|
||||||
storage,
|
storage,
|
||||||
|
chronology,
|
||||||
unavailable,
|
unavailable,
|
||||||
} = element;
|
} = element;
|
||||||
const holdingIndex = holdings.findIndex(
|
|
||||||
holding => holding.id === departmentId,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (holdingIndex === -1) {
|
|
||||||
const holdingStatus = this.holdingHasStatus(
|
const holdingStatus = this.holdingHasStatus(
|
||||||
available || [],
|
available || [],
|
||||||
)
|
)
|
||||||
@@ -141,14 +136,17 @@ export class DaiaDataProvider {
|
|||||||
? (
|
? (
|
||||||
unavailable.find(
|
unavailable.find(
|
||||||
item => item.service === 'loan',
|
item => item.service === 'loan',
|
||||||
) as SCDaiaService
|
) as DaiaService
|
||||||
).expected
|
).expected
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
holdings.push({
|
holdings.push({
|
||||||
|
id: element.id,
|
||||||
|
department: {
|
||||||
id: departmentId,
|
id: departmentId,
|
||||||
label: departmentLabel,
|
content: departmentLabel,
|
||||||
href: departmentLink,
|
href: departmentLink,
|
||||||
|
},
|
||||||
signature: label,
|
signature: label,
|
||||||
status: holdingStatus,
|
status: holdingStatus,
|
||||||
dueDate: dueDate,
|
dueDate: dueDate,
|
||||||
@@ -159,12 +157,11 @@ export class DaiaDataProvider {
|
|||||||
) !== 'undefined',
|
) !== 'undefined',
|
||||||
available:
|
available:
|
||||||
(Array.isArray(available) &&
|
(Array.isArray(available) &&
|
||||||
(available.find(
|
available.find(item =>
|
||||||
item => item.service === 'openaccess',
|
['openaccess', 'loan', 'presentation'].includes(
|
||||||
) ||
|
item.service,
|
||||||
available.find(
|
),
|
||||||
item => item.service === 'loan',
|
)) ||
|
||||||
))) ||
|
|
||||||
undefined,
|
undefined,
|
||||||
unavailable:
|
unavailable:
|
||||||
(Array.isArray(unavailable) &&
|
(Array.isArray(unavailable) &&
|
||||||
@@ -174,8 +171,8 @@ export class DaiaDataProvider {
|
|||||||
undefined,
|
undefined,
|
||||||
storage,
|
storage,
|
||||||
about,
|
about,
|
||||||
|
holdings: chronology?.about,
|
||||||
});
|
});
|
||||||
}
|
|
||||||
} catch {
|
} catch {
|
||||||
// No element available
|
// No element available
|
||||||
}
|
}
|
||||||
@@ -194,7 +191,7 @@ export class DaiaDataProvider {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
getHoldingLink(holding: SCDaiaHolding) {
|
getHoldingLink(holding: DaiaHolding) {
|
||||||
if (typeof this.hebisProxyUrl === 'undefined') {
|
if (typeof this.hebisProxyUrl === 'undefined') {
|
||||||
this.logger.error('HeBIS proxy url undefined');
|
this.logger.error('HeBIS proxy url undefined');
|
||||||
|
|
||||||
@@ -212,18 +209,25 @@ export class DaiaDataProvider {
|
|||||||
return `${this.hebisProxyUrl}${resourceLink}`;
|
return `${this.hebisProxyUrl}${resourceLink}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
holdingHasStatus(available: SCDaiaService[]): boolean {
|
holdingHasStatus(available: DaiaService[]): boolean {
|
||||||
return !available.some(item => item.service === 'remote');
|
return !available.some(item => item.service === 'remote');
|
||||||
}
|
}
|
||||||
|
|
||||||
getHoldingStatus(
|
getHoldingStatus(
|
||||||
available: SCDaiaService[],
|
available: DaiaService[],
|
||||||
unavailable: SCDaiaService[],
|
unavailable: DaiaService[],
|
||||||
): SCDaiaHolding['status'] {
|
): DaiaHolding['status'] {
|
||||||
const loan: {available: number; unavailable: number} = {
|
const loan: {available: number; unavailable: number} = {
|
||||||
available: available.findIndex(item => item.service === 'loan'),
|
available: available.findIndex(item => item.service === 'loan'),
|
||||||
unavailable: unavailable.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 (
|
if (
|
||||||
loan.unavailable !== -1 &&
|
loan.unavailable !== -1 &&
|
||||||
typeof unavailable[loan.unavailable].expected !== 'undefined'
|
typeof unavailable[loan.unavailable].expected !== 'undefined'
|
||||||
@@ -249,16 +253,16 @@ export class DaiaDataProvider {
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
(loan.unavailable !== -1 &&
|
(loan.unavailable !== -1 &&
|
||||||
(!Array.isArray(unavailable[loan.unavailable].limitations) ||
|
|
||||||
(unavailable[loan.unavailable].limitations as SCDaiaSimpleContent[])
|
|
||||||
.length === 0 ||
|
|
||||||
unavailable[loan.unavailable].limitations?.some(limitation =>
|
unavailable[loan.unavailable].limitations?.some(limitation =>
|
||||||
['OnlyInHouse'].includes(limitation.id),
|
['OnlyInHouse'].includes(limitation.id),
|
||||||
))) ||
|
)) ||
|
||||||
(loan.available !== -1 &&
|
(loan.available !== -1 &&
|
||||||
available[loan.available].limitations?.some(limitation =>
|
available[loan.available].limitations?.some(limitation =>
|
||||||
['ExternalLoan'].includes(limitation.id),
|
['ExternalLoan'].includes(limitation.id),
|
||||||
))
|
)) ||
|
||||||
|
(loan.available === -1 &&
|
||||||
|
presentation.available !== -1 &&
|
||||||
|
presentation.unavailable === -1)
|
||||||
)
|
)
|
||||||
return 'library_only';
|
return 'library_only';
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
import {Injectable} from '@angular/core';
|
import {Injectable} from '@angular/core';
|
||||||
import {Client} from '@openstapps/api/lib/client';
|
import {Client} from '@openstapps/api/lib/client';
|
||||||
import {SCHebisSearchRequest} from './protocol/request';
|
import {SCHebisSearchRequest} from './protocol/request';
|
||||||
import {SCHebisSearchResponse} from './protocol/response';
|
import {HebisSearchResponse} from './protocol/response';
|
||||||
import {StorageProvider} from '../storage/storage.provider';
|
import {StorageProvider} from '../storage/storage.provider';
|
||||||
import {StAppsWebHttpClient} from '../data/stapps-web-http-client.provider';
|
import {StAppsWebHttpClient} from '../data/stapps-web-http-client.provider';
|
||||||
import {HttpClient} from '@angular/common/http';
|
import {HttpClient} from '@angular/common/http';
|
||||||
@@ -80,7 +80,7 @@ export class HebisDataProvider extends DataProvider {
|
|||||||
async hebisSearch(
|
async hebisSearch(
|
||||||
searchRequest: SCHebisSearchRequest,
|
searchRequest: SCHebisSearchRequest,
|
||||||
options?: {addPrefix: boolean},
|
options?: {addPrefix: boolean},
|
||||||
): Promise<SCHebisSearchResponse> {
|
): Promise<HebisSearchResponse> {
|
||||||
if (options?.addPrefix) {
|
if (options?.addPrefix) {
|
||||||
searchRequest.query = [HEBIS_PREFIX, searchRequest.query].join('');
|
searchRequest.query = [HEBIS_PREFIX, searchRequest.query].join('');
|
||||||
}
|
}
|
||||||
@@ -89,7 +89,7 @@ export class HebisDataProvider extends DataProvider {
|
|||||||
|
|
||||||
if (typeof page === 'undefined') {
|
if (typeof page === 'undefined') {
|
||||||
const preFlightResponse =
|
const preFlightResponse =
|
||||||
await this.client.invokeRoute<SCHebisSearchResponse>(
|
await this.client.invokeRoute<HebisSearchResponse>(
|
||||||
this.hebisSearchRoute,
|
this.hebisSearchRoute,
|
||||||
undefined,
|
undefined,
|
||||||
{
|
{
|
||||||
@@ -101,7 +101,7 @@ export class HebisDataProvider extends DataProvider {
|
|||||||
page = preFlightResponse.pagination.total;
|
page = preFlightResponse.pagination.total;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.client.invokeRoute<SCHebisSearchResponse>(
|
return this.client.invokeRoute<HebisSearchResponse>(
|
||||||
this.hebisSearchRoute,
|
this.hebisSearchRoute,
|
||||||
undefined,
|
undefined,
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import {HebisDataProvider} from '../hebis-data.provider';
|
|||||||
import {FavoritesService} from '../../favorites/favorites.service';
|
import {FavoritesService} from '../../favorites/favorites.service';
|
||||||
import {DataProvider} from '../../data/data.provider';
|
import {DataProvider} from '../../data/data.provider';
|
||||||
import {DataDetailComponent} from '../../data/detail/data-detail.component';
|
import {DataDetailComponent} from '../../data/detail/data-detail.component';
|
||||||
import {SCDaiaHolding} from '../protocol/response';
|
import {DaiaHolding} from '../protocol/response';
|
||||||
import {ModalController} from '@ionic/angular';
|
import {ModalController} from '@ionic/angular';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -32,7 +32,7 @@ import {ModalController} from '@ionic/angular';
|
|||||||
templateUrl: 'hebis-detail.html',
|
templateUrl: 'hebis-detail.html',
|
||||||
})
|
})
|
||||||
export class HebisDetailComponent extends DataDetailComponent {
|
export class HebisDetailComponent extends DataDetailComponent {
|
||||||
holdings: SCDaiaHolding[];
|
holdings: DaiaHolding[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import {
|
|||||||
SCSearchResultPagination,
|
SCSearchResultPagination,
|
||||||
} from '@openstapps/core';
|
} from '@openstapps/core';
|
||||||
|
|
||||||
export interface SCHebisSearchResponse {
|
export interface HebisSearchResponse {
|
||||||
/**
|
/**
|
||||||
* Response Array of SCBook type or Object
|
* Response Array of SCBook type or Object
|
||||||
*/
|
*/
|
||||||
@@ -17,48 +17,51 @@ export interface SCHebisSearchResponse {
|
|||||||
pagination: SCSearchResultPagination;
|
pagination: SCSearchResultPagination;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SCDaiaAvailabilityResponse {
|
export interface DaiaAvailabilityResponse {
|
||||||
document: Array<{
|
document: Array<{
|
||||||
item: Array<{
|
item: Array<{
|
||||||
id: string;
|
id: string;
|
||||||
label: string;
|
label: string;
|
||||||
department: SCDaiaSimpleContent;
|
chronology?: {
|
||||||
available: SCDaiaService[];
|
about?: string;
|
||||||
unavailable: SCDaiaService[];
|
};
|
||||||
|
department: DaiaSimpleContent;
|
||||||
|
available: DaiaService[];
|
||||||
|
unavailable: DaiaService[];
|
||||||
debugInfo: string;
|
debugInfo: string;
|
||||||
about?: string;
|
about?: string;
|
||||||
storage?: SCDaiaSimpleContent;
|
storage?: DaiaSimpleContent;
|
||||||
}>;
|
}>;
|
||||||
}>;
|
}>;
|
||||||
institution: SCDaiaSimpleContent;
|
institution: DaiaSimpleContent;
|
||||||
timestamp: string;
|
timestamp: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SCDaiaSimpleContent {
|
export interface DaiaSimpleContent {
|
||||||
id: string;
|
id: string;
|
||||||
content: string;
|
content: string;
|
||||||
href?: string;
|
href?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SCDaiaService {
|
export interface DaiaService {
|
||||||
delay?: string;
|
delay?: string;
|
||||||
href?: string;
|
href?: string;
|
||||||
service: string;
|
service: string;
|
||||||
expected?: string;
|
expected?: string;
|
||||||
limitations?: SCDaiaSimpleContent[];
|
limitations?: DaiaSimpleContent[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SCDaiaHolding {
|
export interface DaiaHolding {
|
||||||
id: string;
|
id: string;
|
||||||
label: string;
|
department: DaiaSimpleContent;
|
||||||
href?: string;
|
|
||||||
signature: string;
|
signature: string;
|
||||||
storage?: SCDaiaSimpleContent;
|
storage?: DaiaSimpleContent;
|
||||||
available?: SCDaiaService;
|
available?: DaiaService;
|
||||||
unavailable?: SCDaiaService;
|
unavailable?: DaiaService;
|
||||||
about?: string;
|
about?: string;
|
||||||
online: boolean;
|
online: boolean;
|
||||||
dueDate?: string;
|
dueDate?: string;
|
||||||
|
holdings?: string;
|
||||||
status?:
|
status?:
|
||||||
| 'checked_out'
|
| 'checked_out'
|
||||||
| 'not_yet_available'
|
| 'not_yet_available'
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ import {AuthHelperService} from '../../auth/auth-helper.service';
|
|||||||
import {ConfigProvider} from '../../config/config.provider';
|
import {ConfigProvider} from '../../config/config.provider';
|
||||||
import {TranslateService} from '@ngx-translate/core';
|
import {TranslateService} from '@ngx-translate/core';
|
||||||
import {AlertController} from '@ionic/angular';
|
import {AlertController} from '@ionic/angular';
|
||||||
import {SCHebisSearchResponse} from '../../hebis/protocol/response';
|
import {HebisSearchResponse} from '../../hebis/protocol/response';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root',
|
providedIn: 'root',
|
||||||
@@ -141,7 +141,7 @@ export class LibraryAccountService {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let response: SCHebisSearchResponse;
|
let response: HebisSearchResponse;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
response = await this.hebisDataProvider.hebisSearch(
|
response = await this.hebisDataProvider.hebisSearch(
|
||||||
|
|||||||
@@ -370,7 +370,8 @@
|
|||||||
"ejournal": "ejournal",
|
"ejournal": "ejournal",
|
||||||
"unknownAvailability": "Keine Information vorhanden",
|
"unknownAvailability": "Keine Information vorhanden",
|
||||||
"unavailableAvailability": "System nicht erreichbar",
|
"unavailableAvailability": "System nicht erreichbar",
|
||||||
"fulltext": "Zum Volltext"
|
"fulltext": "Zum Volltext",
|
||||||
|
"holdings": "Bestand"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"schedule": {
|
"schedule": {
|
||||||
|
|||||||
@@ -358,7 +358,7 @@
|
|||||||
"not_available": "not available",
|
"not_available": "not available",
|
||||||
"library_only": "for use in library only",
|
"library_only": "for use in library only",
|
||||||
"available": "available",
|
"available": "available",
|
||||||
"unknown": "not available"
|
"unknown": "unknown"
|
||||||
},
|
},
|
||||||
"dueDate": "Due date",
|
"dueDate": "Due date",
|
||||||
"location": "Location",
|
"location": "Location",
|
||||||
@@ -370,7 +370,8 @@
|
|||||||
"ejournal": "ejournal",
|
"ejournal": "ejournal",
|
||||||
"unknownAvailability": "No information available",
|
"unknownAvailability": "No information available",
|
||||||
"unavailableAvailability": "System unreachable",
|
"unavailableAvailability": "System unreachable",
|
||||||
"fulltext": "Full text"
|
"fulltext": "Full text",
|
||||||
|
"holdings": "Holdings"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"schedule": {
|
"schedule": {
|
||||||
|
|||||||
Reference in New Issue
Block a user