summaryrefslogtreecommitdiffstats
path: root/models/swimlanes.js
diff options
context:
space:
mode:
Diffstat (limited to 'models/swimlanes.js')
-rw-r--r--models/swimlanes.js76
1 files changed, 76 insertions, 0 deletions
diff --git a/models/swimlanes.js b/models/swimlanes.js
index e2c3925c..9da4afb5 100644
--- a/models/swimlanes.js
+++ b/models/swimlanes.js
@@ -78,6 +78,13 @@ Swimlanes.attachSchema(new SimpleSchema({
}
},
},
+ type: {
+ /**
+ * The type of swimlane
+ */
+ type: String,
+ defaultValue: 'swimlane',
+ },
}));
Swimlanes.allow({
@@ -94,6 +101,30 @@ Swimlanes.allow({
});
Swimlanes.helpers({
+ copy(boardId) {
+ const oldId = this._id;
+ const oldBoardId = this.boardId;
+ this.boardId = boardId;
+ delete this._id;
+ const _id = Swimlanes.insert(this);
+
+ const query = {
+ swimlaneId: {$in: [oldId, '']},
+ archived: false,
+ };
+ if (oldBoardId) {
+ query.boardId = oldBoardId;
+ }
+
+ // Copy all lists in swimlane
+ Lists.find(query).forEach((list) => {
+ list.type = 'list';
+ list.swimlaneId = oldId;
+ list.boardId = boardId;
+ list.copy(boardId, _id);
+ });
+ },
+
cards() {
return Cards.find(Filter.mongoSelector({
swimlaneId: this._id,
@@ -101,6 +132,18 @@ Swimlanes.helpers({
}), { sort: ['sort'] });
},
+ lists() {
+ return Lists.find({
+ boardId: this.boardId,
+ swimlaneId: {$in: [this._id, '']},
+ archived: false,
+ }, { sort: ['sort'] });
+ },
+
+ myLists() {
+ return Lists.find({ swimlaneId: this._id });
+ },
+
allCards() {
return Cards.find({ swimlaneId: this._id });
},
@@ -114,6 +157,29 @@ Swimlanes.helpers({
return this.color;
return '';
},
+
+ isTemplateSwimlane() {
+ return this.type === 'template-swimlane';
+ },
+
+ isTemplateContainer() {
+ return this.type === 'template-container';
+ },
+
+ isListTemplatesSwimlane() {
+ const user = Users.findOne(Meteor.userId());
+ return user.profile.listTemplatesSwimlaneId === this._id;
+ },
+
+ isCardTemplatesSwimlane() {
+ const user = Users.findOne(Meteor.userId());
+ return user.profile.cardTemplatesSwimlaneId === this._id;
+ },
+
+ isBoardTemplatesSwimlane() {
+ const user = Users.findOne(Meteor.userId());
+ return user.profile.boardTemplatesSwimlaneId === this._id;
+ },
});
Swimlanes.mutations({
@@ -122,10 +188,20 @@ Swimlanes.mutations({
},
archive() {
+ if (this.isTemplateSwimlane()) {
+ this.myLists().forEach((list) => {
+ return list.archive();
+ });
+ }
return { $set: { archived: true } };
},
restore() {
+ if (this.isTemplateSwimlane()) {
+ this.myLists().forEach((list) => {
+ return list.restore();
+ });
+ }
return { $set: { archived: false } };
},