From 650e13881b5389ade8f6fca478bfe8887fac250e Mon Sep 17 00:00:00 2001 From: Kenneth Jao Date: Sun, 23 Oct 2016 22:10:02 -0400 Subject: [PATCH] Added admin buttons for status, and user info --- hourglass/client/admin/admin.css | 56 ++++++++++++++++++++++++++ hourglass/client/admin/admin.html | 17 ++++++++ hourglass/client/admin/admin.js | 66 +++++++++++++++++++++++++++++++ hourglass/collections/main.js | 8 ---- hourglass/lib/constants.js | 22 +++++------ hourglass/server/main.js | 8 ++-- 6 files changed, 154 insertions(+), 23 deletions(-) create mode 100644 hourglass/client/admin/admin.css create mode 100644 hourglass/client/admin/admin.html create mode 100644 hourglass/client/admin/admin.js diff --git a/hourglass/client/admin/admin.css b/hourglass/client/admin/admin.css new file mode 100644 index 0000000..395809f --- /dev/null +++ b/hourglass/client/admin/admin.css @@ -0,0 +1,56 @@ +.adminUserIcon { + width: 2.7vw; + margin: 1%; + + cursor: pointer; + + -moz-border-radius: 50%; + -webkit-border-radius: 50%; + border-radius: 50%; +} + +.adminUserInfo { + margin-top: 1vh; + padding: 0.5% 1.5% 0.5% 1.5%; + + background-color: #fff; + -webkit-filter: drop-shadow(0px -1px 2px #666); + filter: drop-shadow(0px -1px 2px #666); + + position: fixed; + display: none; + z-index: 5; +} + +.adminUserInfo p { + margin: 5% 0 5% 0; +} + +.infoTitle { + font-weight: 600; +} + +.infoTab { + width: 0; + height: 0; + + border-bottom: 2vh solid #fff; + border-left: 1.5vh solid transparent; + border-right: 1.5vh solid transparent; + + position: absolute; + right: 1vh; + top: -1.9vh; +} + +.approveStatus { + cursor: pointer; +} + +.approveStatus .fa { + font-size: 5vh +} + +.approveStatus .fa-toggle-on { + color: #288cd3; +} \ No newline at end of file diff --git a/hourglass/client/admin/admin.html b/hourglass/client/admin/admin.html new file mode 100644 index 0000000..9df4827 --- /dev/null +++ b/hourglass/client/admin/admin.html @@ -0,0 +1,17 @@ + + + \ No newline at end of file diff --git a/hourglass/client/admin/admin.js b/hourglass/client/admin/admin.js new file mode 100644 index 0000000..b2f827c --- /dev/null +++ b/hourglass/client/admin/admin.js @@ -0,0 +1,66 @@ +var inInfo = false; +var openUserDisplay = null; + +Template.adminUserDisplay.helpers({ + info() { + var ids = (this.value instanceof Array) ? this.value : [this.value]; + var userInfo = []; + for(var i = 0; i < ids.length; i++) { + var user = Meteor.users.findOne({_id: ids[i]}); + userInfo.push({ + name: user.profile.name, + email: user.services.google.email, + id: user._id, + icon: user.services.google.picture + }) + } + return userInfo; + } +}); + +Template.statusButton.helpers({ + status() { + console.log(this.value); + return (this.value) ? "on" : "off"; + } +}); + +Template.adminUserDisplay.events({ + 'click .adminUserIcon' (event) { + var icoCoords = $(event.target)[0].getBoundingClientRect(); + var x = window.innerWidth - icoCoords.right; + var y = icoCoords.bottom; + openUserDisplay = $(event.target).next(); + $(".adminUserInfo").fadeOut(200); + openUserDisplay + .css({'right': x, 'top': y}) + .fadeIn(200); + }, + 'mouseenter .adminUserInfo' () { + inInfo = true; + }, + 'mouseleave .adminUserInfo' (event) { + if(inInfo) openUserDisplay.fadeOut(200); + inInfo = false; + openUserDisplay = null; + } +}); + +Template.AdminLTE.events({ + 'click' (event) { + if(!event.target.className.includes("adminUserInfo") && + !event.target.className.includes("adminUserIcon") && + openUserDisplay !== null) { + openUserDisplay.fadeOut(200); + openUserDisplay = null; + } + } +}); + +Template.statusButton.events({ + 'click .approveStatus' () { + console.log(this.doc._id); + Meteor.call("approveClass", this.doc._id); + } +}) + diff --git a/hourglass/collections/main.js b/hourglass/collections/main.js index 211d46d..abb9b71 100644 --- a/hourglass/collections/main.js +++ b/hourglass/collections/main.js @@ -48,11 +48,3 @@ schools.attachSchema(schools.schema); classes.attachSchema(classes.schema); work.attachSchema(work.schema); requests.attachSchema(requests.schema); - -classes.helpers({ - fullUserInfo() { - var user = Meteor.users.findOne({_id: this.admin}); - console.log(user); - return this.admin + " | " + user.services.google.email + " | " + user.profile.name; - } -}) diff --git a/hourglass/lib/constants.js b/hourglass/lib/constants.js index 61a21e8..c8cd341 100644 --- a/hourglass/lib/constants.js +++ b/hourglass/lib/constants.js @@ -131,16 +131,16 @@ AdminConfig = { { label: 'Name', name: 'name' }, { label: 'Hour', name: 'hour' }, { label: 'Teacher', name: 'teacher' }, - { label: 'Admin', name: 'admin' }, - { label: 'Status', name: 'status' }, + { label: 'Admin', name: 'admin', template: 'adminUserDisplay' }, + { label: 'Status', name: 'status', template: 'statusButton'}, { label: 'Code', name: 'code' }, { label: 'Privacy', name: 'privacy' }, { label: 'Category', name: 'category' }, - { label: 'Moderators', name: 'moderators' }, - { label: 'Banned', name: 'banned' }, - { label: 'Subscribers', name: 'subscribers' } + { label: 'Moderators', name: 'moderators', template: 'adminUserDisplay' }, + { label: 'Banned', name: 'banned', template: 'adminUserDisplay' }, + { label: 'Subscribers', name: 'subscribers', template: 'adminUserDisplay'} ], - color: 'blue' + color: 'purple' }, work: { tableColumns: [ @@ -149,11 +149,11 @@ AdminConfig = { { label: 'Name', name: 'name' }, { label: 'Due Date', name: 'dueDate' }, { label: 'Description', name: 'description' }, - { label: 'Creator', name: 'creator' }, + { label: 'Creator', name: 'creator', template: 'adminUserDisplay' }, { label: 'Comments', name: 'comments' }, - { label: 'Confirmations', name: 'confirmations' }, - { label: 'Reports', name: 'reports' }, - { label: 'Done', name: 'done' }, + { label: 'Confirmations', name: 'confirmations', template: 'adminUserDisplay' }, + { label: 'Reports', name: 'reports', template: 'adminUserDisplay' }, + { label: 'Done', name: 'done', template: 'adminUserDisplay' }, { label: 'Type', name: 'type' } ], color: 'yellow' @@ -161,7 +161,7 @@ AdminConfig = { requests: { tableColumns: [ { label: 'ID', name: '_id' }, - { label: 'User', name: 'requestor' }, + { label: 'User', name: 'requestor', template: 'adminUserDisplay' }, { label: 'Request', name: 'request' }, { label: 'Time', name: 'timeRequested' } ], diff --git a/hourglass/server/main.js b/hourglass/server/main.js index 1c3b2c6..5909dc3 100644 --- a/hourglass/server/main.js +++ b/hourglass/server/main.js @@ -208,15 +208,15 @@ Meteor.methods({ }, 'approveClass': function(classId) { if (Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin'])) { - var currentclass = classes.find({ + var currentclass = classes.findOne({ _id: classId }); - currentclass.status = !currentclass.status; - Meteor.update({ + + classes.update({ _id: classId }, { $set: { - currentclass + status: !currentclass.status } }); }