mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-09-18 08:42:20 +00:00
Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e0ef20e96c | ||
|
|
e3b6f14536 | ||
|
|
03bc259f88 | ||
|
|
59a1dffd7c | ||
|
|
fb8c51de74 | ||
|
|
1eaa70193d |
@@ -29,19 +29,6 @@ const menus = [
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
icon: 'local_library',
|
|
||||||
route: '/hebis-search',
|
|
||||||
title: 'library catalog',
|
|
||||||
translations: {
|
|
||||||
de: {
|
|
||||||
title: 'Bibliothekskatalog',
|
|
||||||
},
|
|
||||||
en: {
|
|
||||||
title: 'library catalog',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
icon: 'inventory_2',
|
icon: 'inventory_2',
|
||||||
route: '/catalog',
|
route: '/catalog',
|
||||||
@@ -137,20 +124,6 @@ const menus = [
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
authProvider: 'paia',
|
|
||||||
icon: 'badge',
|
|
||||||
route: '/library-account',
|
|
||||||
title: 'library account',
|
|
||||||
translations: {
|
|
||||||
de: {
|
|
||||||
title: 'Bibliothekskonto',
|
|
||||||
},
|
|
||||||
en: {
|
|
||||||
title: 'library account',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
icon: 'settings',
|
icon: 'settings',
|
||||||
route: '/settings',
|
route: '/settings',
|
||||||
|
|||||||
@@ -13,42 +13,23 @@ const config = {
|
|||||||
default: {
|
default: {
|
||||||
client: {
|
client: {
|
||||||
clientId: '1cac3f99-33fa-4234-8438-979f07e0cdab',
|
clientId: '1cac3f99-33fa-4234-8438-979f07e0cdab',
|
||||||
scopes: '',
|
scopes: 'openid profile email offline_access',
|
||||||
url: 'https://cas.rz.uni-frankfurt.de/cas/oauth2.0',
|
url: 'https://idp5-test.ub.uni-frankfurt.de/idp/profile/oidc',
|
||||||
},
|
},
|
||||||
endpoints: {
|
endpoints: {
|
||||||
authorization: 'https://cas.rz.uni-frankfurt.de/cas/oauth2.0/authorize',
|
authorization: 'https://idp5-test.ub.uni-frankfurt.de/idp/profile/oidc/authorize',
|
||||||
endSession: 'https://cas.rz.uni-frankfurt.de/cas/logout',
|
endSession: 'https://idp5-test.ub.uni-frankfurt.de/idp/profile/oidc/end-session',
|
||||||
mapping: {
|
mapping: {
|
||||||
id: '$.id',
|
id: '$.preferred_username',
|
||||||
email: '$.attributes.mailPrimaryAddress',
|
email: '$.mailPrimaryAddress',
|
||||||
familyName: '$.attributes.sn',
|
familyName: '$.family_name',
|
||||||
givenName: '$.attributes.givenName',
|
givenName: '$.given_name',
|
||||||
name: '$.attributes.givenName',
|
|
||||||
role: '$.attributes.eduPersonPrimaryAffiliation',
|
|
||||||
studentId: '$.attributes.employeeNumber',
|
|
||||||
},
|
|
||||||
token: 'https://cas.rz.uni-frankfurt.de/cas/oauth2.0/accessToken',
|
|
||||||
userinfo: 'https://cas.rz.uni-frankfurt.de/cas/oauth2.0/profile',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
paia: {
|
|
||||||
client: {
|
|
||||||
clientId: '',
|
|
||||||
scopes: '',
|
|
||||||
url: 'https://hds.hebis.de/Shibboleth.sso/UBFFM?target=https://hds.hebis.de/ubffm/paia_login_stub.php',
|
|
||||||
},
|
|
||||||
endpoints: {
|
|
||||||
authorization:
|
|
||||||
'https://hds.hebis.de/Shibboleth.sso/UBFFM?target=https://hds.hebis.de/ubffm/paia_login_stub.php',
|
|
||||||
endSession: 'https://ubffm.hds.hebis.de/Shibboleth.sso/Logout',
|
|
||||||
mapping: {
|
|
||||||
id: '$.email',
|
|
||||||
name: '$.name',
|
name: '$.name',
|
||||||
role: '$.type',
|
role: '$.eduPersonPrimaryAffiliation',
|
||||||
|
studentId: '$.employeeNumber',
|
||||||
},
|
},
|
||||||
token: 'https://hds.hebis.de/paia/auth/login',
|
token: 'https://idp5-test.ub.uni-frankfurt.de/idp/profile/oidc/token',
|
||||||
userinfo: 'https://hds.hebis.de/paia/core',
|
userinfo: 'https://idp5-test.ub.uni-frankfurt.de/idp/profile/oidc/userinfo',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -60,16 +41,6 @@ const config = {
|
|||||||
authProvider: 'default',
|
authProvider: 'default',
|
||||||
url: 'https://his-self-service.rz.uni-frankfurt.de',
|
url: 'https://his-self-service.rz.uni-frankfurt.de',
|
||||||
},
|
},
|
||||||
daia: {
|
|
||||||
url: 'https://daia.hebis.de/DAIA2/UB_Frankfurt',
|
|
||||||
},
|
|
||||||
hebisProxy: {
|
|
||||||
url: 'https://proxy.ub.uni-frankfurt.de/login?qurl=',
|
|
||||||
},
|
|
||||||
paia: {
|
|
||||||
authProvider: 'paia',
|
|
||||||
url: 'https://hds.hebis.de/paia/core',
|
|
||||||
},
|
|
||||||
/** TODO: idCards: {
|
/** TODO: idCards: {
|
||||||
authProvider: 'default',
|
authProvider: 'default',
|
||||||
url: 'TODO',
|
url: 'TODO',
|
||||||
|
|||||||
@@ -36,7 +36,7 @@
|
|||||||
"format:fix": "prettier --write . --ignore-path ../../.gitignore",
|
"format:fix": "prettier --write . --ignore-path ../../.gitignore",
|
||||||
"lint": "tsc --noEmit && eslint --ext .ts src/",
|
"lint": "tsc --noEmit && eslint --ext .ts src/",
|
||||||
"lint:fix": "eslint --fix --ext .ts src/",
|
"lint:fix": "eslint --fix --ext .ts src/",
|
||||||
"start": "cross-env NODE_CONFIG_ENV=elasticsearch ALLOW_NO_TRANSPORT=true node app.js",
|
"start": "cross-env NODE_CONFIG_ENV=elasticsearch ALLOW_NO_TRANSPORT=true NODE_APP_INSTANCE=\"f-u\" node app.js",
|
||||||
"start:debug": "cross-env STAPPS_LOG_LEVEL=31 NODE_CONFIG_ENV=elasticsearch ALLOW_NO_TRANSPORT=true node app.js",
|
"start:debug": "cross-env STAPPS_LOG_LEVEL=31 NODE_CONFIG_ENV=elasticsearch ALLOW_NO_TRANSPORT=true node app.js",
|
||||||
"test": "pnpm run test:unit",
|
"test": "pnpm run test:unit",
|
||||||
"test:integration": "sh integration-test.sh",
|
"test:integration": "sh integration-test.sh",
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import jwt from 'jsonwebtoken';
|
||||||
|
|
||||||
|
const token =
|
||||||
|
'AAdzZWNyZXQyo6P-FC41Z55r2N3phG84ZaFN5WQS-Q4GRYVeOLAj8yidLW8ErnsVHdH2lhsPm43UYdE3fCchxryqkDEeqxyw8lqR4aDGjJjKvVIMqWnlHWWhBwXG169NGAGpfwGyxMRp7MropxSFOsY0ZGgy6Sjo6Au65xvEFn2p4mHlVhN8HCZAjfwS7mD1g0jdYM_FO2eeAQHzAct_AxN5ttbREiwu00flZhJbURl3JN0QI4KcGL82nBFCS-Izui5mTbrv_ynRjds9W6oFVO1wU8E23-AvR8h9dwadVj1_J46EPUPZFrLrXd0ggZDxCq6MXMGThXKdNAdPpmJ7VWLk-N-tpLF84dsbcjda55KK6sVaj-T1WhHxgQYcu_j-cDnLNI9TDaFOnQZbtgDT0qX4W0166iGxMQw9gT7fMIkjaxx02_dOwETjywKubFFuvCaHogn5mdnqsNiNL0mUgYTKmXfKyKwJGVxk2RHNt0xd1LRlERVzPhGy0uoB5mxydo6AArifybhXmBDL_1i6PbMOktyveBcnknoJfyslNnO4Tc7edxWZx_oBOM1zAJnpoZGlJoCZlN6kW9o49AlvY4DuNPDXUSEOO6A1Bd7bgZFDVJ3OgsGaoFTdBrX1CAVapcy8';
|
||||||
|
|
||||||
|
const decoded = jwt.decode(token, {complete: false});
|
||||||
|
console.log(decoded);
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
// -----------------------------------------------------------
|
||||||
|
// 1. Hier Ihr ID Token einfügen:
|
||||||
|
const idToken =
|
||||||
|
'eyJraWQiOiJkZWZhdWx0UlNBU2lnbiIsImFsZyI6IlJTMjU2In0.eyJhdF9oYXNoIjoibVJpdzR3cDVKMUw0bzgtenVaWnlMQSIsInN1YiI6InM1MTgxNzAxQHVuaS1mcmFua2Z1cnQuZGUiLCJhdWQiOiIxY2FjM2Y5OS0zM2ZhLTQyMzQtODQzOC05NzlmMDdlMGNkYWIiLCJhdXRoX3RpbWUiOjE3NjU5Njc1NjEsImlzcyI6Imh0dHBzOi8vaWRwNS10ZXN0LnViLnVuaS1mcmFua2Z1cnQuZGUiLCJwcmVmZXJyZWRfdXNlcm5hbWUiOiJzNTE4MTcwMSIsImV4cCI6MTc2NTk3MTE2OSwiaWF0IjoxNzY1OTY3NTY5LCJzaWQiOiJfNTg1NmVkOGNlZmNlZTQ2ODQ0OTA4YTM0ZjNlZTQxMWQifQ.eDbIPjB6zeYiHrbYwqxG2_iV6loJHcvA3l0BT9W0kT4_NZxVVXL_OK7Z-qnC4ppw-SwPzUP7KSiFVBmSiqjQsTF9JWx7xWgcNo9MDxn8MT7F8T_a0CuaAKQtVMn9_adOyyiGgLiQ7_aSwnE0NfE_RomE3pWCQwK1-hr4au3QKR-MKwZehrDdcq0pmAzmCrlWJ8SZ6DmcErxvyXZ799LTjj2Vyn4kpp2uXWTuA5TxgpoKGdeVfTPzD6s6ZRshoVR1bLpkZbIYviE9mtDOw9RmAvZbdZ4-ZVDBX6AXktfq7WnNLDyT43pKRRql3oqdOVs9BD7e7LdJQRy4HgcK5IluSsEXuGNSV_iysvd3HV0yoLFXBkKiRnWsa0-U1WNz-Rnxb4OL_6ZxEfEjWIrdHxnDbbzq0iQomEeAaJRHU9FUSdch5NnHKpPz3W9cbd_9a9geMn5FXkGWwZKOVFPOQEPNBwVflpp_vYzGad0pvOTRSX4lMFnZ0FA1ADuUXuqaOJCk';
|
||||||
|
// -----------------------------------------------------------
|
||||||
|
|
||||||
|
// Payload isolieren
|
||||||
|
const payloadBase64 = idToken.split('.')[1];
|
||||||
|
|
||||||
|
// Base64Url in Base64 konvertieren und dekodieren
|
||||||
|
try {
|
||||||
|
const sanitizedPayload = payloadBase64.replace(/-/g, '+').replace(/_/g, '/');
|
||||||
|
|
||||||
|
// HINWEIS: Manchmal muss Padding (das '=' am Ende) hinzugefügt werden,
|
||||||
|
// aber moderne Browser-Implementierungen kommen oft ohne aus.
|
||||||
|
|
||||||
|
// Dekodieren des Base64-Strings zur JSON-Zeichenkette
|
||||||
|
const jsonPayload = decodeURIComponent(
|
||||||
|
atob(sanitizedPayload)
|
||||||
|
.split('')
|
||||||
|
.map(function (c) {
|
||||||
|
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
|
||||||
|
})
|
||||||
|
.join(''),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Parsen in ein JavaScript-Objekt
|
||||||
|
const claims = JSON.parse(jsonPayload);
|
||||||
|
|
||||||
|
console.log('*** Erfolgreich dekodierte ID Token Claims ***');
|
||||||
|
console.table(claims); // Zeigt die Claims in einer schönen Tabelle an
|
||||||
|
console.log(claims);
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Fehler beim Dekodieren des ID Tokens. Haben Sie das gesamte Token korrekt eingefügt?');
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
@@ -57,4 +57,4 @@ include ':transistorsoft-capacitor-background-fetch'
|
|||||||
project(':transistorsoft-capacitor-background-fetch').projectDir = new File('../../../node_modules/.pnpm/@transistorsoft+capacitor-background-fetch@8.0.0_@capacitor+core@8.2.0/node_modules/@transistorsoft/capacitor-background-fetch/android')
|
project(':transistorsoft-capacitor-background-fetch').projectDir = new File('../../../node_modules/.pnpm/@transistorsoft+capacitor-background-fetch@8.0.0_@capacitor+core@8.2.0/node_modules/@transistorsoft/capacitor-background-fetch/android')
|
||||||
|
|
||||||
include ':capacitor-secure-storage-plugin'
|
include ':capacitor-secure-storage-plugin'
|
||||||
project(':capacitor-secure-storage-plugin').projectDir = new File('../../../node_modules/.pnpm/capacitor-secure-storage-plugin@0.12.0_@capacitor+core@8.2.0/node_modules/capacitor-secure-storage-plugin/android')
|
project(':capacitor-secure-storage-plugin').projectDir = new File('../../../node_modules/.pnpm/capacitor-secure-storage-plugin@0.13.0_@capacitor+core@8.2.0/node_modules/capacitor-secure-storage-plugin/android')
|
||||||
|
|||||||
@@ -175,16 +175,6 @@
|
|||||||
"hisometry": {
|
"hisometry": {
|
||||||
"authProvider": "default",
|
"authProvider": "default",
|
||||||
"url": "https://his-self-service.rz.uni-frankfurt.de"
|
"url": "https://his-self-service.rz.uni-frankfurt.de"
|
||||||
},
|
|
||||||
"daia": {
|
|
||||||
"url": "https://daia.hebis.de/DAIA2/UB_Frankfurt"
|
|
||||||
},
|
|
||||||
"hebisProxy": {
|
|
||||||
"url": "https://proxy.ub.uni-frankfurt.de/login?qurl="
|
|
||||||
},
|
|
||||||
"paia": {
|
|
||||||
"authProvider": "paia",
|
|
||||||
"url": "https://hds.hebis.de/paia/core"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"plugins": {
|
"plugins": {
|
||||||
@@ -193,9 +183,6 @@
|
|||||||
},
|
},
|
||||||
"feedback": {
|
"feedback": {
|
||||||
"urlPath": "/feedback"
|
"urlPath": "/feedback"
|
||||||
},
|
|
||||||
"hebis-plugin": {
|
|
||||||
"urlPath": "/hebissearch"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -229,19 +216,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"icon": "local_library",
|
|
||||||
"route": "/hebis-search",
|
|
||||||
"title": "library catalog",
|
|
||||||
"translations": {
|
|
||||||
"de": {
|
|
||||||
"title": "Bibliothekskatalog"
|
|
||||||
},
|
|
||||||
"en": {
|
|
||||||
"title": "library catalog"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"icon": "inventory_2",
|
"icon": "inventory_2",
|
||||||
"route": "/catalog",
|
"route": "/catalog",
|
||||||
@@ -324,20 +298,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"authProvider": "paia",
|
|
||||||
"icon": "badge",
|
|
||||||
"route": "/library-account",
|
|
||||||
"title": "library account",
|
|
||||||
"translations": {
|
|
||||||
"de": {
|
|
||||||
"title": "Bibliothekskonto"
|
|
||||||
},
|
|
||||||
"en": {
|
|
||||||
"title": "library account"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"icon": "settings",
|
"icon": "settings",
|
||||||
"route": "/settings",
|
"route": "/settings",
|
||||||
@@ -473,24 +433,6 @@
|
|||||||
"token": "https://cas.rz.uni-frankfurt.de/cas/oauth2.0/accessToken",
|
"token": "https://cas.rz.uni-frankfurt.de/cas/oauth2.0/accessToken",
|
||||||
"userinfo": "https://cas.rz.uni-frankfurt.de/cas/oauth2.0/profile"
|
"userinfo": "https://cas.rz.uni-frankfurt.de/cas/oauth2.0/profile"
|
||||||
}
|
}
|
||||||
},
|
|
||||||
"paia": {
|
|
||||||
"client": {
|
|
||||||
"clientId": "",
|
|
||||||
"scopes": "",
|
|
||||||
"url": "https://hds.hebis.de/Shibboleth.sso/UBFFM?target=https://hds.hebis.de/ubffm/paia_login_stub.php"
|
|
||||||
},
|
|
||||||
"endpoints": {
|
|
||||||
"authorization": "https://hds.hebis.de/Shibboleth.sso/UBFFM?target=https://hds.hebis.de/ubffm/paia_login_stub.php",
|
|
||||||
"endSession": "https://ubffm.hds.hebis.de/Shibboleth.sso/Logout",
|
|
||||||
"mapping": {
|
|
||||||
"id": "$.email",
|
|
||||||
"name": "$.name",
|
|
||||||
"role": "$.type"
|
|
||||||
},
|
|
||||||
"token": "https://hds.hebis.de/paia/auth/login",
|
|
||||||
"userinfo": "https://hds.hebis.de/paia/core"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"backend": {
|
"backend": {
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ def capacitor_pods
|
|||||||
pod 'CapacitorShare', :path => '../../../../node_modules/.pnpm/@capacitor+share@8.0.1_@capacitor+core@8.2.0/node_modules/@capacitor/share'
|
pod 'CapacitorShare', :path => '../../../../node_modules/.pnpm/@capacitor+share@8.0.1_@capacitor+core@8.2.0/node_modules/@capacitor/share'
|
||||||
pod 'CapacitorSplashScreen', :path => '../../../../node_modules/.pnpm/@capacitor+splash-screen@8.0.1_@capacitor+core@8.2.0/node_modules/@capacitor/splash-screen'
|
pod 'CapacitorSplashScreen', :path => '../../../../node_modules/.pnpm/@capacitor+splash-screen@8.0.1_@capacitor+core@8.2.0/node_modules/@capacitor/splash-screen'
|
||||||
pod 'TransistorsoftCapacitorBackgroundFetch', :path => '../../../../node_modules/.pnpm/@transistorsoft+capacitor-background-fetch@8.0.0_@capacitor+core@8.2.0/node_modules/@transistorsoft/capacitor-background-fetch'
|
pod 'TransistorsoftCapacitorBackgroundFetch', :path => '../../../../node_modules/.pnpm/@transistorsoft+capacitor-background-fetch@8.0.0_@capacitor+core@8.2.0/node_modules/@transistorsoft/capacitor-background-fetch'
|
||||||
pod 'CapacitorSecureStoragePlugin', :path => '../../../../node_modules/.pnpm/capacitor-secure-storage-plugin@0.12.0_@capacitor+core@8.2.0/node_modules/capacitor-secure-storage-plugin'
|
pod 'CapacitorSecureStoragePlugin', :path => '../../../../node_modules/.pnpm/capacitor-secure-storage-plugin@0.13.0_@capacitor+core@8.2.0/node_modules/capacitor-secure-storage-plugin'
|
||||||
pod 'CordovaPlugins', :path => '../capacitor-cordova-ios-plugins'
|
pod 'CordovaPlugins', :path => '../capacitor-cordova-ios-plugins'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
"changelog": "conventional-changelog -p angular -i src/assets/about/CHANGELOG.md -s -r 0",
|
"changelog": "conventional-changelog -p angular -i src/assets/about/CHANGELOG.md -s -r 0",
|
||||||
"check-icons": "node scripts/check-icon-correctness.mjs",
|
"check-icons": "node scripts/check-icon-correctness.mjs",
|
||||||
"chromium:no-cors": "chromium --disable-web-security --user-data-dir=\".browser-data/chromium\"",
|
"chromium:no-cors": "chromium --disable-web-security --user-data-dir=\".browser-data/chromium\"",
|
||||||
"chromium:virtual-host": "chromium --host-resolver-rules=\"MAP mobile.app.uni-frankfurt.de:* localhost:8100\" --ignore-certificate-errors",
|
"chromium:virtual-host": "chromium --host-resolver-rules=\"MAP dev.app.uni-frankfurt.de:* localhost:8100\" --ignore-certificate-errors --disable-web-security --user-data-dir=\".browser-data/chromium\"",
|
||||||
"cypress:open": "cypress open",
|
"cypress:open": "cypress open",
|
||||||
"cypress:run": "cypress run",
|
"cypress:run": "cypress run",
|
||||||
"docker:build": "sudo docker run -p 8100:8100 -p 35729:35729 -p 53703:53703 -v $PWD:/app -it registry.gitlab.com/openstapps/app bash -c \"npm install && npm run build\"",
|
"docker:build": "sudo docker run -p 8100:8100 -p 35729:35729 -p 53703:53703 -v $PWD:/app -it registry.gitlab.com/openstapps/app bash -c \"npm install && npm run build\"",
|
||||||
@@ -43,7 +43,7 @@
|
|||||||
"start": "ionic serve",
|
"start": "ionic serve",
|
||||||
"start:external": "ionic serve --external",
|
"start:external": "ionic serve --external",
|
||||||
"start:prod": "ionic serve --prod",
|
"start:prod": "ionic serve --prod",
|
||||||
"start:virtual-host": "ionic serve --public-host=mobile.app.uni-frankfurt.de --ssl=true --open=false",
|
"start:virtual-host": "ionic serve --public-host=dev.app.uni-frankfurt.de --ssl=true --open=false",
|
||||||
"test": "ng test --code-coverage",
|
"test": "ng test --code-coverage",
|
||||||
"test:integration": "sh integration-test.sh"
|
"test:integration": "sh integration-test.sh"
|
||||||
},
|
},
|
||||||
@@ -81,19 +81,18 @@
|
|||||||
"@maplibre/ngx-maplibre-gl": "17.4.1",
|
"@maplibre/ngx-maplibre-gl": "17.4.1",
|
||||||
"@ngx-translate/core": "15.0.0",
|
"@ngx-translate/core": "15.0.0",
|
||||||
"@ngx-translate/http-loader": "8.0.0",
|
"@ngx-translate/http-loader": "8.0.0",
|
||||||
"@openid/appauth": "1.3.2",
|
"@openid/appauth": "1.4.0",
|
||||||
"@openstapps/api": "workspace:*",
|
"@openstapps/api": "workspace:*",
|
||||||
"@openstapps/collection-utils": "workspace:*",
|
"@openstapps/collection-utils": "workspace:*",
|
||||||
"@openstapps/core": "workspace:*",
|
"@openstapps/core": "workspace:*",
|
||||||
"@transistorsoft/capacitor-background-fetch": "8.0.0",
|
"@transistorsoft/capacitor-background-fetch": "8.0.0",
|
||||||
"@types/dom-view-transitions": "1.0.4",
|
"@types/dom-view-transitions": "1.0.4",
|
||||||
"capacitor-secure-storage-plugin": "0.12.0",
|
"capacitor-secure-storage-plugin": "0.13.0",
|
||||||
"cordova-plugin-calendar": "5.1.6",
|
"cordova-plugin-calendar": "5.1.6",
|
||||||
"date-fns": "3.6.0",
|
"date-fns": "3.6.0",
|
||||||
"deepmerge": "4.3.1",
|
"deepmerge": "4.3.1",
|
||||||
"form-data": "4.0.4",
|
"form-data": "4.0.4",
|
||||||
"geojson": "0.5.0",
|
"geojson": "0.5.0",
|
||||||
"ionic-appauth": "2.1.0",
|
|
||||||
"ionicons": "8.0.13",
|
"ionicons": "8.0.13",
|
||||||
"jsonpath-plus": "10.3.0",
|
"jsonpath-plus": "10.3.0",
|
||||||
"maplibre-gl": "4.0.2",
|
"maplibre-gl": "4.0.2",
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
// // src/app/_interceptors/fake-config.interceptor.ts
|
||||||
|
// import { Injectable } from '@angular/core';
|
||||||
|
// import {
|
||||||
|
// HttpRequest,
|
||||||
|
// HttpHandler,
|
||||||
|
// HttpEvent,
|
||||||
|
// HttpInterceptor,
|
||||||
|
// HttpResponse
|
||||||
|
// } from '@angular/common/http';
|
||||||
|
// import { Observable, of } from 'rxjs';
|
||||||
|
// import { delay } from 'rxjs/operators';
|
||||||
|
//
|
||||||
|
// @Injectable()
|
||||||
|
// export class FakeConfigInterceptor implements HttpInterceptor {
|
||||||
|
// intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
|
||||||
|
// const targetUrl = 'https://mobile.server.uni-frankfur.de';
|
||||||
|
//
|
||||||
|
// const isTargetUrl = request.url === targetUrl;
|
||||||
|
// const isPostMethod = request.method === 'POST';
|
||||||
|
//
|
||||||
|
// if (isTargetUrl && isPostMethod) {
|
||||||
|
// const fakeConfig = {
|
||||||
|
// appName: 'Uni Frankfurt Mobile',
|
||||||
|
// version: '1.0.0-fake',
|
||||||
|
// environment: 'development',
|
||||||
|
// features: {
|
||||||
|
// login: true,
|
||||||
|
// offlineMode: true,
|
||||||
|
// darkMode: false
|
||||||
|
// },
|
||||||
|
// message: 'Diese Konfiguration kommt vom FakeConfigInterceptor 🤖'
|
||||||
|
// };
|
||||||
|
//
|
||||||
|
// return of(new HttpResponse({
|
||||||
|
// status: 200,
|
||||||
|
// body: fakeConfig
|
||||||
|
// })).pipe(delay(300)); // Simuliere kurze Serververzögerung
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // Weiterleiten, wenn nicht exakt die Zielroute + POST
|
||||||
|
// return next.handle(request);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
@@ -25,6 +25,7 @@ import {ScheduleSyncService} from './modules/background/schedule/schedule-sync.s
|
|||||||
import {Keyboard, KeyboardResize} from '@capacitor/keyboard';
|
import {Keyboard, KeyboardResize} from '@capacitor/keyboard';
|
||||||
import {AppVersionService} from './modules/about/app-version.service';
|
import {AppVersionService} from './modules/about/app-version.service';
|
||||||
import {SplashScreen} from '@capacitor/splash-screen';
|
import {SplashScreen} from '@capacitor/splash-screen';
|
||||||
|
import {AuthService} from "./modules/auth/auth.service";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO
|
* TODO
|
||||||
@@ -60,6 +61,7 @@ export class AppComponent implements AfterContentInit {
|
|||||||
private readonly router: Router,
|
private readonly router: Router,
|
||||||
private readonly zone: NgZone,
|
private readonly zone: NgZone,
|
||||||
private readonly authHelper: AuthHelperService,
|
private readonly authHelper: AuthHelperService,
|
||||||
|
private readonly authService: AuthService,
|
||||||
private readonly toastController: ToastController,
|
private readonly toastController: ToastController,
|
||||||
private readonly scheduleSyncService: ScheduleSyncService,
|
private readonly scheduleSyncService: ScheduleSyncService,
|
||||||
private readonly versionService: AppVersionService,
|
private readonly versionService: AppVersionService,
|
||||||
@@ -120,12 +122,8 @@ export class AppComponent implements AfterContentInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async authNotificationsInit() {
|
private async authNotificationsInit() {
|
||||||
this.authHelper
|
this.authService
|
||||||
.getProvider('default')
|
.events$.subscribe(action => this.showMessage(this.authHelper.getAuthMessage(action)));
|
||||||
.events$.subscribe(action => this.showMessage(this.authHelper.getAuthMessage('default', action)));
|
|
||||||
this.authHelper
|
|
||||||
.getProvider('paia')
|
|
||||||
.events$.subscribe(action => this.showMessage(this.authHelper.getAuthMessage('paia', action)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async showMessage(message?: string) {
|
private async showMessage(message?: string) {
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ import {CatalogModule} from './modules/catalog/catalog.module';
|
|||||||
import {ConfigProvider} from './modules/config/config.provider';
|
import {ConfigProvider} from './modules/config/config.provider';
|
||||||
import {DashboardModule} from './modules/dashboard/dashboard.module';
|
import {DashboardModule} from './modules/dashboard/dashboard.module';
|
||||||
import {DataModule} from './modules/data/data.module';
|
import {DataModule} from './modules/data/data.module';
|
||||||
import {HebisModule} from './modules/hebis/hebis.module';
|
|
||||||
import {MapModule} from './modules/map/map.module';
|
import {MapModule} from './modules/map/map.module';
|
||||||
import {MenuModule} from './modules/menu/menu.module';
|
import {MenuModule} from './modules/menu/menu.module';
|
||||||
import {NewsModule} from './modules/news/news.module';
|
import {NewsModule} from './modules/news/news.module';
|
||||||
@@ -53,14 +52,11 @@ import {FeedbackModule} from './modules/feedback/feedback.module';
|
|||||||
import {DebugDataCollectorService} from './modules/data/debug-data-collector.service';
|
import {DebugDataCollectorService} from './modules/data/debug-data-collector.service';
|
||||||
import {AuthModule} from './modules/auth/auth.module';
|
import {AuthModule} from './modules/auth/auth.module';
|
||||||
import {BackgroundModule} from './modules/background/background.module';
|
import {BackgroundModule} from './modules/background/background.module';
|
||||||
import {LibraryModule} from './modules/library/library.module';
|
|
||||||
import {StorageProvider} from './modules/storage/storage.provider';
|
import {StorageProvider} from './modules/storage/storage.provider';
|
||||||
import {AssessmentsModule} from './modules/assessments/assessments.module';
|
import {AssessmentsModule} from './modules/assessments/assessments.module';
|
||||||
import {ServiceHandlerInterceptor} from './_helpers/service-handler.interceptor';
|
import {ServiceHandlerInterceptor} from './_helpers/service-handler.interceptor';
|
||||||
import {RoutingStackService} from './util/routing-stack.service';
|
import {RoutingStackService} from './util/routing-stack.service';
|
||||||
import {SCLanguageCode, SCSettingValue} from '@openstapps/core';
|
import {SCLanguageCode, SCSettingValue} from '@openstapps/core';
|
||||||
import {DefaultAuthService} from './modules/auth/default-auth.service';
|
|
||||||
import {PAIAAuthService} from './modules/auth/paia/paia-auth.service';
|
|
||||||
import {NavigationModule} from './modules/menu/navigation/navigation.module';
|
import {NavigationModule} from './modules/menu/navigation/navigation.module';
|
||||||
import {browserFactory, SimpleBrowser} from './util/browser.factory';
|
import {browserFactory, SimpleBrowser} from './util/browser.factory';
|
||||||
import {getDateFnsLocale} from './translation/dfns-locale';
|
import {getDateFnsLocale} from './translation/dfns-locale';
|
||||||
@@ -70,6 +66,7 @@ import {Capacitor} from '@capacitor/core';
|
|||||||
import {SplashScreen} from '@capacitor/splash-screen';
|
import {SplashScreen} from '@capacitor/splash-screen';
|
||||||
import maplibregl from 'maplibre-gl';
|
import maplibregl from 'maplibre-gl';
|
||||||
import {Protocol} from 'pmtiles';
|
import {Protocol} from 'pmtiles';
|
||||||
|
import {AuthService} from "./modules/auth/auth.service";
|
||||||
|
|
||||||
registerLocaleData(localeDe);
|
registerLocaleData(localeDe);
|
||||||
|
|
||||||
@@ -85,8 +82,7 @@ export function initializerFactory(
|
|||||||
configProvider: ConfigProvider,
|
configProvider: ConfigProvider,
|
||||||
translateService: TranslateService,
|
translateService: TranslateService,
|
||||||
_routingStackService: RoutingStackService,
|
_routingStackService: RoutingStackService,
|
||||||
defaultAuthService: DefaultAuthService,
|
authService: AuthService,
|
||||||
paiaAuthService: PAIAAuthService,
|
|
||||||
dateFnsConfigurationService: DateFnsConfigurationService,
|
dateFnsConfigurationService: DateFnsConfigurationService,
|
||||||
) {
|
) {
|
||||||
return async () => {
|
return async () => {
|
||||||
@@ -114,8 +110,7 @@ export function initializerFactory(
|
|||||||
setDefaultOptions({locale: dateFnsLocale});
|
setDefaultOptions({locale: dateFnsLocale});
|
||||||
dateFnsConfigurationService.setLocale(dateFnsLocale);
|
dateFnsConfigurationService.setLocale(dateFnsLocale);
|
||||||
|
|
||||||
await defaultAuthService.init();
|
await authService.init();
|
||||||
await paiaAuthService.init();
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.warn(error);
|
logger.warn(error);
|
||||||
}
|
}
|
||||||
@@ -154,10 +149,8 @@ export function createTranslateLoader(http: HttpClient) {
|
|||||||
CommonModule,
|
CommonModule,
|
||||||
DashboardModule,
|
DashboardModule,
|
||||||
DataModule,
|
DataModule,
|
||||||
HebisModule,
|
|
||||||
JobModule,
|
JobModule,
|
||||||
FavoritesModule,
|
FavoritesModule,
|
||||||
LibraryModule,
|
|
||||||
ProfilePageModule,
|
ProfilePageModule,
|
||||||
FeedbackModule,
|
FeedbackModule,
|
||||||
MapModule,
|
MapModule,
|
||||||
@@ -207,8 +200,7 @@ export function createTranslateLoader(http: HttpClient) {
|
|||||||
ConfigProvider,
|
ConfigProvider,
|
||||||
TranslateService,
|
TranslateService,
|
||||||
RoutingStackService,
|
RoutingStackService,
|
||||||
DefaultAuthService,
|
AuthService,
|
||||||
PAIAAuthService,
|
|
||||||
DateFnsConfigurationService,
|
DateFnsConfigurationService,
|
||||||
],
|
],
|
||||||
useFactory: initializerFactory,
|
useFactory: initializerFactory,
|
||||||
|
|||||||
@@ -15,9 +15,9 @@
|
|||||||
import {Injectable} from '@angular/core';
|
import {Injectable} from '@angular/core';
|
||||||
import {ConfigProvider} from '../config/config.provider';
|
import {ConfigProvider} from '../config/config.provider';
|
||||||
import {SCAssessment, SCUuid} from '@openstapps/core';
|
import {SCAssessment, SCUuid} from '@openstapps/core';
|
||||||
import {DefaultAuthService} from '../auth/default-auth.service';
|
|
||||||
import {HttpClient} from '@angular/common/http';
|
import {HttpClient} from '@angular/common/http';
|
||||||
import {uniqBy, keyBy} from '@openstapps/collection-utils';
|
import {uniqBy, keyBy} from '@openstapps/collection-utils';
|
||||||
|
import {AuthService} from "../auth/auth.service";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -66,7 +66,7 @@ export class AssessmentsProvider {
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
readonly configProvider: ConfigProvider,
|
readonly configProvider: ConfigProvider,
|
||||||
readonly defaultAuth: DefaultAuthService,
|
readonly authService: AuthService,
|
||||||
readonly http: HttpClient,
|
readonly http: HttpClient,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
@@ -97,7 +97,7 @@ export class AssessmentsProvider {
|
|||||||
this.cache = this.http
|
this.cache = this.http
|
||||||
.get<{data: SCAssessment[]}>(`${url}/${this.assessmentPath}`, {
|
.get<{data: SCAssessment[]}>(`${url}/${this.assessmentPath}`, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${accessToken ?? (await this.defaultAuth.getValidToken()).accessToken}`,
|
Authorization: `Bearer ${accessToken ?? (await this.authService.getValidToken()).accessToken}`,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.toPromise()
|
.toPromise()
|
||||||
|
|||||||
+42
-22
@@ -12,15 +12,17 @@
|
|||||||
* 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/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {Component} from '@angular/core';
|
import {Component} from '@angular/core';
|
||||||
import {NavController} from '@ionic/angular/standalone';
|
|
||||||
import {Router} from '@angular/router';
|
|
||||||
import {AuthActions, IAuthAction} from 'ionic-appauth';
|
|
||||||
import {AuthHelperService} from '../../auth-helper.service';
|
|
||||||
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
||||||
import {Observable} from 'rxjs';
|
import {NavController} from '@ionic/angular/standalone';
|
||||||
import {IPAIAAuthAction} from '../../paia/paia-auth-action';
|
|
||||||
import {DefaultAuthService} from '../../default-auth.service';
|
import {
|
||||||
|
AuthActions,
|
||||||
|
AuthService,
|
||||||
|
IAuthAction,
|
||||||
|
} from '../../auth.service';
|
||||||
|
import {AuthHelperService} from '../../auth-helper.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
templateUrl: 'auth-callback-page.component.html',
|
templateUrl: 'auth-callback-page.component.html',
|
||||||
@@ -28,25 +30,43 @@ import {DefaultAuthService} from '../../default-auth.service';
|
|||||||
})
|
})
|
||||||
export class AuthCallbackPageComponent {
|
export class AuthCallbackPageComponent {
|
||||||
constructor(
|
constructor(
|
||||||
private navCtrl: NavController,
|
private readonly navCtrl: NavController,
|
||||||
private router: Router,
|
private readonly authHelper: AuthHelperService,
|
||||||
private authHelper: AuthHelperService,
|
private readonly authService: AuthService,
|
||||||
private auth: DefaultAuthService,
|
|
||||||
) {
|
) {
|
||||||
const events: Observable<IPAIAAuthAction | IAuthAction> = this.auth.events$;
|
this.authService.events$
|
||||||
|
.pipe(takeUntilDestroyed())
|
||||||
|
.subscribe(action => {
|
||||||
|
void this.postCallback(action);
|
||||||
|
});
|
||||||
|
|
||||||
events.pipe(takeUntilDestroyed()).subscribe((action: IAuthAction) => this.postCallback(action));
|
this.authService.authorizationCallback(
|
||||||
this.auth.authorizationCallback(window.location.origin + this.router.url);
|
window.location.href,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async postCallback(action: IAuthAction) {
|
private async postCallback(
|
||||||
if (action.action === AuthActions.SignInSuccess) {
|
action: IAuthAction,
|
||||||
const originPath = await this.authHelper.getOriginPath();
|
): Promise<void> {
|
||||||
this.navCtrl.navigateRoot(originPath ?? 'profile');
|
switch (action.action) {
|
||||||
this.authHelper.deleteOriginPath();
|
case AuthActions.SignInSuccess: {
|
||||||
}
|
const originPath =
|
||||||
if (action.action === AuthActions.SignInFailed) {
|
await this.authHelper.getOriginPath();
|
||||||
this.navCtrl.navigateRoot('profile');
|
|
||||||
|
await this.authHelper.deleteOriginPath();
|
||||||
|
|
||||||
|
await this.navCtrl.navigateRoot(
|
||||||
|
originPath ?? 'profile',
|
||||||
|
);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case AuthActions.SignInFailed: {
|
||||||
|
await this.navCtrl.navigateRoot('profile');
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import {Injectable} from '@angular/core';
|
|||||||
import {CanActivate, NavigationExtras, Router, RouterStateSnapshot} from '@angular/router';
|
import {CanActivate, NavigationExtras, Router, RouterStateSnapshot} from '@angular/router';
|
||||||
import {ActivatedProtectedRouteSnapshot} from './protected.routes';
|
import {ActivatedProtectedRouteSnapshot} from './protected.routes';
|
||||||
import {AuthHelperService} from './auth-helper.service';
|
import {AuthHelperService} from './auth-helper.service';
|
||||||
|
import {AuthService} from "./auth.service";
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root',
|
providedIn: 'root',
|
||||||
@@ -24,6 +25,7 @@ import {AuthHelperService} from './auth-helper.service';
|
|||||||
export class AuthGuardService implements CanActivate {
|
export class AuthGuardService implements CanActivate {
|
||||||
constructor(
|
constructor(
|
||||||
private authHelper: AuthHelperService,
|
private authHelper: AuthHelperService,
|
||||||
|
private authService: AuthService,
|
||||||
private router: Router,
|
private router: Router,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
@@ -33,7 +35,7 @@ export class AuthGuardService implements CanActivate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await this.authHelper.getProvider(route.data.authProvider).getValidToken();
|
await this.authService.getValidToken();
|
||||||
} catch {
|
} catch {
|
||||||
const originNavigation = this.router.getCurrentNavigation();
|
const originNavigation = this.router.getCurrentNavigation();
|
||||||
let extras: NavigationExtras = {};
|
let extras: NavigationExtras = {};
|
||||||
@@ -42,7 +44,7 @@ export class AuthGuardService implements CanActivate {
|
|||||||
extras = {queryParams: {origin_path: url}};
|
extras = {queryParams: {origin_path: url}};
|
||||||
}
|
}
|
||||||
this.router.navigate(['profile'], extras);
|
this.router.navigate(['profile'], extras);
|
||||||
await this.authHelper.getProvider(route.data.authProvider).signIn();
|
await this.authService.signIn();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,124 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with
|
|
||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
import {TestBed} from '@angular/core/testing';
|
|
||||||
import {AuthHelperService} from './auth-helper.service';
|
|
||||||
import {ConfigProvider} from '../config/config.provider';
|
|
||||||
import {StorageProvider} from '../storage/storage.provider';
|
|
||||||
import {DefaultAuthService} from './default-auth.service';
|
|
||||||
import {Browser} from 'ionic-appauth';
|
|
||||||
import {Requestor, StorageBackend} from '@openid/appauth';
|
|
||||||
import {TranslateService} from '@ngx-translate/core';
|
|
||||||
import {PAIAAuthService} from './paia/paia-auth.service';
|
|
||||||
import {StAppsWebHttpClient} from '../data/stapps-web-http-client.provider';
|
|
||||||
import {provideHttpClient, withInterceptorsFromDi} from '@angular/common/http';
|
|
||||||
import {SimpleBrowser} from '../../util/browser.factory';
|
|
||||||
import {LoggerTestingModule} from 'ngx-logger/testing';
|
|
||||||
|
|
||||||
describe('AuthHelperService', () => {
|
|
||||||
let authHelperService: AuthHelperService;
|
|
||||||
const storageProviderSpy = jasmine.createSpyObj('StorageProvider', ['init', 'get', 'has', 'put', 'search']);
|
|
||||||
const translateServiceSpy = jasmine.createSpyObj('TranslateService', ['setDefaultLang', 'use']);
|
|
||||||
const defaultAuthServiceMock = jasmine.createSpyObj('DefaultAuthService', ['init', 'setupConfiguration']);
|
|
||||||
const paiaAuthServiceMock = jasmine.createSpyObj('PAIAAuthService', ['init', 'setupConfiguration']);
|
|
||||||
const authHelperServiceMock = jasmine.createSpyObj('AuthHelperService', ['constructor']);
|
|
||||||
const simpleBrowserMock = jasmine.createSpyObj('SimpleBrowser', ['open']);
|
|
||||||
const configProvider = jasmine.createSpyObj('ConfigProvider', {
|
|
||||||
getAnyValue: {
|
|
||||||
default: {
|
|
||||||
endpoints: {
|
|
||||||
mapping: {
|
|
||||||
id: '$.id',
|
|
||||||
email: '$.attributes.mailPrimaryAddress',
|
|
||||||
givenName: '$.attributes.givenName',
|
|
||||||
familyName: '$.attributes.sn',
|
|
||||||
name: '$.attributes.sn',
|
|
||||||
role: '$.attributes.eduPersonPrimaryAffiliation',
|
|
||||||
studentId: '$.attributes.employeeNumber',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
TestBed.configureTestingModule({
|
|
||||||
imports: [LoggerTestingModule],
|
|
||||||
providers: [
|
|
||||||
StAppsWebHttpClient,
|
|
||||||
{
|
|
||||||
provide: TranslateService,
|
|
||||||
useValue: translateServiceSpy,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
provide: StorageProvider,
|
|
||||||
useValue: storageProviderSpy,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
provider: DefaultAuthService,
|
|
||||||
useValue: defaultAuthServiceMock,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
provider: PAIAAuthService,
|
|
||||||
useValue: paiaAuthServiceMock,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
provide: ConfigProvider,
|
|
||||||
useValue: configProvider,
|
|
||||||
},
|
|
||||||
Browser,
|
|
||||||
StorageBackend,
|
|
||||||
Requestor,
|
|
||||||
{
|
|
||||||
provider: AuthHelperService,
|
|
||||||
useValue: authHelperServiceMock,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
provide: SimpleBrowser,
|
|
||||||
useValue: simpleBrowserMock,
|
|
||||||
},
|
|
||||||
provideHttpClient(withInterceptorsFromDi()),
|
|
||||||
],
|
|
||||||
});
|
|
||||||
authHelperService = TestBed.inject(AuthHelperService);
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('getUserFromUserInfo', () => {
|
|
||||||
it('should provide user configuration from userInfo', async () => {
|
|
||||||
const userConfiguration = authHelperService.getUserFromUserInfo({
|
|
||||||
attributes: {
|
|
||||||
eduPersonPrimaryAffiliation: 'student',
|
|
||||||
employeeNumber: '123456',
|
|
||||||
givenName: 'Erika',
|
|
||||||
mailPrimaryAddress: 'emuster@anyschool.de',
|
|
||||||
oauthClientId: '123-abc-123',
|
|
||||||
sn: 'Musterfrau',
|
|
||||||
uid: 'emuster',
|
|
||||||
},
|
|
||||||
id: 'emuster',
|
|
||||||
client_id: '123-abc-123',
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(userConfiguration).toEqual({
|
|
||||||
id: 'emuster',
|
|
||||||
givenName: 'Erika',
|
|
||||||
familyName: 'Musterfrau',
|
|
||||||
name: 'Erika Musterfrau',
|
|
||||||
email: 'emuster@anyschool.de',
|
|
||||||
role: 'student',
|
|
||||||
studentId: '123456',
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -14,39 +14,40 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {Injectable} from '@angular/core';
|
import {Injectable} from '@angular/core';
|
||||||
import {IPAIAAuthAction} from './paia/paia-auth-action';
|
import {AlertController} from '@ionic/angular/standalone';
|
||||||
import {AuthActions, IAuthAction} from 'ionic-appauth';
|
|
||||||
import {TranslateService} from '@ngx-translate/core';
|
import {TranslateService} from '@ngx-translate/core';
|
||||||
import {JSONPath} from 'jsonpath-plus';
|
|
||||||
import {
|
import {
|
||||||
SCAuthorizationProvider,
|
SCAuthorizationProvider,
|
||||||
SCAuthorizationProviderType,
|
|
||||||
SCUserConfiguration,
|
SCUserConfiguration,
|
||||||
SCUserConfigurationMap,
|
SCUserConfigurationMap,
|
||||||
} from '@openstapps/core';
|
} from '@openstapps/core';
|
||||||
|
import {JSONPath} from 'jsonpath-plus';
|
||||||
|
|
||||||
|
import {SimpleBrowser} from '../../util/browser.factory';
|
||||||
import {ConfigProvider} from '../config/config.provider';
|
import {ConfigProvider} from '../config/config.provider';
|
||||||
import {StorageProvider} from '../storage/storage.provider';
|
import {StorageProvider} from '../storage/storage.provider';
|
||||||
import {DefaultAuthService} from './default-auth.service';
|
import {
|
||||||
import {PAIAAuthService} from './paia/paia-auth.service';
|
AuthActions,
|
||||||
import {SimpleBrowser} from '../../util/browser.factory';
|
AuthService,
|
||||||
import {AlertController} from '@ionic/angular/standalone';
|
IAuthAction,
|
||||||
|
} from './auth.service';
|
||||||
|
|
||||||
const AUTH_ORIGIN_PATH = 'stapps.auth.origin_path';
|
const AUTH_ORIGIN_PATH = 'stapps.auth.origin_path';
|
||||||
|
const AUTH_MESSAGE_PREFIX = 'auth.messages.default';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root',
|
providedIn: 'root',
|
||||||
})
|
})
|
||||||
export class AuthHelperService {
|
export class AuthHelperService {
|
||||||
userConfigurationMap: SCUserConfigurationMap;
|
readonly userConfigurationMap: SCUserConfigurationMap;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private translateService: TranslateService,
|
private readonly translateService: TranslateService,
|
||||||
private configProvider: ConfigProvider,
|
private readonly configProvider: ConfigProvider,
|
||||||
private storageProvider: StorageProvider,
|
private readonly storageProvider: StorageProvider,
|
||||||
private defaultAuth: DefaultAuthService,
|
private readonly authService: AuthService,
|
||||||
private paiaAuth: PAIAAuthService,
|
private readonly browser: SimpleBrowser,
|
||||||
private browser: SimpleBrowser,
|
private readonly alertController: AlertController,
|
||||||
private alertController: AlertController,
|
|
||||||
) {
|
) {
|
||||||
this.userConfigurationMap =
|
this.userConfigurationMap =
|
||||||
(
|
(
|
||||||
@@ -56,98 +57,139 @@ export class AuthHelperService {
|
|||||||
).default?.endpoints.mapping ?? {};
|
).default?.endpoints.mapping ?? {};
|
||||||
}
|
}
|
||||||
|
|
||||||
public getAuthMessage(provider: SCAuthorizationProviderType, action: IAuthAction | IPAIAAuthAction) {
|
public getAuthMessage(
|
||||||
let message: string | undefined;
|
action: IAuthAction,
|
||||||
|
): string | undefined {
|
||||||
switch (action.action) {
|
switch (action.action) {
|
||||||
case AuthActions.SignInSuccess: {
|
case AuthActions.SignInSuccess:
|
||||||
message = this.translateService.instant(`auth.messages.${provider}.logged_in_success`);
|
return this.translateService.instant(
|
||||||
break;
|
`${AUTH_MESSAGE_PREFIX}.logged_in_success`,
|
||||||
}
|
);
|
||||||
case AuthActions.SignOutSuccess: {
|
|
||||||
message = this.translateService.instant(`auth.messages.${provider}.logged_out_success`);
|
case AuthActions.SignOutSuccess:
|
||||||
break;
|
return this.translateService.instant(
|
||||||
}
|
`${AUTH_MESSAGE_PREFIX}.logged_out_success`,
|
||||||
|
);
|
||||||
|
|
||||||
|
default:
|
||||||
|
return undefined;
|
||||||
}
|
}
|
||||||
return message;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getUserFromUserInfo(userInfo: object) {
|
public getUserFromUserInfo(
|
||||||
|
userInfo: object,
|
||||||
|
): SCUserConfiguration {
|
||||||
const user: SCUserConfiguration = {
|
const user: SCUserConfiguration = {
|
||||||
id: '',
|
id: '',
|
||||||
name: '',
|
name: '',
|
||||||
role: 'student',
|
role: 'student',
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const key in this.userConfigurationMap) {
|
for (const key in this.userConfigurationMap) {
|
||||||
user[key as keyof SCUserConfiguration] = JSONPath({
|
const userKey =
|
||||||
path: this.userConfigurationMap[key as keyof SCUserConfiguration] as string,
|
key as keyof SCUserConfiguration;
|
||||||
|
|
||||||
|
user[userKey] = JSONPath({
|
||||||
|
path:
|
||||||
|
this.userConfigurationMap[
|
||||||
|
userKey
|
||||||
|
] as string,
|
||||||
json: userInfo,
|
json: userInfo,
|
||||||
})[0];
|
})[0];
|
||||||
}
|
}
|
||||||
if (user.givenName && user.givenName.length > 0 && user.familyName && user.familyName.length > 0) {
|
|
||||||
user.name = `${user.givenName} ${user.familyName}`;
|
if (
|
||||||
|
user.givenName &&
|
||||||
|
user.familyName
|
||||||
|
) {
|
||||||
|
user.name =
|
||||||
|
`${user.givenName} ${user.familyName}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
async deleteOriginPath() {
|
public async deleteOriginPath():
|
||||||
return this.storageProvider.delete(AUTH_ORIGIN_PATH);
|
Promise<void> {
|
||||||
|
await this.storageProvider.delete(
|
||||||
|
AUTH_ORIGIN_PATH,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async setOriginPath(path: string) {
|
public async setOriginPath(
|
||||||
return this.storageProvider.put<string>(AUTH_ORIGIN_PATH, path);
|
path: string,
|
||||||
|
): Promise<void> {
|
||||||
|
await this.storageProvider.put(
|
||||||
|
AUTH_ORIGIN_PATH,
|
||||||
|
path,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getOriginPath() {
|
public async getOriginPath():
|
||||||
let originPath: string;
|
Promise<string | undefined> {
|
||||||
try {
|
try {
|
||||||
originPath = await this.storageProvider.get<string>(AUTH_ORIGIN_PATH);
|
return await this.storageProvider.get<string>(
|
||||||
|
AUTH_ORIGIN_PATH,
|
||||||
|
);
|
||||||
} catch {
|
} catch {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async endBrowserSession():
|
||||||
|
Promise<void> {
|
||||||
|
const endSessionEndpoint =
|
||||||
|
await this.authService
|
||||||
|
.getEndSessionEndpoint();
|
||||||
|
|
||||||
|
if (!endSessionEndpoint) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return originPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
getProvider<B extends SCAuthorizationProviderType>(
|
const alert =
|
||||||
providerType: B,
|
await this.alertController.create({
|
||||||
): B extends 'paia' ? PAIAAuthService : DefaultAuthService;
|
header:
|
||||||
/**
|
this.translateService.instant(
|
||||||
* Provides appropriate auth service instance based on type (string) parameter
|
`${AUTH_MESSAGE_PREFIX}.log_out_alert.header`,
|
||||||
*/
|
),
|
||||||
getProvider(providerType: SCAuthorizationProviderType): DefaultAuthService | PAIAAuthService {
|
|
||||||
return providerType === 'paia'
|
|
||||||
? (this.paiaAuth as PAIAAuthService)
|
|
||||||
: (this.defaultAuth as DefaultAuthService);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
message:
|
||||||
* Ends browser session by opening endSessionEndpoint URL of the provider
|
this.translateService.instant(
|
||||||
* @param providerType Type of the provider (e.g. 'default' or 'paia')
|
`${AUTH_MESSAGE_PREFIX}.log_out_alert.message`,
|
||||||
*/
|
),
|
||||||
async endBrowserSession(providerType: SCAuthorizationProviderType) {
|
|
||||||
const endSessionEndpoint = (await this.getProvider(providerType).configuration).endSessionEndpoint;
|
|
||||||
|
|
||||||
if (endSessionEndpoint) {
|
|
||||||
const alert: HTMLIonAlertElement = await this.alertController.create({
|
|
||||||
header: this.translateService.instant(`auth.messages.${providerType}.log_out_alert.header`),
|
|
||||||
message: this.translateService.instant(`auth.messages.${providerType}.log_out_alert.message`),
|
|
||||||
buttons: [
|
buttons: [
|
||||||
{
|
{
|
||||||
text: this.translateService.instant('no'),
|
text:
|
||||||
|
this.translateService.instant(
|
||||||
|
'no',
|
||||||
|
),
|
||||||
|
|
||||||
|
role: 'cancel',
|
||||||
cssClass: 'default',
|
cssClass: 'default',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
text: this.translateService.instant('yes'),
|
text:
|
||||||
|
this.translateService.instant(
|
||||||
|
'yes',
|
||||||
|
),
|
||||||
|
|
||||||
role: 'confirm',
|
role: 'confirm',
|
||||||
cssClass: 'preferred',
|
cssClass: 'preferred',
|
||||||
handler: () => {
|
|
||||||
this.browser.open(new URL(endSessionEndpoint).href);
|
handler: async () => {
|
||||||
|
/*
|
||||||
|
* Only now, after explicit confirmation,
|
||||||
|
* open the IdP end-session endpoint.
|
||||||
|
*/
|
||||||
|
await this.browser.open(
|
||||||
|
endSessionEndpoint,
|
||||||
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
await alert.present();
|
await alert.present();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,15 +12,5 @@
|
|||||||
* 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/>.
|
||||||
*/
|
*/
|
||||||
import {SCAuthorizationProviderType} from '@openstapps/core';
|
|
||||||
|
|
||||||
export const authPaths: {
|
export const AUTH_REDIRECT_PATH = 'auth/callback';
|
||||||
[key in SCAuthorizationProviderType]: {redirect_path: string};
|
|
||||||
} = {
|
|
||||||
default: {
|
|
||||||
redirect_path: 'auth/callback',
|
|
||||||
},
|
|
||||||
paia: {
|
|
||||||
redirect_path: 'auth/paia/callback',
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -15,21 +15,14 @@
|
|||||||
|
|
||||||
import {RouterModule, Routes} from '@angular/router';
|
import {RouterModule, Routes} from '@angular/router';
|
||||||
import {NgModule} from '@angular/core';
|
import {NgModule} from '@angular/core';
|
||||||
import {authPaths} from './auth-paths';
|
import {AUTH_REDIRECT_PATH} from './auth-paths';
|
||||||
import {AuthCallbackPageComponent} from './auth-callback/page/auth-callback-page.component';
|
import {AuthCallbackPageComponent} from './auth-callback/page/auth-callback-page.component';
|
||||||
import {DefaultAuthService} from './default-auth.service';
|
|
||||||
import {PAIAAuthService} from './paia/paia-auth.service';
|
|
||||||
|
|
||||||
const authRoutes: Routes = [
|
const authRoutes: Routes = [
|
||||||
{
|
{
|
||||||
path: authPaths.default.redirect_path,
|
path: AUTH_REDIRECT_PATH,
|
||||||
component: AuthCallbackPageComponent,
|
component: AuthCallbackPageComponent,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
path: authPaths.paia.redirect_path,
|
|
||||||
component: AuthCallbackPageComponent,
|
|
||||||
providers: [{provide: DefaultAuthService, useExisting: PAIAAuthService}],
|
|
||||||
},
|
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -3,15 +3,12 @@ import {CommonModule} from '@angular/common';
|
|||||||
import {Platform} from '@ionic/angular/standalone';
|
import {Platform} from '@ionic/angular/standalone';
|
||||||
import {Requestor, StorageBackend} from '@openid/appauth';
|
import {Requestor, StorageBackend} from '@openid/appauth';
|
||||||
import {storageFactory} from './factories';
|
import {storageFactory} from './factories';
|
||||||
import {Browser} from 'ionic-appauth';
|
import {requestorFactory} from './factories/requestor.factory';
|
||||||
import {CapacitorBrowser} from 'ionic-appauth/lib/capacitor';
|
|
||||||
import {httpFactory} from './factories/http.factory';
|
|
||||||
import {HttpClient} from '@angular/common/http';
|
import {HttpClient} from '@angular/common/http';
|
||||||
import {AuthRoutingModule} from './auth-routing.module';
|
import {AuthRoutingModule} from './auth-routing.module';
|
||||||
import {TranslateModule} from '@ngx-translate/core';
|
import {TranslateModule} from '@ngx-translate/core';
|
||||||
import {AuthCallbackPageComponent} from './auth-callback/page/auth-callback-page.component';
|
import {AuthCallbackPageComponent} from './auth-callback/page/auth-callback-page.component';
|
||||||
import {DefaultAuthService} from './default-auth.service';
|
import {AuthService} from "./auth.service";
|
||||||
import {PAIAAuthService} from './paia/paia-auth.service';
|
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
declarations: [AuthCallbackPageComponent],
|
declarations: [AuthCallbackPageComponent],
|
||||||
@@ -24,15 +21,10 @@ import {PAIAAuthService} from './paia/paia-auth.service';
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
provide: Requestor,
|
provide: Requestor,
|
||||||
useFactory: httpFactory,
|
useFactory: requestorFactory,
|
||||||
deps: [Platform, HttpClient],
|
deps: [Platform, HttpClient],
|
||||||
},
|
},
|
||||||
{
|
AuthService,
|
||||||
provide: Browser,
|
|
||||||
useClass: CapacitorBrowser,
|
|
||||||
},
|
|
||||||
DefaultAuthService,
|
|
||||||
PAIAAuthService,
|
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class AuthModule {}
|
export class AuthModule {}
|
||||||
|
|||||||
@@ -13,69 +13,90 @@
|
|||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {AuthorizationServiceConfigurationJson} from '@openid/appauth';
|
|
||||||
import {IAuthConfig} from 'ionic-appauth';
|
|
||||||
import {SCAuthorizationProvider, SCAuthorizationProviderType} from '@openstapps/core';
|
|
||||||
import {Capacitor} from '@capacitor/core';
|
import {Capacitor} from '@capacitor/core';
|
||||||
import {authPaths} from './auth-paths';
|
import {SCAuthorizationProvider} from '@openstapps/core';
|
||||||
|
import {
|
||||||
|
AuthorizationServiceConfiguration,
|
||||||
|
} from '@openid/appauth';
|
||||||
|
|
||||||
import {environment} from '../../../environments/environment';
|
import {environment} from '../../../environments/environment';
|
||||||
|
import {AUTH_REDIRECT_PATH} from './auth-paths';
|
||||||
|
import type {AuthConfig} from './auth.service';
|
||||||
|
|
||||||
|
export interface OidcEndpoints {
|
||||||
|
userinfo?: string;
|
||||||
|
endSession?: string;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get configuration of an OAuth2 client
|
* Returns the configuration of the OIDC client.
|
||||||
*/
|
*/
|
||||||
export function getClientConfig(
|
export function getClientConfig(
|
||||||
providerType: SCAuthorizationProviderType,
|
|
||||||
authConfig: {
|
authConfig: {
|
||||||
default?: SCAuthorizationProvider;
|
default: SCAuthorizationProvider;
|
||||||
paia?: SCAuthorizationProvider;
|
|
||||||
},
|
},
|
||||||
): IAuthConfig {
|
): AuthConfig {
|
||||||
const providerConfig = authConfig[providerType] as SCAuthorizationProvider;
|
const provider =
|
||||||
|
authConfig.default;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
end_session_redirect_url: '',
|
server_host: provider.client.url,
|
||||||
|
client_id: provider.client.clientId,
|
||||||
|
scopes: provider.client.scopes,
|
||||||
|
redirect_url: getRedirectUrl(),
|
||||||
pkce: true,
|
pkce: true,
|
||||||
scopes: providerConfig.client.scopes,
|
|
||||||
server_host: providerConfig.client.url,
|
|
||||||
client_id: providerConfig.client.clientId,
|
|
||||||
redirect_url: getRedirectUrl(authPaths[providerType].redirect_path),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get configuration about endpoints of an OAuth2 server
|
* Returns the AppAuth OAuth/OIDC service configuration.
|
||||||
*/
|
*/
|
||||||
export function getEndpointsConfig(
|
export function getServiceConfiguration(
|
||||||
providerType: SCAuthorizationProviderType,
|
|
||||||
authConfig: {
|
authConfig: {
|
||||||
default?: SCAuthorizationProvider;
|
default: SCAuthorizationProvider;
|
||||||
paia?: SCAuthorizationProvider;
|
|
||||||
},
|
},
|
||||||
): AuthorizationServiceConfigurationJson {
|
): AuthorizationServiceConfiguration {
|
||||||
const providerConfig = authConfig[providerType] as SCAuthorizationProvider;
|
const endpoints =
|
||||||
|
authConfig.default.endpoints;
|
||||||
|
|
||||||
|
return new AuthorizationServiceConfiguration({
|
||||||
|
authorization_endpoint: endpoints.authorization,
|
||||||
|
token_endpoint: endpoints.token,
|
||||||
|
revocation_endpoint: endpoints.revoke || '',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the additional OIDC endpoints that AppAuth-JS does not expose
|
||||||
|
* through AuthorizationServiceConfiguration.
|
||||||
|
*/
|
||||||
|
export function getOidcEndpoints(
|
||||||
|
authConfig: {
|
||||||
|
default: SCAuthorizationProvider;
|
||||||
|
},
|
||||||
|
): OidcEndpoints {
|
||||||
|
const endpoints = authConfig.default.endpoints;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
authorization_endpoint: providerConfig.endpoints.authorization,
|
userinfo:
|
||||||
end_session_endpoint: providerConfig.endpoints.endSession,
|
endpoints.userinfo,
|
||||||
revocation_endpoint: providerConfig.endpoints.revoke ?? '',
|
|
||||||
token_endpoint: providerConfig.endpoints.token,
|
endSession:
|
||||||
userinfo_endpoint: providerConfig.endpoints.userinfo,
|
endpoints.endSession,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a URL of the app, depending on the platform where it is running
|
* Returns the OIDC redirect URL depending on the current platform.
|
||||||
*/
|
*/
|
||||||
function getRedirectUrl(routePath: string): string {
|
function getRedirectUrl(): string {
|
||||||
let appHost: string;
|
if (Capacitor.isNativePlatform()) {
|
||||||
let appSchema: string;
|
return `${environment.custom_url_scheme}://${environment.app_host}/${AUTH_REDIRECT_PATH}`;
|
||||||
if (environment.production) {
|
|
||||||
appSchema = Capacitor.isNativePlatform() ? environment.custom_url_scheme : 'https';
|
|
||||||
appHost = environment.app_host;
|
|
||||||
} else {
|
|
||||||
appSchema = Capacitor.isNativePlatform()
|
|
||||||
? environment.custom_url_scheme
|
|
||||||
: window.location.protocol.split(':')[0];
|
|
||||||
|
|
||||||
appHost = Capacitor.isNativePlatform() ? environment.app_host : window.location.host;
|
|
||||||
}
|
}
|
||||||
return `${appSchema}://${appHost}/${routePath}`;
|
|
||||||
|
if (environment.production) {
|
||||||
|
return `https://${environment.app_host}/${AUTH_REDIRECT_PATH}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return `${window.location.origin}/${AUTH_REDIRECT_PATH}`;
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,270 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2026 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.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
* more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with
|
||||||
|
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import {Browser} from '@capacitor/browser';
|
||||||
|
import {
|
||||||
|
AuthorizationError,
|
||||||
|
AuthorizationErrorJson,
|
||||||
|
AuthorizationRequest,
|
||||||
|
AuthorizationRequestHandler,
|
||||||
|
AuthorizationRequestJson,
|
||||||
|
AuthorizationRequestResponse,
|
||||||
|
AuthorizationResponse,
|
||||||
|
AuthorizationResponseJson,
|
||||||
|
AuthorizationServiceConfiguration,
|
||||||
|
BasicQueryStringUtils,
|
||||||
|
DefaultCrypto,
|
||||||
|
StorageBackend,
|
||||||
|
StringMap,
|
||||||
|
} from '@openid/appauth';
|
||||||
|
|
||||||
|
const AUTHORIZATION_REQUEST_KEY =
|
||||||
|
'appauth_capacitor_authorization_request';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AppAuth authorization request handler for native Capacitor applications.
|
||||||
|
*
|
||||||
|
* AppAuth-JS handles:
|
||||||
|
* - state generation and validation data
|
||||||
|
* - PKCE code_verifier / code_challenge
|
||||||
|
* - authorization URL construction
|
||||||
|
* - AuthorizationNotifier
|
||||||
|
*
|
||||||
|
* This handler adds the Capacitor-specific parts:
|
||||||
|
* - persist the pending authorization request
|
||||||
|
* - open the authorization URL using @capacitor/browser
|
||||||
|
* - process the callback URL delivered through appUrlOpen
|
||||||
|
*/
|
||||||
|
export class CapacitorAuthorizationRequestHandler extends AuthorizationRequestHandler {
|
||||||
|
private callbackUrl?: string;
|
||||||
|
|
||||||
|
constructor(private readonly storage: StorageBackend) {
|
||||||
|
super(
|
||||||
|
new BasicQueryStringUtils(),
|
||||||
|
new DefaultCrypto(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async performAuthorizationRequest(
|
||||||
|
configuration: AuthorizationServiceConfiguration,
|
||||||
|
request: AuthorizationRequest,
|
||||||
|
): Promise<void> {
|
||||||
|
/*
|
||||||
|
* Important:
|
||||||
|
*
|
||||||
|
* toJson() calls setupCodeVerifier() internally.
|
||||||
|
* Therefore PKCE is initialized before buildRequestUrl()
|
||||||
|
* constructs the authorization URL.
|
||||||
|
*/
|
||||||
|
const requestJson =
|
||||||
|
await request.toJson();
|
||||||
|
|
||||||
|
await this.storage.setItem(
|
||||||
|
AUTHORIZATION_REQUEST_KEY,
|
||||||
|
JSON.stringify(requestJson),
|
||||||
|
);
|
||||||
|
|
||||||
|
const url =
|
||||||
|
this.buildRequestUrl(
|
||||||
|
configuration,
|
||||||
|
request,
|
||||||
|
);
|
||||||
|
|
||||||
|
await Browser.open({url});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Completes the authorization flow using the URL received from
|
||||||
|
* Capacitor's App.addListener('appUrlOpen', ...).
|
||||||
|
*/
|
||||||
|
public async completeAuthorizationRequestFromUrl(
|
||||||
|
callbackUrl: string,
|
||||||
|
): Promise<void> {
|
||||||
|
this.callbackUrl = callbackUrl;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The deep link has returned control to the application.
|
||||||
|
* Close the SFSafariViewController / Custom Tab if it is still open.
|
||||||
|
*/
|
||||||
|
try {
|
||||||
|
await Browser.close();
|
||||||
|
} catch {
|
||||||
|
// Browser might already have been closed by the platform.
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.completeAuthorizationRequestIfPossible();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async completeAuthorizationRequest():
|
||||||
|
Promise<AuthorizationRequestResponse | null> {
|
||||||
|
if (!this.callbackUrl) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const storedRequest =
|
||||||
|
await this.storage.getItem(
|
||||||
|
AUTHORIZATION_REQUEST_KEY,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!storedRequest) {
|
||||||
|
this.callbackUrl = undefined;
|
||||||
|
|
||||||
|
throw new Error(
|
||||||
|
'No pending authorization request found.',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const requestJson =
|
||||||
|
JSON.parse(
|
||||||
|
storedRequest,
|
||||||
|
) as AuthorizationRequestJson;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The serialized request also contains `internal`, including
|
||||||
|
* AppAuth's PKCE code_verifier.
|
||||||
|
*/
|
||||||
|
const request =
|
||||||
|
new AuthorizationRequest(requestJson);
|
||||||
|
|
||||||
|
const parameters =
|
||||||
|
this.parseCallbackUrl(
|
||||||
|
this.callbackUrl,
|
||||||
|
);
|
||||||
|
|
||||||
|
const state =
|
||||||
|
parameters['state'];
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Never accept an authorization response for a different request.
|
||||||
|
*/
|
||||||
|
if (!state || state !== request.state) {
|
||||||
|
this.callbackUrl = undefined;
|
||||||
|
|
||||||
|
throw new Error(
|
||||||
|
'Authorization response state does not match the authorization request.',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const error =
|
||||||
|
parameters['error'];
|
||||||
|
|
||||||
|
let response:
|
||||||
|
AuthorizationResponse | null = null;
|
||||||
|
|
||||||
|
let authorizationError:
|
||||||
|
AuthorizationError | null = null;
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
const errorJson:
|
||||||
|
AuthorizationErrorJson = {
|
||||||
|
error,
|
||||||
|
|
||||||
|
error_description:
|
||||||
|
parameters[
|
||||||
|
'error_description'
|
||||||
|
],
|
||||||
|
|
||||||
|
error_uri:
|
||||||
|
parameters['error_uri'],
|
||||||
|
|
||||||
|
state,
|
||||||
|
};
|
||||||
|
|
||||||
|
authorizationError =
|
||||||
|
new AuthorizationError(
|
||||||
|
errorJson,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
const code =
|
||||||
|
parameters['code'];
|
||||||
|
|
||||||
|
if (!code) {
|
||||||
|
this.callbackUrl = undefined;
|
||||||
|
|
||||||
|
throw new Error(
|
||||||
|
'Authorization callback contains neither an authorization code nor an error.',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const responseJson:
|
||||||
|
AuthorizationResponseJson = {
|
||||||
|
code,
|
||||||
|
state,
|
||||||
|
};
|
||||||
|
|
||||||
|
response =
|
||||||
|
new AuthorizationResponse(
|
||||||
|
responseJson,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The response has been successfully associated with the
|
||||||
|
* pending request. It can now be consumed exactly once.
|
||||||
|
*/
|
||||||
|
await this.storage.removeItem(
|
||||||
|
AUTHORIZATION_REQUEST_KEY,
|
||||||
|
);
|
||||||
|
|
||||||
|
this.callbackUrl = undefined;
|
||||||
|
|
||||||
|
return {
|
||||||
|
request,
|
||||||
|
response,
|
||||||
|
error: authorizationError,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private parseCallbackUrl(
|
||||||
|
callbackUrl: string,
|
||||||
|
): StringMap {
|
||||||
|
const result: StringMap = {};
|
||||||
|
|
||||||
|
const url = new URL(callbackUrl);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Authorization Code Flow normally returns code/state in
|
||||||
|
* the query string:
|
||||||
|
*
|
||||||
|
* openstapps:/callback?code=...&state=...
|
||||||
|
*/
|
||||||
|
url.searchParams.forEach(
|
||||||
|
(value, key) => {
|
||||||
|
result[key] = value;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Also accept parameters in the fragment as a fallback.
|
||||||
|
*/
|
||||||
|
if (url.hash.length > 1) {
|
||||||
|
const hash =
|
||||||
|
url.hash.substring(1);
|
||||||
|
|
||||||
|
const hashParameters =
|
||||||
|
new URLSearchParams(hash);
|
||||||
|
|
||||||
|
hashParameters.forEach(
|
||||||
|
(value, key) => {
|
||||||
|
if (!(key in result)) {
|
||||||
|
result[key] = value;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,61 +13,77 @@
|
|||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {Requestor} from '@openid/appauth';
|
import {
|
||||||
import {CapacitorHttp, HttpHeaders, HttpResponse} from '@capacitor/core';
|
AppAuthError,
|
||||||
import {XhrSettings} from 'ionic-appauth/lib/cordova';
|
Requestor,
|
||||||
|
} from '@openid/appauth';
|
||||||
|
import {
|
||||||
|
CapacitorHttp,
|
||||||
|
HttpHeaders,
|
||||||
|
HttpOptions,
|
||||||
|
} from '@capacitor/core';
|
||||||
|
|
||||||
// REQUIRES CAPACITOR PLUGIN
|
type XhrSettings = Parameters<Requestor['xhr']>[0];
|
||||||
// @capacitor-community/http
|
|
||||||
export class CapacitorRequestor extends Requestor {
|
|
||||||
constructor() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
export class CapacitorRequestor implements Requestor {
|
||||||
public async xhr<T>(settings: XhrSettings): Promise<T> {
|
public async xhr<T>(settings: XhrSettings): Promise<T> {
|
||||||
if (!settings.method) settings.method = 'GET';
|
if (!settings.url) {
|
||||||
|
throw new AppAuthError('A URL must be provided.');
|
||||||
|
}
|
||||||
|
|
||||||
switch (settings.method) {
|
const method = (settings.method ?? 'GET').toUpperCase();
|
||||||
case 'GET': {
|
const url = new URL(settings.url);
|
||||||
return this.get(settings.url, settings.headers);
|
|
||||||
}
|
let data: unknown;
|
||||||
case 'POST': {
|
|
||||||
return this.post(settings.url, settings.data, settings.headers);
|
if (settings.data) {
|
||||||
}
|
if (method === 'POST') {
|
||||||
case 'PUT': {
|
data = settings.data;
|
||||||
return this.put(settings.url, settings.data, settings.headers);
|
} else {
|
||||||
}
|
const searchParams = new URLSearchParams(settings.data);
|
||||||
case 'DELETE': {
|
|
||||||
return this.delete(settings.url, settings.headers);
|
searchParams.forEach((value, key) => {
|
||||||
|
url.searchParams.append(key, value);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private async get<T>(url: string, headers: HttpHeaders) {
|
const options: HttpOptions = {
|
||||||
return CapacitorHttp.get({url, headers}).then((response: HttpResponse) => response.data as T);
|
url: url.toString(),
|
||||||
}
|
method,
|
||||||
|
headers: this.getHeaders(settings.headers),
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
private async post<T>(url: string, data: any, headers: HttpHeaders) {
|
|
||||||
return CapacitorHttp.post({
|
|
||||||
url,
|
|
||||||
data,
|
data,
|
||||||
headers,
|
};
|
||||||
}).then((response: HttpResponse) => {
|
|
||||||
return response.data as T;
|
if (settings.dataType?.toLowerCase() === 'json') {
|
||||||
});
|
options.responseType = 'json';
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await CapacitorHttp.request(options);
|
||||||
|
|
||||||
|
if (response.status < 200 || response.status >= 300) {
|
||||||
|
throw new AppAuthError(
|
||||||
|
`HTTP ${response.status}`,
|
||||||
|
response.data,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.data as T;
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
private getHeaders(headers: XhrSettings['headers']): HttpHeaders {
|
||||||
private async put<T>(url: string, data: any, headers: HttpHeaders) {
|
const result: HttpHeaders = {};
|
||||||
return CapacitorHttp.put({
|
|
||||||
url,
|
|
||||||
data,
|
|
||||||
headers,
|
|
||||||
}).then((response: HttpResponse) => response.data as T);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async delete<T>(url: string, headers: HttpHeaders) {
|
if (!headers) {
|
||||||
return CapacitorHttp.delete({url, headers}).then((response: HttpResponse) => response.data as T);
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const [key, value] of Object.entries(headers)) {
|
||||||
|
if (value !== undefined && value !== null) {
|
||||||
|
result[key] = String(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,104 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with
|
|
||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
import {TestBed} from '@angular/core/testing';
|
|
||||||
import {ConfigProvider} from '../config/config.provider';
|
|
||||||
import {StorageProvider} from '../storage/storage.provider';
|
|
||||||
import {DefaultAuthService} from './default-auth.service';
|
|
||||||
import {Browser} from 'ionic-appauth';
|
|
||||||
import {nowInSeconds, Requestor, StorageBackend} from '@openid/appauth';
|
|
||||||
import {TranslateService} from '@ngx-translate/core';
|
|
||||||
import {StAppsWebHttpClient} from '../data/stapps-web-http-client.provider';
|
|
||||||
import {provideHttpClient, withInterceptorsFromDi} from '@angular/common/http';
|
|
||||||
import {IonicStorage} from 'ionic-appauth/lib';
|
|
||||||
import {RouterModule} from '@angular/router';
|
|
||||||
import {LoggerTestingModule} from 'ngx-logger/testing';
|
|
||||||
|
|
||||||
describe('AuthService', () => {
|
|
||||||
let defaultAuthService: DefaultAuthService;
|
|
||||||
let storageBackendSpy: jasmine.SpyObj<StorageBackend>;
|
|
||||||
const storageProviderSpy = jasmine.createSpyObj('StorageProvider', ['init', 'get', 'has', 'put', 'search']);
|
|
||||||
const translateServiceSpy = jasmine.createSpyObj('TranslateService', ['setDefaultLang', 'use']);
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
storageBackendSpy = jasmine.createSpyObj('StorageBackend', ['getItem']);
|
|
||||||
|
|
||||||
TestBed.configureTestingModule({
|
|
||||||
imports: [LoggerTestingModule, RouterModule.forRoot([])],
|
|
||||||
providers: [
|
|
||||||
StAppsWebHttpClient,
|
|
||||||
{
|
|
||||||
provide: TranslateService,
|
|
||||||
useValue: translateServiceSpy,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
provide: StorageProvider,
|
|
||||||
useValue: storageProviderSpy,
|
|
||||||
},
|
|
||||||
IonicStorage,
|
|
||||||
ConfigProvider,
|
|
||||||
Browser,
|
|
||||||
{
|
|
||||||
provide: StorageBackend,
|
|
||||||
useValue: storageBackendSpy,
|
|
||||||
},
|
|
||||||
Requestor,
|
|
||||||
provideHttpClient(withInterceptorsFromDi()),
|
|
||||||
],
|
|
||||||
});
|
|
||||||
defaultAuthService = TestBed.inject(DefaultAuthService);
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('loadTokenFromStorage', () => {
|
|
||||||
it('should provide false through isAuthenticated$ when there is no token response', async () => {
|
|
||||||
// eslint-disable-next-line unicorn/no-null
|
|
||||||
storageBackendSpy.getItem.and.returnValue(Promise.resolve(null));
|
|
||||||
let loggedInHolder;
|
|
||||||
defaultAuthService.isAuthenticated$.subscribe(loggedIn => {
|
|
||||||
loggedInHolder = loggedIn;
|
|
||||||
});
|
|
||||||
await defaultAuthService.loadTokenFromStorage();
|
|
||||||
|
|
||||||
expect(loggedInHolder).toBeFalse();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should provide true through isAuthenticated$ when access token is valid', async () => {
|
|
||||||
const validToken = `{"access_token":"AT-XXXX","refresh_token":"RT-XXXX","scope":"","token_type":"bearer","issued_at":${nowInSeconds()},"expires_in":"${
|
|
||||||
8 * 60 * 60
|
|
||||||
}"}`;
|
|
||||||
storageBackendSpy.getItem.and.returnValue(Promise.resolve(validToken));
|
|
||||||
let loggedInHolder;
|
|
||||||
defaultAuthService.isAuthenticated$.subscribe(loggedIn => {
|
|
||||||
loggedInHolder = loggedIn;
|
|
||||||
});
|
|
||||||
await defaultAuthService.loadTokenFromStorage();
|
|
||||||
|
|
||||||
expect(loggedInHolder).toBeTrue();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should provide false through isAuthenticated$ when access token is invalid', async () => {
|
|
||||||
const invalidToken = `{"access_token":"AT-INVALID-XXXX","refresh_token":"RT-XXXX","scope":"","token_type":"bearer","issued_at":${
|
|
||||||
nowInSeconds() - 9 * 60 * 60
|
|
||||||
},"expires_in":"${8 * 60 * 60}"}`;
|
|
||||||
storageBackendSpy.getItem.and.returnValue(Promise.resolve(invalidToken));
|
|
||||||
let loggedInHolder;
|
|
||||||
defaultAuthService.isAuthenticated$.subscribe(loggedIn => {
|
|
||||||
loggedInHolder = loggedIn;
|
|
||||||
});
|
|
||||||
await defaultAuthService.loadTokenFromStorage();
|
|
||||||
|
|
||||||
expect(loggedInHolder).toBeFalse();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,91 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with
|
|
||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import {
|
|
||||||
AuthorizationRequestHandler,
|
|
||||||
AuthorizationServiceConfiguration,
|
|
||||||
JQueryRequestor,
|
|
||||||
LocalStorageBackend,
|
|
||||||
Requestor,
|
|
||||||
StorageBackend,
|
|
||||||
TokenRequestHandler,
|
|
||||||
} from '@openid/appauth';
|
|
||||||
import {AuthActionBuilder, Browser, DefaultBrowser, EndSessionHandler, UserInfoHandler} from 'ionic-appauth';
|
|
||||||
import {ConfigProvider} from '../config/config.provider';
|
|
||||||
import {SCAuthorizationProvider} from '@openstapps/core';
|
|
||||||
import {getClientConfig, getEndpointsConfig} from './auth.provider.methods';
|
|
||||||
import {Injectable} from '@angular/core';
|
|
||||||
import {AuthService} from './auth.service';
|
|
||||||
|
|
||||||
const TOKEN_RESPONSE_KEY = 'token_response';
|
|
||||||
|
|
||||||
@Injectable({
|
|
||||||
providedIn: 'root',
|
|
||||||
})
|
|
||||||
export class DefaultAuthService extends AuthService {
|
|
||||||
public localConfiguration: AuthorizationServiceConfiguration;
|
|
||||||
|
|
||||||
protected tokenHandler: TokenRequestHandler;
|
|
||||||
|
|
||||||
protected userInfoHandler: UserInfoHandler;
|
|
||||||
|
|
||||||
protected requestHandler: AuthorizationRequestHandler;
|
|
||||||
|
|
||||||
protected endSessionHandler: EndSessionHandler;
|
|
||||||
|
|
||||||
constructor(
|
|
||||||
protected browser: Browser = new DefaultBrowser(),
|
|
||||||
protected storage: StorageBackend = new LocalStorageBackend(),
|
|
||||||
protected requestor: Requestor = new JQueryRequestor(),
|
|
||||||
private readonly configProvider: ConfigProvider,
|
|
||||||
) {
|
|
||||||
super(browser, storage, requestor);
|
|
||||||
}
|
|
||||||
|
|
||||||
get configuration(): Promise<AuthorizationServiceConfiguration> {
|
|
||||||
if (!this.localConfiguration) throw new Error('Local Configuration Not Defined');
|
|
||||||
|
|
||||||
return Promise.resolve(this.localConfiguration);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async init() {
|
|
||||||
this.setupConfiguration();
|
|
||||||
this.setupAuthorizationNotifier();
|
|
||||||
await this.loadTokenFromStorage();
|
|
||||||
}
|
|
||||||
|
|
||||||
setupConfiguration() {
|
|
||||||
const authConfig = this.configProvider.getAnyValue('auth') as {
|
|
||||||
default: SCAuthorizationProvider;
|
|
||||||
};
|
|
||||||
this.authConfig = getClientConfig('default', authConfig);
|
|
||||||
this.localConfiguration = new AuthorizationServiceConfiguration(
|
|
||||||
getEndpointsConfig('default', authConfig),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async signOut() {
|
|
||||||
await this.revokeTokens().catch(error => {
|
|
||||||
this.notifyActionListers(AuthActionBuilder.SignOutFailed(error));
|
|
||||||
});
|
|
||||||
this.notifyActionListers(AuthActionBuilder.SignOutSuccess());
|
|
||||||
}
|
|
||||||
|
|
||||||
public async revokeTokens() {
|
|
||||||
// Note: only locally
|
|
||||||
await this.storage.removeItem(TOKEN_RESPONSE_KEY);
|
|
||||||
this.notifyActionListers(AuthActionBuilder.RevokeTokensSuccess());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+5
-4
@@ -13,11 +13,12 @@
|
|||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {HttpClient} from '@angular/common/http';
|
|
||||||
import {Platform} from '@ionic/angular/standalone';
|
import {Platform} from '@ionic/angular/standalone';
|
||||||
|
import {FetchRequestor, Requestor} from '@openid/appauth';
|
||||||
import {CapacitorRequestor} from '../capacitor-requestor';
|
import {CapacitorRequestor} from '../capacitor-requestor';
|
||||||
import {NgHttpService} from '../ng-http.service';
|
|
||||||
|
|
||||||
export const httpFactory = (platform: Platform, httpClient: HttpClient) => {
|
export const requestorFactory = (platform: Platform): Requestor => {
|
||||||
return platform.is('capacitor') ? new CapacitorRequestor() : new NgHttpService(httpClient);
|
return platform.is('capacitor')
|
||||||
|
? new CapacitorRequestor()
|
||||||
|
: new FetchRequestor();
|
||||||
};
|
};
|
||||||
@@ -14,9 +14,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {Platform} from '@ionic/angular/standalone';
|
import {Platform} from '@ionic/angular/standalone';
|
||||||
import {IonicStorage} from 'ionic-appauth/lib';
|
import {LocalStorageBackend, StorageBackend} from '@openid/appauth';
|
||||||
import {SafeCapacitorSecureStorage} from '../../storage/capacitor-secure-storage';
|
import {SafeCapacitorSecureStorage} from '../../storage/capacitor-secure-storage';
|
||||||
|
|
||||||
export const storageFactory = (platform: Platform) => {
|
export const storageFactory = (platform: Platform): StorageBackend => {
|
||||||
return platform.is('capacitor') ? new SafeCapacitorSecureStorage() : new IonicStorage();
|
return platform.is('capacitor')
|
||||||
|
? new SafeCapacitorSecureStorage()
|
||||||
|
: new LocalStorageBackend();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,77 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with
|
|
||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import {Injectable} from '@angular/core';
|
|
||||||
import {Requestor} from '@openid/appauth';
|
|
||||||
import {HttpClient, HttpHeaders} from '@angular/common/http';
|
|
||||||
import {XhrSettings} from 'ionic-appauth/lib/cordova';
|
|
||||||
import {firstValueFrom, Observable} from 'rxjs';
|
|
||||||
|
|
||||||
@Injectable({
|
|
||||||
providedIn: 'root',
|
|
||||||
})
|
|
||||||
export class NgHttpService implements Requestor {
|
|
||||||
constructor(private http: HttpClient) {}
|
|
||||||
|
|
||||||
public async xhr<T>(settings: XhrSettings): Promise<T> {
|
|
||||||
if (!settings.method) {
|
|
||||||
settings.method = 'GET';
|
|
||||||
}
|
|
||||||
|
|
||||||
let observable: Observable<T>;
|
|
||||||
|
|
||||||
switch (settings.method) {
|
|
||||||
case 'GET': {
|
|
||||||
observable = this.http.get<T>(settings.url, {
|
|
||||||
headers: this.getHeaders(settings.headers),
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 'POST': {
|
|
||||||
observable = this.http.post<T>(settings.url, settings.data, {
|
|
||||||
headers: this.getHeaders(settings.headers),
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 'PUT': {
|
|
||||||
observable = this.http.put<T>(settings.url, settings.data, {
|
|
||||||
headers: this.getHeaders(settings.headers),
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 'DELETE': {
|
|
||||||
observable = this.http.delete<T>(settings.url, {
|
|
||||||
headers: this.getHeaders(settings.headers),
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return firstValueFrom(observable);
|
|
||||||
}
|
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
private getHeaders(headers: any): HttpHeaders {
|
|
||||||
let httpHeaders: HttpHeaders = new HttpHeaders();
|
|
||||||
|
|
||||||
if (headers !== undefined) {
|
|
||||||
for (const key of Object.keys(headers)) {
|
|
||||||
httpHeaders = httpHeaders.append(key, headers[key]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return httpHeaders;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,197 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2022 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.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with
|
|
||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import {
|
|
||||||
StorageBackend,
|
|
||||||
BasicQueryStringUtils,
|
|
||||||
DefaultCrypto,
|
|
||||||
AuthorizationServiceConfiguration,
|
|
||||||
AuthorizationRequest,
|
|
||||||
StringMap,
|
|
||||||
AuthorizationError,
|
|
||||||
AuthorizationErrorJson,
|
|
||||||
BUILT_IN_PARAMETERS,
|
|
||||||
} from '@openid/appauth';
|
|
||||||
import {Browser} from 'ionic-appauth';
|
|
||||||
import {PAIAAuthorizationNotifier} from './paia-authorization-notifier';
|
|
||||||
import {PAIAAuthorizationRequestResponse} from './authorization-request-response';
|
|
||||||
import {PAIAAuthorizationResponse, PAIAAuthorizationResponseJson} from './paia-authorization-response';
|
|
||||||
|
|
||||||
/** key for authorization request. */
|
|
||||||
const authorizationRequestKey = (handle: string) => {
|
|
||||||
return `${handle}_appauth_authorization_request`;
|
|
||||||
};
|
|
||||||
|
|
||||||
/** key in local storage which represents the current authorization request. */
|
|
||||||
const AUTHORIZATION_REQUEST_HANDLE_KEY = 'appauth_current_authorization_request';
|
|
||||||
export const AUTHORIZATION_RESPONSE_KEY = 'auth_response';
|
|
||||||
|
|
||||||
export class PAIAAuthorizationRequestHandler {
|
|
||||||
notifier: PAIAAuthorizationNotifier;
|
|
||||||
|
|
||||||
constructor(
|
|
||||||
private browser: Browser,
|
|
||||||
private storage: StorageBackend,
|
|
||||||
public utils = new BasicQueryStringUtils(),
|
|
||||||
protected crypto = new Crypto(),
|
|
||||||
private generateRandom = new DefaultCrypto(),
|
|
||||||
) {}
|
|
||||||
|
|
||||||
public async performAuthorizationRequest(
|
|
||||||
configuration: AuthorizationServiceConfiguration,
|
|
||||||
request: AuthorizationRequest,
|
|
||||||
): Promise<void> {
|
|
||||||
const handle = this.generateRandom.generateRandom(10);
|
|
||||||
await this.storage.setItem(AUTHORIZATION_REQUEST_HANDLE_KEY, handle);
|
|
||||||
await this.storage.setItem(authorizationRequestKey(handle), JSON.stringify(await request.toJson()));
|
|
||||||
const url = this.buildRequestUrl(configuration, request);
|
|
||||||
const returnedUrl: string | undefined = await this.browser.showWindow(url, request.redirectUri);
|
|
||||||
|
|
||||||
// callback may come from showWindow or via another method
|
|
||||||
if (returnedUrl !== undefined) {
|
|
||||||
await this.storage.setItem(AUTHORIZATION_RESPONSE_KEY, returnedUrl);
|
|
||||||
await this.completeAuthorizationRequestIfPossible();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected async completeAuthorizationRequest(): Promise<PAIAAuthorizationRequestResponse> {
|
|
||||||
const handle = await this.storage.getItem(AUTHORIZATION_REQUEST_HANDLE_KEY);
|
|
||||||
|
|
||||||
if (!handle) {
|
|
||||||
throw new Error('Handle Not Available');
|
|
||||||
}
|
|
||||||
|
|
||||||
const request: AuthorizationRequest = this.getAuthorizationRequest(
|
|
||||||
await this.storage.getItem(authorizationRequestKey(handle)),
|
|
||||||
);
|
|
||||||
const queryParameters = this.getQueryParams(await this.storage.getItem(AUTHORIZATION_RESPONSE_KEY));
|
|
||||||
void this.removeItemsFromStorage(handle);
|
|
||||||
|
|
||||||
const state: string | undefined = queryParameters['state'];
|
|
||||||
const error: string | undefined = queryParameters['error'];
|
|
||||||
|
|
||||||
if (state !== request.state) {
|
|
||||||
throw new Error('State Does Not Match');
|
|
||||||
}
|
|
||||||
|
|
||||||
return <PAIAAuthorizationRequestResponse>{
|
|
||||||
request: request, // request
|
|
||||||
response: error ? undefined : this.getAuthorizationResponse(queryParameters),
|
|
||||||
error: error ? this.getAuthorizationError(queryParameters) : undefined,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private getAuthorizationRequest(authRequest: string | null): AuthorizationRequest {
|
|
||||||
if (authRequest == undefined) {
|
|
||||||
throw new Error('No Auth Request Available');
|
|
||||||
}
|
|
||||||
|
|
||||||
return new AuthorizationRequest(JSON.parse(authRequest));
|
|
||||||
}
|
|
||||||
|
|
||||||
private getAuthorizationError(queryParameters: StringMap): AuthorizationError {
|
|
||||||
const authorizationErrorJSON: AuthorizationErrorJson = {
|
|
||||||
error: queryParameters['error'],
|
|
||||||
error_description: queryParameters['error_description'],
|
|
||||||
error_uri: undefined,
|
|
||||||
state: queryParameters['state'],
|
|
||||||
};
|
|
||||||
return new AuthorizationError(authorizationErrorJSON);
|
|
||||||
}
|
|
||||||
|
|
||||||
private getAuthorizationResponse(queryParameters: StringMap): PAIAAuthorizationResponse {
|
|
||||||
const authorizationResponseJSON: PAIAAuthorizationResponseJson = {
|
|
||||||
code: queryParameters['code'],
|
|
||||||
patron: queryParameters['patron'],
|
|
||||||
// TODO: currently PAIA is not providing state
|
|
||||||
state: queryParameters['state'] ?? '',
|
|
||||||
};
|
|
||||||
return new PAIAAuthorizationResponse(authorizationResponseJSON);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async removeItemsFromStorage(handle: string): Promise<void> {
|
|
||||||
await this.storage.removeItem(AUTHORIZATION_REQUEST_HANDLE_KEY);
|
|
||||||
await this.storage.removeItem(authorizationRequestKey(handle));
|
|
||||||
await this.storage.removeItem(AUTHORIZATION_RESPONSE_KEY);
|
|
||||||
}
|
|
||||||
|
|
||||||
private getQueryParams(authResponse: string | null): StringMap {
|
|
||||||
if (authResponse == undefined) {
|
|
||||||
return {};
|
|
||||||
} else {
|
|
||||||
const querySide: string = authResponse.split('#')[0];
|
|
||||||
const parts: string[] = querySide.split('?');
|
|
||||||
if (parts.length !== 2) throw new Error('Invalid auth response string');
|
|
||||||
const hash = parts[1];
|
|
||||||
return this.utils.parseQueryString(hash);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
setAuthorizationNotifier(notifier: PAIAAuthorizationNotifier): PAIAAuthorizationRequestHandler {
|
|
||||||
this.notifier = notifier;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
completeAuthorizationRequestIfPossible(): Promise<void> {
|
|
||||||
// call complete authorization if possible to see there might
|
|
||||||
// be a response that needs to be delivered.
|
|
||||||
console.log(`Checking to see if there is an authorization response to be delivered.`);
|
|
||||||
if (!this.notifier) {
|
|
||||||
console.log(`Notifier is not present on AuthorizationRequest handler.
|
|
||||||
No delivery of result will be possible`);
|
|
||||||
}
|
|
||||||
return this.completeAuthorizationRequest().then(result => {
|
|
||||||
if (!result) {
|
|
||||||
console.log(`No result is available yet.`);
|
|
||||||
}
|
|
||||||
if (result && this.notifier) {
|
|
||||||
this.notifier.onAuthorizationComplete(result.request, result.response, result.error);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A utility method to be able to build the authorization request URL.
|
|
||||||
*/
|
|
||||||
protected buildRequestUrl(configuration: AuthorizationServiceConfiguration, request: AuthorizationRequest) {
|
|
||||||
// build the query string
|
|
||||||
// coerce to any type for convenience
|
|
||||||
const requestMap: StringMap = {
|
|
||||||
redirect_uri: request.redirectUri,
|
|
||||||
client_id: request.clientId,
|
|
||||||
response_type: request.responseType,
|
|
||||||
state: request.state,
|
|
||||||
scope: request.scope,
|
|
||||||
};
|
|
||||||
|
|
||||||
// copy over extras
|
|
||||||
if (request.extras) {
|
|
||||||
for (const extra in request.extras) {
|
|
||||||
if (
|
|
||||||
request.extras.hasOwnProperty(extra) && // check before inserting to requestMap
|
|
||||||
!BUILT_IN_PARAMETERS.includes(extra)
|
|
||||||
) {
|
|
||||||
requestMap[extra] = request.extras[extra];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const query = this.utils.stringify(requestMap);
|
|
||||||
const baseUrl = configuration.authorizationEndpoint;
|
|
||||||
|
|
||||||
// required encoding (PAIA specific)
|
|
||||||
return `${baseUrl}?${encodeURIComponent(query)}`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2021 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.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with
|
|
||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import {AuthorizationError, AuthorizationRequest} from '@openid/appauth';
|
|
||||||
import {PAIAAuthorizationResponse} from './paia-authorization-response';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents a structural type holding both authorization request and response.
|
|
||||||
*/
|
|
||||||
export interface PAIAAuthorizationRequestResponse {
|
|
||||||
request: AuthorizationRequest;
|
|
||||||
response: PAIAAuthorizationResponse | null;
|
|
||||||
error: AuthorizationError | null;
|
|
||||||
}
|
|
||||||
@@ -1,75 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2022 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.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with
|
|
||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import {PAIATokenResponse} from './paia-token-response';
|
|
||||||
import {AuthActionBuilder, IAuthAction} from 'ionic-appauth';
|
|
||||||
|
|
||||||
export interface IPAIAAuthAction extends IAuthAction {
|
|
||||||
tokenResponse?: PAIATokenResponse;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class PAIAAuthActionBuilder extends AuthActionBuilder {
|
|
||||||
public static Init(): IPAIAAuthAction {
|
|
||||||
return AuthActionBuilder.Init() as IPAIAAuthAction;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SignOutSuccess(): IPAIAAuthAction {
|
|
||||||
return AuthActionBuilder.SignOutSuccess() as IPAIAAuthAction;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SignOutFailed(error: Error): IPAIAAuthAction {
|
|
||||||
return AuthActionBuilder.SignOutFailed(error) as IPAIAAuthAction;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static RefreshSuccess(tokenResponse: PAIATokenResponse): IPAIAAuthAction {
|
|
||||||
return AuthActionBuilder.RefreshSuccess(tokenResponse) as IPAIAAuthAction;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static RefreshFailed(error: Error): IPAIAAuthAction {
|
|
||||||
return AuthActionBuilder.RefreshFailed(error) as IPAIAAuthAction;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SignInSuccess(tokenResponse: PAIATokenResponse): IPAIAAuthAction {
|
|
||||||
return AuthActionBuilder.SignInSuccess(tokenResponse) as IPAIAAuthAction;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SignInFailed(error: Error): IPAIAAuthAction {
|
|
||||||
return AuthActionBuilder.SignInFailed(error) as IPAIAAuthAction;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static LoadTokenFromStorageSuccess(tokenResponse: PAIATokenResponse): IPAIAAuthAction {
|
|
||||||
return AuthActionBuilder.LoadTokenFromStorageSuccess(tokenResponse) as IPAIAAuthAction;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static LoadTokenFromStorageFailed(error: Error): IPAIAAuthAction {
|
|
||||||
return AuthActionBuilder.LoadTokenFromStorageFailed(error) as IPAIAAuthAction;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static RevokeTokensSuccess(): IPAIAAuthAction {
|
|
||||||
return AuthActionBuilder.RevokeTokensSuccess() as IPAIAAuthAction;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static RevokeTokensFailed(error: Error): IPAIAAuthAction {
|
|
||||||
return AuthActionBuilder.RevokeTokensFailed(error) as IPAIAAuthAction;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static LoadUserInfoSuccess(user: Error): IPAIAAuthAction {
|
|
||||||
return AuthActionBuilder.LoadUserInfoSuccess(user) as IPAIAAuthAction;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static LoadUserInfoFailed(error: Error): IPAIAAuthAction {
|
|
||||||
return AuthActionBuilder.LoadUserInfoFailed(error) as IPAIAAuthAction;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,365 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with
|
|
||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import {
|
|
||||||
AuthorizationError,
|
|
||||||
AuthorizationRequest,
|
|
||||||
AuthorizationRequestJson,
|
|
||||||
AuthorizationServiceConfiguration,
|
|
||||||
BasicQueryStringUtils,
|
|
||||||
DefaultCrypto,
|
|
||||||
JQueryRequestor,
|
|
||||||
LocalStorageBackend,
|
|
||||||
Requestor,
|
|
||||||
StorageBackend,
|
|
||||||
StringMap,
|
|
||||||
TokenResponse,
|
|
||||||
} from '@openid/appauth';
|
|
||||||
import {
|
|
||||||
AuthActions,
|
|
||||||
AUTHORIZATION_RESPONSE_KEY,
|
|
||||||
AuthSubject,
|
|
||||||
Browser,
|
|
||||||
DefaultBrowser,
|
|
||||||
EndSessionHandler,
|
|
||||||
IAuthConfig,
|
|
||||||
IonicEndSessionHandler,
|
|
||||||
IonicUserInfoHandler,
|
|
||||||
UserInfoHandler,
|
|
||||||
} from 'ionic-appauth';
|
|
||||||
import {BehaviorSubject, Observable} from 'rxjs';
|
|
||||||
import {PAIATokenRequestHandler} from './token-request-handler';
|
|
||||||
import {PAIAAuthorizationRequestHandler} from './authorization-request-handler';
|
|
||||||
import {PAIATokenRequest, PAIATokenRequestJson} from './paia-token-request';
|
|
||||||
import {PAIAAuthorizationResponse} from './paia-authorization-response';
|
|
||||||
import {PAIAAuthorizationNotifier} from './paia-authorization-notifier';
|
|
||||||
import {PAIATokenResponse} from './paia-token-response';
|
|
||||||
import {IPAIAAuthAction, PAIAAuthActionBuilder} from './paia-auth-action';
|
|
||||||
import {SCAuthorizationProvider} from '@openstapps/core';
|
|
||||||
import {ConfigProvider} from '../../config/config.provider';
|
|
||||||
import {getClientConfig, getEndpointsConfig} from '../auth.provider.methods';
|
|
||||||
import {Injectable} from '@angular/core';
|
|
||||||
|
|
||||||
const TOKEN_RESPONSE_KEY = 'paia_token_response';
|
|
||||||
const AUTH_EXPIRY_BUFFER = 10 * 60 * -1; // 10 minutes in seconds
|
|
||||||
|
|
||||||
export interface IAuthService {
|
|
||||||
signIn(authExtras?: StringMap, state?: string): void;
|
|
||||||
signOut(state?: string, revokeTokens?: boolean): void;
|
|
||||||
loadUserInfo(): void;
|
|
||||||
authorizationCallback(callbackUrl: string): void;
|
|
||||||
loadTokenFromStorage(): void;
|
|
||||||
getValidToken(buffer?: number): Promise<PAIATokenResponse>;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Injectable({
|
|
||||||
providedIn: 'root',
|
|
||||||
})
|
|
||||||
export class PAIAAuthService {
|
|
||||||
private _authConfig?: IAuthConfig;
|
|
||||||
|
|
||||||
private _authSubject: AuthSubject = new AuthSubject();
|
|
||||||
|
|
||||||
private _authSubjectV2 = new BehaviorSubject<IPAIAAuthAction>(PAIAAuthActionBuilder.Init());
|
|
||||||
|
|
||||||
private _tokenSubject = new BehaviorSubject<PAIATokenResponse | undefined>(undefined);
|
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
private _userSubject = new BehaviorSubject<any>(undefined);
|
|
||||||
|
|
||||||
private _authenticatedSubject = new BehaviorSubject<boolean>(false);
|
|
||||||
|
|
||||||
private _loggedIn = new BehaviorSubject<boolean>(false);
|
|
||||||
|
|
||||||
private _initComplete = new BehaviorSubject<boolean>(false);
|
|
||||||
|
|
||||||
protected tokenHandler: PAIATokenRequestHandler;
|
|
||||||
|
|
||||||
protected userInfoHandler: UserInfoHandler;
|
|
||||||
|
|
||||||
protected requestHandler: PAIAAuthorizationRequestHandler;
|
|
||||||
|
|
||||||
protected endSessionHandler: EndSessionHandler;
|
|
||||||
|
|
||||||
public localConfiguration: AuthorizationServiceConfiguration;
|
|
||||||
|
|
||||||
constructor(
|
|
||||||
protected browser: Browser = new DefaultBrowser(),
|
|
||||||
protected storage: StorageBackend = new LocalStorageBackend(),
|
|
||||||
protected requestor: Requestor = new JQueryRequestor(),
|
|
||||||
private readonly configProvider: ConfigProvider,
|
|
||||||
) {
|
|
||||||
this.tokenHandler = new PAIATokenRequestHandler(requestor);
|
|
||||||
this.userInfoHandler = new IonicUserInfoHandler(requestor);
|
|
||||||
this.requestHandler = new PAIAAuthorizationRequestHandler(
|
|
||||||
browser,
|
|
||||||
storage,
|
|
||||||
new BasicQueryStringUtils(),
|
|
||||||
crypto,
|
|
||||||
);
|
|
||||||
this.endSessionHandler = new IonicEndSessionHandler(browser);
|
|
||||||
}
|
|
||||||
|
|
||||||
get token$(): Observable<PAIATokenResponse | undefined> {
|
|
||||||
return this._tokenSubject.asObservable();
|
|
||||||
}
|
|
||||||
|
|
||||||
get isAuthenticated$(): Observable<boolean> {
|
|
||||||
return this._authenticatedSubject.asObservable();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Similar to isAuthenticated$, but will also return true if the token is expired
|
|
||||||
*/
|
|
||||||
get isLoggedIn$(): Observable<boolean> {
|
|
||||||
return this._loggedIn.asObservable();
|
|
||||||
}
|
|
||||||
|
|
||||||
get initComplete$(): Observable<boolean> {
|
|
||||||
return this._initComplete.asObservable();
|
|
||||||
}
|
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
get user$(): Observable<any> {
|
|
||||||
return this._userSubject.asObservable();
|
|
||||||
}
|
|
||||||
|
|
||||||
get events$(): Observable<IPAIAAuthAction> {
|
|
||||||
return this._authSubjectV2.asObservable();
|
|
||||||
}
|
|
||||||
|
|
||||||
get authConfig(): IAuthConfig {
|
|
||||||
if (!this._authConfig) throw new Error('AuthConfig Not Defined');
|
|
||||||
|
|
||||||
return this._authConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
set authConfig(value: IAuthConfig) {
|
|
||||||
this._authConfig = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
get configuration(): Promise<AuthorizationServiceConfiguration> {
|
|
||||||
if (!this.localConfiguration) throw new Error('Local Configuration Not Defined');
|
|
||||||
|
|
||||||
return Promise.resolve(this.localConfiguration);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async init() {
|
|
||||||
this.setupConfiguration();
|
|
||||||
this.setupAuthorizationNotifier();
|
|
||||||
await this.loadTokenFromStorage();
|
|
||||||
}
|
|
||||||
|
|
||||||
setupConfiguration() {
|
|
||||||
const authConfig = this.configProvider.getAnyValue('auth') as {
|
|
||||||
paia: SCAuthorizationProvider;
|
|
||||||
};
|
|
||||||
this.authConfig = getClientConfig('paia', authConfig);
|
|
||||||
this.localConfiguration = new AuthorizationServiceConfiguration(getEndpointsConfig('paia', authConfig));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected notifyActionListers(action: IPAIAAuthAction) {
|
|
||||||
/* eslint-disable unicorn/no-useless-undefined */
|
|
||||||
switch (action.action) {
|
|
||||||
case AuthActions.SignInFailed:
|
|
||||||
case AuthActions.SignOutSuccess:
|
|
||||||
case AuthActions.SignOutFailed: {
|
|
||||||
this._tokenSubject.next(undefined);
|
|
||||||
this._userSubject.next(undefined);
|
|
||||||
this._authenticatedSubject.next(false);
|
|
||||||
this._loggedIn.next(false);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case AuthActions.LoadTokenFromStorageFailed: {
|
|
||||||
this._tokenSubject.next(undefined);
|
|
||||||
this._userSubject.next(undefined);
|
|
||||||
this._authenticatedSubject.next(false);
|
|
||||||
this._loggedIn.next(false);
|
|
||||||
this._initComplete.next(true);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case AuthActions.SignInSuccess: {
|
|
||||||
this._tokenSubject.next(action.tokenResponse);
|
|
||||||
this._authenticatedSubject.next(true);
|
|
||||||
this._loggedIn.next(true);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case AuthActions.LoadTokenFromStorageSuccess: {
|
|
||||||
this._tokenSubject.next(action.tokenResponse);
|
|
||||||
this._authenticatedSubject.next((action.tokenResponse as TokenResponse).isValid(0));
|
|
||||||
this._loggedIn.next(true);
|
|
||||||
this._initComplete.next(true);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case AuthActions.RevokeTokensSuccess: {
|
|
||||||
this._tokenSubject.next(undefined);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case AuthActions.LoadUserInfoSuccess: {
|
|
||||||
this._userSubject.next(action.user);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case AuthActions.LoadUserInfoFailed: {
|
|
||||||
this._userSubject.next(undefined);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this._authSubjectV2.next(action);
|
|
||||||
this._authSubject.notify(action);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected setupAuthorizationNotifier() {
|
|
||||||
const notifier = new PAIAAuthorizationNotifier();
|
|
||||||
this.requestHandler.setAuthorizationNotifier(notifier);
|
|
||||||
notifier.setAuthorizationListener((request, response, error) =>
|
|
||||||
this.onAuthorizationNotification(request, response, error),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected onAuthorizationNotification(
|
|
||||||
request: AuthorizationRequest,
|
|
||||||
response: PAIAAuthorizationResponse | null,
|
|
||||||
error: AuthorizationError | null,
|
|
||||||
) {
|
|
||||||
const codeVerifier: string | undefined =
|
|
||||||
request.internal != undefined && this.authConfig.pkce ? request.internal.code_verifier : undefined;
|
|
||||||
|
|
||||||
if (response != undefined) {
|
|
||||||
this.requestAccessToken(response.code, response.patron, codeVerifier);
|
|
||||||
} else if (error == undefined) {
|
|
||||||
throw new Error('Unknown Error With Authentication');
|
|
||||||
} else {
|
|
||||||
throw new Error(error.errorDescription);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected async internalAuthorizationCallback(url: string) {
|
|
||||||
this.browser.closeWindow();
|
|
||||||
await this.storage.setItem(AUTHORIZATION_RESPONSE_KEY, url);
|
|
||||||
return this.requestHandler.completeAuthorizationRequestIfPossible();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected async performAuthorizationRequest(authExtras?: StringMap, state?: string): Promise<void> {
|
|
||||||
const requestJson: AuthorizationRequestJson = {
|
|
||||||
response_type: AuthorizationRequest.RESPONSE_TYPE_CODE,
|
|
||||||
client_id: this.authConfig.client_id,
|
|
||||||
redirect_uri: this.authConfig.redirect_url,
|
|
||||||
scope: this.authConfig.scopes,
|
|
||||||
extras: authExtras,
|
|
||||||
state: state || undefined,
|
|
||||||
};
|
|
||||||
|
|
||||||
const request = new AuthorizationRequest(requestJson, new DefaultCrypto(), this.authConfig.pkce);
|
|
||||||
|
|
||||||
if (this.authConfig.pkce) await request.setupCodeVerifier();
|
|
||||||
|
|
||||||
return this.requestHandler.performAuthorizationRequest(await this.configuration, request);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected async requestAccessToken(code: string, patron: string, codeVerifier?: string): Promise<void> {
|
|
||||||
const requestJSON: PAIATokenRequestJson = {
|
|
||||||
code: code,
|
|
||||||
patron: patron,
|
|
||||||
extras: codeVerifier
|
|
||||||
? {
|
|
||||||
code_verifier: codeVerifier,
|
|
||||||
}
|
|
||||||
: {},
|
|
||||||
};
|
|
||||||
|
|
||||||
const token: PAIATokenResponse = await this.tokenHandler.performTokenRequest(
|
|
||||||
await this.configuration,
|
|
||||||
new PAIATokenRequest(requestJSON),
|
|
||||||
);
|
|
||||||
await this.storage.setItem(TOKEN_RESPONSE_KEY, JSON.stringify(token.toJson()));
|
|
||||||
this.notifyActionListers(PAIAAuthActionBuilder.SignInSuccess(token));
|
|
||||||
}
|
|
||||||
|
|
||||||
public async revokeTokens() {
|
|
||||||
// Note: only locally
|
|
||||||
await this.storage.removeItem(TOKEN_RESPONSE_KEY);
|
|
||||||
this.notifyActionListers(PAIAAuthActionBuilder.RevokeTokensSuccess());
|
|
||||||
}
|
|
||||||
|
|
||||||
public async signOut() {
|
|
||||||
await this.revokeTokens().catch(error =>
|
|
||||||
this.notifyActionListers(PAIAAuthActionBuilder.SignOutFailed(error)),
|
|
||||||
);
|
|
||||||
this.notifyActionListers(PAIAAuthActionBuilder.SignOutSuccess());
|
|
||||||
}
|
|
||||||
|
|
||||||
protected async internalLoadTokenFromStorage() {
|
|
||||||
let token: PAIATokenResponse | undefined;
|
|
||||||
const tokenResponseString: string | null = await this.storage.getItem(TOKEN_RESPONSE_KEY);
|
|
||||||
|
|
||||||
if (tokenResponseString != undefined) {
|
|
||||||
token = new PAIATokenResponse(JSON.parse(tokenResponseString));
|
|
||||||
|
|
||||||
if (token) {
|
|
||||||
return this.notifyActionListers(PAIAAuthActionBuilder.LoadTokenFromStorageSuccess(token));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new Error('No Token In Storage');
|
|
||||||
}
|
|
||||||
|
|
||||||
protected async internalRequestUserInfo() {
|
|
||||||
if (this._tokenSubject.value) {
|
|
||||||
const userInfo = await this.userInfoHandler.performUserInfoRequest(
|
|
||||||
await this.configuration,
|
|
||||||
this._tokenSubject.value,
|
|
||||||
);
|
|
||||||
this.notifyActionListers(PAIAAuthActionBuilder.LoadUserInfoSuccess(userInfo));
|
|
||||||
} else {
|
|
||||||
throw new Error('No Token Available');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public async loadTokenFromStorage() {
|
|
||||||
await this.internalLoadTokenFromStorage().catch(error => {
|
|
||||||
this.notifyActionListers(PAIAAuthActionBuilder.LoadTokenFromStorageFailed(error));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public async signIn(authExtras?: StringMap, state?: string) {
|
|
||||||
await this.performAuthorizationRequest(authExtras, state).catch(error => {
|
|
||||||
this.notifyActionListers(PAIAAuthActionBuilder.SignInFailed(error));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public async loadUserInfo() {
|
|
||||||
await this.internalRequestUserInfo().catch(error => {
|
|
||||||
this.notifyActionListers(PAIAAuthActionBuilder.LoadUserInfoFailed(error));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public authorizationCallback(callbackUrl: string): void {
|
|
||||||
this.internalAuthorizationCallback(callbackUrl).catch(error => {
|
|
||||||
this.notifyActionListers(PAIAAuthActionBuilder.SignInFailed(error));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public async getValidToken(buffer: number = AUTH_EXPIRY_BUFFER): Promise<PAIATokenResponse> {
|
|
||||||
if (this._tokenSubject.value && this._tokenSubject.value.isValid(buffer)) {
|
|
||||||
return this._tokenSubject.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
const error = new Error('Unable To Obtain Valid Token');
|
|
||||||
this.notifyActionListers(PAIAAuthActionBuilder.SignInFailed(error));
|
|
||||||
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2021 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.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with
|
|
||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import {AuthorizationError, AuthorizationRequest} from '@openid/appauth';
|
|
||||||
import {PAIAAuthorizationResponse} from './paia-authorization-response';
|
|
||||||
|
|
||||||
export type PAIAAuthorizationListener = (
|
|
||||||
request: AuthorizationRequest,
|
|
||||||
response: PAIAAuthorizationResponse | null,
|
|
||||||
error: AuthorizationError | null,
|
|
||||||
) => void;
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2021 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.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with
|
|
||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
import {PAIAAuthorizationListener} from './paia-authorization-listener';
|
|
||||||
import {AuthorizationError, AuthorizationRequest} from '@openid/appauth';
|
|
||||||
import {PAIAAuthorizationResponse} from './paia-authorization-response';
|
|
||||||
|
|
||||||
export class PAIAAuthorizationNotifier {
|
|
||||||
// eslint-disable-next-line unicorn/no-null
|
|
||||||
private listener: PAIAAuthorizationListener | null = null;
|
|
||||||
|
|
||||||
setAuthorizationListener(listener: PAIAAuthorizationListener) {
|
|
||||||
this.listener = listener;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The authorization complete callback.
|
|
||||||
*/
|
|
||||||
onAuthorizationComplete(
|
|
||||||
request: AuthorizationRequest,
|
|
||||||
response: PAIAAuthorizationResponse | null,
|
|
||||||
error: AuthorizationError | null,
|
|
||||||
): void {
|
|
||||||
if (this.listener) {
|
|
||||||
// complete authorization request
|
|
||||||
this.listener(request, response, error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2021 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.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with
|
|
||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
export interface PAIAAuthorizationResponseJson {
|
|
||||||
code: string;
|
|
||||||
state: string;
|
|
||||||
patron: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class PAIAAuthorizationResponse {
|
|
||||||
code: string;
|
|
||||||
|
|
||||||
state: string;
|
|
||||||
|
|
||||||
patron: string;
|
|
||||||
|
|
||||||
constructor(response: PAIAAuthorizationResponseJson) {
|
|
||||||
this.code = response.code;
|
|
||||||
this.state = response.state;
|
|
||||||
this.patron = response.patron;
|
|
||||||
}
|
|
||||||
|
|
||||||
toJson(): PAIAAuthorizationResponseJson {
|
|
||||||
return {code: this.code, state: this.state, patron: this.patron};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2021 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.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with
|
|
||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
import {StringMap} from '@openid/appauth';
|
|
||||||
|
|
||||||
// TODO: add documentation
|
|
||||||
export interface PAIATokenRequestJson {
|
|
||||||
code: string;
|
|
||||||
patron: string;
|
|
||||||
extras?: StringMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class PAIATokenRequest {
|
|
||||||
code: string;
|
|
||||||
|
|
||||||
patron: string;
|
|
||||||
|
|
||||||
extras?: StringMap;
|
|
||||||
|
|
||||||
constructor(request: PAIATokenRequestJson) {
|
|
||||||
this.code = request.code;
|
|
||||||
this.patron = request.patron;
|
|
||||||
this.extras = request.extras;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Serializes a TokenRequest to a JavaScript object.
|
|
||||||
*/
|
|
||||||
toJson(): PAIATokenRequestJson {
|
|
||||||
return {
|
|
||||||
code: this.code,
|
|
||||||
patron: this.patron,
|
|
||||||
extras: this.extras,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
toStringMap(): StringMap {
|
|
||||||
const map: StringMap = {
|
|
||||||
patron: this.patron,
|
|
||||||
code: this.code,
|
|
||||||
};
|
|
||||||
|
|
||||||
// copy over extras
|
|
||||||
if (this.extras) {
|
|
||||||
for (const extra in this.extras) {
|
|
||||||
if (this.extras.hasOwnProperty(extra) && !map.hasOwnProperty(extra)) {
|
|
||||||
// check before inserting to requestMap
|
|
||||||
map[extra] = this.extras[extra];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return map;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2021 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.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with
|
|
||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import {TokenResponse, TokenResponseJson} from '@openid/appauth';
|
|
||||||
import {nowInSeconds} from '@openid/appauth';
|
|
||||||
|
|
||||||
const AUTH_EXPIRY_BUFFER = 10 * 60 * -1; // 10 mins in seconds
|
|
||||||
|
|
||||||
export interface PAIATokenResponseJson extends TokenResponseJson {
|
|
||||||
patron: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class PAIATokenResponse extends TokenResponse {
|
|
||||||
patron: string;
|
|
||||||
|
|
||||||
constructor(response: PAIATokenResponseJson) {
|
|
||||||
super(response);
|
|
||||||
this.patron = response.patron;
|
|
||||||
}
|
|
||||||
|
|
||||||
toJson(): PAIATokenResponseJson {
|
|
||||||
return {
|
|
||||||
access_token: this.accessToken,
|
|
||||||
id_token: this.idToken,
|
|
||||||
refresh_token: this.refreshToken,
|
|
||||||
scope: this.scope,
|
|
||||||
token_type: this.tokenType,
|
|
||||||
issued_at: this.issuedAt,
|
|
||||||
expires_in: this.expiresIn?.toString(),
|
|
||||||
patron: this.patron,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
isValid(buffer: number = AUTH_EXPIRY_BUFFER): boolean {
|
|
||||||
if (this.expiresIn) {
|
|
||||||
const now = nowInSeconds();
|
|
||||||
return now < this.issuedAt + this.expiresIn + buffer;
|
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2022 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.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with
|
|
||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
import {AuthorizationServiceConfiguration, Requestor} from '@openid/appauth';
|
|
||||||
import {PAIATokenResponse} from './paia-token-response';
|
|
||||||
|
|
||||||
export interface UserInfoHandler {
|
|
||||||
performUserInfoRequest(
|
|
||||||
configuration: AuthorizationServiceConfiguration,
|
|
||||||
token: PAIATokenResponse,
|
|
||||||
): Promise<unknown>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class PAIAUserInfoHandler implements UserInfoHandler {
|
|
||||||
constructor(private requestor: Requestor) {}
|
|
||||||
|
|
||||||
public async performUserInfoRequest(
|
|
||||||
configuration: AuthorizationServiceConfiguration,
|
|
||||||
token: PAIATokenResponse,
|
|
||||||
): Promise<unknown> {
|
|
||||||
const settings: JQueryAjaxSettings = {
|
|
||||||
url: `${configuration.userInfoEndpoint}/${token.patron}`,
|
|
||||||
method: 'GET',
|
|
||||||
headers: {
|
|
||||||
Authorization: `${token.tokenType == 'bearer' ? 'Bearer' : token.tokenType} ${token.accessToken}`,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
return this.requestor.xhr(settings);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,81 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2022 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.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with
|
|
||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
import {
|
|
||||||
TokenErrorJson,
|
|
||||||
AuthorizationServiceConfiguration,
|
|
||||||
RevokeTokenRequest,
|
|
||||||
Requestor,
|
|
||||||
JQueryRequestor,
|
|
||||||
BasicQueryStringUtils,
|
|
||||||
QueryStringUtils,
|
|
||||||
AppAuthError,
|
|
||||||
TokenError,
|
|
||||||
} from '@openid/appauth';
|
|
||||||
import {PAIATokenRequest} from './paia-token-request';
|
|
||||||
import {PAIATokenResponse, PAIATokenResponseJson} from './paia-token-response';
|
|
||||||
|
|
||||||
export class PAIATokenRequestHandler {
|
|
||||||
constructor(
|
|
||||||
public readonly requestor: Requestor = new JQueryRequestor(),
|
|
||||||
public readonly utils: QueryStringUtils = new BasicQueryStringUtils(),
|
|
||||||
) {}
|
|
||||||
|
|
||||||
private isTokenResponse(
|
|
||||||
response: PAIATokenResponseJson | TokenErrorJson,
|
|
||||||
): response is PAIATokenResponseJson {
|
|
||||||
return (response as TokenErrorJson).error === undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
performRevokeTokenRequest(
|
|
||||||
configuration: AuthorizationServiceConfiguration,
|
|
||||||
request: RevokeTokenRequest,
|
|
||||||
): Promise<boolean> {
|
|
||||||
const revokeTokenResponse = this.requestor.xhr<boolean>({
|
|
||||||
url: configuration.revocationEndpoint,
|
|
||||||
method: 'GET',
|
|
||||||
// headers: {'Content-Type': 'application/x-www-form-urlencoded'},
|
|
||||||
data: this.utils.stringify(request.toStringMap()),
|
|
||||||
});
|
|
||||||
|
|
||||||
return revokeTokenResponse.then(_response => {
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
performTokenRequest(
|
|
||||||
configuration: AuthorizationServiceConfiguration,
|
|
||||||
request: PAIATokenRequest,
|
|
||||||
): Promise<PAIATokenResponse> {
|
|
||||||
const tokenResponse = this.requestor.xhr<PAIATokenResponseJson | TokenErrorJson>({
|
|
||||||
url: configuration.tokenEndpoint,
|
|
||||||
method: 'POST',
|
|
||||||
data: {
|
|
||||||
patron: request.patron,
|
|
||||||
grant_type: 'authorization_code',
|
|
||||||
...request.toStringMap(),
|
|
||||||
},
|
|
||||||
headers: {
|
|
||||||
'Authorization': `Basic ${request.code}`,
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
return tokenResponse.then(response => {
|
|
||||||
return this.isTokenResponse(response)
|
|
||||||
? new PAIATokenResponse(response)
|
|
||||||
: Promise.reject<PAIATokenResponse>(new AppAuthError(response.error, new TokenError(response)));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2022 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.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with
|
|
||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
export interface IUserInfo {
|
|
||||||
display_name: string;
|
|
||||||
role: string;
|
|
||||||
email: string;
|
|
||||||
user_name: string;
|
|
||||||
}
|
|
||||||
@@ -114,10 +114,6 @@ import {SkeletonListComponent} from './list/skeleton-list.component';
|
|||||||
import {TreeListFragmentComponent} from './list/tree-list-fragment.component';
|
import {TreeListFragmentComponent} from './list/tree-list-fragment.component';
|
||||||
import {TreeListComponent} from './list/tree-list.component';
|
import {TreeListComponent} from './list/tree-list.component';
|
||||||
import {StAppsWebHttpClient} from './stapps-web-http-client.provider';
|
import {StAppsWebHttpClient} from './stapps-web-http-client.provider';
|
||||||
import {ArticleDetailContentComponent} from './types/article/article-detail-content.component';
|
|
||||||
import {ArticleListItemComponent} from './types/article/article-item.component';
|
|
||||||
import {BookDetailContentComponent} from './types/book/book-detail-content.component';
|
|
||||||
import {BookListItemComponent} from './types/book/book-list-item.component';
|
|
||||||
import {CatalogDetailContentComponent} from './types/catalog/catalog-detail-content.component';
|
import {CatalogDetailContentComponent} from './types/catalog/catalog-detail-content.component';
|
||||||
import {CatalogListItemComponent} from './types/catalog/catalog-list-item.component';
|
import {CatalogListItemComponent} from './types/catalog/catalog-list-item.component';
|
||||||
import {DateSeriesDetailContentComponent} from './types/date-series/date-series-detail-content.component';
|
import {DateSeriesDetailContentComponent} from './types/date-series/date-series-detail-content.component';
|
||||||
@@ -136,8 +132,6 @@ import {MessageDetailContentComponent} from './types/message/message-detail-cont
|
|||||||
import {MessageListItemComponent} from './types/message/message-list-item.component';
|
import {MessageListItemComponent} from './types/message/message-list-item.component';
|
||||||
import {OrganizationDetailContentComponent} from './types/organization/organization-detail-content.component';
|
import {OrganizationDetailContentComponent} from './types/organization/organization-detail-content.component';
|
||||||
import {OrganizationListItemComponent} from './types/organization/organization-list-item.component';
|
import {OrganizationListItemComponent} from './types/organization/organization-list-item.component';
|
||||||
import {PeriodicalDetailContentComponent} from './types/periodical/periodical-detail-content.component';
|
|
||||||
import {PeriodicalListItemComponent} from './types/periodical/periodical-list-item.component';
|
|
||||||
import {PersonDetailContentComponent} from './types/person/person-detail-content.component';
|
import {PersonDetailContentComponent} from './types/person/person-detail-content.component';
|
||||||
import {PersonListItemComponent} from './types/person/person-list-item.component';
|
import {PersonListItemComponent} from './types/person/person-list-item.component';
|
||||||
import {PlaceDetailContentComponent} from './types/place/place-detail-content.component';
|
import {PlaceDetailContentComponent} from './types/place/place-detail-content.component';
|
||||||
@@ -216,12 +210,6 @@ import {IonIconDirective} from 'src/app/util/ion-icon/ion-icon.directive';
|
|||||||
SimpleDataListComponent,
|
SimpleDataListComponent,
|
||||||
TitleCardComponent,
|
TitleCardComponent,
|
||||||
ExternalLinkComponent,
|
ExternalLinkComponent,
|
||||||
ArticleListItemComponent,
|
|
||||||
ArticleDetailContentComponent,
|
|
||||||
BookListItemComponent,
|
|
||||||
BookDetailContentComponent,
|
|
||||||
PeriodicalListItemComponent,
|
|
||||||
PeriodicalDetailContentComponent,
|
|
||||||
ShareButtonComponent,
|
ShareButtonComponent,
|
||||||
],
|
],
|
||||||
exports: [
|
exports: [
|
||||||
@@ -241,9 +229,6 @@ import {IonIconDirective} from 'src/app/util/ion-icon/ion-icon.directive';
|
|||||||
FavoriteButtonComponent,
|
FavoriteButtonComponent,
|
||||||
TreeListComponent,
|
TreeListComponent,
|
||||||
ExternalLinkComponent,
|
ExternalLinkComponent,
|
||||||
ArticleDetailContentComponent,
|
|
||||||
BookDetailContentComponent,
|
|
||||||
PeriodicalDetailContentComponent,
|
|
||||||
TitleCardComponent,
|
TitleCardComponent,
|
||||||
],
|
],
|
||||||
imports: [
|
imports: [
|
||||||
|
|||||||
@@ -33,9 +33,6 @@
|
|||||||
<ng-template #defaultContent>
|
<ng-template #defaultContent>
|
||||||
<div class="content-switch">
|
<div class="content-switch">
|
||||||
@switch (item.type) {
|
@switch (item.type) {
|
||||||
@case ('article') {
|
|
||||||
<stapps-article-detail-content [item]="$any(item)"></stapps-article-detail-content>
|
|
||||||
}
|
|
||||||
@case ('catalog') {
|
@case ('catalog') {
|
||||||
<stapps-catalog-detail-content [item]="$any(item)"></stapps-catalog-detail-content>
|
<stapps-catalog-detail-content [item]="$any(item)"></stapps-catalog-detail-content>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,6 @@
|
|||||||
*/
|
*/
|
||||||
import {ComponentRef, Directive, Input, Type, ViewContainerRef} from '@angular/core';
|
import {ComponentRef, Directive, Input, Type, ViewContainerRef} from '@angular/core';
|
||||||
import {SCThings, SCThingType} from '@openstapps/core';
|
import {SCThings, SCThingType} from '@openstapps/core';
|
||||||
import {BookListItemComponent} from '../types/book/book-list-item.component';
|
|
||||||
import {CatalogListItemComponent} from '../types/catalog/catalog-list-item.component';
|
import {CatalogListItemComponent} from '../types/catalog/catalog-list-item.component';
|
||||||
import {DateSeriesListItemComponent} from '../types/date-series/date-series-list-item.component';
|
import {DateSeriesListItemComponent} from '../types/date-series/date-series-list-item.component';
|
||||||
import {EventListItemComponent} from '../types/event/event-list-item.component';
|
import {EventListItemComponent} from '../types/event/event-list-item.component';
|
||||||
@@ -25,9 +24,7 @@ import {PersonListItemComponent} from '../types/person/person-list-item.componen
|
|||||||
import {PlaceListItemComponent} from '../types/place/place-list-item.component';
|
import {PlaceListItemComponent} from '../types/place/place-list-item.component';
|
||||||
import {SemesterListItemComponent} from '../types/semester/semester-list-item.component';
|
import {SemesterListItemComponent} from '../types/semester/semester-list-item.component';
|
||||||
import {VideoListItemComponent} from '../types/video/video-list-item.component';
|
import {VideoListItemComponent} from '../types/video/video-list-item.component';
|
||||||
import {PeriodicalListItemComponent} from '../types/periodical/periodical-list-item.component';
|
|
||||||
import {DataListItemHostDefaultComponent} from './data-list-item-host-default.component';
|
import {DataListItemHostDefaultComponent} from './data-list-item-host-default.component';
|
||||||
import {ArticleListItemComponent} from '../types/article/article-item.component';
|
|
||||||
import {DishListItemComponent} from '../types/dish/dish-list-item.component';
|
import {DishListItemComponent} from '../types/dish/dish-list-item.component';
|
||||||
import {JobPostingListItemComponent} from '../types/job-posting/job-posting-list-item.component';
|
import {JobPostingListItemComponent} from '../types/job-posting/job-posting-list-item.component';
|
||||||
|
|
||||||
@@ -51,9 +48,6 @@ const DataListItemIndex: Partial<Record<SCThingType, Type<DataListItem>>> = {
|
|||||||
[SCThingType.Room]: PlaceListItemComponent,
|
[SCThingType.Room]: PlaceListItemComponent,
|
||||||
[SCThingType.Semester]: SemesterListItemComponent,
|
[SCThingType.Semester]: SemesterListItemComponent,
|
||||||
[SCThingType.Video]: VideoListItemComponent,
|
[SCThingType.Video]: VideoListItemComponent,
|
||||||
[SCThingType.Periodical]: PeriodicalListItemComponent,
|
|
||||||
[SCThingType.Book]: BookListItemComponent,
|
|
||||||
[SCThingType.Article]: ArticleListItemComponent,
|
|
||||||
[SCThingType.JobPosting]: JobPostingListItemComponent,
|
[SCThingType.JobPosting]: JobPostingListItemComponent,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
<stapps-search-page
|
<stapps-search-page
|
||||||
[title]="'canteens.title' | translate"
|
[title]="'canteens.title' | translate"
|
||||||
[navigation]="[]"
|
|
||||||
[showDefaultData]="true"
|
[showDefaultData]="true"
|
||||||
[forcedFilter]="forcedFilter"
|
[forcedFilter]="forcedFilter"
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -22,14 +22,7 @@ import {
|
|||||||
ModalController,
|
ModalController,
|
||||||
} from '@ionic/angular/standalone';
|
} from '@ionic/angular/standalone';
|
||||||
import {Capacitor} from '@capacitor/core';
|
import {Capacitor} from '@capacitor/core';
|
||||||
import {
|
import {SCFacet, SCSearchFilter, SCSearchQuery, SCSearchSort, SCThings} from '@openstapps/core';
|
||||||
SCFacet,
|
|
||||||
SCFeatureConfiguration,
|
|
||||||
SCSearchFilter,
|
|
||||||
SCSearchQuery,
|
|
||||||
SCSearchSort,
|
|
||||||
SCThings,
|
|
||||||
} from '@openstapps/core';
|
|
||||||
import {NGXLogger} from 'ngx-logger';
|
import {NGXLogger} from 'ngx-logger';
|
||||||
import {combineLatest, Subject} from 'rxjs';
|
import {combineLatest, Subject} from 'rxjs';
|
||||||
import {debounceTime, distinctUntilChanged, startWith} from 'rxjs/operators';
|
import {debounceTime, distinctUntilChanged, startWith} from 'rxjs/operators';
|
||||||
@@ -67,14 +60,6 @@ export class SearchPageComponent implements OnInit {
|
|||||||
*/
|
*/
|
||||||
loading = false;
|
loading = false;
|
||||||
|
|
||||||
/**
|
|
||||||
* Navigation elements between search pages
|
|
||||||
*/
|
|
||||||
@Input() navigation: Array<{label: string; routerLink?: string[]}> = [
|
|
||||||
{label: 'search.type'},
|
|
||||||
{label: 'hebisSearch.type', routerLink: ['/hebis-search']},
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show default data (e.g. when there is user interaction)
|
* Show default data (e.g. when there is user interaction)
|
||||||
*/
|
*/
|
||||||
@@ -353,17 +338,6 @@ export class SearchPageComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
// TODO: make this hack more generic
|
|
||||||
if (this.navigation[1]?.routerLink?.[0] === '/hebis-search') {
|
|
||||||
const features = this.configProvider.getValue('features') as SCFeatureConfiguration;
|
|
||||||
if (features.plugins?.['hebis-plugin']?.urlPath === undefined) {
|
|
||||||
this.navigation = [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
this.logger.error(error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -43,26 +43,6 @@
|
|||||||
</ion-menu-button>
|
</ion-menu-button>
|
||||||
}
|
}
|
||||||
</ion-toolbar>
|
</ion-toolbar>
|
||||||
@if (navigation.length > 0) {
|
|
||||||
<ion-toolbar color="primary" class="category-tab">
|
|
||||||
<ion-buttons class="ion-justify-content-between">
|
|
||||||
@for (target of navigation; track target) {
|
|
||||||
@if (target.routerLink) {
|
|
||||||
<ion-button
|
|
||||||
[routerLink]="target.routerLink"
|
|
||||||
queryParamsHandling="merge"
|
|
||||||
[routerAnimation]="routeAnimation"
|
|
||||||
fill="outline"
|
|
||||||
size="large"
|
|
||||||
>{{ target.label | translate }}
|
|
||||||
</ion-button>
|
|
||||||
} @else {
|
|
||||||
<ion-button class="button-active" size="large">{{ target.label | translate }}</ion-button>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</ion-buttons>
|
|
||||||
</ion-toolbar>
|
|
||||||
}
|
|
||||||
</ion-header>
|
</ion-header>
|
||||||
|
|
||||||
<ion-content class="content">
|
<ion-content class="content">
|
||||||
|
|||||||
@@ -1,24 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2019 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.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with
|
|
||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
import {Component, Input} from '@angular/core';
|
|
||||||
import {SCArticle} from '@openstapps/core';
|
|
||||||
|
|
||||||
@Component({
|
|
||||||
selector: 'stapps-article-detail-content',
|
|
||||||
templateUrl: 'article-detail-content.html',
|
|
||||||
})
|
|
||||||
export class ArticleDetailContentComponent {
|
|
||||||
@Input() item: SCArticle;
|
|
||||||
}
|
|
||||||
@@ -1,105 +0,0 @@
|
|||||||
<!--
|
|
||||||
~ Copyright (C) 2022 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.
|
|
||||||
~
|
|
||||||
~ This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
~ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
~ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
~ more details.
|
|
||||||
~
|
|
||||||
~ You should have received a copy of the GNU General Public License along with
|
|
||||||
~ this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
-->
|
|
||||||
|
|
||||||
@if (item.sameAs) {
|
|
||||||
<ion-card>
|
|
||||||
<ion-card-header>{{ 'hebisSearch.detail.title' | translate | sentencecase }}</ion-card-header>
|
|
||||||
<ion-card-content>
|
|
||||||
<stapps-external-link
|
|
||||||
[text]="'name' | thingTranslate: item"
|
|
||||||
[link]="item.sameAs"
|
|
||||||
></stapps-external-link>
|
|
||||||
</ion-card-content>
|
|
||||||
</ion-card>
|
|
||||||
}
|
|
||||||
@if (!item.sameAs) {
|
|
||||||
<stapps-simple-card
|
|
||||||
[title]="'name' | propertyNameTranslate: item | sentencecase"
|
|
||||||
[content]="'name' | thingTranslate: item"
|
|
||||||
>
|
|
||||||
</stapps-simple-card>
|
|
||||||
}
|
|
||||||
@if (item.description) {
|
|
||||||
<stapps-simple-card
|
|
||||||
[title]="'hebisSearch.detail.description' | translate | sentencecase"
|
|
||||||
[content]="item.description"
|
|
||||||
></stapps-simple-card>
|
|
||||||
}
|
|
||||||
@if (item.sourceOrganization) {
|
|
||||||
<stapps-simple-card
|
|
||||||
[title]="'sourceOrganization' | propertyNameTranslate: item | sentencecase"
|
|
||||||
[content]="item.sourceOrganization"
|
|
||||||
></stapps-simple-card>
|
|
||||||
}
|
|
||||||
@if (item.authors && item.authors.length > 0) {
|
|
||||||
<ion-card>
|
|
||||||
<ion-card-header>{{ 'authors' | propertyNameTranslate: item | sentencecase }}</ion-card-header>
|
|
||||||
<ion-card-content>
|
|
||||||
@for (author of item.authors; track author) {
|
|
||||||
<ion-label>{{ 'name' | thingTranslate: author }}</ion-label>
|
|
||||||
}
|
|
||||||
</ion-card-content>
|
|
||||||
</ion-card>
|
|
||||||
}
|
|
||||||
@if (item.firstPublished && !item.lastPublished) {
|
|
||||||
<stapps-simple-card
|
|
||||||
[title]="'hebisSearch.detail.firstPublished' | translate | sentencecase"
|
|
||||||
[content]="item.firstPublished"
|
|
||||||
>
|
|
||||||
</stapps-simple-card>
|
|
||||||
}
|
|
||||||
@if (item.firstPublished && item.lastPublished) {
|
|
||||||
<stapps-simple-card
|
|
||||||
[title]="'hebisSearch.detail.firstPublished' | translate | sentencecase"
|
|
||||||
[content]="[item.firstPublished, item.lastPublished] | join: ' - '"
|
|
||||||
>
|
|
||||||
</stapps-simple-card>
|
|
||||||
}
|
|
||||||
@if (item.publications) {
|
|
||||||
<ion-card>
|
|
||||||
<ion-card-header>{{ 'publications' | propertyNameTranslate: item | sentencecase }}</ion-card-header>
|
|
||||||
<ion-card-content>
|
|
||||||
@for (publication of item.publications; track publication) {
|
|
||||||
<p>
|
|
||||||
{{ publication.locations | join: ', ' }}
|
|
||||||
{{ publication.locations && publication.publisher ? ':' : '' }} {{ publication.publisher }}
|
|
||||||
</p>
|
|
||||||
}
|
|
||||||
</ion-card-content>
|
|
||||||
</ion-card>
|
|
||||||
}
|
|
||||||
@if (item.reference) {
|
|
||||||
<stapps-simple-card
|
|
||||||
[title]="'reference' | propertyNameTranslate: item | sentencecase"
|
|
||||||
[content]="item.reference"
|
|
||||||
></stapps-simple-card>
|
|
||||||
}
|
|
||||||
@if (item.isPartOf) {
|
|
||||||
<stapps-simple-card
|
|
||||||
[title]="'isPartOf' | propertyNameTranslate: item | sentencecase"
|
|
||||||
[content]="item.isPartOf.name"
|
|
||||||
></stapps-simple-card>
|
|
||||||
}
|
|
||||||
@if (item.categories) {
|
|
||||||
<ion-card>
|
|
||||||
<ion-card-header>{{ 'categories' | propertyNameTranslate: item | sentencecase }}</ion-card-header>
|
|
||||||
<ion-card-content>
|
|
||||||
<ion-chip [color]="'primary'">
|
|
||||||
<ion-icon [name]="item.type | dataIcon"></ion-icon>
|
|
||||||
<ion-label>{{ 'categories' | thingTranslate: item }}</ion-label>
|
|
||||||
</ion-chip>
|
|
||||||
</ion-card-content>
|
|
||||||
</ion-card>
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2019 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.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with
|
|
||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
import {Component, Input} from '@angular/core';
|
|
||||||
import {SCArticle} from '@openstapps/core';
|
|
||||||
import {DataListItemComponent} from '../../list/data-list-item.component';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TODO
|
|
||||||
*/
|
|
||||||
@Component({
|
|
||||||
selector: 'stapps-article-item',
|
|
||||||
templateUrl: 'article-list-item.html',
|
|
||||||
styleUrl: 'article-list-item.scss',
|
|
||||||
})
|
|
||||||
export class ArticleListItemComponent extends DataListItemComponent {
|
|
||||||
/**
|
|
||||||
* TODO
|
|
||||||
*/
|
|
||||||
@Input() item: SCArticle;
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
<!--
|
|
||||||
~ 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.
|
|
||||||
~
|
|
||||||
~ This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
~ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
~ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
~ more details.
|
|
||||||
~
|
|
||||||
~ You should have received a copy of the GNU General Public License along with
|
|
||||||
~ this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<ion-label class="title">{{ 'name' | thingTranslate: item }}</ion-label>
|
|
||||||
<p class="title-sub">
|
|
||||||
@for (author of item.authors; track author) {
|
|
||||||
{{ 'name' | thingTranslate: author }}
|
|
||||||
}
|
|
||||||
@if (item.authors && item.authors && item.firstPublished) {
|
|
||||||
,
|
|
||||||
}
|
|
||||||
@if (item.firstPublished && !item.lastPublished) {
|
|
||||||
{{ item.firstPublished }}
|
|
||||||
} @else {
|
|
||||||
@if (item.firstPublished && item.lastPublished) {
|
|
||||||
{{ [item.firstPublished, item.lastPublished] | join: ' - ' }}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</p>
|
|
||||||
<ion-note> {{ 'categories' | thingTranslate: item }} </ion-note>
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
p.title-sub {
|
|
||||||
white-space: unset;
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2019 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.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with
|
|
||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
import {Component, Input} from '@angular/core';
|
|
||||||
import {SCBook} from '@openstapps/core';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TODO
|
|
||||||
*/
|
|
||||||
@Component({
|
|
||||||
selector: 'stapps-book-detail-content',
|
|
||||||
templateUrl: 'book-detail-content.html',
|
|
||||||
})
|
|
||||||
export class BookDetailContentComponent {
|
|
||||||
/**
|
|
||||||
* TODO
|
|
||||||
*/
|
|
||||||
@Input() item: SCBook;
|
|
||||||
}
|
|
||||||
@@ -1,104 +0,0 @@
|
|||||||
<!--
|
|
||||||
~ Copyright (C) 2022 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.
|
|
||||||
~
|
|
||||||
~ This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
~ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
~ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
~ more details.
|
|
||||||
~
|
|
||||||
~ You should have received a copy of the GNU General Public License along with
|
|
||||||
~ this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
-->
|
|
||||||
|
|
||||||
@if (item.sameAs) {
|
|
||||||
<ion-card>
|
|
||||||
<ion-card-header>{{ 'hebisSearch.detail.title' | translate | sentencecase }}</ion-card-header>
|
|
||||||
<ion-card-content>
|
|
||||||
<stapps-external-link
|
|
||||||
[text]="'name' | thingTranslate: item"
|
|
||||||
[link]="item.sameAs"
|
|
||||||
></stapps-external-link>
|
|
||||||
</ion-card-content>
|
|
||||||
</ion-card>
|
|
||||||
}
|
|
||||||
@if (!item.sameAs) {
|
|
||||||
<stapps-simple-card
|
|
||||||
[title]="'name' | propertyNameTranslate: item | sentencecase"
|
|
||||||
[content]="'name' | thingTranslate: item"
|
|
||||||
>
|
|
||||||
</stapps-simple-card>
|
|
||||||
}
|
|
||||||
@if (item.edition) {
|
|
||||||
<stapps-simple-card
|
|
||||||
[title]="'edition' | propertyNameTranslate: item | sentencecase"
|
|
||||||
[content]="'edition' | thingTranslate: item"
|
|
||||||
>
|
|
||||||
</stapps-simple-card>
|
|
||||||
}
|
|
||||||
@if (item.description) {
|
|
||||||
<stapps-simple-card
|
|
||||||
[title]="'hebisSearch.detail.description' | translate | sentencecase"
|
|
||||||
[content]="item.description"
|
|
||||||
></stapps-simple-card>
|
|
||||||
}
|
|
||||||
@if (item.sourceOrganization) {
|
|
||||||
<stapps-simple-card
|
|
||||||
[title]="'sourceOrganization' | propertyNameTranslate: item | sentencecase"
|
|
||||||
[content]="item.sourceOrganization"
|
|
||||||
></stapps-simple-card>
|
|
||||||
}
|
|
||||||
@if (item.authors && item.authors.length > 0) {
|
|
||||||
<ion-card>
|
|
||||||
<ion-card-header>{{ 'authors' | propertyNameTranslate: item | sentencecase }}</ion-card-header>
|
|
||||||
<ion-card-content>
|
|
||||||
@for (author of item.authors; track author) {
|
|
||||||
<ion-label>{{ 'name' | thingTranslate: author }}</ion-label>
|
|
||||||
}
|
|
||||||
</ion-card-content>
|
|
||||||
</ion-card>
|
|
||||||
}
|
|
||||||
@if (item.ISBNs) {
|
|
||||||
<stapps-simple-card [title]="'ISBNs' | propertyNameTranslate: item | sentencecase" [content]="item.ISBNs">
|
|
||||||
</stapps-simple-card>
|
|
||||||
}
|
|
||||||
@if (item.firstPublished && !item.lastPublished) {
|
|
||||||
<stapps-simple-card
|
|
||||||
[title]="'hebisSearch.detail.firstPublished' | translate | sentencecase"
|
|
||||||
[content]="item.firstPublished"
|
|
||||||
>
|
|
||||||
</stapps-simple-card>
|
|
||||||
}
|
|
||||||
@if (item.firstPublished && item.lastPublished) {
|
|
||||||
<stapps-simple-card
|
|
||||||
[title]="'hebisSearch.detail.firstPublished' | translate | sentencecase"
|
|
||||||
[content]="[item.firstPublished, item.lastPublished] | join: ' - '"
|
|
||||||
>
|
|
||||||
</stapps-simple-card>
|
|
||||||
}
|
|
||||||
@if (item.publications) {
|
|
||||||
<ion-card>
|
|
||||||
<ion-card-header>{{ 'publications' | propertyNameTranslate: item | sentencecase }}</ion-card-header>
|
|
||||||
<ion-card-content>
|
|
||||||
@for (publication of item.publications; track publication) {
|
|
||||||
<p>
|
|
||||||
{{ publication.locations | join: ', ' }}
|
|
||||||
{{ publication.locations && publication.publisher ? ':' : '' }} {{ publication.publisher }}
|
|
||||||
</p>
|
|
||||||
}
|
|
||||||
</ion-card-content>
|
|
||||||
</ion-card>
|
|
||||||
}
|
|
||||||
@if (item.categories) {
|
|
||||||
<ion-card>
|
|
||||||
<ion-card-header>{{ 'categories' | propertyNameTranslate: item | sentencecase }}</ion-card-header>
|
|
||||||
<ion-card-content>
|
|
||||||
<ion-chip [color]="'primary'">
|
|
||||||
<ion-icon [name]="item.type | dataIcon"></ion-icon>
|
|
||||||
<ion-label>{{ 'categories' | thingTranslate: item }}</ion-label>
|
|
||||||
</ion-chip>
|
|
||||||
</ion-card-content>
|
|
||||||
</ion-card>
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2019 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.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with
|
|
||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
import {Component, Input} from '@angular/core';
|
|
||||||
import {SCBook} from '@openstapps/core';
|
|
||||||
import {DataListItemComponent} from '../../list/data-list-item.component';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TODO
|
|
||||||
*/
|
|
||||||
@Component({
|
|
||||||
selector: 'stapps-book-list-item',
|
|
||||||
templateUrl: 'book-list-item.html',
|
|
||||||
styleUrl: 'book-list-item.scss',
|
|
||||||
})
|
|
||||||
export class BookListItemComponent extends DataListItemComponent {
|
|
||||||
/**
|
|
||||||
* TODO
|
|
||||||
*/
|
|
||||||
@Input() item: SCBook;
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
<!--
|
|
||||||
~ 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.
|
|
||||||
~
|
|
||||||
~ This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
~ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
~ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
~ more details.
|
|
||||||
~
|
|
||||||
~ You should have received a copy of the GNU General Public License along with
|
|
||||||
~ this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<ion-label class="title">{{ 'name' | thingTranslate: item }}</ion-label>
|
|
||||||
<p class="title-sub">
|
|
||||||
@for (author of item.authors; track author) {
|
|
||||||
{{ 'name' | thingTranslate: author }}
|
|
||||||
}
|
|
||||||
@if (item.authors && item.authors && item.firstPublished) {
|
|
||||||
,
|
|
||||||
}
|
|
||||||
@if (item.firstPublished && !item.lastPublished) {
|
|
||||||
{{ item.firstPublished }}
|
|
||||||
} @else {
|
|
||||||
@if (item.firstPublished && item.lastPublished) {
|
|
||||||
{{ [item.firstPublished, item.lastPublished] | join: ' - ' }}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</p>
|
|
||||||
<ion-note> {{ 'categories' | thingTranslate: item }} </ion-note>
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
p.title-sub {
|
|
||||||
white-space: unset;
|
|
||||||
}
|
|
||||||
-30
@@ -1,30 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2019 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.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with
|
|
||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
import {Component, Input} from '@angular/core';
|
|
||||||
import {SCPeriodical} from '@openstapps/core';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TODO
|
|
||||||
*/
|
|
||||||
@Component({
|
|
||||||
selector: 'stapps-periodical-detail-content',
|
|
||||||
templateUrl: 'periodical-detail-content.html',
|
|
||||||
})
|
|
||||||
export class PeriodicalDetailContentComponent {
|
|
||||||
/**
|
|
||||||
* TODO
|
|
||||||
*/
|
|
||||||
@Input() item: SCPeriodical;
|
|
||||||
}
|
|
||||||
@@ -1,100 +0,0 @@
|
|||||||
<!--
|
|
||||||
~ Copyright (C) 2022 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.
|
|
||||||
~
|
|
||||||
~ This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
~ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
~ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
~ more details.
|
|
||||||
~
|
|
||||||
~ You should have received a copy of the GNU General Public License along with
|
|
||||||
~ this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
-->
|
|
||||||
|
|
||||||
@if (item.sameAs) {
|
|
||||||
<ion-card>
|
|
||||||
<ion-card-header>{{ 'hebisSearch.detail.title' | translate | sentencecase }}</ion-card-header>
|
|
||||||
<ion-card-content>
|
|
||||||
<stapps-external-link
|
|
||||||
[text]="'name' | thingTranslate: item"
|
|
||||||
[link]="item.sameAs"
|
|
||||||
></stapps-external-link>
|
|
||||||
</ion-card-content>
|
|
||||||
</ion-card>
|
|
||||||
}
|
|
||||||
@if (!item.sameAs) {
|
|
||||||
<stapps-simple-card
|
|
||||||
[title]="'name' | propertyNameTranslate: item | sentencecase"
|
|
||||||
[content]="'name' | thingTranslate: item"
|
|
||||||
>
|
|
||||||
</stapps-simple-card>
|
|
||||||
}
|
|
||||||
@if (item.description) {
|
|
||||||
<stapps-simple-card
|
|
||||||
[title]="'hebisSearch.detail.description' | translate | sentencecase"
|
|
||||||
[content]="item.description"
|
|
||||||
></stapps-simple-card>
|
|
||||||
}
|
|
||||||
@if (item.sourceOrganization) {
|
|
||||||
<stapps-simple-card
|
|
||||||
[title]="'sourceOrganization' | propertyNameTranslate: item | sentencecase"
|
|
||||||
[content]="item.sourceOrganization"
|
|
||||||
></stapps-simple-card>
|
|
||||||
}
|
|
||||||
@if (item.authors && item.authors.length > 0) {
|
|
||||||
<ion-card>
|
|
||||||
<ion-card-header>{{ 'authors' | propertyNameTranslate: item | sentencecase }}</ion-card-header>
|
|
||||||
<ion-card-content>
|
|
||||||
@for (author of item.authors; track author) {
|
|
||||||
<ion-label>{{ 'name' | thingTranslate: author }}</ion-label>
|
|
||||||
}
|
|
||||||
</ion-card-content>
|
|
||||||
</ion-card>
|
|
||||||
}
|
|
||||||
@if (item.firstPublished && !item.lastPublished) {
|
|
||||||
<stapps-simple-card
|
|
||||||
[title]="'hebisSearch.detail.firstPublished' | translate | sentencecase"
|
|
||||||
[content]="item.firstPublished + '-'"
|
|
||||||
>
|
|
||||||
</stapps-simple-card>
|
|
||||||
}
|
|
||||||
@if (item.firstPublished && item.lastPublished) {
|
|
||||||
<stapps-simple-card
|
|
||||||
[title]="'hebisSearch.detail.firstPublished' | translate | sentencecase"
|
|
||||||
[content]="[item.firstPublished, item.lastPublished] | join: ' - '"
|
|
||||||
>
|
|
||||||
</stapps-simple-card>
|
|
||||||
}
|
|
||||||
@if (item.publications) {
|
|
||||||
<ion-card>
|
|
||||||
<ion-card-header>{{ 'publications' | propertyNameTranslate: item | sentencecase }}</ion-card-header>
|
|
||||||
<ion-card-content>
|
|
||||||
@for (publication of item.publications; track publication) {
|
|
||||||
<p>
|
|
||||||
{{ publication.locations | join: ', ' }}
|
|
||||||
{{ publication.locations && publication.publisher ? ':' : '' }} {{ publication.publisher }}
|
|
||||||
</p>
|
|
||||||
}
|
|
||||||
</ion-card-content>
|
|
||||||
</ion-card>
|
|
||||||
}
|
|
||||||
@if (item.categories) {
|
|
||||||
<ion-card>
|
|
||||||
<ion-card-header>{{ 'categories' | propertyNameTranslate: item | sentencecase }}</ion-card-header>
|
|
||||||
<ion-card-content>
|
|
||||||
<ion-chip [color]="'primary'">
|
|
||||||
<ion-icon [name]="item.type | dataIcon"></ion-icon>
|
|
||||||
<ion-label>{{ 'categories' | thingTranslate: item }}</ion-label>
|
|
||||||
</ion-chip>
|
|
||||||
</ion-card-content>
|
|
||||||
</ion-card>
|
|
||||||
}
|
|
||||||
@if (item.ISSNs) {
|
|
||||||
<stapps-simple-card
|
|
||||||
[title]="'ISSNs' | propertyNameTranslate: item | sentencecase"
|
|
||||||
[content]="item.ISSNs | join: ', '"
|
|
||||||
>
|
|
||||||
</stapps-simple-card>
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2019 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.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with
|
|
||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
import {Component, Input} from '@angular/core';
|
|
||||||
import {SCPeriodical} from '@openstapps/core';
|
|
||||||
import {DataListItemComponent} from '../../list/data-list-item.component';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TODO
|
|
||||||
*/
|
|
||||||
@Component({
|
|
||||||
selector: 'stapps-periodical-list-item',
|
|
||||||
templateUrl: 'periodical-list-item.html',
|
|
||||||
styleUrl: 'periodical-list-item.scss',
|
|
||||||
})
|
|
||||||
export class PeriodicalListItemComponent extends DataListItemComponent {
|
|
||||||
/**
|
|
||||||
* TODO
|
|
||||||
*/
|
|
||||||
@Input() item: SCPeriodical;
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
<!--
|
|
||||||
~ 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.
|
|
||||||
~
|
|
||||||
~ This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
~ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
~ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
~ more details.
|
|
||||||
~
|
|
||||||
~ You should have received a copy of the GNU General Public License along with
|
|
||||||
~ this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<ion-label class="title">{{ 'name' | thingTranslate: item }}</ion-label>
|
|
||||||
<p class="title-sub">
|
|
||||||
@for (author of item.authors; track author) {
|
|
||||||
{{ 'name' | thingTranslate: author }}
|
|
||||||
}
|
|
||||||
@if (item.authors && item.authors && item.firstPublished) {
|
|
||||||
,
|
|
||||||
}
|
|
||||||
@if (item.firstPublished && !item.lastPublished) {
|
|
||||||
{{ item.firstPublished }}
|
|
||||||
} @else {
|
|
||||||
@if (item.firstPublished && item.lastPublished) {
|
|
||||||
{{ [item.firstPublished, item.lastPublished] | join: ' - ' }}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</p>
|
|
||||||
<ion-note> {{ 'categories' | thingTranslate: item }} </ion-note>
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
p.title-sub {
|
|
||||||
white-space: unset;
|
|
||||||
}
|
|
||||||
@@ -18,7 +18,6 @@ import {ActivatedRoute, Router} from '@angular/router';
|
|||||||
import {NGXLogger} from 'ngx-logger';
|
import {NGXLogger} from 'ngx-logger';
|
||||||
import {debounceTime, distinctUntilChanged, startWith, take} from 'rxjs/operators';
|
import {debounceTime, distinctUntilChanged, startWith, take} from 'rxjs/operators';
|
||||||
import {combineLatest} from 'rxjs';
|
import {combineLatest} from 'rxjs';
|
||||||
import {SCThingType} from '@openstapps/core';
|
|
||||||
import {FavoritesService} from './favorites.service';
|
import {FavoritesService} from './favorites.service';
|
||||||
import {DataRoutingService} from '../data/data-routing.service';
|
import {DataRoutingService} from '../data/data-routing.service';
|
||||||
import {ContextMenuService} from '../menu/context/context-menu.service';
|
import {ContextMenuService} from '../menu/context/context-menu.service';
|
||||||
@@ -113,17 +112,7 @@ export class FavoritesPageComponent extends SearchPageComponent implements OnIni
|
|||||||
.pipe(takeUntilDestroyed(this.destroy$))
|
.pipe(takeUntilDestroyed(this.destroy$))
|
||||||
.subscribe(item => {
|
.subscribe(item => {
|
||||||
if (this.itemRouting) {
|
if (this.itemRouting) {
|
||||||
if ([SCThingType.Book, SCThingType.Periodical, SCThingType.Article].includes(item.type)) {
|
void this.router.navigate(['data-detail', item.uid], {state: {item}});
|
||||||
void this.router.navigate(
|
|
||||||
[
|
|
||||||
'hebis-detail',
|
|
||||||
(item.origin && 'originalId' in item.origin && item.origin['originalId']) || '',
|
|
||||||
],
|
|
||||||
{state: {item}},
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
void this.router.navigate(['data-detail', item.uid], {state: {item}});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
-120
@@ -1,120 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2022 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.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with
|
|
||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* eslint-disable @typescript-eslint/no-non-null-assertion,@typescript-eslint/no-explicit-any */
|
|
||||||
import {CUSTOM_ELEMENTS_SCHEMA} from '@angular/core';
|
|
||||||
import {ComponentFixture, TestBed} from '@angular/core/testing';
|
|
||||||
import {ActivatedRoute, RouterModule} from '@angular/router';
|
|
||||||
import {TranslateLoader, TranslateModule, TranslateService} from '@ngx-translate/core';
|
|
||||||
import {sampleThingsMap} from '../../../_helpers/data/sample-things';
|
|
||||||
import {HebisRoutingModule} from '../hebis-routing.module';
|
|
||||||
import {HebisModule} from '../hebis.module';
|
|
||||||
import {DaiaAvailabilityComponent} from './daia-availability.component';
|
|
||||||
import {Observable, of} from 'rxjs';
|
|
||||||
import {StorageProvider} from '../../storage/storage.provider';
|
|
||||||
import {DaiaDataProvider} from '../daia-data.provider';
|
|
||||||
import {ConfigProvider} from '../../config/config.provider';
|
|
||||||
import {LoggerTestingModule} from 'ngx-logger/testing';
|
|
||||||
import {provideIonicAngular} from '@ionic/angular/standalone';
|
|
||||||
|
|
||||||
const translations: any = {data: {detail: {TITLE: 'Foo'}}};
|
|
||||||
|
|
||||||
class TranslateFakeLoader implements TranslateLoader {
|
|
||||||
getTranslation(_lang: string): Observable<any> {
|
|
||||||
return of(translations);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
describe('DaiaAvailabilityComponent', () => {
|
|
||||||
let comp: DaiaAvailabilityComponent;
|
|
||||||
let fixture: ComponentFixture<DaiaAvailabilityComponent>;
|
|
||||||
let dataProvider: DaiaDataProvider;
|
|
||||||
const sampleThing = sampleThingsMap.book[0];
|
|
||||||
let translateService: TranslateService;
|
|
||||||
let configProviderMock: jasmine.SpyObj<ConfigProvider>;
|
|
||||||
|
|
||||||
// @Component({ selector: 'stapps-data-list-item', template: '' })
|
|
||||||
// class DataListItemComponent {
|
|
||||||
// @Input() item;
|
|
||||||
// }
|
|
||||||
|
|
||||||
const fakeActivatedRoute = {
|
|
||||||
snapshot: {
|
|
||||||
paramMap: {
|
|
||||||
get: () => {
|
|
||||||
return sampleThing.uid;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const storageProviderSpy = jasmine.createSpyObj('StorageProvider', ['init', 'get', 'has', 'put', 'search']);
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
configProviderMock = jasmine.createSpyObj('ConfigProvider', ['init', 'getValue', 'getAnyValue']);
|
|
||||||
TestBed.configureTestingModule({
|
|
||||||
imports: [
|
|
||||||
RouterModule.forRoot([]),
|
|
||||||
HebisRoutingModule,
|
|
||||||
HebisModule,
|
|
||||||
TranslateModule.forRoot({
|
|
||||||
loader: {provide: TranslateLoader, useClass: TranslateFakeLoader},
|
|
||||||
}),
|
|
||||||
LoggerTestingModule,
|
|
||||||
],
|
|
||||||
providers: [
|
|
||||||
provideIonicAngular(),
|
|
||||||
{
|
|
||||||
provide: ActivatedRoute,
|
|
||||||
useValue: fakeActivatedRoute,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
provide: StorageProvider,
|
|
||||||
useValue: storageProviderSpy,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
provide: ConfigProvider,
|
|
||||||
useValue: configProviderMock,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
schemas: [CUSTOM_ELEMENTS_SCHEMA],
|
|
||||||
}).compileComponents();
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
dataProvider = TestBed.inject(DaiaDataProvider);
|
|
||||||
const workingDAIAurl = 'https://daia.hebis.de/DAIA2/UB_Frankfurt';
|
|
||||||
dataProvider.daiaServiceUrl = workingDAIAurl;
|
|
||||||
translateService = TestBed.inject(TranslateService);
|
|
||||||
spyOn(dataProvider, 'getAvailability' as any).and.returnValue(Promise.resolve([]));
|
|
||||||
spyOn(DaiaAvailabilityComponent.prototype, 'getAvailability').and.callThrough();
|
|
||||||
fixture = await TestBed.createComponent(DaiaAvailabilityComponent);
|
|
||||||
comp = fixture.componentInstance;
|
|
||||||
translateService.use('foo');
|
|
||||||
fixture.detectChanges();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should create component', () => expect(comp).toBeDefined());
|
|
||||||
|
|
||||||
it('should get the availability of an item', () => {
|
|
||||||
comp.getAvailability(sampleThing.uid);
|
|
||||||
expect(DaiaAvailabilityComponent.prototype.getAvailability).toHaveBeenCalledWith(sampleThing.uid);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should get the availability of an item when the view is entered', () => {
|
|
||||||
comp.ngOnInit();
|
|
||||||
expect(DaiaAvailabilityComponent.prototype.getAvailability).toHaveBeenCalledWith(sampleThing.uid);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2022 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.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with
|
|
||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
import {Component, inject, OnInit} from '@angular/core';
|
|
||||||
import {SCUuid} from '@openstapps/core';
|
|
||||||
import {DataDetailComponent} from '../../data/detail/data-detail.component';
|
|
||||||
import {DaiaDataProvider} from '../daia-data.provider';
|
|
||||||
import {DaiaHolding} from '../protocol/response';
|
|
||||||
import {groupByStable} from '@openstapps/collection-utils';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A Component to display an SCThing detailed
|
|
||||||
*/
|
|
||||||
@Component({
|
|
||||||
selector: 'stapps-daia-availability',
|
|
||||||
styleUrls: ['daia-availability.scss'],
|
|
||||||
templateUrl: 'daia-availability.html',
|
|
||||||
})
|
|
||||||
export class DaiaAvailabilityComponent extends DataDetailComponent implements OnInit {
|
|
||||||
holdings?: DaiaHolding[];
|
|
||||||
|
|
||||||
holdingsByDepartments?: Map<DaiaHolding['department']['id'], DaiaHolding[]>;
|
|
||||||
|
|
||||||
private daiaDataProvider = inject(DaiaDataProvider);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @override
|
|
||||||
*/
|
|
||||||
async ngOnInit() {
|
|
||||||
const uid = this.route.snapshot.paramMap.get('uid');
|
|
||||||
if (uid) {
|
|
||||||
await this.getAvailability(uid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides data item with given UID
|
|
||||||
* @param uid Unique identifier of a thing
|
|
||||||
*/
|
|
||||||
async getAvailability(uid: SCUuid) {
|
|
||||||
this.daiaDataProvider.getAvailability(uid).then(holdings => {
|
|
||||||
if (holdings !== undefined) {
|
|
||||||
this.holdings = holdings;
|
|
||||||
this.holdingsByDepartments = groupByStable(holdings, holding => holding.department.id);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
<!--
|
|
||||||
~ Copyright (C) 2022 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.
|
|
||||||
~
|
|
||||||
~ This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
~ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
~ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
~ more details.
|
|
||||||
~
|
|
||||||
~ You should have received a copy of the GNU General Public License along with
|
|
||||||
~ this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<ng-container>
|
|
||||||
<ion-card>
|
|
||||||
<ion-card-header> {{ 'hebisSearch.daia.availability' | translate }} </ion-card-header>
|
|
||||||
<ion-card-content>
|
|
||||||
@if (holdingsByDepartments) {
|
|
||||||
@for (holdingsByDepartment of holdingsByDepartments | keyvalue; track holdingsByDepartment) {
|
|
||||||
<ion-label>
|
|
||||||
@if (holdingsByDepartment.value[0].department.href) {
|
|
||||||
<stapps-external-link
|
|
||||||
[text]="holdingsByDepartment.value[0].department.content"
|
|
||||||
[link]="holdingsByDepartment.value[0].department.href"
|
|
||||||
>
|
|
||||||
</stapps-external-link>
|
|
||||||
}
|
|
||||||
</ion-label>
|
|
||||||
@for (holding of holdingsByDepartment.value; track holding) {
|
|
||||||
<stapps-daia-holding [holding]="holding"></stapps-daia-holding>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@if (!holdings) {
|
|
||||||
<ion-label> {{ 'hebisSearch.daia.unavailableAvailability' | translate }} </ion-label>
|
|
||||||
}
|
|
||||||
@if (holdings?.length === 0) {
|
|
||||||
<ion-label> {{ 'hebisSearch.daia.unknownAvailability' | translate }} </ion-label>
|
|
||||||
}
|
|
||||||
</ion-card-content>
|
|
||||||
</ion-card>
|
|
||||||
</ng-container>
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
/*!
|
|
||||||
* Copyright (C) 2022 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.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with
|
|
||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
:host ion-card {
|
|
||||||
margin: 0;
|
|
||||||
box-shadow: none;
|
|
||||||
|
|
||||||
ion-card-content {
|
|
||||||
padding-bottom: 8px;
|
|
||||||
|
|
||||||
h1 {
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ion-card-header {
|
|
||||||
padding-top: 8px;
|
|
||||||
padding-bottom: 4px;
|
|
||||||
font-weight: bold;
|
|
||||||
color: var(--ion-color-dark);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with
|
|
||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import {Component, Input, OnInit} from '@angular/core';
|
|
||||||
import {DaiaHolding} from '../protocol/response';
|
|
||||||
import {DaiaDataProvider} from '../daia-data.provider';
|
|
||||||
|
|
||||||
@Component({
|
|
||||||
selector: 'stapps-daia-holding',
|
|
||||||
templateUrl: './daia-holding.html',
|
|
||||||
styleUrls: ['./daia-holding.scss'],
|
|
||||||
})
|
|
||||||
export class DaiaHoldingComponent implements OnInit {
|
|
||||||
@Input() holding: DaiaHolding;
|
|
||||||
|
|
||||||
constructor(private daiaDataProvider: DaiaDataProvider) {}
|
|
||||||
|
|
||||||
resourceLink?: string;
|
|
||||||
|
|
||||||
ngOnInit(): void {
|
|
||||||
this.resourceLink = this.daiaDataProvider.getHoldingLink(this.holding, this.holding.open);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,89 +0,0 @@
|
|||||||
<!--
|
|
||||||
~ Copyright (C) 2022 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.
|
|
||||||
~
|
|
||||||
~ This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
~ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
~ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
~ more details.
|
|
||||||
~
|
|
||||||
~ You should have received a copy of the GNU General Public License along with
|
|
||||||
~ this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
-->
|
|
||||||
<ion-grid>
|
|
||||||
@if (holding.storage && holding.storage.content) {
|
|
||||||
<ion-row>
|
|
||||||
<ion-col size="3">{{ 'hebisSearch.daia.location' | translate }}</ion-col>
|
|
||||||
<ion-col size="9" [innerHTML]="holding.storage.content"></ion-col>
|
|
||||||
</ion-row>
|
|
||||||
}
|
|
||||||
@if (holding.signature && !holding.online) {
|
|
||||||
<ion-row>
|
|
||||||
<ion-col size="3">{{ 'hebisSearch.daia.signature' | translate }}</ion-col>
|
|
||||||
<ion-col size="9">{{ holding.signature }}</ion-col>
|
|
||||||
</ion-row>
|
|
||||||
}
|
|
||||||
@if (holding.holdings) {
|
|
||||||
<ion-row>
|
|
||||||
<ion-col size="3">{{ 'hebisSearch.daia.holdings' | translate }}</ion-col>
|
|
||||||
<ion-col size="9">{{ holding.holdings }}</ion-col>
|
|
||||||
</ion-row>
|
|
||||||
}
|
|
||||||
@if (holding.about) {
|
|
||||||
<ion-row>
|
|
||||||
<ion-col size="3">{{ 'hebisSearch.daia.comment' | translate }}</ion-col>
|
|
||||||
<ion-col size="9" [innerHTML]="holding.about"></ion-col>
|
|
||||||
</ion-row>
|
|
||||||
}
|
|
||||||
@if (holding.available && holding.online && resourceLink) {
|
|
||||||
<ion-row>
|
|
||||||
<ion-col size="3">{{ 'Online' }}</ion-col>
|
|
||||||
<ion-col size="9">
|
|
||||||
<stapps-external-link
|
|
||||||
[link]="resourceLink"
|
|
||||||
[text]="'hebisSearch.daia.fulltext' | translate"
|
|
||||||
></stapps-external-link
|
|
||||||
></ion-col>
|
|
||||||
</ion-row>
|
|
||||||
}
|
|
||||||
@if (holding.status) {
|
|
||||||
<ion-row>
|
|
||||||
<ion-col size="3">{{ 'hebisSearch.daia.status' | translate }}</ion-col>
|
|
||||||
<ion-col size="9">
|
|
||||||
@if (holding.status === 'available') {
|
|
||||||
<ion-icon name="check_circle" color="success"></ion-icon>
|
|
||||||
}
|
|
||||||
@if (holding.status === 'library_only') {
|
|
||||||
<ion-icon name="check_circle" color="warning"></ion-icon>
|
|
||||||
}
|
|
||||||
@if (['checked_out', 'not_yet_available', 'not_available'].indexOf(holding.status) > -1) {
|
|
||||||
<ion-icon name="cancel" color="danger"> </ion-icon>
|
|
||||||
}
|
|
||||||
{{ 'hebisSearch.daia.status_states' + '.' + holding.status | translate }}
|
|
||||||
@if (
|
|
||||||
(holding.status === 'available' || holding.status === 'library_only') &&
|
|
||||||
holding.available &&
|
|
||||||
holding.available.href
|
|
||||||
) {
|
|
||||||
<stapps-external-link [text]="'hebisSearch.daia.order' | translate" [link]="holding.available.href">
|
|
||||||
</stapps-external-link>
|
|
||||||
}
|
|
||||||
@if (holding.status === 'checked_out' && holding.unavailable && holding.unavailable.href) {
|
|
||||||
<stapps-external-link
|
|
||||||
[text]="'hebisSearch.daia.reserve' | translate"
|
|
||||||
[link]="holding.unavailable.href"
|
|
||||||
>
|
|
||||||
</stapps-external-link>
|
|
||||||
}
|
|
||||||
</ion-col>
|
|
||||||
</ion-row>
|
|
||||||
}
|
|
||||||
@if (holding.dueDate) {
|
|
||||||
<ion-row>
|
|
||||||
<ion-col size="3">{{ 'hebisSearch.daia.dueDate' | translate }}</ion-col>
|
|
||||||
<ion-col size="9">{{ holding.dueDate | amDateFormat: 'll' }}</ion-col>
|
|
||||||
</ion-row>
|
|
||||||
}
|
|
||||||
</ion-grid>
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
/*!
|
|
||||||
* Copyright (C) 2022 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.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with
|
|
||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
ion-label a {
|
|
||||||
display: block;
|
|
||||||
|
|
||||||
margin: 20px 0 5px;
|
|
||||||
|
|
||||||
font-weight: 700;
|
|
||||||
color: var(--ion-color-primary);
|
|
||||||
text-decoration: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
ion-grid {
|
|
||||||
margin: 5px;
|
|
||||||
padding: 0;
|
|
||||||
|
|
||||||
ion-row {
|
|
||||||
color: var(--ion-color-light-contrast);
|
|
||||||
background-color: var(--ion-color-light);
|
|
||||||
border-bottom: 1px solid #fff;
|
|
||||||
|
|
||||||
ion-col:first-child {
|
|
||||||
font-weight: 700;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ion-icon {
|
|
||||||
--fill: 1;
|
|
||||||
}
|
|
||||||
@@ -1,231 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with
|
|
||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
/* eslint-disable @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-explicit-any, unicorn/no-thenable */
|
|
||||||
import {TestBed} from '@angular/core/testing';
|
|
||||||
import {DaiaDataProvider} from './daia-data.provider';
|
|
||||||
import {HebisModule} from './hebis.module';
|
|
||||||
import {ConfigProvider} from '../config/config.provider';
|
|
||||||
import {StAppsWebHttpClient} from '../data/stapps-web-http-client.provider';
|
|
||||||
import {StorageProvider} from '../storage/storage.provider';
|
|
||||||
import {LoggerTestingModule} from 'ngx-logger/testing';
|
|
||||||
import {MapModule} from '../map/map.module';
|
|
||||||
import {provideHttpClient, withInterceptorsFromDi} from '@angular/common/http';
|
|
||||||
import {StorageModule} from '../storage/storage.module';
|
|
||||||
import {DaiaHolding, DaiaService} from './protocol/response';
|
|
||||||
import {Observable, of} from 'rxjs';
|
|
||||||
import {TranslateLoader, TranslateModule} from '@ngx-translate/core';
|
|
||||||
|
|
||||||
const translations: any = {data: {detail: {TITLE: 'Foo'}}};
|
|
||||||
|
|
||||||
class TranslateFakeLoader implements TranslateLoader {
|
|
||||||
getTranslation(_lang: string): Observable<any> {
|
|
||||||
return of(translations);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
describe('DaiaDataProvider', () => {
|
|
||||||
let daiaDataProvider: DaiaDataProvider;
|
|
||||||
let configProvider: ConfigProvider;
|
|
||||||
const proxyUrl = 'https://some-proxy.com?q=';
|
|
||||||
const getProxifiedUrl = (url: string) => `${proxyUrl}${encodeURIComponent(url)}`;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
configProvider = jasmine.createSpyObj('ConfigProvider', ['getValue']);
|
|
||||||
TestBed.configureTestingModule({
|
|
||||||
imports: [
|
|
||||||
HebisModule,
|
|
||||||
MapModule,
|
|
||||||
StorageModule,
|
|
||||||
LoggerTestingModule,
|
|
||||||
TranslateModule.forRoot({
|
|
||||||
loader: {provide: TranslateLoader, useClass: TranslateFakeLoader},
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
providers: [
|
|
||||||
{
|
|
||||||
provide: ConfigProvider,
|
|
||||||
useValue: configProvider,
|
|
||||||
},
|
|
||||||
StAppsWebHttpClient,
|
|
||||||
StorageProvider,
|
|
||||||
DaiaDataProvider,
|
|
||||||
provideHttpClient(withInterceptorsFromDi()),
|
|
||||||
],
|
|
||||||
});
|
|
||||||
daiaDataProvider = TestBed.inject(DaiaDataProvider);
|
|
||||||
daiaDataProvider.hebisProxyUrl = proxyUrl;
|
|
||||||
});
|
|
||||||
describe('getResourceLink', () => {
|
|
||||||
it('should return link with proxy when open property is undefined', () => {
|
|
||||||
const available: DaiaService = {
|
|
||||||
delay: '',
|
|
||||||
expected: '',
|
|
||||||
href: 'https://some-url.com',
|
|
||||||
limitations: [],
|
|
||||||
service: 'presentation',
|
|
||||||
};
|
|
||||||
const holding: DaiaHolding = {
|
|
||||||
department: {id: '', content: ''},
|
|
||||||
id: '',
|
|
||||||
online: false,
|
|
||||||
signature: '',
|
|
||||||
available: available,
|
|
||||||
};
|
|
||||||
|
|
||||||
expect(daiaDataProvider.getHoldingLink(holding, holding.open)).toEqual(
|
|
||||||
getProxifiedUrl(available.href as string),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return the resource link without proxy when the resource is open', () => {
|
|
||||||
const available: DaiaService = {
|
|
||||||
delay: '',
|
|
||||||
expected: '',
|
|
||||||
href: 'https://some-url.com',
|
|
||||||
limitations: [],
|
|
||||||
service: 'other',
|
|
||||||
};
|
|
||||||
const holding: DaiaHolding = {
|
|
||||||
department: {id: '', content: ''},
|
|
||||||
id: '',
|
|
||||||
online: false,
|
|
||||||
open: true,
|
|
||||||
signature: '',
|
|
||||||
available: available,
|
|
||||||
};
|
|
||||||
|
|
||||||
expect(daiaDataProvider.getHoldingLink(holding, holding.open)).toEqual(available.href as string);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return the resource link with proxy when the resource is not open', () => {
|
|
||||||
const available: DaiaService = {
|
|
||||||
delay: '',
|
|
||||||
expected: '',
|
|
||||||
href: 'https://some-url.com',
|
|
||||||
limitations: [],
|
|
||||||
service: 'other',
|
|
||||||
};
|
|
||||||
const holding: DaiaHolding = {
|
|
||||||
department: {id: '', content: ''},
|
|
||||||
id: '',
|
|
||||||
online: false,
|
|
||||||
open: false,
|
|
||||||
signature: '',
|
|
||||||
available: available,
|
|
||||||
};
|
|
||||||
|
|
||||||
expect(daiaDataProvider.getHoldingLink(holding, holding.open)).toEqual(
|
|
||||||
getProxifiedUrl(available.href as string),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('getResourceStatus', () => {
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
||||||
// let available, unavalable: SCDaiaService[];
|
|
||||||
|
|
||||||
const checkedOut: DaiaService = {
|
|
||||||
expected: '2022-09-01',
|
|
||||||
limitations: [],
|
|
||||||
service: 'loan',
|
|
||||||
};
|
|
||||||
|
|
||||||
const notYetAvailableOnBuy: DaiaService = {
|
|
||||||
limitations: [{id: 'OnBuy', content: ''}],
|
|
||||||
service: 'loan',
|
|
||||||
};
|
|
||||||
|
|
||||||
const notYetAvailableJustReturned: DaiaService = {
|
|
||||||
limitations: [{id: 'JustReturned', content: ''}],
|
|
||||||
service: 'loan',
|
|
||||||
};
|
|
||||||
|
|
||||||
const notAvailableCopyIsMissing: DaiaService = {
|
|
||||||
limitations: [{id: 'CopyIsMissing', content: ''}],
|
|
||||||
service: 'loan',
|
|
||||||
};
|
|
||||||
|
|
||||||
const notAvailableCanceled: DaiaService = {
|
|
||||||
limitations: [{id: 'Canceled', content: ''}],
|
|
||||||
service: 'loan',
|
|
||||||
};
|
|
||||||
|
|
||||||
const libraryOnlyOnlyInHouse: DaiaService = {
|
|
||||||
limitations: [{id: 'OnlyInHouse', content: ''}],
|
|
||||||
service: 'loan',
|
|
||||||
};
|
|
||||||
|
|
||||||
const libraryOnlyExternalLoan: DaiaService = {
|
|
||||||
limitations: [{id: 'ExternalLoan', content: ''}],
|
|
||||||
service: 'loan',
|
|
||||||
};
|
|
||||||
|
|
||||||
const libraryOnlyPresentation: DaiaService = {
|
|
||||||
service: 'presentation',
|
|
||||||
};
|
|
||||||
|
|
||||||
const availableLimitationsUndefined: DaiaService = {
|
|
||||||
service: 'loan',
|
|
||||||
};
|
|
||||||
|
|
||||||
const availableLimitationsEmpty: DaiaService = {
|
|
||||||
limitations: [],
|
|
||||||
service: 'loan',
|
|
||||||
};
|
|
||||||
|
|
||||||
it('should return check out', () => {
|
|
||||||
expect(daiaDataProvider.getHoldingStatus([], [checkedOut])).toEqual('checked_out');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return not yet available', () => {
|
|
||||||
expect(daiaDataProvider.getHoldingStatus([], [notYetAvailableOnBuy])).toEqual('not_yet_available');
|
|
||||||
expect(daiaDataProvider.getHoldingStatus([], [notYetAvailableJustReturned])).toEqual(
|
|
||||||
'not_yet_available',
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return not available', () => {
|
|
||||||
expect(daiaDataProvider.getHoldingStatus([], [notAvailableCopyIsMissing])).toEqual('not_available');
|
|
||||||
expect(daiaDataProvider.getHoldingStatus([], [notAvailableCanceled])).toEqual('not_available');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return library only', () => {
|
|
||||||
expect(daiaDataProvider.getHoldingStatus([], [libraryOnlyOnlyInHouse])).toEqual('library_only');
|
|
||||||
expect(daiaDataProvider.getHoldingStatus([libraryOnlyExternalLoan], [])).toEqual('library_only');
|
|
||||||
expect(daiaDataProvider.getHoldingStatus([libraryOnlyPresentation], [])).toEqual('library_only');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return available', () => {
|
|
||||||
expect(
|
|
||||||
daiaDataProvider.getHoldingStatus([availableLimitationsUndefined, libraryOnlyPresentation], []),
|
|
||||||
).toEqual('available');
|
|
||||||
expect(
|
|
||||||
daiaDataProvider.getHoldingStatus([availableLimitationsEmpty, libraryOnlyPresentation], []),
|
|
||||||
).toEqual('available');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return unknown otherwise', () => {
|
|
||||||
const withoutLoan: DaiaService = {
|
|
||||||
limitations: [],
|
|
||||||
service: 'anything else',
|
|
||||||
};
|
|
||||||
|
|
||||||
expect(daiaDataProvider.getHoldingStatus([withoutLoan], [])).toEqual('unknown');
|
|
||||||
expect(daiaDataProvider.getHoldingStatus([], [withoutLoan])).toEqual('unknown');
|
|
||||||
expect(daiaDataProvider.getHoldingStatus([], [availableLimitationsUndefined])).toEqual('unknown');
|
|
||||||
expect(daiaDataProvider.getHoldingStatus([], [availableLimitationsEmpty])).toEqual('unknown');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,231 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with
|
|
||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
import {Injectable} from '@angular/core';
|
|
||||||
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';
|
|
||||||
import {SCFeatureConfiguration} from '@openstapps/core';
|
|
||||||
import {NGXLogger} from 'ngx-logger';
|
|
||||||
import {TranslateService} from '@ngx-translate/core';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generated class for the DataProvider provider.
|
|
||||||
*
|
|
||||||
* See https://angular.io/guide/dependency-injection for more info on providers
|
|
||||||
* and Angular DI.
|
|
||||||
*/
|
|
||||||
@Injectable({
|
|
||||||
providedIn: 'root',
|
|
||||||
})
|
|
||||||
export class DaiaDataProvider {
|
|
||||||
/**
|
|
||||||
* TODO
|
|
||||||
*/
|
|
||||||
storageProvider: StorageProvider;
|
|
||||||
|
|
||||||
httpClient: HttpClient;
|
|
||||||
|
|
||||||
daiaServiceUrl?: string;
|
|
||||||
|
|
||||||
hebisProxyUrl?: string;
|
|
||||||
|
|
||||||
clientHeaders = new HttpHeaders();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TODO
|
|
||||||
* @param storageProvider TODO
|
|
||||||
* @param httpClient TODO
|
|
||||||
* @param configProvider TODO
|
|
||||||
* @param logger TODO
|
|
||||||
* @param translateService TODO
|
|
||||||
*/
|
|
||||||
constructor(
|
|
||||||
storageProvider: StorageProvider,
|
|
||||||
httpClient: HttpClient,
|
|
||||||
private configProvider: ConfigProvider,
|
|
||||||
private readonly logger: NGXLogger,
|
|
||||||
private translateService: TranslateService,
|
|
||||||
) {
|
|
||||||
this.storageProvider = storageProvider;
|
|
||||||
this.httpClient = httpClient;
|
|
||||||
this.clientHeaders = this.clientHeaders.set('Content-Type', 'application/json');
|
|
||||||
}
|
|
||||||
|
|
||||||
async getAvailability(id: string): Promise<DaiaHolding[] | undefined> {
|
|
||||||
if (this.daiaServiceUrl === undefined) {
|
|
||||||
try {
|
|
||||||
const features = this.configProvider.getValue('features') as SCFeatureConfiguration;
|
|
||||||
if (features.extern?.daia?.url) {
|
|
||||||
this.daiaServiceUrl = features.extern?.daia?.url;
|
|
||||||
} else {
|
|
||||||
this.logger.error('Daia service url undefined');
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
if (features.extern?.hebisProxy?.url) {
|
|
||||||
this.hebisProxyUrl = features.extern?.hebisProxy?.url;
|
|
||||||
} else {
|
|
||||||
this.logger.error('HeBIS proxy url undefined');
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
this.logger.error(error);
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Promise(resolve =>
|
|
||||||
this.httpClient
|
|
||||||
.get<DaiaAvailabilityResponse>(this.daiaServiceUrl as string, {
|
|
||||||
params: {id, lang: this.translateService.currentLang},
|
|
||||||
})
|
|
||||||
.subscribe(
|
|
||||||
(response: DaiaAvailabilityResponse) => {
|
|
||||||
const holdings: DaiaHolding[] = [];
|
|
||||||
if (response && Array.isArray(response.document)) {
|
|
||||||
response.document.map(document => {
|
|
||||||
Array.isArray(document.item) &&
|
|
||||||
document.item.map(element => {
|
|
||||||
try {
|
|
||||||
const {
|
|
||||||
department: {id: departmentId, content: departmentLabel, href: departmentLink} = {
|
|
||||||
id: 'noDep',
|
|
||||||
content: '',
|
|
||||||
href: '',
|
|
||||||
},
|
|
||||||
label,
|
|
||||||
about,
|
|
||||||
available,
|
|
||||||
storage,
|
|
||||||
chronology,
|
|
||||||
unavailable,
|
|
||||||
} = element;
|
|
||||||
const holdingStatus = this.holdingHasStatus(available || [])
|
|
||||||
? this.getHoldingStatus(available || [], unavailable || [])
|
|
||||||
: undefined;
|
|
||||||
|
|
||||||
const dueDate =
|
|
||||||
holdingStatus === 'checked_out'
|
|
||||||
? (unavailable.find(item => item.service === 'loan') 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) && available.some(item => item.service === 'remote'),
|
|
||||||
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,
|
|
||||||
open:
|
|
||||||
(Array.isArray(available) &&
|
|
||||||
available.some(item => item.service === 'openaccess')) ||
|
|
||||||
undefined,
|
|
||||||
});
|
|
||||||
} catch {
|
|
||||||
// No element available
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
resolve(holdings);
|
|
||||||
},
|
|
||||||
error => {
|
|
||||||
// handle "availability info not found" separately from the problems with getting the info
|
|
||||||
if (error.status === 404) resolve([]);
|
|
||||||
// eslint-disable-next-line unicorn/no-useless-undefined
|
|
||||||
resolve(undefined);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
getHoldingLink(holding: DaiaHolding, open = false) {
|
|
||||||
if (this.hebisProxyUrl === undefined) {
|
|
||||||
this.logger.error('HeBIS proxy url undefined');
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const resourceLink = holding.available?.href;
|
|
||||||
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'] {
|
|
||||||
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 && unavailable[loan.unavailable].expected !== undefined) {
|
|
||||||
return 'checked_out';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
loan.unavailable !== -1 &&
|
|
||||||
unavailable[loan.unavailable].limitations?.some(limitation =>
|
|
||||||
['OnBuy', 'JustReturned'].includes(limitation.id),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
return 'not_yet_available';
|
|
||||||
|
|
||||||
if (
|
|
||||||
loan.unavailable !== -1 &&
|
|
||||||
unavailable[loan.unavailable].limitations?.some(limitation =>
|
|
||||||
['CopyIsMissing', 'Canceled'].includes(limitation.id),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
return 'not_available';
|
|
||||||
|
|
||||||
if (
|
|
||||||
(loan.unavailable !== -1 &&
|
|
||||||
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';
|
|
||||||
|
|
||||||
if (loan.available !== -1) return 'available';
|
|
||||||
|
|
||||||
return 'unknown';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,114 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2022 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.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with
|
|
||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
import {Injectable} from '@angular/core';
|
|
||||||
import {Client} from '@openstapps/api';
|
|
||||||
import {SCHebisSearchRequest} from './protocol/request';
|
|
||||||
import {HebisSearchResponse} from './protocol/response';
|
|
||||||
import {StorageProvider} from '../storage/storage.provider';
|
|
||||||
import {StAppsWebHttpClient} from '../data/stapps-web-http-client.provider';
|
|
||||||
import {HttpClient} from '@angular/common/http';
|
|
||||||
import {DataProvider} from '../data/data.provider';
|
|
||||||
import {SCHebisSearchRoute} from './protocol/route';
|
|
||||||
import {SCSearchRequest, SCSearchResponse} from '@openstapps/core';
|
|
||||||
|
|
||||||
const HEBIS_PREFIX = 'HEB';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generated class for the DataProvider provider.
|
|
||||||
*
|
|
||||||
* See https://angular.io/guide/dependency-injection for more info on providers
|
|
||||||
* and Angular DI.
|
|
||||||
*/
|
|
||||||
@Injectable({
|
|
||||||
providedIn: 'root',
|
|
||||||
})
|
|
||||||
export class HebisDataProvider extends DataProvider {
|
|
||||||
/**
|
|
||||||
* TODO
|
|
||||||
*/
|
|
||||||
storageProvider: StorageProvider;
|
|
||||||
|
|
||||||
httpClient: HttpClient;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instance of hebis search request route
|
|
||||||
*/
|
|
||||||
private readonly hebisSearchRoute = new SCHebisSearchRoute();
|
|
||||||
|
|
||||||
constructor(
|
|
||||||
stAppsWebHttpClient: StAppsWebHttpClient,
|
|
||||||
storageProvider: StorageProvider,
|
|
||||||
httpClient: HttpClient,
|
|
||||||
) {
|
|
||||||
super(stAppsWebHttpClient, storageProvider);
|
|
||||||
this.storageProvider = storageProvider;
|
|
||||||
this.httpClient = httpClient;
|
|
||||||
this.client = new Client(stAppsWebHttpClient, this.backendUrl, this.appVersion);
|
|
||||||
}
|
|
||||||
|
|
||||||
override async search(query: SCSearchRequest): Promise<SCSearchResponse> {
|
|
||||||
const response = await this.hebisSearch({
|
|
||||||
query: query.query ?? '',
|
|
||||||
page: query.from,
|
|
||||||
});
|
|
||||||
console.log(response.pagination);
|
|
||||||
|
|
||||||
return {
|
|
||||||
data: response.data,
|
|
||||||
facets: [],
|
|
||||||
pagination: response.pagination,
|
|
||||||
stats: {
|
|
||||||
time: Number.NaN,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Send a search request to the backend
|
|
||||||
*
|
|
||||||
* All results will be returned if no size is set in the request.
|
|
||||||
* @param searchRequest Search request
|
|
||||||
* @param options Search options
|
|
||||||
* @param options.addPrefix Add HeBIS prefix (useful when having only an ID, e.g. when using PAIA)
|
|
||||||
*/
|
|
||||||
async hebisSearch(
|
|
||||||
searchRequest: SCHebisSearchRequest,
|
|
||||||
options?: {addPrefix: boolean},
|
|
||||||
): Promise<HebisSearchResponse> {
|
|
||||||
if (options?.addPrefix) {
|
|
||||||
searchRequest.query = [HEBIS_PREFIX, searchRequest.query].join('');
|
|
||||||
}
|
|
||||||
|
|
||||||
let page: number | undefined = searchRequest.page;
|
|
||||||
|
|
||||||
if (page === undefined) {
|
|
||||||
const preFlightResponse = await this.client.invokeRoute<HebisSearchResponse>(
|
|
||||||
this.hebisSearchRoute,
|
|
||||||
undefined,
|
|
||||||
{
|
|
||||||
...searchRequest,
|
|
||||||
page: 0,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
page = preFlightResponse.pagination.total;
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.client.invokeRoute<HebisSearchResponse>(this.hebisSearchRoute, undefined, {
|
|
||||||
...searchRequest,
|
|
||||||
page,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2019 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.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with
|
|
||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
import {Component, Input} from '@angular/core';
|
|
||||||
import {SCThings} from '@openstapps/core';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TODO
|
|
||||||
*/
|
|
||||||
@Component({
|
|
||||||
selector: 'stapps-hebis-detail-content',
|
|
||||||
styleUrls: ['hebis-detail-content.scss'],
|
|
||||||
templateUrl: 'hebis-detail-content.html',
|
|
||||||
})
|
|
||||||
export class HebisDetailContentComponent {
|
|
||||||
/**
|
|
||||||
* TODO
|
|
||||||
*/
|
|
||||||
@Input() item: SCThings;
|
|
||||||
}
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
<!--
|
|
||||||
~ 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.
|
|
||||||
~
|
|
||||||
~ This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
~ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
~ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
~ more details.
|
|
||||||
~
|
|
||||||
~ You should have received a copy of the GNU General Public License along with
|
|
||||||
~ this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<div>
|
|
||||||
@switch (item.type) {
|
|
||||||
@case ('book') {
|
|
||||||
<stapps-book-detail-content [item]="$any(item)"></stapps-book-detail-content>
|
|
||||||
}
|
|
||||||
@case ('periodical') {
|
|
||||||
<stapps-periodical-detail-content [item]="$any(item)"></stapps-periodical-detail-content>
|
|
||||||
}
|
|
||||||
@case ('article') {
|
|
||||||
<stapps-article-detail-content [item]="$any(item)"></stapps-article-detail-content>
|
|
||||||
}
|
|
||||||
@default {
|
|
||||||
<ion-item class="ion-text-wrap" lines="inset">
|
|
||||||
<ion-thumbnail slot="start" class="ion-margin-end">
|
|
||||||
<ion-icon color="dark" [name]="item.type | dataIcon"></ion-icon>
|
|
||||||
</ion-thumbnail>
|
|
||||||
<ion-grid>
|
|
||||||
<ion-row>
|
|
||||||
<ion-col>
|
|
||||||
<div class="ion-text-wrap">
|
|
||||||
<h2 class="name">{{ item.name }}</h2>
|
|
||||||
<ion-note>{{ item.type }}</ion-note>
|
|
||||||
</div>
|
|
||||||
</ion-col>
|
|
||||||
</ion-row>
|
|
||||||
</ion-grid>
|
|
||||||
</ion-item>
|
|
||||||
@if (item.description) {
|
|
||||||
<stapps-simple-card
|
|
||||||
[title]="'description' | propertyNameTranslate: item | titlecase"
|
|
||||||
[content]="'description' | thingTranslate: item"
|
|
||||||
></stapps-simple-card>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</div>
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
/*!
|
|
||||||
* Copyright (C) 2022 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.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with
|
|
||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
:host ::ng-deep {
|
|
||||||
ion-grid,
|
|
||||||
ion-col {
|
|
||||||
padding-top: 0;
|
|
||||||
padding-bottom: 0;
|
|
||||||
padding-inline-start: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
ion-card {
|
|
||||||
margin: 0;
|
|
||||||
box-shadow: none;
|
|
||||||
|
|
||||||
ion-card-content {
|
|
||||||
padding-bottom: 8px;
|
|
||||||
|
|
||||||
h1 {
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ion-card-header {
|
|
||||||
padding-top: 8px;
|
|
||||||
padding-bottom: 4px;
|
|
||||||
font-weight: bold;
|
|
||||||
color: var(--ion-color-dark);
|
|
||||||
}
|
|
||||||
|
|
||||||
ion-grid,
|
|
||||||
ion-col {
|
|
||||||
padding-top: 0;
|
|
||||||
padding-bottom: 0;
|
|
||||||
padding-inline-start: 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,114 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with
|
|
||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* eslint-disable @typescript-eslint/no-non-null-assertion,@typescript-eslint/no-explicit-any */
|
|
||||||
/* eslint-disable @typescript-eslint/no-non-null-assertion,@typescript-eslint/no-explicit-any */
|
|
||||||
import {CUSTOM_ELEMENTS_SCHEMA} from '@angular/core';
|
|
||||||
import {ComponentFixture, TestBed} from '@angular/core/testing';
|
|
||||||
import {ActivatedRoute, RouterModule} from '@angular/router';
|
|
||||||
import {TranslateLoader, TranslateModule, TranslateService} from '@ngx-translate/core';
|
|
||||||
import {sampleThingsMap} from '../../../_helpers/data/sample-things';
|
|
||||||
import {HebisRoutingModule} from '../hebis-routing.module';
|
|
||||||
import {HebisModule} from '../hebis.module';
|
|
||||||
import {HebisDataProvider} from '../hebis-data.provider';
|
|
||||||
import {HebisDetailComponent} from './hebis-detail.component';
|
|
||||||
import {Observable, of} from 'rxjs';
|
|
||||||
import {StorageProvider} from '../../storage/storage.provider';
|
|
||||||
import {LoggerModule, NgxLoggerLevel} from 'ngx-logger';
|
|
||||||
import {IonIconDirective} from '../../../util/ion-icon/ion-icon.directive';
|
|
||||||
import {provideIonicAngular} from '@ionic/angular/standalone';
|
|
||||||
|
|
||||||
const translations: any = {data: {detail: {TITLE: 'Foo'}}};
|
|
||||||
|
|
||||||
class TranslateFakeLoader implements TranslateLoader {
|
|
||||||
getTranslation(_lang: string): Observable<any> {
|
|
||||||
return of(translations);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
describe('HebisDetailComponent', () => {
|
|
||||||
let comp: HebisDetailComponent;
|
|
||||||
let fixture: ComponentFixture<HebisDetailComponent>;
|
|
||||||
let dataProvider: HebisDataProvider;
|
|
||||||
const sampleThing = sampleThingsMap.book[0];
|
|
||||||
let translateService: TranslateService;
|
|
||||||
|
|
||||||
// @Component({ selector: 'stapps-data-list-item', template: '' })
|
|
||||||
// class DataListItemComponent {
|
|
||||||
// @Input() item;
|
|
||||||
// }
|
|
||||||
|
|
||||||
const fakeActivatedRoute = {
|
|
||||||
snapshot: {
|
|
||||||
paramMap: {
|
|
||||||
get: () => {
|
|
||||||
return sampleThing.uid;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const storageProviderSpy = jasmine.createSpyObj('StorageProvider', ['init', 'get', 'has', 'put', 'search']);
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
TestBed.configureTestingModule({
|
|
||||||
imports: [
|
|
||||||
RouterModule.forRoot([]),
|
|
||||||
HebisRoutingModule,
|
|
||||||
HebisModule,
|
|
||||||
IonIconDirective,
|
|
||||||
TranslateModule.forRoot({
|
|
||||||
loader: {provide: TranslateLoader, useClass: TranslateFakeLoader},
|
|
||||||
}),
|
|
||||||
LoggerModule.forRoot({level: NgxLoggerLevel.TRACE}),
|
|
||||||
],
|
|
||||||
providers: [
|
|
||||||
provideIonicAngular(),
|
|
||||||
{
|
|
||||||
provide: ActivatedRoute,
|
|
||||||
useValue: fakeActivatedRoute,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
provide: StorageProvider,
|
|
||||||
useValue: storageProviderSpy,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
schemas: [CUSTOM_ELEMENTS_SCHEMA],
|
|
||||||
}).compileComponents();
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
dataProvider = TestBed.inject(HebisDataProvider);
|
|
||||||
translateService = TestBed.inject(TranslateService);
|
|
||||||
spyOn(dataProvider, 'get' as any).and.returnValue(Promise.resolve(sampleThing));
|
|
||||||
spyOn(HebisDetailComponent.prototype, 'getItem').and.callThrough();
|
|
||||||
fixture = TestBed.createComponent(HebisDetailComponent);
|
|
||||||
comp = fixture.componentInstance;
|
|
||||||
translateService.use('foo');
|
|
||||||
fixture.detectChanges();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should create component', () => expect(comp).toBeDefined());
|
|
||||||
|
|
||||||
it('should get a data item', () => {
|
|
||||||
comp.getItem(sampleThing.uid, false);
|
|
||||||
expect(HebisDetailComponent.prototype.getItem).toHaveBeenCalledWith(sampleThing.uid, false);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should get a data item when initialized', () => {
|
|
||||||
comp.ngOnInit();
|
|
||||||
expect(HebisDetailComponent.prototype.getItem).toHaveBeenCalledWith(sampleThing.uid, false);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2022 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.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with
|
|
||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
import {Component, inject, OnInit} from '@angular/core';
|
|
||||||
import {SCUuid} from '@openstapps/core';
|
|
||||||
import {HebisDataProvider} from '../hebis-data.provider';
|
|
||||||
import {DataDetailComponent} from '../../data/detail/data-detail.component';
|
|
||||||
import {DaiaHolding} from '../protocol/response';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A Component to display an SCThing detailed
|
|
||||||
*/
|
|
||||||
@Component({
|
|
||||||
selector: 'stapps-hebis-detail',
|
|
||||||
styleUrls: ['hebis-detail.scss'],
|
|
||||||
templateUrl: 'hebis-detail.html',
|
|
||||||
})
|
|
||||||
export class HebisDetailComponent extends DataDetailComponent implements OnInit {
|
|
||||||
holdings: DaiaHolding[];
|
|
||||||
|
|
||||||
private hebisDataProvider = inject(HebisDataProvider);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @override
|
|
||||||
*/
|
|
||||||
async ngOnInit() {
|
|
||||||
const uid = this.route.snapshot.paramMap.get('uid') || '';
|
|
||||||
await this.getItem(uid ?? '', false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides data item with given UID
|
|
||||||
* @param uid Unique identifier of a thing
|
|
||||||
* @param _forceReload Ignore any cached data
|
|
||||||
*/
|
|
||||||
async getItem(uid: SCUuid, _forceReload: boolean) {
|
|
||||||
this.item = await (this.inputItem ??
|
|
||||||
this.hebisDataProvider.hebisSearch({query: uid, page: 0}).then(
|
|
||||||
result =>
|
|
||||||
// eslint-disable-next-line unicorn/no-null
|
|
||||||
(result.data && result.data[0]) || null,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
<!--
|
|
||||||
~ Copyright (C) 2022 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.
|
|
||||||
~
|
|
||||||
~ This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
~ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
~ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
~ more details.
|
|
||||||
~
|
|
||||||
~ You should have received a copy of the GNU General Public License along with
|
|
||||||
~ this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<ion-header>
|
|
||||||
<ion-toolbar color="primary" mode="ios">
|
|
||||||
<ion-buttons slot="start">
|
|
||||||
<ion-back-button></ion-back-button>
|
|
||||||
</ion-buttons>
|
|
||||||
<ion-title>{{ 'data.detail.TITLE' | translate }}</ion-title>
|
|
||||||
<ion-buttons slot="primary">
|
|
||||||
@if (item) {
|
|
||||||
<stapps-favorite-button [item]="$any(item)"></stapps-favorite-button>
|
|
||||||
}
|
|
||||||
</ion-buttons>
|
|
||||||
</ion-toolbar>
|
|
||||||
</ion-header>
|
|
||||||
<ion-content class="ion-no-padding">
|
|
||||||
<div>
|
|
||||||
@switch (true) {
|
|
||||||
@case (!item && (isDisconnected | async)) {
|
|
||||||
<div class="centered-message-container">
|
|
||||||
<ion-icon name="signal_disconnected"></ion-icon>
|
|
||||||
<ion-label> {{ 'data.detail.COULD_NOT_CONNECT' | translate }} </ion-label>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
@case (item === null) {
|
|
||||||
<div class="centered-message-container">
|
|
||||||
<ion-icon name="link_off"></ion-icon>
|
|
||||||
<ion-label> {{ 'data.detail.NOT_FOUND' | translate }} </ion-label>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
@case (!item && item !== null) {
|
|
||||||
<stapps-skeleton-list-item></stapps-skeleton-list-item>
|
|
||||||
<stapps-skeleton-simple-card></stapps-skeleton-simple-card>
|
|
||||||
}
|
|
||||||
@default {
|
|
||||||
@if (item) {
|
|
||||||
<stapps-hebis-detail-content [item]="item"></stapps-hebis-detail-content>
|
|
||||||
}
|
|
||||||
@if (item) {
|
|
||||||
<stapps-daia-availability></stapps-daia-availability>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</div>
|
|
||||||
</ion-content>
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
::ng-deep {
|
|
||||||
ion-card-header {
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2022 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.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with
|
|
||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
import {NgModule} from '@angular/core';
|
|
||||||
import {RouterModule, Routes} from '@angular/router';
|
|
||||||
import {HebisDetailComponent} from './hebis-detail/hebis-detail.component';
|
|
||||||
import {HebisSearchPageComponent} from './list/hebis-search-page.component';
|
|
||||||
|
|
||||||
const hebisRoutes: Routes = [
|
|
||||||
{path: 'hebis-search', component: HebisSearchPageComponent},
|
|
||||||
{path: 'hebis-detail/:uid', component: HebisDetailComponent},
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Module defining routes for data module
|
|
||||||
*/
|
|
||||||
@NgModule({
|
|
||||||
exports: [RouterModule],
|
|
||||||
imports: [RouterModule.forChild(hebisRoutes)],
|
|
||||||
})
|
|
||||||
export class HebisRoutingModule {}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2022 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.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with
|
|
||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import {Injectable} from '@angular/core';
|
|
||||||
|
|
||||||
@Injectable({
|
|
||||||
providedIn: 'root',
|
|
||||||
})
|
|
||||||
export class HebisSearchProvider {}
|
|
||||||
@@ -1,112 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2018-2022 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.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with
|
|
||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
import {ScrollingModule} from '@angular/cdk/scrolling';
|
|
||||||
import {CommonModule} from '@angular/common';
|
|
||||||
import {provideHttpClient, withInterceptorsFromDi} from '@angular/common/http';
|
|
||||||
import {NgModule} from '@angular/core';
|
|
||||||
import {FormsModule} from '@angular/forms';
|
|
||||||
import {TranslateModule} from '@ngx-translate/core';
|
|
||||||
import {MarkdownModule} from 'ngx-markdown';
|
|
||||||
import {MomentModule} from 'ngx-moment';
|
|
||||||
import {ThingTranslateModule} from '../../translation/thing-translate.module';
|
|
||||||
import {MenuModule} from '../menu/menu.module';
|
|
||||||
import {StorageModule} from '../storage/storage.module';
|
|
||||||
import {HebisDetailComponent} from './hebis-detail/hebis-detail.component';
|
|
||||||
import {HebisDetailContentComponent} from './hebis-detail/hebis-detail-content.component';
|
|
||||||
import {HebisSearchPageComponent} from './list/hebis-search-page.component';
|
|
||||||
import {HebisDataProvider} from './hebis-data.provider';
|
|
||||||
import {DaiaDataProvider} from './daia-data.provider';
|
|
||||||
import {StAppsWebHttpClient} from '../data/stapps-web-http-client.provider';
|
|
||||||
import {HebisRoutingModule} from './hebis-routing.module';
|
|
||||||
import {DataModule} from '../data/data.module';
|
|
||||||
import {DaiaAvailabilityComponent} from './daia-availability/daia-availability.component';
|
|
||||||
import {UtilModule} from '../../util/util.module';
|
|
||||||
import {DaiaHoldingComponent} from './daia-availability/daia-holding.component';
|
|
||||||
import {
|
|
||||||
IonBackButton,
|
|
||||||
IonButton,
|
|
||||||
IonButtons,
|
|
||||||
IonCard,
|
|
||||||
IonCardContent,
|
|
||||||
IonCardHeader,
|
|
||||||
IonCol,
|
|
||||||
IonContent,
|
|
||||||
IonGrid,
|
|
||||||
IonHeader,
|
|
||||||
IonItem,
|
|
||||||
IonLabel,
|
|
||||||
IonNote,
|
|
||||||
IonRow,
|
|
||||||
IonThumbnail,
|
|
||||||
IonTitle,
|
|
||||||
IonToolbar,
|
|
||||||
} from '@ionic/angular/standalone';
|
|
||||||
import {IonIconDirective} from 'src/app/util/ion-icon/ion-icon.directive';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Module for handling data
|
|
||||||
*/
|
|
||||||
@NgModule({
|
|
||||||
declarations: [
|
|
||||||
HebisSearchPageComponent,
|
|
||||||
HebisDetailComponent,
|
|
||||||
HebisDetailContentComponent,
|
|
||||||
DaiaAvailabilityComponent,
|
|
||||||
DaiaHoldingComponent,
|
|
||||||
],
|
|
||||||
imports: [
|
|
||||||
CommonModule,
|
|
||||||
DataModule,
|
|
||||||
FormsModule,
|
|
||||||
HebisRoutingModule,
|
|
||||||
IonIconDirective,
|
|
||||||
MarkdownModule.forRoot(),
|
|
||||||
MenuModule,
|
|
||||||
MomentModule.forRoot({
|
|
||||||
relativeTimeThresholdOptions: {
|
|
||||||
m: 59,
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
ScrollingModule,
|
|
||||||
StorageModule,
|
|
||||||
TranslateModule.forChild(),
|
|
||||||
ThingTranslateModule.forChild(),
|
|
||||||
UtilModule,
|
|
||||||
IonBackButton,
|
|
||||||
IonLabel,
|
|
||||||
IonButton,
|
|
||||||
IonContent,
|
|
||||||
IonButtons,
|
|
||||||
IonTitle,
|
|
||||||
IonToolbar,
|
|
||||||
IonNote,
|
|
||||||
IonHeader,
|
|
||||||
IonGrid,
|
|
||||||
IonRow,
|
|
||||||
IonCol,
|
|
||||||
IonCard,
|
|
||||||
IonCardContent,
|
|
||||||
IonCardHeader,
|
|
||||||
IonItem,
|
|
||||||
IonThumbnail,
|
|
||||||
],
|
|
||||||
providers: [
|
|
||||||
HebisDataProvider,
|
|
||||||
DaiaDataProvider,
|
|
||||||
StAppsWebHttpClient,
|
|
||||||
provideHttpClient(withInterceptorsFromDi()),
|
|
||||||
],
|
|
||||||
})
|
|
||||||
export class HebisModule {}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with
|
|
||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
import {Component} from '@angular/core';
|
|
||||||
import {HebisDataProvider} from '../hebis-data.provider';
|
|
||||||
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
|
||||||
import {DataProvider} from '../../data/data.provider';
|
|
||||||
import {DataRoutingService} from '../../data/data-routing.service';
|
|
||||||
import {Router} from '@angular/router';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* HebisSearchPageComponent queries things and shows list of things as search results and filter as context menu
|
|
||||||
*/
|
|
||||||
@Component({
|
|
||||||
selector: 'stapps-hebissearch-page',
|
|
||||||
templateUrl: 'hebis-search-page.html',
|
|
||||||
styleUrls: ['../../data/list/search-page.scss'],
|
|
||||||
providers: [{provide: DataProvider, useClass: HebisDataProvider}],
|
|
||||||
})
|
|
||||||
export class HebisSearchPageComponent {
|
|
||||||
constructor(dataRoutingService: DataRoutingService, router: Router) {
|
|
||||||
dataRoutingService
|
|
||||||
.itemSelectListener()
|
|
||||||
.pipe(takeUntilDestroyed())
|
|
||||||
.subscribe(async item => {
|
|
||||||
void router.navigate(
|
|
||||||
['hebis-detail', (item.origin && 'originalId' in item.origin && item.origin['originalId']) || ''],
|
|
||||||
{state: {item}},
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
<!--
|
|
||||||
~ Copyright (C) 2022 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.
|
|
||||||
~
|
|
||||||
~ This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
~ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
~ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
~ more details.
|
|
||||||
~
|
|
||||||
~ You should have received a copy of the GNU General Public License along with
|
|
||||||
~ this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<stapps-search-page
|
|
||||||
[placeholder]="'hebisSearch.search_bar.placeholder' | translate"
|
|
||||||
[title]="'hebisSearch.title' | translate"
|
|
||||||
[searchInstruction]="'hebisSearch.instruction' | translate"
|
|
||||||
[itemRouting]="false"
|
|
||||||
[showContextMenu]="false"
|
|
||||||
[pageSize]="1"
|
|
||||||
[navigation]="[{label: 'search.type', routerLink: ['/search']}, {label: 'hebisSearch.type'}]"
|
|
||||||
>
|
|
||||||
</stapps-search-page>
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
import {SCLicensePlate} from '@openstapps/core';
|
|
||||||
|
|
||||||
export interface SCHebisSearchRequest {
|
|
||||||
/**
|
|
||||||
* HDS2 will supply results for the speficied insitute / university if available (Defaults to f-u)
|
|
||||||
*/
|
|
||||||
institute?: SCLicensePlate;
|
|
||||||
/**
|
|
||||||
* Simple pagination support (Defaults to 0)
|
|
||||||
*/
|
|
||||||
page?: number;
|
|
||||||
/**
|
|
||||||
* Search query for HDS
|
|
||||||
*/
|
|
||||||
query: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface SCDaiaAvailabilityRequest {
|
|
||||||
id: string;
|
|
||||||
}
|
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2022 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.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with
|
|
||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import {SCArticle, SCBook, SCPeriodical, SCSearchResultPagination} from '@openstapps/core';
|
|
||||||
|
|
||||||
export interface HebisSearchResponse {
|
|
||||||
/**
|
|
||||||
* Response Array of SCBook type or Object
|
|
||||||
*/
|
|
||||||
data: Array<SCBook | SCArticle | SCPeriodical>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Pagination information
|
|
||||||
*/
|
|
||||||
pagination: SCSearchResultPagination;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface DaiaAvailabilityResponse {
|
|
||||||
document: Array<{
|
|
||||||
item: Array<{
|
|
||||||
id: string;
|
|
||||||
label: string;
|
|
||||||
chronology?: {
|
|
||||||
about?: string;
|
|
||||||
};
|
|
||||||
department: DaiaSimpleContent;
|
|
||||||
available: DaiaService[];
|
|
||||||
unavailable: DaiaService[];
|
|
||||||
debugInfo: string;
|
|
||||||
about?: string;
|
|
||||||
storage?: DaiaSimpleContent;
|
|
||||||
}>;
|
|
||||||
}>;
|
|
||||||
institution: DaiaSimpleContent;
|
|
||||||
timestamp: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface DaiaSimpleContent {
|
|
||||||
id: string;
|
|
||||||
content: string;
|
|
||||||
href?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface DaiaService {
|
|
||||||
delay?: string;
|
|
||||||
href?: string;
|
|
||||||
service: string;
|
|
||||||
expected?: string;
|
|
||||||
limitations?: DaiaSimpleContent[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface DaiaHolding {
|
|
||||||
id: string;
|
|
||||||
department: DaiaSimpleContent;
|
|
||||||
signature: string;
|
|
||||||
storage?: DaiaSimpleContent;
|
|
||||||
available?: DaiaService;
|
|
||||||
unavailable?: DaiaService;
|
|
||||||
about?: string;
|
|
||||||
online: boolean;
|
|
||||||
open?: boolean;
|
|
||||||
dueDate?: string;
|
|
||||||
holdings?: string;
|
|
||||||
status?: 'checked_out' | 'not_yet_available' | 'not_available' | 'library_only' | 'available' | 'unknown';
|
|
||||||
}
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
import {
|
|
||||||
SCAbstractRoute,
|
|
||||||
SCRouteHttpVerbs,
|
|
||||||
SCInternalServerErrorResponse,
|
|
||||||
SCMethodNotAllowedErrorResponse,
|
|
||||||
SCRequestBodyTooLargeErrorResponse,
|
|
||||||
SCSyntaxErrorResponse,
|
|
||||||
SCUnsupportedMediaTypeErrorResponse,
|
|
||||||
SCValidationErrorResponse,
|
|
||||||
} from '@openstapps/core';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Route for searching things
|
|
||||||
*/
|
|
||||||
export class SCHebisSearchRoute extends SCAbstractRoute {
|
|
||||||
constructor() {
|
|
||||||
super();
|
|
||||||
this.errorNames = [
|
|
||||||
SCInternalServerErrorResponse,
|
|
||||||
SCMethodNotAllowedErrorResponse,
|
|
||||||
SCRequestBodyTooLargeErrorResponse,
|
|
||||||
SCSyntaxErrorResponse,
|
|
||||||
SCUnsupportedMediaTypeErrorResponse,
|
|
||||||
SCValidationErrorResponse,
|
|
||||||
];
|
|
||||||
this.method = SCRouteHttpVerbs.POST;
|
|
||||||
this.requestBodyName = 'SCHebisSearchRequest';
|
|
||||||
this.responseBodyName = 'SCHebisSearchResponse';
|
|
||||||
this.statusCodeSuccess = 200;
|
|
||||||
this.urlPath = '/hebissearch';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Route for availability
|
|
||||||
*/
|
|
||||||
export class SCDaiaRoute extends SCAbstractRoute {
|
|
||||||
constructor() {
|
|
||||||
super();
|
|
||||||
this.errorNames = [
|
|
||||||
SCInternalServerErrorResponse,
|
|
||||||
SCMethodNotAllowedErrorResponse,
|
|
||||||
SCRequestBodyTooLargeErrorResponse,
|
|
||||||
SCSyntaxErrorResponse,
|
|
||||||
SCUnsupportedMediaTypeErrorResponse,
|
|
||||||
SCValidationErrorResponse,
|
|
||||||
];
|
|
||||||
this.method = SCRouteHttpVerbs.GET;
|
|
||||||
this.requestBodyName = 'SCDaiaAvailabilityRequest';
|
|
||||||
this.responseBodyName = 'SCDaiaAvailabilityResponse';
|
|
||||||
this.statusCodeSuccess = 200;
|
|
||||||
this.urlPath = '/UB_Frankfurt';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,7 +2,6 @@
|
|||||||
[title]="'jobs.title' | translate"
|
[title]="'jobs.title' | translate"
|
||||||
[placeholder]="'jobs.placeholder' | translate"
|
[placeholder]="'jobs.placeholder' | translate"
|
||||||
[showDefaultData]="true"
|
[showDefaultData]="true"
|
||||||
[navigation]="[]"
|
|
||||||
[forcedFilter]="forcedFilter"
|
[forcedFilter]="forcedFilter"
|
||||||
[backUrl]="'/'"
|
[backUrl]="'/'"
|
||||||
></stapps-search-page>
|
></stapps-search-page>
|
||||||
|
|||||||
@@ -1,50 +0,0 @@
|
|||||||
<!--
|
|
||||||
~ Copyright (C) 2022 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.
|
|
||||||
~
|
|
||||||
~ This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
~ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
~ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
~ more details.
|
|
||||||
~
|
|
||||||
~ You should have received a copy of the GNU General Public License along with
|
|
||||||
~ this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<ion-header>
|
|
||||||
<ion-toolbar color="primary" mode="ios">
|
|
||||||
<ion-buttons slot="start">
|
|
||||||
<ion-back-button></ion-back-button>
|
|
||||||
</ion-buttons>
|
|
||||||
<ion-title>{{ 'library.account.title' | translate | titlecase }}</ion-title>
|
|
||||||
</ion-toolbar>
|
|
||||||
</ion-header>
|
|
||||||
|
|
||||||
<ion-content>
|
|
||||||
@if (name) {
|
|
||||||
<p>
|
|
||||||
{{ 'library.account.greeting' | translate }} {{ name | firstLastName }}!
|
|
||||||
{{ 'library.account.login.success' | translate }}
|
|
||||||
</p>
|
|
||||||
} @else {
|
|
||||||
<p><ion-skeleton-text animated style="width: 80%"></ion-skeleton-text></p>
|
|
||||||
}
|
|
||||||
<ion-item [routerLink]="['profile']">
|
|
||||||
<ion-icon name="account_circle" slot="start"></ion-icon
|
|
||||||
>{{ 'library.account.pages.profile.title' | translate | titlecase }}
|
|
||||||
</ion-item>
|
|
||||||
<ion-item [routerLink]="['holds']">
|
|
||||||
<ion-icon name="collections_bookmark" slot="start"></ion-icon
|
|
||||||
>{{ 'library.account.pages.holds.title' | translate | titlecase }}
|
|
||||||
</ion-item>
|
|
||||||
<ion-item [routerLink]="['checked-out']">
|
|
||||||
<ion-icon name="book" slot="start"></ion-icon
|
|
||||||
>{{ 'library.account.pages.checked_out.title' | translate | titlecase }}
|
|
||||||
</ion-item>
|
|
||||||
<ion-item [routerLink]="['fines']">
|
|
||||||
<ion-icon name="request_quote" slot="start"></ion-icon
|
|
||||||
>{{ 'library.account.pages.fines.title' | translate | titlecase }}
|
|
||||||
</ion-item>
|
|
||||||
</ion-content>
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
ion-content {
|
|
||||||
--padding-start: 8px;
|
|
||||||
--padding-top: 8px;
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
import {Component} from '@angular/core';
|
|
||||||
import {LibraryAccountService} from './library-account.service';
|
|
||||||
|
|
||||||
@Component({
|
|
||||||
templateUrl: './account.page.html',
|
|
||||||
styleUrls: ['./account.page.scss'],
|
|
||||||
})
|
|
||||||
export class LibraryAccountPageComponent {
|
|
||||||
name?: string;
|
|
||||||
|
|
||||||
constructor(private readonly libraryAccountService: LibraryAccountService) {}
|
|
||||||
|
|
||||||
async ionViewWillEnter(): Promise<void> {
|
|
||||||
const patron = await this.libraryAccountService.getPatron();
|
|
||||||
this.name = patron?.name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-51
@@ -1,51 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with
|
|
||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import {Component} from '@angular/core';
|
|
||||||
import {DocumentAction, PAIADocument, PAIADocumentStatus} from '../../types';
|
|
||||||
import {LibraryAccountService} from '../library-account.service';
|
|
||||||
|
|
||||||
@Component({
|
|
||||||
selector: 'app-checked-out',
|
|
||||||
templateUrl: './checked-out-page.html',
|
|
||||||
styleUrls: ['./checked-out-page.scss'],
|
|
||||||
})
|
|
||||||
export class CheckedOutPageComponent {
|
|
||||||
checkedOutItems?: PAIADocument[];
|
|
||||||
|
|
||||||
constructor(private readonly libraryAccountService: LibraryAccountService) {}
|
|
||||||
|
|
||||||
async ionViewWillEnter(): Promise<void> {
|
|
||||||
await this.fetchItems();
|
|
||||||
}
|
|
||||||
|
|
||||||
async onDocumentAction(documentAction: DocumentAction) {
|
|
||||||
const answer = await this.libraryAccountService.handleDocumentAction(documentAction);
|
|
||||||
|
|
||||||
if (answer) await this.fetchItems();
|
|
||||||
}
|
|
||||||
|
|
||||||
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 {
|
|
||||||
await this.libraryAccountService.handleError();
|
|
||||||
this.checkedOutItems = [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
<!--
|
|
||||||
~ Copyright (C) 2022 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.
|
|
||||||
~
|
|
||||||
~ This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
~ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
~ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
~ more details.
|
|
||||||
~
|
|
||||||
~ You should have received a copy of the GNU General Public License along with
|
|
||||||
~ this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<ion-header>
|
|
||||||
<ion-toolbar color="primary" mode="ios">
|
|
||||||
<ion-buttons slot="start">
|
|
||||||
<ion-back-button></ion-back-button>
|
|
||||||
</ion-buttons>
|
|
||||||
<ion-title>{{ 'library.account.pages.checked_out.title' | translate | titlecase }}</ion-title>
|
|
||||||
</ion-toolbar>
|
|
||||||
</ion-header>
|
|
||||||
|
|
||||||
<ion-content>
|
|
||||||
@if (checkedOutItems) {
|
|
||||||
@for (checkedOutItem of checkedOutItems; track checkedOutItem) {
|
|
||||||
<stapps-paia-item
|
|
||||||
[item]="checkedOutItem"
|
|
||||||
[propertiesToShow]="['label', 'renewals', 'duedate']"
|
|
||||||
(documentAction)="onDocumentAction($event)"
|
|
||||||
listName="checked_out"
|
|
||||||
>
|
|
||||||
</stapps-paia-item>
|
|
||||||
} @empty {
|
|
||||||
<ion-label class="centered-message-container">
|
|
||||||
{{ 'search.nothing_found' | translate | titlecase }}
|
|
||||||
</ion-label>
|
|
||||||
}
|
|
||||||
} @else {
|
|
||||||
<stapps-skeleton-list-item [hideThumbnail]="true"></stapps-skeleton-list-item>
|
|
||||||
}
|
|
||||||
</ion-content>
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with
|
|
||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import {Component, Input} from '@angular/core';
|
|
||||||
import {PAIAFee} from '../../../types';
|
|
||||||
import {SCArticle, SCBook, SCPeriodical} from '@openstapps/core';
|
|
||||||
import {LibraryAccountService} from '../../library-account.service';
|
|
||||||
|
|
||||||
@Component({
|
|
||||||
selector: 'stapps-fee-item',
|
|
||||||
templateUrl: './fee-item.html',
|
|
||||||
styleUrls: ['./fee-item.scss'],
|
|
||||||
})
|
|
||||||
export class FeeItemComponent {
|
|
||||||
_fee: PAIAFee;
|
|
||||||
|
|
||||||
book?: SCBook | SCPeriodical | SCArticle;
|
|
||||||
|
|
||||||
hasEdition = false;
|
|
||||||
|
|
||||||
@Input()
|
|
||||||
set fee(fee: PAIAFee) {
|
|
||||||
this.hasEdition = !fee.edition?.includes('null');
|
|
||||||
this._fee = fee;
|
|
||||||
if (this.hasEdition) {
|
|
||||||
this.libraryAccountService.getDocumentFromHDS(fee.edition as string).then(book => {
|
|
||||||
this.book = book;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
get fee() {
|
|
||||||
return this._fee;
|
|
||||||
}
|
|
||||||
|
|
||||||
propertiesToShow: (keyof PAIAFee)[] = ['about', 'date', 'amount'];
|
|
||||||
|
|
||||||
constructor(private readonly libraryAccountService: LibraryAccountService) {}
|
|
||||||
}
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
<!--
|
|
||||||
~ 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.
|
|
||||||
~
|
|
||||||
~ This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
~ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
~ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
~ more details.
|
|
||||||
~
|
|
||||||
~ You should have received a copy of the GNU General Public License along with
|
|
||||||
~ this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<ion-item>
|
|
||||||
<ion-label class="ion-text-wrap">
|
|
||||||
@if (hasEdition) {
|
|
||||||
@if (book) {
|
|
||||||
<h2 class="name">{{ 'library.account.pages.fines.labels.edition' | translate }}: {{ book.name }}</h2>
|
|
||||||
} @else {
|
|
||||||
<h2>
|
|
||||||
<ion-skeleton-text animated style="width: 80%"></ion-skeleton-text>
|
|
||||||
</h2>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@for (property of propertiesToShow; track property) {
|
|
||||||
@if (fee[property]) {
|
|
||||||
<p>
|
|
||||||
{{ 'library.account.pages.fines.labels' + '.' + property | translate }}:
|
|
||||||
@if (!['date'].includes(property)) {
|
|
||||||
{{ fee[property] }}
|
|
||||||
} @else {
|
|
||||||
{{ fee[property] | amDateFormat: 'll' }}
|
|
||||||
}
|
|
||||||
</p>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</ion-label>
|
|
||||||
</ion-item>
|
|
||||||
@@ -1,76 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2022 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.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with
|
|
||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import {Component, EventEmitter, Input, Output} from '@angular/core';
|
|
||||||
import {DocumentAction, PAIADocument, PAIADocumentStatus, PAIADocumentVisualStatus} from '../../../types';
|
|
||||||
import {LibraryAccountService} from '../../library-account.service';
|
|
||||||
|
|
||||||
@Component({
|
|
||||||
selector: 'stapps-paia-item',
|
|
||||||
templateUrl: './paiaitem.html',
|
|
||||||
styleUrls: ['./paiaitem.scss'],
|
|
||||||
})
|
|
||||||
export class PAIAItemComponent {
|
|
||||||
private _item: PAIADocument;
|
|
||||||
|
|
||||||
renewable: boolean;
|
|
||||||
|
|
||||||
visualStatus?: PAIADocumentVisualStatus;
|
|
||||||
|
|
||||||
constructor(private readonly libraryAccountService: LibraryAccountService) {}
|
|
||||||
|
|
||||||
@Input()
|
|
||||||
set item(value: PAIADocument) {
|
|
||||||
this._item = value;
|
|
||||||
void this.setRenewable();
|
|
||||||
this.visualStatus = this.getVisualStatus(Number(this.item.status));
|
|
||||||
}
|
|
||||||
|
|
||||||
get item(): PAIADocument {
|
|
||||||
return this._item;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Input()
|
|
||||||
propertiesToShow: (keyof PAIADocument)[];
|
|
||||||
|
|
||||||
@Input()
|
|
||||||
listName: string;
|
|
||||||
|
|
||||||
@Output()
|
|
||||||
documentAction: EventEmitter<DocumentAction> = new EventEmitter<DocumentAction>();
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
private getVisualStatus(status: PAIADocumentStatus): PAIADocumentVisualStatus | undefined {
|
|
||||||
switch (status) {
|
|
||||||
case PAIADocumentStatus.Ordered: {
|
|
||||||
return {color: 'warning', status: status, statusText: 'ordered'};
|
|
||||||
}
|
|
||||||
case PAIADocumentStatus.Provided: {
|
|
||||||
return {color: 'success', status: status, statusText: 'ready'};
|
|
||||||
}
|
|
||||||
default: {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
<!--
|
|
||||||
~ 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.
|
|
||||||
~
|
|
||||||
~ This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
~ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
~ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
~ more details.
|
|
||||||
~
|
|
||||||
~ You should have received a copy of the GNU General Public License along with
|
|
||||||
~ this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<ion-item>
|
|
||||||
<ion-label class="ion-text-wrap">
|
|
||||||
@if (item.about) {
|
|
||||||
<h2 class="name">
|
|
||||||
@if (visualStatus) {
|
|
||||||
<ion-badge [color]="visualStatus.color" slot="start">
|
|
||||||
{{ 'library.account.pages' + '.' + listName + '.' + visualStatus.statusText | translate }}
|
|
||||||
</ion-badge>
|
|
||||||
}
|
|
||||||
{{ item.about }}
|
|
||||||
</h2>
|
|
||||||
}
|
|
||||||
@for (property of propertiesToShow; track property) {
|
|
||||||
@if (item[property]) {
|
|
||||||
<p>
|
|
||||||
{{ 'library.account.pages' + '.' + listName + '.' + 'labels' + '.' + property | translate }}:
|
|
||||||
@if (!['starttime', 'duedate'].includes(property)) {
|
|
||||||
{{ item[property] }}
|
|
||||||
} @else {
|
|
||||||
{{ $any(item[property]) | amDateFormat: 'll' }}
|
|
||||||
}
|
|
||||||
</p>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
<span class="ion-float-right">
|
|
||||||
<!-- TODO: Add "cancel button" when functionality ready for production-->
|
|
||||||
<!-- <ion-button-->
|
|
||||||
<!-- *ngIf="item.cancancel"-->
|
|
||||||
<!-- color="primary"-->
|
|
||||||
<!-- (click)="onClick('cancel')"-->
|
|
||||||
<!-- >-->
|
|
||||||
<!-- {{ 'library.account.actions.cancel.header' | translate }}</ion-button-->
|
|
||||||
<!-- >-->
|
|
||||||
@if (renewable && item.canrenew) {
|
|
||||||
<ion-button color="primary" (click)="onClick('renew')">
|
|
||||||
{{ 'library.account.actions.renew.header' | translate }}</ion-button
|
|
||||||
>
|
|
||||||
}
|
|
||||||
</span>
|
|
||||||
</ion-label>
|
|
||||||
</ion-item>
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user