summaryrefslogtreecommitdiffstats
path: root/models/boards.js
diff options
context:
space:
mode:
Diffstat (limited to 'models/boards.js')
-rw-r--r--models/boards.js38
1 files changed, 35 insertions, 3 deletions
diff --git a/models/boards.js b/models/boards.js
index 8862f301..26dc6127 100644
--- a/models/boards.js
+++ b/models/boards.js
@@ -493,6 +493,14 @@ Boards.attachSchema(
type: String,
defaultValue: 'board',
},
+ sort: {
+ /**
+ * Sort value
+ */
+ type: Number,
+ decimal: true,
+ defaultValue: -1,
+ },
}),
);
@@ -806,7 +814,11 @@ Boards.helpers({
if (term) {
const regex = new RegExp(term, 'i');
- query.$or = [{ title: regex }, { description: regex }];
+ query.$or = [
+ { title: regex },
+ { description: regex },
+ { customFields: { $elemMatch: { value: regex } } },
+ ];
}
return Cards.find(query, projection);
@@ -1182,6 +1194,10 @@ Boards.mutations({
setPresentParentTask(presentParentTask) {
return { $set: { presentParentTask } };
},
+
+ move(sortIndex) {
+ return { $set: { sort: sortIndex } };
+ },
});
function boardRemover(userId, doc) {
@@ -1279,6 +1295,17 @@ if (Meteor.isServer) {
});
}
+// Insert new board at last position in sort order.
+Boards.before.insert((userId, doc) => {
+ const lastBoard = Boards.findOne(
+ { sort: { $exists: true } },
+ { sort: { sort: -1 } },
+ );
+ if (lastBoard && typeof lastBoard.sort !== 'undefined') {
+ doc.sort = lastBoard.sort + 1;
+ }
+});
+
if (Meteor.isServer) {
// Let MongoDB ensure that a member is not included twice in the same board
Meteor.startup(() => {
@@ -1462,7 +1489,7 @@ if (Meteor.isServer) {
'members.userId': paramUserId,
},
{
- sort: ['title'],
+ sort: { sort: 1 /* boards default sorting */ },
},
).map(function(board) {
return {
@@ -1492,7 +1519,12 @@ if (Meteor.isServer) {
Authentication.checkUserId(req.userId);
JsonRoutes.sendResult(res, {
code: 200,
- data: Boards.find({ permission: 'public' }).map(function(doc) {
+ data: Boards.find(
+ { permission: 'public' },
+ {
+ sort: { sort: 1 /* boards default sorting */ },
+ },
+ ).map(function(doc) {
return {
_id: doc._id,
title: doc.title,