From 01eaa246c7aebcea616eccf7989c63ac6f54fdf0 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 4 Sep 2014 15:30:07 -0400 Subject: project view --- public/assets/javascripts/ui/site/StaffView.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 public/assets/javascripts/ui/site/StaffView.js (limited to 'public/assets/javascripts/ui/site/StaffView.js') diff --git a/public/assets/javascripts/ui/site/StaffView.js b/public/assets/javascripts/ui/site/StaffView.js new file mode 100644 index 0000000..115d417 --- /dev/null +++ b/public/assets/javascripts/ui/site/StaffView.js @@ -0,0 +1,14 @@ +var StaffView = View.extend({ + + initialize: function() { + }, + + load: function() { + $(".json").each(function(){ + $(this).JSONView( this.innerText ) + }) + + this.projectList = new ProjectList () + } + +}) -- cgit v1.2.3-70-g09d2 From 8bf2ead240f5daeac98b3a92c81f37b77fd4ddbd Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 4 Sep 2014 16:24:00 -0400 Subject: make users admins --- public/assets/javascripts/ui/site/StaffView.js | 29 ++++++++++- server/lib/views/staff.js | 22 ++++---- views/staff/_header.ejs | 1 + views/staff/_users.ejs | 6 +++ views/staff/_users_recent.ejs | 8 +++ views/staff/users/show.ejs | 70 ++++++++++++++++++++++++++ 6 files changed, 125 insertions(+), 11 deletions(-) (limited to 'public/assets/javascripts/ui/site/StaffView.js') diff --git a/public/assets/javascripts/ui/site/StaffView.js b/public/assets/javascripts/ui/site/StaffView.js index 115d417..8f677cb 100644 --- a/public/assets/javascripts/ui/site/StaffView.js +++ b/public/assets/javascripts/ui/site/StaffView.js @@ -1,6 +1,15 @@ var StaffView = View.extend({ + el: ".page", + + events: { + "click #toggle-staff": "toggleStaff", + }, initialize: function() { + this.$toggleStaff = $("#toggle-staff") + if (this.$toggleStaff.data().isstaff) { + this.$toggleStaff.html("Is Staff") + } }, load: function() { @@ -9,6 +18,24 @@ var StaffView = View.extend({ }) this.projectList = new ProjectList () - } + }, + + toggleStaff: function(){ + var state = ! this.$toggleStaff.data().isstaff + $.ajax({ + type: "put", + dataType: "json", + url: window.location.href + "/bless", + data: { + state: state, + _csrf: $("#_csrf").val(), + }, + success: function(data){ + this.$toggleStaff.data("isstaff", data.state) + this.$toggleStaff.html(data.state ? "Is Staff" : "Make Staff") + $("#is-staff").html(data.state ? "yes" : "no") + }.bind(this) + }) + }, }) diff --git a/server/lib/views/staff.js b/server/lib/views/staff.js index ae414d7..b78fd5a 100644 --- a/server/lib/views/staff.js +++ b/server/lib/views/staff.js @@ -111,7 +111,7 @@ var staff = module.exports = { if (username) { User.findOne({ username: username }, function (err, user) { if (user) { - res.locals.profile = staff.helpers.user(user) + res.locals.profile = req.method == "GET" ? staff.helpers.user(user) : user } else { res.locals.profile = null @@ -236,6 +236,14 @@ var staff = module.exports = { staff.users.show ); + app.put('/staff/users/:username/bless', + middleware.ensureAuthenticated, + middleware.ensureIsStaff, + + staff.middleware.ensureProfile, + + staff.users.bless + ); app.get('/staff/projects', middleware.ensureAuthenticated, middleware.ensureIsStaff, @@ -259,12 +267,6 @@ var staff = module.exports = { staff.projects.show ); - app.put('/staff/users/:username/bless', - middleware.ensureAuthenticated, - middleware.ensureIsStaff, - - staff.users.bless - ); }, index: function(req, res){ @@ -288,9 +290,9 @@ var staff = module.exports = { } }, bless: function(req, res){ - res.locals.profile.isStaff = req.body.isStaff - res.locals.profile.save(function(){ - res.redirect("/staff") + res.locals.profile.isStaff = req.body.state == "true" + res.locals.profile.save(function(err, user){ + res.json({ state: user.isStaff }) }) }, }, diff --git a/views/staff/_header.ejs b/views/staff/_header.ejs index 1880c98..3bbf4f1 100644 --- a/views/staff/_header.ejs +++ b/views/staff/_header.ejs @@ -5,6 +5,7 @@ [[ include ../partials/meta ]] +
diff --git a/views/staff/_users.ejs b/views/staff/_users.ejs index ab8c9b3..344ee0c 100644 --- a/views/staff/_users.ejs +++ b/views/staff/_users.ejs @@ -1,12 +1,18 @@ [[ users.forEach(function(user){ ]] + + diff --git a/views/staff/_users_recent.ejs b/views/staff/_users_recent.ejs index ff3fd55..e55fe28 100644 --- a/views/staff/_users_recent.ejs +++ b/views/staff/_users_recent.ejs @@ -6,9 +6,17 @@ [[ users.forEach(function(user){ ]] + + diff --git a/views/staff/users/show.ejs b/views/staff/users/show.ejs index d306443..2315043 100644 --- a/views/staff/users/show.ejs +++ b/views/staff/users/show.ejs @@ -9,8 +9,78 @@
+
+
+
[[- user.username ]] [[- user.displayName ]] [[- user.last_seen ]]
+ [[ if (user.photo) { ]] +
+ [[ } ]] +
[[- user.username ]] [[- user.displayName ]]
+ + + + + + +
+
+
+ [[- profile.username ]] + + [[- profile.displayName ]] +
+
+ + + + + + + + + + + + + + + + + + + + + + +
+ location + + [[- profile.location ]] +
+ last seen + + [[- profile.last_seen ]] +
+ ip addresses + + [[- profile.created_ip ]] + [[- profile.last_ip ]] +
+ is admin? + + [[- profile.isStaff ? "yes" : "no" ]] +
+ + [[ if (String(user._id) != String(profile._id)) { ]] + + [[ } ]] +
+

[[- profileJSON ]]
[[ include ../_footer ]] + \ No newline at end of file -- cgit v1.2.3-70-g09d2 From 415dad29407362a76fde6d07d8b100285a84518d Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 4 Sep 2014 17:52:48 -0400 Subject: media api --- public/assets/img/profile.png | Bin 0 -> 9320 bytes public/assets/javascripts/ui/site/StaffView.js | 33 +++--- public/assets/stylesheets/staff.css | 4 + server/lib/views/staff.js | 141 ++++++++++++++++++++++--- views/staff/_media.ejs | 1 + views/staff/_stats.ejs | 4 + views/staff/_users.ejs | 2 +- views/staff/_users_recent.ejs | 6 +- views/staff/index.ejs | 1 + views/staff/media/index.ejs | 16 +++ views/staff/media/show.ejs | 14 +++ views/staff/media/show_404.ejs | 14 +++ views/staff/projects/index.ejs | 2 + views/staff/projects/show.ejs | 1 + views/staff/projects/show_404.ejs | 2 + views/staff/users/index.ejs | 2 + views/staff/users/show.ejs | 26 +++-- views/staff/users/show_404.ejs | 1 + 18 files changed, 230 insertions(+), 40 deletions(-) create mode 100644 public/assets/img/profile.png create mode 100644 views/staff/_media.ejs create mode 100644 views/staff/media/index.ejs create mode 100644 views/staff/media/show.ejs create mode 100644 views/staff/media/show_404.ejs (limited to 'public/assets/javascripts/ui/site/StaffView.js') diff --git a/public/assets/img/profile.png b/public/assets/img/profile.png new file mode 100644 index 0000000..bde68e0 Binary files /dev/null and b/public/assets/img/profile.png differ diff --git a/public/assets/javascripts/ui/site/StaffView.js b/public/assets/javascripts/ui/site/StaffView.js index 8f677cb..fd173e5 100644 --- a/public/assets/javascripts/ui/site/StaffView.js +++ b/public/assets/javascripts/ui/site/StaffView.js @@ -7,7 +7,7 @@ var StaffView = View.extend({ initialize: function() { this.$toggleStaff = $("#toggle-staff") - if (this.$toggleStaff.data().isstaff) { + if (this.$toggleStaff.length && this.$toggleStaff.data().isstaff) { this.$toggleStaff.html("Is Staff") } }, @@ -22,20 +22,23 @@ var StaffView = View.extend({ toggleStaff: function(){ var state = ! this.$toggleStaff.data().isstaff - $.ajax({ - type: "put", - dataType: "json", - url: window.location.href + "/bless", - data: { - state: state, - _csrf: $("#_csrf").val(), - }, - success: function(data){ - this.$toggleStaff.data("isstaff", data.state) - this.$toggleStaff.html(data.state ? "Is Staff" : "Make Staff") - $("#is-staff").html(data.state ? "yes" : "no") - }.bind(this) - }) + var verb = state ? "promote this user to staff?" : "remove this user from staff?" + ConfirmModal.confirm("Are you sure you want to " + verb, function(){ + $.ajax({ + type: "put", + dataType: "json", + url: window.location.href + "/bless", + data: { + state: state, + _csrf: $("#_csrf").val(), + }, + success: function(data){ + this.$toggleStaff.data("isstaff", data.state) + this.$toggleStaff.html(data.state ? "Is Staff" : "Make Staff") + $("#is-staff").html(data.state ? "yes" : "no") + }.bind(this) + }) + }.bind(this)) }, }) diff --git a/public/assets/stylesheets/staff.css b/public/assets/stylesheets/staff.css index 9b9226f..02510a3 100644 --- a/public/assets/stylesheets/staff.css +++ b/public/assets/stylesheets/staff.css @@ -78,6 +78,10 @@ h2 { display: inline-block; background-size: cover; } +#actions button { + float: none; + width: auto; +} iframe.embed { position: static; width: 100%; diff --git a/server/lib/views/staff.js b/server/lib/views/staff.js index b78fd5a..b9fe78a 100644 --- a/server/lib/views/staff.js +++ b/server/lib/views/staff.js @@ -28,10 +28,10 @@ var staff = module.exports = { middleware: { ensureUsers: function(req, res, next){ - var limit = Math.max( Number(req.params.limit) || 50, 200 ) - var offset = Number(req.params.offset) || 0 + var limit = Math.max( Number(req.query.limit) || 50, 200 ) + var offset = Number(req.query.offset) || 0 var sort - switch (req.params.sort) { + switch (req.query.sort) { case 'date': sort = {'created_at': -1} break @@ -60,9 +60,10 @@ var staff = module.exports = { }, ensureProjects: function(req, res, next){ - var offset = Number(req.params.offset) || 0 + var limit = Math.max( Number(req.query.limit) || 50, 200 ) + var offset = Number(req.query.offset) || 0 var sort - switch (req.params.sort) { + switch (req.query.sort) { case 'date': sort = {'created_at': -1} break @@ -74,13 +75,34 @@ var staff = module.exports = { .select(staff.fields.project) .sort(sort) .skip(offset) - .limit(50) + .limit(limit) .exec(function (err, projects) { res.locals.projects = projects.map(staff.helpers.project) next() }) }, + ensureMedia: function(req, res, next){ + var limit = Math.max( Number(req.query.limit) || 50, 200 ) + var offset = Number(req.query.offset) || 0 + var sort + switch (req.query.sort) { + default: + case 'date': + sort = {'created_at': -1} + break + } + Media.find({}) + // .select(staff.fields.media) + .sort(sort) + .skip(offset) + .limit(limit) + .exec(function (err, media) { + res.locals.media = media.map(staff.helpers.media) + next() + }) + }, + ensureRecentProjects: function(req, res, next){ var dreq = { params: { sort: 'created_at', limit: 20, offset: 0 } } staff.middleware.ensureProjects(dreq, res, next) @@ -88,18 +110,32 @@ var staff = module.exports = { ensureProjectsUsers: function(req, res, next){ if (! res.locals.projects || ! res.locals.projects.length) { return next() } + staff.middleware.ensureObjectsUsers(res.locals.projects, next) + }, + + ensureMediaUsers: function(req, res, next){ + if (! res.locals.media || ! res.locals.media.length) { return next() } + staff.middleware.ensureObjectsUsers(res.locals.media, next) + }, + + ensureMediaUser: function(req, res, next){ + if (! res.locals.media) { return next() } + staff.middleware.ensureObjectsUsers([ res.locals.media ], next) + }, + + ensureObjectsUsers: function(objects, next){ var dedupe = {}, user_ids - res.locals.projects.forEach(function(project){ - dedupe[ project.user_id ] = dedupe[ project.user_id ] || [] - dedupe[ project.user_id ].push(project) + objects.forEach(function(obj){ + dedupe[ obj.user_id ] = dedupe[ obj.user_id ] || [] + dedupe[ obj.user_id ].push(obj) }) user_ids = _.keys(dedupe) User.find({ _id: user_ids }) .select(staff.fields.user) .exec(function (err, users) { users.forEach(function(user){ - dedupe[user._id].forEach(function(project){ - project.user = user + dedupe[user._id].forEach(function(obj){ + obj.user = user }) }) next() @@ -125,6 +161,25 @@ var staff = module.exports = { } }, + ensureSingleMedia: function(req, res, next){ + var id = req.params.id + if (id) { + Media.findOne({ _id: id }, function (err, id) { + if (media) { + res.locals.media = req.method == "GET" ? staff.helpers.media(media) : media + } + else { + res.locals.media = null + } + next() + }) + } + else { + res.locals.media = null + next() + } + }, + ensureUsersCount: function(req, res, next){ User.count({}, function(err, count){ res.locals.userCount = count || 0 @@ -138,6 +193,13 @@ var staff = module.exports = { next() }) }, + + ensureMediaCount: function(req, res, next){ + Media.count({}, function(err, count){ + res.locals.mediaCount = count || 0 + next() + }) + }, ensureProfileProjectCount: function(req, res, next){ if (! res.locals.profile) { return next() } @@ -202,7 +264,14 @@ var staff = module.exports = { project.date = moment( project.updated_at || project.created_at ).format("M/DD/YYYY H:MM") project.user = {} return project - } + }, + + media: function(media){ + media = media.toObject() + media.date = moment( media.updated_at || media.created_at ).format("M/DD/YYYY H:MM") + media.user = {} + return media + } }, route: function(app){ @@ -213,9 +282,14 @@ var staff = module.exports = { staff.middleware.ensureRecentUsers, staff.middleware.ensureUsersCount, staff.middleware.ensureProjectsCount, + staff.middleware.ensureMediaCount, staff.index ); + + // + // users + app.get('/staff/users', middleware.ensureAuthenticated, middleware.ensureIsStaff, @@ -244,6 +318,10 @@ var staff = module.exports = { staff.users.bless ); + + // + // projects + app.get('/staff/projects', middleware.ensureAuthenticated, middleware.ensureIsStaff, @@ -266,6 +344,28 @@ var staff = module.exports = { staff.projects.show ); + + // + // media + + app.get('/staff/media', + middleware.ensureAuthenticated, + middleware.ensureIsStaff, + + staff.middleware.ensureMedia, + staff.middleware.ensureMediaUsers, + + staff.media.index + ); + app.get('/staff/media/:id', + middleware.ensureAuthenticated, + middleware.ensureIsStaff, + + staff.middleware.ensureSingleMedia, + staff.middleware.ensureMediaUser, + + staff.media.show + ); }, @@ -316,5 +416,22 @@ var staff = module.exports = { } }, }, + + media: { + index: function(req, res){ + res.render('staff/media/index') + }, + show: function(req, res){ + if (res.locals.project) { + res.render('staff/media/show', { + mediaJSON: util.escape( JSON.stringify( res.locals.media ) ), + mediaUserJSON: util.escape( JSON.stringify( res.locals.mediaUser ) ), + }) + } + else { + res.render('staff/media/show_404') + } + }, + } } \ No newline at end of file diff --git a/views/staff/_media.ejs b/views/staff/_media.ejs new file mode 100644 index 0000000..27949aa --- /dev/null +++ b/views/staff/_media.ejs @@ -0,0 +1 @@ +media \ No newline at end of file diff --git a/views/staff/_stats.ejs b/views/staff/_stats.ejs index 6439ab9..d1ad96f 100644 --- a/views/staff/_stats.ejs +++ b/views/staff/_stats.ejs @@ -10,4 +10,8 @@ projects [[- projectCount ]] + + media + [[- mediaCount ]] + diff --git a/views/staff/_users.ejs b/views/staff/_users.ejs index 344ee0c..d46058f 100644 --- a/views/staff/_users.ejs +++ b/views/staff/_users.ejs @@ -11,7 +11,7 @@ [[- user.displayName ]] - [view profile] + [view profile] [[- user.last_seen ]] diff --git a/views/staff/_users_recent.ejs b/views/staff/_users_recent.ejs index e55fe28..b452c08 100644 --- a/views/staff/_users_recent.ejs +++ b/views/staff/_users_recent.ejs @@ -7,15 +7,13 @@ [[ users.forEach(function(user){ ]] - [[ if (user.photo) { ]] -
- [[ } ]] +
[[- user.username ]] - [view profile] + [view profile] [[- user.displayName ]] diff --git a/views/staff/index.ejs b/views/staff/index.ejs index 842e086..f721339 100644 --- a/views/staff/index.ejs +++ b/views/staff/index.ejs @@ -5,6 +5,7 @@
diff --git a/views/staff/media/index.ejs b/views/staff/media/index.ejs new file mode 100644 index 0000000..76aaafb --- /dev/null +++ b/views/staff/media/index.ejs @@ -0,0 +1,16 @@ +[[ include ../_header ]] + +

Media

+ + + +
+ +[[ include ../_media ]] + +[[ include ../_footer ]] diff --git a/views/staff/media/show.ejs b/views/staff/media/show.ejs new file mode 100644 index 0000000..43afe14 --- /dev/null +++ b/views/staff/media/show.ejs @@ -0,0 +1,14 @@ +[[ include ../_header ]] + +

Media [[- media.type ]]

+ + + +
+ +[[ include ../_footer ]] diff --git a/views/staff/media/show_404.ejs b/views/staff/media/show_404.ejs new file mode 100644 index 0000000..f07cef2 --- /dev/null +++ b/views/staff/media/show_404.ejs @@ -0,0 +1,14 @@ +[[ include ../_header ]] + +

Media not found

+ + + +
+ +[[ include ../_footer ]] diff --git a/views/staff/projects/index.ejs b/views/staff/projects/index.ejs index a5a9308..a6fad6b 100644 --- a/views/staff/projects/index.ejs +++ b/views/staff/projects/index.ejs @@ -1,10 +1,12 @@ [[ include ../_header ]] +

Projects


diff --git a/views/staff/projects/show.ejs b/views/staff/projects/show.ejs index 23e96b2..0fdb00b 100644 --- a/views/staff/projects/show.ejs +++ b/views/staff/projects/show.ejs @@ -6,6 +6,7 @@ home users projects + media
diff --git a/views/staff/projects/show_404.ejs b/views/staff/projects/show_404.ejs index 193333f..70320c0 100644 --- a/views/staff/projects/show_404.ejs +++ b/views/staff/projects/show_404.ejs @@ -1,10 +1,12 @@ [[ include ../_header ]] +

Project not found


diff --git a/views/staff/users/index.ejs b/views/staff/users/index.ejs index ad92fc3..8c56565 100644 --- a/views/staff/users/index.ejs +++ b/views/staff/users/index.ejs @@ -1,10 +1,12 @@ [[ include ../_header ]] +

Users


diff --git a/views/staff/users/show.ejs b/views/staff/users/show.ejs index 2315043..afcd761 100644 --- a/views/staff/users/show.ejs +++ b/views/staff/users/show.ejs @@ -5,6 +5,7 @@ home users projects + media
@@ -21,7 +22,7 @@ [[- profile.displayName ]] - [view profile] + [view profile] @@ -43,6 +44,22 @@ [[- profile.last_seen ]] + + + projects + + + [[- profile.projectCount ]] + + + + + media + + + [[- profile.mediaCount ]] + + ip addresses @@ -77,10 +94,3 @@
[[ include ../_footer ]] - \ No newline at end of file diff --git a/views/staff/users/show_404.ejs b/views/staff/users/show_404.ejs index 3fd20a8..bcd0271 100644 --- a/views/staff/users/show_404.ejs +++ b/views/staff/users/show_404.ejs @@ -5,6 +5,7 @@ home users projects + media
-- cgit v1.2.3-70-g09d2 From 4c3720f1ac1ce86fd54fcd4887aab6d31bcd68c2 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Fri, 5 Sep 2014 13:27:48 -0400 Subject: media view --- public/assets/javascripts/ui/lib/Parser.js | 27 +++++++++++++++++----- public/assets/javascripts/ui/site/StaffView.js | 7 +++++- public/assets/stylesheets/staff.css | 5 ++++- server/lib/views/staff.js | 7 ++++-- views/staff/media/show.ejs | 31 ++++++++++++++++++++++++++ 5 files changed, 67 insertions(+), 10 deletions(-) (limited to 'public/assets/javascripts/ui/site/StaffView.js') diff --git a/public/assets/javascripts/ui/lib/Parser.js b/public/assets/javascripts/ui/lib/Parser.js index 1cf0418..52c96e6 100644 --- a/public/assets/javascripts/ui/lib/Parser.js +++ b/public/assets/javascripts/ui/lib/Parser.js @@ -21,7 +21,7 @@ var Parser = { } }, tag: function (media) { - return ''; + return ''; } }, { type: 'video', @@ -43,7 +43,7 @@ var Parser = { video.load() }, tag: function (media) { - return '