Skip to content

Commit a430c25

Browse files
committed
Progress on collections + Cleanups.
1 parent bccf47c commit a430c25

5 files changed

Lines changed: 120 additions & 12 deletions

File tree

js/crud.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -179,24 +179,23 @@ function collecOne(req, res) {
179179
const mid = req.params.entity
180180
m = dico.getModel(mid),
181181
collecId = req.params.collec,
182-
collec = m.collecsH[collecId],
183-
pId = parseInt(req.query.id, 10);
182+
collec = m.collecsH[collecId]
184183

185184
if(m && collec){
186-
const sqlParams = [pId],
187-
sql = 'SELECT t1.id, '+sqls.select(collec.fields, null, 't1')+
188-
' FROM '+schema+'."'+collec.table+'" AS t1'+
189-
sqls.sqlFromLOVs(collec.fields, schema)+
190-
' WHERE t1."'+collec.column+'"=$1'+
191-
' ORDER BY t1.'+collecOrderBy(collec)+
192-
' LIMIT '+defaultPageSize+';';
193-
194-
query.runQuery(res, sql, sqlParams, false);
185+
const sqlParams = [parseInt(req.query.id, 10)];
186+
query.runQuery(res, SQLCollecOne(collec), sqlParams, false);
195187
}else{
196188
errors.badRequest(res)
197189
}
198190
}
199191

192+
const SQLCollecOne = collec => 'SELECT t1.id, '+sqls.select(collec.fields, null, 't1')+
193+
' FROM '+schema+'."'+collec.table+'" AS t1'+
194+
sqls.sqlFromLOVs(collec.fields, schema)+
195+
' WHERE t1."'+collec.column+'"=$1'+
196+
' ORDER BY t1.'+collecOrderBy(collec)+
197+
' LIMIT '+defaultPageSize+';';
198+
200199
// --------------------------------------------------------------------------------------
201200

202201
module.exports = {

js/designer.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const objProps = {
3939
"icon",
4040
"description",
4141
"groups",
42+
"collections",
4243
//"c_date",
4344
//"u_date",
4445
],
@@ -47,6 +48,7 @@ const objProps = {
4748
"table",
4849
"pkey",
4950
"active",
51+
"collections",
5052
]
5153
}
5254
/*

js/setup/database.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,6 @@ function createSchema(runSQL = true, logFile = true){
339339

340340
if(logFile) {
341341
logToFile(sql, false)
342-
logToFile(sqlData, true)
343342
}
344343
pool.connect(function(err, client, done) {
345344
// - Create schema and tables

models/data/designer/object-data.js

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,49 @@ module.exports = [
244244
"comments"
245245
]
246246
}
247+
],
248+
"collections": [
249+
{
250+
"id": "wine_tasting",
251+
"title": 'Degustations',
252+
"table": "wine_tasting",
253+
"column": "wine_id",
254+
"object": "winetasting",
255+
"order": "desc",
256+
"fields": [
257+
{
258+
"id": "drink_date",
259+
"column": "drink_date",
260+
"type": "date",
261+
"label": "Date",
262+
"required": true
263+
},
264+
{
265+
"id": "robe",
266+
"column": "robe",
267+
"type": "text",
268+
"label": "Robe"
269+
},
270+
{
271+
"id": "nose",
272+
"column": "nose",
273+
"type": "text",
274+
"label": "Nose"
275+
},
276+
{
277+
"id": "taste",
278+
"column": "taste",
279+
"type": "text",
280+
"label": "Taste"
281+
},
282+
{
283+
"id": "notes",
284+
"column": "notes",
285+
"type": "textmultiline",
286+
"label": "Note"
287+
}
288+
]
289+
}
247290
]
248291
},
249292
{
@@ -315,6 +358,40 @@ module.exports = [
315358
"cover"
316359
]
317360
}
361+
],
362+
"collections": [
363+
{
364+
"id": "music_track",
365+
"label": "Tracks",
366+
"icon": "music.png",
367+
"table": "music_track",
368+
"column": "album_id",
369+
"orderBy": "name",
370+
"object": "track",
371+
"fields": [
372+
{
373+
"id": "name",
374+
"type": "text",
375+
"label": "Track",
376+
"column": "name",
377+
"inMany": true,
378+
},
379+
{
380+
"id": "genre",
381+
"type": "lov",
382+
"label": "Genre",
383+
"column": "genre_id",
384+
"lovTable": "music_genre",
385+
},
386+
{
387+
"id": "length",
388+
"type": "text",
389+
"label": "Length",
390+
"column": "length",
391+
"inMany": true
392+
},
393+
]
394+
}
318395
]
319396
},
320397
{
@@ -349,6 +426,31 @@ module.exports = [
349426
"photo"
350427
]
351428
}
429+
],
430+
"collections": [
431+
{
432+
"id": "music_album",
433+
"label": "Albums",
434+
"icon": "cd.png",
435+
"table": "music_album",
436+
"object": "album",
437+
"column": "artist_id",
438+
"orderBy": "title",
439+
"fields": [
440+
{
441+
"id": "title",
442+
"type": "text",
443+
"label": "Title",
444+
"column": "title",
445+
},
446+
{
447+
"id": "cover",
448+
"column": "cover",
449+
"type": "image",
450+
"label": "Cover",
451+
}
452+
]
453+
}
352454
]
353455
},
354456
{

models/designer/object.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,12 @@ module.exports = {
129129
"type": "json",
130130
"label": "Fields groups",
131131
"column": "groups"
132+
},
133+
{
134+
"id": "collections",
135+
"type": "json",
136+
"label": "Collections",
137+
"column": "collections"
132138
}
133139
],
134140
"collections": [

0 commit comments

Comments
 (0)