mirror of
https://github.com/wekan/wekan.git
synced 2026-02-20 06:58:07 +01:00
Add checklist items model, migration and publication
This commit is contained in:
parent
83848dbee2
commit
bf7de463f1
4 changed files with 116 additions and 26 deletions
85
models/checklistItems.js
Normal file
85
models/checklistItems.js
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
ChecklistItems = new Mongo.Collection('checklistItems');
|
||||
|
||||
ChecklistItems.attachSchema(new SimpleSchema({
|
||||
title: {
|
||||
type: String,
|
||||
},
|
||||
sort: {
|
||||
type: Number,
|
||||
decimal: true,
|
||||
},
|
||||
isFinished: {
|
||||
type: Boolean,
|
||||
defaultValue: false,
|
||||
},
|
||||
checklistId: {
|
||||
type: String,
|
||||
},
|
||||
cardId: {
|
||||
type: String,
|
||||
},
|
||||
}));
|
||||
|
||||
ChecklistItems.allow({
|
||||
insert(userId, doc) {
|
||||
return allowIsBoardMemberByCard(userId, Cards.findOne(doc.cardId));
|
||||
},
|
||||
update(userId, doc) {
|
||||
return allowIsBoardMemberByCard(userId, Cards.findOne(doc.cardId));
|
||||
},
|
||||
remove(userId, doc) {
|
||||
return allowIsBoardMemberByCard(userId, Cards.findOne(doc.cardId));
|
||||
},
|
||||
fetch: ['userId', 'cardId'],
|
||||
});
|
||||
|
||||
ChecklistItems.before.insert((userId, doc) => {
|
||||
if (!doc.userId) {
|
||||
doc.userId = userId;
|
||||
}
|
||||
});
|
||||
|
||||
// Mutations
|
||||
ChecklistItems.mutations({
|
||||
setTitle(title) {
|
||||
return { $set: { title } };
|
||||
},
|
||||
toggleItem() {
|
||||
return { $set: { isFinished: !this.isFinished } };
|
||||
},
|
||||
});
|
||||
|
||||
// Activities helper
|
||||
function itemCreation(userId, doc) {
|
||||
const card = Cards.findOne(doc.cardId);
|
||||
const boardId = card.boardId;
|
||||
Activities.insert({
|
||||
userId,
|
||||
activityType: 'addChecklistItem',
|
||||
cardId: doc.cardId,
|
||||
boardId,
|
||||
checklistId: doc.checklistId,
|
||||
checklistItemId: doc._id,
|
||||
});
|
||||
}
|
||||
|
||||
function itemRemover(userId, doc) {
|
||||
Activities.remove({
|
||||
checklistItemId: doc._id,
|
||||
});
|
||||
}
|
||||
|
||||
// Activities
|
||||
if (Meteor.isServer) {
|
||||
Meteor.startup(() => {
|
||||
ChecklistItems._collection._ensureIndex({ checklistId: 1 });
|
||||
});
|
||||
|
||||
ChecklistItems.after.insert((userId, doc) => {
|
||||
itemCreation(userId, doc);
|
||||
});
|
||||
|
||||
ChecklistItems.after.remove((userId, doc) => {
|
||||
itemRemover(userId, doc);
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue