mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-22 17:42:57 +00:00
refactor: adjustments for recent PAIA changes
This commit is contained in:
@@ -11,7 +11,7 @@ export class LibraryAccountPageComponent {
|
||||
constructor(private readonly libraryAccountService: LibraryAccountService) {}
|
||||
|
||||
async ionViewWillEnter(): Promise<void> {
|
||||
const patron = await this.libraryAccountService.getProfile();
|
||||
const patron = await this.libraryAccountService.getPatron();
|
||||
this.name = patron?.name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,8 @@ export class CheckedOutPageComponent {
|
||||
|
||||
async fetchItems() {
|
||||
try {
|
||||
// Prepare patron (status) for the items
|
||||
await this.libraryAccountService.getPatron();
|
||||
this.checkedOutItems = undefined;
|
||||
this.checkedOutItems = await this.libraryAccountService.getFilteredItems([PAIADocumentStatus.Held]);
|
||||
} catch {
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
@for (checkedOutItem of checkedOutItems; track checkedOutItem) {
|
||||
<stapps-paia-item
|
||||
[item]="checkedOutItem"
|
||||
[propertiesToShow]="['label', 'renewals', 'endtime']"
|
||||
[propertiesToShow]="['label', 'renewals', 'duedate']"
|
||||
(documentAction)="onDocumentAction($event)"
|
||||
listName="checked_out"
|
||||
>
|
||||
|
||||
@@ -14,7 +14,8 @@
|
||||
*/
|
||||
|
||||
import {Component, EventEmitter, Input, Output} from '@angular/core';
|
||||
import {DocumentAction, PAIADocument} from '../../../types';
|
||||
import {DocumentAction, PAIADocument, PAIADocumentStatus} from '../../../types';
|
||||
import {LibraryAccountService} from '../../library-account.service';
|
||||
|
||||
@Component({
|
||||
selector: 'stapps-paia-item',
|
||||
@@ -22,7 +23,21 @@ import {DocumentAction, PAIADocument} from '../../../types';
|
||||
styleUrls: ['./paiaitem.scss'],
|
||||
})
|
||||
export class PAIAItemComponent {
|
||||
@Input() item: PAIADocument;
|
||||
private _item: PAIADocument;
|
||||
|
||||
renewable: boolean;
|
||||
|
||||
constructor(private readonly libraryAccountService: LibraryAccountService) {}
|
||||
|
||||
@Input()
|
||||
set item(value: PAIADocument) {
|
||||
this._item = value;
|
||||
void this.setRenewable();
|
||||
}
|
||||
|
||||
get item(): PAIADocument {
|
||||
return this._item;
|
||||
}
|
||||
|
||||
@Input()
|
||||
propertiesToShow: (keyof PAIADocument)[];
|
||||
@@ -36,4 +51,9 @@ export class PAIAItemComponent {
|
||||
async onClick(action: DocumentAction['action']) {
|
||||
this.documentAction.emit({doc: this.item, action});
|
||||
}
|
||||
|
||||
private async setRenewable() {
|
||||
const isActive = await this.libraryAccountService.isActivePatron();
|
||||
this.renewable = isActive && Number(this.item.status) === PAIADocumentStatus.Held;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
@if (item[property]) {
|
||||
<p>
|
||||
{{ 'library.account.pages' + '.' + listName + '.' + 'labels' + '.' + property | translate }}:
|
||||
@if (!['endtime', 'duedate'].includes(property)) {
|
||||
@if (!['starttime', 'duedate'].includes(property)) {
|
||||
{{ item[property] }}
|
||||
} @else {
|
||||
{{ $any(item[property]) | amDateFormat: 'll' }}
|
||||
@@ -40,7 +40,7 @@
|
||||
<!-- >-->
|
||||
<!-- {{ 'library.account.actions.cancel.header' | translate }}</ion-button-->
|
||||
<!-- >-->
|
||||
@if (item.canrenew) {
|
||||
@if (renewable && item.canrenew) {
|
||||
<ion-button color="primary" (click)="onClick('renew')">
|
||||
{{ 'library.account.actions.renew.header' | translate }}</ion-button
|
||||
>
|
||||
|
||||
@@ -45,6 +45,8 @@ export class HoldsPageComponent {
|
||||
? [PAIADocumentStatus.Reserved]
|
||||
: [PAIADocumentStatus.Ordered, PAIADocumentStatus.Provided];
|
||||
try {
|
||||
// Prepare patron (status) for the items
|
||||
await this.libraryAccountService.getPatron();
|
||||
this.paiaDocuments = await this.libraryAccountService.getFilteredItems(itemsStatus);
|
||||
} catch {
|
||||
await this.libraryAccountService.handleError();
|
||||
|
||||
@@ -58,7 +58,7 @@
|
||||
@for (hold of paiaDocuments; track hold) {
|
||||
<stapps-paia-item
|
||||
[item]="hold"
|
||||
[propertiesToShow]="['label']"
|
||||
[propertiesToShow]="['label', 'starttime', 'storage', 'queue']"
|
||||
(documentAction)="onDocumentAction($event)"
|
||||
listName="holds"
|
||||
>
|
||||
|
||||
@@ -20,7 +20,15 @@ import {
|
||||
SCFeatureConfiguration,
|
||||
SCFeatureConfigurationExtern,
|
||||
} from '@openstapps/core';
|
||||
import {DocumentAction, PAIADocument, PAIADocumentStatus, PAIAFees, PAIAItems, PAIAPatron} from '../types';
|
||||
import {
|
||||
DocumentAction,
|
||||
PAIADocument,
|
||||
PAIADocumentStatus,
|
||||
PAIAFees,
|
||||
PAIAItems,
|
||||
PAIAPatron,
|
||||
PAIAPatronStatus,
|
||||
} from '../types';
|
||||
import {HebisDataProvider} from '../../hebis/hebis-data.provider';
|
||||
import {PAIATokenResponse} from '../../auth/paia/paia-token-response';
|
||||
import {AuthHelperService} from '../../auth/auth-helper.service';
|
||||
@@ -43,6 +51,11 @@ export class LibraryAccountService {
|
||||
*/
|
||||
authType: SCAuthorizationProviderType;
|
||||
|
||||
/**
|
||||
* Account (Patron) status
|
||||
*/
|
||||
private status?: PAIAPatronStatus;
|
||||
|
||||
constructor(
|
||||
protected requestor: Requestor = new JQueryRequestor(),
|
||||
private readonly hebisDataProvider: HebisDataProvider,
|
||||
@@ -60,12 +73,23 @@ export class LibraryAccountService {
|
||||
this.authType = config.authProvider as SCAuthorizationProviderType;
|
||||
}
|
||||
|
||||
async getProfile() {
|
||||
const patron = ((await this.getValidToken()) as PAIATokenResponse).patron;
|
||||
return {
|
||||
async getPatron() {
|
||||
const patronId = ((await this.getValidToken()) as PAIATokenResponse).patron;
|
||||
const patron = {
|
||||
...(await this.performRequest<PAIAPatron>(`${this.baseUrl}/{patron}`)),
|
||||
id: patron,
|
||||
id: patronId,
|
||||
} as PAIAPatron;
|
||||
// Refresh the status
|
||||
this.status = Number(patron.status);
|
||||
return patron;
|
||||
}
|
||||
|
||||
async getPatronStatus() {
|
||||
return this.status ?? (this.status = Number((await this.getPatron()).status) as PAIAPatronStatus);
|
||||
}
|
||||
|
||||
async isActivePatron() {
|
||||
return (await this.getPatronStatus()) === PAIAPatronStatus.Active;
|
||||
}
|
||||
|
||||
async getItems() {
|
||||
|
||||
@@ -25,15 +25,19 @@ import {PAIAPatron} from '../../types';
|
||||
export class ProfilePageComponent {
|
||||
patron?: PAIAPatron;
|
||||
|
||||
propertiesToShow: (keyof PAIAPatron)[] = ['id', 'name', 'email', 'address', 'expires', 'note'];
|
||||
propertiesToShow: (keyof PAIAPatron)[] = ['id', 'name', 'email', 'address', 'expires'];
|
||||
|
||||
constructor(private readonly libraryAccountService: LibraryAccountService) {}
|
||||
|
||||
async ionViewWillEnter(): Promise<void> {
|
||||
try {
|
||||
this.patron = await this.libraryAccountService.getProfile();
|
||||
this.patron = await this.libraryAccountService.getPatron();
|
||||
} catch {
|
||||
await this.libraryAccountService.handleError();
|
||||
}
|
||||
}
|
||||
|
||||
isUnlimitedExpiry(date = ''): boolean {
|
||||
return new Date(date).getFullYear() === 9999;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,11 +36,11 @@
|
||||
@if (!['expires'].includes(property)) {
|
||||
{{ patron[property] }}
|
||||
} @else {
|
||||
@if (patron[property] === '9999-12-31') {
|
||||
@if (isUnlimitedExpiry(patron['expires'])) {
|
||||
{{ 'library.account.pages.profile.values.unlimited' | translate }}
|
||||
} @else {
|
||||
{{ 'library.account.pages.profile.values.expires' | translate }}: {{
|
||||
patron[property] | amDateFormat: 'll'
|
||||
patron['expires'] | amDateFormat: 'll'
|
||||
}}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,11 +19,19 @@ export interface PAIAPatron {
|
||||
email?: string;
|
||||
address?: string;
|
||||
expires?: string;
|
||||
status?: string;
|
||||
status?: PAIAPatronStatus;
|
||||
type?: string;
|
||||
note?: string;
|
||||
}
|
||||
|
||||
export enum PAIAPatronStatus {
|
||||
Active = 0,
|
||||
Inactive = 1,
|
||||
InactiveExpired = 2,
|
||||
InactiveOutstandingFees = 3,
|
||||
InactiveExpiredOutstandingFees = 4,
|
||||
}
|
||||
|
||||
/*
|
||||
* Document representing a library item received from the HeBIS PAIA service
|
||||
* TODO: would be good to standardize the items of HeBIS PAIA to match the official PAIA documentation
|
||||
@@ -39,7 +47,7 @@ export interface PAIADocument {
|
||||
queue?: string;
|
||||
renewals?: string;
|
||||
reminder?: string;
|
||||
endtime?: string;
|
||||
starttime?: string;
|
||||
duedate?: string;
|
||||
cancancel?: boolean;
|
||||
canrenew?: boolean;
|
||||
|
||||
@@ -336,8 +336,10 @@
|
||||
"title": "Titel",
|
||||
"about": "Mehr Informationen",
|
||||
"label": "Signatur",
|
||||
"starttime": "Übermittelt am",
|
||||
"endtime": "Abzuholen bis",
|
||||
"storage": "Abholbereit"
|
||||
"storage": "Abholtheke",
|
||||
"queue": "Position in der Warteschlange"
|
||||
},
|
||||
"holds": "Bestellungen",
|
||||
"reservations": "Vormerkungen"
|
||||
@@ -348,7 +350,7 @@
|
||||
"title": "Titel",
|
||||
"about": "Mehr Informationen",
|
||||
"label": "Signatur",
|
||||
"endtime": "Leihfristende",
|
||||
"duedate": "Leihfristende",
|
||||
"renewals": "Verlängerungen"
|
||||
}
|
||||
},
|
||||
|
||||
@@ -336,8 +336,10 @@
|
||||
"title": "Title",
|
||||
"about": "More information",
|
||||
"label": "Shelfmark",
|
||||
"starttime": "Submitted at",
|
||||
"endtime": "Available for pickup until",
|
||||
"storage": "Available for pickup"
|
||||
"storage": "Pick-up counter",
|
||||
"queue": "Position in the queue"
|
||||
},
|
||||
"holds": "orders",
|
||||
"reservations": "reservations"
|
||||
@@ -348,7 +350,7 @@
|
||||
"title": "Title",
|
||||
"about": "More information",
|
||||
"label": "Label",
|
||||
"endtime": "Due date",
|
||||
"duedate": "Due date",
|
||||
"renewals": "Renewals"
|
||||
}
|
||||
},
|
||||
|
||||
@@ -21,7 +21,7 @@ export const environment = {
|
||||
backend_url: 'https://mobile.server.uni-frankfurt.de',
|
||||
app_host: 'mobile.app.uni-frankfurt.de',
|
||||
custom_url_scheme: 'de.anyschool.app',
|
||||
backend_version: '3.1.0',
|
||||
backend_version: '3.3.0',
|
||||
production: true,
|
||||
};
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ export const environment = {
|
||||
backend_url: 'https://mobile.server.uni-frankfurt.de',
|
||||
app_host: 'mobile.app.uni-frankfurt.de',
|
||||
custom_url_scheme: 'de.anyschool.app',
|
||||
backend_version: '3.1.0',
|
||||
backend_version: '3.3.0',
|
||||
production: false,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user