summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--public/assets/javascripts/ui/lib/Router.js1
-rw-r--r--public/assets/javascripts/ui/site/ProjectList.js28
-rw-r--r--server/index.js1
-rw-r--r--server/lib/views/index.js123
-rw-r--r--views/projects/list-projects.ejs6
5 files changed, 112 insertions, 47 deletions
diff --git a/public/assets/javascripts/ui/lib/Router.js b/public/assets/javascripts/ui/lib/Router.js
index 0b6385c..28905b2 100644
--- a/public/assets/javascripts/ui/lib/Router.js
+++ b/public/assets/javascripts/ui/lib/Router.js
@@ -16,6 +16,7 @@ var Router = View.extend({
if (pathname in routes) {
this[this.routes[pathname]](null)
+ return
}
if (path[path.length-1] == null) {
diff --git a/public/assets/javascripts/ui/site/ProjectList.js b/public/assets/javascripts/ui/site/ProjectList.js
index ebb0a96..27c8aca 100644
--- a/public/assets/javascripts/ui/site/ProjectList.js
+++ b/public/assets/javascripts/ui/site/ProjectList.js
@@ -1,14 +1,17 @@
var projectListTimeout = null
+window.fuck = 'suck'
var ProjectList = View.extend({
el: ".projectList",
events: {
+ "click .viewMore": 'viewMore',
"mouseenter .room": 'enter',
"mouseleave .room": 'leave',
},
initialize: function(){
+ this.$viewMore = this.$(".viewMore")
this.$(".images").each(function(){
$divs = $(this).children("div")
$divs.hide()
@@ -41,7 +44,30 @@ var ProjectList = View.extend({
$divs.eq(index).hide()
$divs.eq(nextIndex).show()
$images.data("index", nextIndex)
- }
+ },
+
+ viewMore: function(e){
+ e.preventDefault()
+ var criteria = {}
+ criteria.offset = this.$(".projectItem").length
+ if (window.location.pathname == "/" || window.location.pathname.match("/home")) {
+ criteria.home = 1
+ }
+ else {
+ criteria.user_id = this.$(".projectItem").first().data("userid")
+ }
+
+ $.get("/api/project/paginate", criteria, function(data){
+ var offset = this.$viewMore.offset()
+ var $data = $(data)
+ var $els = $data.find(".projectItem")
+ $els.insertBefore( this.$viewMore )
+ if (! $data.find(".viewMore").length) {
+ this.$viewMore.hide()
+ }
+ $("body,html").animate({ scrollTop: offset.top - 80 }, 300)
+ }.bind(this))
+ },
/*
spinOn: function(e){
diff --git a/server/index.js b/server/index.js
index f6636dd..8f66418 100644
--- a/server/index.js
+++ b/server/index.js
@@ -133,6 +133,7 @@ site.route = function () {
app.delete('/api/layout/destroy', middleware.ensureAuthenticated, middleware.ensureIsStaff, api.layouts.destroy)
app.get('/api/project', middleware.ensureAuthenticated, api.projects.index)
+ app.get('/api/project/paginate', views.projectsPaginate)
app.get('/api/project/:slug', api.projects.show)
app.get('/api/rooms/:slug', api.rooms.show)
app.post('/api/project/new', middleware.ensureAuthenticated, api.projects.create)
diff --git a/server/lib/views/index.js b/server/lib/views/index.js
index 5b1a72e..eacff1f 100644
--- a/server/lib/views/index.js
+++ b/server/lib/views/index.js
@@ -78,27 +78,16 @@ var views = module.exports = {
},
home: function (req, res) {
- if (req.user) {
- Project.find({ featured: true })
- .sort('-created_at')
- .limit(6)
- .exec(function(err, projects){
- projects = projects.map(function(project){
- project = project.toObject()
- project.date = moment(project.updated_at).format("M/DD/YYYY")
- if (! project.colors || project.colors.wall && project.colors.wall[0] == project.colors.wall[1] && project.colors.wall[1] == project.colors.wall[2] && project.colors.wall[2] > 238) {
- project.color = [238,238,238]
- } else {
- project.color = project.colors.wall
- }
- return project
- })
- res.render('home', { projects: projects || [] })
- })
- }
- else {
- res.send("<html></html>")
+ // while in development, blank homepage if not logged in
+ if (! req.user) {
+ res.send("<html></html>")
+ return
}
+ views_middleware.fetchProjects({ featured: true }, null, null, function(err, projects){
+ res.render('home', {
+ projects: projects || []
+ })
+ })
},
docs: function (req, res){
@@ -131,45 +120,93 @@ var views = module.exports = {
profile: function (req, res) {
var username = req.params.username || (req.user && req.user.username)
+ var user, isOwnProfile = false
if (username) {
- User.findOne({ username: username }, function (err, user) {
- user ? next(user) : done(err, {}, [])
+ User.findOne({ username: username }, function (err, profileUser) {
+ if (profileUser) {
+ user = profileUser
+ isOwnProfile = (String(user._id) == (req.user && String(req.user._id)))
+ next()
+ }
+ else {
+ done(err, [])
+ }
})
}
else {
done()
}
- function next(user){
+ function next(){
var criteria = { user_id: user._id }
- if ( ! (req.user && req.user._id && req.user._id == user._id) ) {
+ if ( ! isOwnProfile ) {
criteria.privacy = false
}
- Project.find(criteria)
- .sort('-created_at')
- .exec(function(err, projects){
- projects = projects.map(function(project){
- project = project.toObject()
- project.date = moment(project.updated_at).format("M/DD/YYYY")
- if (! project.colors || project.colors.wall && project.colors.wall[0] == project.colors.wall[1] && project.colors.wall[1] == project.colors.wall[2] && project.colors.wall[2] > 238) {
- project.color = [238,238,238]
- } else {
- project.color = project.colors.wall
- }
- return project
- })
- done(err, user, projects)
- })
+ views_middleware.fetchProjects(criteria, null, null, done)
}
- function done(err, user, projects){
+ function done(err, projects){
if (! user) { return res.redirect('/') }
res.render('profile', {
- isOwnProfile: String(user._id) == (req.user && String(req.user._id)),
+ isOwnProfile: isOwnProfile,
profile: user,
projects: projects || [],
})
}
- }
+ },
+
+ projectsPaginate: function(req, res) {
+ var criteria = {}
+ var offset = Number(req.query.offset || 0)
+ var user_id, isOwnProfile
+
+ if (req.query.home) {
+ criteria.featured = true
+ criteria.privacy = false
+ }
+ else if (req.query.user_id) {
+ user_id = req.query.user_id
+ isOwnProfile = (String(user_id) == (req.user && String(req.user._id)))
+
+ criteria.user_id = user_id
+ if ( ! isOwnProfile ) {
+ criteria.privacy = false
+ }
+ }
+ else {
+ res.end("")
+ return
+ }
+
+ views_middleware.fetchProjects(criteria, null, offset, function(err, projects){
+ res.render('projects/list-projects', {
+ projects: projects || []
+ })
+ })
+ },
+
+}
-} \ No newline at end of file
+var views_middleware = {
+ fetchProjects: function (criteria, limit, offset, next) {
+ limit = limit || 7
+ offset = offset || 0
+ Project.find(criteria)
+ .sort('-created_at')
+ .skip(offset)
+ .limit(limit)
+ .exec(function(err, projects){
+ projects = projects.map(function(project){
+ project = project.toObject()
+ project.date = moment(project.updated_at).format("M/D/YYYY")
+ if (! project.colors || project.colors.wall && project.colors.wall[0] == project.colors.wall[1] && project.colors.wall[1] == project.colors.wall[2] && project.colors.wall[2] > 238) {
+ project.color = [238,238,238]
+ } else {
+ project.color = project.colors.wall
+ }
+ return project
+ })
+ next(err, projects)
+ })
+ }
+}
diff --git a/views/projects/list-projects.ejs b/views/projects/list-projects.ejs
index eb66449..5ecaec1 100644
--- a/views/projects/list-projects.ejs
+++ b/views/projects/list-projects.ejs
@@ -1,13 +1,13 @@
[[ if (projects.length) { ]]
-
+
<div class="projectList">
[[ projects.forEach(function(project, i) { ]]
[[ if (i > 5) { return } ]]
[[ if (String(user._id) == String(project.user_id)) { ]]
- <a href="/project/[[- project.slug ]]/edit" class="projectItem">
+ <a href="/project/[[- project.slug ]]/edit" class="projectItem" data-userid="[[- project.user_id ]]">
[[ } else { ]]
- <a href="/project/[[- project.slug ]]" class="projectItem">
+ <a href="/project/[[- project.slug ]]" class="projectItem" data-userid="[[- project.user_id ]]">
[[ } ]]
<span class="room" style="background-color: rgb([[- project.color ]]);">