@@ -21,14 +21,14 @@ import { PatronService } from '@app/admin/service/patron.service';
2121import { TranslateService } from '@ngx-translate/core' ;
2222import { CONFIG , DateTranslatePipe } from '@rero/ng-core' ;
2323import { ItemStatus , User , UserService } from '@rero/shared' ;
24+ import { cloneDeep } from 'lodash-es' ;
2425import { MessageService } from 'primeng/api' ;
2526import { DynamicDialogRef } from 'primeng/dynamicdialog' ;
2627import { 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' ;
2829import { LoanFixedDateService } from '../../services/loan-fixed-date.service' ;
2930import { CirculationStatsService } from '../service/circulation-stats.service' ;
3031import { 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