[455] | 1 | module.exports = { |
---|
[464] | 2 | |
---|
[519] | 3 | "schemaInfo": { |
---|
| 4 | _id: "schemaInfo", |
---|
[523] | 5 | version: "4", |
---|
| 6 | viewsVersion: "1" |
---|
[480] | 7 | }, |
---|
| 8 | |
---|
[519] | 9 | "_design/protectPublished": { |
---|
[455] | 10 | __configAction: "replace", |
---|
| 11 | language: "javascript", |
---|
| 12 | validate_doc_update: function(newDoc, oldDoc, userCtx, secObj) { |
---|
[487] | 13 | if ( oldDoc && oldDoc.publicationDate ) { |
---|
| 14 | throw({forbidden:'Published documents cannot be modified.'}); |
---|
| 15 | } |
---|
[516] | 16 | } |
---|
| 17 | }, |
---|
| 18 | |
---|
[519] | 19 | "_design/default": { |
---|
[516] | 20 | __configAction: "replace", |
---|
| 21 | language: "javascript", |
---|
[455] | 22 | views: { |
---|
| 23 | by_type: { |
---|
| 24 | map: function(doc){ |
---|
| 25 | emit(doc.type, doc); |
---|
| 26 | } |
---|
[477] | 27 | }, |
---|
| 28 | typeless: { |
---|
| 29 | map: function(doc){ |
---|
| 30 | if ( !doc.type ) { |
---|
| 31 | emit(doc._id, doc); |
---|
| 32 | } |
---|
| 33 | } |
---|
[455] | 34 | } |
---|
| 35 | } |
---|
| 36 | }, |
---|
[464] | 37 | |
---|
[519] | 38 | "_design/questions": { |
---|
[455] | 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++ ) { |
---|
[487] | 47 | emit([doc.categories[i],doc.topic||"(default)"],1); |
---|
[455] | 48 | } |
---|
| 49 | } else { |
---|
[487] | 50 | emit(["(default)","(default)"],1); |
---|
[455] | 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++ ) { |
---|
[487] | 60 | emit([doc.categories[i],doc.topic||"(default)"],1); |
---|
[455] | 61 | } |
---|
| 62 | } else { |
---|
[487] | 63 | emit(["(default)","(default)"],1); |
---|
[455] | 64 | } |
---|
| 65 | }, |
---|
| 66 | reduce: function(keys,values){ return sum(values); } |
---|
| 67 | }, |
---|
| 68 | all_topics: { |
---|
| 69 | map: function(doc){ |
---|
| 70 | if( doc.type !== 'Question' ){ return; } |
---|
[487] | 71 | emit(doc.topic||"(default)",1); |
---|
[455] | 72 | }, |
---|
[487] | 73 | reduce: function(key, values, rereduce) { return sum(values); } |
---|
[455] | 74 | }, |
---|
| 75 | published_topics: { |
---|
| 76 | map: function(doc){ |
---|
| 77 | if ( doc.type !== 'Question' || !doc.publicationDate ) { return; } |
---|
[487] | 78 | emit(doc.topic||"(default)",1); |
---|
[455] | 79 | }, |
---|
[487] | 80 | reduce: function(key, values, rereduce) { return sum(values); } |
---|
| 81 | }, |
---|
[501] | 82 | all_by_code: { |
---|
[487] | 83 | map: function(doc){ |
---|
| 84 | if ( doc.type !== 'Question' ) { return; } |
---|
| 85 | emit(doc.code,doc); |
---|
| 86 | } |
---|
[501] | 87 | }, |
---|
| 88 | published_by_code: { |
---|
| 89 | map: function(doc){ |
---|
| 90 | if ( doc.type !== 'Question' || !doc.publicationDate ) { return; } |
---|
| 91 | emit(doc.code,doc); |
---|
| 92 | } |
---|
[455] | 93 | } |
---|
| 94 | } |
---|
| 95 | }, |
---|
[464] | 96 | |
---|
[519] | 97 | "_design/surveys": { |
---|
[455] | 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 | }, |
---|
[464] | 115 | |
---|
[519] | 116 | "_design/surveyRuns": { |
---|
[492] | 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 | |
---|
[519] | 131 | "_design/responses": { |
---|
[455] | 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 | } |
---|
[464] | 143 | |
---|
[455] | 144 | }; |
---|