Ignore:
Timestamp:
03/19/14 21:33:13 (11 years ago)
Author:
hendrikvanantwerpen
Message:
  • Allow empty subcodes.
  • Use HTTPResult exclusively on server (no more q).
  • Set readonly & disabled on ourselves as well in _ComplexValueMixin
  • Split server into several modules.
  • Check codes on the variable level, not question level.
  • We can add modules in design documents now.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Dev/trunk/src/server/config/couchdb-design-docs.js

    r523 r525  
     1var fs = require('fs')
     2  , path = require('path')
     3  ;
     4
     5function readModule(name) {
     6    var filename;
     7    if ( name.indexOf('.') === 0 ) {
     8        filename = path.join(path.dirname(module.filename),name+'.js');
     9    } else {
     10        var dirname = path.join(path.dirname(module.filename),
     11                                '../../node_modules',name);
     12        filename = path.join(dirname,name+'.js');
     13        var pkgfile = path.join(dirname,'package.json');
     14        if ( fs.exists(pkgfile) ) {
     15            var pkg = require(pkgfile);
     16            if ( pkg.main ) {
     17                filename = path.join(dirname,pkg.main);
     18            }
     19        }
     20    }
     21    var src = fs.readFileSync(filename, 'utf8');
     22    src = src.replace(/require\s*\(\s*(['\"])([^'"]*)(['\"])\s*\)/g,
     23                      'require($1views/lib/$2$3)');
     24    return src;
     25}
     26
    127module.exports = {
    228
     
    80106                reduce: function(key, values, rereduce) { return sum(values); }
    81107            },
     108            all_variables: {
     109                map: function(doc) {
     110                    if ( doc.type !== 'Question' ) { return; }
     111                    var _ = require('views/lib/underscore');
     112                    var objF = require('views/lib/object');
     113                    _.chain(objF.collectFields('subcode',doc.content))
     114                    .map(function(subcode){
     115                        return doc.code+subcode;
     116                    })
     117                    .each(function(variable){
     118                        emit(variable,doc._id);
     119                    });
     120                }
     121            },
     122            published_variables: {
     123                map: function(doc) {
     124                    if ( doc.type !== 'Question' || !doc.publicationDate ) { return; }
     125                    var _ = require('views/lib/underscore');
     126                    var objF = require('views/lib/object');
     127                    _.chain(objF.collectFields('subcode',doc.content))
     128                    .map(function(subcode){
     129                        return doc.code+subcode;
     130                    })
     131                    .each(function(variable){
     132                        emit(variable,doc._id);
     133                    });
     134                }
     135            },
    82136            all_by_code: {
    83137                map: function(doc){
     
    91145                    emit(doc.code,doc);
    92146                }
     147            },
     148            lib: {
     149                underscore: readModule('underscore'),
     150                object: readModule('../util/object')
    93151            }
    94152        }
Note: See TracChangeset for help on using the changeset viewer.