@@ -117,6 +117,7 @@ export default class extends BaseGenerator {
117
117
handlebars . registerHelper ( "inArray" , hbh_array . inArray ) ;
118
118
handlebars . registerHelper ( "forEach" , hbh_array . forEach ) ;
119
119
handlebars . registerHelper ( "downcase" , hbh_string . downcase ) ;
120
+ handlebars . registerHelper ( "capitalize" , hbh_string . capitalize ) ;
120
121
121
122
this . registerSwitchHelper ( ) ;
122
123
}
@@ -233,7 +234,7 @@ export const store = new Vuex.Store({
233
234
var stack =
234
235
handlebars . __switch_stack__ [ handlebars . __switch_stack__ . length - 1 ] ;
235
236
236
- if ( stack . switch_match || caseValues . includes ( stack . switch_value ) ) {
237
+ if ( stack . switch_match || caseValues . indexOf ( stack . switch_value ) === - 1 ) {
237
238
return "" ;
238
239
} else {
239
240
stack . switch_match = true ;
@@ -250,21 +251,23 @@ export const store = new Vuex.Store({
250
251
}
251
252
252
253
generate ( api , resource , dir ) {
253
- return resource . getParameters ( ) . then ( params => {
254
- params = params . map ( param => ( {
255
- ...param ,
256
- ...this . getHtmlInputTypeFromField ( param )
257
- } ) ) ;
258
-
259
- params = this . cleanupParams ( params ) ;
260
- this . generateFiles ( api , resource , dir , params ) ;
261
- } ) ;
254
+ return resource
255
+ . getParameters ( )
256
+ . then ( params => {
257
+ params = params . map ( param => ( {
258
+ ...param ,
259
+ ...this . getHtmlInputTypeFromField ( param )
260
+ } ) ) ;
261
+
262
+ params = this . cleanupParams ( params ) ;
263
+ this . generateFiles ( api , resource , dir , params ) ;
264
+ } )
265
+ . catch ( e => console . log ( chalk . red ( e ) ) ) ;
262
266
}
263
267
264
268
cleanupParams ( params ) {
265
269
const stats = { } ;
266
270
const result = [ ] ;
267
-
268
271
params . forEach ( p => {
269
272
let key = p . variable . endsWith ( "[]" )
270
273
? p . variable . slice ( 0 , - 2 )
@@ -274,13 +277,14 @@ export const store = new Vuex.Store({
274
277
}
275
278
stats [ key ] += 1 ;
276
279
} ) ;
277
-
278
280
params . forEach ( p => {
279
- if ( p . variable . endsWith ( "[exists]" ) ) {
281
+ if ( p . variable . startsWith ( "exists[" ) ) {
282
+ result . push ( p ) ;
280
283
return ; // removed for the moment, it can help to add null option to select
281
284
}
282
285
if ( p . variable . startsWith ( "order[" ) ) {
283
- return ; // removed for the moment, it can help to sorting data
286
+ result . push ( p ) ;
287
+ return ;
284
288
}
285
289
if ( ! stats [ p . variable ] && p . variable . endsWith ( "[]" ) ) {
286
290
if ( stats [ p . variable . slice ( 0 , - 2 ) ] === 1 ) {
@@ -293,7 +297,6 @@ export const store = new Vuex.Store({
293
297
result . push ( p ) ;
294
298
}
295
299
} ) ;
296
-
297
300
return result ;
298
301
}
299
302
@@ -330,10 +333,43 @@ export const store = new Vuex.Store({
330
333
331
334
const parameters = [ ] ;
332
335
params . forEach ( p => {
333
- const param = fields . find ( field => field . name === p . variable ) ;
334
- if ( ! param ) {
335
- parameters . push ( p ) ;
336
+ const paramIndex = fields . findIndex ( field => field . name === p . variable ) ;
337
+ if ( paramIndex === - 1 ) {
338
+ if ( p . variable . startsWith ( "order[" ) ) {
339
+ var v = p . variable . slice ( 6 , - 1 ) ;
340
+ var found = fields . findIndex ( field => field . name === v ) ;
341
+ if ( found !== - 1 ) {
342
+ fields [ found ] . sortable = true ;
343
+ }
344
+ return ;
345
+ }
346
+
347
+ if ( p . variable . startsWith ( "exists[" ) ) {
348
+ var exists = p . variable . slice ( 7 , - 1 ) ;
349
+ var foundExistsFieldIndex = fields . findIndex (
350
+ field => field . name === exists
351
+ ) ;
352
+ if ( foundExistsFieldIndex !== - 1 ) {
353
+ const param = fields [ foundExistsFieldIndex ] ;
354
+ param . variable = p . variable ;
355
+ param . filterType = "exists" ;
356
+ parameters . push ( param ) ;
357
+ } else {
358
+ p . name = exists ;
359
+ p . filterType = "exists" ;
360
+ parameters . push ( p ) ;
361
+ }
362
+ return ;
363
+ }
364
+
365
+ if ( ! p . name ) {
366
+ p = { ...p , name : p . variable } ;
367
+ }
368
+ if ( ! p . sortable ) {
369
+ parameters . push ( p ) ;
370
+ }
336
371
} else {
372
+ const param = fields [ paramIndex ] ;
337
373
param . multiple = p . multiple ;
338
374
parameters . push ( param ) ;
339
375
}
@@ -345,6 +381,8 @@ export const store = new Vuex.Store({
345
381
346
382
const labels = this . commonLabelTexts ( ) ;
347
383
384
+ const hashEntry = this . hashCode ( api . entrypoint ) ;
385
+
348
386
const context = {
349
387
title : resource . title ,
350
388
name : resource . name ,
@@ -359,7 +397,8 @@ export const store = new Vuex.Store({
359
397
formContainsDate,
360
398
hydraPrefix : this . hydraPrefix ,
361
399
titleUcFirst,
362
- labels
400
+ labels,
401
+ hashEntry
363
402
} ;
364
403
365
404
// Create directories
@@ -509,7 +548,11 @@ export const store = new Vuex.Store({
509
548
false
510
549
) ;
511
550
512
- this . createEntrypoint ( api . entrypoint , `${ dir } /config/entrypoint.js` ) ;
551
+ this . createEntrypoint (
552
+ api . entrypoint ,
553
+ `${ dir } /config/${ hashEntry } _entrypoint.js`
554
+ ) ;
555
+
513
556
this . createFile (
514
557
"utils/fetch.js" ,
515
558
`${ dir } /utils/fetch.js` ,
@@ -535,6 +578,15 @@ export const store = new Vuex.Store({
535
578
) ;
536
579
}
537
580
581
+ hashCode ( s ) {
582
+ return Math . abs (
583
+ Array . from ( s ) . reduce (
584
+ ( s , c ) => ( Math . imul ( 31 , s ) + c . charCodeAt ( 0 ) ) | 0 ,
585
+ 0
586
+ )
587
+ ) ;
588
+ }
589
+
538
590
contextLabelTexts ( formFields , fields ) {
539
591
let texts = [ ] ;
540
592
formFields . forEach ( x => texts . push ( x . name ) ) ; // forms
0 commit comments