summaryrefslogtreecommitdiffstats
path: root/models/lists.js
diff options
context:
space:
mode:
Diffstat (limited to 'models/lists.js')
-rw-r--r--models/lists.js198
1 files changed, 150 insertions, 48 deletions
diff --git a/models/lists.js b/models/lists.js
index d9a5b8e2..6f6996cb 100644
--- a/models/lists.js
+++ b/models/lists.js
@@ -42,6 +42,23 @@ Lists.attachSchema(new SimpleSchema({
}
},
},
+ wipLimit: {
+ type: Object,
+ optional: true,
+ },
+ 'wipLimit.value': {
+ type: Number,
+ decimal: false,
+ defaultValue: 1,
+ },
+ 'wipLimit.enabled': {
+ type: Boolean,
+ defaultValue: false,
+ },
+ 'wipLimit.soft': {
+ type: Boolean,
+ defaultValue: false,
+ },
}));
Lists.allow({
@@ -58,11 +75,15 @@ Lists.allow({
});
Lists.helpers({
- cards() {
- return Cards.find(Filter.mongoSelector({
+ cards(swimlaneId) {
+ const selector = {
listId: this._id,
archived: false,
- }), { sort: ['sort'] });
+ };
+ if (swimlaneId)
+ selector.swimlaneId = swimlaneId;
+ return Cards.find(Filter.mongoSelector(selector),
+ { sort: ['sort'] });
},
allCards() {
@@ -72,6 +93,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 +118,44 @@ Lists.mutations({
restore() {
return { $set: { archived: false } };
},
+
+ toggleSoftLimit(toggle) {
+ return { $set: { 'wipLimit.soft': toggle } };
+ },
+
+ 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);
+ if(limit === 0){
+ limit = 1;
+ }
+ Lists.findOne({ _id: listId }).setWipLimit(limit);
+ },
+
+ enableWipLimit(listId) {
+ check(listId, String);
+ const list = Lists.findOne({ _id: listId });
+ if(list.getWipLimit('value') === 0){
+ list.setWipLimit(1);
+ }
+ list.toggleWipLimit(!list.getWipLimit('enabled'));
+ },
+
+ enableSoftLimit(listId) {
+ check(listId, String);
+ const list = Lists.findOne({ _id: listId });
+ list.toggleSoftLimit(!list.getWipLimit('soft'));
+ },
});
Lists.hookOptions.after.update = { fetchPrevious: false };
@@ -131,57 +201,89 @@ if (Meteor.isServer) {
//LISTS REST API
if (Meteor.isServer) {
- JsonRoutes.add('GET', '/api/boards/:boardId/lists', function (req, res, next) {
- const paramBoardId = req.params.boardId;
- Authentication.checkBoardAccess( req.userId, paramBoardId);
-
- JsonRoutes.sendResult(res, {
- code: 200,
- data: Lists.find({ boardId: paramBoardId, archived: false }).map(function (doc) {
- return {
- _id: doc._id,
- title: doc.title,
- };
- }),
- });
+ JsonRoutes.add('GET', '/api/boards/:boardId/lists', function (req, res) {
+ try {
+ const paramBoardId = req.params.boardId;
+ Authentication.checkBoardAccess( req.userId, paramBoardId);
+
+ JsonRoutes.sendResult(res, {
+ code: 200,
+ data: Lists.find({ boardId: paramBoardId, archived: false }).map(function (doc) {
+ return {
+ _id: doc._id,
+ title: doc.title,
+ };
+ }),
+ });
+ }
+ catch (error) {
+ JsonRoutes.sendResult(res, {
+ code: 200,
+ data: error,
+ });
+ }
});
- JsonRoutes.add('GET', '/api/boards/:boardId/lists/:listId', function (req, res, next) {
- const paramBoardId = req.params.boardId;
- const paramListId = req.params.listId;
- Authentication.checkBoardAccess( req.userId, paramBoardId);
- JsonRoutes.sendResult(res, {
- code: 200,
- data: Lists.findOne({ _id: paramListId, boardId: paramBoardId, archived: false }),
- });
+ JsonRoutes.add('GET', '/api/boards/:boardId/lists/:listId', function (req, res) {
+ try {
+ const paramBoardId = req.params.boardId;
+ const paramListId = req.params.listId;
+ Authentication.checkBoardAccess( req.userId, paramBoardId);
+ JsonRoutes.sendResult(res, {
+ code: 200,
+ data: Lists.findOne({ _id: paramListId, boardId: paramBoardId, archived: false }),
+ });
+ }
+ catch (error) {
+ JsonRoutes.sendResult(res, {
+ code: 200,
+ data: error,
+ });
+ }
});
- JsonRoutes.add('POST', '/api/boards/:boardId/lists', function (req, res, next) {
- Authentication.checkUserId( req.userId);
- const paramBoardId = req.params.boardId;
- const id = Lists.insert({
- title: req.body.title,
- boardId: paramBoardId,
- });
- JsonRoutes.sendResult(res, {
- code: 200,
- data: {
- _id: id,
- },
- });
+ JsonRoutes.add('POST', '/api/boards/:boardId/lists', function (req, res) {
+ try {
+ Authentication.checkUserId( req.userId);
+ const paramBoardId = req.params.boardId;
+ const id = Lists.insert({
+ title: req.body.title,
+ boardId: paramBoardId,
+ });
+ JsonRoutes.sendResult(res, {
+ code: 200,
+ data: {
+ _id: id,
+ },
+ });
+ }
+ catch (error) {
+ JsonRoutes.sendResult(res, {
+ code: 200,
+ data: error,
+ });
+ }
});
- JsonRoutes.add('DELETE', '/api/boards/:boardId/lists/:listId', function (req, res, next) {
- Authentication.checkUserId( req.userId);
- const paramBoardId = req.params.boardId;
- const paramListId = req.params.listId;
- Lists.remove({ _id: paramListId, boardId: paramBoardId });
- JsonRoutes.sendResult(res, {
- code: 200,
- data: {
- _id: paramListId,
- },
- });
+ JsonRoutes.add('DELETE', '/api/boards/:boardId/lists/:listId', function (req, res) {
+ try {
+ Authentication.checkUserId( req.userId);
+ const paramBoardId = req.params.boardId;
+ const paramListId = req.params.listId;
+ Lists.remove({ _id: paramListId, boardId: paramBoardId });
+ JsonRoutes.sendResult(res, {
+ code: 200,
+ data: {
+ _id: paramListId,
+ },
+ });
+ }
+ catch (error) {
+ JsonRoutes.sendResult(res, {
+ code: 200,
+ data: error,
+ });
+ }
});
}