This commit is contained in:
Kenneth Jao 2016-08-25 23:09:51 -04:00
commit 2c1d8cddd8
2 changed files with 68 additions and 50 deletions

View File

@ -1,7 +1,9 @@
import { import {
Template Template
} from 'meteor/templating'; } from 'meteor/templating';
// Sets up global variables
Session.set("profInputOpen", null); Session.set("profInputOpen", null);
Session.set("profClassTab", "manClass"); Session.set("profClassTab", "manClass");
Session.set("modifying", null); Session.set("modifying", null);
@ -17,6 +19,9 @@ Session.set("code",null);
Session.set("noclass",null); Session.set("noclass",null);
Session.set("notfound",null); Session.set("notfound",null);
// Colors of the theme
var themeColors = { var themeColors = {
"light": { "light": {
"header": "#EBEBEB", "header": "#EBEBEB",
@ -72,14 +77,14 @@ Template.profile.helpers({
}] }]
}; };
}, },
mainCenter() { mainCenter() { // Centers main container
var width = window.innerWidth * 1600 / 1920 + 10; var width = window.innerWidth * 1600 / 1920 + 10;
return "width:" + width.toString() + "px;margin-left:" + -0.5 * width.toString() + "px"; return "width:" + width.toString() + "px;margin-left:" + -0.5 * width.toString() + "px";
}, },
mainHeight() { mainHeight() {
return window.innerHeight.toString() + "px"; return window.innerHeight.toString() + "px";
}, },
banner() { banner() { //Styles the banner
var width = window.innerWidth * 1600 / 1920; var width = window.innerWidth * 1600 / 1920;
var height = width * 615 / 1600; var height = width * 615 / 1600;
if (Meteor.user().profile.banner !== undefined) { if (Meteor.user().profile.banner !== undefined) {
@ -92,7 +97,7 @@ Template.profile.helpers({
} }
return "width:" + width.toString() + "px;height:" + height.toString() + "px;background-image:url(" + banner + ");background-size:" + width.toString() + "px " + height.toString() + "px"; return "width:" + width.toString() + "px;height:" + height.toString() + "px;background-image:url(" + banner + ");background-size:" + width.toString() + "px " + height.toString() + "px";
}, },
avatar() { avatar() { //Styles the avatar
var dim = window.innerWidth * 1600 / 1920 * 0.16; var dim = window.innerWidth * 1600 / 1920 * 0.16;
var pic = ""; var pic = "";
var userprofile = Meteor.user().profile.avatar; var userprofile = Meteor.user().profile.avatar;
@ -106,35 +111,35 @@ Template.profile.helpers({
} }
return "background-image:url(" + pic + ");background-size:" + dim.toString() + "px " + dim.toString() + "px"; return "background-image:url(" + pic + ");background-size:" + dim.toString() + "px " + dim.toString() + "px";
}, },
avatarDim() { avatarDim() { //Dimensions the avatar
var dim = window.innerWidth * 1600 / 1920 * 0.16; var dim = window.innerWidth * 1600 / 1920 * 0.16;
return "height:" + dim.toString() + "px;width:" + dim.toString() + "px;top:" + 0.43 * window.innerHeight.toString() + "px;"; return "height:" + dim.toString() + "px;width:" + dim.toString() + "px;top:" + 0.43 * window.innerHeight.toString() + "px;";
}, },
username() { username() { //Returns current user's username
return Meteor.user().profile.name; return Meteor.user().profile.name;
}, },
motd() { motd() { //Returns the current user's description
if (Meteor.user().profile.description) { if (Meteor.user().profile.description) {
return Meteor.user().profile.description; return Meteor.user().profile.description;
} else { } else {
return "Say something about yourself!"; return "Say something about yourself!";
} }
}, },
school() { school() { //Returns the current user's school's name
if (Meteor.user().profile.school) { if (Meteor.user().profile.school) {
return Meteor.user().profile.school; return Meteor.user().profile.school;
} else { } else {
return "Click here to edit..."; return "Click here to edit...";
} }
}, },
grade() { grade() { //Returns the current user's grade
if (Meteor.user().profile.grade) { if (Meteor.user().profile.grade) {
return Meteor.user().profile.grade + "th"; return Meteor.user().profile.grade + "th";
} else { } else {
return "Click here to edit..."; return "Click here to edit...";
} }
}, },
classes() { classes() { //Loads all of the possible classes ( Limit of twenty shown ) ( Sorts by class size )
var array = classes.find( var array = classes.find(
{ {
status: {$eq: true}, status: {$eq: true},
@ -155,30 +160,30 @@ Template.profile.helpers({
} }
return array; return array;
}, },
profClassHeight() { profClassHeight() { // Dimensions the class height
return 0.6 * window.innerHeight.toString() + "px"; return 0.6 * window.innerHeight.toString() + "px";
}, },
classHolderHeight() { classHolderHeight() { // Dimensions the container for the classes
return 0.26 * window.innerHeight.toString() + "px"; return 0.26 * window.innerHeight.toString() + "px";
}, },
profClassTabColor(status) {         profClassTabColor(status) { // Change this [Supposed to show the current mode that's selected via color]       
if (status === Session.get("profClassTab")) {             if (status === Session.get("profClassTab")) {            
return themeColors[Cookie.get("theme")].highlightText;         return themeColors[Cookie.get("theme")].highlightText;        
} else {             } else {            
return;         return;        
}     }    
}, },
profClassTab(tab) { profClassTab(tab) { // Tells current class
if (tab === Session.get("profClassTab")) { if (tab === Session.get("profClassTab")) {
return true; return true;
} else { } else {
return false; return false;
} }
}, },
notsearching() { notsearching() { // Tells whether user is using the searchbox
return Session.get("notsearching"); return Session.get("notsearching");
}, },
autocompleteClasses() { autocompleteClasses() { // Returns current auto-completes for classes
return Session.get("autocompleteDivs"); return Session.get("autocompleteDivs");
}, },
notfound() { notfound() {
@ -226,14 +231,7 @@ Template.profile.helpers({
}); });
Template.profile.events({ Template.profile.events({
'click profOptions p' (event) { 'click .change' (event) { // Allows changes to profile values
var p = event.target;
p.parentNode.parentNode.childNodes[1].value = p.childNodes[0].nodeValue;
closeDivFade(p.parentNode);
Session.set("radioDiv", null);
Session.set("radioOffset", null);
},
'click .change' (event) {
var ele = event.target; var ele = event.target;
var sessval = Session.get("modifying"); var sessval = Session.get("modifying");
if (ele.id !== sessval && sessval !== null) closeInput(sessval); if (ele.id !== sessval && sessval !== null) closeInput(sessval);
@ -276,7 +274,7 @@ Template.profile.events({
ele.parentNode.appendChild(span); ele.parentNode.appendChild(span);
} }
}, },
'click' (event) { 'click' (event) { // Whenever a click happens
var sessval = Session.get("modifying"); var sessval = Session.get("modifying");
if (event.target.id !== sessval && if (event.target.id !== sessval &&
event.target.id !== sessval + "a" && event.target.id !== sessval + "a" &&
@ -316,7 +314,7 @@ Template.profile.events({
document.getElementById("joinPrivClass").style.marginBottom = "-10%"; document.getElementById("joinPrivClass").style.marginBottom = "-10%";
} }
}, },
'keydown' (event) { 'keydown' (event) { // Whenever one key is pressed (for character restrictions)
var sessval = Session.get("modifying"); var sessval = Session.get("modifying");
if (event.keyCode == 13) { if (event.keyCode == 13) {
try { try {
@ -343,7 +341,7 @@ Template.profile.events({
} }
} }
}, },
'click .radio' (event) { 'click .radio' (event) { // Click on an input that has a drop-down menu
var op = event.target; var op = event.target;
Session.set("radioDiv", op.getAttribute("op")); Session.set("radioDiv", op.getAttribute("op"));
Session.set("radioOffset", op.getAttribute("opc")); Session.set("radioOffset", op.getAttribute("opc"));
@ -357,7 +355,7 @@ Template.profile.events({
} catch (err) {} } catch (err) {}
openDivFade(document.getElementsByClassName("profOptions")[op.getAttribute("op")]); openDivFade(document.getElementsByClassName("profOptions")[op.getAttribute("op")]);
}, },
'click .profOptions p' (event) { 'click .profOptions p' (event) { // When someone selects "drop-down item"
var sessval = Session.get("modifying"); var sessval = Session.get("modifying");
var p = event.target; var p = event.target;
var opnum = parseInt(Session.get("radioDiv")) - parseInt(Session.get("radioOffset")); var opnum = parseInt(Session.get("radioDiv")) - parseInt(Session.get("radioOffset"));
@ -396,13 +394,7 @@ Template.profile.events({
openDivFade(functionHolder);         openDivFade(functionHolder);        
}, 300);     }, 300);    
}, },
'click .fa-search' () { 'keyup #profClassSearch' (event) { // Auto-complete updater
Session.set("searching", true);
},
'click .fa-times-thin' () {
Session.set("searching", false);
},
'keyup #profClassSearch' (event) {
if (event.target.value.length === 0) { if (event.target.value.length === 0) {
Session.set("notsearching", true); Session.set("notsearching", true);
} else { } else {
@ -431,7 +423,7 @@ Template.profile.events({
} }
} catch (err) {} } catch (err) {}
}, },
'click .classBox' (event) { 'click .classBox' (event) { // When you click on a box that holds class
if (event.target.id === "label" || if (event.target.id === "label" ||
Session.get("profClassTab") === "manClass" || Session.get("profClassTab") === "manClass" ||
event.target.className.includes("fa-times")) return; event.target.className.includes("fa-times")) return;
@ -451,7 +443,7 @@ Template.profile.events({
document.getElementsByClassName("overlay")[0].style.opacity = "1"; document.getElementsByClassName("overlay")[0].style.opacity = "1";
}, 200); }, 200);
}, },
'click .fa-check-circle-o' () { 'click .fa-check-circle-o' () { // Confirmation Button
sendData(Session.get("confirm")); sendData(Session.get("confirm"));
closeDivFade(document.getElementsByClassName("overlay")[0]); closeDivFade(document.getElementsByClassName("overlay")[0]);
if(Session.get("confirm") === "createClass") { if(Session.get("confirm") === "createClass") {
@ -461,12 +453,12 @@ Template.profile.events({
Session.set("serverData", null); Session.set("serverData", null);
Session.set("confirm", null); Session.set("confirm", null);
}, },
'click .fa-times-circle-o' () { 'click .fa-times-circle-o' () { // Deny Button
closeDivFade(document.getElementsByClassName("overlay")[0]); closeDivFade(document.getElementsByClassName("overlay")[0]);
Session.set("serverData", null); Session.set("serverData", null);
Session.set("confirm", null); Session.set("confirm", null);
}, },
'click #creSubmit' () { 'click #creSubmit' () { //Submits form data for class
var data = getCreateFormData(); var data = getCreateFormData();
if (data === null) return; if (data === null) return;
Session.set("serverData", data); Session.set("serverData", data);
@ -475,10 +467,10 @@ Template.profile.events({
openDivFade(document.getElementsByClassName("overlay")[0]); openDivFade(document.getElementsByClassName("overlay")[0]);
}, },
'focus .op' (event) { 'focus .op' (event) { // Browser Casework
event.target.click(); event.target.click();
}, },
'click .owned' (event) { 'click .owned' (event) { // When you click your own class
if (event.target.id === "label") return; if (event.target.id === "label") return;
if (!event.target.className.includes("owned")) { if (!event.target.className.includes("owned")) {
var attribute = event.target.parentNode.getAttribute("classid"); var attribute = event.target.parentNode.getAttribute("classid");
@ -488,7 +480,7 @@ Template.profile.events({
Session.set("selectClassId",attribute); Session.set("selectClassId",attribute);
document.getElementById("createdClasses").style.marginRight = "0"; document.getElementById("createdClasses").style.marginRight = "0";
}, },
'click .userAdder .fa-plus' (event) { 'click .userAdder .fa-plus' (event) { // Gives/Removes User Privileges
var input = event.target.parentNode.childNodes[3]; var input = event.target.parentNode.childNodes[3];
input.placeholder = "1234@abc.xyz"; input.placeholder = "1234@abc.xyz";
input.className.replace(" formInvalid",""); input.className.replace(" formInvalid","");
@ -509,7 +501,7 @@ Template.profile.events({
sendData("trackUserInClass"); sendData("trackUserInClass");
}, },
'click .classBox .fa-times' (event) { 'click .classBox .fa-times' (event) { // Leaves a class
var box = event.target.parentNode; var box = event.target.parentNode;
var classid = box.getAttribute("classid"); var classid = box.getAttribute("classid");
Session.set("serverData", box.getAttribute("classid")); Session.set("serverData", box.getAttribute("classid"));
@ -517,7 +509,7 @@ Template.profile.events({
Session.set("confirmText", "Leave this class?"); Session.set("confirmText", "Leave this class?");
openDivFade(document.getElementsByClassName("overlay")[0]); openDivFade(document.getElementsByClassName("overlay")[0]);
}, },
'click .userBox .fa-times' (event) { 'click .userBox .fa-times' (event) { // Removes user from permissions
var box = event.target.parentNode; var box = event.target.parentNode;
Session.set("serverData", [ Session.set("serverData", [
box.getAttribute("userid"), box.getAttribute("userid"),
@ -526,18 +518,18 @@ Template.profile.events({
]) ])
sendData("untrackUserInClass"); sendData("untrackUserInClass");
}, },
'click #copy' () { 'click #copy' () { //Copies googlee-classroom style code
if(document.getElementById("code").value === "None") return; if(document.getElementById("code").value === "None") return;
document.getElementById("code").select(); document.getElementById("code").select();
document.execCommand("copy"); document.execCommand("copy");
}, },
'click #deleteClass' () { 'click #deleteClass' () {
Session.set("serverData",document.getElementById("createdClasses").getAttribute("classid")); Session.set("serverData",document.getElementById("createdClasses").getAttribute("classid"));
Session.set("confirm", "deleteClass"); Session.set("confirm", "deleteClass");
Session.set("confirmText", "Delete this class?"); Session.set("confirmText", "Delete this class?");
openDivFade(document.getElementsByClassName("overlay")[0]); openDivFade(document.getElementsByClassName("overlay")[0]);
}, },
'click #changeAdmin span' (event) { 'click #changeAdmin span' (event) {
if(Session.get("changeAdmin")) return; if(Session.get("changeAdmin")) return;
Session.set("changeAdmin",true); Session.set("changeAdmin",true);
var input = document.createElement("input"); var input = document.createElement("input");
@ -548,7 +540,7 @@ Template.profile.events({
event.target.parentNode.appendChild(input); event.target.parentNode.appendChild(input);
event.target.parentNode.appendChild(i); event.target.parentNode.appendChild(i);
}, },
'click .fa-exchange' (event) { 'click .fa-exchange' (event) { //Changes class admin upon confirmation
var input = event.target.parentNode.childNodes[3]; var input = event.target.parentNode.childNodes[3];
input.placeholder = "1234@abc.xyz"; input.placeholder = "1234@abc.xyz";
input.className.replace(" formInvalid",""); input.className.replace(" formInvalid","");
@ -567,14 +559,14 @@ Template.profile.events({
openDivFade(document.getElementsByClassName("overlay")[0]) openDivFade(document.getElementsByClassName("overlay")[0])
document.getElementById("createdClasses").style.marginRight = "-40%"; document.getElementById("createdClasses").style.marginRight = "-40%";
}, },
'click #private' (event) { 'click #private' (event) { // Joins private class
Session.set("privateClass",true); Session.set("privateClass",true);
var input = document.getElementById("privateCode"); var input = document.getElementById("privateCode");
input.className = ""; input.className = "";
input.placeholder = "Enter code here..."; input.placeholder = "Enter code here...";
document.getElementById("joinPrivClass").style.marginBottom = "0"; document.getElementById("joinPrivClass").style.marginBottom = "0";
}, },
'click #privSubmit' () { 'click #privSubmit' () { // Submits private class code
var input = document.getElementById("privateCode"); var input = document.getElementById("privateCode");
var code = input.value; var code = input.value;
input.value = ""; input.value = "";

View File

@ -1,3 +1,4 @@
//meteor things
import { import {
Meteor Meteor
} from 'meteor/meteor'; } from 'meteor/meteor';
@ -5,15 +6,20 @@ import {
Mongo Mongo
} from 'meteor/mongo'; } from 'meteor/mongo';
// Defines who the admins are - not added
superadmins = [ superadmins = [
"ybq987@gmail.com", "ybq987@gmail.com",
"ksjdragon@gmail.com" "ksjdragon@gmail.com"
]; ];
worktype = ["test", "quiz", "project", "normal", "other"]; worktype = ["test", "quiz", "project", "normal", "other"];
var possiblelist = ["moderators", "banned"]; var possiblelist = ["moderators", "banned"];
// Adds roles to superadmins // Adds roles to superadmins
// Not necessary on every run // Not necessary on every run
// Makes superadmins superadmins
for (var i = 0; i < superadmins.length; i++) { for (var i = 0; i < superadmins.length; i++) {
var superadmin = superadmins[i]; var superadmin = superadmins[i];
if (Meteor.users.findOne({ if (Meteor.users.findOne({
@ -26,10 +32,14 @@ for (var i = 0; i < superadmins.length; i++) {
} }
} }
//
Meteor.publish('schools', function() { Meteor.publish('schools', function() {
return schools.find(); return schools.find();
}); });
// Returns the code for classes (for debug)
Meteor.publish('classes', function() { Meteor.publish('classes', function() {
if (Roles.userIsInRole(this.userId, ['superadmin', 'admin'])) { if (Roles.userIsInRole(this.userId, ['superadmin', 'admin'])) {
return classes.find(); return classes.find();
@ -70,6 +80,8 @@ Meteor.publish('classes', function() {
} }
}); });
//Gives everything in work if superadmin
Meteor.publish('work', function() { Meteor.publish('work', function() {
if (Roles.userIsInRole(this.userId, ['superadmin', 'admin'])) { if (Roles.userIsInRole(this.userId, ['superadmin', 'admin'])) {
return work.find(); return work.find();
@ -92,6 +104,8 @@ Meteor.publish('work', function() {
}); });
//Returns issues in sites (not implemented on client)
Meteor.publish('requests', function() { Meteor.publish('requests', function() {
if (Roles.userIsInRole(this.userId, ['superadmin', 'admin'])) { if (Roles.userIsInRole(this.userId, ['superadmin', 'admin'])) {
return requests.find(); return requests.find();
@ -102,6 +116,8 @@ Meteor.publish('requests', function() {
} }
}); });
//Publishes every-persons email and user-ids
Meteor.publish('users', function() { Meteor.publish('users', function() {
if (Roles.userIsInRole(this.userId, ['superadmin', 'admin'])) { if (Roles.userIsInRole(this.userId, ['superadmin', 'admin'])) {
return Meteor.users.find(); return Meteor.users.find();
@ -120,6 +136,9 @@ Security.permit(['insert', 'update', 'remove']).collections([schools, classes, w
Meteor.methods({ Meteor.methods({
//Stuff that is accessible in client
//Generates private codes for classes - like google classroom
'genCode': function() { 'genCode': function() {
currcode = Math.random().toString(36).substr(2, 6); currcode = Math.random().toString(36).substr(2, 6);
while (classes.findOne({ while (classes.findOne({
@ -131,6 +150,8 @@ Meteor.methods({
}, },
// School Functions // School Functions
//Ability to create schools for selections
'createSchool': function(schoolname) { 'createSchool': function(schoolname) {
if (Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin'])) { if (Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin'])) {
schools.insert({ schools.insert({
@ -140,6 +161,7 @@ Meteor.methods({
throw "Unauthorized"; throw "Unauthorized";
} }
}, },
//Deletes school
'deleteSchool': function(schoolId) { 'deleteSchool': function(schoolId) {
if (Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin'])) { if (Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin'])) {
schools.remove({ schools.remove({
@ -219,6 +241,9 @@ Meteor.methods({
throw "Unauthorized"; throw "Unauthorized";
} }
}, },
// Allows someone to manage the class
'trackUserInClass': function(input) { 'trackUserInClass': function(input) {
var foundclass = classes.findOne({ var foundclass = classes.findOne({
_id: input[1] _id: input[1]
@ -410,6 +435,7 @@ Meteor.methods({
throw "Unauthorized"; throw "Unauthorized";
} }
}, },
'toggleWork': function(input) { 'toggleWork': function(input) {
var workobject = work.findOne({ var workobject = work.findOne({
_id: input[0] _id: input[0]