Some inspiration from checklists to subtasks

This commit is contained in:
Nicu Tofan 2018-06-17 22:55:01 +03:00
parent c3037b155f
commit b627ced605
No known key found for this signature in database
GPG key ID: 7EE66E95E64FD0B7

View file

@ -4,6 +4,29 @@ Subtasks.attachSchema(new SimpleSchema({
title: {
type: String,
},
startAt: { // this is a predicted time
type: Date,
optional: true,
},
endAt: { // this is a predicted time
type: Date,
optional: true,
},
finishedAt: { // The date & time when it is marked as being done
type: Date,
optional: true,
},
createdAt: {
type: Date,
denyUpdate: false,
autoValue() { // eslint-disable-line consistent-return
if (this.isInsert) {
return new Date();
} else {
this.unset();
}
},
},
sort: {
type: Number,
decimal: true,
@ -17,6 +40,16 @@ Subtasks.attachSchema(new SimpleSchema({
},
}));
Subtasks.helpers({
isFinished() {
return 0 !== this.itemCount() && this.itemCount() === this.finishedCount();
},
itemIndex(itemId) {
const items = self.findOne({_id : this._id}).items;
return _.pluck(items, '_id').indexOf(itemId);
},
});
Subtasks.allow({
insert(userId, doc) {
return allowIsBoardMemberByCard(userId, Cards.findOne(doc.cardId));
@ -31,6 +64,7 @@ Subtasks.allow({
});
Subtasks.before.insert((userId, doc) => {
doc.createdAt = new Date();
if (!doc.userId) {
doc.userId = userId;
}