Commit 502db5fc authored by Curtis Adam's avatar Curtis Adam Committed by Tom Käsler

Fix the cardset preview mode

parent 32dc5f7d
......@@ -54,7 +54,6 @@ check@1.3.1
shell-server@0.4.0
tsega:bootstrap3-lightbox
polyroid:font-roboto
ground:db
meteorhacks:ssr
fezvrasta:bootstrap-material-design
mrt:mathjax
......
......@@ -43,8 +43,6 @@ ddp-rate-limiter@1.0.7
ddp-server@2.2.0
deps@1.0.12
diff-sequence@1.1.0
dispatch:kernel@0.0.6
dispatch:request-animation-frame@0.0.1
dsyko:jquery-ui-touch-punch@1.2.4
dynamic-import@0.5.0
east5th:package-scan@0.0.5
......@@ -68,13 +66,6 @@ fourseven:scss@3.13.0
geojson-utils@1.0.10
google-config-ui@1.0.1
google-oauth@1.2.6
ground:db@0.3.15
ground:dictionary@0.2.1
ground:localstorage@0.1.9
ground:minimax@1.1.3
ground:servertime@0.0.3
ground:store@0.1.2
ground:util@0.1.17
harrison:papa-parse@1.1.7
hot-code-push@1.0.4
html-tools@1.0.11
......@@ -141,8 +132,6 @@ pfafman:filesaver@1.3.2
polyroid:font-roboto@1.0.1
promise@0.11.1
raix:eventemitter@0.1.3
raix:onetimeout@1.0.4
raix:stubfence@1.0.3
random@1.1.0
rate-limit@1.0.9
reactive-dict@1.2.1
......
......@@ -10,7 +10,14 @@ import {UserPermissions} from "./permissions";
export const Cards = new Mongo.Collection("cards");
function getPreviewCards(filterQuery) {
function getPreviewCards(cardset_id) {
let cardset = Cardsets.findOne({_id: cardset_id}, {fields: {_id: 1, owner: 1, cardGroups: 1, kind: 1}});
let filterQuery = {
$or: [
{cardset_id: cardset._id},
{cardset_id: {$in: cardset.cardGroups}}
]
};
let count = Cards.find(filterQuery).count();
let cardIdArray = Cards.find(filterQuery, {_id: 1}).map(function (card) {
return card._id;
......@@ -59,8 +66,7 @@ if (Meteor.isServer) {
Meteor.publish("cardsetCards", function (cardset_id) {
let cardset = Cardsets.findOne({_id: cardset_id}, {fields: {_id: 1, owner: 1, cardGroups: 1, kind: 1}});
if (this.userId && cardset !== undefined) {
let user = Meteor.users.findOne({_id: this.userId}, {fields: {_id: 1}});
let paidCardsets = Paid.findOne({user_id: user._id, cardset_id: cardset._id});
let paidCardsets = Paid.findOne({user_id: this.userId, cardset_id: cardset._id});
let filterQuery = {
$or: [
{cardset_id: cardset._id},
......@@ -74,32 +80,26 @@ if (Meteor.isServer) {
])) {
return Cards.find(filterQuery);
} else if (Roles.userIsInRole(this.userId, 'pro')) {
if (cardset.owner === user._id || !cardset.kind.includes("personal")) {
if (cardset.owner === this.userId || !cardset.kind.includes("personal")) {
return Cards.find(filterQuery);
} else {
return getPreviewCards(cardset._id);
}
} else if (Roles.userIsInRole(this.userId, 'university')) {
if (cardset.owner === user._id || cardset.kind.includes("free") || cardset.kind.includes("edu") || paidCardsets !== undefined) {
if (cardset.owner === this.userId || cardset.kind.includes("free") || cardset.kind.includes("edu") || paidCardsets !== undefined) {
return Cards.find(filterQuery);
} else {
return getPreviewCards(cardset._id);
}
} else {
if (cardset.owner === user._id || cardset.kind.includes("free") || paidCardsets !== undefined) {
if (cardset.owner === this.userId || cardset.kind.includes("free") || paidCardsets !== undefined) {
return Cards.find(filterQuery);
} else {
return getPreviewCards(cardset._id);
}
}
}
});
Meteor.publish("previewCards", function (cardset_id) {
let cardset = Cardsets.findOne({_id: cardset_id}, {fields: {_id: 1, owner: 1, cardGroups: 1, kind: 1}});
if (this.userId && !cardset.kind.includes("personal")) {
let filterQuery = {
$or: [
{cardset_id: cardset._id},
{cardset_id: {$in: cardset.cardGroups}}
]
};
return getPreviewCards(filterQuery);
}
});
}
var CardsSchema = new SimpleSchema({
......
import {AdminSettings} from "./adminSettings.js";
import {Cards} from "./cards.js";
import {Cardsets} from "./cardsets.js";
import {CollegesCourses} from "./colleges_courses.js";
import {Leitner, Wozniak} from "./learned.js";
import {Notifications} from "./notifications.js";
import {Paid} from "./paid.js";
import {Ratings} from "./ratings.js";
import {Categories} from "./settings.js";
Ground.Collection(Meteor.users);
Ground.Collection(AdminSettings);
Ground.Collection(Cards);
Ground.Collection(Cardsets);
Ground.Collection(CollegesCourses);
Ground.Collection(Leitner);
Ground.Collection(Wozniak);
Ground.Collection(Notifications);
Ground.Collection(Paid);
Ground.Collection(Ratings);
Ground.Collection(Categories);
......@@ -65,7 +65,9 @@
{{> cardSidebarRightNavigation}}
{{> cardSidebarLeftNavigation}}
{{/if}}
{{> cardSidebarItemCardList}}
{{#if hasCardsetPermission}}
{{> cardSidebarItemCardList}}
{{/if}}
{{> flashcardSidebarDictionary}}
{{> cardSidebarItemDelete}}
</template>
......
......@@ -2,8 +2,6 @@
import {Meteor} from "meteor/meteor";
import {Template} from "meteor/templating";
import {Session} from "meteor/session";
import {Cards} from "../../api/cards";
import {Cardsets} from "../../api/cardsets";
import "./preview.html";
/*
......@@ -26,22 +24,6 @@ Template.cardsetPreview.events({
}
});
Template.cardsetPreview.onCreated(function () {
if (Router.current().params._id) {
let cardset = Cardsets.findOne({_id: Router.current().params._id}, {fields: {_id: 1, cardGroups: 1}});
if (cardset !== undefined) {
let filterQuery = {
$or: [
{cardset_id: cardset._id},
{cardset_id: {$in: cardset.cardGroups}}
]
};
Cards._collection.remove(filterQuery);
Meteor.subscribe("previewCards", cardset._id);
}
}
});
Template.cardsetPreview.onDestroyed(function () {
if (Router.current().params._id) {
Meteor.subscribe('cardsetCards', Router.current().params._id);
......
......@@ -23,7 +23,6 @@ import "../first_login/first_login.js";
import "../editor/editor.js";
import "../editor/cardEditor.js";
import "../pomodoroTimer/pomodoroTimer.js";
import "../../api/groundDB.js";
import "../../api/cardIndex.js";
import "./overlays/zoomText.js";
import "../card/sidebar/sidebar.js";
......
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