1- import { Component , OnInit , Input , NgZone , OnDestroy , OnChanges } from '@angular/core' ;
1+ import { Component , OnInit , Input , OnDestroy } from '@angular/core' ;
22import { CommonModule } from '@angular/common' ;
33import { MatButtonModule } from '@angular/material/button' ;
44import { publicConstants } from '@pega/pcore-pconnect-typedefs/constants' ;
55import { ProgressSpinnerService } from '../../../_messages/progress-spinner.service' ;
66import { ErrorMessagesService } from '../../../_messages/error-messages.service' ;
77import { Utils } from '../../../_helpers/utils' ;
8+ import { updateWorkList } from '../../../_helpers/createstage-utils' ;
9+
10+ const fetchMyWorkList = ( datapage , fields , numberOfRecords , includeTotalCount , context ) => {
11+ return PCore . getDataPageUtils ( )
12+ . getDataAsync (
13+ datapage ,
14+ context ,
15+ { } ,
16+ {
17+ pageNumber : 1 ,
18+ pageSize : numberOfRecords
19+ } ,
20+ {
21+ select : Object . keys ( fields ) . map ( key => ( { field : PCore . getAnnotationUtils ( ) . getPropertyName ( fields [ key ] ) } ) ) ,
22+ sortBy : [
23+ { field : 'pxUrgencyAssign' , type : 'DESC' } ,
24+ { field : 'pxDeadlineTime' , type : 'ASC' } ,
25+ { field : 'pxCreateDateTime' , type : 'DESC' }
26+ ]
27+ } ,
28+ {
29+ invalidateCache : true ,
30+ additionalApiParams : {
31+ includeTotalCount
32+ }
33+ }
34+ )
35+ . then ( response => {
36+ return {
37+ ...response ,
38+ data : ( Array . isArray ( response ?. data ) ? response . data : [ ] ) . map ( row =>
39+ Object . keys ( fields ) . reduce ( ( obj , key ) => {
40+ obj [ key ] = row [ PCore . getAnnotationUtils ( ) . getPropertyName ( fields [ key ] ) ] ;
41+ return obj ;
42+ } , { } )
43+ )
44+ } ;
45+ } ) ;
46+ } ;
47+
48+ const getMappedValue = value => {
49+ const mappedValue = PCore . getEnvironmentInfo ( ) . getKeyMapping ( value ) ;
50+ return mappedValue === null ? value : mappedValue ;
51+ } ;
852
953interface ToDoProps {
1054 // If any, enter additional props that only exist on this component
@@ -23,7 +67,7 @@ interface ToDoProps {
2367 standalone : true ,
2468 imports : [ CommonModule , MatButtonModule ]
2569} )
26- export class TodoComponent implements OnInit , OnDestroy , OnChanges {
70+ export class TodoComponent implements OnInit , OnDestroy {
2771 @Input ( ) pConn$ : typeof PConnect ;
2872 @Input ( ) caseInfoID$ : string ;
2973 @Input ( ) datasource$ : any ;
@@ -38,7 +82,6 @@ export class TodoComponent implements OnInit, OnDestroy, OnChanges {
3882 configProps$ : ToDoProps ;
3983 currentUser$ : string | undefined ;
4084 currentUserInitials$ = '--' ;
41- assignmentCount$ : number ;
4285 bShowMore$ = true ;
4386 arAssignments$ : any [ ] ;
4487 assignmentsSource$ : any ;
@@ -49,41 +92,21 @@ export class TodoComponent implements OnInit, OnDestroy, OnChanges {
4992 showlessLocalizedValue = this . localizedVal ( 'show_less' , 'CosmosFields' ) ;
5093 showMoreLocalizedValue = this . localizedVal ( 'show_more' , 'CosmosFields' ) ;
5194 canPerform : boolean ;
95+ count : number ;
5296
5397 constructor (
5498 private psService : ProgressSpinnerService ,
5599 private erService : ErrorMessagesService ,
56- private ngZone : NgZone ,
57100 private utils : Utils
58101 ) { }
59102
60103 ngOnInit ( ) {
61104 this . CONSTS = PCore . getConstants ( ) ;
62105 const { CREATE_STAGE_SAVED , CREATE_STAGE_DELETED } = PCore . getEvents ( ) . getCaseEvent ( ) ;
63106
64- PCore . getPubSubUtils ( ) . subscribe (
65- PCore . getConstants ( ) . PUB_SUB_EVENTS . EVENT_CANCEL ,
66- ( ) => {
67- this . updateToDo ( ) ;
68- } ,
69- 'updateToDo'
70- ) ;
71-
72- PCore . getPubSubUtils ( ) . subscribe (
73- CREATE_STAGE_SAVED ,
74- ( ) => {
75- this . updateList ( ) ;
76- } ,
77- CREATE_STAGE_SAVED
78- ) ;
79-
80- PCore . getPubSubUtils ( ) . subscribe (
81- CREATE_STAGE_DELETED ,
82- ( ) => {
83- this . updateList ( ) ;
84- } ,
85- CREATE_STAGE_DELETED
86- ) ;
107+ PCore . getPubSubUtils ( ) . subscribe ( PCore . getConstants ( ) . PUB_SUB_EVENTS . EVENT_CANCEL , ( ) => this . updateToDo ( ) , 'updateToDo' ) ;
108+ PCore . getPubSubUtils ( ) . subscribe ( CREATE_STAGE_SAVED , ( ) => this . updateList ( ) , CREATE_STAGE_SAVED ) ;
109+ PCore . getPubSubUtils ( ) . subscribe ( CREATE_STAGE_DELETED , ( ) => this . updateList ( ) , CREATE_STAGE_DELETED ) ;
87110
88111 this . updateToDo ( ) ;
89112 }
@@ -92,55 +115,39 @@ export class TodoComponent implements OnInit, OnDestroy, OnChanges {
92115 const { CREATE_STAGE_SAVED , CREATE_STAGE_DELETED } = PCore . getEvents ( ) . getCaseEvent ( ) ;
93116
94117 PCore . getPubSubUtils ( ) . unsubscribe ( PCore . getConstants ( ) . PUB_SUB_EVENTS . EVENT_CANCEL , 'updateToDo' ) ;
95-
96118 PCore . getPubSubUtils ( ) . unsubscribe ( CREATE_STAGE_SAVED , CREATE_STAGE_SAVED ) ;
97-
98119 PCore . getPubSubUtils ( ) . unsubscribe ( CREATE_STAGE_DELETED , CREATE_STAGE_DELETED ) ;
99120 }
100121
101- ngOnChanges ( ) {
102- // don't update until we'va had an init
103- if ( PCore ) {
104- this . updateToDo ( ) ;
105- }
106- }
107-
108- updateWorkList ( key ) {
109- PCore . getDataApiUtils ( )
110- . getData ( key )
111- . then ( responseData => {
112- const dataObject = { } ;
113- dataObject [ key ] = {
114- pxResults : responseData . data . data
115- } ;
116-
117- this . pConn$ . updateState ( dataObject ) ;
118- this . updateToDo ( ) ;
119- } )
120- . catch ( err => {
121- console . error ( err ?. stack ) ;
122- } ) ;
123- }
124-
125122 updateList ( ) {
126- this . updateWorkList ( 'D_pyMyWorkList' ) ;
123+ const {
124+ WORK_BASKET : {
125+ DATA_PAGES : { D__PY_MY_WORK_LIST }
126+ }
127+ } = PCore . getConstants ( ) ;
128+ updateWorkList ( getPConnect , getMappedValue ( D__PY_MY_WORK_LIST ) ) ;
127129 }
128130
129131 updateToDo ( ) {
130132 this . configProps$ = this . pConn$ . resolveConfigProps ( this . pConn$ . getConfigProps ( ) ) as ToDoProps ;
131133
132- if ( this . headerText$ == undefined ) {
133- this . headerText$ = this . configProps$ . headerText ;
134- }
135-
136- this . datasource$ = this . configProps$ . datasource ? this . configProps$ . datasource : this . datasource$ ;
137- this . myWorkList$ = this . configProps$ . myWorkList ? this . configProps$ . myWorkList : this . myWorkList$ ;
134+ this . headerText$ = this . headerText$ || this . configProps$ . headerText ;
135+ this . datasource$ = this . datasource$ || this . configProps$ . datasource ;
136+ this . myWorkList$ = this . myWorkList$ || this . configProps$ . myWorkList ;
138137
139138 this . assignmentsSource$ = this . datasource$ ?. source || this . myWorkList$ ?. source ;
140139
141140 if ( this . showTodoList$ ) {
142- this . assignmentCount$ = this . assignmentsSource$ != null ? this . assignmentsSource$ . length : 0 ;
143- this . arAssignments$ = this . topThreeAssignments ( this . assignmentsSource$ ) ;
141+ if ( this . assignmentsSource$ ) {
142+ this . count = this . assignmentsSource$ ? this . assignmentsSource$ . length : 0 ;
143+ this . arAssignments$ = this . topThreeAssignments ( this . assignmentsSource$ ) ;
144+ } else if ( this . myWorkList$ . datapage ) {
145+ fetchMyWorkList ( this . myWorkList$ . datapage , this . pConn$ . getComponentConfig ( ) ?. myWorkList . fields , 3 , true , this . context$ ) . then ( responseData => {
146+ this . deferLoadWorklistItems ( responseData ) ;
147+ } ) ;
148+ } else {
149+ this . arAssignments$ = [ ] ;
150+ }
144151 } else {
145152 // get caseInfoId assignment.
146153 // eslint-disable-next-line no-lonely-if
@@ -155,6 +162,11 @@ export class TodoComponent implements OnInit, OnDestroy, OnChanges {
155162 this . currentUserInitials$ = this . utils . getInitials ( this . currentUser$ ?? '' ) ;
156163 }
157164
165+ deferLoadWorklistItems ( responseData ) {
166+ this . count = responseData . totalCount ;
167+ this . arAssignments$ = responseData . data ;
168+ }
169+
158170 getID ( assignment : any ) {
159171 if ( assignment . value ) {
160172 const refKey = assignment . value ;
@@ -181,15 +193,6 @@ export class TodoComponent implements OnInit, OnDestroy, OnChanges {
181193 return this . type$ === this . CONSTS . TODO ? assignment . name : assignment . stepName ;
182194 }
183195
184- initAssignments ( ) : any [ ] {
185- if ( this . assignmentsSource$ ) {
186- this . assignmentCount$ = this . assignmentsSource$ . length ;
187- return this . topThreeAssignments ( this . assignmentsSource$ ) ;
188- }
189- // turn off todolist
190- return [ ] ;
191- }
192-
193196 getCaseInfoAssignment ( assignmentsSource : any [ ] , caseInfoID : string ) {
194197 const result : any [ ] = [ ] ;
195198 for ( const source of assignmentsSource ) {
@@ -206,18 +209,26 @@ export class TodoComponent implements OnInit, OnDestroy, OnChanges {
206209 }
207210
208211 _showMore ( ) {
209- this . ngZone . run ( ( ) => {
210- this . bShowMore$ = false ;
212+ this . bShowMore$ = false ;
213+
214+ const { WORKLIST } = PCore . getConstants ( ) ;
215+
216+ if ( this . type$ === WORKLIST && this . count && this . count > this . arAssignments$ . length && ! this . assignmentsSource$ ) {
217+ fetchMyWorkList ( this . myWorkList$ . datapage , this . pConn$ . getComponentConfig ( ) ?. myWorkList . fields , this . count , false , this . context$ ) . then (
218+ response => {
219+ this . arAssignments$ = response . data ;
220+ }
221+ ) ;
222+ } else {
211223 this . arAssignments$ = this . assignmentsSource$ ;
212- } ) ;
224+ }
213225 }
214226
215227 _showLess ( ) {
216- this . ngZone . run ( ( ) => {
217- this . bShowMore$ = true ;
228+ this . bShowMore$ = true ;
229+ const { WORKLIST } = PCore . getConstants ( ) ;
218230
219- this . arAssignments$ = this . topThreeAssignments ( this . assignmentsSource$ ) ;
220- } ) ;
231+ this . arAssignments$ = this . type$ === WORKLIST ? this . arAssignments$ . slice ( 0 , 3 ) : this . topThreeAssignments ( this . assignmentsSource$ ) ;
221232 }
222233
223234 isChildCase ( assignment ) {
0 commit comments