summaryrefslogtreecommitdiffstats
path: root/models/boards.js
diff options
context:
space:
mode:
authorNicoP-S <paetni1@gmail.com>2020-04-26 00:37:30 +0200
committerGitHub <noreply@github.com>2020-04-26 00:37:30 +0200
commit8e709c1b79b3134d0be95fa922c42d02bb165005 (patch)
tree296574dd4f710e043c06538e39ec0b709f7924e0 /models/boards.js
parentedf52bc4382823ed8768251954371094a849213e (diff)
parent3908fe0ab875cf4b793c884a3d82df2f1a3b2686 (diff)
downloadwekan-8e709c1b79b3134d0be95fa922c42d02bb165005.tar.gz
wekan-8e709c1b79b3134d0be95fa922c42d02bb165005.tar.bz2
wekan-8e709c1b79b3134d0be95fa922c42d02bb165005.zip
Merge pull request #6 from wekan/master
Update
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,