@@ -4,13 +4,17 @@ import { MatButtonModule } from '@angular/material/button';
44import { MatInputModule } from '@angular/material/input' ;
55import { MatFormFieldModule } from '@angular/material/form-field' ;
66import download from 'downloadjs' ;
7+ import debounce from 'lodash.debounce' ;
8+
79import { AngularPConnectData , AngularPConnectService } from '../../../_bridge/angular-pconnect' ;
810import { Utils } from '../../../_helpers/utils' ;
911import { ComponentMapperComponent } from '../../../_bridge/component-mapper/component-mapper.component' ;
12+ import { getResolvedConstantValue } from '../../../_helpers/object-utils' ;
1013
1114interface FileUtilityProps {
1215 // If any, enter additional props that only exist on this component
1316 label ?: string ;
17+ caseId ?: string ;
1418}
1519
1620@Component ( {
@@ -62,6 +66,8 @@ export class FileUtilityComponent implements OnInit, OnDestroy {
6266 closeSvgIcon$ = '' ;
6367
6468 currentCaseID = '' ;
69+ debouncedGetAttachments : any ;
70+ attachSubId ;
6571
6672 addAttachmentsActions : any ;
6773
@@ -77,7 +83,9 @@ export class FileUtilityComponent implements OnInit, OnDestroy {
7783
7884 const configProps : FileUtilityProps = this . pConn$ . resolveConfigProps ( this . pConn$ . getConfigProps ( ) ) ;
7985
80- this . lu_name$ = configProps . label ?? '' ;
86+ const { caseId, label } = configProps ;
87+
88+ this . lu_name$ = label ?? '' ;
8189 this . lu_icon$ = 'paper-clip' ;
8290
8391 this . closeSvgIcon$ = this . utils . getImageSrc ( 'times' , this . utils . getSDKStaticContentUrl ( ) ) ;
@@ -100,23 +108,31 @@ export class FileUtilityComponent implements OnInit, OnDestroy {
100108 this . removeFileFromList$ = { onClick : this . removeFileFromList . bind ( this ) } ;
101109 this . removeLinksFromList$ = { onClick : this . removeLinksFromList . bind ( this ) } ;
102110
111+ this . debouncedGetAttachments = debounce ( this . refreshAttachments . bind ( this ) , 1000 ) ;
112+
103113 this . updateSelf ( ) ;
104114
105115 this . createModalButtons ( ) ;
106116
107- PCore . getPubSubUtils ( ) . subscribe (
108- PCore . getEvents ( ) . getCaseEvent ( ) . CASE_ATTACHMENTS_UPDATED_FROM_CASEVIEW ,
109- this . updateSelf . bind ( this ) ,
110- 'caseAttachmentsUpdateFromCaseview'
111- ) ;
117+ const caseID = caseId ?? getResolvedConstantValue ( this . pConn$ , PCore . getConstants ( ) . CASE_INFO . CASE_INFO_ID ) ;
118+
119+ const attachSubObject = {
120+ matcher : 'ATTACHMENTS' ,
121+ criteria : {
122+ ID : caseID
123+ }
124+ } ;
125+ this . attachSubId = PCore . getMessagingServiceManager ( ) . subscribe ( attachSubObject , this . debouncedGetAttachments , this . pConn$ . getContextName ( ) ) ;
126+
127+ this . debouncedGetAttachments ( ) ;
112128 }
113129
114130 ngOnDestroy ( ) : void {
115131 if ( this . angularPConnectData . unsubscribeFn ) {
116132 this . angularPConnectData . unsubscribeFn ( ) ;
117133 }
118134
119- PCore . getPubSubUtils ( ) . unsubscribe ( PCore . getEvents ( ) . getCaseEvent ( ) . CASE_ATTACHMENTS_UPDATED_FROM_CASEVIEW , 'caseAttachmentsUpdateFromCaseview' ) ;
135+ PCore . getMessagingServiceManager ( ) . unsubscribe ( this . attachSubId ) ;
120136 }
121137
122138 // Callback passed when subscribing to store change
@@ -136,7 +152,7 @@ export class FileUtilityComponent implements OnInit, OnDestroy {
136152 }
137153 }
138154
139- onAttachFiles ( files ) {
155+ onAttachFiles ( files : any [ ] = [ ] ) {
140156 const attachmentUtils = PCore . getAttachmentUtils ( ) ;
141157 const caseID = this . pConn$ . getValue ( PCore . getConstants ( ) . CASE_INFO . CASE_INFO_ID ) ;
142158
0 commit comments