diff options
| author | Jules Laplace <jules@okfoc.us> | 2014-09-04 13:50:40 -0400 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2014-09-04 13:50:40 -0400 |
| commit | b2164f9f6001dcac952a3d2b301f1425fdb3cbe9 (patch) | |
| tree | eb69107c324d46133cee95196eb807ab59c549c1 | |
| parent | 95f62d72945acbac295f2342fd51cea9337d7cb7 (diff) | |
admin users views
| -rwxr-xr-x | public/assets/stylesheets/app.css | 4 | ||||
| -rw-r--r-- | public/assets/stylesheets/staff.css | 38 | ||||
| -rw-r--r-- | server/lib/api/projects.js | 2 | ||||
| -rw-r--r-- | server/lib/util.js | 4 | ||||
| -rw-r--r-- | server/lib/views/staff.js | 70 | ||||
| -rw-r--r-- | views/staff/_footer.ejs | 6 | ||||
| -rw-r--r-- | views/staff/_header.ejs | 3 | ||||
| -rw-r--r-- | views/staff/_projects.ejs | 22 | ||||
| -rw-r--r-- | views/staff/_stats.ejs | 13 | ||||
| -rw-r--r-- | views/staff/index.ejs | 14 | ||||
| -rw-r--r-- | views/staff/projects/index.ejs | 10 | ||||
| -rw-r--r-- | views/staff/projects/show.ejs | 15 | ||||
| -rw-r--r-- | views/staff/projects/show_404.ejs | 8 | ||||
| -rw-r--r-- | views/staff/users/index.ejs | 10 | ||||
| -rw-r--r-- | views/staff/users/show.ejs | 14 | ||||
| -rw-r--r-- | views/staff/users/show_404.ejs | 8 |
16 files changed, 210 insertions, 31 deletions
diff --git a/public/assets/stylesheets/app.css b/public/assets/stylesheets/app.css index 25bcf56..17a7dc0 100755 --- a/public/assets/stylesheets/app.css +++ b/public/assets/stylesheets/app.css @@ -164,6 +164,7 @@ h5 { .page.profile { color:white; } +.page table.demo, .page table.profilepage, .page table.projectList { width: 100%; @@ -193,6 +194,7 @@ iframe.embed { z-index: -1; pointer-events: none; } +.page table.demo td, .page table.profilepage td, .page table.projectList td { width: 33.3333%; @@ -241,7 +243,7 @@ iframe.embed { color:white; } -#projectList .editBtn { +.projectList .editBtn { position: absolute; right: 10px; top: 10px; diff --git a/public/assets/stylesheets/staff.css b/public/assets/stylesheets/staff.css index 0208878..2d1f802 100644 --- a/public/assets/stylesheets/staff.css +++ b/public/assets/stylesheets/staff.css @@ -4,7 +4,43 @@ th, b { font-weight: bold; } -#users td { +table { + display: inline-block; + margin-right: 40px; + vertical-align: top; +} +td, th { text-align: left; padding: 2px 5px; +} +.staff .body { + text-align: left; +} +.staff h1 { + text-align: left; + display: inline-block; +} +.staff nav { + display: inline-block; + text-align: left; +} +.staff nav a { + padding-left: 20px; +} +.staff hr { + border: 1px solid #bbb; + margin: 5px auto 10px; +} +.body { + width: 80%; + margin: 0 auto; +} +.jsonview * { + font-family: monospace !important; +} +.staff { + font-size: 15px; +} +.staff .editLinks a { + color: #00f; }
\ No newline at end of file diff --git a/server/lib/api/projects.js b/server/lib/api/projects.js index 2a5beff..da41b48 100644 --- a/server/lib/api/projects.js +++ b/server/lib/api/projects.js @@ -41,6 +41,7 @@ var projects = { data.media = JSON.parse(data.media) data.colors = JSON.parse(data.colors) data.startPosition = JSON.parse(data.startPosition) + data.created_at = new Date () upload.put("projects", req.files.thumbnail, { unacceptable: function(err){ @@ -72,6 +73,7 @@ var projects = { data.name = util.sanitize(data.name) data.slug = util.slugify(data.name) data.description = util.sanitize(data.description) + data.updated_at = new Date () if (req.files.thumbnail) { upload.put("projects", req.files.thumbnail, { diff --git a/server/lib/util.js b/server/lib/util.js index 6d43750..791d3e2 100644 --- a/server/lib/util.js +++ b/server/lib/util.js @@ -8,7 +8,6 @@ var nonAlphanumerics = new RegExp('[^-_a-zA-Z0-9]', 'g') var consecutiveDashes = new RegExp("-+", 'g') var entities = new RegExp("[<>&]", 'g') - var util = {} util.trim = function (s){ return (s || "").replace(whitespaceHead,"").replace(whitespaceTail,"") } @@ -19,6 +18,9 @@ util.slugify = function (s){ util.sanitize = function (s){ return (s || "").replace(entities, "") } +util.escape = function (s){ + return (s || "").replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">") +} util.capitalize = function (s) { return (s || "").split(" ").map(util.capitalizeWord).join(" "); } diff --git a/server/lib/views/staff.js b/server/lib/views/staff.js index 9643626..cf43081 100644 --- a/server/lib/views/staff.js +++ b/server/lib/views/staff.js @@ -15,7 +15,7 @@ var staff = module.exports = { fields: { user: "_id username displayName created_at updated_at last_seen created_ip last_ip", - project: "_id name slug created_at updated_at", + project: "_id name slug user_id privacy created_at updated_at", }, defaults: { @@ -35,9 +35,10 @@ var staff = module.exports = { case 'date': sort = {'created_at': -1} break - case 'lastseen': + case 'last_seen': sort = {'last_seen': -1} break + case 'username': default: sort = {'username': 1} break @@ -63,7 +64,7 @@ var staff = module.exports = { var sort switch (req.params.sort) { case 'date': - sort = {'date': -1} + sort = {'created_at': -1} break default: sort = {'slug': 1} @@ -75,13 +76,34 @@ var staff = module.exports = { .skip(offset) .limit(50) .exec(function (err, projects) { - res.locals.projects = projects.map(staff.helpers.projects) + res.locals.projects = projects.map(staff.helpers.project) next() }) }, + + ensureRecentProjects: function(req, res, next){ + var dreq = { params: { sort: 'created_at', limit: 20, offset: 0 } } + staff.middleware.ensureProjects(dreq, res, next) + }, ensureProjectsUsers: function(req, res, next){ - + if (! res.locals.projects || ! res.locals.projects.length) { return 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) + }) + 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 + }) + }) + next() + }) }, ensureProfile: function(req, res, next){ @@ -116,7 +138,7 @@ var staff = module.exports = { next() }) }, - + ensureProfileProjectCount: function(req, res, next){ if (! res.locals.profile) { return next() } Project.count({ user_id: res.locals.profile._id}, function(err, count){ @@ -177,6 +199,8 @@ var staff = module.exports = { project: function(project){ project = project.toObject() + project.date = moment( project.updated_at || project.created_at ).format("M/DD/YYYY H:MM") + project.user = {} return project } }, @@ -234,23 +258,19 @@ var staff = module.exports = { staff.projects.show ); -// app.post('/staff/bless', -// middleware.ensureAuthenticated, -// views.staff.bless -// ); + + app.put('/staff/users/:username/bless', + middleware.ensureAuthenticated, + middleware.ensureIsStaff, + + staff.users.bless + ); }, index: function(req, res){ res.render('staff/index') }, - - bless: function(req, res){ - req.user.isStaff = true - req.user.save(function(){ - res.redirect("/staff") - }) - }, - + // /staff/users/ // /staff/users/:username users: { @@ -259,12 +279,20 @@ var staff = module.exports = { }, show: function(req, res){ if (res.locals.profile) { - res.render('staff/users/show') + res.render('staff/users/show', { + profileJSON: util.escape( JSON.stringify( res.locals.profile ) ) + }) } else { res.render('staff/users/show_404') } }, + bless: function(req, res){ + res.locals.profile.isStaff = req.body.isStaff + res.locals.profile.save(function(){ + res.redirect("/staff") + }) + }, }, // /staff/projects/ @@ -275,7 +303,9 @@ var staff = module.exports = { }, show: function(req, res){ if (res.locals.project) { - res.render('staff/projects/show') + res.render('staff/projects/show', { + projectJSON: util.escape( JSON.stringify( res.locals.profile ) ) + }) } else { res.render('staff/projects/show_404') diff --git a/views/staff/_footer.ejs b/views/staff/_footer.ejs index 580828f..c363beb 100644 --- a/views/staff/_footer.ejs +++ b/views/staff/_footer.ejs @@ -1,3 +1,4 @@ + </div> [[ include ../partials/confirm-modal ]] [[ include ../partials/footer ]] </div> @@ -5,4 +6,9 @@ </body> [[ include ../partials/scripts ]] <script type="text/javascript" src="/assets/javascripts/vendor/bower_components/jquery-jsonview/dist/jquery.jsonview.js"></script> +<script> +$(".json").each(function(){ + $(this).JSONView( this.innerText ) +}) +</script> </html> diff --git a/views/staff/_header.ejs b/views/staff/_header.ejs index d726b02..1880c98 100644 --- a/views/staff/_header.ejs +++ b/views/staff/_header.ejs @@ -7,7 +7,8 @@ <link rel="stylesheet" href="/assets/stylesheets/staff.css"></script> </head> <body class="loading"> -<div class="rapper page"> +<div class="rapper page staff"> [[ include ../partials/header ]] <br clear="all"> + <div class="body"> diff --git a/views/staff/_projects.ejs b/views/staff/_projects.ejs new file mode 100644 index 0000000..83041ae --- /dev/null +++ b/views/staff/_projects.ejs @@ -0,0 +1,22 @@ +<table id="users"> +[[ projects.forEach(function(project){ ]] + <tr> + <td> + <a href="/staff/projects/[[- project.slug ]]">[[- project.name ]]</a> + </td> + <td class="editLinks"> + <a href="/project/[[- project.slug ]]">[view]</a> + <a href="/project/[[- project.slug ]]/edit">[edit]</a> + </td> + <td> + <a href="/staff/users/[[- project.user.username ]]">[[- project.user.username ]]</a> + </td> + <td> + [[- project.date ]] + </td> + <td> + [[- project.privacy ? "private" : "" ]] + </td> + </tr> +[[ }) ]] +</table> diff --git a/views/staff/_stats.ejs b/views/staff/_stats.ejs new file mode 100644 index 0000000..6439ab9 --- /dev/null +++ b/views/staff/_stats.ejs @@ -0,0 +1,13 @@ +<table> + <tr> + <th>stats</th> + </tr> + <tr> + <td><a href="/staff/users">users</a></td> + <td>[[- userCount ]]</td> + </tr> + <tr> + <td><a href="/staff/projects">projects</a></td> + <td>[[- projectCount ]]</td> + </tr> +</table> diff --git a/views/staff/index.ejs b/views/staff/index.ejs index 0cb67da..842e086 100644 --- a/views/staff/index.ejs +++ b/views/staff/index.ejs @@ -2,10 +2,14 @@ <h1>Staff Area</h1> -<b>users:</b> [[- userCount ]] -<b>projects:</b> [[- projectCount ]] - -<br> -[[ include _users_recent ]] + <nav> + <a href="/staff/users">users</a> + <a href="/staff/projects">projects</a> + </nav> + + <hr> + + [[ include _users_recent ]] + [[ include _stats ]] [[ include _footer ]]
\ No newline at end of file diff --git a/views/staff/projects/index.ejs b/views/staff/projects/index.ejs index a27a132..a5a9308 100644 --- a/views/staff/projects/index.ejs +++ b/views/staff/projects/index.ejs @@ -1,4 +1,14 @@ [[ include ../_header ]] <h1>Projects</h1> + <nav> + <a href="/staff">home</a> + <a href="/staff/users">users</a> + <a href="/staff/projects">projects</a> + </nav> + + <hr> + +[[ include ../_projects ]] + [[ include ../_footer ]] diff --git a/views/staff/projects/show.ejs b/views/staff/projects/show.ejs index 01b5c76..e821614 100644 --- a/views/staff/projects/show.ejs +++ b/views/staff/projects/show.ejs @@ -1,2 +1,17 @@ [[ include ../_header ]] + + <h1>Project</h1> + + <nav> + <a href="/staff">home</a> + <a href="/staff/users">users</a> + <a href="/staff/projects">projects</a> + </nav> + + <hr> + + <div class="json"> + [[- projectJSON ]] + </div> + [[ include ../_footer ]] diff --git a/views/staff/projects/show_404.ejs b/views/staff/projects/show_404.ejs index e0cf0e2..193333f 100644 --- a/views/staff/projects/show_404.ejs +++ b/views/staff/projects/show_404.ejs @@ -1,4 +1,12 @@ [[ include ../_header ]] <h1>Project not found</h1> + <nav> + <a href="/staff">home</a> + <a href="/staff/users">users</a> + <a href="/staff/projects">projects</a> + </nav> + + <hr> + [[ include ../_footer ]] diff --git a/views/staff/users/index.ejs b/views/staff/users/index.ejs index fb072d8..ad92fc3 100644 --- a/views/staff/users/index.ejs +++ b/views/staff/users/index.ejs @@ -1,6 +1,14 @@ [[ include ../_header ]] <h1>Users</h1> -[[ include _users ]] + <nav> + <a href="/staff">home</a> + <a href="/staff/users">users</a> + <a href="/staff/projects">projects</a> + </nav> + + <hr> + +[[ include ../_users ]] [[ include ../_footer ]] diff --git a/views/staff/users/show.ejs b/views/staff/users/show.ejs index b5e1a6c..d306443 100644 --- a/views/staff/users/show.ejs +++ b/views/staff/users/show.ejs @@ -1,4 +1,16 @@ [[ include ../_header ]] - <h1>User: [[ profile.username ]]</h1> + <h1>User: [[- profile.username ]]</h1> + + <nav> + <a href="/staff">home</a> + <a href="/staff/users">users</a> + <a href="/staff/projects">projects</a> + </nav> + + <hr> + + <div class="json"> + [[- profileJSON ]] + </div> [[ include ../_footer ]] diff --git a/views/staff/users/show_404.ejs b/views/staff/users/show_404.ejs index c52e1e7..3fd20a8 100644 --- a/views/staff/users/show_404.ejs +++ b/views/staff/users/show_404.ejs @@ -1,4 +1,12 @@ [[ include ../_header ]] <h1>User not found</h1> + <nav> + <a href="/staff">home</a> + <a href="/staff/users">users</a> + <a href="/staff/projects">projects</a> + </nav> + + <hr> + [[ include ../_footer ]] |
