Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
circulation: clear input after checkout action
Browse files Browse the repository at this point in the history
The input field is automatically disabled during
the transaction on the "checkin/checkout" and "Request" screens.

* Closes rero/rero-ils#2244.

Co-Authored-by: Bertrand Zuchuat <bertrand.zuchuat@rero.ch>
Garfield-fr committed Aug 19, 2021
1 parent d4ba704 commit 182ac3d
Showing 6 changed files with 54 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -22,7 +22,9 @@ <h4 translate>Checkout/checkin</h4>
[placeholder]="placeholder | translate"
[searchText]="searchText"
(search)="searchValueUpdated($event)"
[focus]="searchInputFocus">
[focus]="searchInputFocus"
[disabled]="searchInputDisabled"
>
</ng-core-search-input>
</div>
<div class="col col-md-6 mb-4">
25 changes: 18 additions & 7 deletions projects/admin/src/app/circulation/checkin/checkin.component.ts
Original file line number Diff line number Diff line change
@@ -31,9 +31,7 @@ import { PatronService } from '../../service/patron.service';
templateUrl: './checkin.component.html'
})
export class CheckinComponent implements OnInit {
public placeholder: string = this._translate.instant(
'Please enter a patron card number or an item barcode.'
);
public placeholder = 'Please enter a patron card number or an item barcode.';
public searchText = '';
public patronInfo: User;
public barcode: string;
@@ -48,7 +46,10 @@ export class CheckinComponent implements OnInit {
}

/** Focus attribute of the search input */
searchInputFocus = false;
searchInputFocus = true;

/** Disabled attribute of the search input */
searchInputDisabled = false;

/** Constructor
* @param _userService: UserService
@@ -74,7 +75,6 @@ export class CheckinComponent implements OnInit {
this._patronService.currentPatron$.subscribe(
patron => this.patronInfo = patron
);
this.searchInputFocus = true;
this.currentLibraryPid = this._loggedUser.currentLibrary;
this.patronInfo = null;
this.barcode = null;
@@ -96,6 +96,7 @@ export class CheckinComponent implements OnInit {
*/
checkin(itemBarcode: string) {
this.searchInputFocus = false;
this.searchInputDisabled = true;
this._itemsService.checkin(itemBarcode, this._loggedUser.currentLibrary).subscribe(
item => {
// TODO: remove this when policy will be in place
@@ -104,6 +105,7 @@ export class CheckinComponent implements OnInit {
this._translate.instant('Item or patron not found!'),
this._translate.instant('Checkin')
);
this._resetSearchInput();
return;
}
if (item.hasRequests) {
@@ -133,8 +135,7 @@ export class CheckinComponent implements OnInit {
break;
}
this._itemsList.unshift(item);
this.searchText = '';
this.searchInputFocus = true;
this._resetSearchInput();
},
error => {
// If no action could be done by the '/item/checkin' api, an error will be raised.
@@ -225,6 +226,7 @@ export class CheckinComponent implements OnInit {
);
}
this.isLoading = false;
this._resetSearchInput();
},
error =>
this._toastService.error(
@@ -300,4 +302,13 @@ export class CheckinComponent implements OnInit {
);
}
}

/** Reset search input */
private _resetSearchInput(): void {
setTimeout(() => {
this.searchInputDisabled = false;
this.searchInputFocus = true;
this.searchText = '';
}, 300);
}
}
Original file line number Diff line number Diff line change
@@ -18,10 +18,11 @@
<div class="row mb-4">
<div class="col-12 col-md-6">
<ng-core-search-input
[placeholder]="placeholder"
[placeholder]="placeholder | translate"
[searchText]="searchText"
(search)="searchValueUpdated($event)"
[focus]="searchInputFocus"
[disabled]="searchInputDisabled"
></ng-core-search-input>
</div>
<!-- Sorting loans -->
Original file line number Diff line number Diff line change
@@ -48,7 +48,7 @@ export class MainRequestComponent implements OnInit, OnDestroy {
];

/** the placeholder string used on the */
public placeholder: string = this._translateService.instant('Please enter an item barcode.');
public placeholder = 'Please enter an item barcode.';
/** search text used into the search input component */
public searchText = '';
/** requested items loaded */
@@ -60,7 +60,9 @@ export class MainRequestComponent implements OnInit, OnDestroy {
/** is the requested items detail should be collapsed or not */
public isDetailCollapsed = true;
/** Focus attribute of the search input */
public searchInputFocus = false;
public searchInputFocus = true;
/** Disabled attribute of the search input */
public searchInputDisabled = false;

/** the library pid for which load the requested items */
private _libraryPid: string;
@@ -92,7 +94,6 @@ export class MainRequestComponent implements OnInit, OnDestroy {
this.getRequestedLoans();
this._enableAutoRefresh();
}
this.searchInputFocus = true;
}

/** OnDestroy hook */
@@ -159,13 +160,16 @@ export class MainRequestComponent implements OnInit, OnDestroy {
if (! searchText) {
return null;
}
this.searchInputFocus = false;
this.searchInputDisabled = true;
this.searchText = searchText;
const item = this.items.find(currItem => currItem.barcode === searchText);
if (item === undefined) {
this._toastService.warning(
this._translateService.instant('No request corresponding to the given item has been found.'),
this._translateService.instant('request')
);
this._resetSearchInput();
} else {
/*const items = this.items;
this.items = null;*/
@@ -176,11 +180,10 @@ export class MainRequestComponent implements OnInit, OnDestroy {
this._translateService.instant('The item is ').concat(this._translateService.instant(newItem.status)),
this._translateService.instant('request')
);
this.searchText = '';
this._resetSearchInput();
}
);
}
this.searchInputFocus = true;
}

/**
@@ -217,4 +220,13 @@ export class MainRequestComponent implements OnInit, OnDestroy {
this._sortCriteria = criteria;
this._sortingRequestedLoans(this.items);
}

/** Reset search input */
private _resetSearchInput(): void {
setTimeout(() => {
this.searchInputDisabled = false;
this.searchInputFocus = true;
this.searchText = '';
}, 300);
}
}
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@
[searchText]="searchText"
(search)="searchValueUpdated($event)"
[focus]="searchInputFocus"
[disabled]="searchInputDisabled"
></ng-core-search-input>
</div>
<div class="col-sm-2 col-md-1 align-self-end pl-1">
14 changes: 13 additions & 1 deletion projects/admin/src/app/circulation/patron/loan/loan.component.ts
Original file line number Diff line number Diff line change
@@ -57,6 +57,8 @@ export class LoanComponent implements OnInit, OnDestroy {
public checkedInItems = [];
/** Focus attribute of the search input */
searchInputFocus = false;
/** Disabled attribute of the search input */
searchInputDisabled = false;
/** Library PID of the logged user */
currentLibraryPid: string;

@@ -193,6 +195,7 @@ export class LoanComponent implements OnInit, OnDestroy {
*/
getItem(barcode: string) {
this.searchInputFocus = false;
this.searchInputDisabled = true;
const item = this.checkedOutItems.find(currItem => currItem.barcode === barcode);
if (item && item.actions.includes(ItemAction.checkin)) {
item.currentAction = ItemAction.checkin;
@@ -219,6 +222,7 @@ export class LoanComponent implements OnInit, OnDestroy {
);
this.searchText = '';
this.searchInputFocus = true;
this.searchInputDisabled = false;
} else {
if (newItem.status === ItemStatus.ON_LOAN) {
this._toastService.error(
@@ -227,6 +231,7 @@ export class LoanComponent implements OnInit, OnDestroy {
);
this.searchText = '';
this.searchInputFocus = true;
this.searchInputDisabled = false;
} else {
if (newItem.pending_loans && newItem.pending_loans[0].patron_pid !== this.patron.pid) {
this._toastService.error(
@@ -235,6 +240,7 @@ export class LoanComponent implements OnInit, OnDestroy {
);
this.searchText = '';
this.searchInputFocus = true;
this.searchInputDisabled = false;
} else {
newItem.currentAction = ItemAction.checkout;
this.applyItems([newItem]);
@@ -249,6 +255,7 @@ export class LoanComponent implements OnInit, OnDestroy {
);
this.searchText = '';
this.searchInputFocus = true;
this.searchInputDisabled = false;
}
);
}
@@ -305,7 +312,7 @@ export class LoanComponent implements OnInit, OnDestroy {
this.checkedInItems = this.checkedInItems.filter(currItem => currItem.pid !== newItem.pid);
this._circulationService.incrementCirculationStatistic('loans');
// check if items was ready to pickup. if yes, then we need to decrement the counter
const idx = this._pickupItems.findIndex(item => item.metadata.item_pid.value === newItem.pid);
const idx = this._pickupItems.findIndex(item => item.metadata.item.pid === newItem.pid);
if (idx > -1) {
this._pickupItems.splice(idx, 1);
this._circulationService.decrementCirculationStatistic('pickup');
@@ -318,9 +325,13 @@ export class LoanComponent implements OnInit, OnDestroy {
break;
}
}
this.searchText = '';
this.searchInputFocus = true;
this.searchInputDisabled = false;
});
this.searchText = '';
this.searchInputFocus = true;
this.searchInputDisabled = false;
},
err => {
let errorMessage = '';
@@ -350,6 +361,7 @@ export class LoanComponent implements OnInit, OnDestroy {
}
this.searchText = '';
this.searchInputFocus = true;
this.searchInputDisabled = false;
}
);
}

0 comments on commit 182ac3d

Please sign in to comment.