Skip to content

Commit e61d760

Browse files
author
Nathan Python
committed
feat: in progress
Authored-by: Nathan Python <nathan.python@hes-so.ch
1 parent 1fd8394 commit e61d760

2 files changed

Lines changed: 27 additions & 11 deletions

File tree

angular.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,7 @@
663663
"cli": {
664664
"schematicCollections": [
665665
"@angular-eslint/schematics"
666-
]
666+
],
667+
"analytics": false
667668
}
668669
}

projects/admin/src/app/circulation/patron/loan/loan.component.ts

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ import { PatronService } from '@app/admin/service/patron.service';
2121
import { TranslateService } from '@ngx-translate/core';
2222
import { CONFIG, DateTranslatePipe } from '@rero/ng-core';
2323
import { ItemStatus, User, UserService } from '@rero/shared';
24+
import { cloneDeep } from 'lodash-es';
2425
import { MessageService } from 'primeng/api';
2526
import { DynamicDialogRef } from 'primeng/dynamicdialog';
2627
import { SelectChangeEvent } from 'primeng/select';
27-
import { delay, forkJoin, Subscription, switchMap, tap } from 'rxjs';
28+
import { concatMap, delay, forkJoin, from, Subscription, switchMap, tap, toArray } from 'rxjs';
2829
import { LoanFixedDateService } from '../../services/loan-fixed-date.service';
2930
import { CirculationStatsService } from '../service/circulation-stats.service';
3031
import { CirculationSettingsService, ICirculationSetting } from './circulation-settings/circulation-settings.service';
31-
3232
@Component({
3333
selector: 'admin-loan',
3434
templateUrl: './loan.component.html',
@@ -43,6 +43,7 @@ export class LoanComponent implements OnInit, OnDestroy {
4343
private messageService: MessageService = inject(MessageService);
4444
private circulationSettingsService: CirculationSettingsService = inject(CirculationSettingsService);
4545
private circulationStatsService: CirculationStatsService = inject(CirculationStatsService);
46+
loading = false;
4647

4748
dialogRef: DynamicDialogRef | undefined;
4849

@@ -248,15 +249,21 @@ export class LoanComponent implements OnInit, OnDestroy {
248249
);
249250
}
250251
}
251-
forkJoin(observables)
252-
.pipe(
252+
console.log(observables);
253+
let checkedOutItems = cloneDeep(this.checkedOutItems);
254+
let checkedInItems = cloneDeep(this.checkedInItems);
255+
this.loading = true;
256+
257+
from (observables).pipe(
258+
concatMap(obs => obs),
259+
toArray(),
253260
tap((newItems: any[]) =>
254261
newItems.map((newItem: Item) => {
255262
switch (newItem.actionDone) {
256263
case ItemAction.checkin: {
257264
this.displayCirculationInformation(ItemAction.checkin, newItem, ItemNoteType.CHECKIN);
258-
this.checkedOutItems = this.checkedOutItems.filter((currItem) => currItem.pid !== newItem.pid);
259-
this.checkedInItems.unshift(newItem);
265+
checkedOutItems = checkedOutItems.filter((currItem) => currItem.pid !== newItem.pid);
266+
checkedInItems.unshift(newItem);
260267
// display a toast message if the item goes in transit...
261268
if (newItem.status === ItemStatus.IN_TRANSIT) {
262269
const destination = newItem.loan.item_destination.library_name;
@@ -274,8 +281,8 @@ export class LoanComponent implements OnInit, OnDestroy {
274281
case ItemAction.checkout: {
275282
this._displayTransactionEndDateChanged(newItem);
276283
this.displayCirculationInformation(ItemAction.checkout, newItem, ItemNoteType.CHECKOUT);
277-
this.checkedOutItems.unshift(newItem);
278-
this.checkedInItems = this.checkedInItems.filter((currItem) => currItem.pid !== newItem.pid);
284+
checkedOutItems.unshift(newItem);
285+
checkedInItems = checkedInItems.filter((currItem) => currItem.pid !== newItem.pid);
279286
// check if items was ready to pickup. if yes, then we need to decrement the counter
280287
const idx = this.pickupItems.findIndex((item) => item.metadata.item.pid === newItem.pid);
281288
if (idx > -1) {
@@ -284,8 +291,8 @@ export class LoanComponent implements OnInit, OnDestroy {
284291
break;
285292
}
286293
case ItemAction.extend_loan: {
287-
const index = this.checkedOutItems.findIndex((currItem) => currItem.pid === newItem.pid);
288-
this.checkedOutItems[index] = newItem;
294+
const index = checkedOutItems.findIndex((currItem) => currItem.pid === newItem.pid);
295+
checkedOutItems[index] = newItem;
289296
break;
290297
}
291298
}
@@ -296,6 +303,11 @@ export class LoanComponent implements OnInit, OnDestroy {
296303
switchMap(() => this.circulationStatsService.getStats(this.patron.pid))
297304
)
298305
.subscribe({
306+
next: () => {
307+
this.checkedOutItems = checkedOutItems;
308+
this.checkedInItems = checkedInItems;
309+
this.loading = false;
310+
},
299311
error: (err) => {
300312
let errorMessage = '';
301313
if (err && err.error && err.error.message) {
@@ -328,7 +340,10 @@ export class LoanComponent implements OnInit, OnDestroy {
328340
closable: true,
329341
});
330342
}
343+
this.checkedOutItems = checkedOutItems;
344+
this.checkedInItems = checkedInItems;
331345
this._resetSearchInput();
346+
this.loading = false;
332347
},
333348
});
334349
}

0 commit comments

Comments
 (0)