Skip to content

Commit

Permalink
circulation : toastr message when item goes in transit
Browse files Browse the repository at this point in the history
Adds a toastr message to inform the librarian that the checked-in item
goes in transit.

Co-Authored-by: Renaud Michtote <renaud.michotte@gmail.com>
  • Loading branch information
zannkukai committed Aug 18, 2020
1 parent 04f0d14 commit f0170c7
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 13 deletions.
47 changes: 38 additions & 9 deletions projects/admin/src/app/circulation/checkin/checkin.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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);
}
);
}
Expand Down Expand Up @@ -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 += `<br/>${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 += '<br/>' + this._translate.instant('Item not found!');
}
);
}

hasFees(event: boolean) {
if (event) {
this._toastService.error(
Expand Down
15 changes: 11 additions & 4 deletions projects/admin/src/app/circulation/patron/loan/loan.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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')
);
}
Expand Down
11 changes: 11 additions & 0 deletions projects/admin/src/app/class/items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ export enum ItemAction {

type ItemActionObjectType<R> = {[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;
Expand All @@ -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);
Expand Down

0 comments on commit f0170c7

Please sign in to comment.