@@ -51,6 +51,14 @@ export class EntityEditorComponent {
5151 this . actions = actions ;
5252 this . dataTypes = dataTypes ;
5353 this . entityBackup = JSON . stringify ( this . entity ) ;
54+ // Set property ui flags based on entity state
55+ this . entity . definition . properties . forEach ( function ( property ) {
56+ property . isPrimaryKey = this . entity . definition . primaryKey === property . name ;
57+ property . hasElementRangeIndex = this . entity . definition . elementRangeIndex . indexOf ( property . name ) >= 0 ;
58+ property . hasRangeIndex = this . entity . definition . rangeIndex . indexOf ( property . name ) >= 0 ;
59+ property . hasWordLexicon = this . entity . definition . wordLexicon . indexOf ( property . name ) >= 0 ;
60+ property . required = this . entity . definition . required . indexOf ( property . name ) >= 0 ;
61+ } , this ) ;
5462 }
5563
5664 getType ( property : PropertyType ) {
@@ -147,26 +155,6 @@ export class EntityEditorComponent {
147155 } ) ;
148156 }
149157
150- isPrimaryKey ( key : string ) {
151- return this . entity . definition . primaryKey === key ;
152- }
153-
154- isRangeIndex ( key : string ) {
155- return this . entity . definition . elementRangeIndex . indexOf ( key ) >= 0 ;
156- }
157-
158- isPathRangeIndex ( key : string ) {
159- return this . entity . definition . rangeIndex . indexOf ( key ) >= 0 ;
160- }
161-
162- isWordLexicon ( key : string ) {
163- return this . entity . definition . wordLexicon . indexOf ( key ) >= 0 ;
164- }
165-
166- isRequired ( key : string ) {
167- return this . entity . definition . required . indexOf ( key ) >= 0 ;
168- }
169-
170158 addProperty ( ) {
171159 this . entity . definition . properties . push ( new PropertyType ( ) ) ;
172160 }
@@ -212,6 +200,29 @@ export class EntityEditorComponent {
212200
213201 saveEntity ( ) {
214202 if ( this . actions . save ) {
203+ // Set entity state based on property ui flags
204+ this . entity . definition . primaryKey = null ;
205+ this . entity . definition . elementRangeIndex = [ ] ;
206+ this . entity . definition . rangeIndex = [ ] ;
207+ this . entity . definition . wordLexicon = [ ] ;
208+ this . entity . definition . required = [ ] ;
209+ this . entity . definition . properties . forEach ( function ( property ) {
210+ if ( property . isPrimaryKey ) {
211+ this . entity . definition . primaryKey = property . name ;
212+ }
213+ if ( property . hasElementRangeIndex ) {
214+ this . entity . definition . elementRangeIndex . push ( property . name ) ;
215+ }
216+ if ( property . hasRangeIndex ) {
217+ this . entity . definition . rangeIndex . push ( property . name ) ;
218+ }
219+ if ( property . hasWordLexicon ) {
220+ this . entity . definition . wordLexicon . push ( property . name ) ;
221+ }
222+ if ( property . required ) {
223+ this . entity . definition . required . push ( property . name ) ;
224+ }
225+ } , this ) ;
215226 this . actions . save ( ) ;
216227 }
217228 this . dialog . hide ( ) ;
@@ -243,28 +254,14 @@ export class EntityEditorComponent {
243254 }
244255
245256 togglePrimaryKey ( property : PropertyType ) {
246- if ( this . entity . definition . primaryKey === property . name ) {
247- this . entity . definition . primaryKey = null ;
257+ if ( property . isPrimaryKey ) {
258+ property . isPrimaryKey = false ;
248259 } else {
249- this . entity . definition . primaryKey = property . name ;
250- }
251- }
252-
253- toggleRangeIndex ( property : PropertyType ) {
254- let idx = this . entity . definition . elementRangeIndex . indexOf ( property . name ) ;
255- if ( idx >= 0 ) {
256- this . entity . definition . elementRangeIndex . splice ( idx , 1 ) ;
257- } else {
258- this . entity . definition . elementRangeIndex . push ( property . name ) ;
259- }
260- }
261-
262- togglePathRangeIndex ( property : PropertyType ) {
263- let idx = this . entity . definition . rangeIndex . indexOf ( property . name ) ;
264- if ( idx >= 0 ) {
265- this . entity . definition . rangeIndex . splice ( idx , 1 ) ;
266- } else {
267- this . entity . definition . rangeIndex . push ( property . name ) ;
260+ // Unset any existing primary key
261+ this . entity . definition . properties . map ( function ( prop ) {
262+ prop . isPrimaryKey = false ;
263+ } ) ;
264+ property . isPrimaryKey = true ;
268265 }
269266 }
270267
@@ -314,24 +311,6 @@ export class EntityEditorComponent {
314311 }
315312 }
316313
317- toggleWordLexicon ( property : PropertyType ) {
318- let idx = this . entity . definition . wordLexicon . indexOf ( property . name ) ;
319- if ( idx >= 0 ) {
320- this . entity . definition . wordLexicon . splice ( idx , 1 ) ;
321- } else {
322- this . entity . definition . wordLexicon . push ( property . name ) ;
323- }
324- }
325-
326- toggleRequired ( property : PropertyType ) {
327- let idx = this . entity . definition . required . indexOf ( property . name ) ;
328- if ( idx >= 0 ) {
329- this . entity . definition . required . splice ( idx , 1 ) ;
330- } else {
331- this . entity . definition . required . push ( property . name ) ;
332- }
333- }
334-
335314 onDescKey ( $event : KeyboardEvent , propertyIndex : number ) {
336315 if (
337316 ( propertyIndex === ( this . entity . definition . properties . length - 1 ) ) &&
0 commit comments