[410] | 1 | define([],function(){ |
---|
| 2 | return { |
---|
[414] | 3 | "_users/qed_admin": { |
---|
[410] | 4 | __configAction: "ignore", |
---|
[414] | 5 | _id: "org.couchdb.user:qed_admin", |
---|
| 6 | name: "qed_admin", |
---|
[410] | 7 | password: "Welkom01", |
---|
[414] | 8 | roles: [ "qed_admin" ], |
---|
[410] | 9 | type: "user" |
---|
[362] | 10 | }, |
---|
[414] | 11 | "qed/_security": { |
---|
[410] | 12 | __configAction: "ignore", |
---|
| 13 | admins: { |
---|
| 14 | names: [], |
---|
[414] | 15 | roles: ["qed_admin"] |
---|
[362] | 16 | }, |
---|
[410] | 17 | readers: { |
---|
| 18 | names: [], |
---|
[414] | 19 | roles: ["qed_user"] |
---|
[410] | 20 | } |
---|
| 21 | }, |
---|
[414] | 22 | "qed/_design/default": { |
---|
[410] | 23 | __configAction: "replace", |
---|
| 24 | _id: "_design/default", |
---|
| 25 | language: "javascript", |
---|
| 26 | validate_doc_update: function(newDoc, oldDoc, userCtx, secObj) { |
---|
| 27 | if ( oldDoc && oldDoc.publicationDate ) { throw({forbidden:'Published documents cannot be modified.'}); } |
---|
| 28 | if ( !newDoc._deleted && !newDoc.type ) { throw({forbidden:'Documents must have a type field.'}); } |
---|
[362] | 29 | }, |
---|
[410] | 30 | views: { |
---|
| 31 | by_type: { |
---|
| 32 | map: function(doc){ |
---|
| 33 | emit(doc.type, doc); |
---|
| 34 | } |
---|
| 35 | } |
---|
| 36 | } |
---|
| 37 | }, |
---|
[414] | 38 | "qed/_design/questions": { |
---|
[410] | 39 | __configAction: "replace", |
---|
| 40 | _id: "_design/questions", |
---|
| 41 | language: "javascript", |
---|
| 42 | validate_doc_update: function(newDoc, oldDoc, userCtx, secObj) { |
---|
| 43 | if( newDoc._deleted || newDoc.type!=='Question' ){ return; } |
---|
| 44 | if( !newDoc.code ){ throw({forbidden:'Question must have a code field.'});} |
---|
[375] | 45 | }, |
---|
[410] | 46 | views: { |
---|
| 47 | all: { |
---|
| 48 | map: function(doc){ |
---|
| 49 | if ( doc.type !== 'Question' ) { return; } |
---|
| 50 | if ( doc.categories && doc.categories.length > 0 ) { |
---|
| 51 | for ( var i = 0; i < doc.categories.length; i++ ) { |
---|
| 52 | emit([doc.categories[i],doc.topic||null],1); |
---|
| 53 | } |
---|
| 54 | } else { |
---|
| 55 | emit([null,null],1); |
---|
| 56 | } |
---|
| 57 | }, |
---|
| 58 | reduce: function(keys,values){ return sum(values); } |
---|
| 59 | }, |
---|
| 60 | published: { |
---|
| 61 | map: function(doc){ |
---|
| 62 | if ( doc.type!=='Question' || !doc.publicationDate ) { return; } |
---|
| 63 | if ( doc.categories && doc.categories.length > 0 ) { |
---|
| 64 | for ( var i = 0; i < doc.categories.length; i++ ) { |
---|
| 65 | emit([doc.categories[i],doc.topic||null],1); |
---|
| 66 | } |
---|
| 67 | } else { |
---|
| 68 | emit([null,null],1); |
---|
| 69 | } |
---|
| 70 | }, |
---|
| 71 | reduce: function(keys,values){ return sum(values); } |
---|
| 72 | }, |
---|
| 73 | all_topics: { |
---|
| 74 | map: function(doc){ |
---|
| 75 | if( doc.type !== 'Question' ){ return; } |
---|
| 76 | emit(doc.topic); |
---|
[414] | 77 | }, |
---|
| 78 | reduce: function(key, values, rereduce) { return null; } |
---|
[410] | 79 | }, |
---|
| 80 | published_topics: { |
---|
| 81 | map: function(doc){ |
---|
| 82 | if ( doc.type !== 'Question' || !doc.publicationDate ) { return; } |
---|
| 83 | emit(doc.topic); |
---|
[414] | 84 | }, |
---|
| 85 | reduce: function(key, values, rereduce) { return null; } |
---|
[410] | 86 | } |
---|
[362] | 87 | } |
---|
[410] | 88 | }, |
---|
[414] | 89 | "qed/_design/surveys": { |
---|
[410] | 90 | __configAction: "replace", |
---|
| 91 | _id: "_design/surveys", |
---|
| 92 | language: "javascript", |
---|
| 93 | views: { |
---|
| 94 | drafts: { |
---|
| 95 | map: function(doc){ |
---|
| 96 | if ( doc.type !== 'Survey' || doc.publicationDate ) { return; } |
---|
| 97 | emit(doc._id,doc); |
---|
| 98 | } |
---|
| 99 | }, |
---|
| 100 | published: { |
---|
| 101 | map: function(doc){ |
---|
| 102 | if ( doc.type !== 'Survey' || !doc.publicationDate ) { return; } |
---|
| 103 | emit(doc._id,doc); |
---|
| 104 | } |
---|
| 105 | } |
---|
| 106 | } |
---|
[362] | 107 | } |
---|
[410] | 108 | }; |
---|
[414] | 109 | }); |
---|