2018-01-19 12:22:03 -03:00
|
|
|
Swimlanes = new Mongo.Collection('swimlanes');
|
|
|
|
|
2018-10-26 07:27:24 +02:00
|
|
|
/**
|
|
|
|
* A swimlane is an line in the kaban board.
|
|
|
|
*/
|
2018-01-19 12:22:03 -03:00
|
|
|
Swimlanes.attachSchema(new SimpleSchema({
|
|
|
|
title: {
|
2018-10-26 07:27:24 +02:00
|
|
|
/**
|
|
|
|
* the title of the swimlane
|
|
|
|
*/
|
2018-01-19 12:22:03 -03:00
|
|
|
type: String,
|
|
|
|
},
|
|
|
|
archived: {
|
2018-10-26 07:27:24 +02:00
|
|
|
/**
|
|
|
|
* is the swimlane archived?
|
|
|
|
*/
|
2018-01-19 12:22:03 -03:00
|
|
|
type: Boolean,
|
|
|
|
autoValue() { // eslint-disable-line consistent-return
|
|
|
|
if (this.isInsert && !this.isSet) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
boardId: {
|
2018-10-26 07:27:24 +02:00
|
|
|
/**
|
|
|
|
* the ID of the board the swimlane is attached to
|
|
|
|
*/
|
2018-01-19 12:22:03 -03:00
|
|
|
type: String,
|
|
|
|
},
|
|
|
|
createdAt: {
|
2018-10-26 07:27:24 +02:00
|
|
|
/**
|
|
|
|
* creation date of the swimlane
|
|
|
|
*/
|
2018-01-19 12:22:03 -03:00
|
|
|
type: Date,
|
|
|
|
autoValue() { // eslint-disable-line consistent-return
|
|
|
|
if (this.isInsert) {
|
|
|
|
return new Date();
|
|
|
|
} else {
|
|
|
|
this.unset();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
sort: {
|
2018-10-26 07:27:24 +02:00
|
|
|
/**
|
|
|
|
* the sort value of the swimlane
|
|
|
|
*/
|
2018-01-19 12:22:03 -03:00
|
|
|
type: Number,
|
|
|
|
decimal: true,
|
|
|
|
// XXX We should probably provide a default
|
|
|
|
optional: true,
|
|
|
|
},
|
2019-01-24 16:47:09 +01:00
|
|
|
color: {
|
|
|
|
/**
|
|
|
|
* the color of the swimlane
|
|
|
|
*/
|
|
|
|
type: String,
|
|
|
|
optional: true,
|
|
|
|
// silver is the default, so it is left out
|
|
|
|
allowedValues: [
|
|
|
|
'white', 'green', 'yellow', 'orange', 'red', 'purple',
|
|
|
|
'blue', 'sky', 'lime', 'pink', 'black',
|
|
|
|
'peachpuff', 'crimson', 'plum', 'darkgreen',
|
|
|
|
'slateblue', 'magenta', 'gold', 'navy', 'gray',
|
|
|
|
'saddlebrown', 'paleturquoise', 'mistyrose', 'indigo',
|
|
|
|
],
|
|
|
|
},
|
2018-01-19 12:22:03 -03:00
|
|
|
updatedAt: {
|
2018-10-26 07:27:24 +02:00
|
|
|
/**
|
|
|
|
* when was the swimlane last edited
|
|
|
|
*/
|
2018-01-19 12:22:03 -03:00
|
|
|
type: Date,
|
|
|
|
optional: true,
|
|
|
|
autoValue() { // eslint-disable-line consistent-return
|
|
|
|
if (this.isUpdate) {
|
|
|
|
return new Date();
|
|
|
|
} else {
|
|
|
|
this.unset();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
2019-02-22 22:59:19 +01:00
|
|
|
type: {
|
|
|
|
/**
|
|
|
|
* The type of swimlane
|
|
|
|
*/
|
|
|
|
type: String,
|
|
|
|
defaultValue: 'swimlane',
|
|
|
|
},
|
2018-01-19 12:22:03 -03:00
|
|
|
}));
|
|
|
|
|
|
|
|
Swimlanes.allow({
|
|
|
|
insert(userId, doc) {
|
2018-09-04 20:09:36 +03:00
|
|
|
return allowIsBoardMemberCommentOnly(userId, Boards.findOne(doc.boardId));
|
2018-01-19 12:22:03 -03:00
|
|
|
},
|
|
|
|
update(userId, doc) {
|
2018-09-04 20:09:36 +03:00
|
|
|
return allowIsBoardMemberCommentOnly(userId, Boards.findOne(doc.boardId));
|
2018-01-19 12:22:03 -03:00
|
|
|
},
|
|
|
|
remove(userId, doc) {
|
2018-09-04 20:09:36 +03:00
|
|
|
return allowIsBoardMemberCommentOnly(userId, Boards.findOne(doc.boardId));
|
2018-01-19 12:22:03 -03:00
|
|
|
},
|
|
|
|
fetch: ['boardId'],
|
|
|
|
});
|
|
|
|
|
|
|
|
Swimlanes.helpers({
|
2019-02-27 20:45:58 +01:00
|
|
|
copy(boardId) {
|
2019-02-24 00:13:35 +01:00
|
|
|
const oldId = this._id;
|
2019-02-27 20:45:58 +01:00
|
|
|
const oldBoardId = this.boardId;
|
|
|
|
this.boardId = boardId;
|
2019-02-25 22:48:25 +01:00
|
|
|
delete this._id;
|
2019-02-24 00:13:35 +01:00
|
|
|
const _id = Swimlanes.insert(this);
|
|
|
|
|
2019-02-25 22:48:25 +01:00
|
|
|
const query = {
|
|
|
|
swimlaneId: {$in: [oldId, '']},
|
2019-02-24 00:13:35 +01:00
|
|
|
archived: false,
|
2019-02-25 22:48:25 +01:00
|
|
|
};
|
|
|
|
if (oldBoardId) {
|
|
|
|
query.boardId = oldBoardId;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy all lists in swimlane
|
|
|
|
Lists.find(query).forEach((list) => {
|
2019-02-24 00:13:35 +01:00
|
|
|
list.type = 'list';
|
2019-02-25 22:48:25 +01:00
|
|
|
list.swimlaneId = oldId;
|
2019-02-27 20:45:58 +01:00
|
|
|
list.boardId = boardId;
|
|
|
|
list.copy(boardId, _id);
|
2019-02-24 00:13:35 +01:00
|
|
|
});
|
2019-02-23 23:07:54 +01:00
|
|
|
},
|
|
|
|
|
2018-01-19 12:22:03 -03:00
|
|
|
cards() {
|
|
|
|
return Cards.find(Filter.mongoSelector({
|
|
|
|
swimlaneId: this._id,
|
|
|
|
archived: false,
|
|
|
|
}), { sort: ['sort'] });
|
|
|
|
},
|
|
|
|
|
2019-02-23 01:40:11 +01:00
|
|
|
lists() {
|
2019-03-01 14:41:09 +02:00
|
|
|
return Lists.find({
|
2019-02-24 11:54:52 +01:00
|
|
|
boardId: this.boardId,
|
|
|
|
swimlaneId: {$in: [this._id, '']},
|
2019-02-24 00:13:35 +01:00
|
|
|
archived: false,
|
2019-03-01 14:41:09 +02:00
|
|
|
}, { sort: ['sort'] });
|
2019-02-23 01:40:11 +01:00
|
|
|
},
|
|
|
|
|
2019-03-01 14:41:09 +02:00
|
|
|
myLists() {
|
2019-02-23 23:07:54 +01:00
|
|
|
return Lists.find({ swimlaneId: this._id });
|
|
|
|
},
|
|
|
|
|
2018-01-19 12:22:03 -03:00
|
|
|
allCards() {
|
|
|
|
return Cards.find({ swimlaneId: this._id });
|
|
|
|
},
|
|
|
|
|
|
|
|
board() {
|
|
|
|
return Boards.findOne(this.boardId);
|
|
|
|
},
|
2019-01-24 16:47:09 +01:00
|
|
|
|
|
|
|
colorClass() {
|
|
|
|
if (this.color)
|
|
|
|
return this.color;
|
|
|
|
return '';
|
|
|
|
},
|
2019-02-22 22:59:19 +01:00
|
|
|
|
|
|
|
isTemplateSwimlane() {
|
|
|
|
return this.type === 'template-swimlane';
|
|
|
|
},
|
2019-02-22 23:48:23 +01:00
|
|
|
|
|
|
|
isTemplateContainer() {
|
2019-02-24 00:13:35 +01:00
|
|
|
return this.type === 'template-container';
|
2019-02-22 23:48:23 +01:00
|
|
|
},
|
2019-02-23 01:40:11 +01:00
|
|
|
|
|
|
|
isListTemplatesSwimlane() {
|
2019-02-24 00:13:35 +01:00
|
|
|
const user = Users.findOne(Meteor.userId());
|
|
|
|
return user.profile.listTemplatesSwimlaneId === this._id;
|
2019-02-23 01:40:11 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
isCardTemplatesSwimlane() {
|
2019-02-24 00:13:35 +01:00
|
|
|
const user = Users.findOne(Meteor.userId());
|
|
|
|
return user.profile.cardTemplatesSwimlaneId === this._id;
|
2019-02-23 01:40:11 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
isBoardTemplatesSwimlane() {
|
2019-02-24 00:13:35 +01:00
|
|
|
const user = Users.findOne(Meteor.userId());
|
|
|
|
return user.profile.boardTemplatesSwimlaneId === this._id;
|
2019-02-23 01:40:11 +01:00
|
|
|
},
|
2018-01-19 12:22:03 -03:00
|
|
|
});
|
|
|
|
|
|
|
|
Swimlanes.mutations({
|
|
|
|
rename(title) {
|
|
|
|
return { $set: { title } };
|
|
|
|
},
|
|
|
|
|
|
|
|
archive() {
|
2019-02-23 23:07:54 +01:00
|
|
|
if (this.isTemplateSwimlane()) {
|
2019-03-01 14:41:09 +02:00
|
|
|
this.myLists().forEach((list) => {
|
2019-02-24 00:13:35 +01:00
|
|
|
return list.archive();
|
2019-02-23 23:07:54 +01:00
|
|
|
});
|
|
|
|
}
|
2018-01-19 12:22:03 -03:00
|
|
|
return { $set: { archived: true } };
|
|
|
|
},
|
|
|
|
|
|
|
|
restore() {
|
2019-02-23 23:07:54 +01:00
|
|
|
if (this.isTemplateSwimlane()) {
|
2019-03-01 14:41:09 +02:00
|
|
|
this.myLists().forEach((list) => {
|
2019-02-24 00:13:35 +01:00
|
|
|
return list.restore();
|
2019-02-23 23:07:54 +01:00
|
|
|
});
|
|
|
|
}
|
2018-01-19 12:22:03 -03:00
|
|
|
return { $set: { archived: false } };
|
|
|
|
},
|
2019-01-24 16:47:09 +01:00
|
|
|
|
|
|
|
setColor(newColor) {
|
|
|
|
if (newColor === 'silver') {
|
|
|
|
newColor = null;
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
$set: {
|
|
|
|
color: newColor,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
2018-01-19 12:22:03 -03:00
|
|
|
});
|
|
|
|
|
|
|
|
Swimlanes.hookOptions.after.update = { fetchPrevious: false };
|
|
|
|
|
|
|
|
if (Meteor.isServer) {
|
|
|
|
Meteor.startup(() => {
|
|
|
|
Swimlanes._collection._ensureIndex({ boardId: 1 });
|
|
|
|
});
|
|
|
|
|
|
|
|
Swimlanes.after.insert((userId, doc) => {
|
|
|
|
Activities.insert({
|
|
|
|
userId,
|
|
|
|
type: 'swimlane',
|
|
|
|
activityType: 'createSwimlane',
|
|
|
|
boardId: doc.boardId,
|
|
|
|
swimlaneId: doc._id,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
Swimlanes.before.remove((userId, doc) => {
|
|
|
|
Activities.insert({
|
|
|
|
userId,
|
|
|
|
type: 'swimlane',
|
|
|
|
activityType: 'removeSwimlane',
|
|
|
|
boardId: doc.boardId,
|
|
|
|
swimlaneId: doc._id,
|
|
|
|
title: doc.title,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
Swimlanes.after.update((userId, doc) => {
|
|
|
|
if (doc.archived) {
|
|
|
|
Activities.insert({
|
|
|
|
userId,
|
|
|
|
type: 'swimlane',
|
|
|
|
activityType: 'archivedSwimlane',
|
|
|
|
swimlaneId: doc._id,
|
|
|
|
boardId: doc.boardId,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
//SWIMLANE REST API
|
|
|
|
if (Meteor.isServer) {
|
2018-10-26 07:27:24 +02:00
|
|
|
/**
|
|
|
|
* @operation get_all_swimlanes
|
|
|
|
*
|
|
|
|
* @summary Get the list of swimlanes attached to a board
|
|
|
|
*
|
|
|
|
* @param {string} boardId the ID of the board
|
|
|
|
* @return_type [{_id: string,
|
|
|
|
* title: string}]
|
|
|
|
*/
|
2018-02-27 02:57:58 +01:00
|
|
|
JsonRoutes.add('GET', '/api/boards/:boardId/swimlanes', function (req, res) {
|
2018-01-19 12:22:03 -03:00
|
|
|
try {
|
|
|
|
const paramBoardId = req.params.boardId;
|
|
|
|
Authentication.checkBoardAccess( req.userId, paramBoardId);
|
|
|
|
|
|
|
|
JsonRoutes.sendResult(res, {
|
|
|
|
code: 200,
|
|
|
|
data: Swimlanes.find({ boardId: paramBoardId, archived: false }).map(function (doc) {
|
|
|
|
return {
|
|
|
|
_id: doc._id,
|
|
|
|
title: doc.title,
|
|
|
|
};
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
catch (error) {
|
|
|
|
JsonRoutes.sendResult(res, {
|
|
|
|
code: 200,
|
|
|
|
data: error,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-10-26 07:27:24 +02:00
|
|
|
/**
|
|
|
|
* @operation get_swimlane
|
|
|
|
*
|
|
|
|
* @summary Get a swimlane
|
|
|
|
*
|
|
|
|
* @param {string} boardId the ID of the board
|
|
|
|
* @param {string} swimlaneId the ID of the swimlane
|
|
|
|
* @return_type Swimlanes
|
|
|
|
*/
|
2018-02-27 02:57:58 +01:00
|
|
|
JsonRoutes.add('GET', '/api/boards/:boardId/swimlanes/:swimlaneId', function (req, res) {
|
2018-01-19 12:22:03 -03:00
|
|
|
try {
|
|
|
|
const paramBoardId = req.params.boardId;
|
|
|
|
const paramSwimlaneId = req.params.swimlaneId;
|
|
|
|
Authentication.checkBoardAccess( req.userId, paramBoardId);
|
|
|
|
JsonRoutes.sendResult(res, {
|
|
|
|
code: 200,
|
|
|
|
data: Swimlanes.findOne({ _id: paramSwimlaneId, boardId: paramBoardId, archived: false }),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
catch (error) {
|
|
|
|
JsonRoutes.sendResult(res, {
|
|
|
|
code: 200,
|
|
|
|
data: error,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-10-26 07:27:24 +02:00
|
|
|
/**
|
|
|
|
* @operation new_swimlane
|
|
|
|
*
|
|
|
|
* @summary Add a swimlane to a board
|
|
|
|
*
|
|
|
|
* @param {string} boardId the ID of the board
|
|
|
|
* @param {string} title the new title of the swimlane
|
|
|
|
* @return_type {_id: string}
|
|
|
|
*/
|
2018-02-27 02:57:58 +01:00
|
|
|
JsonRoutes.add('POST', '/api/boards/:boardId/swimlanes', function (req, res) {
|
2018-01-19 12:22:03 -03:00
|
|
|
try {
|
|
|
|
Authentication.checkUserId( req.userId);
|
|
|
|
const paramBoardId = req.params.boardId;
|
2019-01-25 10:57:46 +01:00
|
|
|
const board = Boards.findOne(paramBoardId);
|
2018-01-19 12:22:03 -03:00
|
|
|
const id = Swimlanes.insert({
|
|
|
|
title: req.body.title,
|
|
|
|
boardId: paramBoardId,
|
2019-01-25 10:57:46 +01:00
|
|
|
sort: board.swimlanes().count(),
|
2018-01-19 12:22:03 -03:00
|
|
|
});
|
|
|
|
JsonRoutes.sendResult(res, {
|
|
|
|
code: 200,
|
|
|
|
data: {
|
|
|
|
_id: id,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
catch (error) {
|
|
|
|
JsonRoutes.sendResult(res, {
|
|
|
|
code: 200,
|
|
|
|
data: error,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-10-26 07:27:24 +02:00
|
|
|
/**
|
|
|
|
* @operation delete_swimlane
|
|
|
|
*
|
|
|
|
* @summary Delete a swimlane
|
|
|
|
*
|
|
|
|
* @description The swimlane will be deleted, not moved to the recycle bin
|
|
|
|
*
|
|
|
|
* @param {string} boardId the ID of the board
|
|
|
|
* @param {string} swimlaneId the ID of the swimlane
|
|
|
|
* @return_type {_id: string}
|
|
|
|
*/
|
2018-02-27 02:57:58 +01:00
|
|
|
JsonRoutes.add('DELETE', '/api/boards/:boardId/swimlanes/:swimlaneId', function (req, res) {
|
2018-01-19 12:22:03 -03:00
|
|
|
try {
|
|
|
|
Authentication.checkUserId( req.userId);
|
|
|
|
const paramBoardId = req.params.boardId;
|
|
|
|
const paramSwimlaneId = req.params.swimlaneId;
|
|
|
|
Swimlanes.remove({ _id: paramSwimlaneId, boardId: paramBoardId });
|
|
|
|
JsonRoutes.sendResult(res, {
|
|
|
|
code: 200,
|
|
|
|
data: {
|
|
|
|
_id: paramSwimlaneId,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
catch (error) {
|
|
|
|
JsonRoutes.sendResult(res, {
|
|
|
|
code: 200,
|
|
|
|
data: error,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|