Browse Source

wherewasi?

windhamdavid 3 years ago
parent
commit
91ba83e203

+ 24 - 38
app.js

@@ -5,14 +5,14 @@ var exphbs = require('express-handlebars');
 var session = require('express-session');
 var flash = require('express-flash');
 var cookieParser = require('cookie-parser');
+var compress = require('compression');
 var bodyParser = require('body-parser');
 var favicon = require('serve-favicon');
 var errorHandler = require('errorhandler');
 var events = require('events');
 var http = require('http');
 var path = require('path');
-var FileStreamRotator = require('file-stream-rotator')
-var fs = require('fs')
+var fs = require('fs');
 var logger = require('morgan');
 
 var _ = require('lodash');
@@ -27,15 +27,11 @@ var expressValidator = require('express-validator');
 
 /********** Config **************/
 
-var app = express();
 
-var config = {
-  development: require('./config/config-dev.js'),
-  production: require('./config/config.js')
-};
+var conf = require('./config/config');
 var secure = require('./config/secure');
 var passportConf = require('./config/passport');
-
+var app = express();
 
 
 /********** MongoDB **************/
@@ -50,15 +46,10 @@ mongoose.connection.on('error', function() {
 
 /********** app.engine **************/
 
-app.engine('.hbs', exphbs({ 
-  defaultLayout: 'main', 
-  extname: '.hbs',
-  layoutsDir:'app/views/layouts',
-  partialsDir:'app/views/partials'
-}));
-app.set('view engine', 'jade');
+app.set('port', process.env.PORT || 3000);
 app.set('views', path.join(__dirname, 'app/views'));
-
+app.set('view engine', 'jade');
+app.use(compress());
 
 
 
@@ -135,12 +126,19 @@ router.get('/account/unlink/:provider', passportConf.isAuthenticated, userContro
 var eventRouter = require('./routes/event_route');
 app.use('/event', eventRouter);
 
+router.get('/event', eventController.getEvent);
+router.get('/event/new', eventController.getEvent_new);
+router.get('/event/new', passportConf.isAuthenticated, eventController.postEvent_new);
 
 /********** entry routes **************/
 
 var entryRouter = require('./routes/entry_route');
 app.use('/entry', entryRouter);
 
+router.get('/entry', entryController.getEntry);
+router.get('/entry/new', entryController.getEntry_new);
+router.get('/entry/new', passportConf.isAuthenticated, entryController.postEntry_new);
+
 
 /********** static routes controllers **************/
 
@@ -197,38 +195,26 @@ app.use(function handleNotFound(req, res, next){
   };
 });
 
-// development error handler
-// will print stacktrace
-if (app.get('env') === 'development') {
+if (process.env.NODE_ENV === 'development') {
+  app.use(errorHandler())
+};
+
+if (process.env.NODE_ENV !== 'development') {
   app.use(function(err, req, res, next) {
     res.status(err.status || 500);
-    res.render('error', {
+    res.render('500', {
       message: err.message,
-      error: err
+      error: {}
     });
   });
 }
 
-// production error handler
-// no stacktraces leaked to user
-app.use(function(err, req, res, next) {
-  res.status(err.status || 500);
-  res.render('error', {
-    message: err.message,
-    error: {}
-  });
-});
-
-if (process.env.NODE_ENV === 'development') {
-  app.use(errorHandler())
-};
-
 
 
 /********** app.listen **************/
 
-app.listen(conf.port), function() {
-  console.log('listening on port %d in %s mode', app.get('port'), app.get('env'));
-}
+app.listen(app.get('port'), function() {
+  console.log('Express server listening on port %d in %s mode', app.get('port'), app.get('env'));
+});
 
 module.exports = app;

+ 39 - 2
controllers/entry_control.js

@@ -7,10 +7,47 @@ var User = require('../models/user');
 var secure = require('../config/secure');
 
 
-/********** GET / Login **************/
+/********** GET / Entry **************/
 
 exports.getEntry = function (req, res) {
-  res.render('entries/entry', {
+  res.render('entry/entry', {
     title: 'Entry'
   });
+};
+
+
+
+/********** GET / New Entry **************/
+
+exports.getEntry_new = function (req, res) {
+  res.render('entry/event_new', {
+    title: 'Create an Entry'
+  });
+};
+
+
+/********** POST / New Entry **************/
+
+exports.postEntry_new= function(req, res, next) {
+
+  var errors = req.validationErrors();
+
+  var event = new Entry ({
+    entryname: req.body.evenname
+  });
+
+  Event.findOne({ eventname: req.body.eventname }, function(err, existingEvent) {
+    if (existingEvent) {
+      req.flash('errors', { msg: 'Event with that name already exists.' });
+      return res.redirect('/entry/error');
+    }
+    event.save(function(err) {
+      if (err) {
+        return next(err);
+      }
+      req.flash('success', { msg: 'Success!' });
+      res.redirect(req.session.returnTo || '/');
+    });
+  });
+  
 };

+ 42 - 2
controllers/event_control.js

@@ -4,13 +4,53 @@ var crypto = require('crypto');
 var nodemailer = require('nodemailer');
 var passport = require('passport');
 var User = require('../models/user');
+var Event = require('../models/event');
 var secure = require('../config/secure');
 
 
 /********** GET / Event **************/
 
 exports.getEvent = function (req, res) {
-  res.render('events/event', {
-    title: 'Events'
+  res.render('event/event', {
+    title: 'Event'
   });
 };
+
+
+/********** GET / New Event **************/
+
+exports.getEvent_new = function (req, res) {
+  res.render('event/event_new', {
+    title: 'Create an Event'
+  });
+};
+
+
+/********** POST / New Event **************/
+
+exports.postEvent_new= function(req, res, next) {
+
+  var errors = req.validationErrors();
+
+  var event = new Event({
+    eventname: req.body.evenname
+  });
+
+  Event.findOne({ eventname: req.body.eventname }, function(err, existingEvent) {
+    if (existingEvent) {
+      req.flash('errors', { msg: 'Event with that name already exists.' });
+      return res.redirect('/event/error');
+    }
+    event.save(function(err) {
+      if (err) {
+        return next(err);
+      }
+      req.flash('success', { msg: 'Success!' });
+      res.redirect(req.session.returnTo || '/');
+    });
+  });
+  
+};
+
+
+

+ 20 - 2
gulpfile.js

@@ -1,5 +1,6 @@
 var gulp = require('gulp');
 var nodemon = require('gulp-nodemon');
+var browserSync = require('browser-sync').create();
 var jshint = require('gulp-jshint');
 var uglify = require('gulp-uglify');
 var minifyHTML = require('gulp-minify-html');
@@ -102,14 +103,31 @@ gulp.task('watch', function() {
 });
 
 
+var syncTask = function() {
+    browserSync.init({
+        proxy: {
+          target: 'https://juryd.macs',
+          ws: true
+        },
+        https: true,
+        files: ['./app/**/*.*'],
+        port: 7000,
+    });
+};
+
+gulp.task('sync', function() {
+  watchTask();
+  syncTask();
+});
+
 var nodemonTask = function() {
   nodemon({
     tasks: ['watch'],
+    env: { 'NODE_ENV': 'development' },
     script: 'app.js',
     verbose: true,
-    env: { 'NODE_ENV': 'development' },
     watch: ['./src/'],
-    ext: 'css js html hbs'
+    ext: 'css js html jade hbs'
   });
 };
 

+ 1 - 0
models/event.js

@@ -8,3 +8,4 @@ var eventSchema = new mongoose.Schema({
     eventname: { type: String, default: '' }
   }
 });
+

+ 4 - 1
package.json

@@ -17,6 +17,7 @@
     "bcrypt-nodejs": "0.0.3",
     "bcryptjs": "^2.3.0",
     "body-parser": "^1.14.1",
+    "compression": "^1.6.0",
     "connect-mongo": "^0.8.2",
     "cookie-parser": "^1.3.5",
     "errorhandler": "^1.4.2",
@@ -38,6 +39,7 @@
     "serve-favicon": "~2.3.0"
   },
   "devDependencies": {
+    "browser-sync": "^2.10.0",
     "del": "^2.1.0",
     "gulp": "^3.9.0",
     "gulp-concat": "^2.6.0",
@@ -50,6 +52,7 @@
     "nodemon": "^1.8.1"
   },
   "scripts": {
-    "start": "node app.js"
+    "start": "node app.js",
+    "test": "mocha --reporter spec --timeout 5000"
   }
 }

+ 2 - 2
routes/entry_route.js

@@ -1,8 +1,8 @@
 var express = require('express');
 var app = express();
 var router = express.Router();
-var eventsController = require('../controllers/entry_control');
+var entryController = require('../controllers/entry_control');
 
-router.get('/entry', entryController.getEvent);
+router.get('/entry', entryController.getEntry);
 
 module.exports = router;

+ 2 - 1
routes/event_route.js

@@ -3,6 +3,7 @@ var app = express();
 var router = express.Router();
 var eventController = require('../controllers/event_control');
 
-router.get('/event', eventController.getEvent);
+
+
 
 module.exports = router;

+ 15 - 0
server.js

@@ -0,0 +1,15 @@
+var os = require('os');
+var cluster = require('cluster');
+
+cluster.setupMaster({
+  exec: 'app.js'
+});
+
+cluster.on('exit', function(worker) {
+  console.log('worker ' + worker.id + ' died');
+  cluster.fork();
+});
+
+for (var i = 0; i < os.cpus().length; i++) {
+  cluster.fork();
+}

+ 3 - 68
src/css/main.css

@@ -22,77 +22,12 @@ a {
 /* =================================================
 ===================  Navbar ========================
 ==================================================== */
-.navbar-default {
-  border-color: rgba(34,34,34,.05);
-  background-color: rgba(255,255,255,.5);
-  -webkit-transition: all .35s;
-  -moz-transition: all .35s;
-  transition: all .35s;
-  min-height: 85px;
-}
-nav.navbar.shrink {
-  min-height: 35px;
-}
-nav.shrink .navbar-brand {
-  font-size: 25px;
-}
-nav a {
-  margin: 20px 5px !important;
-  margin-bottom: 20px !important;
-  font-size: 18px !important;
-}
-nav.shrink a {
-  margin: 10px 5px !important;
-  font-size: 16px !important;
-}
+
 .navbar-default .navbar-header .navbar-brand {
   background-image:url(../img/ribbon.svg) no-repeat;
 }
-.navbar-default .navbar-header .navbar-brand:hover,
-.navbar-default .navbar-header .navbar-brand:focus {}
-.navbar-default .nav > li>a,
-.navbar-default .nav>li>a:focus {
-  font-size: 13px;
-  font-weight: 700;
-  color: #222;
-}
-.navbar-default .nav > li>a:hover,
-.navbar-default .nav>li>a:focus:hover {
-}
-.navbar-default .nav > li.active>a,
-.navbar-default .nav>li.active>a:focus {
-    background-color: transparent;
-}
-.navbar-default .nav > li.active>a:hover,
-.navbar-default .nav>li.active>a:focus:hover {
-    background-color: transparent;
-}
-.navbar .navbar-nav > li > a.btn {
-  border-radius: 20px;
-  box-sizing: border-box;
-  border-width: 2px;
-  background-color: transparent;
-  font-size: 16px;
-  font-weight: 500;
-  padding: 7px 18px;
-  border-color: #66615B;
-  color: #66615B;
-  -webkit-transition: all 150ms linear;
-  -moz-transition: all 150ms linear;
-  -o-transition: all 150ms linear;
-  -ms-transition: all 150ms linear;
-  transition: all 150ms linear;
-}
-.btn:hover, .btn:focus, .btn:active, .btn.active, .open > .btn.dropdown-toggle,
-.navbar .navbar-nav > li > a.btn:hover,
-.navbar .navbar-nav > li > a.btn:focus,
-.navbar .navbar-nav > li > a.btn:active,
-.navbar .navbar-nav > li > a.btn.active, .open >
-.navbar .navbar-nav > li > a.btn.dropdown-toggle {
-  background-color: #66615B;
-  color: rgba(255, 255, 255, 0.7);
-  border-color: #66615B;
-}
+
+
 
 /* =================================================
 ===================  Header ========================

src/views/entries/entries.jade → src/views/entry/entries.jade


src/views/entries/entry.jade → src/views/entry/entry.jade


+ 19 - 0
src/views/event/event.jade

@@ -0,0 +1,19 @@
+extends ../layout
+
+block content
+  section#partial
+    .container
+      .row
+        .col-sm-8.col-sm-offset-2.text-center
+          h2 Event
+      hr
+      .row
+        .col-sm-8.col-sm-offset-2
+          ul.nav.nav-pills
+            li(role='presentation', class=title=='event'?'active':undefined)
+              a(href='/event/new') new event
+            li(role='presentation', class=title=='event'?'active':undefined)
+              a(href='/event/search') seach events
+            li(role='presentation', class=title=='event'?'active':undefined)
+              a(href='/event/list') list events
+      hr

+ 36 - 0
src/views/event/event_new.jade

@@ -0,0 +1,36 @@
+extends ../layout
+
+block content
+  section#partial
+    .container
+      .row
+        .col-sm-8.col-sm-offset-2
+          ul.nav.nav-pills
+            li(role='presentation', class=title=='event'?'active':undefined)
+              a(href='/event/new') new event
+            li(role='presentation', class=title=='event'?'active':undefined)
+              a(href='/event/search') seach events
+            li(role='presentation', class=title=='event'?'active':undefined)
+              a(href='/event/list') list events
+      hr
+      .row
+        .col-sm-8.col-sm-offset-2.text-center
+          h3 Create An Event      
+      hr
+      .row
+        .col-sm-8.col-sm-offset-2
+          form.form-horizontal(id='event-form', method='POST')
+            input(type='hidden', name='_csrf', value=_csrf)
+            .form-group
+              label.col-sm-3.control-label(for='eventname') Event Name
+              .col-sm-7
+                input.form-control(type='text', name='eventname', id='eventname', value='', autofocus)
+            .form-group
+              label.col-sm-3.control-label(for='eventname') Event Description
+              .col-sm-7
+                textarea.form-control(type='textarea', rows='5', name='eventdesc', id='eventdesc', value='', autofocus)
+            .form-group
+              .col-sm-offset-3.col-sm-7
+                button.btn.btn-success(type='submit')
+                  i.fa.fa-balance-scale
+                  | Create Event

src/views/events/events.jade → src/views/event/events.jade


+ 0 - 13
src/views/events/event.jade

@@ -1,13 +0,0 @@
-extends ../layout
-
-block content
-  section#partial
-    .container
-      .row
-        .col-sm-8.col-sm-offset-2.text-center
-          h3 Event
-          
-          
-          
-      hr
-      .row

+ 7 - 2
src/views/partials/header.jade

@@ -1,4 +1,4 @@
-nav#mainNav.navbar.navbar-default.navbar-fixed-top
+.navbar.navbar-default.navbar-fixed-top
   .container
     .navbar-header
       button.navbar-toggle(type='button', data-toggle='collapse', data-target='.navbar-collapse')
@@ -10,7 +10,12 @@ nav#mainNav.navbar.navbar-default.navbar-fixed-top
         img.svg.icon-small(src="/img/ribbon.svg")
     .collapse.navbar-collapse
       ul.nav.navbar-nav
-
+        li(class=title=='event'?'active':undefined)
+          a(href='/event') event
+        li(class=title=='entry'?'active':undefined)
+          a(href='/entry') entry
+        li(class=title=='api'?'active':undefined)
+          a(href='/api') api
       ul.nav.navbar-nav.navbar-right
         if !user
           li(class=title=='Login'?'active':undefined)