From cf082c40d9e4fd794cd41825123c54db57429980 Mon Sep 17 00:00:00 2001 From: Kenneth Jao Date: Wed, 25 Jan 2017 23:19:23 -0500 Subject: [PATCH] Finished profile page, fixed minor bugs, css fixes --- hourglass/client/main/main.css | 1 - hourglass/client/main/main.js | 1 + hourglass/client/menus/menus.css | 9 ++- hourglass/client/profile/profile.css | 15 ++--- hourglass/client/profile/profile.html | 2 +- hourglass/client/profile/profile.js | 90 +++++++++++++++++++++------ hourglass/lib/adminConfig.js | 2 + hourglass/lib/constants.js | 16 ++--- hourglass/lib/router.js | 63 ++++++++++--------- hourglass/server/main.js | 40 ++++++++---- 10 files changed, 155 insertions(+), 84 deletions(-) diff --git a/hourglass/client/main/main.css b/hourglass/client/main/main.css index 0ae8e65..97c0d13 100644 --- a/hourglass/client/main/main.css +++ b/hourglass/client/main/main.css @@ -1264,7 +1264,6 @@ textarea.clickModify { #userFunctions { margin-bottom: 1%; - border-bottom: 2px solid #666; } .userFunction { diff --git a/hourglass/client/main/main.js b/hourglass/client/main/main.js index a661fbf..a9e0406 100644 --- a/hourglass/client/main/main.js +++ b/hourglass/client/main/main.js @@ -69,6 +69,7 @@ Template.registerHelper('screen', (multiplier, fraction) => { }); Template.registerHelper('divColor', (div) => { // Reactive color changing based on preferences. Colors stored in themeColors. + if(Session.get("user") === null) return; return (Object.keys(Session.get("user")).length === 0) ? themeColors["lux"][div] : Session.get("user").preferences.theme[div]; }); diff --git a/hourglass/client/menus/menus.css b/hourglass/client/menus/menus.css index 433d24e..c86cb1a 100644 --- a/hourglass/client/menus/menus.css +++ b/hourglass/client/menus/menus.css @@ -105,7 +105,7 @@ } #colRight { - border-left: 1px solid #666; + border-left: 1px solid #9C9C9C; float: right; width: 40%; box-shadow: inset 0 0 0 99999px rgba(0,0,0,0.2); @@ -549,13 +549,14 @@ } #creRules p { + font-size: 2vh; padding: 0; } .formDiv { width: 100%; margin: 0; - padding: 2%; + padding: 0; background-color: transparent; position: relative; display: inline; @@ -580,6 +581,8 @@ } .profTitle { + font-size: 2vh; + margin: 1% !important; padding-left: 0 !important; } @@ -589,7 +592,7 @@ #creSubmit { font-weight: 200; - width: 30%; + width: 50%; padding: 2%; margin: auto; margin-top: 2%; diff --git a/hourglass/client/profile/profile.css b/hourglass/client/profile/profile.css index fb43152..d515b9e 100644 --- a/hourglass/client/profile/profile.css +++ b/hourglass/client/profile/profile.css @@ -58,7 +58,7 @@ .opTitle { font-weight: 200; - margin: 0; + margin: 1%; } #basicNext { @@ -230,6 +230,7 @@ #profPageWrapper #createWrapper { margin: auto; + margin-top: -1%; padding: 3%; padding-bottom: 2%; width: 30%; @@ -237,12 +238,8 @@ background-color: rgba(255,255,255,0.2); } -.formDiv { - width: 100%; - margin: 0; - padding: 2%; - background-color: transparent; - display: inline; +#profPageWrapper .-autocomplete-container { + margin-top: -6%; } #profPageWrapper #creSubmit { @@ -253,10 +250,6 @@ margin-bottom: 1%; } -#createWrapper p { - margin: 0; -} - #profPageWrapper input { margin: 0; padding: 2%; diff --git a/hourglass/client/profile/profile.html b/hourglass/client/profile/profile.html index ff9da78..272b126 100644 --- a/hourglass/client/profile/profile.html +++ b/hourglass/client/profile/profile.html @@ -72,7 +72,7 @@
-

Submit a request for a class to be approved by an administrator.
+

Submit a request for a class to be approved by an administrator. You can have up to 8 unapproved classes at once.

diff --git a/hourglass/client/profile/profile.js b/hourglass/client/profile/profile.js index 71e353c..9a55530 100644 --- a/hourglass/client/profile/profile.js +++ b/hourglass/client/profile/profile.js @@ -215,22 +215,7 @@ Template.profile.events({ }); Session.set("newClasses", newClasses); $(".creInput").each(function(){$(this).val('');}); - /*if (!teachers.findOne({ - name: values.teacher - })) { - Meteor.call("createTeacher", values.teacher, values.school, function(error, result) { - if (error !== undefined) { - sAlert.error(error.message, { - effect: 'stackslide', - position: 'top' - }); - } else { - sendData("createClass"); - } - }); - } else { - sendData("createClass"); - }*/ + }, 'click #backArrow' () { slideToField(Session.get("sections")[1]-1); @@ -343,9 +328,10 @@ Template.profile.events({ } } catch(err) {} }, - 'click .classBox .fa-plus' (event) { + 'click .classBox .fa-plus, click #classBody .classBox' (event) { var profile = Session.get("profile"); - var id = event.target.parentNode.getAttribute("classid"); + while(event.target.getAttribute("classid") === null) event.target = event.target.parentNode; + var id = event.target.getAttribute("classid"); if(profile.classes.indexOf(id) === -1) { profile.classes.push(id); Session.set("profile", profile); @@ -382,6 +368,74 @@ Template.profile.events({ return b.subscribers - a.subscribers; })); } + }, + 'click #profileSubmit' () { + // clear html and make page uninteractable + var myClasses = Session.get("profile").classes; + var newClasses = Session.get("newClasses"); + var message = "Sorry, your profile couldn't be created. Please try again!"; + + _.each(myClasses, function(myClass) { + Meteor.call("joinClass", [myClass, ""], function(err, result) { + if(err !== undefined) { + sAlert.error(message, { + effect: 'stackslide', + position: 'top' + }); + } + }) + }); + _.each(newClasses, function(newClass) { + if (!teachers.findOne({ + name: newClass.teacher + })) { + Meteor.call("createTeacher", newClass.teacher, newClass.school, function(error, result) { + if (error !== undefined) { + sAlert.error(message, { + effect: 'stackslide', + position: 'top' + }); + } else { + Meteor.call("createClass", newClass, function(error, result) { + if(error !== undefined) { + sAlert.error(message, { + effect: 'stackslide', + position: 'top' + }); + } + }); + } + }); + } else { + Meteor.call("createClass", newClass, function(error, result) { + if(error !== undefined) { + sAlert.error(message, { + effect: 'stackslide', + position: 'top' + }); + } + }); + } + }); + var profile = Session.get("profile"); + profile.complete = true; + profile.preferences = Meteor.user().profile.preferences; + profile.classes.push(Meteor.userId()); + Meteor.call("editProfile", profile, function(err, result) { + if(err !== undefined) { + sAlert.error(message, { + effect: 'stackslide', + position: 'top' + }); + } + Meteor.subscribe('classes'); + Meteor.subscribe('schools'); + Meteor.subscribe('teachers'); + Meteor.subscribe('work'); + Meteor.subscribe('requests'); + Meteor.subscribe("personalUser"); + Meteor.subscribe('users'); + }); } }); diff --git a/hourglass/lib/adminConfig.js b/hourglass/lib/adminConfig.js index 82fb376..f56c4f3 100644 --- a/hourglass/lib/adminConfig.js +++ b/hourglass/lib/adminConfig.js @@ -77,6 +77,7 @@ AdminConfig = { { label: 'Name', name: 'profile.name' }, { label: 'School', name: 'profile.school' }, { label: 'Graduation Year', name:'profile.grade' }, + { label: 'Complete', name:'profile.complete'}, { label: 'Icon', name: '_id', template: 'adminUserDisplay' }, ], templates: { @@ -98,6 +99,7 @@ AdminConfig = { { label: 'Name', name: 'profile.name' }, { label: 'School', name: 'profile.school' }, { label: 'Graduation Year', name:'profile.grade' }, + { label: 'Complete', name:'profile.complete'}, { label: 'Icon', name: '_id', template: 'adminUserDisplay' }, ], templates: { diff --git a/hourglass/lib/constants.js b/hourglass/lib/constants.js index 1af0f98..1f5733a 100644 --- a/hourglass/lib/constants.js +++ b/hourglass/lib/constants.js @@ -1,14 +1,14 @@ themeColors = { "lux": { "background": "White.jpg", - "mainColor": "#DBDBDB", - "secondaryColor": "#567393", - "sidebarColor": "#6C94B4", - "userDropdownColor": "#E6E6E6", - "iconHighlight": "#FFF", - "modeHighlight": "#D34949", - "classCardColor":"#EBEBEB", - "textColor": "#000" + "mainColor": "#4D82AC", + "secondaryColor": "#4C75A2", + "sidebarColor": "#5E88A8", + "userDropdownColor": "#427EB4", + "iconHighlight": "#39CAFF", + "modeHighlight": "#F02C2C", + "classCardColor":"#5D86A8", + "textColor": "#FFF" }, "nox": { "background": "Black.jpg", diff --git a/hourglass/lib/router.js b/hourglass/lib/router.js index be739f1..c824811 100644 --- a/hourglass/lib/router.js +++ b/hourglass/lib/router.js @@ -8,26 +8,30 @@ function completeProfile() { Router.route('/', { waitOn: function() { + if(!Meteor.userId()) { + return; + } + return [ + Meteor.subscribe('classes', this.params._id), + Meteor.subscribe('schools', this.params._id), + Meteor.subscribe('teachers', this.params._id), + Meteor.subscribe('work', this.params._id), + Meteor.subscribe('requests', this.params._id), + Meteor.subscribe('personalUser', this.params._id), + Meteor.subscribe('users', this.params._id) + ]; + }, + action: function() { if (!Meteor.userId() || !completeProfile()) { this.redirect('/login'); } else { - return [ - Meteor.subscribe('classes', this.params._id), - Meteor.subscribe('schools', this.params._id), - Meteor.subscribe('teachers', this.params._id), - Meteor.subscribe('work', this.params._id), - Meteor.subscribe('requests', this.params._id), - Meteor.subscribe('users', this.params._id) - ]; - } - }, - action: function() { - if(_.contains([null, undefined, ""], Meteor.user().profile.school || - _.contains([null, undefined, ""], Meteor.user().profile.grade))) { - this.redirect('/profile'); - } else { - Session.set("user", Meteor.user().profile); - this.render("main"); + if(_.contains([null, undefined, ""], Meteor.user().profile.school || + _.contains([null, undefined, ""], Meteor.user().profile.grade))) { + this.redirect('/profile'); + } else { + Session.set("user", Meteor.user().profile); + this.render("main"); + } } } }); @@ -37,10 +41,8 @@ Router.route('/login', { if (!Meteor.userId()) { this.render("login"); } else if (!completeProfile()) { - Session.set("user", Meteor.user().profile); this.redirect('/profile'); } else { - Session.set("user", Meteor.user().profile); this.redirect('/'); } } @@ -48,21 +50,22 @@ Router.route('/login', { Router.route('/profile', { waitOn: function() { + return [ + Meteor.subscribe('classes', this.params._id), + Meteor.subscribe('schools', this.params._id), + Meteor.subscribe('teachers', this.params._id), + Meteor.subscribe('work', this.params._id), + Meteor.subscribe('requests', this.params._id), + Meteor.subscribe('personalUser', this.params._id), + Meteor.subscribe('users', this.params._id) + ]; + }, + action: function() { if (!Meteor.userId() || completeProfile()) { this.redirect('/login'); } else { - return [ - Meteor.subscribe('classes', this.params._id), - Meteor.subscribe('schools', this.params._id), - Meteor.subscribe('teachers', this.params._id), - Meteor.subscribe('work', this.params._id), - Meteor.subscribe('requests', this.params._id), - Meteor.subscribe('users', this.params._id) - ]; + this.render("profile"); } - }, - action: function() { - this.render("profile"); } }); diff --git a/hourglass/server/main.js b/hourglass/server/main.js index 433e6db..5742b26 100644 --- a/hourglass/server/main.js +++ b/hourglass/server/main.js @@ -65,7 +65,23 @@ Meteor.publish('classes', function() { } else { Meteor.call('createProfile', this.userId); return classes.find({ - _id: null + privacy: false, + status: true, + }, { + // Return non-sensitive fields + fields: { + school: 1, + name: 1, + hour: 1, + teacher: 1, + admin: 1, + status: 1, + privacy: 1, + category: 1, + moderators: 1, + banned: 1, + subscribers: 1 + } }); } } @@ -108,6 +124,15 @@ Meteor.publish('requests', function() { } }); +Meteor.publish("personalUser", function() { + return Meteor.users.find({_id: this.userId}, { + fields: { + 'services': 1, + 'profile': 1 + } + }); +}); + //Publishes every-persons email and user-ids Meteor.publish('users', function() { @@ -119,9 +144,7 @@ Meteor.publish('users', function() { fields: { 'services.google.email': 1, 'services.google.picture': 1, - 'profile.banner': 1, 'profile.grade': 1, - 'profile.description': 1, 'profile.name': 1, 'profile.school': 1 } @@ -129,7 +152,6 @@ Meteor.publish('users', function() { } }); - // Allows only superadmins to edit collections from client Security.permit(['insert', 'update', 'remove']).collections([schools, classes, work]).ifHasRole('superadmin'); @@ -595,7 +617,6 @@ Meteor.methods({ throw new Meteor.Error(errors[security]); } }, - // User Functions 'editProfile': function(change) { var refyear = new Date().getUTCFullYear(); @@ -605,15 +626,11 @@ Meteor.methods({ "school": change.school, "grade": change.grade, "classes": current.classes, - "description": change.description, - "banner": change.banner, "preferences": change.preferences, "name": current.name, - "complete": current.complete + "complete": change.complete }; - if (current.description && current.description.length > 50) { - current.description = current.description.slice(0, 50); - } + if ((current.grade <= refyear || current.grade >= refyear + 4) && current.grade !== 0) { current.grade = refyear; } @@ -646,7 +663,6 @@ Meteor.methods({ _id: userId }); var current = currentuser.profile; - current.banner = "/Banners/defaultcover.jpg"; current.classes = [userId]; current.preferences = { "theme": themeColors.lux,