diff options
| author | Jules Laplace <jules@okfoc.us> | 2014-10-09 17:26:24 -0400 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2014-10-09 17:26:24 -0400 |
| commit | 4d4add72dec5d5f1db96430fe2de21c09451ebea (patch) | |
| tree | e9746b90ad929a3827f5db8187c92a6fdb216d39 | |
| parent | 376d300765870960e161c96324693a2c21e0194b (diff) | |
feature projects, show featured projects on homepage, fix profile sort
| -rw-r--r-- | public/assets/javascripts/ui/site/StaffView.js | 23 | ||||
| -rwxr-xr-x | public/assets/stylesheets/app.css | 3 | ||||
| -rw-r--r-- | server/lib/schemas/Project.js | 1 | ||||
| -rw-r--r-- | server/lib/views/index.js | 42 | ||||
| -rw-r--r-- | server/lib/views/staff.js | 15 | ||||
| -rwxr-xr-x | views/home.ejs | 5 | ||||
| -rw-r--r-- | views/staff/projects/show.ejs | 13 |
7 files changed, 84 insertions, 18 deletions
diff --git a/public/assets/javascripts/ui/site/StaffView.js b/public/assets/javascripts/ui/site/StaffView.js index fdf39d2..0398f71 100644 --- a/public/assets/javascripts/ui/site/StaffView.js +++ b/public/assets/javascripts/ui/site/StaffView.js @@ -3,14 +3,19 @@ var StaffView = View.extend({ events: { "click #toggle-staff": "toggleStaff", + "click #toggle-featured": "toggleFeatured", }, initialize: function() { this.$toggleStaff = $("#toggle-staff") + this.$toggleFeatured = $("#toggle-featured") this.$mediaEmbed = $("#media-embed") if (this.$toggleStaff.length && this.$toggleStaff.data().isstaff) { this.$toggleStaff.html("Is Staff") } + if (this.$toggleFeatured.length && this.$toggleFeatured.data().featured) { + this.$toggleFeatured.html("Featured Project") + } if (this.$mediaEmbed.length) { var media = this.$mediaEmbed.data() this.$mediaEmbed.html( Parser.tag( media ) ) @@ -44,6 +49,24 @@ var StaffView = View.extend({ }.bind(this) }) }.bind(this)) + }, + + toggleFeatured: function(){ + var state = ! this.$toggleFeatured.data().featured + $.ajax({ + type: "put", + dataType: "json", + url: window.location.href + "/feature", + data: { + state: state, + _csrf: $("#_csrf").val(), + }, + success: function(data){ + this.$toggleFeatured.data("featured", data.state) + this.$toggleFeatured.html(data.state ? "Featured Project" : "Feature this project") + $("#isFeaturedProject").html(data.state ? "yes" : "no") + }.bind(this) + }) }, }) diff --git a/public/assets/stylesheets/app.css b/public/assets/stylesheets/app.css index 9a2f6f8..85d14eb 100755 --- a/public/assets/stylesheets/app.css +++ b/public/assets/stylesheets/app.css @@ -357,6 +357,9 @@ iframe.embed { background-color: #ddd; background-size: cover; } +.projectList a:hover .room .mask { + background-color: rgba(238,238,238,0.1); +} .room .images { position: absolute; top: 0; left: 0; diff --git a/server/lib/schemas/Project.js b/server/lib/schemas/Project.js index abf34fb..dd50da6 100644 --- a/server/lib/schemas/Project.js +++ b/server/lib/schemas/Project.js @@ -35,6 +35,7 @@ var ProjectSchema = new mongoose.Schema({ user_id: { type: mongoose.Schema.ObjectId, index: true }, created_at: { type: Date }, updated_at: { type: Date }, + featured: { type: Boolean, default: false }, }); module.exports = exports = mongoose.model('project', ProjectSchema); diff --git a/server/lib/views/index.js b/server/lib/views/index.js index 3f3880f..1b547ef 100644 --- a/server/lib/views/index.js +++ b/server/lib/views/index.js @@ -79,10 +79,20 @@ views.modal = function (req, res) { views.home = function (req, res) { if (req.user) { - Project.find({ privacy: false }) + Project.find({ featured: true }) .sort('-created_at') - .limit(20) + .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.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 || [] }) }) } @@ -135,19 +145,21 @@ views.profile = function (req, res) { if ( ! (req.user && req.user._id && req.user._id == user._id) ) { criteria.privacy = false } - Project.find(criteria, function(err, projects){ - projects = projects.map(function(project){ - project = project.toObject() - project.date = moment(project.updated_at).format("M/DD/YYYY") - if (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) - }) + 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.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) + }) } function done(err, user, projects){ diff --git a/server/lib/views/staff.js b/server/lib/views/staff.js index 41877c8..da09d83 100644 --- a/server/lib/views/staff.js +++ b/server/lib/views/staff.js @@ -389,6 +389,15 @@ var staff = module.exports = { staff.projects.show ); + app.put('/staff/projects/:slug/feature', + middleware.ensureAuthenticated, + middleware.ensureIsStaff, + + middleware.ensureProject, + staff.middleware.ensureProject, + + staff.projects.feature + ); // // media @@ -505,6 +514,12 @@ var staff = module.exports = { res.render('staff/projects/show_404') } }, + feature: function(req, res){ + res.locals.project.featured = req.body.state == "true" + res.locals.project.save(function(err, project){ + res.json({ state: project.featured }) + }) + }, }, media: { diff --git a/views/home.ejs b/views/home.ejs index 51d5a92..7ec8c1e 100755 --- a/views/home.ejs +++ b/views/home.ejs @@ -62,10 +62,9 @@ </div> <h1>Room Showcase</h1> - <img src="https://s3.amazonaws.com/uploads.hipchat.com/14935/55226/twq38ErgSnriaOq/vvalls-thumbnail-options2.gif" style="border-top:1px solid;width:100%"> - <!-- + [[ include projects/list-projects ]] - --> + <a href="#loadmore" class="viewMore btn">View More</a> [[ include partials/confirm-modal ]] diff --git a/views/staff/projects/show.ejs b/views/staff/projects/show.ejs index 687f0c2..1034b31 100644 --- a/views/staff/projects/show.ejs +++ b/views/staff/projects/show.ejs @@ -41,8 +41,21 @@ "[[- project.description ]]" </td> </tr> + <tr> + <th> + featured? + </th> + <td id="isFeaturedProject"> + [[- project.featured ? "yes" : "no" ]] + </td> + </tr> </table> + <br><br> + <div id="actions"> + <button id="toggle-featured" data-featured="[[- !! project.featured ]]">Feature this Project</button> + </div> + <br> <br> <table id="iframe-embed" class="projectList"> |
