The Open Source kanban (built with Meteor). Keep variable/table/field names camelCase. For translations, only add Pull Request changes to wekan/i18n/en.i18n.json , other translations are done at https://transifex.com/wekan/wekan only.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
wekan/models/checklistItems.js

95 lines
1.9 KiB

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 } };
},
move(checklistId, sortIndex) {
const cardId = Checklists.findOne(checklistId).cardId;
const mutatedFields = {
cardId,
checklistId,
sort: sortIndex,
};
return {$set: mutatedFields};
},
});
// 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);
});
}