Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Media Ranker #12

Open
wants to merge 53 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
3715f24
App setup
sophiabaldonado Jul 14, 2016
9c054fd
DB Schema
sophiabaldonado Jul 14, 2016
8679414
Fix seed data and scripts;
sophiabaldonado Jul 14, 2016
9a6008f
Create view files;
sophiabaldonado Jul 14, 2016
ed503c8
Books controller index function;
sophiabaldonado Jul 14, 2016
7fb3ce5
Book model all function;
sophiabaldonado Jul 14, 2016
d712898
views setup;
sophiabaldonado Jul 14, 2016
3a8b2e6
partials views;
sophiabaldonado Jul 14, 2016
09e3293
include massive in app.js;
sophiabaldonado Jul 14, 2016
bb41602
require books controller file;
sophiabaldonado Jul 14, 2016
1f87b94
Fix controller index functions and routers;
sophiabaldonado Jul 14, 2016
e5a2dbe
Working on books index;
sophiabaldonado Jul 14, 2016
155be77
Display book info on index view;
sophiabaldonado Jul 14, 2016
1d151c4
update seed files;
sophiabaldonado Jul 14, 2016
0415e31
Rewrite index function to be dynamic;
sophiabaldonado Jul 14, 2016
6c2eed4
Add .all functions for Movies and Albums models;
sophiabaldonado Jul 14, 2016
0bb8aec
Fix views;
sophiabaldonado Jul 14, 2016
a60e314
Index controller and home page;
sophiabaldonado Jul 15, 2016
190c4a8
Add bootstrap;
sophiabaldonado Jul 15, 2016
5b4c121
Add bootstrap and jquery
sophiabaldonado Jul 18, 2016
808dfa1
Load resources as callbacks in Index controller
sophiabaldonado Jul 18, 2016
82bdfe4
structure html on home page
sophiabaldonado Jul 18, 2016
41c9286
CSS Styling
sophiabaldonado Jul 18, 2016
58017ff
Create topTen functions for models to display on home page
sophiabaldonado Jul 18, 2016
5e5757c
Link to index pages that display resources in tables
sophiabaldonado Jul 19, 2016
a15b275
Model .all functions return resources in order by votes
sophiabaldonado Jul 19, 2016
a33ac09
Post movie upvote and movies show setup
sophiabaldonado Jul 19, 2016
d8c5432
Show action for Movies;
sophiabaldonado Jul 19, 2016
1013040
Upvote and Show actions for books and albums;
sophiabaldonado Jul 19, 2016
de97db6
Use one show page for all models;
sophiabaldonado Jul 20, 2016
d00f502
Add media links to home page
sophiabaldonado Jul 20, 2016
7f6d37c
Edit form view and controller action for movies
sophiabaldonado Jul 20, 2016
6c9a017
Edit form view and controller action for movies
sophiabaldonado Jul 20, 2016
80a50fb
Index pages link to media and fix typos
sophiabaldonado Jul 20, 2016
7da0e90
fix typo
sophiabaldonado Jul 20, 2016
b01ff49
Update movies route, controller, model functions, and view
sophiabaldonado Jul 20, 2016
9392e57
Create update functions, routes, views, for Books and Albums
sophiabaldonado Jul 20, 2016
e126aff
Create Delete routes, controller actions, and model functions for Movies
sophiabaldonado Jul 20, 2016
004bfbf
Create Delete routes, actions, model functions for Books and Albums
sophiabaldonado Jul 20, 2016
4719d82
Display media in descending order on index pages
sophiabaldonado Jul 20, 2016
83598dc
Formatting, standard style
sophiabaldonado Jul 22, 2016
da55399
Change routes for editing path
sophiabaldonado Jul 22, 2016
8fbfaf0
Restructure Edit form for styling purposes
sophiabaldonado Jul 23, 2016
12eaa35
Fix typo
sophiabaldonado Jul 23, 2016
7681f18
Use rems and percent instead of px for styling
sophiabaldonado Jul 23, 2016
62d4337
Begin setup for new media form
sophiabaldonado Jul 23, 2016
66ed9bc
Use more explicit url for upvote path
sophiabaldonado Jul 23, 2016
ab80925
Create movie record function in model and new movie action and view
sophiabaldonado Jul 24, 2016
06fb43c
Fix index page button links and add displayType attribute for movies
sophiabaldonado Jul 24, 2016
a05392f
Create new books and albums, model, controller functions and views
sophiabaldonado Jul 24, 2016
7caf7d3
Fix redirects
sophiabaldonado Jul 24, 2016
590c27f
rm unused views
sophiabaldonado Jul 24, 2016
4fc3895
Setup directories for testing lol
sophiabaldonado Jul 24, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# https://docs.npmjs.com/cli/shrinkwrap#caveats
node_modules

# Debug log from npm
npm-debug.log
77 changes: 77 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');

// var jQuery = require('jQuery')
// var bootstrap = require('bootstrap')
var massive = require('massive')

var app = express();
module.exports = app

var connectionString = "postgres://localhost/media_" + app.get('env')
var db = massive.connectSync({connectionString : connectionString})
app.set("db", db)

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');

// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));


var routes = require('./routes/index')
app.use('/', routes)

var books = require('./routes/books')
app.use('/books', books)

var movies = require('./routes/movies')
app.use('/movies', movies)

var albums = require('./routes/albums')
app.use('/albums', albums)


// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});

// error handlers

// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: err
});
});
}

// 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: {}
});
});


module.exports = app;
90 changes: 90 additions & 0 deletions bin/www
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/usr/bin/env node

/**
* Module dependencies.
*/

var app = require('../app');
var debug = require('debug')('MediaRanker:server');
var http = require('http');

/**
* Get port from environment and store in Express.
*/

var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);

/**
* Create HTTP server.
*/

var server = http.createServer(app);

/**
* Listen on provided port, on all network interfaces.
*/

server.listen(port);
server.on('error', onError);
server.on('listening', onListening);

/**
* Normalize a port into a number, string, or false.
*/

function normalizePort(val) {
var port = parseInt(val, 10);

if (isNaN(port)) {
// named pipe
return val;
}

if (port >= 0) {
// port number
return port;
}

return false;
}

/**
* Event listener for HTTP server "error" event.
*/

function onError(error) {
if (error.syscall !== 'listen') {
throw error;
}

var bind = typeof port === 'string'
? 'Pipe ' + port
: 'Port ' + port;

// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error(bind + ' requires elevated privileges');
process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
process.exit(1);
break;
default:
throw error;
}
}

/**
* Event listener for HTTP server "listening" event.
*/

function onListening() {
var addr = server.address();
var bind = typeof addr === 'string'
? 'pipe ' + addr
: 'port ' + addr.port;
debug('Listening on ' + bind);
}
130 changes: 130 additions & 0 deletions controllers/albums.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
var Album = require("../models/album")

var AlbumsController = {
index: function (req, res, next) {

Album.all(function(error, albums) {
if(error) {
var err = new Error("Error retrieving book list:\n" + error.message)
err.status = 500
next(err)
} else {
var locals = {}
locals.type = "albums"
locals.displayType = "Album"
locals.media = albums
res.render ('index', { locals: locals })
}
})
},

show: function (req, res, next) {
var id = req.params.album_id

Album.find(id, function(error, albums) {
if(error) {
var err = new Error("Error retrieving book list:\n" + error.message)
err.status = 500
next(err)
} else {
var locals = {}
locals.type = "albums"
locals.displayType = "Album"
locals.madeBy = "Recorded"
locals.media = albums[0]
res.render ('show', { locals: locals })
}
})
},

upvote: function (req, res, next) {
var album_id = req.body.upvote

Album.addVote(album_id, function(error, moe_id) {
if(error) {
var err = new Error("Error retrieving book list:\n" + error.message)
err.status = 500
next(err)
} else {
return res.redirect ('/albums/' + album_id)
}
})
},

new: function (req, res, next) {
var locals = {}
locals.type = "albums"
locals.displayType = "Album"
locals.madeBy = "Directed"
res.render ('new', { locals: locals })
},

edit: function (req, res, next) {
var album_id = req.params.album_id

Album.find(album_id, function(error, albums) {
if(error) {
var err = new Error("Error retrieving album:\n" + error.message)
err.status = 500
next(err)
} else {
var locals = {}
locals.type = "albums"
locals.madeBy = "Directed"
locals.media = albums[0]
res.render ('edit', { locals: locals })
}
})
},

update: function (req, res, next) {
var album_id = req.body.albums_id
var name = req.body.name
var description = req.body.description
var artist = req.body.by

Album.update([name, description, artist, album_id], function(error, id) {
if(error) {
var err = new Error("Error retrieving album list:\n" + error.message)
err.status = 500
next(err)
} else {
return res.redirect ('/albums/' + album_id)
}
})
},

add: function (req, res, next) {
var name = req.body.name
var description = req.body.description
var artist = req.body.by

Album.create([name, description, artist], function(error, album) {
console.log("boop: ", album)
if(error) {
var err = new Error("Error retrieving album list:\n" + error.message)
err.status = 500
next(err)
} else {
return res.redirect ('/albums/' + album.id)
}
})
},

delete: function (req, res, next) {
var album_id = req.body.delete

Album.delete(album_id, function(error, id) {
if(error) {
var err = new Error("Error retrieving album list:\n" + error.message)
err.status = 500
next(err)
} else {
return res.redirect ('/albums')
}
})
}

}

module.exports = AlbumsController
Loading