Added support for tags

This commit is contained in:
Dobie Wollert
2013-06-26 03:54:22 -07:00
parent b92068b6b2
commit 4ca472f2cb
9 changed files with 225 additions and 6 deletions

View File

@ -5,6 +5,6 @@ module.exports = function(piler) {
js: piler.js.renderTags(),
css: piler.css.renderTags()
});
}
},
};
};

50
app/controllers/tags.js Normal file
View File

@ -0,0 +1,50 @@
var mongoose = require('mongoose'),
Tag = mongoose.model('Tag');
module.exports = function(piler) {
return {
index: function(req, res, next) {
host = String(req.headers.host);
host = host.split(':')[0];
if (host != 'n.atlb.co') {
return next();
}
if (!req.user) {
req.session.redirectUrl = req.url
}
var path = req.path.slice(1);
Tag.findById(path)
.populate('client', 'name identifier address')
.exec(function(err, result) {
var payload = {
user: req.user,
id: path,
tag: result || undefined,
};
res.render('tag.jade', {
css: piler.css.renderTags(),
payload: payload
});
})
},
post: function(req, res) {
var tag_id = req.body.tag_id;
delete req.body.tag_id;
Tag.findByIdAndUpdate(tag_id, req.body, { upsert: true }, function(err, result) {
if (err) {
res.json(500, err);
} else {
res.json(result);
}
});
}
}
}