Esempio n. 1
0
    provides('html', function(){
        var Mustache = require('views/lib/mustache');
        var util = require('views/lib/util');

        var username = req.userCtx.name;

        var querySkip = parseInt((req.query.skip || 0), 10);
        var skip = querySkip + parseInt(this.templates.partials.conf_perpage, 10);
        var data = {
            title: req.query.id + '\'s comments',
            username: username,
            login: !(username),
            skip: skip,
            userid: req.query.id,
            comments: []
        };
        var row;
        while(row = getRow()) {
            var comment = row.value.comment;
            if(comment.author === username) {
                comment.owner = true;
            }
            // indent
            comment.indent = (row.key.length - 2) * 40;
            comment.doc_id = row.value._id;
            comment.pretty_date = util.timeDifference(new Date(), new Date(comment.comment_id), this.templates.partials);

            data.comments.push(comment);
        }
        var html = Mustache.to_html(this.templates.threads, data, this.templates.partials);
        return html;
    });
Esempio n. 2
0
    provides('html', function(){
        var Mustache = require('views/lib/mustache');

        var username = req.userCtx.name;
        var user = {};
        user.name = req.query.id;

        var data = {
            title: user.name,
            username: username,
            login: !(username),
            myprofile: user.name === username,
            user: user
        };
        var row = getRow();
        if(row) {
            var value = row.value;

            user.karma = value.totalPoints;
            user.about = value.about;
            user.about_html = value.about_html;

            data.user = user;
        }

        var html = Mustache.to_html(this.templates.user, data, this.templates.partials);
        return html;
    });
Esempio n. 3
0
ddoc.shows.about = function(doc, req) {
    var Mustache = require('views/lib/mustache');

    var data = {
        title: 'About',
        username: req.userCtx.name,
        login: !(req.userCtx.name)
    };

    var html = Mustache.to_html(this.templates.about, data, this.templates.partials);
    return html;
}
Esempio n. 4
0
    provides('html', function(){
        var Mustache = require('views/lib/mustache');
        var util = require('views/lib/util');
        
        var username = req.userCtx.name;

        var value = getRow()['value'];
        var currDate = new Date();
        
        var doc = value.doc;
        doc.domain = value.domain;

        var point = this.templates.partials.conf_point;
        var points = this.templates.partials.conf_points;

        if(value.points == 1) {
            doc.points = value.points + ' ' + point;
        } else {
            doc.points = value.points + ' ' + points;
        }
        doc.numcomments = (value.numcomments == 1 ? 
                            value.numcomments + ' ' + this.templates.partials.conf_comment :
                            value.numcomments + ' ' + this.templates.partials.conf_comments);

        doc.pretty_date = util.timeDifference(currDate, new Date(doc.created_at), this.templates.partials);

        // check if we upvoted already
        if(util.inArray(username, doc.voted)) {
            doc.upvoted = true;
        }

        for(var i in value.comments) {
            var comment = value.comments[i];
            if(util.inArray(username, comment.voted)) {
                comment.upvoted = true;
            } else {
                comment.upvoted = false;
            }

            if(comment.author === username) {
                comment.owner = true;
            } else {
                comment.owner = false;
            }
            comment.pretty_date = util.timeDifference(currDate, new Date(comment.comment_id), this.templates.partials);

            if(comment.points == 1) {
                comment.points += ' ' + point;
            } else {
                comment.points += ' ' + points;
            }
        }

        var data = {
            title: doc.title,
            username: req.userCtx.name,
            login: !(req.userCtx.name),
            item: doc,
            owner: doc.author == username,
            comments: value.comments
        };

        var html = Mustache.to_html(this.templates.item, data, this.templates.partials);
        return html;
    });
Esempio n. 5
0
    provides('html', function(){
        var row,
            Mustache = require('views/lib/mustache');
        var util = require('views/lib/util');

        var username = req.userCtx.name;

        var querySkip = parseInt((req.query.skip || 0), 10);
        var skip = querySkip + parseInt(this.templates.partials.conf_perpage, 10);

        var data = {
            title: '',
            username: username,
            login: !(username),
            skip: skip,
            rows: []
        };

        var lastPath = req.path[req.path.length - 1];
        var userId = req.query.id;

        if(lastPath === 'submitted') {
            data.title = userId + "'s submissions";
        } else if (lastPath === 'newest') {
            data.title = 'New Links';
        } else if (lastPath === 'saved') {
            data.title = 'Saved Links';
            if(userId !== username) {
                return "Can't display that.";
            }
        }

        var point = this.templates.partials.conf_point;
        var points = this.templates.partials.conf_points;
        var conf_comment = this.templates.partials.conf_comment;
        var conf_comments = this.templates.partials.conf_comments;

        var counter = 0;
        while(row = getRow()) {
            var doc = row.value.doc;
            doc.domain = row.value.domain;

            if(row.value.points == 1) {
                doc.points = row.value.points + ' ' + point;
            } else {
                doc.points = row.value.points + ' ' + points;
            }

            doc.numcomments = (row.value.numcomments == 1 ? row.value.numcomments + ' ' + conf_comment : row.value.numcomments + ' ' + conf_comments);

            doc.counter = (++counter) + querySkip;
            doc.pretty_date = util.timeDifference(new Date(), new Date(doc.created_at), this.templates.partials);

            doc.owner = (doc.author == req.userCtx.name);
            if(util.inArray(username, doc.voted)) {
                doc.upvoted = true;
            }

            data.rows.push(doc);
        }
        var html = Mustache.to_html(this.templates.all, data, this.templates.partials);

        return html;
    });