Example #1
0
exports.discussion = function (head, req) {
    start({code: 200, headers: {'Content-Type': 'text/html'}});

    var row, rows = [];
    while (row = getRow()) {
        rows.push(row);
    }
    var comments = _.filter(rows, function (r) {
        return r.doc.type === 'comment';
    });
    var doc_row = _.detect(rows, function (r) {
        return r.doc.type === 'page';
    });
    var empty_doc = !(doc_row);
    var doc = doc_row ? doc_row.doc: {};

    comments = _.map(comments, function (c) {
        c.doc.type = 'comment';
        c.doc.pptime = utils.prettyTime(c.doc.time);
        return c.doc;
    });
    // add edit events to comments
    if (doc && doc.history) {
        _.each(doc.history, function (h) {
            h.type = 'edit';
            h.is_edit = true;
            h.pptime = utils.prettyTime(h.time);
            comments.push(h);
        });
    }
    comments = _.sortBy(comments, function (c) {
        return c.time;
    });
    var participants = comments.map(function (c) {
        return c.user;
    });
    participants = _.uniq(participants);

    if (req.query.page && req.query.page[0] === '_') {
        return shows.not_found(null, req);
    }

    events.once('afterResponse', discussion_ui.bindDiscussion);

    return {
        title: doc.title || utils.idToTitle(req.query.page),
        content: templates.render('discussion.html', req, {
            doc: doc,
            page_title: doc.title || utils.idToTitle(req.query.page),
            page_subtitle: doc.subtitle,
            pageid: doc._id || req.query.page,
            participants: participants,
            comments: comments,
            current_tab: "discussion_page",
            logged_in: !!(req.userCtx.name),
            empty_doc: empty_doc
        })
    };
};
Example #2
0
exports.edit_page = function (head, req) {
    start({code: 200, headers: {'Content-Type': 'text/html'}});

    var row, rows = [];
    while (row = getRow()) {
        rows.push(row);
    }

    var doc = _.detect(rows, function (r) {
        return r.id === req.query.page;
    });
    var sidebar = _.detect(rows, function (r) {
        return r.id === 'sidebar';
    });
    if (doc) {
        doc = doc.doc;
    }
    if (sidebar) {
        sidebar = sidebar.doc;
    }
    var empty_doc = !(doc);
    if (!doc) {

        doc = utils.createPage(req.query.page, req.userCtx.name);
    }
    if (!sidebar) {
        sidebar = utils.createPage('sidebar', req.userCtx.name);
    }

    events.once('afterResponse', function (info, req, res) {
        editor_ui.bindEditor(doc, req)
    });
    return {
        title: doc.title,
        content: templates.render('edit_page.html', req, {
            doc: doc,
            pageid: doc._id,
            current_tab: "edit_page",
            sidebar: sidebar,
            logged_in: !!(req.userCtx.name),
            empty_doc: empty_doc
        })
    };
};
Example #3
0
 function(err, files) {
     // Confirm that layers have .prj files 
     // in line with the .shp and .dbf, etc files.
     var prj = _.detect(files, function(f) {
         return path.extname(f).toLowerCase() == '.prj';
     });
     if (prj) {
         prj = path.join(path.dirname(l.Datasource.file), prj);
         fs.readFile(prj, 'utf-8', this);
     } else {
         this(new Error('No projection found'));
     }
 },
Example #4
0
    return _.reduce(ids, function (errs, id, i) {

        var curr_errs = [];
        var nd = _.detect(nVal, function (v) {
            return v && v._id === id;
        });
        nd = nd || {_deleted: true};
        var od = _.detect(oVal, function (v) {
            return v && v._id === id;
        });
        var args = [nDoc, oDoc, nd, od, user];

        if (_.isFunction(perms)) {
            curr_errs = utils.getErrors(perms, args);
        }
        var fn;
        // on add
        if (nd && !od) {
            fn = perms.add;
        }
        // on remove
        else if (nd._deleted) {
            fn = perms.remove;
        }
        // on update
        else if (JSON.stringify(nd) !== JSON.stringify(od)) {
            fn = perms.update;
        }
        if (fn) {
            curr_errs = curr_errs.concat(utils.getErrors(fn, args));
        }
        curr_errs = _.map(curr_errs, function (e) {
            e.field = [i].concat(e.field || []);
            return e;
        });
        return errs.concat(curr_errs);

    }, []);
Example #5
0
Render.prototype._compileFile = function (fileName, callback) {
  var self = this,
      names = this._fileNames(fileName),
      found,
      compileFn;

  if (callback) {
    // Async version
    async.forEach(names, function (fileName, callback) {
      path.exists(fileName, function (exists) {
        if (!found && exists) { found = fileName; }
        callback();
      });
    }, function (err) {
      if (found) {
        compileFn = ViewCompileFns[self._fileTemplateType(found)];
        fs.readFile(found, function (err, data) {
          if (!err && data && compileFn) {
            callback(null, compileFn(data.toString()));
          } else {
            callback(null, function () { return data && data.toString(); });
          }
        });
      } else {
        callback('no file found ' + names.join(', '));
      }
    });
  } else {
  // Sync version
    found = _.detect(names, function (fileName) { return path.existsSync(fileName); });
    if (found) {
      compileFn = ViewCompileFns[self._fileTemplateType(found)];
      if (compileFn) {
        return compileFn(fs.readFileSync(found).toString());
      } else {
        var data = fs.readFileSync(found);
        return function () { return data && data.toString(); };
      }
    } else {
      return 'no file found ' + names.join(', ');
    }
  }
};
Example #6
0
function mergeDocs(oldDoc, newDoc){
  if(oldDoc.type !== "hourData" && oldDoc.type !== "user" && oldDoc.type !== "meta" && oldDoc.type !== "questions" && oldDoc.type !== "discussions"){
    var error = {"error":"cant merge documents with type "+oldDoc.type} ;
    console.log(error);
    throw error;
  }
  
  if(oldDoc.type === "hourData" ){
    oldDoc.weight += newDoc.weight;
    oldDoc.rt += newDoc.rt;
    oldDoc.rt += newDoc.rt;
    oldDoc.rtu = analyser.aggrigateAggrigatedData(oldDoc.rtu, newDoc.rtu);
    oldDoc.ht = analyser.aggrigateAggrigatedData(oldDoc.ht, newDoc.ht);
    oldDoc.un = analyser.aggrigateAggrigatedData(oldDoc.un, newDoc.un);
    oldDoc.geo = analyser.aggrigateGeo(oldDoc.geo, newDoc.geo);
    oldDoc.keywords = analyser.aggrigateAggrigatedData(oldDoc.keywords, newDoc.keywords);
    oldDoc.language = analyser.aggrigateAggrigatedData(oldDoc.language, newDoc.language);
    oldDoc.me = analyser.aggrigateAggrigatedData(oldDoc.me, newDoc.me);
    oldDoc.sentiment.positive += newDoc.sentiment.positive;
    oldDoc.sentiment.neutral += newDoc.sentiment.neutral;
    oldDoc.sentiment.negative += newDoc.sentiment.negative;
    oldDoc.urls = analyser.aggrigateAggrigatedData(oldDoc.urls, newDoc.urls);
    
    return oldDoc;
  }
  
  if(oldDoc.type === "user" ){
    newDoc._rev = oldDoc._rev;
    if(!(_.detect(oldDoc.archives, function(archive){
      return archive[0] === newDoc.archives[0][0];
    }))){
      newDoc.archives = newDoc.archives.concat(oldDoc.archives);
    }
    return newDoc;
  }
  if(oldDoc.type === "meta" || oldDoc.type === "questions"|| oldDoc.type === "discussions"){
    newDoc._rev = oldDoc._rev;
    
    return newDoc;
  }
}
Example #7
0
    fs.readdir(dir, function (err, files) {
        if (err) {
            return callback(err);
        }
        // make sure the files are sorted so the same filename will match
        // first reliably in the same set
        files = files.sort();

        var readme = _.detect(files, function (f) {
            return /^README$|^README\..*$/.test(f);
        });
        var filename = path.join(dir, readme);
        if (readme) {
            fs.stat(filename, function (err, stat) {
                if (err) {
                    return callback(err);
                }
                return callback(null, stat.isFile() ? filename: null);
            });
        }
        else {
            return callback(null, null);
        }
    });
Example #8
0
exports.page = function (head, req) {
    start({code: 200, headers: {'Content-Type': 'text/html'}});

    var row, rows = [];
    while (row = getRow()) {
        rows.push(row);
    }

    var doc = _.detect(rows, function (r) {
        return r.id === req.query.page;
    });
    var sidebar = _.detect(rows, function (r) {
        return r.id === 'sidebar';
    });
    if (doc) {
        doc = doc.doc;
    }
    if (sidebar) {
        sidebar = sidebar.doc;
    }
    var empty_doc = !(doc);

    if (!doc && req.query.page === 'index') {
        doc = utils.createPage('index', req.userCtx.name);
    }
    if (!sidebar) {
        sidebar = utils.createPage('sidebar', req.userCtx.name);
    }

    if (req.query.page === 'sidebar') {
        // don't show the sidebar twice
        sidebar = {
            body: '#### Viewing Sidebar\n\n' +
                  '[Back to home](' + duality_utils.getBaseURL() + ')'
        };
    }

    if (doc) {
        doc.body_html = showdown.convert(doc.body);
        return {
            title: doc.title,
            content: templates.render('page.html', req, {
                doc: doc,
                pageid: doc._id,
                current_tab: "page",
                sidebar: showdown.convert(sidebar.body),
                logged_in: !!(req.userCtx.name),
                empty_doc: empty_doc
            })
        };
    }
    else {
        // empty page
        if (req.query.page && req.query.page[0] === '_') {
            return shows.not_found(doc, req);
        }
        return {
            title: utils.idToTitle(req.query.page),
            content: templates.render('empty_page.html', req, {
                pageid: req.query.page,
                page_title: utils.idToTitle(req.query.page),
                current_tab: "page",
                sidebar: showdown.convert(sidebar.body),
                logged_in: !!(req.userCtx.name),
                empty_doc: empty_doc
            })
        };
    }
};
Example #9
0
exports.history_page = function (head, req) {
    start({code: 200, headers: {'Content-Type': 'text/html'}});

    var row, rows = [];
    while (row = getRow()) {
        rows.push(row);
    }

    var doc = _.detect(rows, function (r) {
        return r.id === req.query.page;
    });
    var sidebar = _.detect(rows, function (r) {
        return r.id === 'sidebar';
    });
    if (doc) {
        doc = doc.doc;
    }
    if (sidebar) {
        sidebar = sidebar.doc;
    }
    var empty_doc = !(doc);
    if (!doc && req.query.page === 'index') {
        doc = utils.createPage('index', req.userCtx.name);
    }
    if (!sidebar) {
        sidebar = utils.createPage('sidebar', req.userCtx.name);
    }

    if (!empty_doc) {
        var h;
        var h_id = req.query.change || doc.latest_change._id;
        h = _.detect(doc.history, function (h) {
            return h._id === h_id;
        });
        // used in template
        h.selected = true;
        // display newest first
        doc.history.reverse();

        doc.history = _.map(doc.history, function (h) {
            h.pptime = utils.prettyTime(h.time);
            return h;
        });

        // pass to bindHistoryViewer
        req.h = h;
        events.once('afterResponse', history_ui.bindHistoryViewer);

        return {
            title: doc.title,
            content: templates.render('history_page.html', req, {
                doc: doc,
                pageid: doc._id,
                current_tab: "history_page",
                logged_in: !!(req.userCtx.name),
                empty_doc: empty_doc
            })
        };
    }
    else {
        return {
            title: utils.idToTitle(req.query.page),
            content: templates.render('empty_history_page.html', req, {
                doc: doc,
                pageid: req.query.page,
                page_title: utils.idToTitle(req.query.page),
                current_tab: "history_page",
                logged_in: !!(req.userCtx.name),
                empty_doc: empty_doc
            })
        };
    }
};
Example #10
0
function mkv_check_has_avc(mkv, callback) {
    callback(mkv.tracks && _.detect(mkv.tracks, function (t) { 
	return t.type == 'video' && /AVC/.test(t.codec) ? t : null
    }) ? null : "can't find suitable AVC video track", mkv);
}