From 4b56bbfe6dd1c16ac8d2cc8da91dc55cff60177e Mon Sep 17 00:00:00 2001 From: Peter Verraedt Date: Wed, 22 Jan 2020 12:09:26 +0100 Subject: Add rule action to move cards to other boards Fixes #1996 --- client/components/rules/actions/boardActions.jade | 37 ++++++++---- client/components/rules/actions/boardActions.js | 30 +++++++-- server/rulesHelper.js | 74 ++++++++++++++++------- 3 files changed, 102 insertions(+), 39 deletions(-) diff --git a/client/components/rules/actions/boardActions.jade b/client/components/rules/actions/boardActions.jade index 6034184c..fda15062 100644 --- a/client/components/rules/actions/boardActions.jade +++ b/client/components/rules/actions/boardActions.jade @@ -1,29 +1,42 @@ template(name="boardActions") div.trigger-item div.trigger-content - div.trigger-text + div.trigger-text | {{_'r-move-card-to'}} div.trigger-dropdown select(id="move-gen-action") option(value="top") {{_'r-top-of'}} option(value="bottom") {{_'r-bottom-of'}} - div.trigger-text + div.trigger-text | {{_'r-its-list'}} div.trigger-button.js-add-gen-move-action.js-goto-rules i.fa.fa-plus div.trigger-item div.trigger-content - div.trigger-text + div.trigger-text | {{_'r-move-card-to'}} div.trigger-dropdown select(id="move-spec-action") option(value="top") {{_'r-top-of'}} option(value="bottom") {{_'r-bottom-of'}} - div.trigger-text - | {{_'r-list'}} + div.trigger-text + | {{_'r-the-board'}} + div.trigger-dropdown + select(id="board-id") + each boards + if $eq _id currentBoard._id + option(value="{{_id}}" selected) {{_ 'current'}} + else + option(value="{{_id}}") {{title}} + div.trigger-text + | {{_'r-in-list'}} div.trigger-dropdown input(id="listName",type=text,placeholder="{{_'r-name'}}") + div.trigger-text + | {{_'r-in-swimlane'}} + div.trigger-dropdown + input(id="swimlaneName",type=text,placeholder="{{_'r-name'}}") div.trigger-button.js-add-spec-move-action.js-goto-rules i.fa.fa-plus @@ -33,14 +46,14 @@ template(name="boardActions") select(id="arch-action") option(value="archive") {{_'r-archive'}} option(value="unarchive") {{_'r-unarchive'}} - div.trigger-text + div.trigger-text | {{_'r-card'}} div.trigger-button.js-add-arch-action.js-goto-rules i.fa.fa-plus div.trigger-item div.trigger-content - div.trigger-text + div.trigger-text | {{_'r-add-swimlane'}} div.trigger-dropdown input(id="swimlane-name",type=text,placeholder="{{_'r-name'}}") @@ -49,15 +62,15 @@ template(name="boardActions") div.trigger-item div.trigger-content - div.trigger-text + div.trigger-text | {{_'r-create-card'}} div.trigger-dropdown input(id="card-name",type=text,placeholder="{{_'r-name'}}") - div.trigger-text + div.trigger-text | {{_'r-in-list'}} div.trigger-dropdown input(id="list-name",type=text,placeholder="{{_'r-name'}}") - div.trigger-text + div.trigger-text | {{_'r-in-swimlane'}} div.trigger-dropdown input(id="swimlane-name2",type=text,placeholder="{{_'r-name'}}") @@ -65,8 +78,8 @@ template(name="boardActions") i.fa.fa-plus - - + + diff --git a/client/components/rules/actions/boardActions.js b/client/components/rules/actions/boardActions.js index 8568d2bf..c2f2375a 100644 --- a/client/components/rules/actions/boardActions.js +++ b/client/components/rules/actions/boardActions.js @@ -1,6 +1,22 @@ BlazeComponent.extendComponent({ onCreated() {}, + boards() { + const boards = Boards.find( + { + archived: false, + 'members.userId': Meteor.userId(), + _id: { + $ne: Meteor.user().getTemplatesBoardId(), + }, + }, + { + sort: ['title'], + }, + ); + return boards; + }, + events() { return [ { @@ -52,15 +68,18 @@ BlazeComponent.extendComponent({ const ruleName = this.data().ruleName.get(); const trigger = this.data().triggerVar.get(); const actionSelected = this.find('#move-spec-action').value; - const listTitle = this.find('#listName').value; + const swimlaneName = this.find('#swimlaneName').value; + const listName = this.find('#listName').value; const boardId = Session.get('currentBoard'); + const destBoardId = this.find('#board-id').value; const desc = Utils.getTriggerActionDesc(event, this); if (actionSelected === 'top') { const triggerId = Triggers.insert(trigger); const actionId = Actions.insert({ actionType: 'moveCardToTop', - listTitle, - boardId, + listName, + swimlaneName, + boardId: destBoardId, desc, }); Rules.insert({ @@ -74,8 +93,9 @@ BlazeComponent.extendComponent({ const triggerId = Triggers.insert(trigger); const actionId = Actions.insert({ actionType: 'moveCardToBottom', - listTitle, - boardId, + listName, + swimlaneName, + boardId: destBoardId, desc, }); Rules.insert({ diff --git a/server/rulesHelper.js b/server/rulesHelper.js index cf278c52..63e330ab 100644 --- a/server/rulesHelper.js +++ b/server/rulesHelper.js @@ -42,35 +42,65 @@ RulesHelper = { performAction(activity, action) { const card = Cards.findOne({ _id: activity.cardId }); const boardId = activity.boardId; - if (action.actionType === 'moveCardToTop') { - let listId; + if ( + action.actionType === 'moveCardToTop' || + action.actionType === 'moveCardToBottom' + ) { let list; - if (action.listTitle === '*') { - listId = card.listId; + let listId; + if (action.listName === '*') { list = card.list(); + if (boardId !== action.boardId) { + list = Lists.findOne({ title: list.title, boardId: action.boardId }); + } } else { - list = Lists.findOne({ title: action.listTitle, boardId }); - listId = list._id; + list = Lists.findOne({ + title: action.listName, + boardId: action.boardId, + }); } - const minOrder = _.min( - list.cardsUnfiltered(card.swimlaneId).map(c => c.sort), - ); - card.move(boardId, card.swimlaneId, listId, minOrder - 1); - } - if (action.actionType === 'moveCardToBottom') { - let listId; - let list; - if (action.listTitle === '*') { - listId = card.listId; - list = card.list(); + if (list === undefined) { + listId = ''; } else { - list = Lists.findOne({ title: action.listTitle, boardId }); listId = list._id; } - const maxOrder = _.max( - list.cardsUnfiltered(card.swimlaneId).map(c => c.sort), - ); - card.move(boardId, card.swimlaneId, listId, maxOrder + 1); + + let swimlane; + let swimlaneId; + if (action.swimlaneName === '*') { + swimlane = Swimlanes.findOne(card.swimlaneId); + if (boardId !== action.boardId) { + swimlane = Swimlanes.findOne({ + title: swimlane.title, + boardId: action.boardId, + }); + } + } else { + swimlane = Swimlanes.findOne({ + title: action.swimlaneName, + boardId: action.boardId, + }); + } + if (swimlane === undefined) { + swimlaneId = Swimlanes.findOne({ + title: 'Default', + boardId: action.boardId, + })._id; + } else { + swimlaneId = swimlane._id; + } + + if (action.actionType === 'moveCardToTop') { + const minOrder = _.min( + list.cardsUnfiltered(swimlaneId).map(c => c.sort), + ); + card.move(action.boardId, swimlaneId, listId, minOrder - 1); + } else { + const maxOrder = _.max( + list.cardsUnfiltered(swimlaneId).map(c => c.sort), + ); + card.move(action.boardId, swimlaneId, listId, maxOrder + 1); + } } if (action.actionType === 'sendEmail') { const to = action.emailTo; -- cgit v1.2.3-1-g7c22