new updating system, in progress
This commit is contained in:
parent
a029d886d0
commit
f10e29767a
@ -1089,6 +1089,11 @@ textarea.clickModify {
|
|||||||
pointer-events: auto;
|
pointer-events: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.fc-day {
|
||||||
|
max-height: 11vh;
|
||||||
|
overflow-y: auto;
|
||||||
|
}
|
||||||
|
|
||||||
#workComment {
|
#workComment {
|
||||||
width: 99%;
|
width: 99%;
|
||||||
margin-bottom: 3%;
|
margin-bottom: 3%;
|
||||||
|
|||||||
@ -23,6 +23,7 @@ var defaultWork = {
|
|||||||
Session.set("user", {}); // Stores user preferences.
|
Session.set("user", {}); // Stores user preferences.
|
||||||
Session.set("calendarEvents", []); // Stores calendar classes.
|
Session.set("calendarEvents", []); // Stores calendar classes.
|
||||||
Session.set("myClasses", []); // Stores user classes.
|
Session.set("myClasses", []); // Stores user classes.
|
||||||
|
Session.set("myWork", []); // Stores user related work.
|
||||||
Session.set("requests", false); // Status of requests.
|
Session.set("requests", false); // Status of requests.
|
||||||
Session.set("sidebarMode", ""); // Status of sidebars.
|
Session.set("sidebarMode", ""); // Status of sidebars.
|
||||||
Session.set("newWork", null); // If user creating new work.
|
Session.set("newWork", null); // If user creating new work.
|
||||||
@ -48,6 +49,18 @@ Template.main.created = function() {
|
|||||||
$(".overlay").fadeOut(150);
|
$(".overlay").fadeOut(150);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
getClasses();
|
||||||
|
work.find().observeChanges({
|
||||||
|
added: function (id, fields) {
|
||||||
|
updateWork(id, fields, "added");
|
||||||
|
},
|
||||||
|
changed: function (id, fields) {
|
||||||
|
updateWork(id, fields, "changed");
|
||||||
|
},
|
||||||
|
removed: function (id) {
|
||||||
|
updateWork(id, null, "remove");
|
||||||
|
}
|
||||||
|
});
|
||||||
/*if (Notification.permission !== "granted") {
|
/*if (Notification.permission !== "granted") {
|
||||||
Notification.requestPermission().then(function(result) {
|
Notification.requestPermission().then(function(result) {
|
||||||
|
|
||||||
@ -130,19 +143,171 @@ Template.registerHelper('overlayDim', (part) => { // Gets size of the overlay co
|
|||||||
});
|
});
|
||||||
|
|
||||||
Template.registerHelper('myClasses', () => { // Gets all classes and respective works.
|
Template.registerHelper('myClasses', () => { // Gets all classes and respective works.
|
||||||
if (Session.get("user").classes.length === 0) { // Null checking.
|
/*var myClasses = Session.get("user").classes;
|
||||||
|
var classDisp = Session.get("classDisp");
|
||||||
|
if (myClasses.length === 0) { // Null checking.
|
||||||
return [];
|
return [];
|
||||||
} else {
|
} else {
|
||||||
var array = myClasses();
|
var array = [];
|
||||||
|
for(var i = 0; i < myClasses.length; i++) {
|
||||||
|
var classObj;
|
||||||
|
if(myClasses[i] === Meteor.userId()) {
|
||||||
|
classObj.name = "Personal";
|
||||||
|
classObj.box = " owned";
|
||||||
|
classObj.mine = false; // Actual value is reversed.
|
||||||
|
classObj.subscribers = 1;
|
||||||
|
} else {
|
||||||
|
classObj = classes.findOne({_id: myClasses[i]});
|
||||||
|
if(classObj === undefined) return;
|
||||||
|
var isAdmin = classObj.admin === Meteor.userId();
|
||||||
|
classObj.box = (isAdmin) ? " owned" : "";
|
||||||
|
classObj.mine = (isAdmin) ? false : true; // Actual value is reversed
|
||||||
|
classObj.subscribers = classObj.subscribers.length;
|
||||||
|
classObj.teachershort = (found.teacher === undefined) ? "" : found.teacher.split(" ").slice(1).reduce(function(a,b) { return a+ " " + b;});
|
||||||
|
}
|
||||||
|
|
||||||
|
classObj.selected = ((classDisp.indexOf(myClasses[i]) !== -1)) ? Session.get("user").preferences.theme.modeHighlight : "rgba(0,0,0,0)"; // Filter selected.
|
||||||
|
array.push(classObj);
|
||||||
|
}*/
|
||||||
|
/* var array = myClasses();
|
||||||
if(Meteor.Device.isPhone()) mobileWork();
|
if(Meteor.Device.isPhone()) mobileWork();
|
||||||
Session.set("myClasses", array);
|
Session.set("myClasses", array);
|
||||||
calendarEvents(array);
|
calendarEvents(array);
|
||||||
$("#fullcalendar").fullCalendar("removeEvents");
|
$("#fullcalendar").fullCalendar("removeEvents");
|
||||||
$("#fullcalendar").fullCalendar("addEventSource", Session.get("calendarEvents"))
|
$("#fullcalendar").fullCalendar("addEventSource", Session.get("calendarEvents"))*/
|
||||||
return array;
|
return Session.get("myClasses");
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Template.registerHelper('myWork', () => {
|
||||||
|
return Session.get("myWork");
|
||||||
|
});
|
||||||
|
|
||||||
|
getClasses = function() {
|
||||||
|
var array = [];
|
||||||
|
var myClasses = Session.get("user").classes;
|
||||||
|
var classDisp = Session.get("classDisp");
|
||||||
|
for(var i = 0; i < myClasses.length; i++) {
|
||||||
|
var classObj = {};
|
||||||
|
if(myClasses[i] === Meteor.userId()) {
|
||||||
|
classObj.name = "Personal";
|
||||||
|
classObj.box = " owned";
|
||||||
|
classObj.mine = false; // Actual value is reversed.
|
||||||
|
classObj.subscribers = 1;
|
||||||
|
classObj.admin = Meteor.userId();
|
||||||
|
classObj._id = Meteor.userId();
|
||||||
|
} else {
|
||||||
|
classObj = classes.findOne({_id: myClasses[i]});
|
||||||
|
if(classObj === undefined) return;
|
||||||
|
var isAdmin = classObj.admin === Meteor.userId();
|
||||||
|
classObj.box = (isAdmin) ? " owned" : "";
|
||||||
|
classObj.mine = (isAdmin) ? false : true; // Actual value is reversed
|
||||||
|
classObj.subscribers = classObj.subscribers.length;
|
||||||
|
classObj.teachershort = (classObj.teacher === undefined) ? "" : classObj.teacher.split(" ").slice(1).reduce(function(a,b) { return a+ " " + b;});
|
||||||
|
}
|
||||||
|
|
||||||
|
classObj.selected = ((classDisp.indexOf(myClasses[i]) !== -1)) ? Session.get("user").preferences.theme.modeHighlight : "rgba(0,0,0,0)"; // Filter selected.
|
||||||
|
array.push(classObj);
|
||||||
|
}
|
||||||
|
Session.set("myClasses", array);
|
||||||
|
}
|
||||||
|
|
||||||
|
updateWork = function(id, fields, type) {
|
||||||
|
if(type === "remove" && Session.get("myWork").filter(function(work) { // Removed work and exists in user data.
|
||||||
|
return work._id === id;
|
||||||
|
}).length !== 0) {
|
||||||
|
Session.set("myWork", Session.get("myWork").filter(function(work) {
|
||||||
|
return work._id !== id;
|
||||||
|
}));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var classDisp = Session.get("classDisp");
|
||||||
|
var sideFilter = Session.get("typeFilter"); // Get sidebar type filter.
|
||||||
|
var hideTime = Session.get("user").preferences.timeHide;
|
||||||
|
var workObj;
|
||||||
|
|
||||||
|
if(type === "added") {
|
||||||
|
workObj = Object.assign({}, fields, {_id: id})
|
||||||
|
} else if(type === "changed") {
|
||||||
|
workObj = Object.assign(Session.get("myWork").filter(function(work) {
|
||||||
|
return work._id === id;
|
||||||
|
}), fields);
|
||||||
|
}
|
||||||
|
|
||||||
|
workObj.classid = workObj.class;
|
||||||
|
workObj.realDate = workObj.dueDate;
|
||||||
|
workObj.dueDate = moment(workObj.dueDate).calendar(null, {
|
||||||
|
sameDay: '[Today]',
|
||||||
|
nextDay: '[Tomorrow]',
|
||||||
|
nextWeek: 'dddd',
|
||||||
|
lastDay: '[Yesterday]',
|
||||||
|
lastWeek: '[Last] dddd',
|
||||||
|
sameElse: 'MMMM Do'
|
||||||
|
});
|
||||||
|
|
||||||
|
if (workObj.dueDate === "Today") { // Font weight based on date proximity.
|
||||||
|
workObj.cardDate = "600";
|
||||||
|
} else if (workObj.dueDate === "Tomorrow") {
|
||||||
|
workObj.cardDate = "400";
|
||||||
|
}
|
||||||
|
|
||||||
|
workObj.typeColor = workColors[workObj.type];
|
||||||
|
workObj.confirmationLength = workObj.confirmations.length; // Counts the number of confirmations and reports for a particular work.
|
||||||
|
workObj.reportLength = workObj.reports.length;
|
||||||
|
|
||||||
|
workObj.creatorname = Meteor.users.findOne({
|
||||||
|
_id: workObj.creator
|
||||||
|
}).profile.name;
|
||||||
|
|
||||||
|
workObj.hide = false;
|
||||||
|
|
||||||
|
//Filters
|
||||||
|
var notInClassFilter = classDisp.length !== 0 && !_.contains(classDisp, workObj.classid);
|
||||||
|
var pastHideDate = hideTime !== 0 && (moment().subtract(hideTime, 'days'))._d > (moment(workObj.realDate))._d;
|
||||||
|
var markedDone = Session.get("user").preferences.done && !Meteor.Device.isPhone() && _.contains(workObj.done, Meteor.userId());
|
||||||
|
var reported = (workObj.reportLength / (workObj.reportLength + workObj.confirmationLength)) > 0.7; // Over 70% are reports
|
||||||
|
|
||||||
|
if(notInClassFilter || pastHideDate || markedDone) workObj.hide = true;
|
||||||
|
|
||||||
|
var normalColor = Session.get("user").preferences.theme.text;
|
||||||
|
// Ratio color handling
|
||||||
|
/*var conf = workObj.confirmations.length;
|
||||||
|
var repo = workObj.reports.length;
|
||||||
|
var ratio = conf / repo;
|
||||||
|
|
||||||
|
if (Math.abs(conf - repo)) {
|
||||||
|
if ((conf + repo) <= 1) {
|
||||||
|
thisWork[j].doneRatio = normalColor;
|
||||||
|
} else {
|
||||||
|
thisWork[j].doneRatio = "#F9F906";
|
||||||
|
}
|
||||||
|
} else if (ratio >= 2) {
|
||||||
|
thisWork[j].doneRatio = "#33DD33";
|
||||||
|
} else if (ratio <= 0.9) {
|
||||||
|
thisWork[j].doneRatio = "#FF1A1A";
|
||||||
|
}*/
|
||||||
|
|
||||||
|
workObj.doneRatio = normalColor;
|
||||||
|
|
||||||
|
var myWork;
|
||||||
|
if(type === "added") {
|
||||||
|
myWork = Session.get("myWork");
|
||||||
|
} else if(type === "changed") {
|
||||||
|
myWork = Session.get("myWork").filter(function(work) {
|
||||||
|
return work._id !== id;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
myWork.push(workObj);
|
||||||
|
Session.set("myWork", myWork.sort(function(a,b) {
|
||||||
|
return Date.parse(a.realDate) - Date.parse(b.realDate);
|
||||||
|
}));
|
||||||
|
|
||||||
|
calendarEvents();
|
||||||
|
$("#fullcalendar").fullCalendar("removeEvents");
|
||||||
|
$("#fullcalendar").fullCalendar("addEventSource", Session.get("calendarEvents"));
|
||||||
|
}
|
||||||
|
|
||||||
Template.registerHelper('pref', (val) => { // Obtains all user preferences.
|
Template.registerHelper('pref', (val) => { // Obtains all user preferences.
|
||||||
try {
|
try {
|
||||||
if(val === "school") return Session.get("user").school;
|
if(val === "school") return Session.get("user").school;
|
||||||
@ -215,7 +380,9 @@ Template.main.helpers({
|
|||||||
return " - " + Session.get("user").school;
|
return " - " + Session.get("user").school;
|
||||||
},
|
},
|
||||||
avatar() { // Returns avatar.
|
avatar() { // Returns avatar.
|
||||||
return Meteor.user().services.google.picture;
|
try {
|
||||||
|
return Meteor.user().services.google.picture;
|
||||||
|
} catch(err) {}
|
||||||
},
|
},
|
||||||
username() { // Returns user name.
|
username() { // Returns user name.
|
||||||
return Session.get("user").name;
|
return Session.get("user").name;
|
||||||
@ -681,11 +848,11 @@ Template.main.events({
|
|||||||
},
|
},
|
||||||
'click .cWorkBottom .fa-thumbs-up' (event) {
|
'click .cWorkBottom .fa-thumbs-up' (event) {
|
||||||
serverData = [event.target.parentNode.parentNode.parentNode.parentNode.getAttribute("workid"), "confirmations"]
|
serverData = [event.target.parentNode.parentNode.parentNode.parentNode.getAttribute("workid"), "confirmations"]
|
||||||
sendData("toggleWork")
|
sendData("toggleWork");
|
||||||
},
|
},
|
||||||
'click .cWorkBottom .fa-exclamation-triangle' (event) {
|
'click .cWorkBottom .fa-exclamation-triangle' (event) {
|
||||||
serverData = [event.target.parentNode.parentNode.parentNode.parentNode.getAttribute("workid"), "reports"]
|
serverData = [event.target.parentNode.parentNode.parentNode.parentNode.getAttribute("workid"), "reports"]
|
||||||
sendData("toggleWork")
|
sendData("toggleWork");
|
||||||
},
|
},
|
||||||
'click #signout' () {
|
'click #signout' () {
|
||||||
$(".noScroll").velocity("fadeOut", 50);
|
$(".noScroll").velocity("fadeOut", 50);
|
||||||
@ -694,6 +861,15 @@ Template.main.events({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Template.classesMode.helpers({
|
||||||
|
thisClassWork() {
|
||||||
|
var id = this._id;
|
||||||
|
return Session.get("myWork").filter(function(work) {
|
||||||
|
return work.classid === id;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Other Functions
|
// Other Functions
|
||||||
|
|
||||||
toggleOptionMenu = function(toggle, menu) {
|
toggleOptionMenu = function(toggle, menu) {
|
||||||
@ -992,7 +1168,7 @@ myClasses = function() {
|
|||||||
});
|
});
|
||||||
if(found === undefined) return;
|
if(found === undefined) return;
|
||||||
found.subscribers = found.subscribers.length;
|
found.subscribers = found.subscribers.length;
|
||||||
if(found.teacher !== undefined) found.teachershort = found.teacher.split(" ").slice(1).reduce(function(a,b) { return a+ " " + b;});
|
found.teachershort = (found.teacher === undefined) ? "" : found.teacher.split(" ").slice(1).reduce(function(a,b) { return a+ " " + b;});
|
||||||
found.mine = true;
|
found.mine = true;
|
||||||
if (found.admin === Meteor.userId()) { // If user owns this class.
|
if (found.admin === Meteor.userId()) { // If user owns this class.
|
||||||
found.box = " owned";
|
found.box = " owned";
|
||||||
@ -1090,35 +1266,30 @@ myClasses = function() {
|
|||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
function calendarEvents(array) {
|
function calendarEvents() {
|
||||||
var events = [];
|
var events = [];
|
||||||
var userClasses = array;
|
var myWork = Session.get("myWork");
|
||||||
if(userClasses === undefined) return;
|
for(var i = 0; i < myWork.length; i++) {
|
||||||
for (var i = 0; i < userClasses.length; i++) {
|
var work = myWork[i];
|
||||||
var works = userClasses[i].thisClassWork;
|
var currClass = classes.findOne({ _id: work.classid});
|
||||||
for (var j = 0; j < works.length; j++) {
|
var inRole = false;
|
||||||
var work = works[j];
|
|
||||||
var currClass = classes.findOne({
|
|
||||||
_id: work.class
|
|
||||||
});
|
|
||||||
var inRole = false;
|
|
||||||
|
|
||||||
if (work.class === Meteor.userId() ||
|
if (work.class === Meteor.userId() ||
|
||||||
Meteor.userId() === work.creator ||
|
Meteor.userId() === work.creator ||
|
||||||
Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin']) ||
|
Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin']) ||
|
||||||
currClass.moderators.indexOf(Meteor.userId()) !== -1 ||
|
currClass.moderators.indexOf(Meteor.userId()) !== -1 ||
|
||||||
currClass.banned.indexOf(Meteor.userId()) !== -1
|
currClass.banned.indexOf(Meteor.userId()) !== -1
|
||||||
) inRole = true;
|
) inRole = true;
|
||||||
events.push({
|
|
||||||
id: work._id,
|
events.push({
|
||||||
start: work.realDate.toISOString().slice(0, 10),
|
id: work._id,
|
||||||
title: work.name,
|
start: work.realDate.toISOString().slice(0, 10),
|
||||||
backgroundColor: workColors[work.type],
|
title: work.name,
|
||||||
borderColor: "#444",
|
backgroundColor: workColors[work.type],
|
||||||
startEditable: inRole,
|
borderColor: "#444",
|
||||||
className: work.type + " workevent " + work.class
|
startEditable: inRole,
|
||||||
});
|
className: work.type + " workevent " + work.class
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
Session.set("calendarEvents", events);
|
Session.set("calendarEvents", events);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -373,7 +373,7 @@ Template.joinClass.helpers({
|
|||||||
for (var i = 0; i < array.length; i++) {
|
for (var i = 0; i < array.length; i++) {
|
||||||
array[i].join = true;
|
array[i].join = true;
|
||||||
array[i].subscribers = array[i].subscribers.length;
|
array[i].subscribers = array[i].subscribers.length;
|
||||||
array[i].teachershort = array[i].teacher.split(" ").slice(1).reduce(function(a, b) {
|
if(array[i].teacher !== undefined) array[i].teachershort = array[i].teacher.split(" ").slice(1).reduce(function(a, b) {
|
||||||
return a + " " + b;
|
return a + " " + b;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -486,10 +486,11 @@ Template.joinClass.events({
|
|||||||
Meteor.call("joinPrivateClass", input.value, function(error, result) {
|
Meteor.call("joinPrivateClass", input.value, function(error, result) {
|
||||||
if (result) {
|
if (result) {
|
||||||
sAlert.success("Joined!", {
|
sAlert.success("Joined!", {
|
||||||
effect: 'genie',
|
effect: 'stackslide',
|
||||||
position: 'bottom-right',
|
position: 'bottom-right',
|
||||||
timeout: 1500
|
timeout: 1500
|
||||||
});
|
});
|
||||||
|
$("#privateCode").velocity("fadeOut",100);
|
||||||
} else {
|
} else {
|
||||||
sAlert.error("Invalid code!", {
|
sAlert.error("Invalid code!", {
|
||||||
effect: 'stackslide',
|
effect: 'stackslide',
|
||||||
@ -497,7 +498,9 @@ Template.joinClass.events({
|
|||||||
timeout: 1500
|
timeout: 1500
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -754,11 +754,9 @@ Meteor.methods({
|
|||||||
var current = Meteor.user().profile;
|
var current = Meteor.user().profile;
|
||||||
var index = current.classes.indexOf(change);
|
var index = current.classes.indexOf(change);
|
||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
console.log("hi");
|
|
||||||
if (classes.findOne({
|
if (classes.findOne({
|
||||||
_id: change
|
_id: change
|
||||||
}).admin != Meteor.userId()) {
|
}).admin != Meteor.userId()) {
|
||||||
console.log("f");
|
|
||||||
current.classes.splice(index, 1);
|
current.classes.splice(index, 1);
|
||||||
Meteor.users.update({
|
Meteor.users.update({
|
||||||
_id: Meteor.userId()
|
_id: Meteor.userId()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user