summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorAndrés Manelli <andresmanelli@gmail.com>2019-02-25 22:48:25 +0100
committerAndrés Manelli <andresmanelli@gmail.com>2019-02-25 22:48:32 +0100
commitdc7286a0ef8111c0855129911492588ba8a384df (patch)
treedcc4f9be071a1bf55d1f2638ed63c958e0a42634 /models
parent13c2157e36f65be4138a85fae0379e0fe31f02bd (diff)
downloadwekan-dc7286a0ef8111c0855129911492588ba8a384df.tar.gz
wekan-dc7286a0ef8111c0855129911492588ba8a384df.tar.bz2
wekan-dc7286a0ef8111c0855129911492588ba8a384df.zip
Fix list view issues. Allow creation of boards from templates
Diffstat (limited to 'models')
-rw-r--r--models/boards.js36
-rw-r--r--models/cardComments.js2
-rw-r--r--models/cards.js2
-rw-r--r--models/lists.js6
-rw-r--r--models/swimlanes.js19
5 files changed, 55 insertions, 10 deletions
diff --git a/models/boards.js b/models/boards.js
index 0d3213bc..0db2e48e 100644
--- a/models/boards.js
+++ b/models/boards.js
@@ -315,6 +315,21 @@ Boards.attachSchema(new SimpleSchema({
Boards.helpers({
+ copy() {
+ const oldId = this._id;
+ delete this._id;
+ const _id = Boards.insert(this);
+
+ // Copy all swimlanes in board
+ Swimlanes.find({
+ boardId: oldId,
+ archived: false,
+ }).forEach((swimlane) => {
+ swimlane.type = 'swimlane';
+ swimlane.boardId = _id;
+ swimlane.copy(oldId);
+ });
+ },
/**
* Is supplied user authorized to view this board?
*/
@@ -463,6 +478,27 @@ Boards.helpers({
return _id;
},
+ searchBoards(term) {
+ check(term, Match.OneOf(String, null, undefined));
+
+ const query = { boardId: this._id };
+ query.type = 'cardType-linkedBoard';
+ query.archived = false;
+
+ const projection = { limit: 10, sort: { createdAt: -1 } };
+
+ if (term) {
+ const regex = new RegExp(term, 'i');
+
+ query.$or = [
+ { title: regex },
+ { description: regex },
+ ];
+ }
+
+ return Cards.find(query, projection);
+ },
+
searchSwimlanes(term) {
check(term, Match.OneOf(String, null, undefined));
diff --git a/models/cardComments.js b/models/cardComments.js
index f29366a5..fcb97104 100644
--- a/models/cardComments.js
+++ b/models/cardComments.js
@@ -69,7 +69,7 @@ CardComments.allow({
CardComments.helpers({
copy(newCardId) {
this.cardId = newCardId;
- this._id = null;
+ delete this._id;
CardComments.insert(this);
},
diff --git a/models/cards.js b/models/cards.js
index e91f0af5..c733c7f8 100644
--- a/models/cards.js
+++ b/models/cards.js
@@ -274,7 +274,7 @@ Cards.allow({
Cards.helpers({
copy() {
const oldId = this._id;
- this._id = null;
+ delete this._id;
const _id = Cards.insert(this);
// copy checklists
diff --git a/models/lists.js b/models/lists.js
index bf2430ee..d76c961c 100644
--- a/models/lists.js
+++ b/models/lists.js
@@ -139,20 +139,24 @@ Lists.allow({
Lists.helpers({
copy(swimlaneId) {
const oldId = this._id;
+ const oldSwimlaneId = this.swimlaneId || null;
let _id = null;
existingListWithSameName = Lists.findOne({
boardId: this.boardId,
title: this.title,
+ archived: false,
});
if (existingListWithSameName) {
_id = existingListWithSameName._id;
} else {
- this._id = null;
+ delete this._id;
+ delete this.swimlaneId;
_id = Lists.insert(this);
}
// Copy all cards in list
Cards.find({
+ swimlaneId: oldSwimlaneId,
listId: oldId,
archived: false,
}).forEach((card) => {
diff --git a/models/swimlanes.js b/models/swimlanes.js
index d3548329..a3427fc6 100644
--- a/models/swimlanes.js
+++ b/models/swimlanes.js
@@ -101,18 +101,23 @@ Swimlanes.allow({
});
Swimlanes.helpers({
- copy() {
+ copy(oldBoardId) {
const oldId = this._id;
- this._id = null;
+ delete this._id;
const _id = Swimlanes.insert(this);
- // Copy all lists in swimlane
- Lists.find({
- swimlaneId: oldId,
+ const query = {
+ swimlaneId: {$in: [oldId, '']},
archived: false,
- }).forEach((list) => {
+ };
+ if (oldBoardId) {
+ query.boardId = oldBoardId;
+ }
+
+ // Copy all lists in swimlane
+ Lists.find(query).forEach((list) => {
list.type = 'list';
- list.swimlaneId = '';
+ list.swimlaneId = oldId;
list.boardId = this.boardId;
list.copy(_id);
});