summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorLauri Ojansivu <x@xet7.org>2017-10-09 15:55:44 +0300
committerLauri Ojansivu <x@xet7.org>2017-10-09 15:55:44 +0300
commit10cb2db94f4a6bb8160d4250a4a44be766398ace (patch)
tree279d0e56be46500a626fd74510d43ddf5abf9c1f /models
parentc84187bdadb7f1afaa8211773d1d1cb986709099 (diff)
parentc346743234833da6210beb8580dbf1290b2fbb04 (diff)
downloadwekan-10cb2db94f4a6bb8160d4250a4a44be766398ace.tar.gz
wekan-10cb2db94f4a6bb8160d4250a4a44be766398ace.tar.bz2
wekan-10cb2db94f4a6bb8160d4250a4a44be766398ace.zip
Merge branch 'amadilsons-issue783' into devel
WIP Limits. Thanks to amadilsons ! Closes #783
Diffstat (limited to 'models')
-rw-r--r--models/cards.js8
-rw-r--r--models/lists.js62
2 files changed, 70 insertions, 0 deletions
diff --git a/models/cards.js b/models/cards.js
index 0a440697..5b752ec3 100644
--- a/models/cards.js
+++ b/models/cards.js
@@ -179,6 +179,14 @@ Cards.helpers({
cardId: this._id,
});
},
+
+ canBeRestored() {
+ const list = Lists.findOne({_id: this.listId});
+ if(list.getWipLimit() && list.getWipLimit('enabled') && list.getWipLimit('value') === list.cards().count()){
+ return false;
+ }
+ return true;
+ },
});
Cards.mutations({
diff --git a/models/lists.js b/models/lists.js
index d9a5b8e2..1b999b07 100644
--- a/models/lists.js
+++ b/models/lists.js
@@ -42,6 +42,31 @@ Lists.attachSchema(new SimpleSchema({
}
},
},
+ wipLimit: {
+ type: Object,
+ optional: true,
+ },
+ 'wipLimit.value': {
+ type: Number,
+ decimal: false,
+ autoValue() {
+ if(this.isInsert){
+ return 0;
+ }
+ return this.value;
+ },
+ optional: true,
+ },
+ 'wipLimit.enabled':{
+ type: Boolean,
+ autoValue() {
+ if(this.isInsert){
+ return false;
+ }
+ return this.value;
+ },
+ optional: true,
+ },
}));
Lists.allow({
@@ -72,6 +97,17 @@ Lists.helpers({
board() {
return Boards.findOne(this.boardId);
},
+
+ getWipLimit(option){
+ const list = Lists.findOne({ _id: this._id });
+ if(!list.wipLimit) { // Necessary check to avoid exceptions for the case where the doc doesn't have the wipLimit field yet set
+ return 0;
+ } else if(!option) {
+ return list.wipLimit;
+ } else {
+ return list.wipLimit[option] ? list.wipLimit[option] : 0; // Necessary check to avoid exceptions for the case where the doc doesn't have the wipLimit field yet set
+ }
+ },
});
Lists.mutations({
@@ -86,6 +122,32 @@ Lists.mutations({
restore() {
return { $set: { archived: false } };
},
+
+ toggleWipLimit(toggle) {
+ return { $set: { 'wipLimit.enabled': toggle } };
+ },
+
+ setWipLimit(limit) {
+ return { $set: { 'wipLimit.value': limit } };
+ },
+});
+
+Meteor.methods({
+ applyWipLimit(listId, limit){
+ check(listId, String);
+ check(limit, Number);
+ Lists.findOne({ _id: listId }).setWipLimit(limit);
+ },
+
+ enableWipLimit(listId) {
+ check(listId, String);
+ const list = Lists.findOne({ _id: listId });
+ if(list.getWipLimit()){ // Necessary check to avoid exceptions for the case where the doc doesn't have the wipLimit field yet set
+ list.toggleWipLimit(!list.getWipLimit('enabled'));
+ } else {
+ list.toggleWipLimit(true); // First time toggle is always to 'true' because default is 'false'
+ }
+ },
});
Lists.hookOptions.after.update = { fetchPrevious: false };