diff options
Diffstat (limited to 'models/boards.js')
-rw-r--r-- | models/boards.js | 313 |
1 files changed, 309 insertions, 4 deletions
diff --git a/models/boards.js b/models/boards.js index 857aa963..26dc6127 100644 --- a/models/boards.js +++ b/models/boards.js @@ -185,6 +185,7 @@ Boards.attachSchema( isActive: true, isNoComments: false, isCommentOnly: false, + isWorker: false, }, ]; } @@ -222,6 +223,13 @@ Boards.attachSchema( type: Boolean, optional: true, }, + 'members.$.isWorker': { + /** + * Is the member only allowed to move card, assign himself to card and comment + */ + type: Boolean, + optional: true, + }, permission: { /** * visibility of the board @@ -270,6 +278,7 @@ Boards.attachSchema( optional: true, defaultValue: null, }, + subtasksDefaultListId: { /** * The default List ID assigned to subtasks. @@ -278,6 +287,19 @@ Boards.attachSchema( optional: true, defaultValue: null, }, + + dateSettingsDefaultBoardId: { + type: String, + optional: true, + defaultValue: null, + }, + + dateSettingsDefaultListId: { + type: String, + optional: true, + defaultValue: null, + }, + allowsSubtasks: { /** * Does the board allows subtasks? @@ -285,6 +307,127 @@ Boards.attachSchema( type: Boolean, defaultValue: true, }, + + allowsAttachments: { + /** + * Does the board allows attachments? + */ + type: Boolean, + defaultValue: true, + }, + + allowsChecklists: { + /** + * Does the board allows checklists? + */ + type: Boolean, + defaultValue: true, + }, + + allowsComments: { + /** + * Does the board allows comments? + */ + type: Boolean, + defaultValue: true, + }, + + allowsDescriptionTitle: { + /** + * Does the board allows description title? + */ + type: Boolean, + defaultValue: true, + }, + + allowsDescriptionText: { + /** + * Does the board allows description text? + */ + type: Boolean, + defaultValue: true, + }, + + allowsActivities: { + /** + * Does the board allows comments? + */ + type: Boolean, + defaultValue: true, + }, + + allowsLabels: { + /** + * Does the board allows labels? + */ + type: Boolean, + defaultValue: true, + }, + + allowsAssignee: { + /** + * Does the board allows assignee? + */ + type: Boolean, + defaultValue: true, + }, + + allowsMembers: { + /** + * Does the board allows members? + */ + type: Boolean, + defaultValue: true, + }, + + allowsRequestedBy: { + /** + * Does the board allows requested by? + */ + type: Boolean, + defaultValue: true, + }, + + allowsAssignedBy: { + /** + * Does the board allows requested by? + */ + type: Boolean, + defaultValue: true, + }, + + allowsReceivedDate: { + /** + * Does the board allows received date? + */ + type: Boolean, + defaultValue: true, + }, + + allowsStartDate: { + /** + * Does the board allows start date? + */ + type: Boolean, + defaultValue: true, + }, + + allowsEndDate: { + /** + * Does the board allows end date? + */ + type: Boolean, + defaultValue: true, + }, + + allowsDueDate: { + /** + * Does the board allows due date? + */ + type: Boolean, + defaultValue: true, + }, + presentParentTask: { /** * Controls how to present the parent task: @@ -350,6 +493,14 @@ Boards.attachSchema( type: String, defaultValue: 'board', }, + sort: { + /** + * Sort value + */ + type: Number, + decimal: true, + defaultValue: -1, + }, }), ); @@ -538,6 +689,7 @@ Boards.helpers({ isActive: true, isAdmin: false, isNoComments: true, + isWorker: false, }); }, @@ -547,6 +699,17 @@ Boards.helpers({ isActive: true, isAdmin: false, isCommentOnly: true, + isWorker: false, + }); + }, + + hasWorker(memberId) { + return !!_.findWhere(this.members, { + userId: memberId, + isActive: true, + isAdmin: false, + isCommentOnly: false, + isWorker: true, }); }, @@ -651,7 +814,11 @@ Boards.helpers({ if (term) { const regex = new RegExp(term, 'i'); - query.$or = [{ title: regex }, { description: regex }]; + query.$or = [ + { title: regex }, + { description: regex }, + { customFields: { $elemMatch: { value: regex } } }, + ]; } return Cards.find(query, projection); @@ -690,6 +857,39 @@ Boards.helpers({ return Boards.findOne(this.getDefaultSubtasksBoardId()); }, + //Date Settings option such as received date, start date and so on. + getDefaultDateSettingsBoardId() { + if ( + this.dateSettingsDefaultBoardId === null || + this.dateSettingsDefaultBoardId === undefined + ) { + this.dateSettingsDefaultBoardId = Boards.insert({ + title: `^${this.title}^`, + permission: this.permission, + members: this.members, + color: this.color, + description: TAPi18n.__('default-dates-board', { + board: this.title, + }), + }); + + Swimlanes.insert({ + title: TAPi18n.__('default'), + boardId: this.dateSettingsDefaultBoardId, + }); + Boards.update(this._id, { + $set: { + dateSettingsDefaultBoardId: this.dateSettingsDefaultBoardId, + }, + }); + } + return this.dateSettingsDefaultBoardId; + }, + + getDefaultDateSettingsBoard() { + return Boards.findOne(this.getDefaultDateSettingsBoardId()); + }, + getDefaultSubtasksListId() { if ( this.subtasksDefaultListId === null || @@ -708,6 +908,24 @@ Boards.helpers({ return Lists.findOne(this.getDefaultSubtasksListId()); }, + getDefaultDateSettingsListId() { + if ( + this.dateSettingsDefaultListId === null || + this.dateSettingsDefaultListId === undefined + ) { + this.dateSettingsDefaultListId = Lists.insert({ + title: TAPi18n.__('queue'), + boardId: this._id, + }); + this.setDateSettingsDefaultListId(this.dateSettingsDefaultListId); + } + return this.dateSettingsDefaultListId; + }, + + getDefaultDateSettingsList() { + return Lists.findOne(this.getDefaultDateSettingsListId()); + }, + getDefaultSwimline() { let result = Swimlanes.findOne({ boardId: this._id }); if (result === undefined) { @@ -849,6 +1067,7 @@ Boards.mutations({ isActive: true, isNoComments: false, isCommentOnly: false, + isWorker: false, }, }, }; @@ -881,6 +1100,7 @@ Boards.mutations({ isAdmin, isNoComments, isCommentOnly, + isWorker, currentUserId = Meteor.userId(), ) { const memberIndex = this.memberIndex(memberId); @@ -894,6 +1114,7 @@ Boards.mutations({ [`members.${memberIndex}.isAdmin`]: isAdmin, [`members.${memberIndex}.isNoComments`]: isNoComments, [`members.${memberIndex}.isCommentOnly`]: isCommentOnly, + [`members.${memberIndex}.isWorker`]: isWorker, }, }; }, @@ -902,6 +1123,66 @@ Boards.mutations({ return { $set: { allowsSubtasks } }; }, + setAllowsMembers(allowsMembers) { + return { $set: { allowsMembers } }; + }, + + setAllowsChecklists(allowsChecklists) { + return { $set: { allowsChecklists } }; + }, + + setAllowsAssignee(allowsAssignee) { + return { $set: { allowsAssignee } }; + }, + + setAllowsAssignedBy(allowsAssignedBy) { + return { $set: { allowsAssignedBy } }; + }, + + setAllowsRequestedBy(allowsRequestedBy) { + return { $set: { allowsRequestedBy } }; + }, + + setAllowsAttachments(allowsAttachments) { + return { $set: { allowsAttachments } }; + }, + + setAllowsLabels(allowsLabels) { + return { $set: { allowsLabels } }; + }, + + setAllowsComments(allowsComments) { + return { $set: { allowsComments } }; + }, + + setAllowsDescriptionTitle(allowsDescriptionTitle) { + return { $set: { allowsDescriptionTitle } }; + }, + + setAllowsDescriptionText(allowsDescriptionText) { + return { $set: { allowsDescriptionText } }; + }, + + setAllowsActivities(allowsActivities) { + return { $set: { allowsActivities } }; + }, + + setAllowsReceivedDate(allowsReceivedDate) { + return { $set: { allowsReceivedDate } }; + }, + + setAllowsStartDate(allowsStartDate) { + return { $set: { allowsStartDate } }; + }, + + setAllowsEndDate(allowsEndDate) { + return { $set: { allowsEndDate } }; + }, + + setAllowsDueDate(allowsDueDate) { + return { $set: { allowsDueDate } }; + }, + setSubtasksDefaultBoardId(subtasksDefaultBoardId) { return { $set: { subtasksDefaultBoardId } }; }, @@ -913,6 +1194,10 @@ Boards.mutations({ setPresentParentTask(presentParentTask) { return { $set: { presentParentTask } }; }, + + move(sortIndex) { + return { $set: { sort: sortIndex } }; + }, }); function boardRemover(userId, doc) { @@ -1010,6 +1295,17 @@ if (Meteor.isServer) { }); } +// Insert new board at last position in sort order. +Boards.before.insert((userId, doc) => { + const lastBoard = Boards.findOne( + { sort: { $exists: true } }, + { sort: { sort: -1 } }, + ); + if (lastBoard && typeof lastBoard.sort !== 'undefined') { + doc.sort = lastBoard.sort + 1; + } +}); + if (Meteor.isServer) { // Let MongoDB ensure that a member is not included twice in the same board Meteor.startup(() => { @@ -1193,7 +1489,7 @@ if (Meteor.isServer) { 'members.userId': paramUserId, }, { - sort: ['title'], + sort: { sort: 1 /* boards default sorting */ }, }, ).map(function(board) { return { @@ -1223,7 +1519,12 @@ if (Meteor.isServer) { Authentication.checkUserId(req.userId); JsonRoutes.sendResult(res, { code: 200, - data: Boards.find({ permission: 'public' }).map(function(doc) { + data: Boards.find( + { permission: 'public' }, + { + sort: { sort: 1 /* boards default sorting */ }, + }, + ).map(function(doc) { return { _id: doc._id, title: doc.title, @@ -1281,6 +1582,7 @@ if (Meteor.isServer) { * @param {boolean} [isActive] is the board active (default true) * @param {boolean} [isNoComments] disable comments (default false) * @param {boolean} [isCommentOnly] only enable comments (default false) + * @param {boolean} [isWorker] only move cards, assign himself to card and comment (default false) * @param {string} [permission] "private" board <== Set to "public" if you * want public Wekan board * @param {string} [color] the color of the board @@ -1300,6 +1602,7 @@ if (Meteor.isServer) { isActive: req.body.isActive || true, isNoComments: req.body.isNoComments || false, isCommentOnly: req.body.isCommentOnly || false, + isWorker: req.body.isWorker || false, }, ], permission: req.body.permission || 'private', @@ -1403,6 +1706,7 @@ if (Meteor.isServer) { * @param {boolean} isAdmin admin capability * @param {boolean} isNoComments NoComments capability * @param {boolean} isCommentOnly CommentsOnly capability + * @param {boolean} isWorker Worker capability */ JsonRoutes.add('POST', '/api/boards/:boardId/members/:memberId', function( req, @@ -1411,7 +1715,7 @@ if (Meteor.isServer) { try { const boardId = req.params.boardId; const memberId = req.params.memberId; - const { isAdmin, isNoComments, isCommentOnly } = req.body; + const { isAdmin, isNoComments, isCommentOnly, isWorker } = req.body; Authentication.checkBoardAccess(req.userId, boardId); const board = Boards.findOne({ _id: boardId }); function isTrue(data) { @@ -1426,6 +1730,7 @@ if (Meteor.isServer) { isTrue(isAdmin), isTrue(isNoComments), isTrue(isCommentOnly), + isTrue(isWorker), req.userId, ); |