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

Last change on this file since 523 was 523, checked in by hendrikvanantwerpen, 11 years ago
  • Added version for views.
  • Don't automatically upgrade views when starting app, this needs to be done manually.
File size: 4.5 KB
Line 
1module.exports = {
2
3    "schemaInfo": {
4        _id: "schemaInfo",
5        version: "4",
6        viewsVersion: "1"
7    },
8
9    "_design/protectPublished": {
10        __configAction: "replace",
11        language: "javascript",
12        validate_doc_update: function(newDoc, oldDoc, userCtx, secObj) {
13            if ( oldDoc && oldDoc.publicationDate ) {
14                throw({forbidden:'Published documents cannot be modified.'});
15            }
16        }
17    },
18
19    "_design/default": {
20        __configAction: "replace",
21        language: "javascript",
22        views: {
23            by_type: {
24                map: function(doc){
25                    emit(doc.type, doc);
26                }
27            },
28            typeless: {
29                map: function(doc){
30                    if ( !doc.type ) {
31                        emit(doc._id, doc);
32                    }
33                }
34            }
35        }
36    },
37
38    "_design/questions": {
39        __configAction: "replace",
40        language: "javascript",
41        views: {
42            all: {
43                map: function(doc){
44                    if ( doc.type !== 'Question' ) { return; }
45                    if ( doc.categories && doc.categories.length > 0 ) {
46                        for ( var i = 0; i < doc.categories.length; i++ ) {
47                            emit([doc.categories[i],doc.topic||"(default)"],1);
48                        }
49                    } else {
50                        emit(["(default)","(default)"],1);
51                    }
52                },
53                reduce: function(keys,values){ return sum(values); }
54            },
55            published: {
56                map: function(doc){
57                    if ( doc.type!=='Question' || !doc.publicationDate ) { return; }
58                    if ( doc.categories && doc.categories.length > 0 ) {
59                        for ( var i = 0; i < doc.categories.length; i++ ) {
60                            emit([doc.categories[i],doc.topic||"(default)"],1);
61                        }
62                    } else {
63                        emit(["(default)","(default)"],1);
64                    }
65                },
66                reduce: function(keys,values){ return sum(values); }
67            },
68            all_topics: {
69                map: function(doc){
70                    if( doc.type !== 'Question' ){ return; }
71                    emit(doc.topic||"(default)",1);
72                },
73                reduce: function(key, values, rereduce) { return sum(values); }
74            },
75            published_topics: {
76                map: function(doc){
77                    if ( doc.type !== 'Question' || !doc.publicationDate ) { return; }
78                    emit(doc.topic||"(default)",1);
79                },
80                reduce: function(key, values, rereduce) { return sum(values); }
81            },
82            all_by_code: {
83                map: function(doc){
84                    if ( doc.type !== 'Question' ) { return; }
85                    emit(doc.code,doc);
86                }
87            },
88            published_by_code: {
89                map: function(doc){
90                    if ( doc.type !== 'Question' || !doc.publicationDate ) { return; }
91                    emit(doc.code,doc);
92                }
93            }
94        }
95    },
96
97    "_design/surveys": {
98        __configAction: "replace",
99        language: "javascript",
100        views: {
101            drafts: {
102                map: function(doc){
103                    if ( doc.type !== 'Survey' || doc.publicationDate ) { return; }
104                    emit(doc._id,doc);
105                }
106            },
107            published: {
108                map: function(doc){
109                    if ( doc.type !== 'Survey' || !doc.publicationDate ) { return; }
110                    emit(doc._id,doc);
111                }
112            }
113        }
114    },
115
116    "_design/surveyRuns": {
117        __configAction: "replace",
118        language: "javascript",
119        views: {
120            by_dates: {
121                map: function(doc){
122                    if ( doc.type !== 'SurveyRun' ) { return; }
123                    var startDate = doc.startDate || "";
124                    var endDate = doc.endDate || {};
125                    emit([startDate,endDate,doc.liveName||null],doc);
126                }
127            }
128        }
129    },
130
131    "_design/responses": {
132        __configAction: "replace",
133        language: "javascript",
134        views: {
135            by_surveyrun: {
136                map: function(doc){
137                    if ( doc.type !== 'Response' ) { return; }
138                    emit(doc.surveyRunId, doc);
139                }
140            }
141        }
142    }
143
144};
Note: See TracBrowser for help on using the repository browser.