@@ -6,6 +6,7 @@ import { MatSelectModule } from '@angular/material/select';
66import { MatFormFieldModule } from '@angular/material/form-field' ;
77import { interval } from 'rxjs' ;
88import { AngularPConnectData , AngularPConnectService } from '../../../_bridge/angular-pconnect' ;
9+ import { DatapageService } from '../../../_services/datapage.service' ;
910import { Utils } from '../../../_helpers/utils' ;
1011import { ComponentMapperComponent } from '../../../_bridge/component-mapper/component-mapper.component' ;
1112import { handleEvent } from '../../../_helpers/event-util' ;
@@ -22,6 +23,11 @@ interface DropdownProps extends PConnFieldProps {
2223 datasource ?: any [ ] ;
2324 onRecordChange ?: any ;
2425 fieldMetadata ?: any ;
26+ listType ?: string ;
27+ columns ?: any [ ] ;
28+ deferDatasource ?: boolean ;
29+ datasourceMetadata ?: any ;
30+ parameters ?: any ;
2531}
2632
2733@Component ( {
@@ -67,7 +73,8 @@ export class DropdownComponent implements OnInit, OnDestroy {
6773 constructor (
6874 private angularPConnect : AngularPConnectService ,
6975 private cdRef : ChangeDetectorRef ,
70- private utils : Utils
76+ private utils : Utils ,
77+ private dataPageService : DatapageService
7178 ) { }
7279
7380 ngOnInit ( ) : void {
@@ -122,7 +129,8 @@ export class DropdownComponent implements OnInit, OnDestroy {
122129 updateSelf ( ) : void {
123130 // moved this from ngOnInit() and call this from there instead...
124131 this . configProps$ = this . pConn$ . resolveConfigProps ( this . pConn$ . getConfigProps ( ) ) as DropdownProps ;
125-
132+ let { listType, parameters, datasource = [ ] , columns = [ ] } = this . configProps$ ;
133+ const { deferDatasource, datasourceMetadata } = this . pConn$ . getConfigProps ( ) as DropdownProps ;
126134 if ( this . configProps$ . value != undefined ) {
127135 this . value$ = this . configProps$ . value ;
128136 }
@@ -132,6 +140,7 @@ export class DropdownComponent implements OnInit, OnDestroy {
132140 this . label$ = this . configProps$ . label ;
133141 this . helperText = this . configProps$ . helperText ;
134142 this . hideLabel = this . configProps$ . hideLabel ;
143+ const context = this . pConn$ . getContextName ( ) ;
135144 // timeout and detectChanges to avoid ExpressionChangedAfterItHasBeenCheckedError
136145 setTimeout ( ( ) => {
137146 if ( this . configProps$ . required != null ) {
@@ -169,6 +178,33 @@ export class DropdownComponent implements OnInit, OnDestroy {
169178 }
170179
171180 this . actionsApi = this . pConn$ . getActionsApi ( ) ;
181+ if ( deferDatasource && datasourceMetadata ?. datasource ?. name ) {
182+ listType = 'datapage' ;
183+ datasource = datasourceMetadata . datasource . name ;
184+ const { parameters : dataSourceParameters , propertyForDisplayText, propertyForValue } = datasourceMetadata . datasource ;
185+ parameters = this . flattenParameters ( dataSourceParameters ) ;
186+ const displayProp = propertyForDisplayText ?. startsWith ( '@P' ) ? propertyForDisplayText . substring ( 3 ) : propertyForDisplayText ;
187+ const valueProp = propertyForValue ?. startsWith ( '@P' ) ? propertyForValue . substring ( 3 ) : propertyForValue ;
188+ columns = [
189+ {
190+ key : 'true' ,
191+ setProperty : 'Associated property' ,
192+ value : valueProp
193+ } ,
194+ {
195+ display : 'true' ,
196+ primary : 'true' ,
197+ useForSearch : true ,
198+ value : displayProp
199+ }
200+ ] ;
201+ }
202+
203+ columns = this . preProcessColumns ( columns ) || [ ] ;
204+ if ( ! this . displayMode$ && listType !== 'associated' && typeof datasource === 'string' ) {
205+ this . getData ( datasource , parameters , columns , context ) ;
206+ }
207+
172208 this . propName = this . pConn$ . getStateProps ( ) . value ;
173209 const className = this . pConn$ . getCaseInfo ( ) . getClassName ( ) ;
174210 const refName = this . propName ?. slice ( this . propName . lastIndexOf ( '.' ) + 1 ) ;
@@ -199,6 +235,56 @@ export class DropdownComponent implements OnInit, OnDestroy {
199235 }
200236 }
201237
238+ getData ( datasource , parameters , columns , context ) {
239+ this . dataPageService . getDataPageData ( datasource , parameters , context ) . then ( ( results : any ) => {
240+ const optionsData : any [ ] = [ ] ;
241+ const displayColumn = this . getDisplayFieldsMetaData ( columns ) ;
242+ results ?. forEach ( element => {
243+ const val = element [ displayColumn . primary ] ?. toString ( ) ;
244+ const obj = {
245+ key : element [ displayColumn . key ] || element . pyGUID ,
246+ value : val
247+ } ;
248+ optionsData . push ( obj ) ;
249+ } ) ;
250+ optionsData ?. unshift ( { key : 'Select' , value : this . pConn$ . getLocalizedValue ( 'Select...' , '' , '' ) } ) ;
251+ this . options$ = optionsData ;
252+ } ) ;
253+ }
254+
255+ flattenParameters ( params = { } ) {
256+ const flatParams = { } ;
257+ Object . keys ( params ) . forEach ( key => {
258+ const { name, value : theVal } = params [ key ] ;
259+ flatParams [ name ] = theVal ;
260+ } ) ;
261+
262+ return flatParams ;
263+ }
264+
265+ preProcessColumns ( columnList ) {
266+ return columnList . map ( col => {
267+ const tempColObj = { ...col } ;
268+ tempColObj . value = col . value && col . value . startsWith ( '.' ) ? col . value . substring ( 1 ) : col . value ;
269+ return tempColObj ;
270+ } ) ;
271+ }
272+
273+ getDisplayFieldsMetaData ( columnList ) {
274+ const displayColumns = columnList . filter ( col => col . display === 'true' ) ;
275+ const metaDataObj : any = { key : '' , primary : '' , secondary : [ ] } ;
276+ const keyCol = columnList . filter ( col => col . key === 'true' ) ;
277+ metaDataObj . key = keyCol . length > 0 ? keyCol [ 0 ] . value : 'auto' ;
278+ for ( let index = 0 ; index < displayColumns . length ; index += 1 ) {
279+ if ( displayColumns [ index ] . primary === 'true' ) {
280+ metaDataObj . primary = displayColumns [ index ] . value ;
281+ } else {
282+ metaDataObj . secondary . push ( displayColumns [ index ] . value ) ;
283+ }
284+ }
285+ return metaDataObj ;
286+ }
287+
202288 isSelected ( buttonValue : string ) : boolean {
203289 return this . value$ === buttonValue ;
204290 }
0 commit comments