diff options
-rw-r--r-- | app.js | 4 | ||||
-rw-r--r-- | controllers/system.js | 71 | ||||
-rw-r--r-- | models/access.js | 42 | ||||
-rw-r--r-- | models/project.js | 44 | ||||
-rw-r--r-- | public/img/androidA.png | bin | 5772 -> 9055 bytes | |||
-rw-r--r-- | public/img/androidA@2x.png | bin | 5059 -> 22383 bytes | |||
-rw-r--r-- | public/img/dashboard.png | bin | 127906 -> 128952 bytes | |||
-rw-r--r-- | public/img/dashboard@2x.png | bin | 339575 -> 342282 bytes | |||
-rw-r--r-- | public/img/iphoneA.png | bin | 4283 -> 9785 bytes | |||
-rw-r--r-- | public/img/iphoneA@2x.png | bin | 5906 -> 27306 bytes | |||
-rw-r--r-- | public/img/par.png | bin | 6545 -> 3453 bytes | |||
-rw-r--r-- | public/img/par@2x.png | bin | 5110 -> 3900 bytes | |||
-rw-r--r-- | public/img/winA.png | bin | 5296 -> 6468 bytes | |||
-rw-r--r-- | public/img/winA@2x.png | bin | 4678 -> 16853 bytes | |||
-rw-r--r-- | routes.js (renamed from router.js) | 2 | ||||
-rw-r--r-- | views/dashboard.ejs | 32 |
16 files changed, 159 insertions, 36 deletions
@@ -10,7 +10,7 @@ var express = require('express') /** * App configuration */ -var port = process.env.PORT || 8001 +var port = process.env.PORT || 8000 , env = process.env.NODE_ENV || 'development' , config = require('./config/config')[env] , auth = require('./config/middlewares/authorization'); @@ -44,7 +44,7 @@ require('./config/express')(app, config, passport); /** * Routes */ -require('./router')(app, passport, auth); +require('./routes')(app, passport, auth); /** diff --git a/controllers/system.js b/controllers/system.js index e3a55bd..ad5ced0 100644 --- a/controllers/system.js +++ b/controllers/system.js @@ -3,9 +3,9 @@ * Module dependencies */ var mongoose = require('mongoose') - , Project = mongoose.model('Project'); - - + , Project = mongoose.model('Project') + , Access = mongoose.model('Access') + , User = mongoose.model('User'); /** @@ -53,12 +53,47 @@ exports.faq = function(req, res) { exports.dashboard = function(req, res) { - console.log('/dashboard - ' + req.user); - res.render('dashboard', { - title: 'kanin', - loggedin: true + console.log('/dashboard - ' + req.user._id); + +/* + Access.find({ user: req.user._id }, function(err, accesses) { + if (err) return res.render('500'); + console.log('accesses ' + accesses); + accesses.forEach(function(access) { + Project.load(access.project, function(err, project) { + if (err) return res.render('500'); + projectList.push(project); + console.log(project.user.username); + }); + }); }); -}; +*/ + Access.loadUser(req.user._id, function(err, projects) { + if (err) return res.render('500'); + Project.populate(projects, { path: 'project.user', model: User }, function(err, projects) { + + console.log('accesses: ' + projects); + + res.render('dashboard', { + title: 'Dashboard', + loggedin: true, + projects: projects + }); + + }); + + }) + +/* + Project.find(function(err, projects) { + if (err) return res.render('500'); + res.render('dashboard', { + title: 'Dashboad', + loggedin: true, + projects: projects + }); + });*/ +} @@ -72,9 +107,25 @@ exports.newProject = function(req, res) { exports.postNewProject = function(req, res) { var project = new Project(req.body); + project.user = req.user._id; project.save(function(err) { - if (err) return res.render('newproject', { title: 'Nytt prosjekt - en feil oppstod', loggedin: true, errors: err.errors, project: project }); - return res.redirect('/dashboard'); + if (err) { + console.log(err.errors); + return res.render('newproject', { title: 'Nytt prosjekt - en feil oppstod', loggedin: true, errors: err.errors, project: project }); + } }); + + var access = new Access(); + access.user = req.user._id; + access.creator = req.user._id; + access.project = project._id; + access.permissions = 1; + access.save(function(err) { + if (err) { + console.log(err.errors); + return res.render('newproject', { title: 'Nytt prosjekt - en feil oppstod', loggedin: true }); + } + return res.redirect('/dashboard'); + }) } diff --git a/models/access.js b/models/access.js new file mode 100644 index 0000000..ce75f8c --- /dev/null +++ b/models/access.js @@ -0,0 +1,42 @@ + +/** + * Module dependencies + */ + +var mongoose = require('mongoose') + , Schema = mongoose.Schema; + +var AccessSchema = new Schema({ + user: { type: Schema.ObjectId, ref: 'User' }, + creator: { type: Schema.ObjectId, ref: 'User' }, + project: { type: Schema.ObjectId, ref: 'Project' }, + permissions: { type: Number, default: '3' }, + created: { type: Date, default: Date.now }, + updated: { type: Date, default: Date.now } +}); + +// the four validations below only apply if you are signing up traditionally + +AccessSchema.statics = { + + log: function() { + console.log('wat. wat logged this'); + }, + + /** + * Load ALL accesses for a single user + * + * @param {ObjectId} id + * @param {Function} callback + * @api private + */ + + loadUser: function(id, callback) { + this.find({ user: id }) + .populate('project') + .sort({ 'created': -1 }) // sort by date + .exec(callback); + } +} + +mongoose.model('Access', AccessSchema); diff --git a/models/project.js b/models/project.js index 2424694..f29c7f8 100644 --- a/models/project.js +++ b/models/project.js @@ -6,21 +6,17 @@ var mongoose = require('mongoose') , Schema = mongoose.Schema; - - - - var ProjectSchema = new Schema({ - user: { type: String, ref: 'User' }, + user: { type: Schema.ObjectId, ref: 'User' }, name: { type: String, default: '', trim: true }, description: {type: String, default: '', trim: true }, currency: { type: String, default: 'kr', trim: true }, public: { type: String, default: 'invite-only' }, created: { type: Date, default: Date.now }, - updated: { type: Date, default: Date.now } + updated: { type: Date, default: Date.now }, + shortURL: { type: String, unique: true } }); - // the four validations below only apply if you are signing up traditionally ProjectSchema.path('name').validate(function(name) { @@ -28,12 +24,44 @@ ProjectSchema.path('name').validate(function(name) { return name.length; }, 'Project name cannot be blank'); -ProjectSchema.methods = { + +ProjectSchema.pre('save', function(next) { + if (this.shortURL !== undefined) return next(); + var chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; + this.shortURL = ''; + for (var i = 0; i < 6; i++) { + var x = Math.floor(Math.random() * chars.length); + this.shortURL += chars.charAt(x); + } + console.log('SHORT: ' + this.shortURL); + next(); +}); + + + +ProjectSchema.statics = { log: function() { console.log('wat. wat logged this'); + }, + + + + /** + * Find project by id + * + * @param {ObjectId} id + * @param {Function} callback + * @api private + */ + + load: function(id, callback) { + this.findOne({ _id: id }) + .populate('user') + .exec(callback); } + } mongoose.model('Project', ProjectSchema); diff --git a/public/img/androidA.png b/public/img/androidA.png Binary files differindex a0c2f94..afb53f9 100644 --- a/public/img/androidA.png +++ b/public/img/androidA.png diff --git a/public/img/androidA@2x.png b/public/img/androidA@2x.png Binary files differindex 5b80fd9..204c8d0 100644 --- a/public/img/androidA@2x.png +++ b/public/img/androidA@2x.png diff --git a/public/img/dashboard.png b/public/img/dashboard.png Binary files differindex 1b82ffc..0fdbc1f 100644 --- a/public/img/dashboard.png +++ b/public/img/dashboard.png diff --git a/public/img/dashboard@2x.png b/public/img/dashboard@2x.png Binary files differindex 4f582b8..b154265 100644 --- a/public/img/dashboard@2x.png +++ b/public/img/dashboard@2x.png diff --git a/public/img/iphoneA.png b/public/img/iphoneA.png Binary files differindex 3d35eaf..0e0399a 100644 --- a/public/img/iphoneA.png +++ b/public/img/iphoneA.png diff --git a/public/img/iphoneA@2x.png b/public/img/iphoneA@2x.png Binary files differindex a341671..e519291 100644 --- a/public/img/iphoneA@2x.png +++ b/public/img/iphoneA@2x.png diff --git a/public/img/par.png b/public/img/par.png Binary files differindex 5b9beb2..3637a8e 100644 --- a/public/img/par.png +++ b/public/img/par.png diff --git a/public/img/par@2x.png b/public/img/par@2x.png Binary files differindex 1797663..6c15675 100644 --- a/public/img/par@2x.png +++ b/public/img/par@2x.png diff --git a/public/img/winA.png b/public/img/winA.png Binary files differindex b19d985..62bdb33 100644 --- a/public/img/winA.png +++ b/public/img/winA.png diff --git a/public/img/winA@2x.png b/public/img/winA@2x.png Binary files differindex 638145e..cdb2313 100644 --- a/public/img/winA@2x.png +++ b/public/img/winA@2x.png @@ -50,7 +50,7 @@ module.exports = function(app, passport, auth) { */ - app.get('/dashboard', system.dashboard); + app.get('/dashboard', auth.requiresLogin, system.dashboard); app.get('/project', auth.requiresLogin, system.project); diff --git a/views/dashboard.ejs b/views/dashboard.ejs index 5eca9f1..dfd76f6 100644 --- a/views/dashboard.ejs +++ b/views/dashboard.ejs @@ -12,24 +12,26 @@ <div class="smallfullwidth span5"> <h1>Prosjekter</h1> <section class="projects"> - <section class="project"> - <div class="row-fluid"> - <div class="span11"> - <h1><a href="/project">dennisse/<strong>hytteturskogentilfrank</strong></a></h1> - <div class="row-fluid"> - <div class="span8"> - <small>Meg, Robert, Turid-Laila, Kurt, Stian, Aleksander, Frank, Olav, Heidi, Anette, Kristine</small> - </div> - <div class="span4"> - <small>Oppgjør: <span class="text-error">-200 kr</span></small> + <% projects.forEach(function(projects) { %> + <section class="project"> + <div class="row-fluid"> + <div class="span11"> + <h1><a href="/project/<%= projects.project.shortURL %>"><%= projects.project.user.username %>/<strong><%= projects.project.name %></strong></a></h1> + <div class="row-fluid"> + <div class="span8"> + <small>Meg, Robert, Turid-Laila, Kurt, Stian, Aleksander, Frank, Olav, Heidi, Anette, Kristine</small> + </div> + <div class="span4"> + <small>Oppgjør: <span class="text-error">-200 kr</span></small> + </div> </div> </div> + <div class="span1"> + <p>+</p> + </div> </div> - <div class="span1"> - <p>+</p> - </div> - </div> - </section> + </section> + <% }); %> <section class="project"> <div class="row-fluid"> <div class="span11"> |