Skip to content

Commit

Permalink
circulation: add cancel request on pending tag
Browse files Browse the repository at this point in the history
* Closes rero/rero-ils#2998.

Co-Authored-by: Bertrand Zuchuat <bertrand.zuchuat@rero.ch>
  • Loading branch information
Garfield-fr committed Apr 18, 2023
1 parent a405e64 commit c20d481
Show file tree
Hide file tree
Showing 14 changed files with 260 additions and 62 deletions.
10 changes: 6 additions & 4 deletions projects/admin/src/app/circulation/circulation.module.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-2023 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 @@ -25,13 +25,15 @@ import { SharedModule } from '@rero/shared';
import { CollapseModule } from 'ngx-bootstrap/collapse';
import { BsDatepickerModule } from 'ngx-bootstrap/datepicker';
import { BsDropdownModule } from 'ngx-bootstrap/dropdown';
import { CheckinActionComponent } from './checkin/checkin-action/checkin-action.component';
import { CheckinComponent } from './checkin/checkin.component';
import { CirculationRoutingModule } from './circulation-routing.module';
import { ItemComponent } from './item/item.component';
import { ItemsListComponent } from './items-list/items-list.component';
import { MainRequestComponent } from './main-request/main-request.component';
import { RequestedItemComponent } from './main-request/requested-item/requested-item.component';
import { RequestedItemsListComponent } from './main-request/requested-items-list/requested-items-list.component';
import { CancelRequestButtonComponent } from './patron/cancel-request-button.component';
import { CardComponent } from './patron/card/card.component';
import { ChangePasswordFormComponent } from './patron/change-password-form/change-password-form.component';
import { HistoryLogLibraryComponent } from './patron/history/history-log-library/history-log-library.component';
Expand All @@ -41,6 +43,7 @@ import { FixedDateFormComponent } from './patron/loan/fixed-date-form/fixed-date
import { LoanComponent } from './patron/loan/loan.component';
import { MainComponent } from './patron/main/main.component';
import { OverdueTransactionComponent } from './patron/patron-transactions/overdue-transaction/overdue-transaction.component';
import { PatronFeeComponent } from './patron/patron-transactions/patron-fee/patron-fee.component';
import {
PatronTransactionEventFormComponent
} from './patron/patron-transactions/patron-transaction-event-form/patron-transaction-event-form.component';
Expand All @@ -59,8 +62,6 @@ import { PickupItemComponent } from './patron/pickup/pickup-item/pickup-item.com
import { PickupComponent } from './patron/pickup/pickup.component';
import { ProfileComponent } from './patron/profile/profile.component';
import { GetLoanCipoPipe } from './pipe/get-loan-cipo.pipe';
import { CheckinActionComponent } from './checkin/checkin-action/checkin-action.component';
import { PatronFeeComponent } from './patron/patron-transactions/patron-fee/patron-fee.component';


@NgModule({
Expand Down Expand Up @@ -95,7 +96,8 @@ import { PatronFeeComponent } from './patron/patron-transactions/patron-fee/patr
HistoryLogLibraryComponent,
GetLoanCipoPipe,
CheckinActionComponent,
PatronFeeComponent
PatronFeeComponent,
CancelRequestButtonComponent
],
imports: [
BsDropdownModule.forRoot(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* RERO ILS UI
* Copyright (C) 2023 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
* the Free Software Foundation, version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import { Component, EventEmitter, Input, Output } from '@angular/core';
import { LoanService } from '@app/admin/service/loan.service';
import { TranslateService } from '@ngx-translate/core';
import { UserService } from '@rero/shared';
import { ToastrService } from 'ngx-toastr';

@Component({
selector: 'admin-cancel-request-button',
template: `
<ng-container *ngIf="canCancelRequest(); else noCancel">
<button type="button"
class="btn btn-outline-danger btn-sm"
(click)="showCancelRequestDialog()"
name="cancel">
<i class="fa fa-trash-o" aria-hidden="true"></i>
</button>
</ng-container>
<ng-template #noCancel>
<button type="button" class="btn btn-outline-danger btn-sm"
title="{{'The request cannot be cancelled' | translate }}"
name="cancel"
disabled>
<i class="fa fa-trash-o" aria-hidden="true"></i>
</button>
</ng-template>
`
})
export class CancelRequestButtonComponent {

/** Loan record */
@Input() loan: any;

/** Informs parent component to remove request when it is cancelled */
@Output() cancelRequestEvent = new EventEmitter<any>();

/**
* Constructor
* @param _loanService - LoanService
* @param _userService - UserService
* @param _translateService - TranslateService
* @param _toastrService - ToastrService
*/
public constructor(
private _loanService: LoanService,
private _userService: UserService,
private _translateService: TranslateService,
private _toastrService: ToastrService
) {}

/**
* Can cancel a loan request
* @returns true if it is possible to cancel a loan
*/
canCancelRequest(): boolean {
return this._loanService.canCancelRequest(this.loan);
}

/** Show a confirmation dialog box for cancel request. */
showCancelRequestDialog(): void {
this._loanService.cancelRequestDialog().subscribe((confirm: boolean) => {
if (confirm) {
this._loanService.cancelLoan(
this.loan.metadata.item.pid,
this.loan.metadata.pid,
this._userService.user.currentLibrary
).subscribe(() => {
this._toastrService.warning(
this._translateService.instant('The request has been cancelled.'),
this._translateService.instant('Request')
);
this.cancelRequestEvent.emit(this.loan.id);
});
}
});
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!--
RERO ILS UI
Copyright (C) 2020 RERO
Copyright (C) 2020-2023 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 @@ -25,7 +25,7 @@
</button>
<a [routerLink]="['/records', 'items', 'detail', item.pid]">{{ item.barcode }}</a>
</div>
<div class="col-6">
<div class="col-5">
<a [routerLink]="['/records', 'documents', 'detail', document.pid]" *ngIf="document.title | mainTitle as title">
{{ title }}
</a><br/>
Expand All @@ -45,6 +45,9 @@
</div>
<div class="col-2">{{ loan.created | dateTranslate: 'short' }}</div>
<div class="col-2">-<!-- TODO :: display the computed expected_date --></div>
<div class="col-1 text-right">
<admin-cancel-request-button [loan]="loan" (cancelRequestEvent)="cancelRequest($event)"></admin-cancel-request-button>
</div>
<!-- SECOND ROW : item detail -->
<div class="col-12" *ngIf="!isCollapsed">
<dl class="row">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* RERO ILS UI
* Copyright (C) 2020 RERO
* Copyright (C) 2020-2023 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 @@ -14,7 +14,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { Component, Input, OnInit } from '@angular/core';
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { RecordService } from '@rero/ng-core';
import { forkJoin } from 'rxjs';
import { ItemsService } from '../../../../service/items.service';
Expand All @@ -28,12 +28,15 @@ export class PendingItemComponent implements OnInit {
// COMPONENT ATTRIBUTES =====================================================
/** Loan */
@Input() loan = undefined;
/** Informs parent component to remove request when it is cancelled */
@Output() cancelRequestEvent = new EventEmitter<any>();
/** Item, document */
item = undefined;
document = undefined;
/** detail is collapsed */
isCollapsed = true;


// CONSTRUCTOR & HOOKS ======================================================
/**
* Constructor
Expand All @@ -58,4 +61,12 @@ export class PendingItemComponent implements OnInit {
);
}
}

/**
* Emit a new cancel request
* @param loanPid - The current loan pid
*/
cancelRequest(loanPid: string): void {
this.cancelRequestEvent.emit(loanPid);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!--
RERO ILS UI
Copyright (C) 2020 RERO
Copyright (C) 2020-2023 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 @@ -19,12 +19,17 @@
<!-- HEADER -->
<div class="row p-2 mb-1 bg-dark rounded text-light">
<div class="col-2" translate>Item</div>
<div class="col-6" translate>Title</div>
<div class="col-5" translate>Title</div>
<div class="col-2" translate>Request date</div>
<div class="col-2" translate>Expected availability</div>
<div class="col-1" translate>&nbsp;</div>
</div>
<div *ngFor="let loan of loans">
<admin-pending-item [loan]="loan" class="row p-2 mb-1 border rounded align-middle"></admin-pending-item>
<admin-pending-item
class="row p-2 mb-1 border rounded align-middle"
[loan]="loan"
(cancelRequestEvent)="cancelRequest($event)"
></admin-pending-item>
</div>
</div>
</section>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* RERO ILS UI
* Copyright (C) 2020 RERO
* Copyright (C) 2020-2023 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 @@ -17,6 +17,7 @@

import { Component, OnInit } from '@angular/core';
import { PatronService } from '../../../service/patron.service';
import { CirculationService } from '../../services/circulation.service';

@Component({
selector: 'admin-pending',
Expand All @@ -31,7 +32,10 @@ export class PendingComponent implements OnInit {
* Constructor
* @param _patronService - PatronService
*/
constructor(private _patronService: PatronService) {}
constructor(
private _patronService: PatronService,
private _circulationService: CirculationService
) {}

/**
* Init
Expand All @@ -46,4 +50,16 @@ export class PendingComponent implements OnInit {
}
});
}

/**
* Remove the canceled request on the loans list.
* @param loanId, the canceled loan id
*/
cancelRequest(loanId: any): void {
// Remove loan in list
const index = this.loans.findIndex((element: any) => element.id == loanId);
this.loans.splice(index, 1);
// Update count on tab
this._circulationService.circulationInformations.statistics['pending'] -= 1;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!--
RERO ILS UI
Copyright (C) 2020 RERO
Copyright (C) 2020-2023 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,7 +18,7 @@
<div class="col-2">
<a [routerLink]="['/records', 'items', 'detail', item.pid]">{{ item.barcode }}</a>
</div>
<div class="col-5">
<div class="col-4">
<a [routerLink]="['/records', 'documents', 'detail', document.pid]" *ngIf="document.title | mainTitle as title">
{{ title }}
</a><br/>
Expand All @@ -45,4 +45,7 @@
</ng-container>
<ng-template #noDate>{{ 'Unknown' | translate }}</ng-template>
</div>
<div class="col-1 text-right">
<admin-cancel-request-button [loan]="loan" (cancelRequestEvent)="cancelRequest($event)"></admin-cancel-request-button>
</div>
</ng-container>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* RERO ILS UI
* Copyright (C) 2020 RERO
* Copyright (C) 2020-2023 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 @@ -14,7 +14,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { Component, Input, OnInit } from '@angular/core';
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { RecordService } from '@rero/ng-core';
import { forkJoin } from 'rxjs';
import { ItemsService } from '../../../../service/items.service';
Expand All @@ -28,6 +28,8 @@ export class PickupItemComponent implements OnInit {
// COMPONENT ATTRIBUTES =====================================================
/** Loan */
@Input() loan = undefined;
/** Informs parent component to remove request when it is cancelled */
@Output() cancelRequestEvent = new EventEmitter<any>();
/** Item, document */
item = undefined;
document = undefined;
Expand Down Expand Up @@ -56,4 +58,12 @@ export class PickupItemComponent implements OnInit {
);
}
}

/**
* Emit a new cancel request
* @param loanPid - The current loan pid
*/
cancelRequest(loanPid: string): void {
this.cancelRequestEvent.emit(loanPid);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!--
RERO ILS UI
Copyright (C) 2020 RERO
Copyright (C) 2020-2023 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 @@ -19,11 +19,17 @@
<!-- HEADER -->
<div class="row p-2 mb-1 bg-dark rounded text-light row">
<div class="col-2" translate>Item</div>
<div class="col-5" translate>Title</div>
<div class="col-4" translate>Title</div>
<div class="col-3" translate>Pickup location</div>
<div class="col-2" translate>To pick-up until</div>
<div class="col-1">&nbsp;</div>
</div>
<admin-pickup-item *ngFor="let loan of loans" [loan]="loan" class="row p-2 mb-1 border rounded align-middle"></admin-pickup-item>
<admin-pickup-item
*ngFor="let loan of loans"
[loan]="loan"
class="row p-2 mb-1 border rounded align-middle"
(cancelRequestEvent)="cancelRequest($event)"
></admin-pickup-item>
</div>
</section>

Expand Down
Loading

0 comments on commit c20d481

Please sign in to comment.