mirror of
https://github.com/atlanticbiomedical/biomedjs.git
synced 2025-07-02 00:47:26 -04:00
latest changes
This commit is contained in:
111
app/controllers/posts.js
Normal file
111
app/controllers/posts.js
Normal file
@ -0,0 +1,111 @@
|
||||
|
||||
var mongoose = require('mongoose'),
|
||||
Post = mongoose.model('Post');
|
||||
|
||||
var md5 = require('MD5');
|
||||
var fs = require('fs');
|
||||
|
||||
var log = require('log4node');
|
||||
|
||||
exports.index = function(req, res) {
|
||||
log.info('posts.index');
|
||||
var query = Post.find()
|
||||
.populate('author', 'name')
|
||||
.sort('-createdOn')
|
||||
.exec(function(err, results) {
|
||||
if (err) {
|
||||
res.json(500, err);
|
||||
} else {
|
||||
res.json(results);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
exports.get = function(req, res, next) {
|
||||
var id = req.param('post_id');
|
||||
Post.findById(id)
|
||||
.exec(function(err, post) {
|
||||
if (err) return next(err);
|
||||
if (!post) return next(new Error('Failed to load post ' + id));
|
||||
|
||||
res.json(post);
|
||||
});
|
||||
};
|
||||
|
||||
exports.create = function(req, res, next) {
|
||||
log.info('posts.create %j', req.body);
|
||||
|
||||
var post = new Post({
|
||||
title: req.body.title,
|
||||
preview: req.body.preview,
|
||||
details: req.body.details,
|
||||
image: req.body.image,
|
||||
gallery: req.body.gallery,
|
||||
status: req.body.status,
|
||||
createdOn: req.body.createdOn,
|
||||
postedOn: req.body.postedOn,
|
||||
author: req.user
|
||||
});
|
||||
|
||||
return post.save(function(err) {
|
||||
if (err) log.error("Error: %s", err);
|
||||
|
||||
return res.json(post);
|
||||
});
|
||||
};
|
||||
|
||||
exports.update = function(req, res, next) {
|
||||
var id = req.param('post_id');
|
||||
|
||||
console.log('updating post');
|
||||
|
||||
return Post.findById(id, function(err, post) {
|
||||
post.title = req.body.title;
|
||||
post.preview = req.body.preview;
|
||||
post.details = req.body.details;
|
||||
post.image = req.body.image;
|
||||
post.gallery = req.body.gallery;
|
||||
post.status = req.body.status;
|
||||
post.postedOn = req.body.postedOn;
|
||||
|
||||
return post.save(function(err) {
|
||||
if (err)
|
||||
log.error("Error: %s", err);
|
||||
|
||||
return res.json(post);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
exports.destroy = function(req, res, next) {
|
||||
var id = req.param('post_id');
|
||||
log.info('posts.destroy %s', id);
|
||||
|
||||
return Post.findById(id, function(err, post) {
|
||||
post.deleted = true;
|
||||
|
||||
return post.save(function(err) {
|
||||
if (err)
|
||||
log.error("Error: %s", err);
|
||||
|
||||
return res.json(post);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
exports.upload = function(req, res, next) {
|
||||
var path = req.files.file.path;
|
||||
|
||||
fs.readFile(path, function(err, data) {
|
||||
var hash = md5(data);
|
||||
|
||||
fs.writeFile('/srv/biomed-site/images/' + hash, data, function(err) {
|
||||
if (err)
|
||||
log.error("Error: %s", err);
|
||||
|
||||
return res.json({
|
||||
filename: hash
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
25
app/controllers/site.js
Normal file
25
app/controllers/site.js
Normal file
@ -0,0 +1,25 @@
|
||||
var mongoose = require('mongoose'),
|
||||
Post = mongoose.model('Post');
|
||||
|
||||
module.exports = function(piler) {
|
||||
return {
|
||||
index: function(req, res, next) {
|
||||
host = String(req.headers['x-forwarded-host']);
|
||||
host = host.split(':')[0];
|
||||
|
||||
if (host != 'site.atlb.co') {
|
||||
return next();
|
||||
}
|
||||
|
||||
if (!req.user) {
|
||||
req.session.redirectUrl = req.url
|
||||
}
|
||||
|
||||
var path = req.path.slice(1);
|
||||
|
||||
res.render('site.jade', {
|
||||
css: piler.css.renderTags()
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -204,6 +204,6 @@ var blacklist = [
|
||||
"chris.sewell@atlanticbiomedical.com",
|
||||
"devel@atlanticbiomedical.com",
|
||||
"dobie@atlanticbiomedical.com",
|
||||
"akirayasha@gmail.com",
|
||||
// "akirayasha@gmail.com",
|
||||
"receipts@atlanticbiomedical.com",
|
||||
];
|
||||
|
17
app/model/posts.js
Normal file
17
app/model/posts.js
Normal file
@ -0,0 +1,17 @@
|
||||
var mongoose = require('mongoose'),
|
||||
Schema = mongoose.Schema,
|
||||
ObjectId = Schema.ObjectId;
|
||||
|
||||
var postSchema = new Schema({
|
||||
title: { type: String },
|
||||
preview: { type: String },
|
||||
details: { type: String },
|
||||
image: { type: String },
|
||||
gallery: [{ type: String }],
|
||||
status: { type: String },
|
||||
createdOn: { type: Date },
|
||||
postedOn: { type: Date },
|
||||
author: { type: ObjectId, ref: 'User' }
|
||||
});
|
||||
|
||||
var Post = module.exports = mongoose.model('Post', postSchema);
|
@ -19,7 +19,7 @@ html(lang="en", ng-app="biomed", ng-controller="biomed.PageCtrl")
|
||||
i.icon-thumbs-down
|
||||
| Incident
|
||||
li
|
||||
a(href='http://atlanticbiomedical.com/ticket/', target='_blank')
|
||||
a(href='http://jira.devwr.com:9090/servicedesk/customer/portal/2', target='_blank')
|
||||
i.icon-fire
|
||||
| Tickets
|
||||
li
|
||||
@ -54,6 +54,11 @@ html(lang="en", ng-app="biomed", ng-controller="biomed.PageCtrl")
|
||||
i.icon-wrench
|
||||
| Workorders
|
||||
|
||||
li(data-match-route='/posts.*', ng-show="accountHasPermission('system.admin')")
|
||||
a(href='/posts')
|
||||
i.icon-wrench
|
||||
| Posts
|
||||
|
||||
li(data-match-route='/admin.*', ng-show="accountHasPermission('system.admin')")
|
||||
a(href='/admin')
|
||||
i.icon-wrench
|
||||
|
53
app/views/site.jade
Normal file
53
app/views/site.jade
Normal file
@ -0,0 +1,53 @@
|
||||
doctype 5
|
||||
html(lang="en", ng-app="site", ng-controller="site.PageCtrl")
|
||||
head
|
||||
title Atlantic Biomedical
|
||||
!{css}
|
||||
link(rel='stylesheet', href='/css/site.css')
|
||||
meta(name='viewport', content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0')
|
||||
body
|
||||
script(type='text/javascript', src='//ajax.googleapis.com/ajax/libs/angularjs/1.1.4/angular.js')
|
||||
script(type='text/javascript', src='//ajax.googleapis.com/ajax/libs/angularjs/1.1.4/angular-resource.js')
|
||||
script(type='text/javascript', src='//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js')
|
||||
script(type='text/javascript', src='/site/dropzone.js')
|
||||
script(type='text/javascript', src='/site/app.js')
|
||||
|
||||
error-panel
|
||||
.navbar
|
||||
.navbar-inner
|
||||
a.brand(href='/', target='_self') Atlantic Biomedical
|
||||
progress-panel
|
||||
|
||||
.container-fluid(ng-hide='saved')
|
||||
h1 New Post
|
||||
|
||||
|
||||
form
|
||||
.control-group
|
||||
label.control-label Title
|
||||
.controls
|
||||
input.input-xlarge(ng-model='model.title')
|
||||
|
||||
.control-group
|
||||
label.control-label Body
|
||||
.controls
|
||||
textarea.input-xlarge(ng-model='model.preview')
|
||||
|
||||
.control-group
|
||||
label.control-label Header Image
|
||||
.controls
|
||||
.dropzone(dropzone='titleImageOptions')
|
||||
|
||||
.control-group
|
||||
label.control-label Gallery
|
||||
.controls
|
||||
.dropzone(dropzone='galleryImageOptions')
|
||||
|
||||
.control-group
|
||||
.controls
|
||||
button.btn.btn-primary(ng-click='save()', type='button') Save
|
||||
|
||||
|
||||
.container-fluid(ng-show='saved')
|
||||
h1.msg Your post has been saved
|
||||
button.btn.btn-primary(ng-click='refresh()', type='button') Start new Post
|
Reference in New Issue
Block a user