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..3eb6b0d52 100644
--- a/projects/admin/src/app/circulation/patron/main/main.component.html
+++ b/projects/admin/src/app/circulation/patron/main/main.component.html
@@ -39,10 +39,12 @@
class="nav-link"
routerLinkActive="active"
[routerLinkActiveOptions]="{exact: true}"
- [routerLink]="['/circulation', 'patron', patron.patron.barcode, 'loan']"
- translate
- >Checkin/Checkout
+ [routerLink]="['/circulation', 'patron', patron.patron.barcode, 'loan']">
+ {{ 'Checkin/Checkout' | translate }}
+ 0" class="badge badge-info font-weight-normal">
+ {{ this.patronCirculationStatistics.loans }}
+
+
To pick up
+ [routerLink]="['/circulation', 'patron', patron.patron.barcode, 'pickup']">
+ {{ 'To pick up' | translate }}
+ 0" class="badge badge-info font-weight-normal">
+ {{ this.patronCirculationStatistics.pickup }}
+
+
Pending
+=======
+ [routerLink]="['/circulation', 'patron', patron.patron.barcode, 'requested']">
+ {{ 'Pending' | translate }}
+ 0" class="badge badge-info font-weight-normal">
+ {{ this.patronCirculationStatistics.pending }}
+
+
+>>>>>>> circulation: add patron circulation statistics
- {{ 'Fees' }}
+ {{ 'Fees' | translate }}
0" class="badge badge-warning font-weight-normal">
{{ transactionsTotalAmount | currency: organisation.default_currency }}
diff --git a/projects/admin/src/app/circulation/patron/main/main.component.ts b/projects/admin/src/app/circulation/patron/main/main.component.ts
index 94ff3a305..7cee45748 100644
--- a/projects/admin/src/app/circulation/patron/main/main.component.ts
+++ b/projects/admin/src/app/circulation/patron/main/main.component.ts
@@ -31,6 +31,16 @@ export class MainComponent implements OnInit, OnDestroy {
patron: User = undefined;
+ /** circulation statistics about a patron */
+ patronCirculationStatistics = {
+ loans: 0,
+ pickup: 0,
+ pending: 0,
+ };
+
+ /** current patron as observable */
+ patron$: Observable;
+
/** the total amount of all 'open' patron transactions for the current patron */
transactionsTotalAmount = 0;
@@ -52,6 +62,7 @@ export class MainComponent implements OnInit, OnDestroy {
this._patronSubscription$ = this.patronService.getPatron(barcode).subscribe((patron) => {
if (patron) {
this.patron = patron;
+ this.patronService.getCirculationStats(patron.pid).subscribe((stats) => this._parseStatistics(stats));
this._patronTransactionSubscription$ = this.patronTransactionService.patronTransactionsSubject$.subscribe(
(transactions) => {
this.transactionsTotalAmount = this.patronTransactionService.computeTotalTransactionsAmount(transactions);
@@ -62,6 +73,32 @@ export class MainComponent implements OnInit, OnDestroy {
});
}
+ /** Parse statistics from API into corresponding tab statistic.
+ *
+ * @param statistics: a dictionary of loan state/value
+ */
+ private _parseStatistics(statistics: any) {
+ // reset the known stats
+ for (const key of Object.keys(this.patronCirculationStatistics)) {
+ this.patronCirculationStatistics[key] = 0;
+ }
+ // parse the stats
+ for (const key of Object.keys(statistics)) {
+ switch (key) {
+ case LoanState[LoanState.PENDING]:
+ case LoanState[LoanState.ITEM_IN_TRANSIT_FOR_PICKUP]:
+ this.patronCirculationStatistics.pending += statistics[key];
+ break;
+ case LoanState[LoanState.ITEM_AT_DESK]:
+ this.patronCirculationStatistics.pickup += statistics[key];
+ break;
+ case LoanState[LoanState.ITEM_ON_LOAN]:
+ this.patronCirculationStatistics.loans += statistics[key];
+ break;
+ }
+ }
+ }
+
clearPatron() {
this.patronService.clearPatron();
this.router.navigate(['/circulation']);
diff --git a/projects/admin/src/app/service/patron.service.ts b/projects/admin/src/app/service/patron.service.ts
index 57add0b33..479807e87 100644
--- a/projects/admin/src/app/service/patron.service.ts
+++ b/projects/admin/src/app/service/patron.service.ts
@@ -168,6 +168,16 @@ export class PatronService {
return this.getLoans(query, '-end_date');
}
+ /**
+ * Get circulation statistics about a patron
+ * @param patronPid - string : the patron pid to search
+ * @return Observable
+ */
+ getCirculationStats(patronPid: string): Observable {
+ const url = `/api/patrons/${patronPid}/circulation_stats`;
+ return this._http.get(url);
+ }
+
/**
* Get Loans by query
* @param query - string : Query to execute to find loans
@@ -182,4 +192,5 @@ export class PatronService {
map(hits => this._recordService.totalHits(hits.total) === 0 ? [] : hits.hits)
);
}
+
}