Commit 0d870ed2 authored by Curtis Adam's avatar Curtis Adam

Fix Frontend console errors

parent 785c47e5
......@@ -54,6 +54,7 @@
"browser": true,
"client": true,
"module": true,
"expect": true
"expect": true,
"Hammer": true
}
}
......@@ -6,8 +6,12 @@ export const AdminSettings = new Mongo.Collection("adminSettings");
if (Meteor.isServer) {
Meteor.publish('default_db_data', function () {
if (this.userId && !Roles.userIsInRole(this.userId, ["firstLogin", "blocked"]) && Roles.userIsInRole(this.userId, ["admin", "editor"])) {
return AdminSettings.find({});
if (this.userId && !Roles.userIsInRole(this.userId, ["firstLogin", "blocked"])) {
if (Roles.userIsInRole(this.userId, ["admin", "editor"])) {
return AdminSettings.find({});
} else {
return AdminSettings.find({name: "seqSettings"});
}
}
});
}
......
......@@ -338,11 +338,10 @@ Meteor.methods({
Roles.removeUsersFromRoles(Meteor.user()._id, 'firstLogin');
},
updateEarnedBadges: function (userId, index, rank) {
check(userId, String);
updateEarnedBadges: function (index, rank) {
check(index, Number);
check(rank, Number);
Meteor.users.update(userId,
Meteor.users.update(this.userId,
{$addToSet: {"earnedBadges": {"index": index.toString(), "rank": rank.toString()}}});
},
/** Function saves the given colorTheme to the given user
......
......@@ -75,18 +75,24 @@ Template.registerHelper("isCardsetEditor", function (user_id) {
});
Template.registerHelper("learningActiveAndNotEditor", function () {
let cardset = Cardsets.findOne({"_id": Router.current().params._id});
return (cardset.owner !== Meteor.userId() && !cardset.editors.includes(Meteor.userId())) && cardset.learningActive;
if (Router.current().params._id) {
let cardset = Cardsets.findOne({"_id": Router.current().params._id});
return (cardset.owner !== Meteor.userId() && !cardset.editors.includes(Meteor.userId())) && cardset.learningActive;
}
});
Template.registerHelper("learningActiveAndEditor", function () {
let cardset = Cardsets.findOne({"_id": Router.current().params._id});
return (cardset.owner === Meteor.userId() || cardset.editors.includes(Meteor.userId())) && cardset.learningActive;
if (Router.current().params._id) {
let cardset = Cardsets.findOne({"_id": Router.current().params._id});
return (cardset.owner === Meteor.userId() || cardset.editors.includes(Meteor.userId())) && cardset.learningActive;
}
});
Template.registerHelper("isEditor", function () {
let cardset = Cardsets.findOne({"_id": Router.current().params._id});
return (cardset.owner === Meteor.userId() || cardset.editors.includes(Meteor.userId()));
if (Router.current().params._id) {
let cardset = Cardsets.findOne({"_id": Router.current().params._id});
return (cardset.owner === Meteor.userId() || cardset.editors.includes(Meteor.userId()));
}
});
Template.registerHelper("isLecturerOrPro", function () {
......@@ -330,7 +336,7 @@ const helper = new MeteorMathJax.Helper({
});
Template.registerHelper('mathjax', helper.getTemplate());
MeteorMathJax.sourceUrl = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js';
MeteorMathJax.sourceUrl = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js';
MeteorMathJax.defaultConfig = {
config: ["TeX-AMS-MML_HTMLorMML.js"],
jax: ["input/TeX", "input/MathML", "output/HTML-CSS", "output/NativeMML", "output/PreviewHTML"],
......
......@@ -7,6 +7,7 @@ import {Cardsets} from "../../api/cardsets.js";
import {Cards} from "../../api/cards.js";
import {Learned} from "../../api/learned.js";
import "./card.html";
import '/client/hammer.js';
/*
* ############################################################################
......@@ -492,6 +493,20 @@ Template.flashcards.onCreated(function () {
Session.set('activeCardset', Cardsets.findOne({"_id": Router.current().params._id}));
});
Template.flashcards.onRendered(function () {
if (Router.current().route.getName() === "cardsetdetailsid") {
var mc = new Hammer.Manager(document.getElementById('set-details-region'));
mc.add(new Hammer.Swipe({direction: Hammer.DIRECTION_HORIZONTAL, threshold: 50}));
mc.on("swipe", function (ev) {
if (ev.deltaX < 0) {
document.getElementById('rightCarouselControl').click();
} else {
document.getElementById('leftCarouselControl').click();
}
});
}
});
Template.flashcards.helpers({
cardActive: function (index) {
if (Session.get('modifiedCard')) {
......
//------------------------ IMPORTS
/*global Hammer*/
import {Meteor} from "meteor/meteor";
import {Template} from "meteor/templating";
import {Session} from "meteor/session";
......@@ -15,8 +13,6 @@ import "../card/card.js";
import "../learn/box.js";
import "../learn/memo.js";
import "./cardset.html";
import '/client/hammer.js';
Meteor.subscribe("cardsets");
Meteor.subscribe("userData");
......@@ -448,16 +444,6 @@ Template.cardsetInfo.onRendered(function () {
$('[data-toggle="tooltip"]').tooltip({
container: 'body'
});
var mc = new Hammer.Manager(document.getElementById('set-details-region'));
mc.add(new Hammer.Swipe({direction: Hammer.DIRECTION_HORIZONTAL, threshold: 50}));
mc.on("swipe", function (ev) {
if (ev.deltaX < 0) {
document.getElementById('rightCarouselControl').click();
} else {
document.getElementById('leftCarouselControl').click();
}
});
});
Template.cardsetInfo.helpers({
......
......@@ -588,11 +588,11 @@ Template.profileSettings.events({
Template.profileMembership.rendered = function () {
var customerId = Meteor.user().customerId;
if ($('#subscribe-form').length) {
Meteor.call('getClientToken', customerId, function (error, clientToken) {
if (error) {
throw new Meteor.Error(error.statusCode, 'Error getting client token from braintree');
} else {
Meteor.call('getClientToken', customerId, function (error, clientToken) {
if (error) {
throw new Meteor.Error(error.statusCode, 'Error getting client token from braintree');
} else {
if ($('#subscribe-form').length) {
braintree.setup(clientToken, "dropin", {
container: "subscribe-form",
defaultFirst: true,
......@@ -612,8 +612,8 @@ Template.profileMembership.rendered = function () {
}
});
}
});
}
}
});
};
Template.profileMembership.events({
......@@ -670,14 +670,18 @@ Template.profileMembership.helpers({
* ############################################################################
*/
Template.profileBilling.onCreated(function () {
Session.set("switchedSitesCheck", undefined);
});
Template.profileBilling.onRendered(function () {
var customerId = Meteor.user().customerId;
if ($('#paymentMethodDropIn').length) {
Meteor.call('getClientToken', customerId, function (error, clientToken) {
if (error) {
throw new Meteor.Error(error.statusCode, 'Error getting client token from braintree');
} else {
Meteor.call('getClientToken', customerId, function (error, clientToken) {
if (error) {
throw new Meteor.Error(error.statusCode, 'Error getting client token from braintree');
} else {
if ($('#paymentMethodDropIn').length) {
braintree.setup(clientToken, "dropin", {
container: "paymentMethodDropIn",
defaultFirst: true,
......@@ -697,14 +701,15 @@ Template.profileBilling.onRendered(function () {
}
});
}
});
}
}
});
if ($('#payoutDropIn').length) {
Meteor.call('getClientToken', customerId, function (error, clientToken) {
if (error) {
throw new Meteor.Error(error.statusCode, 'Error getting client token from braintree');
} else {
Meteor.call('getClientToken', customerId, function (error, clientToken) {
if (error) {
throw new Meteor.Error(error.statusCode, 'Error getting client token from braintree');
} else {
if ($('#payoutDropIn').length) {
braintree.setup(clientToken, "dropin", {
container: "payoutDropIn",
onPaymentMethodReceived: function (response) {
......@@ -727,8 +732,8 @@ Template.profileBilling.onRendered(function () {
}
});
}
});
}
}
});
});
Template.profileBilling.helpers({
......@@ -1103,13 +1108,13 @@ Template.profileBadges.helpers({
index++; //index in DB starts at 1
var earnedBadges = Meteor.user().earnedBadges;
if (gained) {
if (earnedBadges && gained) {
for (var i = 0; i < earnedBadges.length; i++) {
if (index === earnedBadges[i].index && rank === earnedBadges[i].rank) {
return gained;
}
}
Meteor.call("updateEarnedBadges", Meteor.userId(), index, rank);
Meteor.call("updateEarnedBadges", index, rank);
Bert.alert(TAPi18n.__('newbadge') + ': ' + Badges.findOne(index.toString()).name + ' (' + TAPi18n.__('rank') + ' ' + rank + ')', 'info', 'growl-bottom-right');
}
return gained;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment