Commit 33fdfd52 authored by Curtis Adam's avatar Curtis Adam

Turn the search into a server side function

parent 3d08e32b
......@@ -35,7 +35,6 @@ tap:i18n-db
aldeed:collection2
okgrow:promise
themeteorchef:bert
easy:search
barbatus:stars-rating
rexzh0u:kramed
simple:katex
......
......@@ -46,9 +46,6 @@ diff-sequence@1.1.0
dsyko:jquery-ui-touch-punch@1.2.4
dynamic-import@0.5.0
east5th:package-scan@0.0.5
easy:search@2.2.1
easysearch:components@2.2.1
easysearch:core@2.2.0
ecmascript@0.12.1
ecmascript-runtime@0.7.0
ecmascript-runtime-client@0.8.0
......@@ -121,12 +118,6 @@ observe-sequence@1.0.16
okgrow:promise@0.9.5
ordered-dict@1.1.0
patrickml:braintree@1.32.0
peerlibrary:assert@0.2.5
peerlibrary:base-component@0.16.0
peerlibrary:blaze-components@0.21.0
peerlibrary:computed-field@0.9.0
peerlibrary:data-lookup@0.1.0
peerlibrary:reactive-field@0.3.0
percolate:synced-cron@1.3.2
pfafman:filesaver@1.3.2
polyroid:font-roboto@1.0.1
......
......@@ -235,37 +235,45 @@ const CardsetsSchema = new SimpleSchema({
Cardsets.attachSchema(CardsetsSchema);
CardsetsIndex = new EasySearch.Index({
collection: Cardsets,
fields: [
'name'
],
engine: new EasySearch.Minimongo({
selector: function (searchObject, options, aggregation) {
// Default selector
const defSelector = this.defaultConfiguration().selector(searchObject, options, aggregation);
Meteor.methods({
getSearchCategoriesResult: function (searchValue) {
if (!Meteor.userId() || !UserPermissions.isNotBlockedOrFirstLogin()) {
throw new Meteor.Error("not-authorized");
} else if (searchValue !== undefined && searchValue !== null && searchValue.length > 0) {
let query = {};
// Filter selector
const selector = {};
selector.$and = [
defSelector,
{
if (UserPermissions.isAdmin()) {
query.name = {$regex: searchValue, $options: "i"};
query.kind = {$nin: ['demo', 'server']};
} else {
query = {
name: {$regex: searchValue, $options: "i"},
$or: [
{
owner: Meteor.userId()
},
{
visible: true
}
{owner: Meteor.userId()},
{kind: {$nin: ['demo', 'server', 'personal']}}
]
};
}
let results = Cardsets.find(query, {fields: {_id: 1}}).fetch();
let filter = [];
if (results !== undefined) {
for (let i = 0; i < results.length; i++) {
filter.push(results[i]._id);
}
];
return selector;
return Cardsets.find({_id: {$in: filter}}, {
fields: {
_id: 1,
name: 1,
owner: 1,
description: 1,
kind: 1
}
}).fetch();
}
} else {
return [];
}
})
});
Meteor.methods({
},
/**
* Adds a cardset to the personal deck of cards.
* @param {String} name - Title of the cardset
......@@ -420,7 +428,10 @@ Meteor.methods({
learningActive: false
}
});
let users = Workload.find({cardset_id: cardset._id, 'leitner.bonus': true}, {fields: {user_id: 1}}).fetch();
let users = Workload.find({
cardset_id: cardset._id,
'leitner.bonus': true
}, {fields: {user_id: 1}}).fetch();
for (let i = 0; i < users.length; i++) {
Workload.update({
cardset_id: cardset._id,
......
......@@ -126,7 +126,12 @@ Template.main.events({
'keyup #input-search': function (event) {
event.preventDefault();
Session.set("searchValue", $(event.currentTarget).val());
if ($(event.currentTarget).val() && CardsetsIndex.search(Session.get("searchValue")).count()) {
Meteor.call('getSearchCategoriesResult', Session.get("searchValue"), function (error, result) {
if (result) {
Session.set('searchCategoriesResult', result);
}
});
if ($(event.currentTarget).val() && Session.get('searchCategoriesResult') !== undefined) {
$('#searchDropdown').addClass("open");
} else {
$('#searchDropdown').removeClass("open");
......@@ -174,11 +179,7 @@ Template.main.helpers({
}
},
searchCategories: function () {
if (Session.get("searchValue")) {
return CardsetsIndex.search(Session.get("searchValue")).fetch();
} else {
return undefined;
}
return Session.get('searchCategoriesResult');
},
searchActive: function () {
return Session.get("searchValue") !== "" && Session.get("searchValue") !== undefined;
......@@ -236,6 +237,7 @@ Template.main.onRendered(function () {
$("html, body").click(function () {
$('#input-search').val('');
Session.set("searchValue", undefined);
Session.set('searchCategoriesResult', []);
});
});
......
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