diff --git a/projects/admin/src/app/circulation/checkin/checkin.component.ts b/projects/admin/src/app/circulation/checkin/checkin.component.ts index a4ee487a8..2dc183ea2 100644 --- a/projects/admin/src/app/circulation/checkin/checkin.component.ts +++ b/projects/admin/src/app/circulation/checkin/checkin.component.ts @@ -20,12 +20,12 @@ import { Router } from '@angular/router'; import { TranslateService } from '@ngx-translate/core'; import { RecordService } from '@rero/ng-core'; import { ToastrService } from 'ngx-toastr'; -import { map } from 'rxjs/operators'; +import { finalize, map } from 'rxjs/operators'; +import { Item, ItemAction, ItemNoteType, ItemStatus, LoanState } from '../../class/items'; import { User } from '../../class/user'; import { ItemsService } from '../../service/items.service'; import { PatronService } from '../../service/patron.service'; import { UserService } from '../../service/user.service'; -import { Item, ItemAction, ItemNoteType, ItemStatus } from '../../class/items'; @Component({ selector: 'admin-circulation-checkout', @@ -138,13 +138,7 @@ export class CheckinComponent implements OnInit { error => { // If no action could be done by the '/item/checkin' api, an error will be raised. // catch this error to display it as an toastr message. - const message = (error.hasOwnProperty('error') && error.error.hasOwnProperty('status')) - ? error.error.status.replace(/^error:/, '') - : error.message; - this._toastService.warning( - this._translate.instant(message), - this._translate.instant('Checkin') - ); + this._checkinErrorManagement(error, itemBarcode); } ); } @@ -240,6 +234,41 @@ export class CheckinComponent implements OnInit { } } + + /** create the most relevant message concerning a checkin operation error and display it as a toastr + * + * @param error: the raised error + * @param barcode: the item barcode searched + */ + private _checkinErrorManagement(error: any, barcode: string) { + // get the error message from the raised error. This will be the toastr message core. + let message = (error.hasOwnProperty('error') && error.error.hasOwnProperty('status')) + ? error.error.status.replace(/^error:/, '') + : error.message; + + // the message could contains some data information from the item. So we need to load the item + this._itemsService.getItem(barcode).pipe( + finalize(() => { + this._toastService.warning( + this._translate.instant(message), + this._translate.instant('Checkin'), + { enableHtml: true } + ); + }) + ).subscribe( + item => { + console.log(item); + message += `
${this._translate.instant('Status')}: ${this._translate.instant(item.status.toString())}`; + if (item.status === ItemStatus.IN_TRANSIT && item.loan && item.loan.item_destination) { + message += ` (${this._translate.instant('to')} ${item.loan.item_destination.library_name})`; + } + }, + () => { + message += '
' + this._translate.instant('Item not found!'); + } + ); + } + hasFees(event: boolean) { if (event) { this._toastService.error( diff --git a/projects/admin/src/app/circulation/patron/loan/loan.component.ts b/projects/admin/src/app/circulation/patron/loan/loan.component.ts index c782015c5..4e80649cc 100644 --- a/projects/admin/src/app/circulation/patron/loan/loan.component.ts +++ b/projects/admin/src/app/circulation/patron/loan/loan.component.ts @@ -19,12 +19,12 @@ import { Component, OnInit } from '@angular/core'; import { TranslateService } from '@ngx-translate/core'; import { ToastrService } from 'ngx-toastr'; import { forkJoin } from 'rxjs'; +import { Item, ItemAction, ItemNoteType, ItemStatus } from '../../../class/items'; import { User } from '../../../class/user'; +import { PatronBlockedMessagePipe } from '../../../pipe/patron-blocked-message.pipe'; +import { ItemsService } from '../../../service/items.service'; import { PatronService } from '../../../service/patron.service'; import { UserService } from '../../../service/user.service'; -import { Item, ItemAction, ItemNoteType, ItemStatus } from '../../../class/items'; -import { ItemsService } from '../../../service/items.service'; -import { PatronBlockedMessagePipe } from '../../../pipe/patron-blocked-message.pipe'; @Component({ selector: 'admin-loan', @@ -190,6 +190,13 @@ export class LoanComponent implements OnInit { this._displayCirculationNote(newItem, ItemNoteType.CHECKIN); this.checkedOutItems = this.checkedOutItems.filter(currItem => currItem.pid !== newItem.pid); this.checkedInItems.unshift(newItem); + // display a toast message if the item goes in transit... + if (newItem.status === ItemStatus.IN_TRANSIT) { + this._toastService.warning( + this._translate.instant('The item is ' + ItemStatus.IN_TRANSIT), + this._translate.instant('Checkin') + ); + } break; } case ItemAction.checkout: { @@ -229,7 +236,7 @@ export class LoanComponent implements OnInit { } } else { this._toastService.error( - this._translate.instant('An error occured on the server: ') + errorMessage, + this._translate.instant('An error occurred on the server: ') + errorMessage, this._translate.instant('Circulation') ); } diff --git a/projects/admin/src/app/class/items.ts b/projects/admin/src/app/class/items.ts index 9130617c8..e239fcdca 100644 --- a/projects/admin/src/app/class/items.ts +++ b/projects/admin/src/app/class/items.ts @@ -85,6 +85,16 @@ export enum ItemAction { type ItemActionObjectType = {[key in keyof typeof ItemAction]: R }; + +export class LoanDestination { + location_name: string; + library_name: string; + + constructor(obj?: any) { + Object.assign(this, obj) + } +} + export class Loan { pid?: string; @@ -96,6 +106,7 @@ export class Loan { end_date?: Moment; request_expire_date?: Moment; pickup_location_pid?: string; + item_destination?: LoanDestination; constructor(obj?: any) { Object.assign(this, obj);