This repository has been archived by the owner on Feb 13, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
=frank tree
committed
Dec 10, 2014
1 parent
24358dd
commit 512e1a9
Showing
191 changed files
with
111,550 additions
and
327 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
|
||
/** | ||
* Module dependencies. | ||
*/ | ||
"use strict"; | ||
|
||
var mongoose = require('mongoose'); | ||
var Article = mongoose.model('Article'); | ||
var Table = mongoose.model('Table'); | ||
var utils = require('../../lib/utils'); | ||
var extend = require('util')._extend; | ||
|
||
exports.index = function (req, res){ | ||
var tableOptions = { | ||
perPage: 8, | ||
criteria: { | ||
isPrivate: false | ||
} | ||
}; | ||
|
||
Table.list(tableOptions, function (err, tables) { | ||
if (err) return res.render('500'); | ||
Table.count().exec(function (err, count) { | ||
Article.list({}, function (err, articles) { | ||
if (err) return res.render('500'); | ||
Article.count().exec(function (err, count) { | ||
res.render('home/index', { | ||
title: 'Tablemania', | ||
articles: articles, | ||
tables: tables | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/** | ||
* Module dependencies. | ||
*/ | ||
"use strict"; | ||
|
||
var mongoose = require('mongoose'); | ||
var Table = mongoose.model('Table'); | ||
var utils = require('../../lib/utils'); | ||
|
||
|
||
/** | ||
* Load | ||
*/ | ||
|
||
exports.load = function (req, res, next, id){ | ||
Table.load(id, function (err, table) { | ||
if (err) return next(err); | ||
if (!table) return next(new Error('not found')); | ||
req.table = table; | ||
next(); | ||
}); | ||
}; | ||
|
||
/** | ||
* List | ||
*/ | ||
|
||
exports.index = function (req, res){ | ||
var page = (req.param('page') > 0 ? req.param('page') : 1) - 1; | ||
var perPage = 30; | ||
var options = { | ||
perPage: perPage, | ||
page: page | ||
}; | ||
options.criteria = res.locals.isAdmin ? {} : { isPrivate: false}; | ||
|
||
// res.render('game/index', {layout: false, title: 'game room'}); | ||
|
||
Table.list(options, function (err, tables) { | ||
if (err) return res.render('500'); | ||
Table.count().exec(function (err, count) { | ||
res.render('tables/index', { | ||
title: 'Public Tables', | ||
tables: tables, | ||
page: page + 1, | ||
pages: Math.ceil(count / perPage) | ||
}); | ||
}); | ||
}); | ||
|
||
|
||
}; | ||
|
||
|
||
/** | ||
* New table | ||
*/ | ||
|
||
exports.new = function (req, res){ | ||
res.render('tables/new', { | ||
title: 'New Table', | ||
table: new Table({}) | ||
}); | ||
}; | ||
|
||
|
||
|
||
/** | ||
* Create a table | ||
*/ | ||
|
||
exports.create = function (req, res) { | ||
console.log('create table', req.body); | ||
var table = new Table(req.body); | ||
|
||
table.save(function (err) { | ||
if (!err) { | ||
req.flash('success', 'Successfully created table!'); | ||
return res.redirect('/tables/'+table._id); | ||
} | ||
console.log(err); | ||
res.render('tables/new', { | ||
title: 'New Table', | ||
table: table, | ||
errors: utils.errors(err.errors || err) | ||
}); | ||
}); | ||
}; | ||
|
||
|
||
/** | ||
* Show | ||
*/ | ||
|
||
exports.show = function (req, res){ | ||
var table = req.table; | ||
|
||
console.log('tables show'); | ||
res.render('tables/show', { | ||
title: 'Table Lobby', | ||
table: table | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
|
||
/** | ||
* Module dependencies. | ||
*/ | ||
|
||
var mongoose = require('mongoose'); | ||
var Schema = mongoose.Schema; | ||
|
||
/** | ||
* Getters | ||
*/ | ||
|
||
var getTags = function (tags) { | ||
return tags.join(','); | ||
}; | ||
|
||
/** | ||
* Setters | ||
*/ | ||
|
||
var setTags = function (tags) { | ||
return tags.split(','); | ||
}; | ||
|
||
/** | ||
* Table Schema | ||
*/ | ||
|
||
var TableSchema = new Schema({ | ||
title: {type : String, default : '', trim : true}, | ||
isPrivate: {type : Boolean, default : false}, | ||
users: [{ | ||
user: {type : Schema.ObjectId, ref : 'User'} | ||
}], | ||
tags: {type: [], get: getTags, set: setTags}, | ||
createdAt : {type : Date, default : Date.now} | ||
}); | ||
|
||
/** | ||
* Validations | ||
*/ | ||
|
||
TableSchema.path('title').required(true, 'Table title cannot be blank'); | ||
|
||
|
||
|
||
/** | ||
* Methods | ||
*/ | ||
|
||
TableSchema.methods = { | ||
|
||
|
||
}; | ||
|
||
/** | ||
* Statics | ||
*/ | ||
|
||
TableSchema.statics = { | ||
|
||
/** | ||
* Find table by id | ||
* | ||
* @param {ObjectId} id | ||
* @param {Function} cb | ||
* @api private | ||
*/ | ||
|
||
load: function (id, cb) { | ||
this.findOne({ _id : id }) | ||
.exec(cb); | ||
}, | ||
|
||
/** | ||
* List tables | ||
* | ||
* @param {Object} options | ||
* @param {Function} cb | ||
* @api private | ||
*/ | ||
|
||
list: function (options, cb) { | ||
var criteria = options.criteria || {}; | ||
|
||
this.find(criteria) | ||
.populate('user', 'name username') | ||
.sort({'createdAt': -1}) // sort by date | ||
.limit(options.perPage) | ||
.skip(options.perPage * options.page) | ||
.exec(cb); | ||
} | ||
}; | ||
|
||
mongoose.model('Table', TableSchema); |
Oops, something went wrong.