remove feature

This commit is contained in:
guillaume 2019-04-23 18:00:09 +02:00
parent 6933424fca
commit 8137f2692f
10 changed files with 135 additions and 14 deletions

View file

@ -803,6 +803,13 @@ Boards.mutations({
},
});
function boardRemover(userId, doc) {
[Cards, Lists, Swimlanes, Integrations, Rules, Activities].forEach((element) => {
element.remove({ boardId: doc._id });
});
}
if (Meteor.isServer) {
Boards.allow({
insert: Meteor.userId,
@ -966,6 +973,18 @@ if (Meteor.isServer) {
}
});
Boards.before.remove((userId, doc) => {
boardRemover(userId, doc);
// Add removeBoard activity to keep it
Activities.insert({
userId,
type: 'board',
activityTypeId: doc._id,
activityType: 'removeBoard',
boardId: doc._id,
});
});
// Add a new activity if we add or remove a member to the board
Boards.after.update((userId, doc, fieldNames, modifier) => {
if (!_.contains(fieldNames, 'members')) {

View file

@ -1518,7 +1518,7 @@ function cardCreation(userId, doc) {
}
function cardRemover(userId, doc) {
Activities.remove({
ChecklistItems.remove({
cardId: doc._id,
});
Checklists.remove({
@ -1583,7 +1583,7 @@ if (Meteor.isServer) {
// Remove all activities associated with a card if we remove the card
// Remove also card_comments / checklists / attachments
Cards.after.remove((userId, doc) => {
Cards.before.remove((userId, doc) => {
cardRemover(userId, doc);
});
}

View file

@ -157,8 +157,6 @@ if (Meteor.isServer) {
listId: doc.listId,
swimlaneId: doc.swimlaneId,
});
});
}

View file

@ -217,6 +217,10 @@ Lists.helpers({
isTemplateList() {
return this.type === 'template-list';
},
remove() {
Lists.remove({ _id: this._id});
},
});
Lists.mutations({
@ -310,6 +314,12 @@ if (Meteor.isServer) {
});
Lists.before.remove((userId, doc) => {
const cards = Cards.find({ listId: doc._id });
if (cards) {
cards.forEach((card) => {
Cards.remove(card._id);
});
}
Activities.insert({
userId,
type: 'list',

View file

@ -180,6 +180,10 @@ Swimlanes.helpers({
const user = Users.findOne(Meteor.userId());
return user.profile.boardTemplatesSwimlaneId === this._id;
},
remove() {
Swimlanes.remove({ _id: this._id});
},
});
Swimlanes.mutations({
@ -234,7 +238,21 @@ if (Meteor.isServer) {
});
});
Swimlanes.before.remove((userId, doc) => {
Swimlanes.before.remove(function(userId, doc) {
const lists = Lists.find({
boardId: doc.boardId,
swimlaneId: {$in: [doc._id, '']},
archived: false,
}, { sort: ['sort'] });
if (lists.count() < 2) {
lists.forEach((list) => {
list.remove();
});
} else {
Cards.remove({swimlaneId: doc._id});
}
Activities.insert({
userId,
type: 'swimlane',