From 42b860e41793fc3983a39237a4f7128416485fae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jovan=20Kruni=C4=87?= Date: Fri, 11 Nov 2022 14:08:53 +0000 Subject: [PATCH] feat: add library action confirmations Closes #334 --- src/app/app.component.ts | 1 + .../feedback/feedback-page.component.ts | 1 + .../account/checked-out/checked-out-page.html | 2 +- .../account/elements/paia-item/paiaitem.html | 2 +- .../account/library-account.service.ts | 38 +++++++++++++++---- src/assets/i18n/de.json | 15 +++++--- src/assets/i18n/en.json | 17 +++++---- 7 files changed, 53 insertions(+), 23 deletions(-) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 5d4b5b2f..ed623f20 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -147,6 +147,7 @@ export class AppComponent implements AfterContentInit { const toast = await this.toastController.create({ message: message, duration: 2000, + color: 'success', }); await toast.present(); } diff --git a/src/app/modules/feedback/feedback-page.component.ts b/src/app/modules/feedback/feedback-page.component.ts index eedcc054..c4c30d99 100644 --- a/src/app/modules/feedback/feedback-page.component.ts +++ b/src/app/modules/feedback/feedback-page.component.ts @@ -123,6 +123,7 @@ export class FeedbackPageComponent { 'feedback.system_messages.success', ), duration: 2000, + color: 'success', }); await toast.present(); } diff --git a/src/app/modules/library/account/checked-out/checked-out-page.html b/src/app/modules/library/account/checked-out/checked-out-page.html index 445aa449..b55f2b38 100644 --- a/src/app/modules/library/account/checked-out/checked-out-page.html +++ b/src/app/modules/library/account/checked-out/checked-out-page.html @@ -14,7 +14,7 @@ diff --git a/src/app/modules/library/account/elements/paia-item/paiaitem.html b/src/app/modules/library/account/elements/paia-item/paiaitem.html index 872aa168..b7245174 100644 --- a/src/app/modules/library/account/elements/paia-item/paiaitem.html +++ b/src/app/modules/library/account/elements/paia-item/paiaitem.html @@ -48,7 +48,7 @@ diff --git a/src/app/modules/library/account/library-account.service.ts b/src/app/modules/library/account/library-account.service.ts index 8de44ad0..16c96a04 100644 --- a/src/app/modules/library/account/library-account.service.ts +++ b/src/app/modules/library/account/library-account.service.ts @@ -33,7 +33,7 @@ import {PAIATokenResponse} from '../../auth/paia/paia-token-response'; import {AuthHelperService} from '../../auth/auth-helper.service'; import {ConfigProvider} from '../../config/config.provider'; import {TranslateService} from '@ngx-translate/core'; -import {AlertController} from '@ionic/angular'; +import {AlertController, ToastController} from '@ionic/angular'; import {HebisSearchResponse} from '../../hebis/protocol/response'; @Injectable({ @@ -57,6 +57,7 @@ export class LibraryAccountService { readonly configProvider: ConfigProvider, private readonly translateService: TranslateService, private readonly alertController: AlertController, + private readonly toastController: ToastController, ) { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const config: SCFeatureConfigurationExtern = ( @@ -165,18 +166,28 @@ export class LibraryAccountService { return; } - cancelReservation(document: PAIADocument) { - return this.performRequest( + async cancelReservation(document: PAIADocument) { + const result = await this.performRequest( `${this.baseUrl}/{patron}/cancel`, 'POST', {doc: [document]}, ); + if (result) { + void this.onSuccess('cancel'); + } } - renewLanding(document: PAIADocument) { - return this.performRequest(`${this.baseUrl}/{patron}/renew`, 'POST', { - doc: [document], - }); + async renewLending(document: PAIADocument) { + const result = await this.performRequest( + `${this.baseUrl}/{patron}/renew`, + 'POST', + { + doc: [document], + }, + ); + if (result) { + void this.onSuccess('renew'); + } } async handleDocumentAction(documentAction: DocumentAction): Promise { @@ -187,7 +198,7 @@ export class LibraryAccountService { return this.cancelReservation(documentAction.doc); break; case 'renew': - return this.renewLanding(documentAction.doc); + return this.renewLending(documentAction.doc); } }; const alert = await this.alertController.create({ @@ -234,4 +245,15 @@ export class LibraryAccountService { await alert.present(); } + + async onSuccess(action: DocumentAction['action']) { + const toast = await this.toastController.create({ + message: this.translateService.instant( + `library.account.actions.${action}.success`, + ), + duration: 2000, + color: 'success', + }); + await toast.present(); + } } diff --git a/src/assets/i18n/de.json b/src/assets/i18n/de.json index a33b8bfb..2ed5b2b3 100644 --- a/src/assets/i18n/de.json +++ b/src/assets/i18n/de.json @@ -284,7 +284,8 @@ "title": "Titel", "about": "Mehr Informationen", "label": "Signatur", - "endtime": "Rückgabedatum" + "endtime": "Leihfristende", + "renewals": "Verlängerungen" } }, "fines": { @@ -292,7 +293,7 @@ "labels": { "amount": "Betrag", "about": "Information", - "date": "Rückgabedatum", + "date": "Leihfristende", "item": "Artikel", "edition": "Ausgabe", "feetype": "Gebührenart", @@ -304,13 +305,15 @@ "actions": { "cancel": { "header": "Vormerkung löschen", - "text": "Bist Du dir sicher, die Vormerkung von \"{{value}}\" zu löschen?", - "unknown_book": "unbekanntem Titel" + "text": "Soll die Vormerkung von \"{{value}}\" gelöscht werden?", + "unknown_book": "unbekannter Titel", + "success": "Vormerkung erfolgreich gelöscht." }, "renew": { "header": "Ausleihfrist verlängern", - "text": "Bist Du dir sicher, die Ausleihfrist von \"{{value}}\" zu verlängern?", - "unknown_book": "unbekanntem Titel" + "text": "Soll die Ausleihfrist von \"{{value}}\" verlängert werden?", + "unknown_book": "unbekannter Titel", + "success": "Ausleihfrist erfolgreich verlängert." } } } diff --git a/src/assets/i18n/en.json b/src/assets/i18n/en.json index c1743c69..0a241fda 100644 --- a/src/assets/i18n/en.json +++ b/src/assets/i18n/en.json @@ -284,7 +284,8 @@ "title": "Title", "about": "More information", "label": "Label", - "endtime": "Return date" + "endtime": "Due date", + "renewals": "Renewals" } }, "fines": { @@ -292,7 +293,7 @@ "labels": { "amount": "Amount", "about": "About", - "date": "Return date", + "date": "Due date", "item": "Item", "edition": "Edition", "feetype": "Fee type", @@ -304,13 +305,15 @@ "actions": { "cancel": { "header": "Cancel reservation", - "text": "Are you sure you want to extend the landing period of \"{{value}}\"?", - "unknown_book": "unknown title" + "text": "Are you sure you want to extend the lending period of \"{{value}}\"?", + "unknown_book": "unknown title", + "success": "Reservation cancelled successfully." }, "renew": { - "header": "Extend landing period", - "text": "Are you sure you want to extend the landing period of \"{{value}}\"?", - "unknown_book": "unknown title" + "header": "Extend lending period", + "text": "Are you sure you want to extend the lending period of \"{{value}}\"?", + "unknown_book": "unknown title", + "success": "Lending period extended successfully." } } }