source: Dev/trunk/src/server/config/couchdb-design-docs.js @ 519

Last change on this file since 519 was 519, checked in by hendrikvanantwerpen, 11 years ago
  • Support different environments with QED_ENV. If dev, run against qed-dev database, if production, run against qed database. The UI indicates if we are running in anything but production mode.
  • Return undefined if we allow page leaves, because null is treated as a value.
  • Changed format of design docs, so it can work for different databases.
  • Use correct design documents in configCouch, so server now actually updates them when it starts.
File size: 4.5 KB
Line 
1module.exports = {
2
3    "schemaInfo": {
4        _id: "schemaInfo",
5        version: "4"
6    },
7
8    "_design/protectPublished": {
9        __configAction: "replace",
10        language: "javascript",
11        validate_doc_update: function(newDoc, oldDoc, userCtx, secObj) {
12            if ( oldDoc && oldDoc.publicationDate ) {
13                throw({forbidden:'Published documents cannot be modified.'});
14            }
15        }
16    },
17
18    "_design/default": {
19        __configAction: "replace",
20        language: "javascript",
21        views: {
22            by_type: {
23                map: function(doc){
24                    emit(doc.type, doc);
25                }
26            },
27            typeless: {
28                map: function(doc){
29                    if ( !doc.type ) {
30                        emit(doc._id, doc);
31                    }
32                }
33            }
34        }
35    },
36
37    "_design/questions": {
38        __configAction: "replace",
39        language: "javascript",
40        views: {
41            all: {
42                map: function(doc){
43                    if ( doc.type !== 'Question' ) { return; }
44                    if ( doc.categories && doc.categories.length > 0 ) {
45                        for ( var i = 0; i < doc.categories.length; i++ ) {
46                            emit([doc.categories[i],doc.topic||"(default)"],1);
47                        }
48                    } else {
49                        emit(["(default)","(default)"],1);
50                    }
51                },
52                reduce: function(keys,values){ return sum(values); }
53            },
54            published: {
55                map: function(doc){
56                    if ( doc.type!=='Question' || !doc.publicationDate ) { return; }
57                    if ( doc.categories && doc.categories.length > 0 ) {
58                        for ( var i = 0; i < doc.categories.length; i++ ) {
59                            emit([doc.categories[i],doc.topic||"(default)"],1);
60                        }
61                    } else {
62                        emit(["(default)","(default)"],1);
63                    }
64                },
65                reduce: function(keys,values){ return sum(values); }
66            },
67            all_topics: {
68                map: function(doc){
69                    if( doc.type !== 'Question' ){ return; }
70                    emit(doc.topic||"(default)",1);
71                },
72                reduce: function(key, values, rereduce) { return sum(values); }
73            },
74            published_topics: {
75                map: function(doc){
76                    if ( doc.type !== 'Question' || !doc.publicationDate ) { return; }
77                    emit(doc.topic||"(default)",1);
78                },
79                reduce: function(key, values, rereduce) { return sum(values); }
80            },
81            all_by_code: {
82                map: function(doc){
83                    if ( doc.type !== 'Question' ) { return; }
84                    emit(doc.code,doc);
85                }
86            },
87            published_by_code: {
88                map: function(doc){
89                    if ( doc.type !== 'Question' || !doc.publicationDate ) { return; }
90                    emit(doc.code,doc);
91                }
92            }
93        }
94    },
95
96    "_design/surveys": {
97        __configAction: "replace",
98        language: "javascript",
99        views: {
100            drafts: {
101                map: function(doc){
102                    if ( doc.type !== 'Survey' || doc.publicationDate ) { return; }
103                    emit(doc._id,doc);
104                }
105            },
106            published: {
107                map: function(doc){
108                    if ( doc.type !== 'Survey' || !doc.publicationDate ) { return; }
109                    emit(doc._id,doc);
110                }
111            }
112        }
113    },
114
115    "_design/surveyRuns": {
116        __configAction: "replace",
117        language: "javascript",
118        views: {
119            by_dates: {
120                map: function(doc){
121                    if ( doc.type !== 'SurveyRun' ) { return; }
122                    var startDate = doc.startDate || "";
123                    var endDate = doc.endDate || {};
124                    emit([startDate,endDate,doc.liveName||null],doc);
125                }
126            }
127        }
128    },
129
130    "_design/responses": {
131        __configAction: "replace",
132        language: "javascript",
133        views: {
134            by_surveyrun: {
135                map: function(doc){
136                    if ( doc.type !== 'Response' ) { return; }
137                    emit(doc.surveyRunId, doc);
138                }
139            }
140        }
141    }
142
143};
Note: See TracBrowser for help on using the repository browser.