Commit adfdf94a authored by Christopher Fullarton's avatar Christopher Fullarton

Fix a bunch of gulp errors

parent 8990aa1d
......@@ -30,6 +30,10 @@
"showSplashscreen": true,
"closeAndRedirectTo": true,
"Braintree": true,
"BrainTreeConnect": true
"BrainTreeConnect": true,
"Npm": true,
"EasySearch": true,
"CardsetsIndex": true,
"kramed": true
}
}
import {Meteor } from 'meteor/meteor';
import {Mongo } from 'meteor/mongo';
import {Cardsets } from './cardsets.js';
if (Meteor.isServer) {
......@@ -57,10 +55,12 @@ Meteor.methods({
var roles;
if (newRole === 'pro' && !Roles.userIsInRole(user_id, 'pro')) {
Roles.removeUsersFromRoles(user_id, 'standard'), roles = Roles.getRolesForUser(user_id);
Roles.removeUsersFromRoles(user_id, 'standard');
roles = Roles.getRolesForUser(user_id);
roles.push('pro');
} else if (newRole === 'standard' && !Roles.userIsInRole(user_id, 'standard')) {
Roles.removeUsersFromRoles(user_id, 'pro'), roles = Roles.getRolesForUser(user_id);
Roles.removeUsersFromRoles(user_id, 'pro');
roles = Roles.getRolesForUser(user_id);
roles.push('standard');
} else if (!Roles.userIsInRole(user_id, newRole)) {
roles = Roles.getRolesForUser(user_id);
......
import {Meteor } from 'meteor/meteor';
import {Mongo } from 'meteor/mongo';
export const Badges = new TAPi18n.Collection("badges");
if (Meteor.isServer) {
Meteor.publish("badges", function () {
return Badges.find();
});
}
import {Meteor } from 'meteor/meteor';
export const Badges = new TAPi18n.Collection("badges");
if (Meteor.isServer) {
Meteor.publish("badges", function () {
return Badges.find();
});
}
......@@ -181,7 +181,7 @@ Meteor.methods({
billingDate: response.subscription.nextBillingDate
},
visible: true
}
};
// Perform an update on this user.
Meteor.users.update(Meteor.user(), {
$set: customerSubscription
......@@ -321,7 +321,7 @@ Meteor.methods({
btCancelSubscription.return(error);
} else {
// cancel the active subscription
gateway.subscription.cancel(customerSubscription.id, function (error, result) {
gateway.subscription.cancel(customerSubscription.id, function (error) {
if (error) {
btCancelSubscription.return(error);
} else {
......
This diff is collapsed.
import {Meteor } from 'meteor/meteor';
import {Mongo } from 'meteor/mongo';
import {Meteor} from 'meteor/meteor';
import {Mongo} from 'meteor/mongo';
import {Cards } from './cards.js';
import {Experience } from './experience.js';
import {Ratings } from './ratings.js';
import {SimpleSchema} from 'meteor/aldeed:simple-schema';
import {Cards} from './cards.js';
import {Experience} from './experience.js';
import {Ratings} from './ratings.js';
export const Cardsets = new Mongo.Collection("cardsets");
if (Meteor.isServer) {
Meteor.publish("cardsets", function () {
if (Roles.userIsInRole(this.userId, ['admin', 'editor'])) {
if (Roles.userIsInRole(this.userId, [
'admin',
'editor'
])) {
return Cardsets.find();
}
else if (Roles.userIsInRole(this.userId, 'lecturer')) {
return Cardsets.find({$or: [{visible: true}, {request: true}, {owner: this.userId}]});
}
else if (this.userId && !Roles.userIsInRole(this.userId, 'blocked'))
{
return Cardsets.find({$or: [{visible: true}, {owner: this.userId}]});
} else if (Roles.userIsInRole(this.userId, 'lecturer')) {
return Cardsets.find({
$or: [
{visible: true},
{request: true},
{owner: this.userId}
]
});
} else if (this.userId && !Roles.userIsInRole(this.userId, 'blocked')) {
return Cardsets.find({
$or: [
{visible: true},
{owner: this.userId}
]
});
}
});
}
CardsetsSchema = new SimpleSchema({
const CardsetsSchema = new SimpleSchema({
name: {
type: String
},
......@@ -88,21 +101,30 @@ Cardsets.attachSchema(CardsetsSchema);
CardsetsIndex = new EasySearch.Index({
collection: Cardsets,
fields: ['name', 'description'],
fields: [
'name',
'description'
],
engine: new EasySearch.Minimongo({
selector: function (searchObject, options, aggregation) {
// Default selector
defSelector = this.defaultConfiguration().selector(searchObject, options, aggregation);
const defSelector = this.defaultConfiguration().selector(searchObject, options, aggregation);
// Filter selector
selector = {};
selector.$and = [defSelector, {
$or: [{
owner: Meteor.userId()
}, {
visible: true
}]
}];
const selector = {};
selector.$and = [
defSelector,
{
$or: [
{
owner: Meteor.userId()
},
{
visible: true
}
]
}
];
return selector;
}
})
......@@ -146,7 +168,10 @@ Meteor.methods({
// Make sure only the task owner can make a task private
var cardset = Cardsets.findOne(id);
if (!Roles.userIsInRole(this.userId, ['admin', 'editor'])) {
if (!Roles.userIsInRole(this.userId, [
'admin',
'editor'
])) {
if (!Meteor.userId() || cardset.owner !== Meteor.userId() || Roles.userIsInRole(this.userId, 'blocked')) {
throw new Meteor.Error("not-authorized");
}
......@@ -161,7 +186,10 @@ Meteor.methods({
// Make sure only the task owner can make a task private
var cardset = Cardsets.findOne(id);
if (!Roles.userIsInRole(this.userId, ['admin', 'editor'])) {
if (!Roles.userIsInRole(this.userId, [
'admin',
'editor'
])) {
if (!Meteor.userId() || cardset.owner !== Meteor.userId() || Roles.userIsInRole(this.userId, 'blocked')) {
throw new Meteor.Error("not-authorized");
}
......@@ -211,20 +239,23 @@ Meteor.methods({
// Make sure only the task owner can make a task private
var cardset = Cardsets.findOne(id);
if (!Roles.userIsInRole(this.userId, ['admin', 'editor'])) {
if (!Roles.userIsInRole(this.userId, [
'admin',
'editor'
])) {
if (!Meteor.userId() || cardset.owner !== Meteor.userId() || Roles.userIsInRole(this.userId, 'blocked')) {
throw new Meteor.Error("not-authorized");
}
}
Meteor.call("updateRelevance", id, function (error, relevance){
if(!error){
Meteor.call("updateRelevance", id, function (error, relevance) {
if (!error) {
Cardsets.update(id, {
$set: {
kind: kind,
price: price,
visible: visible,
relevance: relevance
kind: kind,
price: price,
visible: visible,
relevance: relevance
}
});
}
......@@ -265,8 +296,8 @@ Meteor.methods({
},
declineProRequest: function (cardset_id) {
var cardset = Cardsets.findOne(cardset_id);
if ((!Roles.userIsInRole(this.userId, 'lecturer'))&&(!Meteor.userId() || cardset.owner !== Meteor.userId() || Roles.userIsInRole(this.userId, 'blocked'))) {
throw new Meteor.Error("not-authorized");
if ((!Roles.userIsInRole(this.userId, 'lecturer')) && (!Meteor.userId() || cardset.owner !== Meteor.userId() || Roles.userIsInRole(this.userId, 'blocked'))) {
throw new Meteor.Error("not-authorized");
}
Cardsets.update(cardset_id, {
......@@ -281,7 +312,10 @@ Meteor.methods({
updateLicense: function (id, license) {
var cardset = Cardsets.findOne(id);
if (!Roles.userIsInRole(this.userId, ['admin', 'editor'])) {
if (!Roles.userIsInRole(this.userId, [
'admin',
'editor'
])) {
if (!Meteor.userId() || cardset.owner !== Meteor.userId() || Roles.userIsInRole(this.userId, 'blocked')) {
throw new Meteor.Error("not-authorized");
}
......
import {Meteor } from 'meteor/meteor';
import {Mongo } from 'meteor/mongo';
export const Categories = new TAPi18n.Collection("categories");
if (Meteor.isServer) {
Meteor.publish("categories", function () {
return Categories.find();
});
}
import {Meteor} from 'meteor/meteor';
export const Categories = new TAPi18n.Collection("categories");
if (Meteor.isServer) {
Meteor.publish("categories", function () {
return Categories.find();
});
}
import {Meteor } from 'meteor/meteor';
import {Mongo } from 'meteor/mongo';
export const Experience = new Mongo.Collection("experience");
if (Meteor.isServer) {
Meteor.publish("experience", function () {
if (this.userId && !Roles.userIsInRole(this.userId, 'blocked')) {
return Experience.find({
$or: [
{owner: this.userId},
{owner: {$in: Meteor.users.find({visible: true}).map(function (user) {return user._id})}}
]
});
}
});
}
Meteor.methods({
checkLvl: function () {
var pts = 0;
var points = 0;
var output = 0;
var lvl = 1;
var allXp = Experience.find({
owner: Meteor.userId()
});
allXp.forEach(function (xp) {
pts = pts + xp.value;
});
while (pts > output) {
points += Math.floor(lvl + 30 * Math.pow(2, lvl / 10));
output = Math.floor(points / 4);
if (pts >= output) {
lvl++;
}
}
Meteor.users.update(Meteor.userId(), {
$set: {
lvl: lvl
}
});
},
addExperience: function (type, value) {
Experience.insert({
type: type,
value: value,
date: new Date(),
owner: Meteor.userId()
});
Meteor.call('checkLvl');
}
});
import {Meteor} from 'meteor/meteor';
import {Mongo} from 'meteor/mongo';
export const Experience = new Mongo.Collection("experience");
if (Meteor.isServer) {
Meteor.publish("experience", function () {
if (this.userId && !Roles.userIsInRole(this.userId, 'blocked')) {
return Experience.find({
$or: [
{owner: this.userId},
{
owner: {
$in: Meteor.users.find({visible: true}).map(function (user) {
return user._id;
})
}
}
]
});
}
});
}
Meteor.methods({
checkLvl: function () {
var pts = 0;
var points = 0;
var output = 0;
var lvl = 1;
var allXp = Experience.find({
owner: Meteor.userId()
});
allXp.forEach(function (xp) {
pts = pts + xp.value;
});
while (pts > output) {
points += Math.floor(lvl + 30 * Math.pow(2, lvl / 10));
output = Math.floor(points / 4);
if (pts >= output) {
lvl++;
}
}
Meteor.users.update(Meteor.userId(), {
$set: {
lvl: lvl
}
});
},
addExperience: function (type, value) {
Experience.insert({
type: type,
value: value,
date: new Date(),
owner: Meteor.userId()
});
Meteor.call('checkLvl');
}
});
import {Meteor } from 'meteor/meteor';
import {Mongo } from 'meteor/mongo';
import {Cardsets } from './cardsets.js';
export const Learned = new Mongo.Collection("learned");
if (Meteor.isServer) {
Meteor.publish("learned", function () {
if (this.userId && !Roles.userIsInRole(this.userId, 'blocked')) {
var cardsetsIds = Cardsets.find({
owner: this.userId
}).map(function (cardset) {
return cardset._id;
});
var learned = Learned.find({
$or: [
{user_id: this.userId},
{cardset_id: {$in: cardsetsIds}}
]
});
return learned;
}
});
}
Meteor.methods({
addLearned: function (cardset_id, card_id) {
// Make sure the user is logged in
if (!Meteor.userId() || Roles.userIsInRole(this.userId, 'blocked')) {
throw new Meteor.Error("not-authorized");
}
Learned.upsert({
cardset_id: cardset_id,
card_id: card_id,
user_id: Meteor.userId()
}, {
$set: {
cardset_id: cardset_id,
card_id: card_id,
user_id: Meteor.userId()
},
$setOnInsert: {
box: 1,
ef: 2.5,
reps: 0,
interval: 0,
nextDate: new Date(),
currentDate: new Date()
}
});
},
updateLearned: function (learned_id, box) {
// Make sure the user is logged in
if (!Meteor.userId() || Roles.userIsInRole(this.userId, 'blocked')) {
throw new Meteor.Error("not-authorized");
}
Learned.update(learned_id, {
$set: {
box: box,
currentDate: new Date()
}
});
},
updateLearnedMemo: function (learned_id, grade) {
// Make sure the user is logged in
if (!Meteor.userId() || Roles.userIsInRole(this.userId, 'blocked')) {
throw new Meteor.Error("not-authorized");
}
// EF (easiness factor) is a rating for how difficult the card is.
// Grade: (0-2) Set reps and interval to 0, keep current EF (repeat card today)
// (3) Set interval to 0, lower the EF, reps + 1 (repeat card today)
// (4-5) Reps + 1, interval is calculated using EF, increasing in time.
var learned = Learned.findOne(learned_id), ef = learned.ef, reps = learned.reps, nextDate = new Date();
if (grade < 3) {
reps = 0;
interval = 0;
} else {
ef = ef + (0.1 - (5 - grade) * (0.08 + (5 - grade) * 0.02));
if (ef < 1.3) {
ef = 1.3;
}
reps = reps + 1;
var interval = 0;
if (grade === 3) {
interval = 0;
} else {
switch (reps) {
case 1:
interval = 1;
break;
case 2:
interval = 6;
break;
default:
interval = Math.ceil((reps - 1) * ef);
break;
}
nextDate.setDate(nextDate.getDate() + interval);
}
}
Learned.update(learned_id, {
$set: {
ef: ef,
reps: reps,
interval: interval,
nextDate: nextDate
}
});
}
});
import {Meteor} from 'meteor/meteor';
import {Mongo} from 'meteor/mongo';
import {Cardsets } from './cardsets.js';
export const Learned = new Mongo.Collection("learned");
if (Meteor.isServer) {
Meteor.publish("learned", function () {
if (this.userId && !Roles.userIsInRole(this.userId, 'blocked')) {
var cardsetsIds = Cardsets.find({
owner: this.userId
}).map(function (cardset) {
return cardset._id;
});
var learned = Learned.find({
$or: [
{user_id: this.userId},
{cardset_id: {$in: cardsetsIds}}
]
});
return learned;
}
});
}
Meteor.methods({
addLearned: function (cardset_id, card_id) {
// Make sure the user is logged in
if (!Meteor.userId() || Roles.userIsInRole(this.userId, 'blocked')) {
throw new Meteor.Error("not-authorized");
}
Learned.upsert({
cardset_id: cardset_id,
card_id: card_id,
user_id: Meteor.userId()
}, {
$set: {
cardset_id: cardset_id,
card_id: card_id,
user_id: Meteor.userId()
},
$setOnInsert: {
box: 1,
ef: 2.5,
reps: 0,
interval: 0,
nextDate: new Date(),
currentDate: new Date()
}
});
},
updateLearned: function (learned_id, box) {
// Make sure the user is logged in
if (!Meteor.userId() || Roles.userIsInRole(this.userId, 'blocked')) {
throw new Meteor.Error("not-authorized");
}
Learned.update(learned_id, {
$set: {
box: box,
currentDate: new Date()
}
});
},
updateLearnedMemo: function (learned_id, grade) {
// Make sure the user is logged in
if (!Meteor.userId() || Roles.userIsInRole(this.userId, 'blocked')) {
throw new Meteor.Error("not-authorized");
}
// EF (easiness factor) is a rating for how difficult the card is.
// Grade: (0-2) Set reps and interval to 0, keep current EF (repeat card today)
// (3) Set interval to 0, lower the EF, reps + 1 (repeat card today)
// (4-5) Reps + 1, interval is calculated using EF, increasing in time.
var learned = Learned.findOne(learned_id), ef = learned.ef, reps = learned.reps, nextDate = new Date();
var interval = 0;
if (grade < 3) {
reps = 0;
interval = 0;
} else {
ef = ef + (0.1 - (5 - grade) * (0.08 + (5 - grade) * 0.02));
if (ef < 1.3) {
ef = 1.3;
}
reps = reps + 1;
if (grade === 3) {
interval = 0;
} else {
switch (reps) {
case 1:
interval = 1;
break;
case 2:
interval = 6;
break;
default:
interval = Math.ceil((reps - 1) * ef);
break;
}
nextDate.setDate(nextDate.getDate() + interval);
}
}
Learned.update(learned_id, {
$set: {
ef: ef,
reps: reps,
interval: interval,
nextDate: nextDate
}
});
}
});
import {Meteor } from 'meteor/meteor';
import {Mongo } from 'meteor/mongo';
import {Meteor} from 'meteor/meteor';
import {Mongo} from 'meteor/mongo';
import {SimpleSchema} from 'meteor/aldeed:simple-schema';
export const Notifications = new Mongo.Collection("notifications");
......
import {Meteor } from 'meteor/meteor';
import {Mongo } from 'meteor/mongo';
import {Meteor} from 'meteor/meteor';
import {Mongo} from 'meteor/mongo';
import {Cardsets } from './cardsets.js';
import {Cardsets} from './cardsets.js';
export const Paid = new Mongo.Collection("paid");
......@@ -14,7 +14,7 @@ if (Meteor.isServer) {
{
cardset_id: {
$in: Cardsets.find({owner: this.userId}).map(function (doc) {
return doc._id
return doc._id;
})
}
}
......
import {Meteor } from 'meteor/meteor';
import {Mongo } from 'meteor/mongo';
import {Meteor} from 'meteor/meteor';
import {Mongo} from 'meteor/mongo';
import {Experience } from './experience.js';
import {Cardsets } from './cardsets.js';
import {Experience} from './experience.js';
import {Cardsets} from './cardsets.js';
export const Ratings = new Mongo.Collection("ratings");
......
import {Meteor } from 'meteor/meteor';
import {Cardsets } from './cardsets.js';
import {Cards } from './cards.js';
Meteor.methods({
parseUpload: function (data, cardset_id) {
var cardset = Cardsets.findOne(cardset_id);
if (!Meteor.userId() || cardset.owner !== Meteor.userId() || Roles.userIsInRole(this.userId, 'blocked')) {
throw new Meteor.Error("not-authorized");
}
for (var i = 0; i < data.length; i++) {
var item = data[i];
if (item.front === undefined || item.front === "") {
throw new Meteor.Error("entry number: " + i, "front missing");
} else if (item.back === undefined || item.back === "") {
throw new Meteor.Error("entry number: " + i, "back missing");
}
}
for (var i = 0; i < data.length; i++) {
var item = data[i];
var front, back;
try {
// If the string is UTF-8, this will work and not throw an error.
front = decodeURIComponent(escape(item.front));
back = decodeURIComponent(escape(item.back));
} catch (e) {
// If it isn't, an error will be thrown, and we can asume that we have an ISO string.
front = item.front;
back = item.back;
}
if (item.front !== "") {
Cards.insert({
front: front,
back: back,
cardset_id: cardset_id
});
Cardsets.update(cardset_id, {
$set: {
quantity: Cards.find({cardset_id: cardset_id}).count()
}
});
}
}
}
});
import {Meteor} from 'meteor/meteor';
import {Cardsets} from './cardsets.js';