-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathg_conditional_fields.js
More file actions
112 lines (105 loc) · 4.19 KB
/
g_conditional_fields.js
File metadata and controls
112 lines (105 loc) · 4.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import mongoose from 'mongoose';
var Schema = mongoose.Schema;
var GSchema = new Schema({
surname: {type: String, list: {}, index: true},
forename: {type: String, list: true, index: true},
sex: {type: String, enum: ['F', 'M']},
accepted: {type: Boolean, form: {help: 'When someone is accepted additional fields appear'}},
startDate: {type: Date, form: {showWhen: {lhs: '$accepted', comp: 'eq', rhs: true}}},
startingPosition: {type: String, form: {showWhen: {lhs: '$accepted', comp: 'eq', rhs: true}}},
bribeAmount: {type: Number, form: {help: 'Try a number between 10 and 200 to see an angular expression used in a conditional'}},
loggedInBribeBook: {type: Boolean, form: {showWhen: 'record.bribeAmount >= 10 && record.bribeAmount <= 200'}}
});
var G;
try {
G = mongoose.model('G');
} catch (e) {
G = mongoose.model('G', GSchema);
}
GSchema.statics.report = function (report) {
var reportSchema = '',
fullDescription = {field: '_id', translations: [ {value: 'M', display: 'Male'}, {value: 'F', display: 'Female'}, {'value': '', 'display': 'Unspecified'}]};
switch (report) {
case 'breakdownbysex' :
reportSchema = {
pipeline: [
{$group: {_id: '$sex', count: {'$sum': 1}}},
{$sort: {_id: 1}}
],
title: 'Numbers of Applicants By Sex',
columnDefs: [
{field: '_id', displayName: 'Sex', totalsRow: 'Total', 'width': '160px'},
{field: 'count', displayName: 'No of Applicants', totalsRow: '$SUM', 'width': '160px', 'cellFilter': 'number', 'align': 'right'}
],
columnTranslations: [fullDescription]
};
break;
case 'totalforonesex' :
reportSchema = {
'pipeline': [
{'$match': {'sex': '(sex)'}},
{'$group': {'_id': '$sex', 'count': {'$sum': 1}}}
],
'title': 'Numbers of Applicants By Sex',
'columnDefs': [
{'field': '_id', 'displayName': 'Sex', 'width': '200'},
{'field': 'count', 'displayName': 'No of Applicants', 'align': 'right', 'width': '200'}
],
'columnTranslations': [fullDescription],
'params': {'sex': {value: 'M', type: 'select', enum: ['Male', 'Female'], required: true, conversionExpression: 'param[0]'}}
};
break;
case 'totals' :
reportSchema = {
'pipeline': [
{'$project': {'surname': 1, 'forename': 1, 'bribeAmount': 1, '_id': 1}}
],
'title': 'A report with totals and drilldown',
drilldown: 'g_conditional_fields/|_id|/edit',
'columnDefs': [
{'field': 'surname', 'displayName': 'Surname', 'width': '200', totalsRow: 'Total'},
{'field': 'forename', 'displayName': 'Forename', 'width': 200},
{'field': 'bribeAmount', 'displayName': 'Bribe', 'align': 'right', 'width': '200', totalsRow: '$SUM', 'cellFilter': 'currency'}
]
};
break;
case 'functiondemo' :
reportSchema = {
'pipeline': [
{'$group': {'_id': '$sex', 'count': {'$sum': 1}, 'functionResult': {'$sum': 1}}},
{'$sort': {'_id':1}}
],
'title': 'Numbers of Applicants By Sex',
'columnDefs': [
{'field': '_id', 'displayName': 'Sex', 'width': '200'},
{'field': 'count', 'displayName': 'No of Applicants', 'align': 'right', 'width': '200'},
{'field': 'functionResult', 'displayName': 'Applicants + 10', 'align': 'right', 'width': '200'}
],
'columnTranslations': [fullDescription,
{field: 'functionResult',
fn: function (row, cb) {
row.functionResult = row.functionResult + 10;
cb();
}}
]
};
break;
case 'selectbynumber' :
reportSchema = {
'pipeline': [
{'$group': {'_id': '$sex', 'count': {'$sum': 1}}},
{'$match': {'count': '(number_param)'}}
],
'params': {'number_param': {value: 11, type: 'number', required: true}}
};
break;
}
return reportSchema;
};
export default {
model: G,
searchImportance: 1,
searchOrder: {surname: 1},
listOrder: {surname: 1}
};
// "pipeline":[{"$group":{"_id":"$sex","count":{"$sum":1}}},{"$match":{"count":"(number_param)"}}],"params":{"number_param":11}