Skip to content

Commit bff6b1e

Browse files
committed
Fields of type "list" for multiselection + cleanups.
1 parent 21526ac commit bff6b1e

7 files changed

Lines changed: 31 additions & 17 deletions

File tree

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ Models contain the name of the driving table and the list of fields/columns pres
141141
| lovColumn | Column name (in the lovTable) for field value (only for fields of type "lov"). |
142142
| lovIcon | Set to True to include icon with LOV items (only for fields of type "lov"). |
143143
| object | Model id for the object to link to (only for fields of type "lov"). |
144-
| type | Field type is not a database column type but more a UI field type. Possible field types: <ul><li>boolean</li><li>date</li><li>datetime</li><li>decimal</li><li>document</li><li>email</li><li>image</li><li>integer</li><li>lov (list of values)</li><li>money</li><li>text</li><li>textmultiline</li><li>time</li><li>url</li></ul> |
144+
| type | Field type is not a database column type but more a UI field type. Possible field types: <ul><li>boolean</li><li>date</li><li>datetime</li><li>decimal</li><li>document</li><li>email</li><li>image</li><li>integer</li><li>lov (list of values)</li><li>list (multiselect)</li><li>money</li><li>text</li><li>textmultiline</li><li>time</li><li>url</li></ul> |
145145
| required | Determines if the field is required for saving. |
146146
| readOnly | Display field as readOnly (not editable). |
147147
| inMany | Determines if the field is present (by default) in lists of records. |
@@ -533,7 +533,7 @@ Fields of type "lov" (List of values) are represented as 2 fields for Id and val
533533
complete
534534
}
535535
# List - contacts w/ firstname starts w/ "A" and search for "ab"
536-
ab_a_contacts:contacts (search: "ab", firstname: "sw.A") {
536+
ab_a_contacts: contacts (search: "ab", firstname: "sw.A") {
537537
id
538538
firstname
539539
lastname
@@ -554,11 +554,11 @@ All objects flagged as active are exposed for querying a single record by Id.
554554
```
555555
# contact w/ id = 1
556556
{
557-
contact (id: 1 ){
558-
firstname
559-
lastname
560-
category_txt
561-
email
557+
contact (id: 1 ){
558+
firstname
559+
lastname
560+
category_txt
561+
email
562562
}
563563
}
564564

js/graphql-schema.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function fieldType(f){
4242
}else if(f.type===ft.dec){
4343
gqlType = GraphQLFloat
4444
}else if(f.type===ft.list){
45-
gqlType = GraphQLList
45+
gqlType = GraphQLList(GraphQLInt)
4646
}else{
4747
gqlType = GraphQLString
4848
}/*

js/setup/database.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const ft_postgreSQL = {
3636
datetime: 'timestamp'+noTZ,
3737
time: 'time'+noTZ,
3838
lov: 'integer',
39-
list: 'text[]', // many values for one field (behave like tags - return an array of strings)
39+
list: 'integer[]', // many values for one field (array of integer for ids in lovTable)
4040
html: 'text',
4141
email: 'text',
4242
pix: 'text',
@@ -59,7 +59,8 @@ const sysColumns = {
5959

6060
const stringValue = v => v ? ("'"+v.replace(/'/g, "''")+"'") : 'NULL'
6161

62-
const lovTable = f => schema+'."'+(f.lovTable ? f.lovTable : (tableName+'_'+f.id))+'"';
62+
const lovTable = (f, tableName) => f.lovTable ? f.lovTable : (tableName+'_'+f.id);
63+
const lovTableWithSchema = (f, tableName) => schema+'."'+lovTable(f, tableName)+'"';
6364

6465
function sqlInsert(tableNameSchema, m, data){
6566
const { pKey, fieldsH } = m
@@ -130,7 +131,7 @@ function sqlInsert(tableNameSchema, m, data){
130131
}
131132

132133
function sqlCreatePopulateLOV(f, tableName, lovIncluded){
133-
const t = lovTable(f);
134+
const t = lovTableWithSchema(f, tableName);
134135
const icons = f.lovIcon || false;
135136
let sql = ''
136137
let maxId = -1
@@ -156,10 +157,11 @@ function sqlCreatePopulateLOV(f, tableName, lovIncluded){
156157
txt += icons ? (',\'' + (item.icon || '') + '\')') : ')'
157158
return txt
158159
}).join(',\n')+';\n\n';
160+
const t = lovTable(f, tableName);
159161
if(maxId){
160162
maxId++
161163
sql += 'ALTER SEQUENCE '+schema+
162-
'."'+f.lovTable+'_id_seq" RESTART WITH '+maxId+';\n\n'
164+
'."'+t+'_id_seq" RESTART WITH '+maxId+';\n\n'
163165
}
164166
}
165167
lovIncluded.push(t)

js/stats.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ function sqlAggregate(fn, f){
2525
}else{ // min, max, sum
2626
switch(f.type){
2727
case ft.int:
28-
case ft.dec:
29-
//tcast = '::numeric'+f.type
3028
tcast = '::'+f.type
3129
break
30+
case ft.dec:
31+
tcast = '::numeric::float8'
32+
break
3233
}
3334
}
3435
return ', '+fn+'("'+f.column+'"'+num+')'+tcast+' AS "'+f.id+'_'+fn+'"'
@@ -50,7 +51,7 @@ const fnPrep = fields => data => {
5051
if(config.wComments){
5152
pStats.nb_comments = data.nb_comments
5253
}
53-
fields.forEach((f)=>{
54+
fields.forEach(f => {
5455
if(dico.fieldIsNumeric(f)){
5556
let item = {
5657
min: data[f.id+'_min'],

js/utils/dico.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ const fieldIsText = f => [ft.text, ft.textml, ft.url, ft.html, ft.email].indexOf
9393
const fieldIsDateOrTime = f => f.type===ft.date || f.type===ft.datetime || f.type===ft.time
9494
const fieldIsNumeric = f => fieldIsNumber(f) || fieldIsDateOrTime(f)
9595

96-
const fieldChartable = f => f.type===ft.lov || f.type===ft.list || f.type===ft.bool || fieldIsNumber(f)
96+
const fieldChartable = f => f.type===ft.lov || f.type===ft.bool || fieldIsNumber(f)
9797
const fieldInCharts = f => fieldChartable(f) && !f.noCharts
9898

9999
function prepModel(m){

js/utils/query.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function runQuery(res, sql, values, singleRecord, format, header, fnPrep){
7272
return res.json([]);
7373
}
7474
}
75-
errors.badRequest(res, 'Database error.', 500)
75+
return errors.badRequest(res, 'Database error - '+err.message, 500)
7676
})
7777
}
7878

models/tests/test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,17 @@ const fields = [
6161
"column": "f_lovlc",
6262
"lovTable": "z_test_flavor"
6363
},
64+
{
65+
"id": "list",
66+
"type": "list",
67+
"label": "Multiselect",
68+
//"required": true,
69+
"list": flavors,
70+
"column": "f_list",
71+
"inMany": true,
72+
"width": 100,
73+
"lovTable": "z_test_flavor"
74+
},
6475
{
6576
"id": "date",
6677
"type": "date",

0 commit comments

Comments
 (0)