From 3dd703f10359e493499ba21bc0466df3100d7a33 Mon Sep 17 00:00:00 2001 From: Yaman Qalieh Date: Sun, 11 Sep 2016 18:47:50 -0400 Subject: [PATCH] personal work added --- hourglass/client/main/main.js | 42 ++++++++++++++++++++++------------- hourglass/server/main.js | 20 ++++++++--------- 2 files changed, 37 insertions(+), 25 deletions(-) diff --git a/hourglass/client/main/main.js b/hourglass/client/main/main.js index 1817272..f90df37 100644 --- a/hourglass/client/main/main.js +++ b/hourglass/client/main/main.js @@ -98,17 +98,28 @@ Template.registerHelper('myClasses', () => { // Gets all classes and respective var hide = Session.get("user").preferences.timeHide; for (var i = 0; i < courses.length; i++) { // For each user class. - found = classes.findOne({ - _id: courses[i] - }); - found.subscribers = found.subscribers.length; - found.mine = true; - if (found.admin === Meteor.userId()) { // If user owns this class. - found.box = " owned"; - found.mine = false; + if (courses[i] === Meteor.userId()) { + found = { + _id: courses[i], + name: "Personal", + subscribers: 1, + mine: false, + box: " owned" + }; + array.push(found); + } else { + found = classes.findOne({ + _id: courses[i] + }); + found.subscribers = found.subscribers.length; + found.mine = true; + if (found.admin === Meteor.userId()) { // If user owns this class. + found.box = " owned"; + found.mine = false; + } + if (classDisp.indexOf(courses[i]) !== -1) found.selected = true; // Filter selected. + array.push(found); } - if (classDisp.indexOf(courses[i]) !== -1) found.selected = true; // Filter selected. - array.push(found); var thisWork = work.find({ class: courses[i] @@ -300,9 +311,9 @@ Template.main.helpers({ openDivFade(document.getElementsByClassName("overlay")[0]); }, eventMouseover: function (event, jsEvent, view) { - this.style.boxShadow = "inset 0 0 0 99999px rgba(255,255,255,0.2)" + this.style.boxShadow = "inset 0 0 0 99999px rgba(255,255,255,0.2)"; }, - eventMouseout: function (event, jsEvent, view) { + eventMouseout: function (event, jsEvent, view) { this.style.boxShadow = ""; }, dayClick: function(date, jsEvent, view) { // On-click for each day. @@ -334,10 +345,10 @@ Template.main.helpers({ var hoverHighlight = Session.get("classDispHover"); if(Session.equals("mode","classes")) { $(".workCard").toggleClass("scaled",false); - try { + try { $(".workCard[classid=\'"+hoverHighlight+"\']").toggleClass("scaled",true); } catch(err) {} - } else { + } else { $(".workevent").toggleClass("scaled",false); try { $("."+hoverHighlight).toggleClass("scaled",true); @@ -577,7 +588,7 @@ Template.main.events({ area.value = ""; Session.set("commentRestrict",null); },750); - }) + }); }, // HANDLING INPUT CHANGING 'click .change' (event) { // Click changable inputs. Creates an input where the span is. @@ -772,6 +783,7 @@ Template.main.events({ }, 'click #markDone' () { // Click done button. serverData = [Session.get("currentWork")._id, "done"]; + console.log(serverData); sendData("toggleWork"); }, 'click #markConfirm' () { // Click confirm button. diff --git a/hourglass/server/main.js b/hourglass/server/main.js index 3a51441..9fe7f1d 100644 --- a/hourglass/server/main.js +++ b/hourglass/server/main.js @@ -88,7 +88,7 @@ Meteor.publish('work', function() { return work.find({ // Only return work of enrolled classes class: { - $in: userprofile.profile.classes.concat(this.userId) + $in: userprofile.profile.classes } }); } else { @@ -352,15 +352,14 @@ Meteor.methods({ var currentclass = classes.findOne({ _id: currentwork.class }); - var authorized = currentclass.moderators.concat(currentclass.admin); if (Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin'])) { work.update({ _id: currentwork._id }, { $set: change }); - } else if ((_.contains(authorized, Meteor.userId()) || - currentwork.class === Meteor.userId() || + } else if ((currentwork.class === Meteor.userId() || + _.contains(currentclass.moderators.concat(currentclass.admin), Meteor.userId()) || Meteor.userId() === currentwork.creator) && change.name.length <= 50 && change.description.length <= 150 && change.dueDate instanceof Date && change.dueDate.getTime() >= ref && @@ -390,8 +389,9 @@ Meteor.methods({ }); var user = Meteor.userId(); if (typeof comment === "string" && comment.length <= 200 && - _.contains(currentclass.subscribers, Meteor.userId()) && - !_.contains(currentclass.banned, Meteor.userId())) { + (workobject.class === Meteor.userId() || + (_.contains(currentclass.subscribers, Meteor.userId()) && + !_.contains(currentclass.banned, Meteor.userId())))) { var commentInfo = { "comment": input[0], "user": user, @@ -417,7 +417,7 @@ Meteor.methods({ var currentclass = classes.findOne({ _id: workobject.class }); - if (_.contains(currentclass.subscribers, Meteor.userId()) && _.contains(["confirmations", "reports", "done"], input[1])) { + if ((Meteor.userId() === workobject.class || _.contains(currentclass.subscribers, Meteor.userId())) && _.contains(["confirmations", "reports", "done"], input[1])) { var userindex = workobject[input[1]].indexOf(Meteor.userId()); if (userindex === -1) { workobject[input[1]] = workobject[input[1]].concat(Meteor.userId()); @@ -447,9 +447,9 @@ Meteor.methods({ var currentclass = classes.findOne({ _id: currentwork.class }); - var authorized = currentclass.moderators.concat(currentclass.admin); if (Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin']) || - _.contains(authorized, Meteor.userId()) || Meteor.userId() === currentwork.class) { + currentwork.class === Meteor.userId() || + _.contains(currentclass.moderators.concat(currentclass.admin), Meteor.userId()) || Meteor.userId() === currentwork.class) { work.remove({ _id: workId }); @@ -504,7 +504,7 @@ Meteor.methods({ }).profile; current.banner = "/Banners/defaultcover.jpg"; current.avatar = "/Avatars/" + (Math.floor(Math.random() * 10) + 1).toString() + ".png"; - current.classes = []; + current.classes = [userId]; current.preferences = { "theme": "light", "mode": "classes",