@@ -3,7 +3,7 @@ import { MatDialog } from '@angular/material/dialog'
33import { AttributeConfig , AttributeConcatenationConfig , AttributeDefaultConfig , AttributeValueConfig } from '../ArcGISConfig' ;
44import { ArcGISPluginConfig , defaultArcGISPluginConfig } from '../ArcGISPluginConfig'
55import { ArcService , Form , MageEvent } from '../arc.service'
6- import { Subject } from 'rxjs' ;
6+ import { Subject , first } from 'rxjs' ;
77import { FormGroup , FormBuilder } from '@angular/forms' ;
88
99@Component ( {
@@ -59,6 +59,21 @@ export class ArcAdminComponent implements OnInit {
5959 this . config = defaultArcGISPluginConfig ;
6060 this . editConfig = defaultArcGISPluginConfig ;
6161 this . editFieldMappings = false ;
62+ this . attributesForm = this . fb . group ( {
63+ observationIdField : [ '' ] ,
64+ idSeparator : [ '' ] ,
65+ eventIdField : [ '' ] ,
66+ lastEditedDateField : [ '' ] ,
67+ eventNameField : [ '' ] ,
68+ userIdField : [ '' ] ,
69+ usernameField : [ '' ] ,
70+ userDisplayNameField : [ '' ] ,
71+ deviceIdField : [ '' ] ,
72+ createdAtField : [ '' ] ,
73+ lastModifiedField : [ '' ] ,
74+ geometryType : [ '' ]
75+ } ) ;
76+
6277 arcService . fetchArcConfig ( ) . subscribe ( x => {
6378 this . config = x ;
6479 if ( ! this . config . baseUrl ) {
@@ -72,21 +87,32 @@ export class ArcAdminComponent implements OnInit {
7287 this . config = config ;
7388 this . configChangedNotifier . next ( ) ;
7489 }
75- // Visually blank but has underlying value in editConfig
90+
7691 ngOnInit ( ) : void {
77- this . attributesForm = this . fb . group ( {
78- observationIdField : [ '' ] ,
79- idSeparator : [ '' ] ,
80- eventIdField : [ '' ] ,
81- lastEditedDateField : [ '' ] ,
82- eventNameField : [ '' ] ,
83- userIdField : [ '' ] ,
84- usernameField : [ '' ] ,
85- userDisplayNameField : [ '' ] ,
86- deviceIdField : [ '' ] ,
87- createdAtField : [ '' ] ,
88- lastModifiedField : [ '' ] ,
89- geometryType : [ '' ]
92+ this . arcService . fetchArcConfig ( ) . pipe ( first ( ) ) . subscribe ( {
93+ next : config => {
94+ if ( config ) {
95+ // Populate form with values from config
96+ this . attributesForm . patchValue ( {
97+ observationIdField : config . observationIdField || '' ,
98+ idSeparator : config . idSeparator || '' ,
99+ eventIdField : config . eventIdField || '' ,
100+ lastEditedDateField : config . lastEditedDateField || '' ,
101+ eventNameField : config . eventNameField || '' ,
102+ userIdField : config . userIdField || '' ,
103+ usernameField : config . usernameField || '' ,
104+ userDisplayNameField : config . userDisplayNameField || '' ,
105+ deviceIdField : config . deviceIdField || '' ,
106+ createdAtField : config . createdAtField || '' ,
107+ lastModifiedField : config . lastModifiedField || '' ,
108+ geometryType : config . geometryType || ''
109+ } ) ;
110+ console . log ( 'Form initialized with server config:' , config ) ;
111+ }
112+ } ,
113+ error : error => {
114+ console . error ( 'Failed to fetch config:' , error ) ;
115+ }
90116 } ) ;
91117 }
92118
@@ -110,7 +136,7 @@ export class ArcAdminComponent implements OnInit {
110136 createdAtField : formValue . createdAtField || this . editConfig . createdAtField ,
111137 lastModifiedField : formValue . lastModifiedField || this . editConfig . lastModifiedField ,
112138 geometryType : formValue . geometryType || this . editConfig . geometryType
113- } ;
139+ } ;
114140
115141 console . log ( 'Form Submitted:' , this . editConfig ) ;
116142 console . log ( 'formValue: ' , formValue ) ;
@@ -122,25 +148,32 @@ export class ArcAdminComponent implements OnInit {
122148 }
123149 }
124150
125- //when edit attributes is canceled, display and empty form but preserved data in editConfig
126151 onCancel ( ) : void {
127- this . attributesForm . reset ( {
128- observationIdField : '' ,
129- idSeparator : '' ,
130- eventIdField : '' ,
131- lastEditedDateField : '' ,
132- eventNameField : '' ,
133- userIdField : '' ,
134- usernameField : '' ,
135- userDisplayNameField : '' ,
136- deviceIdField : '' ,
137- createdAtField : '' ,
138- lastModifiedField : '' ,
139- geometryType : ''
152+ console . log ( 'Cancel selected' ) ;
153+ this . arcService . fetchArcConfig ( ) . pipe ( first ( ) ) . subscribe ( {
154+ next : config => {
155+ if ( config ) {
156+ this . attributesForm . patchValue ( {
157+ observationIdField : config . observationIdField || '' ,
158+ idSeparator : config . idSeparator || '' ,
159+ eventIdField : config . eventIdField || '' ,
160+ lastEditedDateField : config . lastEditedDateField || '' ,
161+ eventNameField : config . eventNameField || '' ,
162+ userIdField : config . userIdField || '' ,
163+ usernameField : config . usernameField || '' ,
164+ userDisplayNameField : config . userDisplayNameField || '' ,
165+ deviceIdField : config . deviceIdField || '' ,
166+ createdAtField : config . createdAtField || '' ,
167+ lastModifiedField : config . lastModifiedField || '' ,
168+ geometryType : config . geometryType || ''
169+ } ) ;
170+ console . log ( 'Form reloaded with server config:' , config ) ;
171+ }
172+ } ,
173+ error : error => {
174+ console . error ( 'Failed to reload config from server:' , error ) ;
175+ }
140176 } ) ;
141- console . log ( 'Canceled edit' ) ;
142- console . log ( 'Current data: ' , this . editConfig )
143-
144177 }
145178 handleEventResults ( x : MageEvent [ ] ) {
146179 this . events = x
0 commit comments