summaryrefslogtreecommitdiffstats
path: root/models/boards.js
diff options
context:
space:
mode:
Diffstat (limited to 'models/boards.js')
-rw-r--r--models/boards.js32
1 files changed, 30 insertions, 2 deletions
diff --git a/models/boards.js b/models/boards.js
index 35ee1a36..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,
+ },
}),
);
@@ -1186,6 +1194,10 @@ Boards.mutations({
setPresentParentTask(presentParentTask) {
return { $set: { presentParentTask } };
},
+
+ move(sortIndex) {
+ return { $set: { sort: sortIndex } };
+ },
});
function boardRemover(userId, doc) {
@@ -1283,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(() => {
@@ -1466,7 +1489,7 @@ if (Meteor.isServer) {
'members.userId': paramUserId,
},
{
- sort: ['title'],
+ sort: { sort: 1 /* boards default sorting */ },
},
).map(function(board) {
return {
@@ -1496,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,