From 655d5821e930a8c47ccaf3d71c02d60b9e3215f4 Mon Sep 17 00:00:00 2001 From: Yaman Qalieh Date: Sun, 14 Aug 2016 07:52:27 -0400 Subject: [PATCH] remove class if non-existant --- hourglass/client/main/main.js | 40 +++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/hourglass/client/main/main.js b/hourglass/client/main/main.js index db4c567..db1ce89 100644 --- a/hourglass/client/main/main.js +++ b/hourglass/client/main/main.js @@ -59,25 +59,37 @@ Template.registerHelper('overlayDim', (part) => { }); Template.registerHelper('myClasses', () => { - if (Meteor.user().profile.classes === undefined || Meteor.user().profile.classes.length === 0) { + var invalid = []; + if (Meteor.user().profile.classes === undefined || Meteor.user().profile.classes.length === 0) { return []; - } else { + } else { var array = []; var courses = Meteor.user().profile.classes; - for(var i = 0; i < courses.length; i++) { - array.push(classes.findOne({_id:courses[i]})); - var thisWork = work.find({class:array[i]["_id"]}).fetch(); + found = classes.findOne({_id:courses[i]}); + if (found) { + array.push(found); + var thisWork = work.find({class: array.slice(-1)[0]}).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 = getReadableDate(thisWork[j].dueDate); + thisWork[j].typeColor = workColors[thisWork[j].type]; + } + array[i].thisClassWork = thisWork; + } else { + invalid.push(i); + } } + for(var i = 0; i < invalid.length; i++) { + array.splice(invalid[i], 1); + courses.splice(invalid[i], 1); + } + userprofile = Meteor.user().profile; + userprofile.classes = courses; + Meteor.call("editProfile", userprofile); return array; - } -}) + } +}); Template.main.helpers({ schoolName() { @@ -320,7 +332,7 @@ Template.main.events({ } input.value = ele.childNodes[0].nodeValue; input.className = "changeInput"; - + input.style.width = "70%"; input.style.padding = "0.1%"; input.id = ele.id + "a"; @@ -518,4 +530,4 @@ function formReadable(input) { input.dueDate = input.dueDate.getFullYear()+"-"+input.dueDate.getMonth()+"-"+input.dueDate.getDate(); input.type = input.type[0].toUpperCase() + input.type.slice(1); return input; -} \ No newline at end of file +}