diff --git a/hourglass/.meteor/.finished-upgraders b/hourglass/.meteor/.finished-upgraders index 11fc14e..aa60704 100644 --- a/hourglass/.meteor/.finished-upgraders +++ b/hourglass/.meteor/.finished-upgraders @@ -12,3 +12,4 @@ notices-for-facebook-graph-api-2 1.2.0-breaking-changes 1.3.0-split-minifiers-package 1.4.0-remove-old-dev-bundle-link +1.4.1-add-shell-server-package diff --git a/hourglass/.meteor/packages b/hourglass/.meteor/packages index 9803487..70cdd71 100644 --- a/hourglass/.meteor/packages +++ b/hourglass/.meteor/packages @@ -6,23 +6,23 @@ meteor-base@1.0.4 # Packages every Meteor app needs to have mobile-experience@1.0.4 # Packages for a great mobile UX -mongo@1.1.10 # The database Meteor supports right now +mongo@1.1.11 # The database Meteor supports right now blaze-html-templates@1.0.4 # Compile .html files into Meteor Blaze views reactive-var@1.0.10 # Reactive variable for tracker jquery@1.11.9 # Helpful client-side library tracker@1.1.0 # Meteor's client-side reactive programming library -standard-minifier-css@1.1.8 # CSS minifier run for production mode -standard-minifier-js@1.1.8 # JS minifier run for production mode -es5-shim@4.6.13 # ECMAScript 5 compatibility for older browsers. -ecmascript@0.5.7 # Enable ECMAScript2015+ syntax in app code +standard-minifier-css@1.2.0 # CSS minifier run for production mode +standard-minifier-js@1.2.0 # JS minifier run for production mode +es5-shim@4.6.14 # ECMAScript 5 compatibility for older browsers. +ecmascript@0.5.8 # Enable ECMAScript2015+ syntax in app code fortawesome:fontawesome -session +session@1.1.6 proyk:meteor-cookies aldeed:simple-schema -accounts-google -accounts-ui +accounts-google@1.0.10 +accounts-ui@1.1.9 iron:router ongoworks:security mizzao:autocomplete @@ -30,3 +30,4 @@ alanning:roles rzymek:fullcalendar momentjs:moment eternicode:bootstrap-datepicker +shell-server diff --git a/hourglass/.meteor/release b/hourglass/.meteor/release index c85944c..30b2c59 100644 --- a/hourglass/.meteor/release +++ b/hourglass/.meteor/release @@ -1 +1 @@ -METEOR@1.4.0.1 +METEOR@1.4.1 diff --git a/hourglass/.meteor/versions b/hourglass/.meteor/versions index 901579f..12f69eb 100644 --- a/hourglass/.meteor/versions +++ b/hourglass/.meteor/versions @@ -1,4 +1,4 @@ -accounts-base@1.2.9 +accounts-base@1.2.11 accounts-google@1.0.10 accounts-oauth@1.1.13 accounts-ui@1.1.9 @@ -6,41 +6,41 @@ accounts-ui-unstyled@1.1.12 alanning:roles@1.2.15 aldeed:simple-schema@1.5.3 allow-deny@1.0.5 -autoupdate@1.2.11 -babel-compiler@6.9.0 -babel-runtime@0.1.10 +autoupdate@1.3.11 +babel-compiler@6.9.1 +babel-runtime@0.1.11 base64@1.0.9 binary-heap@1.0.9 blaze@2.1.8 blaze-html-templates@1.0.4 blaze-tools@1.0.9 boilerplate-generator@1.0.9 -caching-compiler@1.0.6 +caching-compiler@1.1.7 caching-html-compiler@1.0.6 callback-hook@1.0.9 check@1.2.3 -coffeescript@1.0.17 +coffeescript@1.2.4 dandv:caret-position@2.1.1 ddp@1.2.5 -ddp-client@1.2.9 +ddp-client@1.3.1 ddp-common@1.2.6 ddp-rate-limiter@1.0.5 -ddp-server@1.2.10 +ddp-server@1.3.10 deps@1.0.12 diff-sequence@1.0.6 -ecmascript@0.5.7 -ecmascript-runtime@0.3.12 +ecmascript@0.5.8 +ecmascript-runtime@0.3.14 ejson@1.0.12 -es5-shim@4.6.13 +es5-shim@4.6.14 eternicode:bootstrap-datepicker@1.6.0_3 fastclick@1.0.12 fortawesome:fontawesome@4.5.0 geojson-utils@1.0.9 -google@1.1.13 +google@1.1.14 hot-code-push@1.0.4 html-tools@1.0.10 htmljs@1.0.10 -http@1.1.8 +http@1.2.9 id-map@1.0.8 iron:controller@1.0.12 iron:core@1.0.11 @@ -52,31 +52,31 @@ iron:router@1.0.13 iron:url@1.0.11 jquery@1.11.9 launch-screen@1.0.12 -less@2.6.5 +less@2.7.5 livedata@1.0.18 localstorage@1.0.11 -logging@1.1.14 -mdg:validation-error@0.2.0 -meteor@1.2.16 +logging@1.1.15 +mdg:validation-error@0.5.1 +meteor@1.2.17 meteor-base@1.0.4 -minifier-css@1.2.13 -minifier-js@1.2.13 +minifier-css@1.2.14 +minifier-js@1.2.14 minimongo@1.0.17 mizzao:autocomplete@0.5.1 mobile-experience@1.0.4 mobile-status-bar@1.0.12 -modules@0.7.5 -modules-runtime@0.7.5 -momentjs:moment@2.8.4 -mongo@1.1.10 +modules@0.7.6 +modules-runtime@0.7.6 +momentjs:moment@2.14.4 +mongo@1.1.11 mongo-id@1.0.5 -npm-mongo@1.5.45 +npm-mongo@1.5.46 oauth@1.1.11 oauth2@1.1.10 observe-sequence@1.0.12 ongoworks:security@2.0.1 ordered-dict@1.0.8 -promise@0.8.3 +promise@0.8.4 proyk:meteor-cookies@0.0.1 random@1.0.10 rate-limit@1.0.5 @@ -88,15 +88,16 @@ routepolicy@1.0.11 rzymek:fullcalendar@2.7.2 service-configuration@1.0.10 session@1.1.6 +shell-server@0.2.1 spacebars@1.0.12 spacebars-compiler@1.0.12 -standard-minifier-css@1.1.8 -standard-minifier-js@1.1.8 -templating@1.1.14 +standard-minifier-css@1.2.0 +standard-minifier-js@1.2.0 +templating@1.2.14 templating-tools@1.0.4 tracker@1.1.0 ui@1.0.11 underscore@1.0.9 url@1.0.10 -webapp@1.3.10 +webapp@1.3.11 webapp-hashing@1.0.9 diff --git a/hourglass/client/main/main.js b/hourglass/client/main/main.js index 06fa93c..7a5f2c6 100644 --- a/hourglass/client/main/main.js +++ b/hourglass/client/main/main.js @@ -24,8 +24,8 @@ var themeColors = { }; var workColors = { - "normal": "#2E4F74", - "quiz": "#409333", + "normal": "#2E4F74", + "quiz": "#409333", "test": "#AD3C44", "project": "#E6E619", "other": "#852E6D" @@ -57,35 +57,50 @@ Template.registerHelper('overlayDim', (part) => { }); Template.registerHelper('myClasses', () => { - if (Meteor.user().profile.classes === undefined || Meteor.user().profile.classes.length === 0) { - Session.set("noclass",true); + if (Meteor.user().profile.classes === undefined || Meteor.user().profile.classes.length === 0) { + Session.set("noclass",true); return []; } else { - var array = []; - var courses = Meteor.user().profile.classes; - for(var i = 0; i < courses.length; i++) { - found = classes.findOne({_id:courses[i]}); + var array = []; + var courses = Meteor.user().profile.classes; + for(var i = 0; i < courses.length; i++) { + found = classes.findOne({_id:courses[i]}); found.subscribers = found.subscribers.length; - if(found.admin === Meteor.userId()) found.box = " owned"; - array.push(found); + if(found.admin === Meteor.userId()) found.box = " owned"; + array.push(found); - var thisWork = work.find({class: courses[i]}).fetch(); + var thisWork = work.find({class: courses[i]}).fetch(); - for(var j = 0; j < thisWork.length; j++) { - thisWork[j].dueDate = getReadableDate(thisWork[j].dueDate); - thisWork[j].typeColor = workColors[thisWork[j].type]; - } - array[i].thisClassWork = thisWork; - } + for(var j = 0; j < thisWork.length; j++) { + thisWork[j].dueDate = moment(thisWork[j].dueDate).calendar(null, { + sameDay: '[Today]', + nextDay: '[Tomorrow]', + nextWeek: 'dddd', + lastDay: '[Yesterday]', + lastWeek: '[Last] dddd', + sameElse: 'MMMM Do' + }); + thisWork[j].typeColor = workColors[thisWork[j].type]; + } + array[i].thisClassWork = thisWork; + } Session.set("noclass",false); +<<<<<<< HEAD console.log(array); return array; +======= + return array; +>>>>>>> afd60acb9ab69a32ee86ae92e86e0d67e39af7be } }); Template.main.helpers({ schoolName() { +<<<<<<< HEAD Session.set("calendarclasses", Meteor.user().profile.classes); +======= + Session.set("calendarclasses", Meteor.user().profile.classes); +>>>>>>> afd60acb9ab69a32ee86ae92e86e0d67e39af7be return " - " + Meteor.user().profile.school; }, iconColor(icon) { @@ -175,31 +190,31 @@ Template.main.helpers({ }, work(value) { if(Session.get("currentWork") === null) return; - return Session.get("currentReadableWork")[value]; + return Session.get("currentReadableWork")[value]; }, workType() { if(Session.get("currentWork") === null) return; - type = Session.get("currentWork").type; - if(type.includes("edit")) { - return; - } else { - return workColors[type]; - } + type = Session.get("currentWork").type; + if(type.includes("edit")) { + return; + } else { + return workColors[type]; + } }, newWork() { - return Session.get("newWork"); + return Session.get("newWork"); }, inRole() { - if(Session.get("newWork")) { - return true; - } else { - if(Meteor.userId() === Session.get("currentWork").creator || - Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin']) || - classes.findOne({_id: Session.get("currentWork")._id}).moderators.indexOf(Meteor.userId()) !== -1|| - classes.findOne({_id: Session.get("currentWork")._id}).blockEdit.indexOf(Meteor.userId()) !== -1 || - classes.findOne({_id: Session.get("currentWork")._id}).banned.indexOf(Meteor.userId()) !== -1 - ) return true; - } + if(Session.get("newWork")) { + return true; + } else { + if(Meteor.userId() === Session.get("currentWork").creator || + Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin']) || + classes.findOne({_id: Session.get("currentWork")._id}).moderators.indexOf(Meteor.userId()) !== -1|| + classes.findOne({_id: Session.get("currentWork")._id}).blockEdit.indexOf(Meteor.userId()) !== -1 || + classes.findOne({_id: Session.get("currentWork")._id}).banned.indexOf(Meteor.userId()) !== -1 + ) return true; + } } }); @@ -257,13 +272,13 @@ Template.main.events({ Session.set("sidebar", null); } if(e === "overlay") { - closeDivFade(document.getElementsByClassName("overlay")[0]); - if(!Session.get("newWork")) { - if(getHomeworkFormData() === null) return; - Session.set("serverData",Session.get("currentWork")); - sendData("editWork"); - } - Session.set("newWork",null); + closeDivFade(document.getElementsByClassName("overlay")[0]); + if(!Session.get("newWork")) { + if(getHomeworkFormData() === null) return; + Session.set("serverData",Session.get("currentWork")); + sendData("editWork"); + } + Session.set("newWork",null); } if (event.target.id !== sessval && @@ -273,9 +288,9 @@ Template.main.events({ closeInput(sessval); } if (!event.target.className.includes("radio") && - !Session.equals("radioDiv", null) && - !event.target.parentNode.className.includes("workOptions") && - event.target.readOnly !== true) { + !Session.equals("radioDiv", null) && + !event.target.parentNode.className.includes("workOptions") && + event.target.readOnly !== true) { var opnum = (parseInt(Session.get("radioDiv")) - parseInt(Session.get("radioOffset"))).toString(); for (var i = 0; i < document.getElementsByClassName("workOptions").length; i++) { try { @@ -287,20 +302,20 @@ Template.main.events({ } }, 'click .creWork' (event) { - if(event.target.className !== "creWork") { - var attr = event.target.parentNode.getAttribute("classid"); - } else { - var attr = event.target.getAttribute("classid"); - } + if(event.target.className !== "creWork") { + var attr = event.target.parentNode.getAttribute("classid"); + } else { + var attr = event.target.getAttribute("classid"); + } Session.set("newWork", true); Session.set("currentReadableWork", - { - name:"Name | Click here to edit...", - class:attr, - dueDate:"Click here to edit...", - description:"Click here to edit...", - type:"Click here to edit..." - }); + { + name:"Name | Click here to edit...", + class:attr, + dueDate:"Click here to edit...", + description:"Click here to edit...", + type:"Click here to edit..." + }); Session.set("currentWork",{class:attr}); openDivFade(document.getElementsByClassName("overlay")[0]); }, @@ -329,11 +344,11 @@ Template.main.events({ input.style.height = 3 * dim.height.toString() + "px"; input.rows = "4"; } else if (typ !== null) { - input.type = typ; - input.style.height = 0.9 * dim.height.toString() + "px"; + input.type = typ; + input.style.height = 0.9 * dim.height.toString() + "px"; } else { - input.typ = "text"; - input.style.height = 0.9 * dim.height.toString() + "px"; + input.typ = "text"; + input.style.height = 0.9 * dim.height.toString() + "px"; } input.value = ele.childNodes[0].nodeValue; input.className = "changeInput"; @@ -351,7 +366,7 @@ Template.main.events({ input.select(); } if(ele.id === "workDate") { - input.className += " form-control"; + input.className += " form-control"; } input.focus(); if (ele.getAttribute("restrict") !== null) { @@ -424,37 +439,38 @@ Template.main.events({ } }, 'click #workSubmit' () { - if(getHomeworkFormData() === null) return; - Session.set("serverData",Session.get("currentWork")); - if(Session.get("newWork")) { - sendData("createWork"); - } else { - sendData("editWork"); - } - Session.set("newWork",null); + if(getHomeworkFormData() === null) return; + Session.set("serverData",Session.get("currentWork")); + if(Session.get("newWork")) { + sendData("createWork"); + } else { + sendData("editWork"); + } + Session.set("newWork",null); closeDivFade(document.getElementsByClassName("overlay")[0]); }, 'focus .op' (event) { event.target.click(); }, 'click .workCard' (event) { - var dom = event.target; - while(event.target.className !== "workCard") event.target = event.target.parentNode; - workid = event.target.getAttribute("workid"); - Session.set("newWork",false); - var thisWork = work.findOne({_id:workid}); - Session.set("currentWork",thisWork); - var thisReadWork = formReadable(thisWork); - Session.set("currentReadableWork",thisReadWork); - openDivFade(document.getElementsByClassName("overlay")[0]); + var dom = event.target; + while(event.target.className !== "workCard") event.target = event.target.parentNode; + workid = event.target.getAttribute("workid"); + Session.set("newWork",false); + var thisWork = work.findOne({_id:workid}); + Session.set("currentWork",thisWork); + var thisReadWork = formReadable(thisWork); + Session.set("currentReadableWork",thisReadWork); + openDivFade(document.getElementsByClassName("overlay")[0]); }, 'focus #workDatea' () { - $('#workDatea').datepicker({ - format: 'DD, MM d, yyyy', - startDate: 'mm-dd-yyyy', - autoclose: true, + $('#workDatea').datepicker({ + format: 'DD, MM d, yyyy', + startDate: 'd', + todayHighlight: true, + autoclose: true - }); + }); } }); @@ -494,59 +510,59 @@ function closeInput(sessval) { span.style.display = "initial"; Session.set("modifying", null); if(!Session.get("newWork")) { - if(getHomeworkFormData() === null) return; - Session.set("serverData",Session.get("currentWork")); - sendData("editWork"); + if(getHomeworkFormData() === null) return; + Session.set("serverData",Session.get("currentWork")); + sendData("editWork"); } } function getHomeworkFormData() { - var inputs = document.getElementsByClassName("req"); - var stop; - for(var i = 0; i < inputs.length; i++) { - var value = inputs[i].childNodes[0].nodeValue; - if(value.includes("Click here to edit")) { - inputs[i].childNodes[0].nodeValue = "Missing field"; - inputs[i].style.color = "#FF1A1A"; - stop = true; - } - } - var desc = document.getElementById("workDesc"); - if(desc.childNodes[0].nodeValue.includes("Click here to edit")) { - desc.childNodes[0].nodeValue = "Missing field"; - desc.style.color = "#FF1A1A"; - stop = true; - } - if(stop) return null; + var inputs = document.getElementsByClassName("req"); + var stop; + for(var i = 0; i < inputs.length; i++) { + var value = inputs[i].childNodes[0].nodeValue; + if(value.includes("Click here to edit")) { + inputs[i].childNodes[0].nodeValue = "Missing field"; + inputs[i].style.color = "#FF1A1A"; + stop = true; + } + } + var desc = document.getElementById("workDesc"); + if(desc.childNodes[0].nodeValue.includes("Click here to edit")) { + desc.childNodes[0].nodeValue = "Missing field"; + desc.style.color = "#FF1A1A"; + stop = true; + } + if(stop) return null; - var data = Session.get("currentWork"); - data.name = document.getElementById("workName").childNodes[0].nodeValue; - data.dueDate = toDate(document.getElementById("workDate").childNodes[0].nodeValue); - data.description = document.getElementById("workDesc").childNodes[0].nodeValue; - data.type = document.getElementById("workType").childNodes[0].nodeValue.toLowerCase(); - - Session.set("currentWork", data); - var readableData = formReadable(data); - Session.set("currentReadableWork", readableData); + var data = Session.get("currentWork"); + data.name = document.getElementById("workName").childNodes[0].nodeValue; + data.dueDate = toDate(document.getElementById("workDate").childNodes[0].nodeValue); + data.description = document.getElementById("workDesc").childNodes[0].nodeValue; + data.type = document.getElementById("workType").childNodes[0].nodeValue.toLowerCase(); + + Session.set("currentWork", data); + var readableData = formReadable(data); + Session.set("currentReadableWork", readableData); } var days = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]; var months = ["January","February","March","April","May","June","July","August","September","October","November","December"]; function getReadableDate(date) { - return days[date.getDay()]+", "+months[date.getMonth()]+" "+date.getDate()+", "+date.getFullYear(); + return days[date.getDay()]+", "+months[date.getMonth()]+" "+date.getDate()+", "+date.getFullYear(); } function toDate(date) { - date = date.substring(date.search(",")+2,date.length); - month = months.indexOf(date.substring(0,date.search(" "))); - day = date.substring(date.search(" ")+1,date.search(",")); - year = date.substring(date.search(",")+2,date.length); - return new Date(year,month,day,11,59,59); + date = date.substring(date.search(",")+2,date.length); + month = months.indexOf(date.substring(0,date.search(" "))); + day = date.substring(date.search(" ")+1,date.search(",")); + year = date.substring(date.search(",")+2,date.length); + return new Date(year,month,day,11,59,59); } function formReadable(input) { - input.dueDate = getReadableDate(input.dueDate); - input.type = input.type[0].toUpperCase() + input.type.slice(1); - return input; + input.dueDate = getReadableDate(input.dueDate); + input.type = input.type[0].toUpperCase() + input.type.slice(1); + return input; } diff --git a/hourglass/server/main.js b/hourglass/server/main.js index f8d5910..97d61f7 100644 --- a/hourglass/server/main.js +++ b/hourglass/server/main.js @@ -5,18 +5,13 @@ import { Mongo } from 'meteor/mongo'; -_uuid4 = function(cc) { - var rr = Math.random() * 16 | 0; - return (cc === 'x' ? rr : (rr & 0x3 | 0x8)).toString(16); -}; - superadmins = [ "ybq987@gmail.com", "ksjdragon@gmail.com" ]; -worktype = ["test", "quiz", "project", "normal"]; -var possiblelist = ["moderators","banned"]; +worktype = ["test", "quiz", "project", "normal", "other"]; +var possiblelist = ["moderators", "banned"]; for (var i = 0; i < superadmins.length; i++) { var superadmin = superadmins[i]; @@ -81,7 +76,11 @@ Meteor.publish('users', function() { if (Roles.userIsInRole(this.userId, ['superadmin', 'admin'])) { return Meteor.users.find(); } else { - return Meteor.users.find({}, {fields: {'services.google.email': 1}}); + return Meteor.users.find({}, { + fields: { + 'services.google.email': 1 + } + }); } }); @@ -89,7 +88,7 @@ Security.permit(['insert', 'update', 'remove']).collections([schools, classes, w Meteor.methods({ 'genCode': function() { - return 'xxxxxx'.replace(/[x]/g, _uuid4); + return Math.random().toString(36).substring(7); }, 'createSchool': function(schoolname) { if (Meteor.user() !== null && @@ -153,41 +152,69 @@ Meteor.methods({ classes.insert(input, function(err, result) { Meteor.call('joinClass', [result, input.code]); }); - + return 1; } else { throw "Unauthorized"; } }, 'changeAdmin': function(input) { - var found = Meteor.users.find({_id: input[0]}); - var foundclass = classes.find({_id: input[1]}); + var found = Meteor.users.find({ + _id: input[0] + }); + var foundclass = classes.find({ + _id: input[1] + }); if (Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin'])) { - classes.update({_id: input[1]}, {$set: {admin: input[0]}}); + classes.update({ + _id: input[1] + }, { + $set: { + admin: input[0] + } + }); } else if (found && foundclass && foundclass.admin == Meteor.userId() && - foundclass.banned.indexOf(input[0]) === -1 && - foundclass.subscribers.indexOf(input[0]) !== -1) { - classes.update({_id: input[1]}, {$set: {admin: input[0]}}); + foundclass.banned.indexOf(input[0]) === -1 && + foundclass.subscribers.indexOf(input[0]) !== -1) { + classes.update({ + _id: input[1] + }, { + $set: { + admin: input[0] + } + }); } else { throw "Unauthorized"; } }, 'trackUserInClass': function(input) { - var foundclass = classes.findOne({_id: input[1]}); + var foundclass = classes.findOne({ + _id: input[1] + }); var userlist = input[2]; var index = possiblelist.indexOf(input[2]); var set = {}; set[userlist] = foundclass[userlist].concat(input[0]); if (Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin'])) { - classes.update({_id: input[1]}, {$set: set}); + classes.update({ + _id: input[1] + }, { + $set: set + }); } else if (foundclass && foundclass.admin == Meteor.userId() && index !== -1 && - (index === 1 || foundclass.moderators.indexOf(Meteor.userId()) !== -1) && - foundclass[userlist].indexOf(input[0]) === -1) { - classes.update({_id: input[1]}, {$set: set}); + (index === 1 || foundclass.moderators.indexOf(Meteor.userId()) !== -1) && + foundclass[userlist].indexOf(input[0]) === -1) { + classes.update({ + _id: input[1] + }, { + $set: set + }); } }, 'untrackUserInClass': function(input) { - var foundclass = classes.findOne({_id: input[1]}); + var foundclass = classes.findOne({ + _id: input[1] + }); var userlist = input[2]; var index = possiblelist.indexOf(input[2]); var set = {}; @@ -195,21 +222,31 @@ Meteor.methods({ set[userlist] = foundclass[userlist]; if (Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin'])) { - classes.update({_id: input[1]}, {$set: set}); + classes.update({ + _id: input[1] + }, { + $set: set + }); } else if (foundclass && foundclass.admin == Meteor.userId() && index !== -1 && - (index === 1 || foundclass.moderators.indexOf(Meteor.userId()) !== -1) && - foundclass[userlist].indexOf(input[0]) !== -1) { - classes.update({_id: input[1]}, {$set: set}); + (index === 1 || foundclass.moderators.indexOf(Meteor.userId()) !== -1) && + foundclass[userlist].indexOf(input[0]) !== -1) { + classes.update({ + _id: input[1] + }, { + $set: set + }); } }, 'deleteClass': function(classid) { var found = classes.findOne({ _id: classid }); - if (Meteor.user() !== null && found !== null && - (found.admin === Meteor.user()._id || Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin']))) { + if (Meteor.user() !== null && found !== null && + (found.admin === Meteor.user()._id || Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin']))) { for (var i = 0; i < found.subscribers.length; i++) { - var current = Meteor.users.findOne({_id:found.subscribers[i]}).profile; + var current = Meteor.users.findOne({ + _id: found.subscribers[i] + }).profile; var index = current.classes.indexOf(classid); current.classes.splice(index, 1); Meteor.users.update({ @@ -226,7 +263,9 @@ Meteor.methods({ } }, 'createWork': function(input) { - var ref = new Date().getTime(); + var ref = new Date(); + ref.setHours(0,0,0,0); + ref = ref.getTime(); input.creator = Meteor.userId(); work.schema.validate(input); var found = classes.findOne({ @@ -234,12 +273,12 @@ Meteor.methods({ }); if (Meteor.user() !== null && - found !== null && - Meteor.user().profile.classes.indexOf(input.class) !== -1 && - found.banned.indexOf(Meteor.userId()) === -1 && - input.dueDate instanceof Date && input.dueDate.getTime() >= ref && - worktype.indexOf(input.type) != -1 && - input.name.length <= 50 && input.description.length <= 150) { + found !== null && + Meteor.user().profile.classes.indexOf(input.class) !== -1 && + found.banned.indexOf(Meteor.userId()) === -1 && + input.dueDate instanceof Date && input.dueDate.getTime() >= ref && + worktype.indexOf(input.type) != -1 && + input.name.length <= 50 && input.description.length <= 150) { input.confirmations = [Meteor.userId()]; input.reports = []; @@ -251,8 +290,9 @@ Meteor.methods({ }, 'editWork': function(change) { - var ref = new Date().getTime(); - + var ref = new Date(); + ref.setHours(0,0,0,0); + ref = ref.getTime(); var currentclass = classes.findOne({ _id: work.findOne({ _id: change._id @@ -284,7 +324,7 @@ Meteor.methods({ _id: change._id }).creator) { if (change.name.length <= 50 && worktype.indexOf(change.type) != -1 && - input.dueDate instanceof Date && input.dueDate.getTime() >= ref) { + input.dueDate instanceof Date && input.dueDate.getTime() >= ref) { Meteor.update({ _id: change._id }, { @@ -310,15 +350,15 @@ Meteor.methods({ }); var user = Meteor.userId(); if (typeof comment === "string" && comment.length <= 200 && - currentclass.subscribers.indexOf(Meteor.userId()) != -1 && - currentclass.banned.indexOf(Meteor.userId()) === -1) { + currentclass.subscribers.indexOf(Meteor.userId()) != -1 && + currentclass.banned.indexOf(Meteor.userId()) === -1) { var comments = workobject.comments.concat(comment); work.update({ _id: input[1] }, { $set: { comments: comments, - user:user, + user: user, time: new Date() } }); @@ -331,8 +371,7 @@ Meteor.methods({ var currentclass = classes.findOne({ _id: workobject.class }); - if (currentclass.subscribers.indexOf(Meteor.userId()) != -1 && - ["confirmations", "reports", "done"].indexOf(input[1]) != -1) { + if (currentclass.subscribers.indexOf(Meteor.userId()) != -1 && ["confirmations", "reports", "done"].indexOf(input[1]) != -1) { userindex = workobject[input[1]].indexOf(Meteor.userId()); if (userindex === -1) { workobject[input[1]] = workobject[input[1]].concat(Meteor.userId()); @@ -374,10 +413,10 @@ Meteor.methods({ current.banner = change.banner; current.preferences = change.preferences; if (schools.findOne({ - name: current.school - }) !== null && - Number.isInteger(current.grade) && - current.grade >= 9 && current.grade <= 12) { + name: current.school + }) !== null && + Number.isInteger(current.grade) && + current.grade >= 9 && current.grade <= 12) { if (current.description && current.description.length > 50) { current.description = current.description.slice(0, 50); @@ -403,10 +442,16 @@ Meteor.methods({ status: true }); if (Meteor.user() !== null && - found !== null && - pass === found.code && - prof.classes.indexOf(change) === -1) { - classes.update({_id: found._id}, {$set: {subscribers: found.subscribers.concat(Meteor.userId())}}); + found !== null && + pass === found.code && + prof.classes.indexOf(change) === -1) { + classes.update({ + _id: found._id + }, { + $set: { + subscribers: found.subscribers.concat(Meteor.userId()) + } + }); var current = Meteor.user().profile; current.classes = current.classes.concat(change); Meteor.users.update({ @@ -422,13 +467,29 @@ Meteor.methods({ } }, 'joinPrivateClass': function(input) { - var found = classes.findOne({status: true, privacy: true, code:input}); + var found = classes.findOne({ + status: true, + privacy: true, + code: input + }); var current = Meteor.user().profile; if (found !== undefined && input !== undefined && - current.classes.indexOf(found._id) === -1) { - classes.update({_id: found._id}, {$set: {subscribers: found.subscribers.concat(Meteor.userId())}}); + current.classes.indexOf(found._id) === -1) { + classes.update({ + _id: found._id + }, { + $set: { + subscribers: found.subscribers.concat(Meteor.userId()) + } + }); current.classes = current.classes.concat(found._id); - Meteor.users.update({_id: Meteor.userId()}, {$set: {profile: current}}); + Meteor.users.update({ + _id: Meteor.userId() + }, { + $set: { + profile: current + } + }); return true; } else { return false; @@ -450,8 +511,16 @@ Meteor.methods({ profile: current } }); - var newstudents = classes.findOne({_id: change}).subscribers.splice(Meteor.userId(), 1); - classes.update({_id: change}, {$set: {subscribers: newstudents}}); + var newstudents = classes.findOne({ + _id: change + }).subscribers.splice(Meteor.userId(), 1); + classes.update({ + _id: change + }, { + $set: { + subscribers: newstudents + } + }); return 1; } else { throw "You are currently the admin of this class. Transfer ownership in order to leave this class.";