From e2c1be584a6f00ffeedfafe678c04ba5c14025f6 Mon Sep 17 00:00:00 2001 From: Renaud Michotte Date: Tue, 27 Oct 2020 10:02:10 +0100 Subject: [PATCH] circulation: circulation infos refactoring. The message returned by the backend when a user is blocked has changed. This commit adapts the UI to this change and display the error message returned by the backend directly. This commit also adds counter on tabs of the patron circulation detailed page. Available counters are for checkin/checkout, pickup and pending tabs. Small correction on the template detail view. Closes rero/rero-ils#1278 Closes rero/rero-ils#1281 Authored-by: Renaud Michotte --- .../checkin/checkin.component.html | 6 -- .../patron/card/card.component.html | 48 ++++++----- .../circulation/patron/card/card.component.ts | 44 ++-------- .../circulation/patron/loan/loan.component.ts | 32 +++----- .../patron/main/main.component.html | 38 ++++----- .../circulation/patron/main/main.component.ts | 79 ++++++++++++++---- projects/admin/src/app/class/user.ts | 71 ++++++++++++---- .../template-detail-view.component.html | 2 +- .../admin/src/app/service/patron.service.ts | 11 +++ .../admin/src/app/service/user.service.ts | 82 +++++++++---------- projects/admin/src/app/utils/utils.ts | 35 ++++++++ 11 files changed, 271 insertions(+), 177 deletions(-) create mode 100644 projects/admin/src/app/utils/utils.ts diff --git a/projects/admin/src/app/circulation/checkin/checkin.component.html b/projects/admin/src/app/circulation/checkin/checkin.component.html index b79c96043..4432d2438 100644 --- a/projects/admin/src/app/circulation/checkin/checkin.component.html +++ b/projects/admin/src/app/circulation/checkin/checkin.component.html @@ -31,12 +31,6 @@ -
-
- -
-
-
-
- {{ patron.birth_date | dateTranslate:'mediumDate' }} -
-
- {{ patron.city}} -
+
{{ patron.birth_date | dateTranslate:'mediumDate' }}
+
{{ patron.city }}
-
- {{ patronType }} -
-
- - {{ patron.patron.barcode }} - +
+ {{ patronTypeName }}
+
{{ patron.patron.barcode }}
- - + + + + + + + + + + diff --git a/projects/admin/src/app/circulation/patron/card/card.component.ts b/projects/admin/src/app/circulation/patron/card/card.component.ts index 4c0e6df70..653e2609a 100644 --- a/projects/admin/src/app/circulation/patron/card/card.component.ts +++ b/projects/admin/src/app/circulation/patron/card/card.component.ts @@ -15,56 +15,28 @@ * along with this program. If not, see . */ -import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; -import { DomSanitizer, SafeHtml } from '@angular/platform-browser'; -import { RecordService } from '@rero/ng-core'; -import { map } from 'rxjs/operators'; +import { Component, EventEmitter, Input, Output } from '@angular/core'; import { User } from '../../../class/user'; +import { getBootstrapLevel } from '../../../utils/utils'; + @Component({ selector: 'admin-circulation-patron-detailed', templateUrl: './card.component.html', styleUrls: ['./card.component.scss'] }) -export class CardComponent implements OnInit { +export class CardComponent { @Input() patron: User; @Output() clearPatron = new EventEmitter(); - patronType$: any; - - constructor( - private recordService: RecordService, - private _sanitizer: DomSanitizer - ) { } - - ngOnInit() { - if (this.patron) { - this.patronType$ = this.recordService.getRecord('patron_types', this.patron.patron.type.pid).pipe( - map(patronType => patronType.metadata.name) - ); - } - } clear() { if (this.patron) { this.clearPatron.emit(this.patron); } } - /** - * Get the patron notes. - * - * It replace a new line to the corresponding html code. - * Allows to render html. - */ - get notes(): Array<{ type: string, content: SafeHtml }> { - if (!this.patron || !this.patron.notes || this.patron.notes.length < 1) { - return null; - } - return this.patron.notes.map((note: any) => { - return { - type: note.type, - content: this._sanitizer.bypassSecurityTrustHtml( - note.content.replace('\n', '
')) - }; - }); + + getBoootstrapColor(level: string): string { + return getBootstrapLevel(level); + return 'info'; } } 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 43c74c135..6959a92e3 100644 --- a/projects/admin/src/app/circulation/patron/loan/loan.component.ts +++ b/projects/admin/src/app/circulation/patron/loan/loan.component.ts @@ -21,15 +21,13 @@ import { ToastrService } from 'ngx-toastr'; import { forkJoin, Subscription } 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'; @Component({ selector: 'admin-loan', - templateUrl: './loan.component.html', - providers: [PatronBlockedMessagePipe] + templateUrl: './loan.component.html' }) export class LoanComponent implements OnInit, OnDestroy { public placeholder: string = this._translate.instant( @@ -65,15 +63,13 @@ export class LoanComponent implements OnInit, OnDestroy { * @param _toastService: Toastr Service * @param _patronService: Patron Service * @param _userService: UserService - * @param _patronBlockedMessagePipe: PatronBlockingPipe */ constructor( private _itemsService: ItemsService, private _translate: TranslateService, private _toastService: ToastrService, private _patronService: PatronService, - private _userService: UserService, - private _patronBlockedMessagePipe: PatronBlockedMessagePipe + private _userService: UserService ) {} ngOnInit() { @@ -212,12 +208,14 @@ export class LoanComponent implements OnInit, OnDestroy { this._translate.instant('Checkin') ); } + this.patron.decrementCirculationStatistic('loans'); break; } case ItemAction.checkout: { this._displayCirculationNote(newItem, ItemNoteType.CHECKOUT); this.checkedOutItems.unshift(newItem); this.checkedInItems = this.checkedInItems.filter(currItem => currItem.pid !== newItem.pid); + this.patron.incrementCirculationStatistic('loans'); break; } case ItemAction.extend_loan: { @@ -236,23 +234,17 @@ export class LoanComponent implements OnInit, OnDestroy { errorMessage = err.error.message; } if (err.error.status === 403) { - // Specific case when user is blocked (for better user comprehension) - if (errorMessage !== '' && errorMessage.startsWith('BLOCKED USER')) { - const blockedMessage = this._patronBlockedMessagePipe.transform(this.patron); - this._toastService.error( - `${this._translate.instant('Checkout not possible.')} ${blockedMessage}`, - this._translate.instant('Circulation') - ); - } else { - this._toastService.error( - this._translate.instant('Checkout is not allowed by circulation policy'), - this._translate.instant('Checkout') - ); - } + const message = errorMessage || this._translate.instant('Checkout is not allowed by circulation policy'); + this._toastService.error( + message, + this._translate.instant('Circulation'), + {disableTimeOut: true, closeButton: true, enableHtml: true} + ); } else { this._toastService.error( this._translate.instant('An error occurred on the server: ') + errorMessage, - this._translate.instant('Circulation') + this._translate.instant('Circulation'), + {disableTimeOut: true, closeButton: true, enableHtml: true} ); } this.searchText = ''; diff --git a/projects/admin/src/app/circulation/patron/main/main.component.html b/projects/admin/src/app/circulation/patron/main/main.component.html index 68fa54e87..bd9030b79 100644 --- a/projects/admin/src/app/circulation/patron/main/main.component.html +++ b/projects/admin/src/app/circulation/patron/main/main.component.html @@ -25,12 +25,6 @@ -
- -
-