Prettification abounds.... also created new view controller for photo administration.

This commit is contained in:
Andrew Davidson 2015-11-22 10:05:41 -05:00
parent df25b6cdfc
commit 2be6c664e6
11 changed files with 87 additions and 20 deletions

67
app.js
View file

@ -13,16 +13,15 @@ var build = require('./build.js');
var app = express();
// Get config variables
var config = require('./config.js').config;
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
// Make HTML pretty while we're setting up our jade templates
// but it doesn't need to be pretty in production.
if (app.get('env') === 'development') {
app.locals.pretty = true;
};
// uncomment after placing your favicon in /public
//app.use(require('serve-favicon')(path.join(__dirname, 'public',
@ -35,10 +34,7 @@ app.use(require('express-session')({ secret: 'amdasdfasdfamd',
resave: true, saveUninitialized: true }));
app.use(express.static(path.join(__dirname, 'public')));
var upload = multer({ dest: 'data/uploads/' })
// Get config variables
var config = require('./config.js').config;
var upload = multer({ dest: config.uploadDir });
// Setup authentication via twitter.
passport.use(new Strategy(
@ -239,6 +235,25 @@ app.get('/admin/photo/list/:start?',
});
});
app.get('/admin/photo/view/:id?',
function (req, res, next) {
if (req.params.id) {
db.getPhotoById(req.params.id, function(row) {
res.render('admin-photo-view', {
successNotice: req.flash('successNotice'),
failureNotice: req.flash('failureNotice'),
photo: row,
srcPath: '/'+row.path,
user: req.user
})
})
}
else {
res.redirect('/admin/photo/list');
}
}
);
app.get('/admin/photo/new',
function(req, res, next) {
res.render('admin-photo-new', { user: req.user });
@ -264,7 +279,7 @@ app.post('/admin/photo/new',
var slug = req.body.slug;
}
else if ( req.body.title != "" ){
var slug = helper.makeSlug(title);
var slug = helper.makeSlug(title+'-'+photoDate);
}
else {
var cleanFileName = req.file.originalname.split('.').slice(0,-1).join('-');
@ -281,7 +296,7 @@ app.post('/admin/photo/new',
console.log(row);
db.tagPhoto(row.id, tags);
req.flash('successNotice', 'Photo created.');
res.redirect('/admin/');
res.redirect('/admin/photo/view/'+row.id);
});
});
@ -305,6 +320,7 @@ app.get('/admin/photo/edit/:id',
successNotice: req.flash('successNotice'),
failureNotice: req.flash('failureNotice'),
photo: results.photo,
srcPath: '/'+results.photo.path,
photoTags: results.photoTags,
formattedDate: helper.epochToDateString(results.photo.photoDate),
user: req.user
@ -324,7 +340,7 @@ app.post('/admin/photo/edit/:id',
db.tagPhoto(id, tags);
db.updatePhoto(id, title, slug, markdown, photoDate, function(err, row) {
req.flash('successNotice', 'Photo updated.');
res.redirect('/admin/photo/edit/'+id);
res.redirect('/admin/photo/view/'+id);
});
});
@ -473,6 +489,35 @@ app.get('/galleries/*',
}
);
app.get('/data/*',
require('connect-ensure-login').ensureLoggedIn(),
function(req, res, next) {
if (req.params[0] != '') {
var path = __dirname + '/data/' + req.params[0];
console.log('Trying to serve: ' + path);
fs.exists(path, function(exists) {
if (exists) {
console.log(path + ' exists serving...');
res.sendFile(path);
}
else {
console.log(path + ' does not exist...');
if (path.slice(-1) != '/') path += '/';
path += 'index.html'
console.log('Trying to serve: ' + path);
fs.exists(path, function(exists) {
if (exists) {
console.log(path + ' exists serving...');
res.sendFile(path);
}
});
}
});
}
}
);
// Have to have some sort of home page.
app.get('/', function(req, res, next) {
res.render('admin-index', { title: 'AMDavidson.com', user: req.user });

1
db.js
View file

@ -485,6 +485,7 @@ exports.getPhotoTagsAsString = getPhotoTagsAsString;
// Returns the photo record
exports.getPhotoById = function(id, cb) {
db.get('SELECT * FROM photos WHERE id = ?', id, function(err, row) {
if (err) console.log(err);
cb(row);
});
}

View file

@ -4,7 +4,7 @@ block content
div(class="row")
include ./admin-sidebar.jade
div(class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main")
div(class="col-sm-10 col-sm-offset-2 main")
h1(class="page-header") Crunch Dashboard
include ./admin-messages.jade

View file

@ -4,14 +4,17 @@ block content
div(class="row")
include ./admin-sidebar.jade
div(class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main")
div(class="col-sm-10 col-sm-offset-2 main")
h1(class="page-header") Edit Photo
include ./admin-messages.jade
div(class='page-header row')
div(class="col-sm-6 col-sm-offset-3")
img(class="img-responsive", src='#{srcPath}')
form(method="post", action="/admin/photo/edit/#{photo.id}")
div(class="row page-header")
h1 put photo here
div(class="input-group input-group-lg col-xs-10 col-xs-offset-1 col-md-10 col-md-offset-1")
input(class="form-control", type="text", name="title", placeholder="Enter title", value="#{photo.title}")
div(class="input-group col-xs-10 col-xs-offset-1 col-md-10 col-md-offset-1")

View file

@ -4,7 +4,7 @@ block content
div(class="row")
include ./admin-sidebar.jade
div(class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main")
div(class="col-sm-10 col-sm-offset-2 main")
h1(class="page-header") Photos
include ./admin-messages.jade

View file

@ -4,7 +4,7 @@ block content
div(class="row")
include ./admin-sidebar.jade
div(class="col-sm-10 col-sm-offset-2 col-md-10 col-md-offset-2 main")
div(class="col-sm-10 col-sm-offset-2 main")
h1(class="page-header") New Photo
include ./admin-messages.jade

View file

@ -0,0 +1,18 @@
extends admin-layout
block content
div(class="row")
include ./admin-sidebar.jade
div(class="col-sm-10 col-sm-offset-2 main")
include ./admin-messages.jade
div(class='page-header row')
div(class="col-sm-6 col-sm-offset-3")
img(class="img-responsive", src='#{srcPath}')
div
h3 #{photo.title}
p #{photo.date}
p #{photo.description}

View file

@ -4,7 +4,7 @@ block content
div(class="row")
include ./admin-sidebar.jade
div(class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main")
div(class="col-sm-10 col-sm-offset-2 main")
h1(class="page-header") Edit Post
include ./admin-messages.jade

View file

@ -4,7 +4,7 @@ block content
div(class="row")
include ./admin-sidebar.jade
div(class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main")
div(class="col-sm-10 col-sm-offset-2 main")
h1(class="page-header") Posts
include ./admin-messages.jade

View file

@ -4,7 +4,7 @@ block content
div(class="row")
include ./admin-sidebar.jade
div(class="col-sm-10 col-sm-offset-2 col-md-10 col-md-offset-2 main")
div(class="col-sm-10 col-sm-offset-2 main")
h1(class="page-header") New Post
include ./admin-messages.jade

View file

@ -1,4 +1,4 @@
div(class="col-sm-3 col-md-2 sidebar")
div(class="col-sm-2 sidebar")
ul(class="nav nav-sidebar")
li: a(href="/admin/") Dashboard