fixed bad preference storage

This commit is contained in:
Yaman Qalieh 2016-08-28 20:09:16 -04:00
parent d387699f67
commit 02ea688420
2 changed files with 15 additions and 14 deletions

View File

@ -32,3 +32,4 @@ momentjs:moment
eternicode:bootstrap-datepicker eternicode:bootstrap-datepicker
shell-server@0.2.1 shell-server@0.2.1
http@1.2.9 http@1.2.9
underscore

View File

@ -50,8 +50,8 @@ var workColors = {
var defaults = { var defaults = {
"theme":"light", "theme":"light",
"mode":"classes", "mode":"classes",
"timeHide":"1 Day", "timeHide":1,
"done":true "done": true
}; };
var ref = { var ref = {
@ -59,13 +59,10 @@ var ref = {
"2 Days":2, "2 Days":2,
"1 Week":7, "1 Week":7,
"1 Month":30, "1 Month":30,
"Never":0 "Never":0,
};
var dref = {
"Yes":true, "Yes":true,
"No":false "No":false
} };
// Reactive variables. // Reactive variables.
Session.set("calendarclasses", null); Session.set("calendarclasses", null);
@ -108,7 +105,7 @@ Template.registerHelper('myClasses', () => {
var array = []; var array = [];
var courses = Meteor.user().profile.classes; var courses = Meteor.user().profile.classes;
var classDisp = Session.get("classDisp"); var classDisp = Session.get("classDisp");
var hide = ref[Meteor.user().profile.preferences.timeHide]; var hide = Meteor.user().profile.preferences.timeHide;
for(var i = 0; i < courses.length; i++) { for(var i = 0; i < courses.length; i++) {
found = classes.findOne({_id:courses[i]}); found = classes.findOne({_id:courses[i]});
found.subscribers = found.subscribers.length; found.subscribers = found.subscribers.length;
@ -136,7 +133,7 @@ Template.registerHelper('myClasses', () => {
j = 0; j = 0;
} }
} }
if(thisWork[j] !== "no" && dref[Meteor.user().profile.preferences.done]) { if(thisWork[j] !== "no" && Meteor.user().profile.preferences.done) {
if(thisWork[j].done.indexOf(Meteor.userId()) !== -1) { if(thisWork[j].done.indexOf(Meteor.userId()) !== -1) {
thisWork[j] = "no"; thisWork[j] = "no";
j = 0; j = 0;
@ -187,7 +184,10 @@ Template.registerHelper('pref', (val) => {
return defaults[val].charAt(0).toUpperCase() + defaults[val].slice(1); return defaults[val].charAt(0).toUpperCase() + defaults[val].slice(1);
} else { } else {
var preferences = Meteor.user().profile.preferences; var preferences = Meteor.user().profile.preferences;
if(val === 'timeHide' || val === 'done') return preferences[val]; if(val === 'timeHide' || val === 'done') {
var invert = _.invert(ref);
return invert[preferences[val]];
}
return preferences[val].charAt(0).toUpperCase() + preferences[val].slice(1); return preferences[val].charAt(0).toUpperCase() + preferences[val].slice(1);
} }
}); });
@ -264,7 +264,7 @@ Template.main.helpers({
var events = []; var events = [];
var cursor = work.find({class: {$in: Session.get("calendarclasses")}}); var cursor = work.find({class: {$in: Session.get("calendarclasses")}});
var classDisp = Session.get("classDisp"); var classDisp = Session.get("classDisp");
var hide = ref[Meteor.user().profile.preferences.timeHide]; var hide = Meteor.user().profile.preferences.timeHide;
cursor.forEach(function(current) { cursor.forEach(function(current) {
var disp = true; var disp = true;
if(classDisp.length !== 0 && classDisp.indexOf(current.class) === -1) disp = false; if(classDisp.length !== 0 && classDisp.indexOf(current.class) === -1) disp = false;
@ -504,7 +504,7 @@ Template.main.events({
} }
Session.set("newWork",null); Session.set("newWork",null);
Session.set("commentRestrict",null); Session.set("commentRestrict",null);
} }
if (!event.target.className.includes("radio") && if (!event.target.className.includes("radio") &&
@ -912,8 +912,8 @@ function getPreferencesData() {
var options = { var options = {
"theme":document.getElementById("prefTheme").childNodes[0].nodeValue.toLowerCase(), "theme":document.getElementById("prefTheme").childNodes[0].nodeValue.toLowerCase(),
"mode":document.getElementById("prefMode").childNodes[0].nodeValue.toLowerCase(), "mode":document.getElementById("prefMode").childNodes[0].nodeValue.toLowerCase(),
"timeHide":document.getElementById("prefHide").childNodes[0].nodeValue, "timeHide":ref[document.getElementById("prefHide").childNodes[0].nodeValue],
"done":document.getElementById("prefDone").childNodes[0].nodeValue "done":ref[document.getElementById("prefDone").childNodes[0].nodeValue]
}; };
profile.preferences = options; profile.preferences = options;
return profile; return profile;