Skip to content

Commit f340431

Browse files
committed
Small fixes.
1 parent 720481a commit f340431

5 files changed

Lines changed: 43 additions & 32 deletions

File tree

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ Models contain the name of the driving table and the list of fields/columns pres
129129
| fields | Array of fields. |
130130
| titleField | Field id for the column value used as record title. |
131131
| searchFields | Array of field ids for fields used to perform searches. |
132+
| noCharts | No Charts or Dashboard views. |
133+
| noStats | No Stats on the object. |
132134

133135
<a name="Field"></a>
134136
### Field
@@ -148,7 +150,8 @@ Models contain the name of the driving table and the list of fields/columns pres
148150
| max, min | Maximum/Minimum value allowed (only applies to numeric fields). |
149151
| maxLength, minLength | Maximum/Minimum length allowed (only applies to text fields).|
150152
| unique | Values must be unique (not implemented yet). |
151-
| noCharts | Forbids charts on the field. |
153+
| noCharts | Exclude field from charts. |
154+
| noStats | Exclude field from Stats. |
152155
| deleteTrigger | Deleting records in the lovTable will trigger a cascade delete (this property is only used while creating the database). |
153156

154157

js/charts.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ let sql,
4343
if(m && fid){
4444
let f = m.fieldsH[fid];
4545
if(f){
46-
if(dico.fieldInCharts){
46+
if(dico.fieldInCharts(f)){
4747
const col = '"'+f.column+'"',
4848
sqlFrom = ' FROM '+m.schemaTable+' AS t1';
4949

js/stats.js

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const fnPrep = fields => data => {
5252
pStats.nb_comments = data.nb_comments
5353
}
5454
fields.forEach(f => {
55-
if(dico.fieldIsNumeric(f)){
55+
if(dico.fieldIsNumeric(f) && !f.noStats){
5656
let item = {
5757
min: data[f.id+'_min'],
5858
max: data[f.id+'_max'],
@@ -77,37 +77,43 @@ function numbers(req, res) {
7777
m = dico.getModel(mid)
7878

7979
if(m){
80-
let sql = 'SELECT count(*)::integer AS count';
81-
const sqlFROM = ' FROM '+m.schemaTable;
80+
if(!m.noStats){
81+
let sql = 'SELECT count(*)::integer AS count';
82+
const sqlFROM = ' FROM '+m.schemaTable;
8283

83-
m.fields.forEach(function(f){
84-
if(dico.fieldIsNumeric(f)){
85-
if(!dico.fieldIsDateOrTime(f)){
86-
sql += sqlAggregate('avg', f)
84+
m.fields.forEach(function(f){
85+
if(dico.fieldIsNumeric(f) && !f.noStats){
86+
if(!dico.fieldIsDateOrTime(f)){
87+
sql += sqlAggregate('avg', f)
88+
}
89+
if(f.type===ft.money || f.type===ft.int){
90+
sql += sqlAggregate('sum', f)
91+
}
92+
sql += sqlAggregate('min', f)
93+
sql += sqlAggregate('max', f)
94+
//}else if(f.type===ft.lov){
95+
// sql += ',(select id, count("'+f.column+'")::integer FROM '+m.schemaTable+' GROUP BY id LIMIT 3)'
8796
}
88-
if(f.type===ft.money || f.type===ft.int){
89-
sql += sqlAggregate('sum', f)
90-
}
91-
sql += sqlAggregate('min', f)
92-
sql += sqlAggregate('max', f)
97+
})
98+
if(config.wTimestamp){
99+
// - last update
100+
sql += ', max('+config.updatedDateColumn+') AS u_date_max' +
101+
// - number of insert & updates this week
102+
', (SELECT count('+m.pKey+')::integer '+sqlFROM+
103+
' WHERE '+config.updatedDateColumn+' > NOW() - interval \'7 days\')'+
104+
' AS u_date_week_count' +
105+
// - first insert
106+
', min('+config.createdDateColumn+') AS c_date_min'
93107
}
94-
})
95-
if(config.wTimestamp){
96-
// - last update
97-
sql += ', max('+config.updatedDateColumn+') AS u_date_max' +
98-
// - number of insert & updates this week
99-
', (SELECT count('+m.pKey+')::integer '+sqlFROM+
100-
' WHERE '+config.updatedDateColumn+' > NOW() - interval \'7 days\')'+
101-
' AS u_date_week_count' +
102-
// - first insert
103-
', min('+config.createdDateColumn+') AS c_date_min'
104-
}
105-
if(config.wComments){
106-
// - number of comments
107-
sql += ', sum(nb_comments::integer)::integer AS nb_comments'
108+
if(config.wComments){
109+
// - number of comments
110+
sql += ', sum(nb_comments::integer)::integer AS nb_comments'
111+
}
112+
sql += sqlFROM
113+
query.runQuery(res, sql, [], true, null, null, fnPrep(m.fields));
114+
}else{
115+
errors.badRequest(res, 'noStats set on model "'+mid+'".')
108116
}
109-
sql += sqlFROM
110-
query.runQuery(res, sql, [], true, null, null, fnPrep(m.fields));
111117
}else{
112118
errors.badRequest(res, 'Invalid model: "'+mid+'".')
113119
}

js/utils/errors.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ function badRequest(res, msg, errorCode = 400) {
55

66
logger.logError(msg)
77
res.statusMessage = errorMsg
8-
res.status(errorCode).end();
9-
return res
8+
res.status(errorCode)//.end();
9+
return res.json({error: errorMsg})
1010
}
1111

1212
module.exports = {

models/data/music/album-data.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ module.exports = [
2424
id: 4,
2525
title: "Lovers Rock",
2626
artist: 3,
27+
url: "https://smile.amazon.com/Lovers-Rock-Sade/dp/B00JRBGE62",
2728
cover: "music/sade-loversrock.jpg"
2829
},
2930
{
@@ -37,6 +38,7 @@ module.exports = [
3738
id: 6,
3839
title: "18",
3940
artist: 4,
41+
url: "https://smile.amazon.com/18-Moby/dp/B000063S6Z",
4042
cover: "music/moby-18.jpg"
4143
},
4244
{

0 commit comments

Comments
 (0)