Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

circulation: add link to patron name #894

Merged
merged 1 commit into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions projects/admin/src/app/circulation/item/item.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@
title="{{ 'Requests' | translate }}"
class="badge badge-secondary font-weight-normal mr-1">
<i class="fa fa-shopping-basket pr-1"></i>
{{ item.pending_loans[0].patron.name }}
<a class="text-white" [routerLink]="['/circulation', 'patron', item.pending_loans[0].patron.barcode[0], 'loan']">
{{ item.pending_loans[0].patron.name }}
</a>
</span>
</li>
</ul>
Expand Down Expand Up @@ -199,7 +201,7 @@
</ng-container>
<span class="badge badge-secondary font-weight-normal mr-2" *ngFor="let request of item.pending_loans">
<i class="fa fa-shopping-basket pr-1"></i>
{{ request.patron.name }}
<a class="text-white" [routerLink]="['/circulation', 'patron', request.patron.barcode[0], 'loan']">{{ request.patron.name }}</a>
</span>
</dd>
</ng-container>
Expand Down
73 changes: 42 additions & 31 deletions projects/admin/src/app/circulation/patron/main/main.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* RERO ILS UI
* Copyright (C) 2019 RERO
* Copyright (C) 2019-2022 RERO
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
Expand All @@ -18,14 +18,14 @@ import { Component, OnDestroy, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { HotkeysService } from '@ngneat/hotkeys';
import { TranslateService } from '@ngx-translate/core';
import { Subscription } from 'rxjs';
import { RecordService } from '@rero/ng-core';
import { LoanState } from 'projects/admin/src/app/classes/loans';
import { OrganisationService } from 'projects/admin/src/app/service/organisation.service';
import { PatronService } from 'projects/admin/src/app/service/patron.service';
import { PatronTransactionService } from '../../services/patron-transaction.service';
import { CirculationService } from '../../services/circulation.service';
import { RecordService } from '@rero/ng-core';
import { Subscription } from 'rxjs';
import { OperationLogsApiService } from '../../../api/operation-logs-api.service';
import { CirculationService } from '../../services/circulation.service';
import { PatronTransactionService } from '../../services/patron-transaction.service';

@Component({
selector: 'admin-main',
Expand Down Expand Up @@ -143,10 +143,35 @@ export class MainComponent implements OnInit, OnDestroy {
) { }

/** OnInit hook */
ngOnInit() {
this._circulationService.clear();
this._patronBarcode = this._route.snapshot.paramMap.get('barcode');
this._patronSubscription$ = this._patronService.getPatron(this._patronBarcode).subscribe((patron: any) => {
ngOnInit(): void {
/** load patron if the barcode changes */
this._route.params.subscribe((data: any) => {
if (data.hasOwnProperty('barcode')) {
this.load(data.barcode);
}
});
}

/** OnDestroy hook */
ngOnDestroy(): void {
this._unregisterShortcuts();
if (this._patronFeesOperationSubscription$) {
this._patronFeesOperationSubscription$.unsubscribe();
}
if (this._patronSubscription$) {
this._patronSubscription$.unsubscribe();
}
this._patronService.clearPatron();
}

// COMPONENT FUNCTIONS ====================================================
/**
* Load data
* @param barcode: string, patron barcode
*/
load(barcode: string): void {
this._patronBarcode = barcode;
this._patronSubscription$ = this._patronService.getPatron(barcode).subscribe((patron: any) => {
if (patron) {
this.patron = patron;
// We need to unregister/register the shortcuts after the patron was loaded. Otherwise, the patron could be considered has
Expand All @@ -157,6 +182,7 @@ export class MainComponent implements OnInit, OnDestroy {
this.historyCount = this._recordService.totalHits(result.hits.total);
});
this._patronService.getCirculationInformations(patron.pid).subscribe((data) => {
this._circulationService.clear();
this.feesTotalAmount = data.fees.engaged + data.fees.preview;
this._parseStatistics(data.statistics || {});
for (const message of (data.messages || [])) {
Expand All @@ -174,27 +200,14 @@ export class MainComponent implements OnInit, OnDestroy {
});
}

/** OnDestroy hook */
ngOnDestroy() {
this._unregisterShortcuts();
if (this._patronFeesOperationSubscription$) {
this._patronFeesOperationSubscription$.unsubscribe();
}
if (this._patronSubscription$) {
this._patronSubscription$.unsubscribe();
}
this._patronService.clearPatron();
}

// COMPONENT FUNCTIONS ====================================================
/** reset the patron currently viewed */
clearPatron() {
clearPatron(): void {
this._patronService.clearPatron();
this._router.navigate(['/circulation']);
}

/** Register all component shortcuts on the hotkeysService */
private _registerShortcuts() {
private _registerShortcuts(): void {
for (const shortcut of this._shortcuts) {
const callback = shortcut.callback;
delete shortcut.callback;
Expand All @@ -203,7 +216,7 @@ export class MainComponent implements OnInit, OnDestroy {
}

/** Unregister all component shortcuts from the hotkeysService (if they are registered) */
private _unregisterShortcuts() {
private _unregisterShortcuts(): void {
const registeredHotKeys = this._hotKeysService.getHotkeys().map(shortcut => shortcut.keys);
const componentShortcuts = this._shortcuts.map(shortcut => shortcut.keys);
const intersectionShortcuts = registeredHotKeys.filter(value => componentShortcuts.includes(value));
Expand All @@ -217,19 +230,17 @@ export class MainComponent implements OnInit, OnDestroy {
* @param type: the type of circulation statistics to find.
*/
getCirculationStatistics(type: string): number {
return (
'circulationInformations' in this._circulationService
&& 'statistics' in this._circulationService.circulationInformations
&& type in this._circulationService.circulationInformations.statistics
) ? this._circulationService.circulationInformations.statistics[type]
const stats = this._circulationService?.circulationInformations?.statistics;
return stats && type in stats
? this._circulationService.circulationInformations.statistics[type]
: 0;
}

/**
* Parse statistics from API into corresponding tab statistic.
* @param data: a dictionary of loan state/value
*/
private _parseStatistics(data: any) {
private _parseStatistics(data: any): void {
for (const key of Object.keys(data)) {
switch (key) {
case LoanState[LoanState.PENDING]:
Expand Down