@@ -43,6 +43,14 @@ import { COMMA, ENTER } from '@angular/cdk/keycodes';
43
43
export const defaultStatusBackgroundColour = '#ffffff' ;
44
44
export const defaultStatusColour = '#313132' ;
45
45
46
+ enum searchTabs {
47
+ Applications = 0 ,
48
+ Nois = 1 ,
49
+ Plannings = 2 ,
50
+ Notifications = 3 ,
51
+ Inquiries = 4 ,
52
+ }
53
+
46
54
@Component ( {
47
55
selector : 'app-search' ,
48
56
templateUrl : './search.component.html' ,
@@ -346,6 +354,7 @@ export class SearchComponent implements OnInit, OnDestroy {
346
354
347
355
this . applications = result ?. data ?? [ ] ;
348
356
this . applicationTotal = result ?. total ?? 0 ;
357
+ this . updateApplicationStatuses ( ) ;
349
358
}
350
359
351
360
async onNoticeOfIntentSearch ( ) {
@@ -354,6 +363,7 @@ export class SearchComponent implements OnInit, OnDestroy {
354
363
355
364
this . noticeOfIntents = result ?. data ?? [ ] ;
356
365
this . noticeOfIntentTotal = result ?. total ?? 0 ;
366
+ this . updateNoiStatuses ( ) ;
357
367
}
358
368
359
369
async onPlanningReviewSearch ( ) {
@@ -370,6 +380,7 @@ export class SearchComponent implements OnInit, OnDestroy {
370
380
371
381
this . notifications = result ?. data ?? [ ] ;
372
382
this . notificationTotal = result ?. total ?? 0 ;
383
+ this . updateNotificationStatuses ( ) ;
373
384
}
374
385
375
386
async onInquirySearch ( ) {
@@ -407,6 +418,22 @@ export class SearchComponent implements OnInit, OnDestroy {
407
418
}
408
419
}
409
420
421
+ async onTabChanged ( index : number ) {
422
+ switch ( index ) {
423
+ case searchTabs . Applications :
424
+ await this . updateApplicationStatuses ( ) ;
425
+ break ;
426
+ case searchTabs . Nois :
427
+ await this . updateNoiStatuses ( ) ;
428
+ break ;
429
+ case searchTabs . Notifications :
430
+ await this . updateNotificationStatuses ( ) ;
431
+ break ;
432
+ default :
433
+ break ;
434
+ }
435
+ }
436
+
410
437
onFileTypeChange ( fileTypes : string [ ] ) {
411
438
this . componentTypeControl . setValue ( fileTypes ) ;
412
439
}
@@ -529,6 +556,7 @@ export class SearchComponent implements OnInit, OnDestroy {
529
556
] ;
530
557
531
558
this . tabGroup . selectedIndex = searchCounts . indexOf ( Math . max ( ...searchCounts ) ) ;
559
+ this . onTabChanged ( this . tabGroup . selectedIndex ) ;
532
560
}
533
561
534
562
private formatStringSearchParam ( value : string | undefined | null ) {
@@ -563,4 +591,49 @@ export class SearchComponent implements OnInit, OnDestroy {
563
591
this . allStatuses = result ;
564
592
this . allStatuses . sort ( ( a , b ) => ( a . label > b . label ? 1 : - 1 ) ) ;
565
593
}
594
+
595
+ private async updateApplicationStatuses ( ) {
596
+ const needsUpdate = this . applications . filter ( ( a ) => a . status === null ) . length > 0 ;
597
+ if ( ! needsUpdate ) return ;
598
+ const statusUpdates = await this . searchService . advancedSearchApplicationStatusFetch (
599
+ this . applications . map ( ( a ) => a . fileNumber )
600
+ ) ;
601
+ this . applications = this . applications . map ( ( a ) => {
602
+ const updatedStatus = statusUpdates ? statusUpdates . find ( ( s ) => s . fileNumber === a . fileNumber ) : null ;
603
+ return {
604
+ ...a ,
605
+ status : updatedStatus ? updatedStatus . status : '' ,
606
+ }
607
+ } ) ;
608
+ }
609
+
610
+ private async updateNoiStatuses ( ) {
611
+ const needsUpdate = this . noticeOfIntents . filter ( ( a ) => a . status === null ) . length > 0 ;
612
+ if ( ! needsUpdate ) return ;
613
+ const statusUpdates = await this . searchService . advancedSearchNoiStatusFetch (
614
+ this . noticeOfIntents . map ( ( a ) => a . fileNumber )
615
+ ) ;
616
+ this . noticeOfIntents = this . noticeOfIntents . map ( ( a ) => {
617
+ const updatedStatus = statusUpdates ? statusUpdates . find ( ( s ) => s . fileNumber === a . fileNumber ) : null ;
618
+ return {
619
+ ...a ,
620
+ status : updatedStatus ? updatedStatus . status : '' ,
621
+ }
622
+ } ) ;
623
+ }
624
+
625
+ private async updateNotificationStatuses ( ) {
626
+ const needsUpdate = this . notifications . filter ( ( a ) => a . status === null ) . length > 0 ;
627
+ if ( ! needsUpdate ) return ;
628
+ const statusUpdates = await this . searchService . advancedSearchNotificationStatusFetch (
629
+ this . notifications . map ( ( a ) => a . fileNumber )
630
+ ) ;
631
+ this . notifications = this . notifications . map ( ( a ) => {
632
+ const updatedStatus = statusUpdates ? statusUpdates . find ( ( s ) => s . fileNumber === a . fileNumber ) : null ;
633
+ return {
634
+ ...a ,
635
+ status : updatedStatus ? updatedStatus . status : '' ,
636
+ }
637
+ } ) ;
638
+ }
566
639
}
0 commit comments