From c3037b155fc0de1ef44d1d1c1fc65c25790ca3ad Mon Sep 17 00:00:00 2001 From: Nicu Tofan Date: Sun, 17 Jun 2018 22:46:03 +0300 Subject: [PATCH 01/24] Added subtasks model and APIs for it --- .eslintrc.json | 1 + models/subtasks.js | 139 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 140 insertions(+) create mode 100644 models/subtasks.js diff --git a/.eslintrc.json b/.eslintrc.json index 255e00bad..1adaa6238 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -134,6 +134,7 @@ "Announcements": true, "Swimlanes": true, "ChecklistItems": true, + "Subtasks": true, "Npm": true } } diff --git a/models/subtasks.js b/models/subtasks.js new file mode 100644 index 000000000..6c42072e8 --- /dev/null +++ b/models/subtasks.js @@ -0,0 +1,139 @@ +Subtasks = new Mongo.Collection('subtasks'); + +Subtasks.attachSchema(new SimpleSchema({ + title: { + type: String, + }, + sort: { + type: Number, + decimal: true, + }, + isFinished: { + type: Boolean, + defaultValue: false, + }, + cardId: { + type: String, + }, +})); + +Subtasks.allow({ + insert(userId, doc) { + return allowIsBoardMemberByCard(userId, Cards.findOne(doc.cardId)); + }, + update(userId, doc) { + return allowIsBoardMemberByCard(userId, Cards.findOne(doc.cardId)); + }, + remove(userId, doc) { + return allowIsBoardMemberByCard(userId, Cards.findOne(doc.cardId)); + }, + fetch: ['userId', 'cardId'], +}); + +Subtasks.before.insert((userId, doc) => { + if (!doc.userId) { + doc.userId = userId; + } +}); + +// Mutations +Subtasks.mutations({ + setTitle(title) { + return { $set: { title } }; + }, + toggleItem() { + return { $set: { isFinished: !this.isFinished } }; + }, + move(sortIndex) { + const mutatedFields = { + sort: sortIndex, + }; + + return {$set: mutatedFields}; + }, +}); + +// Activities helper +function itemCreation(userId, doc) { + const card = Cards.findOne(doc.cardId); + const boardId = card.boardId; + Activities.insert({ + userId, + activityType: 'addSubtaskItem', + cardId: doc.cardId, + boardId, + subtaskItemId: doc._id, + }); +} + +function itemRemover(userId, doc) { + Activities.remove({ + subtaskItemId: doc._id, + }); +} + +// Activities +if (Meteor.isServer) { + Meteor.startup(() => { + Subtasks._collection._ensureIndex({ cardId: 1 }); + }); + + Subtasks.after.insert((userId, doc) => { + itemCreation(userId, doc); + }); + + Subtasks.after.remove((userId, doc) => { + itemRemover(userId, doc); + }); +} + +// APIs +if (Meteor.isServer) { + JsonRoutes.add('GET', '/api/boards/:boardId/cards/:cardId/subtasks/:itemId', function (req, res) { + Authentication.checkUserId( req.userId); + const paramItemId = req.params.itemId; + const subtaskItem = Subtasks.findOne({ _id: paramItemId }); + if (subtaskItem) { + JsonRoutes.sendResult(res, { + code: 200, + data: subtaskItem, + }); + } else { + JsonRoutes.sendResult(res, { + code: 500, + }); + } + }); + + JsonRoutes.add('PUT', '/api/boards/:boardId/cards/:cardId/subtasks/:itemId', function (req, res) { + Authentication.checkUserId( req.userId); + + const paramItemId = req.params.itemId; + + if (req.body.hasOwnProperty('isFinished')) { + Subtasks.direct.update({_id: paramItemId}, {$set: {isFinished: req.body.isFinished}}); + } + if (req.body.hasOwnProperty('title')) { + Subtasks.direct.update({_id: paramItemId}, {$set: {title: req.body.title}}); + } + + JsonRoutes.sendResult(res, { + code: 200, + data: { + _id: paramItemId, + }, + }); + }); + + JsonRoutes.add('DELETE', '/api/boards/:boardId/cards/:cardId/subtasks/:itemId', function (req, res) { + Authentication.checkUserId( req.userId); + const paramItemId = req.params.itemId; + Subtasks.direct.remove({ _id: paramItemId }); + JsonRoutes.sendResult(res, { + code: 200, + data: { + _id: paramItemId, + }, + }); + }); +} From b627ced605f0ab98eb2977420da954f31df4f592 Mon Sep 17 00:00:00 2001 From: Nicu Tofan Date: Sun, 17 Jun 2018 22:55:01 +0300 Subject: [PATCH 02/24] Some inspiration from checklists to subtasks --- models/subtasks.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/models/subtasks.js b/models/subtasks.js index 6c42072e8..e842d11d4 100644 --- a/models/subtasks.js +++ b/models/subtasks.js @@ -4,6 +4,29 @@ Subtasks.attachSchema(new SimpleSchema({ title: { type: String, }, + startAt: { // this is a predicted time + type: Date, + optional: true, + }, + endAt: { // this is a predicted time + type: Date, + optional: true, + }, + finishedAt: { // The date & time when it is marked as being done + type: Date, + optional: true, + }, + createdAt: { + type: Date, + denyUpdate: false, + autoValue() { // eslint-disable-line consistent-return + if (this.isInsert) { + return new Date(); + } else { + this.unset(); + } + }, + }, sort: { type: Number, decimal: true, @@ -17,6 +40,16 @@ Subtasks.attachSchema(new SimpleSchema({ }, })); +Subtasks.helpers({ + isFinished() { + return 0 !== this.itemCount() && this.itemCount() === this.finishedCount(); + }, + itemIndex(itemId) { + const items = self.findOne({_id : this._id}).items; + return _.pluck(items, '_id').indexOf(itemId); + }, +}); + Subtasks.allow({ insert(userId, doc) { return allowIsBoardMemberByCard(userId, Cards.findOne(doc.cardId)); @@ -31,6 +64,7 @@ Subtasks.allow({ }); Subtasks.before.insert((userId, doc) => { + doc.createdAt = new Date(); if (!doc.userId) { doc.userId = userId; } From d59583915cca24d53a11251c54ca7caf6b5edb4e Mon Sep 17 00:00:00 2001 From: Nicu Tofan Date: Mon, 18 Jun 2018 23:25:56 +0300 Subject: [PATCH 03/24] Initial implementation for subtasks --- client/components/cards/cardDetails.jade | 3 + client/components/cards/cardDetails.js | 56 +++++--- client/components/cards/checklists.jade | 5 +- client/components/cards/checklists.js | 4 +- client/components/cards/subtasks.jade | 96 +++++++++++++ client/components/cards/subtasks.js | 166 +++++++++++++++++++++++ client/components/cards/subtasks.styl | 139 +++++++++++++++++++ i18n/en.i18n.json | 5 + models/activities.js | 3 + models/cards.js | 24 ++++ models/export.js | 2 + models/subtasks.js | 8 +- server/publications/boards.js | 1 + 13 files changed, 478 insertions(+), 34 deletions(-) create mode 100644 client/components/cards/subtasks.jade create mode 100644 client/components/cards/subtasks.js create mode 100644 client/components/cards/subtasks.styl diff --git a/client/components/cards/cardDetails.jade b/client/components/cards/cardDetails.jade index aa4829a9b..bc0ce45c9 100644 --- a/client/components/cards/cardDetails.jade +++ b/client/components/cards/cardDetails.jade @@ -144,6 +144,9 @@ template(name="cardDetails") hr +checklists(cardId = _id) + hr + +subtasks(cardId = _id) + hr h3 i.fa.fa-paperclip diff --git a/client/components/cards/cardDetails.js b/client/components/cards/cardDetails.js index 72ed678b2..22dacb70a 100644 --- a/client/components/cards/cardDetails.js +++ b/client/components/cards/cardDetails.js @@ -364,6 +364,20 @@ BlazeComponent.extendComponent({ }, }).register('boardsAndLists'); +function cloneCheckList(_id, checklist) { + 'use strict'; + const checklistId = checklist._id; + checklist.cardId = _id; + checklist._id = null; + const newChecklistId = Checklists.insert(checklist); + ChecklistItems.find({checklistId}).forEach(function(item) { + item._id = null; + item.checklistId = newChecklistId; + item.cardId = _id; + ChecklistItems.insert(item); + }); +} + Template.copyCardPopup.events({ 'click .js-done'() { const card = Cards.findOne(Session.get('currentCard')); @@ -392,19 +406,18 @@ Template.copyCardPopup.events({ // copy checklists let cursor = Checklists.find({cardId: oldId}); + cursor.forEach(function() { + cloneCheckList(_id, arguments[0]); + }); + + // copy subtasks + cursor = Subtasks.find({cardId: oldId}); cursor.forEach(function() { 'use strict'; - const checklist = arguments[0]; - const checklistId = checklist._id; - checklist.cardId = _id; - checklist._id = null; - const newChecklistId = Checklists.insert(checklist); - ChecklistItems.find({checklistId}).forEach(function(item) { - item._id = null; - item.checklistId = newChecklistId; - item.cardId = _id; - ChecklistItems.insert(item); - }); + const subtask = arguments[0]; + subtask.cardId = _id; + subtask._id = null; + /* const newSubtaskId = */ Subtasks.insert(subtask); }); // copy card comments @@ -453,19 +466,18 @@ Template.copyChecklistToManyCardsPopup.events({ // copy checklists let cursor = Checklists.find({cardId: oldId}); + cursor.forEach(function() { + cloneCheckList(_id, arguments[0]); + }); + + // copy subtasks + cursor = Subtasks.find({cardId: oldId}); cursor.forEach(function() { 'use strict'; - const checklist = arguments[0]; - const checklistId = checklist._id; - checklist.cardId = _id; - checklist._id = null; - const newChecklistId = Checklists.insert(checklist); - ChecklistItems.find({checklistId}).forEach(function(item) { - item._id = null; - item.checklistId = newChecklistId; - item.cardId = _id; - ChecklistItems.insert(item); - }); + const subtask = arguments[0]; + subtask.cardId = _id; + subtask._id = null; + /* const newSubtaskId = */ Subtasks.insert(subtask); }); // copy card comments diff --git a/client/components/cards/checklists.jade b/client/components/cards/checklists.jade index ae680bd5d..7678f5240 100644 --- a/client/components/cards/checklists.jade +++ b/client/components/cards/checklists.jade @@ -27,7 +27,6 @@ template(name="checklistDetail") if canModifyCard a.js-delete-checklist.toggle-delete-checklist-dialog {{_ "delete"}}... - span.checklist-stat(class="{{#if checklist.isFinished}}is-finished{{/if}}") {{checklist.finishedCount}}/{{checklist.itemCount}} if canModifyCard h2.title.js-open-inlined-form.is-editable +viewer @@ -75,7 +74,7 @@ template(name="checklistItems") +inlinedForm(classNames="js-edit-checklist-item" item = item checklist = checklist) +editChecklistItemForm(type = 'item' item = item checklist = checklist) else - +itemDetail(item = item checklist = checklist) + +cjecklistItemDetail(item = item checklist = checklist) if canModifyCard +inlinedForm(autoclose=false classNames="js-add-checklist-item" checklist = checklist) +addChecklistItemForm @@ -84,7 +83,7 @@ template(name="checklistItems") i.fa.fa-plus | {{_ 'add-checklist-item'}}... -template(name='itemDetail') +template(name='cjecklistItemDetail') .js-checklist-item.checklist-item if canModifyCard .check-box.materialCheckBox(class="{{#if item.isFinished }}is-checked{{/if}}") diff --git a/client/components/cards/checklists.js b/client/components/cards/checklists.js index 1f05aded6..a62e493ec 100644 --- a/client/components/cards/checklists.js +++ b/client/components/cards/checklists.js @@ -204,7 +204,7 @@ Template.checklistDeleteDialog.onDestroyed(() => { $cardDetails.animate( { scrollTop: this.scrollState.position }); }); -Template.itemDetail.helpers({ +Template.cjecklistItemDetail.helpers({ canModifyCard() { return Meteor.user() && Meteor.user().isBoardMember() && !Meteor.user().isCommentOnly(); }, @@ -223,4 +223,4 @@ BlazeComponent.extendComponent({ 'click .js-checklist-item .check-box': this.toggleItem, }]; }, -}).register('itemDetail'); +}).register('cjecklistItemDetail'); diff --git a/client/components/cards/subtasks.jade b/client/components/cards/subtasks.jade new file mode 100644 index 000000000..378d7a46c --- /dev/null +++ b/client/components/cards/subtasks.jade @@ -0,0 +1,96 @@ +template(name="subtasks") + h3 {{_ 'subtasks'}} + if toggleDeleteDialog.get + .board-overlay#card-details-overlay + +subtaskDeleteDialog(subtasks = subtasksToDelete) + + + .card-subtasks-items + each subtasks in currentCard.subtasks + +subtasksDetail(subtasks = subtasks) + + if canModifyCard + +inlinedForm(autoclose=false classNames="js-add-subtask" cardId = cardId) + +addSubtaskItemForm + else + a.js-open-inlined-form + i.fa.fa-plus + | {{_ 'add-subtask'}}... + +template(name="subtasksDetail") + .js-subtasks.subtasks + +inlinedForm(classNames="js-edit-subtasks-title" subtasks = subtasks) + +editsubtasksItemForm(subtasks = subtasks) + else + .subtasks-title + span + if canModifyCard + a.js-delete-subtasks.toggle-delete-subtasks-dialog {{_ "delete"}}... + + if canModifyCard + h2.title.js-open-inlined-form.is-editable + +viewer + = subtasks.title + else + h2.title + +viewer + = subtasks.title + +template(name="subtaskDeleteDialog") + .js-confirm-subtasks-delete + p + i(class="fa fa-exclamation-triangle" aria-hidden="true") + p + | {{_ 'confirm-subtask-delete-dialog'}} + span {{subtasks.title}} + | ? + .js-subtasks-delete-buttons + button.confirm-subtasks-delete(type="button") {{_ 'delete'}} + button.toggle-delete-subtasks-dialog(type="button") {{_ 'cancel'}} + +template(name="addSubtaskItemForm") + textarea.js-add-subtask-item(rows='1' autofocus) + .edit-controls.clearfix + button.primary.confirm.js-submit-add-subtask-item-form(type="submit") {{_ 'save'}} + a.fa.fa-times-thin.js-close-inlined-form + +template(name="editsubtasksItemForm") + textarea.js-edit-subtasks-item(rows='1' autofocus) + if $eq type 'item' + = item.title + else + = subtasks.title + .edit-controls.clearfix + button.primary.confirm.js-submit-edit-subtasks-item-form(type="submit") {{_ 'save'}} + a.fa.fa-times-thin.js-close-inlined-form + span(title=createdAt) {{ moment createdAt }} + if canModifyCard + a.js-delete-subtasks-item {{_ "delete"}}... + +template(name="subtasksItems") + .subtasks-items.js-subtasks-items + each item in subtasks.items + +inlinedForm(classNames="js-edit-subtasks-item" item = item subtasks = subtasks) + +editsubtasksItemForm(type = 'item' item = item subtasks = subtasks) + else + +subtaskItemDetail(item = item subtasks = subtasks) + if canModifyCard + +inlinedForm(autoclose=false classNames="js-add-subtask-item" subtasks = subtasks) + +addSubtaskItemForm + else + a.add-subtask-item.js-open-inlined-form + i.fa.fa-plus + | {{_ 'add-subtask-item'}}... + +template(name='subtaskItemDetail') + .js-subtasks-item.subtasks-item + if canModifyCard + .check-box.materialCheckBox(class="{{#if item.isFinished }}is-checked{{/if}}") + .item-title.js-open-inlined-form.is-editable(class="{{#if item.isFinished }}is-checked{{/if}}") + +viewer + = item.title + else + .materialCheckBox(class="{{#if item.isFinished }}is-checked{{/if}}") + .item-title(class="{{#if item.isFinished }}is-checked{{/if}}") + +viewer + = item.title diff --git a/client/components/cards/subtasks.js b/client/components/cards/subtasks.js new file mode 100644 index 000000000..a611ae262 --- /dev/null +++ b/client/components/cards/subtasks.js @@ -0,0 +1,166 @@ +const { calculateIndexData } = Utils; + +function initSorting(items) { + items.sortable({ + tolerance: 'pointer', + helper: 'clone', + items: '.js-subtasks-item:not(.placeholder)', + connectWith: '.js-subtasks-items', + appendTo: '.board-canvas', + distance: 7, + placeholder: 'subtasks-item placeholder', + scroll: false, + start(evt, ui) { + ui.placeholder.height(ui.helper.height()); + EscapeActions.executeUpTo('popup-close'); + }, + stop(evt, ui) { + const parent = ui.item.parents('.js-subtasks-items'); + const subtasksId = Blaze.getData(parent.get(0)).subtasks._id; + let prevItem = ui.item.prev('.js-subtasks-item').get(0); + if (prevItem) { + prevItem = Blaze.getData(prevItem).item; + } + let nextItem = ui.item.next('.js-subtasks-item').get(0); + if (nextItem) { + nextItem = Blaze.getData(nextItem).item; + } + const nItems = 1; + const sortIndex = calculateIndexData(prevItem, nextItem, nItems); + const subtasksDomElement = ui.item.get(0); + const subtasksData = Blaze.getData(subtasksDomElement); + const subtasksItem = subtasksData.item; + + items.sortable('cancel'); + + subtasksItem.move(subtasksId, sortIndex.base); + }, + }); +} + +BlazeComponent.extendComponent({ + canModifyCard() { + return Meteor.user() && Meteor.user().isBoardMember() && !Meteor.user().isCommentOnly(); + }, +}).register('subtasksDetail'); + +BlazeComponent.extendComponent({ + + addSubtask(event) { + event.preventDefault(); + const textarea = this.find('textarea.js-add-subtask-item'); + const title = textarea.value.trim(); + const cardId = this.currentData().cardId; + const card = Cards.findOne(cardId); + + if (title) { + Subtasks.insert({ + cardId, + title, + sort: card.subtasks().count(), + }); + setTimeout(() => { + this.$('.add-subtask-item').last().click(); + }, 100); + } + textarea.value = ''; + textarea.focus(); + }, + + canModifyCard() { + return Meteor.user() && Meteor.user().isBoardMember() && !Meteor.user().isCommentOnly(); + }, + + deleteSubtask() { + const subtasks = this.currentData().subtasks; + if (subtasks && subtasks._id) { + Subtasks.remove(subtasks._id); + this.toggleDeleteDialog.set(false); + } + }, + + editSubtask(event) { + event.preventDefault(); + const textarea = this.find('textarea.js-edit-subtasks-item'); + const title = textarea.value.trim(); + const subtasks = this.currentData().subtasks; + subtasks.setTitle(title); + }, + + onCreated() { + this.toggleDeleteDialog = new ReactiveVar(false); + this.subtasksToDelete = null; //Store data context to pass to subtaskDeleteDialog template + }, + + pressKey(event) { + //If user press enter key inside a form, submit it + //Unless the user is also holding down the 'shift' key + if (event.keyCode === 13 && !event.shiftKey) { + event.preventDefault(); + const $form = $(event.currentTarget).closest('form'); + $form.find('button[type=submit]').click(); + } + }, + + events() { + const events = { + 'click .toggle-delete-subtasks-dialog'(event) { + if($(event.target).hasClass('js-delete-subtasks')){ + this.subtasksToDelete = this.currentData().subtasks; //Store data context + } + this.toggleDeleteDialog.set(!this.toggleDeleteDialog.get()); + }, + }; + + return [{ + ...events, + 'submit .js-add-subtask': this.addSubtask, + 'submit .js-edit-subtasks-title': this.editSubtask, + 'click .confirm-subtasks-delete': this.deleteSubtask, + keydown: this.pressKey, + }]; + }, +}).register('subtasks'); + +Template.subtaskDeleteDialog.onCreated(() => { + const $cardDetails = this.$('.card-details'); + this.scrollState = { position: $cardDetails.scrollTop(), //save current scroll position + top: false, //required for smooth scroll animation + }; + //Callback's purpose is to only prevent scrolling after animation is complete + $cardDetails.animate({ scrollTop: 0 }, 500, () => { this.scrollState.top = true; }); + + //Prevent scrolling while dialog is open + $cardDetails.on('scroll', () => { + if(this.scrollState.top) { //If it's already in position, keep it there. Otherwise let animation scroll + $cardDetails.scrollTop(0); + } + }); +}); + +Template.subtaskDeleteDialog.onDestroyed(() => { + const $cardDetails = this.$('.card-details'); + $cardDetails.off('scroll'); //Reactivate scrolling + $cardDetails.animate( { scrollTop: this.scrollState.position }); +}); + +Template.subtaskItemDetail.helpers({ + canModifyCard() { + return Meteor.user() && Meteor.user().isBoardMember() && !Meteor.user().isCommentOnly(); + }, +}); + +BlazeComponent.extendComponent({ + toggleItem() { + const subtasks = this.currentData().subtasks; + const item = this.currentData().item; + if (subtasks && item && item._id) { + item.toggleItem(); + } + }, + events() { + return [{ + 'click .js-subtasks-item .check-box': this.toggleItem, + }]; + }, +}).register('subtaskItemDetail'); diff --git a/client/components/cards/subtasks.styl b/client/components/cards/subtasks.styl new file mode 100644 index 000000000..2d18407c5 --- /dev/null +++ b/client/components/cards/subtasks.styl @@ -0,0 +1,139 @@ +.js-add-subtask + color: #8c8c8c + +textarea.js-add-subtask-item, textarea.js-edit-subtasks-item + overflow: hidden + word-wrap: break-word + resize: none + height: 34px + +.delete-text + color: #8c8c8c + text-decoration: underline + word-wrap: break-word + float: right + padding-top: 6px + &:hover + color: inherit + +.subtasks-title + .checkbox + float: left + width: 30px + height 30px + font-size: 18px + line-height: 30px + + .title + font-size: 18px + line-height: 25px + + .subtasks-stat + margin: 0 0.5em + float: right + padding-top: 6px + &.is-finished + color: #3cb500 + + .js-delete-subtasks + @extends .delete-text + + +.js-confirm-subtasks-delete + background-color: darken(white, 3%) + position: absolute + float: left; + width: 60% + margin-top: 0 + margin-left: 13% + padding-bottom: 2% + padding-left: 3% + padding-right: 3% + z-index: 17 + border-radius: 3px + + p + position: relative + margin-top: 3% + width: 100% + text-align: center + span + font-weight: bold + + i + font-size: 2em + + .js-subtasks-delete-buttons + position: relative + padding: left 2% right 2% + .confirm-subtasks-delete + margin-left: 12% + float: left + .toggle-delete-subtasks-dialog + margin-right: 12% + float: right + +#card-details-overlay + top: 0 + bottom: -600px + right: 0 + +.subtasks + background: darken(white, 3%) + + &.placeholder + background: darken(white, 20%) + border-radius: 2px + + &.ui-sortable-helper + box-shadow: -2px 2px 8px rgba(0, 0, 0, .3), + 0 0 1px rgba(0, 0, 0, .5) + transform: rotate(4deg) + cursor: grabbing + + +.subtasks-item + margin: 0 0 0 0.1em + line-height: 18px + font-size: 1.1em + margin-top: 3px + display: flex + background: darken(white, 3%) + + &.placeholder + background: darken(white, 20%) + border-radius: 2px + + &.ui-sortable-helper + box-shadow: -2px 2px 8px rgba(0, 0, 0, .3), + 0 0 1px rgba(0, 0, 0, .5) + transform: rotate(4deg) + cursor: grabbing + + &:hover + background-color: darken(white, 8%) + + .check-box + margin: 0.1em 0 0 0; + &.is-checked + border-bottom: 2px solid #3cb500 + border-right: 2px solid #3cb500 + + .item-title + flex: 1 + padding-left: 10px; + &.is-checked + color: #8c8c8c + font-style: italic + & .viewer + p + margin-bottom: 2px + +.js-delete-subtasks-item + margin: 0 0 0.5em 1.33em + @extends .delete-text + padding: 12px 0 0 0 + +.add-subtask-item + margin: 0.2em 0 0.5em 1.33em + display: inline-block diff --git a/i18n/en.i18n.json b/i18n/en.i18n.json index 83b5caed2..17d0ff715 100644 --- a/i18n/en.i18n.json +++ b/i18n/en.i18n.json @@ -2,6 +2,7 @@ "accept": "Accept", "act-activity-notify": "[Wekan] Activity Notification", "act-addAttachment": "attached __attachment__ to __card__", + "act-addSubtask": "added subtask __checklist__ to __card__", "act-addChecklist": "added checklist __checklist__ to __card__", "act-addChecklistItem": "added __checklistItem__ to checklist __checklist__ on __card__", "act-addComment": "commented on __card__: __comment__", @@ -41,6 +42,7 @@ "activity-removed": "removed %s from %s", "activity-sent": "sent %s to %s", "activity-unjoined": "unjoined %s", + "activity-subtask-added": "added subtask to %s", "activity-checklist-added": "added checklist to %s", "activity-checklist-item-added": "added checklist item to '%s' in %s", "add": "Add", @@ -48,6 +50,7 @@ "add-board": "Add Board", "add-card": "Add Card", "add-swimlane": "Add Swimlane", + "add-subtask": "Add Subtask", "add-checklist": "Add Checklist", "add-checklist-item": "Add an item to checklist", "add-cover": "Add Cover", @@ -140,6 +143,7 @@ "changePasswordPopup-title": "Change Password", "changePermissionsPopup-title": "Change Permissions", "changeSettingsPopup-title": "Change Settings", + "subtasks": "Subtasks", "checklists": "Checklists", "click-to-star": "Click to star this board.", "click-to-unstar": "Click to unstar this board.", @@ -162,6 +166,7 @@ "comment-only": "Comment only", "comment-only-desc": "Can comment on cards only.", "computer": "Computer", + "confirm-subtask-delete-dialog": "Are you sure you want to delete subtask", "confirm-checklist-delete-dialog": "Are you sure you want to delete checklist", "copy-card-link-to-clipboard": "Copy card link to clipboard", "copyCardPopup-title": "Copy Card", diff --git a/models/activities.js b/models/activities.js index f64b53f86..1ff0a2995 100644 --- a/models/activities.js +++ b/models/activities.js @@ -44,6 +44,9 @@ Activities.helpers({ checklistItem() { return ChecklistItems.findOne(this.checklistItemId); }, + subtasks() { + return Subtasks.findOne(this.subtaskId); + }, customField() { return CustomFields.findOne(this.customFieldId); }, diff --git a/models/cards.js b/models/cards.js index 00ec14c29..6edffb797 100644 --- a/models/cards.js +++ b/models/cards.js @@ -215,6 +215,27 @@ Cards.helpers({ return this.checklistItemCount() !== 0; }, + subtasks() { + return Subtasks.find({cardId: this._id}, {sort: { sort: 1 } }); + }, + + subtasksCount() { + return Subtasks.find({cardId: this._id}).count(); + }, + + subtasksFinishedCount() { + return Subtasks.find({cardId: this._id, isFinished: true}).count(); + }, + + subtasksFinished() { + const finishCount = this.subtasksFinishedCount(); + return finishCount > 0 && this.subtasksCount() === finishCount; + }, + + hasSubtasks() { + return this.subtasksCount() !== 0; + }, + customFieldIndex(customFieldId) { return _.pluck(this.customFields, '_id').indexOf(customFieldId); }, @@ -513,6 +534,9 @@ function cardRemover(userId, doc) { Checklists.remove({ cardId: doc._id, }); + Subtasks.remove({ + cardId: doc._id, + }); CardComments.remove({ cardId: doc._id, }); diff --git a/models/export.js b/models/export.js index aff66801d..778633f9b 100644 --- a/models/export.js +++ b/models/export.js @@ -58,9 +58,11 @@ class Exporter { result.activities = Activities.find(byBoard, noBoardId).fetch(); result.checklists = []; result.checklistItems = []; + result.subtaskItems = []; result.cards.forEach((card) => { result.checklists.push(...Checklists.find({ cardId: card._id }).fetch()); result.checklistItems.push(...ChecklistItems.find({ cardId: card._id }).fetch()); + result.subtaskItems.push(...Subtasks.find({ cardId: card._id }).fetch()); }); // [Old] for attachments we only export IDs and absolute url to original doc diff --git a/models/subtasks.js b/models/subtasks.js index e842d11d4..3f8b932c5 100644 --- a/models/subtasks.js +++ b/models/subtasks.js @@ -41,13 +41,7 @@ Subtasks.attachSchema(new SimpleSchema({ })); Subtasks.helpers({ - isFinished() { - return 0 !== this.itemCount() && this.itemCount() === this.finishedCount(); - }, - itemIndex(itemId) { - const items = self.findOne({_id : this._id}).items; - return _.pluck(items, '_id').indexOf(itemId); - }, + // ... }); Subtasks.allow({ diff --git a/server/publications/boards.js b/server/publications/boards.js index b52ac49fd..5b6bf139e 100644 --- a/server/publications/boards.js +++ b/server/publications/boards.js @@ -103,6 +103,7 @@ Meteor.publishRelations('board', function(boardId) { this.cursor(Attachments.find({ cardId })); this.cursor(Checklists.find({ cardId })); this.cursor(ChecklistItems.find({ cardId })); + this.cursor(Subtasks.find({ cardId })); }); if (board.members) { From 5f20e56721cd23ef6b65138f1b2aa074d7f830c6 Mon Sep 17 00:00:00 2001 From: Nicu Tofan Date: Mon, 18 Jun 2018 23:38:41 +0300 Subject: [PATCH 04/24] Remove leftovers from checklist conversion --- client/components/cards/subtasks.js | 53 +---------------------------- 1 file changed, 1 insertion(+), 52 deletions(-) diff --git a/client/components/cards/subtasks.js b/client/components/cards/subtasks.js index a611ae262..e65ef5185 100644 --- a/client/components/cards/subtasks.js +++ b/client/components/cards/subtasks.js @@ -1,43 +1,3 @@ -const { calculateIndexData } = Utils; - -function initSorting(items) { - items.sortable({ - tolerance: 'pointer', - helper: 'clone', - items: '.js-subtasks-item:not(.placeholder)', - connectWith: '.js-subtasks-items', - appendTo: '.board-canvas', - distance: 7, - placeholder: 'subtasks-item placeholder', - scroll: false, - start(evt, ui) { - ui.placeholder.height(ui.helper.height()); - EscapeActions.executeUpTo('popup-close'); - }, - stop(evt, ui) { - const parent = ui.item.parents('.js-subtasks-items'); - const subtasksId = Blaze.getData(parent.get(0)).subtasks._id; - let prevItem = ui.item.prev('.js-subtasks-item').get(0); - if (prevItem) { - prevItem = Blaze.getData(prevItem).item; - } - let nextItem = ui.item.next('.js-subtasks-item').get(0); - if (nextItem) { - nextItem = Blaze.getData(nextItem).item; - } - const nItems = 1; - const sortIndex = calculateIndexData(prevItem, nextItem, nItems); - const subtasksDomElement = ui.item.get(0); - const subtasksData = Blaze.getData(subtasksDomElement); - const subtasksItem = subtasksData.item; - - items.sortable('cancel'); - - subtasksItem.move(subtasksId, sortIndex.base); - }, - }); -} - BlazeComponent.extendComponent({ canModifyCard() { return Meteor.user() && Meteor.user().isBoardMember() && !Meteor.user().isCommentOnly(); @@ -151,16 +111,5 @@ Template.subtaskItemDetail.helpers({ }); BlazeComponent.extendComponent({ - toggleItem() { - const subtasks = this.currentData().subtasks; - const item = this.currentData().item; - if (subtasks && item && item._id) { - item.toggleItem(); - } - }, - events() { - return [{ - 'click .js-subtasks-item .check-box': this.toggleItem, - }]; - }, + // ... }).register('subtaskItemDetail'); From f89de026c414879bdb61a0f3117e92fde6acf5aa Mon Sep 17 00:00:00 2001 From: Nicu Tofan Date: Tue, 19 Jun 2018 00:25:43 +0300 Subject: [PATCH 05/24] Change order using drag-n-drop for subtasks --- client/components/cards/cardDetails.js | 38 +++++++++++++++++++++ client/components/cards/subtasks.jade | 46 +++++++++++++------------- client/components/cards/subtasks.js | 26 +++++++-------- client/components/cards/subtasks.styl | 16 ++++----- 4 files changed, 82 insertions(+), 44 deletions(-) diff --git a/client/components/cards/cardDetails.js b/client/components/cards/cardDetails.js index 22dacb70a..8d917830b 100644 --- a/client/components/cards/cardDetails.js +++ b/client/components/cards/cardDetails.js @@ -107,6 +107,41 @@ BlazeComponent.extendComponent({ }, }); + const $subtasksDom = this.$('.card-subtasks-items'); + + $subtasksDom.sortable({ + tolerance: 'pointer', + helper: 'clone', + handle: '.subtask-title', + items: '.js-subtasks', + placeholder: 'subtasks placeholder', + distance: 7, + start(evt, ui) { + ui.placeholder.height(ui.helper.height()); + EscapeActions.executeUpTo('popup-close'); + }, + stop(evt, ui) { + let prevChecklist = ui.item.prev('.js-subtasks').get(0); + if (prevChecklist) { + prevChecklist = Blaze.getData(prevChecklist).subtask; + } + let nextChecklist = ui.item.next('.js-subtasks').get(0); + if (nextChecklist) { + nextChecklist = Blaze.getData(nextChecklist).subtask; + } + const sortIndex = calculateIndexData(prevChecklist, nextChecklist, 1); + + $subtasksDom.sortable('cancel'); + const subtask = Blaze.getData(ui.item.get(0)).subtask; + + Subtasks.update(subtask._id, { + $set: { + sort: sortIndex.base, + }, + }); + }, + }); + function userIsMember() { return Meteor.user() && Meteor.user().isBoardMember(); } @@ -116,6 +151,9 @@ BlazeComponent.extendComponent({ if ($checklistsDom.data('sortable')) { $checklistsDom.sortable('option', 'disabled', !userIsMember()); } + if ($subtasksDom.data('sortable')) { + $subtasksDom.sortable('option', 'disabled', !userIsMember()); + } }); }, diff --git a/client/components/cards/subtasks.jade b/client/components/cards/subtasks.jade index 378d7a46c..5bf6c7cea 100644 --- a/client/components/cards/subtasks.jade +++ b/client/components/cards/subtasks.jade @@ -2,12 +2,12 @@ template(name="subtasks") h3 {{_ 'subtasks'}} if toggleDeleteDialog.get .board-overlay#card-details-overlay - +subtaskDeleteDialog(subtasks = subtasksToDelete) + +subtaskDeleteDialog(subtask = subtaskToDelete) .card-subtasks-items - each subtasks in currentCard.subtasks - +subtasksDetail(subtasks = subtasks) + each subtask in currentCard.subtasks + +subtaskDetail(subtask = subtask) if canModifyCard +inlinedForm(autoclose=false classNames="js-add-subtask" cardId = cardId) @@ -17,36 +17,36 @@ template(name="subtasks") i.fa.fa-plus | {{_ 'add-subtask'}}... -template(name="subtasksDetail") - .js-subtasks.subtasks - +inlinedForm(classNames="js-edit-subtasks-title" subtasks = subtasks) - +editsubtasksItemForm(subtasks = subtasks) +template(name="subtaskDetail") + .js-subtasks.subtask + +inlinedForm(classNames="js-edit-subtask-title" subtask = subtask) + +editSubtaskItemForm(subtask = subtask) else - .subtasks-title + .subtask-title span if canModifyCard - a.js-delete-subtasks.toggle-delete-subtasks-dialog {{_ "delete"}}... + a.js-delete-subtask.toggle-delete-subtask-dialog {{_ "delete"}}... if canModifyCard h2.title.js-open-inlined-form.is-editable +viewer - = subtasks.title + = subtask.title else h2.title +viewer - = subtasks.title + = subtask.title template(name="subtaskDeleteDialog") - .js-confirm-subtasks-delete + .js-confirm-subtask-delete p i(class="fa fa-exclamation-triangle" aria-hidden="true") p | {{_ 'confirm-subtask-delete-dialog'}} - span {{subtasks.title}} + span {{subtask.title}} | ? - .js-subtasks-delete-buttons - button.confirm-subtasks-delete(type="button") {{_ 'delete'}} - button.toggle-delete-subtasks-dialog(type="button") {{_ 'cancel'}} + .js-subtask-delete-buttons + button.confirm-subtask-delete(type="button") {{_ 'delete'}} + button.toggle-delete-subtask-dialog(type="button") {{_ 'cancel'}} template(name="addSubtaskItemForm") textarea.js-add-subtask-item(rows='1' autofocus) @@ -54,24 +54,24 @@ template(name="addSubtaskItemForm") button.primary.confirm.js-submit-add-subtask-item-form(type="submit") {{_ 'save'}} a.fa.fa-times-thin.js-close-inlined-form -template(name="editsubtasksItemForm") - textarea.js-edit-subtasks-item(rows='1' autofocus) +template(name="editSubtaskItemForm") + textarea.js-edit-subtask-item(rows='1' autofocus) if $eq type 'item' = item.title else - = subtasks.title + = subtask.title .edit-controls.clearfix - button.primary.confirm.js-submit-edit-subtasks-item-form(type="submit") {{_ 'save'}} + button.primary.confirm.js-submit-edit-subtask-item-form(type="submit") {{_ 'save'}} a.fa.fa-times-thin.js-close-inlined-form span(title=createdAt) {{ moment createdAt }} if canModifyCard - a.js-delete-subtasks-item {{_ "delete"}}... + a.js-delete-subtask-item {{_ "delete"}}... template(name="subtasksItems") .subtasks-items.js-subtasks-items each item in subtasks.items - +inlinedForm(classNames="js-edit-subtasks-item" item = item subtasks = subtasks) - +editsubtasksItemForm(type = 'item' item = item subtasks = subtasks) + +inlinedForm(classNames="js-edit-subtask-item" item = item subtasks = subtasks) + +editSubtaskItemForm(type = 'item' item = item subtasks = subtasks) else +subtaskItemDetail(item = item subtasks = subtasks) if canModifyCard diff --git a/client/components/cards/subtasks.js b/client/components/cards/subtasks.js index e65ef5185..dc6c607fa 100644 --- a/client/components/cards/subtasks.js +++ b/client/components/cards/subtasks.js @@ -2,7 +2,7 @@ BlazeComponent.extendComponent({ canModifyCard() { return Meteor.user() && Meteor.user().isBoardMember() && !Meteor.user().isCommentOnly(); }, -}).register('subtasksDetail'); +}).register('subtaskDetail'); BlazeComponent.extendComponent({ @@ -32,24 +32,24 @@ BlazeComponent.extendComponent({ }, deleteSubtask() { - const subtasks = this.currentData().subtasks; - if (subtasks && subtasks._id) { - Subtasks.remove(subtasks._id); + const subtask = this.currentData().subtask; + if (subtask && subtask._id) { + Subtasks.remove(subtask._id); this.toggleDeleteDialog.set(false); } }, editSubtask(event) { event.preventDefault(); - const textarea = this.find('textarea.js-edit-subtasks-item'); + const textarea = this.find('textarea.js-edit-subtask-item'); const title = textarea.value.trim(); - const subtasks = this.currentData().subtasks; - subtasks.setTitle(title); + const subtask = this.currentData().subtask; + subtask.setTitle(title); }, onCreated() { this.toggleDeleteDialog = new ReactiveVar(false); - this.subtasksToDelete = null; //Store data context to pass to subtaskDeleteDialog template + this.subtaskToDelete = null; //Store data context to pass to subtaskDeleteDialog template }, pressKey(event) { @@ -64,9 +64,9 @@ BlazeComponent.extendComponent({ events() { const events = { - 'click .toggle-delete-subtasks-dialog'(event) { - if($(event.target).hasClass('js-delete-subtasks')){ - this.subtasksToDelete = this.currentData().subtasks; //Store data context + 'click .toggle-delete-subtask-dialog'(event) { + if($(event.target).hasClass('js-delete-subtask')){ + this.subtaskToDelete = this.currentData().subtask; //Store data context } this.toggleDeleteDialog.set(!this.toggleDeleteDialog.get()); }, @@ -75,8 +75,8 @@ BlazeComponent.extendComponent({ return [{ ...events, 'submit .js-add-subtask': this.addSubtask, - 'submit .js-edit-subtasks-title': this.editSubtask, - 'click .confirm-subtasks-delete': this.deleteSubtask, + 'submit .js-edit-subtask-title': this.editSubtask, + 'click .confirm-subtask-delete': this.deleteSubtask, keydown: this.pressKey, }]; }, diff --git a/client/components/cards/subtasks.styl b/client/components/cards/subtasks.styl index 2d18407c5..5bb2d4bd0 100644 --- a/client/components/cards/subtasks.styl +++ b/client/components/cards/subtasks.styl @@ -1,7 +1,7 @@ .js-add-subtask color: #8c8c8c -textarea.js-add-subtask-item, textarea.js-edit-subtasks-item +textarea.js-add-subtask-item, textarea.js-edit-subtask-item overflow: hidden word-wrap: break-word resize: none @@ -16,7 +16,7 @@ textarea.js-add-subtask-item, textarea.js-edit-subtasks-item &:hover color: inherit -.subtasks-title +.subtask-title .checkbox float: left width: 30px @@ -35,11 +35,11 @@ textarea.js-add-subtask-item, textarea.js-edit-subtasks-item &.is-finished color: #3cb500 - .js-delete-subtasks + .js-delete-subtask @extends .delete-text -.js-confirm-subtasks-delete +.js-confirm-subtask-delete background-color: darken(white, 3%) position: absolute float: left; @@ -63,13 +63,13 @@ textarea.js-add-subtask-item, textarea.js-edit-subtasks-item i font-size: 2em - .js-subtasks-delete-buttons + .js-subtask-delete-buttons position: relative padding: left 2% right 2% - .confirm-subtasks-delete + .confirm-subtask-delete margin-left: 12% float: left - .toggle-delete-subtasks-dialog + .toggle-delete-subtask-dialog margin-right: 12% float: right @@ -129,7 +129,7 @@ textarea.js-add-subtask-item, textarea.js-edit-subtasks-item p margin-bottom: 2px -.js-delete-subtasks-item +.js-delete-subtask-item margin: 0 0 0.5em 1.33em @extends .delete-text padding: 12px 0 0 0 From 879a84184ff2f9b8719f5ac1e25d35e0fa5f52fb Mon Sep 17 00:00:00 2001 From: Nicu Tofan Date: Tue, 19 Jun 2018 00:42:54 +0300 Subject: [PATCH 06/24] added ability to create a tree of cards --- models/cards.js | 5 +++++ server/migrations.js | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/models/cards.js b/models/cards.js index 6edffb797..c5d7cdf9a 100644 --- a/models/cards.js +++ b/models/cards.js @@ -15,6 +15,11 @@ Cards.attachSchema(new SimpleSchema({ } }, }, + parentId: { + type: String, + optional: true, + defaultValue: '', + }, listId: { type: String, }, diff --git a/server/migrations.js b/server/migrations.js index a1a5c65a1..a32c2f2d0 100644 --- a/server/migrations.js +++ b/server/migrations.js @@ -258,3 +258,15 @@ Migrations.add('add-assigner-field', () => { }, noValidateMulti); }); + +Migrations.add('add-parent-field-to-cards', () => { + Cards.update({ + parentId: { + $exists: false, + }, + }, { + $set: { + parentId:'', + }, + }, noValidateMulti); +}); From fd465fbb60bd92c169991e050b094904c2eec95e Mon Sep 17 00:00:00 2001 From: Nicu Tofan Date: Tue, 19 Jun 2018 01:00:14 +0300 Subject: [PATCH 07/24] Helpers for dealing with trees of cards --- models/cards.js | 19 +++++++++++++++++++ server/migrations.js | 1 - 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/models/cards.js b/models/cards.js index c5d7cdf9a..1e0015015 100644 --- a/models/cards.js +++ b/models/cards.js @@ -297,14 +297,33 @@ Cards.helpers({ } return true; }, + + parentCard() { + if (this.parentId === '') { + return null; + } + return Cards.findOne(this.parentId); + }, + + isTopLevel() { + return this.parentId === ''; + }, }); Cards.mutations({ + applyToKids(funct) { + Cards.find({ parentId: this._id }).forEach((card) => { + funct(card); + }); + }, + archive() { + this.applyToKids((card) => { return card.archive(); }); return {$set: {archived: true}}; }, restore() { + this.applyToKids((card) => { return card.restore(); }); return {$set: {archived: false}}; }, diff --git a/server/migrations.js b/server/migrations.js index a32c2f2d0..cfc0d5ab9 100644 --- a/server/migrations.js +++ b/server/migrations.js @@ -258,7 +258,6 @@ Migrations.add('add-assigner-field', () => { }, noValidateMulti); }); - Migrations.add('add-parent-field-to-cards', () => { Cards.update({ parentId: { From adb7f5b2ca9e8394db314f7ff97d0d0f811c51c0 Mon Sep 17 00:00:00 2001 From: Nicu Tofan Date: Sat, 23 Jun 2018 17:40:53 +0300 Subject: [PATCH 08/24] Switch from subtasks to cards in model --- models/cards.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/models/cards.js b/models/cards.js index 1e0015015..8cf0ef657 100644 --- a/models/cards.js +++ b/models/cards.js @@ -221,15 +221,15 @@ Cards.helpers({ }, subtasks() { - return Subtasks.find({cardId: this._id}, {sort: { sort: 1 } }); + return Cards.find({parentId: this._id}, {sort: { sort: 1 } }); }, subtasksCount() { - return Subtasks.find({cardId: this._id}).count(); + return Cards.find({parentId: this._id}).count(); }, subtasksFinishedCount() { - return Subtasks.find({cardId: this._id, isFinished: true}).count(); + return Cards.find({parentId: this._id, archived: true}).count(); }, subtasksFinished() { From 5a023e431504f7573723db6e0d2262ecb1fc61c5 Mon Sep 17 00:00:00 2001 From: Nicu Tofan Date: Sat, 23 Jun 2018 23:22:38 +0300 Subject: [PATCH 09/24] Can add cards as subtasks --- client/components/cards/subtasks.js | 26 +++++++++++--- i18n/en.i18n.json | 4 ++- models/boards.js | 54 +++++++++++++++++++++++++++++ server/migrations.js | 13 +++++++ 4 files changed, 92 insertions(+), 5 deletions(-) diff --git a/client/components/cards/subtasks.js b/client/components/cards/subtasks.js index dc6c607fa..0df5d21fb 100644 --- a/client/components/cards/subtasks.js +++ b/client/components/cards/subtasks.js @@ -12,13 +12,31 @@ BlazeComponent.extendComponent({ const title = textarea.value.trim(); const cardId = this.currentData().cardId; const card = Cards.findOne(cardId); + const sortIndex = -1; + const crtBoard = Boards.findOne(card.boardId); + const targetBoard = crtBoard.getDefaultSubtasksBoard(); + const listId = targetBoard.getDefaultSubtasksListId(); + const swimlaneId = Swimlanes.findOne({boardId: targetBoard._id})._id; if (title) { - Subtasks.insert({ - cardId, + const _id = Cards.insert({ title, - sort: card.subtasks().count(), + parentId: cardId, + members: [], + labelIds: [], + customFields: [], + listId, + boardId: targetBoard._id, + sort: sortIndex, + swimlaneId, }); + // In case the filter is active we need to add the newly inserted card in + // the list of exceptions -- cards that are not filtered. Otherwise the + // card will disappear instantly. + // See https://github.com/wekan/wekan/issues/80 + Filter.addException(_id); + + setTimeout(() => { this.$('.add-subtask-item').last().click(); }, 100); @@ -34,7 +52,7 @@ BlazeComponent.extendComponent({ deleteSubtask() { const subtask = this.currentData().subtask; if (subtask && subtask._id) { - Subtasks.remove(subtask._id); + Cards.remove(subtask._id); this.toggleDeleteDialog.set(false); } }, diff --git a/i18n/en.i18n.json b/i18n/en.i18n.json index 17d0ff715..3a87179a6 100644 --- a/i18n/en.i18n.json +++ b/i18n/en.i18n.json @@ -479,5 +479,7 @@ "board-delete-notice": "Deleting is permanent. You will lose all lists, cards and actions associated with this board.", "delete-board-confirm-popup": "All lists, cards, labels, and activities will be deleted and you won't be able to recover the board contents. There is no undo.", "boardDeletePopup-title": "Delete Board?", - "delete-board": "Delete Board" + "delete-board": "Delete Board", + "default-subtasks-board": "Subtasks for __board__ board", + "default": "Default" } diff --git a/models/boards.js b/models/boards.js index 911d82a17..6836a3208 100644 --- a/models/boards.js +++ b/models/boards.js @@ -151,6 +151,16 @@ Boards.attachSchema(new SimpleSchema({ type: String, optional: true, }, + subtasksDefaultBoardId: { + type: String, + optional: true, + defaultValue: null, + }, + subtasksDefaultListId: { + type: String, + optional: true, + defaultValue: null, + }, })); @@ -284,8 +294,52 @@ Boards.helpers({ return Cards.find(query, projection); }, + // A board alwasy has another board where it deposits subtasks of thasks + // that belong to itself. + getDefaultSubtasksBoardId() { + if (this.subtasksDefaultBoardId === null) { + this.subtasksDefaultBoardId = Boards.insert({ + title: `^${this.title}^`, + permission: this.permission, + members: this.members, + color: this.color, + description: TAPi18n.__('default-subtasks-board', {board: this.title}), + }); + + Swimlanes.insert({ + title: TAPi18n.__('default'), + boardId: this.subtasksDefaultBoardId, + }); + Boards.update(this._id, {$set: { + subtasksDefaultBoardId: this.subtasksDefaultBoardId, + }}); + } + return this.subtasksDefaultBoardId; + }, + + getDefaultSubtasksBoard() { + return Boards.findOne(this.getDefaultSubtasksBoardId()); + }, + + getDefaultSubtasksListId() { + if (this.subtasksDefaultListId === null) { + this.subtasksDefaultListId = Lists.insert({ + title: TAPi18n.__('new'), + boardId: this._id, + }); + Boards.update(this._id, {$set: { + subtasksDefaultListId: this.subtasksDefaultListId, + }}); + } + return this.subtasksDefaultListId; + }, + + getDefaultSubtasksList() { + return Lists.findOne(this.getDefaultSubtasksListId()); + }, }); + Boards.mutations({ archive() { return { $set: { archived: true } }; diff --git a/server/migrations.js b/server/migrations.js index cfc0d5ab9..3ab3070d7 100644 --- a/server/migrations.js +++ b/server/migrations.js @@ -269,3 +269,16 @@ Migrations.add('add-parent-field-to-cards', () => { }, }, noValidateMulti); }); + +Migrations.add('add-subtasks-boards', () => { + Boards.update({ + subtasksDefaultBoardId: { + $exists: false, + }, + }, { + $set: { + subtasksDefaultBoardId: null, + subtasksDefaultListId: null, + }, + }, noValidateMulti); +}); From 6ab1cbb341da44cbaffc296ea177a8cd146e5244 Mon Sep 17 00:00:00 2001 From: Nicu Tofan Date: Sat, 23 Jun 2018 23:31:44 +0300 Subject: [PATCH 10/24] Take archived status into consideration for subtasks --- models/cards.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/models/cards.js b/models/cards.js index 8cf0ef657..ca0e16be1 100644 --- a/models/cards.js +++ b/models/cards.js @@ -221,15 +221,30 @@ Cards.helpers({ }, subtasks() { - return Cards.find({parentId: this._id}, {sort: { sort: 1 } }); + return Cards.find({ + parentId: this._id, + archived: false, + }, {sort: { sort: 1 } }); + }, + + allSubtasks() { + return Cards.find({ + parentId: this._id, + archived: false, + }, {sort: { sort: 1 } }); }, subtasksCount() { - return Cards.find({parentId: this._id}).count(); + return Cards.find({ + parentId: this._id, + archived: false, + }).count(); }, subtasksFinishedCount() { - return Cards.find({parentId: this._id, archived: true}).count(); + return Cards.find({ + parentId: this._id, + archived: true}).count(); }, subtasksFinished() { From cd36194477593f12103bc3d69e3cdd594c831099 Mon Sep 17 00:00:00 2001 From: Nicu Tofan Date: Sat, 23 Jun 2018 23:44:45 +0300 Subject: [PATCH 11/24] Archive subtask instead of permanent delete --- client/components/cards/subtasks.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/components/cards/subtasks.js b/client/components/cards/subtasks.js index 0df5d21fb..9a6666a3f 100644 --- a/client/components/cards/subtasks.js +++ b/client/components/cards/subtasks.js @@ -52,7 +52,7 @@ BlazeComponent.extendComponent({ deleteSubtask() { const subtask = this.currentData().subtask; if (subtask && subtask._id) { - Cards.remove(subtask._id); + subtask.archive(); this.toggleDeleteDialog.set(false); } }, From 4ac6a507cdd3e7a4610c8961e0a9f76f945a5e6d Mon Sep 17 00:00:00 2001 From: Nicu Tofan Date: Sun, 24 Jun 2018 00:21:23 +0300 Subject: [PATCH 12/24] Get rid of old implementation for substacks --- client/components/cards/cardDetails.js | 14 +-- models/activities.js | 2 +- models/cards.js | 6 + models/export.js | 2 +- models/subtasks.js | 167 ------------------------- server/migrations.js | 13 ++ server/publications/boards.js | 2 +- 7 files changed, 29 insertions(+), 177 deletions(-) delete mode 100644 models/subtasks.js diff --git a/client/components/cards/cardDetails.js b/client/components/cards/cardDetails.js index 8d917830b..4731e448f 100644 --- a/client/components/cards/cardDetails.js +++ b/client/components/cards/cardDetails.js @@ -136,7 +136,7 @@ BlazeComponent.extendComponent({ Subtasks.update(subtask._id, { $set: { - sort: sortIndex.base, + subtaskSort: sortIndex.base, }, }); }, @@ -449,13 +449,13 @@ Template.copyCardPopup.events({ }); // copy subtasks - cursor = Subtasks.find({cardId: oldId}); + cursor = Cards.find({parentId: oldId}); cursor.forEach(function() { 'use strict'; const subtask = arguments[0]; - subtask.cardId = _id; + subtask.parentId = _id; subtask._id = null; - /* const newSubtaskId = */ Subtasks.insert(subtask); + /* const newSubtaskId = */ Cards.insert(subtask); }); // copy card comments @@ -509,13 +509,13 @@ Template.copyChecklistToManyCardsPopup.events({ }); // copy subtasks - cursor = Subtasks.find({cardId: oldId}); + cursor = Cards.find({parentId: oldId}); cursor.forEach(function() { 'use strict'; const subtask = arguments[0]; - subtask.cardId = _id; + subtask.parentId = _id; subtask._id = null; - /* const newSubtaskId = */ Subtasks.insert(subtask); + /* const newSubtaskId = */ Cards.insert(subtask); }); // copy card comments diff --git a/models/activities.js b/models/activities.js index 1ff0a2995..5b54759c9 100644 --- a/models/activities.js +++ b/models/activities.js @@ -45,7 +45,7 @@ Activities.helpers({ return ChecklistItems.findOne(this.checklistItemId); }, subtasks() { - return Subtasks.findOne(this.subtaskId); + return Cards.findOne(this.subtaskId); }, customField() { return CustomFields.findOne(this.customFieldId); diff --git a/models/cards.js b/models/cards.js index ca0e16be1..4ec3ea7ce 100644 --- a/models/cards.js +++ b/models/cards.js @@ -127,6 +127,12 @@ Cards.attachSchema(new SimpleSchema({ type: Number, decimal: true, }, + subtaskSort: { + type: Number, + decimal: true, + defaultValue: -1, + optional: true, + }, })); Cards.allow({ diff --git a/models/export.js b/models/export.js index 778633f9b..8c4c29d48 100644 --- a/models/export.js +++ b/models/export.js @@ -62,7 +62,7 @@ class Exporter { result.cards.forEach((card) => { result.checklists.push(...Checklists.find({ cardId: card._id }).fetch()); result.checklistItems.push(...ChecklistItems.find({ cardId: card._id }).fetch()); - result.subtaskItems.push(...Subtasks.find({ cardId: card._id }).fetch()); + result.subtaskItems.push(...Cards.find({ parentid: card._id }).fetch()); }); // [Old] for attachments we only export IDs and absolute url to original doc diff --git a/models/subtasks.js b/models/subtasks.js deleted file mode 100644 index 3f8b932c5..000000000 --- a/models/subtasks.js +++ /dev/null @@ -1,167 +0,0 @@ -Subtasks = new Mongo.Collection('subtasks'); - -Subtasks.attachSchema(new SimpleSchema({ - title: { - type: String, - }, - startAt: { // this is a predicted time - type: Date, - optional: true, - }, - endAt: { // this is a predicted time - type: Date, - optional: true, - }, - finishedAt: { // The date & time when it is marked as being done - type: Date, - optional: true, - }, - createdAt: { - type: Date, - denyUpdate: false, - autoValue() { // eslint-disable-line consistent-return - if (this.isInsert) { - return new Date(); - } else { - this.unset(); - } - }, - }, - sort: { - type: Number, - decimal: true, - }, - isFinished: { - type: Boolean, - defaultValue: false, - }, - cardId: { - type: String, - }, -})); - -Subtasks.helpers({ - // ... -}); - -Subtasks.allow({ - insert(userId, doc) { - return allowIsBoardMemberByCard(userId, Cards.findOne(doc.cardId)); - }, - update(userId, doc) { - return allowIsBoardMemberByCard(userId, Cards.findOne(doc.cardId)); - }, - remove(userId, doc) { - return allowIsBoardMemberByCard(userId, Cards.findOne(doc.cardId)); - }, - fetch: ['userId', 'cardId'], -}); - -Subtasks.before.insert((userId, doc) => { - doc.createdAt = new Date(); - if (!doc.userId) { - doc.userId = userId; - } -}); - -// Mutations -Subtasks.mutations({ - setTitle(title) { - return { $set: { title } }; - }, - toggleItem() { - return { $set: { isFinished: !this.isFinished } }; - }, - move(sortIndex) { - const mutatedFields = { - sort: sortIndex, - }; - - return {$set: mutatedFields}; - }, -}); - -// Activities helper -function itemCreation(userId, doc) { - const card = Cards.findOne(doc.cardId); - const boardId = card.boardId; - Activities.insert({ - userId, - activityType: 'addSubtaskItem', - cardId: doc.cardId, - boardId, - subtaskItemId: doc._id, - }); -} - -function itemRemover(userId, doc) { - Activities.remove({ - subtaskItemId: doc._id, - }); -} - -// Activities -if (Meteor.isServer) { - Meteor.startup(() => { - Subtasks._collection._ensureIndex({ cardId: 1 }); - }); - - Subtasks.after.insert((userId, doc) => { - itemCreation(userId, doc); - }); - - Subtasks.after.remove((userId, doc) => { - itemRemover(userId, doc); - }); -} - -// APIs -if (Meteor.isServer) { - JsonRoutes.add('GET', '/api/boards/:boardId/cards/:cardId/subtasks/:itemId', function (req, res) { - Authentication.checkUserId( req.userId); - const paramItemId = req.params.itemId; - const subtaskItem = Subtasks.findOne({ _id: paramItemId }); - if (subtaskItem) { - JsonRoutes.sendResult(res, { - code: 200, - data: subtaskItem, - }); - } else { - JsonRoutes.sendResult(res, { - code: 500, - }); - } - }); - - JsonRoutes.add('PUT', '/api/boards/:boardId/cards/:cardId/subtasks/:itemId', function (req, res) { - Authentication.checkUserId( req.userId); - - const paramItemId = req.params.itemId; - - if (req.body.hasOwnProperty('isFinished')) { - Subtasks.direct.update({_id: paramItemId}, {$set: {isFinished: req.body.isFinished}}); - } - if (req.body.hasOwnProperty('title')) { - Subtasks.direct.update({_id: paramItemId}, {$set: {title: req.body.title}}); - } - - JsonRoutes.sendResult(res, { - code: 200, - data: { - _id: paramItemId, - }, - }); - }); - - JsonRoutes.add('DELETE', '/api/boards/:boardId/cards/:cardId/subtasks/:itemId', function (req, res) { - Authentication.checkUserId( req.userId); - const paramItemId = req.params.itemId; - Subtasks.direct.remove({ _id: paramItemId }); - JsonRoutes.sendResult(res, { - code: 200, - data: { - _id: paramItemId, - }, - }); - }); -} diff --git a/server/migrations.js b/server/migrations.js index 3ab3070d7..c49581f50 100644 --- a/server/migrations.js +++ b/server/migrations.js @@ -282,3 +282,16 @@ Migrations.add('add-subtasks-boards', () => { }, }, noValidateMulti); }); + +Migrations.add('add-subtasks-sort', () => { + Boards.update({ + subtaskSort: { + $exists: false, + }, + }, { + $set: { + subtaskSort: -1, + }, + }, noValidateMulti); +}); + diff --git a/server/publications/boards.js b/server/publications/boards.js index 5b6bf139e..5d095c172 100644 --- a/server/publications/boards.js +++ b/server/publications/boards.js @@ -103,7 +103,7 @@ Meteor.publishRelations('board', function(boardId) { this.cursor(Attachments.find({ cardId })); this.cursor(Checklists.find({ cardId })); this.cursor(ChecklistItems.find({ cardId })); - this.cursor(Subtasks.find({ cardId })); + this.cursor(Cards.find({ parentId: cardId })); }); if (board.members) { From 989b026b33508feaa6ba806a624b95a93298327c Mon Sep 17 00:00:00 2001 From: Nicu Tofan Date: Sun, 24 Jun 2018 10:44:09 +0300 Subject: [PATCH 13/24] Can now navigate to subtask --- client/components/cards/subtasks.jade | 1 + client/components/cards/subtasks.js | 11 +++++++++++ client/components/cards/subtasks.styl | 3 +++ 3 files changed, 15 insertions(+) diff --git a/client/components/cards/subtasks.jade b/client/components/cards/subtasks.jade index 5bf6c7cea..b0ef2f332 100644 --- a/client/components/cards/subtasks.jade +++ b/client/components/cards/subtasks.jade @@ -24,6 +24,7 @@ template(name="subtaskDetail") else .subtask-title span + a.js-view-subtask(title="{{ subtask.title }}") {{_ "view-it"}} if canModifyCard a.js-delete-subtask.toggle-delete-subtask-dialog {{_ "delete"}}... diff --git a/client/components/cards/subtasks.js b/client/components/cards/subtasks.js index 9a6666a3f..087824f75 100644 --- a/client/components/cards/subtasks.js +++ b/client/components/cards/subtasks.js @@ -88,6 +88,17 @@ BlazeComponent.extendComponent({ } this.toggleDeleteDialog.set(!this.toggleDeleteDialog.get()); }, + 'click .js-view-subtask'(event) { + if($(event.target).hasClass('js-view-subtask')){ + const subtask = this.currentData().subtask; + const board = subtask.board(); + FlowRouter.go('card', { + boardId: board._id, + slug: board.slug, + cardId: subtask._id, + }); + } + }, }; return [{ diff --git a/client/components/cards/subtasks.styl b/client/components/cards/subtasks.styl index 5bb2d4bd0..c2f09aa13 100644 --- a/client/components/cards/subtasks.styl +++ b/client/components/cards/subtasks.styl @@ -37,7 +37,10 @@ textarea.js-add-subtask-item, textarea.js-edit-subtask-item .js-delete-subtask @extends .delete-text + margin: 0 0.5em + .js-view-subtask + @extends .delete-text .js-confirm-subtask-delete background-color: darken(white, 3%) From 50f170b75d9d149bd333091fb5f7ba150c245b15 Mon Sep 17 00:00:00 2001 From: Nicu Tofan Date: Sun, 24 Jun 2018 10:59:48 +0300 Subject: [PATCH 14/24] A better name for incoming subtasks --- i18n/en.i18n.json | 3 ++- models/boards.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/i18n/en.i18n.json b/i18n/en.i18n.json index 3a87179a6..5e1a99e8b 100644 --- a/i18n/en.i18n.json +++ b/i18n/en.i18n.json @@ -481,5 +481,6 @@ "boardDeletePopup-title": "Delete Board?", "delete-board": "Delete Board", "default-subtasks-board": "Subtasks for __board__ board", - "default": "Default" + "default": "Default", + "queue": "Queue" } diff --git a/models/boards.js b/models/boards.js index 6836a3208..6f0f72939 100644 --- a/models/boards.js +++ b/models/boards.js @@ -324,7 +324,7 @@ Boards.helpers({ getDefaultSubtasksListId() { if (this.subtasksDefaultListId === null) { this.subtasksDefaultListId = Lists.insert({ - title: TAPi18n.__('new'), + title: TAPi18n.__('queue'), boardId: this._id, }); Boards.update(this._id, {$set: { From a0c02f4a5008f9ce47a4dac811aad7efdef5cc21 Mon Sep 17 00:00:00 2001 From: Nicu Tofan Date: Sun, 24 Jun 2018 17:42:58 +0300 Subject: [PATCH 15/24] typo in renaming itemDetail to checklistItemDetail --- client/components/cards/checklists.jade | 4 ++-- client/components/cards/checklists.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/client/components/cards/checklists.jade b/client/components/cards/checklists.jade index 7678f5240..e45e7ad97 100644 --- a/client/components/cards/checklists.jade +++ b/client/components/cards/checklists.jade @@ -74,7 +74,7 @@ template(name="checklistItems") +inlinedForm(classNames="js-edit-checklist-item" item = item checklist = checklist) +editChecklistItemForm(type = 'item' item = item checklist = checklist) else - +cjecklistItemDetail(item = item checklist = checklist) + +checklistItemDetail(item = item checklist = checklist) if canModifyCard +inlinedForm(autoclose=false classNames="js-add-checklist-item" checklist = checklist) +addChecklistItemForm @@ -83,7 +83,7 @@ template(name="checklistItems") i.fa.fa-plus | {{_ 'add-checklist-item'}}... -template(name='cjecklistItemDetail') +template(name='checklistItemDetail') .js-checklist-item.checklist-item if canModifyCard .check-box.materialCheckBox(class="{{#if item.isFinished }}is-checked{{/if}}") diff --git a/client/components/cards/checklists.js b/client/components/cards/checklists.js index a62e493ec..519af629e 100644 --- a/client/components/cards/checklists.js +++ b/client/components/cards/checklists.js @@ -204,7 +204,7 @@ Template.checklistDeleteDialog.onDestroyed(() => { $cardDetails.animate( { scrollTop: this.scrollState.position }); }); -Template.cjecklistItemDetail.helpers({ +Template.checklistItemDetail.helpers({ canModifyCard() { return Meteor.user() && Meteor.user().isBoardMember() && !Meteor.user().isCommentOnly(); }, @@ -223,4 +223,4 @@ BlazeComponent.extendComponent({ 'click .js-checklist-item .check-box': this.toggleItem, }]; }, -}).register('cjecklistItemDetail'); +}).register('checklistItemDetail'); From aead18eb58e230ed06ac090f7ea36c64fd597992 Mon Sep 17 00:00:00 2001 From: Nicu Tofan Date: Sun, 24 Jun 2018 17:47:57 +0300 Subject: [PATCH 16/24] change all mentions of Kids => Children --- models/cards.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/models/cards.js b/models/cards.js index 4ec3ea7ce..2563fdf85 100644 --- a/models/cards.js +++ b/models/cards.js @@ -332,19 +332,19 @@ Cards.helpers({ }); Cards.mutations({ - applyToKids(funct) { + applyToChildren(funct) { Cards.find({ parentId: this._id }).forEach((card) => { funct(card); }); }, archive() { - this.applyToKids((card) => { return card.archive(); }); + this.applyToChildren((card) => { return card.archive(); }); return {$set: {archived: true}}; }, restore() { - this.applyToKids((card) => { return card.restore(); }); + this.applyToChildren((card) => { return card.restore(); }); return {$set: {archived: false}}; }, From 04745f0c2fe83f044032713e1864c5ac00d38ac9 Mon Sep 17 00:00:00 2001 From: Nicu Tofan Date: Mon, 25 Jun 2018 22:01:02 +0300 Subject: [PATCH 17/24] implement getDefaultSwimline for boards --- client/components/cards/subtasks.js | 2 +- client/components/lists/listBody.js | 2 +- models/boards.js | 12 ++++++++++++ server/migrations.js | 10 +--------- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/client/components/cards/subtasks.js b/client/components/cards/subtasks.js index 087824f75..335eba36c 100644 --- a/client/components/cards/subtasks.js +++ b/client/components/cards/subtasks.js @@ -16,7 +16,7 @@ BlazeComponent.extendComponent({ const crtBoard = Boards.findOne(card.boardId); const targetBoard = crtBoard.getDefaultSubtasksBoard(); const listId = targetBoard.getDefaultSubtasksListId(); - const swimlaneId = Swimlanes.findOne({boardId: targetBoard._id})._id; + const swimlaneId = targetBoard.getDefaultSwimline()._id; if (title) { const _id = Cards.insert({ diff --git a/client/components/lists/listBody.js b/client/components/lists/listBody.js index 4bf7b3697..34aeb8a8d 100644 --- a/client/components/lists/listBody.js +++ b/client/components/lists/listBody.js @@ -46,7 +46,7 @@ BlazeComponent.extendComponent({ if (boardView === 'board-view-swimlanes') swimlaneId = this.parentComponent().parentComponent().data()._id; else if (boardView === 'board-view-lists') - swimlaneId = Swimlanes.findOne({boardId})._id; + swimlaneId = this.data().board().getDefaultSwimline()._id; if (title) { const _id = Cards.insert({ diff --git a/models/boards.js b/models/boards.js index 6f0f72939..a8b7191ea 100644 --- a/models/boards.js +++ b/models/boards.js @@ -337,6 +337,18 @@ Boards.helpers({ getDefaultSubtasksList() { return Lists.findOne(this.getDefaultSubtasksListId()); }, + + getDefaultSwimline() { + let result = Swimlanes.findOne({boardId: this._id}); + if (result === undefined) { + Swimlanes.insert({ + title: TAPi18n.__('default'), + boardId: this._id, + }); + result = Swimlanes.findOne({boardId: this._id}); + } + return result; + }, }); diff --git a/server/migrations.js b/server/migrations.js index c49581f50..af866d134 100644 --- a/server/migrations.js +++ b/server/migrations.js @@ -154,15 +154,7 @@ Migrations.add('add-sort-checklists', () => { Migrations.add('add-swimlanes', () => { Boards.find().forEach((board) => { - const swimlane = Swimlanes.findOne({ boardId: board._id }); - let swimlaneId = ''; - if (swimlane) - swimlaneId = swimlane._id; - else - swimlaneId = Swimlanes.direct.insert({ - boardId: board._id, - title: 'Default', - }); + const swimlaneId = board.getDefaultSwimline()._id; Cards.find({ boardId: board._id }).forEach((card) => { if (!card.hasOwnProperty('swimlaneId')) { From c9f70cf382707141561732a46dbd3e3e2f159e6e Mon Sep 17 00:00:00 2001 From: Nicu Tofan Date: Mon, 25 Jun 2018 22:52:50 +0300 Subject: [PATCH 18/24] Check for null and undefined in board defaults --- models/boards.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/boards.js b/models/boards.js index a8b7191ea..fce674aeb 100644 --- a/models/boards.js +++ b/models/boards.js @@ -297,7 +297,7 @@ Boards.helpers({ // A board alwasy has another board where it deposits subtasks of thasks // that belong to itself. getDefaultSubtasksBoardId() { - if (this.subtasksDefaultBoardId === null) { + if ((this.subtasksDefaultBoardId === null) || (this.subtasksDefaultBoardId === undefined)) { this.subtasksDefaultBoardId = Boards.insert({ title: `^${this.title}^`, permission: this.permission, @@ -322,7 +322,7 @@ Boards.helpers({ }, getDefaultSubtasksListId() { - if (this.subtasksDefaultListId === null) { + if ((this.subtasksDefaultListId === null) || (this.subtasksDefaultListId === undefined)) { this.subtasksDefaultListId = Lists.insert({ title: TAPi18n.__('queue'), boardId: this._id, From 94a52080cff14f7587c0ee837c1fca131cd6aff0 Mon Sep 17 00:00:00 2001 From: Nicu Tofan Date: Mon, 25 Jun 2018 23:12:20 +0300 Subject: [PATCH 19/24] Board level settings for subtasks --- client/components/boards/boardHeader.jade | 31 ++++++++++ client/components/boards/boardHeader.js | 70 +++++++++++++++++++++++ client/components/cards/cardDetails.jade | 5 +- client/components/cards/subtasks.js | 1 + i18n/en.i18n.json | 7 ++- models/boards.js | 16 ++++++ models/cards.js | 2 +- server/migrations.js | 12 ++++ 8 files changed, 140 insertions(+), 4 deletions(-) diff --git a/client/components/boards/boardHeader.jade b/client/components/boards/boardHeader.jade index b4ccd3b3b..59691a615 100644 --- a/client/components/boards/boardHeader.jade +++ b/client/components/boards/boardHeader.jade @@ -130,6 +130,10 @@ template(name="boardMenuPopup") li: a(href="{{exportUrl}}", download="{{exportFilename}}") {{_ 'export-board'}} li: a.js-archive-board {{_ 'archive-board'}} li: a.js-outgoing-webhooks {{_ 'outgoing-webhooks'}} + hr + ul.pop-over-list + li: a.js-subtask-settings {{_ 'subtask-settings'}} + if isSandstorm hr ul.pop-over-list @@ -193,6 +197,33 @@ template(name="boardChangeColorPopup") if isSelected i.fa.fa-check +template(name="boardSubtaskSettingsPopup") + form.board-subtask-settings + a.flex.js-field-has-subtasks(class="{{#if allowsSubtasks}}is-checked{{/if}}") + .materialCheckBox(class="{{#if allowsSubtasks}}is-checked{{/if}}") + span {{_ 'show-subtasks-field'}} + label + | {{_ 'deposit-subtasks-board'}} + select.js-field-deposit-board(disabled="{{#unless allowsSubtasks}}disabled{{/unless}}") + each boards + if isBoardSelected + option(value=_id selected="selected") {{title}} + else + option(value=_id) {{title}} + if isNullBoardSelected + option(value='null' selected="selected") {{_ 'custom-field-dropdown-none'}} + else + option(value='null') {{_ 'custom-field-dropdown-none'}} + hr + label + | {{_ 'deposit-subtasks-list'}} + select.js-field-deposit-list(disabled="{{#unless hasLists}}disabled{{/unless}}") + each lists + if isListSelected + option(value=_id selected="selected") {{title}} + else + option(value=_id) {{title}} + template(name="createBoard") form label diff --git a/client/components/boards/boardHeader.js b/client/components/boards/boardHeader.js index b26404746..bafee9b94 100644 --- a/client/components/boards/boardHeader.js +++ b/client/components/boards/boardHeader.js @@ -25,6 +25,7 @@ Template.boardMenuPopup.events({ }), 'click .js-outgoing-webhooks': Popup.open('outgoingWebhooks'), 'click .js-import-board': Popup.open('chooseBoardSource'), + 'click .js-subtask-settings': Popup.open('boardSubtaskSettings'), }); Template.boardMenuPopup.helpers({ @@ -151,6 +152,75 @@ BlazeComponent.extendComponent({ }, }).register('boardChangeColorPopup'); +BlazeComponent.extendComponent({ + onCreated() { + this.currentBoard = Boards.findOne(Session.get('currentBoard')); + }, + + allowsSubtasks() { + return this.currentBoard.allowsSubtasks; + }, + + isBoardSelected() { + return this.currentBoard.subtasksDefaultBoardId === this.currentData()._id; + }, + + isNullBoardSelected() { + return (this.currentBoard.subtasksDefaultBoardId === null) || (this.currentBoard.subtasksDefaultBoardId === undefined); + }, + + boards() { + return Boards.find({ + archived: false, + 'members.userId': Meteor.userId(), + }, { + sort: ['title'], + }); + }, + + lists() { + return Lists.find({ + boardId: this.currentBoard._id, + archived: false, + }, { + sort: ['title'], + }); + }, + + hasLists() { + return this.lists().count() > 0; + }, + + isListSelected() { + return this.currentBoard.subtasksDefaultBoardId === this.currentData()._id; + }, + + events() { + return [{ + 'click .js-field-has-subtasks'(evt) { + evt.preventDefault(); + this.currentBoard.allowsSubtasks = !this.currentBoard.allowsSubtasks; + this.currentBoard.setAllowsSubtasks(this.currentBoard.allowsSubtasks); + $('.js-field-has-subtasks .materialCheckBox').toggleClass('is-checked', this.currentBoard.allowsSubtasks); + $('.js-field-has-subtasks').toggleClass('is-checked', this.currentBoard.allowsSubtasks); + $('.js-field-deposit-board').prop('disabled', !this.currentBoard.allowsSubtasks); + }, + 'change .js-field-deposit-board'(evt) { + let value = evt.target.value; + if (value === 'null') { + value = null; + } + this.currentBoard.setSubtasksDefaultBoardId(value); + evt.preventDefault(); + }, + 'change .js-field-deposit-list'(evt) { + this.currentBoard.setSubtasksDefaultListId(evt.target.value); + evt.preventDefault(); + }, + }]; + }, +}).register('boardSubtaskSettingsPopup'); + const CreateBoard = BlazeComponent.extendComponent({ template() { return 'createBoard'; diff --git a/client/components/cards/cardDetails.jade b/client/components/cards/cardDetails.jade index bc0ce45c9..789cc4b13 100644 --- a/client/components/cards/cardDetails.jade +++ b/client/components/cards/cardDetails.jade @@ -144,8 +144,9 @@ template(name="cardDetails") hr +checklists(cardId = _id) - hr - +subtasks(cardId = _id) + if currentBoard.allowsSubtasks + hr + +subtasks(cardId = _id) hr h3 diff --git a/client/components/cards/subtasks.js b/client/components/cards/subtasks.js index 335eba36c..9c6f265e6 100644 --- a/client/components/cards/subtasks.js +++ b/client/components/cards/subtasks.js @@ -30,6 +30,7 @@ BlazeComponent.extendComponent({ sort: sortIndex, swimlaneId, }); + // In case the filter is active we need to add the newly inserted card in // the list of exceptions -- cards that are not filtered. Otherwise the // card will disappear instantly. diff --git a/i18n/en.i18n.json b/i18n/en.i18n.json index 5e1a99e8b..e410572f3 100644 --- a/i18n/en.i18n.json +++ b/i18n/en.i18n.json @@ -482,5 +482,10 @@ "delete-board": "Delete Board", "default-subtasks-board": "Subtasks for __board__ board", "default": "Default", - "queue": "Queue" + "queue": "Queue", + "subtask-settings": "Subtasks Settings", + "boardSubtaskSettingsPopup-title": "Board Subtasks Settings", + "show-subtasks-field": "Cards can have subtasks:", + "deposit-subtasks-board": "Deposit subtasks to this board:", + "deposit-subtasks-list": "Landing list for subtasks deposited here:" } diff --git a/models/boards.js b/models/boards.js index fce674aeb..b5b0b0fce 100644 --- a/models/boards.js +++ b/models/boards.js @@ -161,6 +161,10 @@ Boards.attachSchema(new SimpleSchema({ optional: true, defaultValue: null, }, + allowsSubtasks: { + type: Boolean, + defaultValue: true, + }, })); @@ -473,6 +477,18 @@ Boards.mutations({ }, }; }, + + setAllowsSubtasks(allowsSubtasks) { + return { $set: { allowsSubtasks } }; + }, + + setSubtasksDefaultBoardId(subtasksDefaultBoardId) { + return { $set: { subtasksDefaultBoardId } }; + }, + + setSubtasksDefaultListId(subtasksDefaultListId) { + return { $set: { subtasksDefaultListId } }; + }, }); if (Meteor.isServer) { diff --git a/models/cards.js b/models/cards.js index 2563fdf85..8d7a93d05 100644 --- a/models/cards.js +++ b/models/cards.js @@ -258,7 +258,7 @@ Cards.helpers({ return finishCount > 0 && this.subtasksCount() === finishCount; }, - hasSubtasks() { + allowsSubtasks() { return this.subtasksCount() !== 0; }, diff --git a/server/migrations.js b/server/migrations.js index af866d134..c3da32216 100644 --- a/server/migrations.js +++ b/server/migrations.js @@ -287,3 +287,15 @@ Migrations.add('add-subtasks-sort', () => { }, noValidateMulti); }); +Migrations.add('add-subtasks-allowed', () => { + Boards.update({ + allowsSubtasks: { + $exists: false, + }, + }, { + $set: { + allowsSubtasks: -1, + }, + }, noValidateMulti); +}); + From c0ffd6c20f2a04bd1436ea2f0953f1c3c8afe145 Mon Sep 17 00:00:00 2001 From: Nicu Tofan Date: Tue, 26 Jun 2018 02:13:31 +0300 Subject: [PATCH 20/24] Show parent in card (no links, yet) --- client/components/boards/boardHeader.jade | 31 +++++++++++-- client/components/boards/boardHeader.js | 27 ++++++++++++ client/components/boards/boardHeader.styl | 19 ++++++++ client/components/cards/cardDetails.jade | 6 +++ client/components/cards/cardDetails.js | 8 ++++ client/components/cards/minicard.jade | 16 ++++++- i18n/en.i18n.json | 11 ++++- models/boards.js | 16 +++++++ models/cards.js | 53 +++++++++++++++++++++++ server/migrations.js | 14 +++++- 10 files changed, 193 insertions(+), 8 deletions(-) diff --git a/client/components/boards/boardHeader.jade b/client/components/boards/boardHeader.jade index 59691a615..a4abfac6d 100644 --- a/client/components/boards/boardHeader.jade +++ b/client/components/boards/boardHeader.jade @@ -199,9 +199,30 @@ template(name="boardChangeColorPopup") template(name="boardSubtaskSettingsPopup") form.board-subtask-settings - a.flex.js-field-has-subtasks(class="{{#if allowsSubtasks}}is-checked{{/if}}") - .materialCheckBox(class="{{#if allowsSubtasks}}is-checked{{/if}}") - span {{_ 'show-subtasks-field'}} + h3 {{_ 'show-parent-in-minicard'}} + a#prefix-with-full-path.flex.js-field-show-parent-in-minicard(class="{{#if $eq presentParentTask 'prefix-with-full-path'}}is-checked{{/if}}") + .materialCheckBox(class="{{#if $eq presentParentTask 'prefix-with-full-path'}}is-checked{{/if}}") + span {{_ 'prefix-with-full-path'}} + a#prefix-with-parent.flex.js-field-show-parent-in-minicard(class="{{#if $eq presentParentTask 'prefix-with-parent'}}is-checked{{/if}}") + .materialCheckBox(class="{{#if $eq presentParentTask 'prefix-with-parent'}}is-checked{{/if}}") + span {{_ 'prefix-with-parent'}} + a#subtext-with-full-path.flex.js-field-show-parent-in-minicard(class="{{#if $eq presentParentTask 'subtext-with-full-path'}}is-checked{{/if}}") + .materialCheckBox(class="{{#if $eq presentParentTask 'subtext-with-full-path'}}is-checked{{/if}}") + span {{_ 'subtext-with-full-path'}} + a#subtext-with-parent.flex.js-field-show-parent-in-minicard(class="{{#if $eq presentParentTask 'subtext-with-parent'}}is-checked{{/if}}") + .materialCheckBox(class="{{#if $eq presentParentTask 'subtext-with-parent'}}is-checked{{/if}}") + span {{_ 'subtext-with-parent'}} + a#no-parent.flex.js-field-show-parent-in-minicard(class="{{#if $eq presentParentTask 'no-parent'}}is-checked{{/if}}") + .materialCheckBox(class="{{#if $eq presentParentTask 'no-parent'}}is-checked{{/if}}") + span {{_ 'no-parent'}} + div + hr + + div.check-div + a.flex.js-field-has-subtasks(class="{{#if allowsSubtasks}}is-checked{{/if}}") + .materialCheckBox(class="{{#if allowsSubtasks}}is-checked{{/if}}") + span {{_ 'show-subtasks-field'}} + label | {{_ 'deposit-subtasks-board'}} select.js-field-deposit-board(disabled="{{#unless allowsSubtasks}}disabled{{/unless}}") @@ -214,7 +235,9 @@ template(name="boardSubtaskSettingsPopup") option(value='null' selected="selected") {{_ 'custom-field-dropdown-none'}} else option(value='null') {{_ 'custom-field-dropdown-none'}} - hr + div + hr + label | {{_ 'deposit-subtasks-list'}} select.js-field-deposit-list(disabled="{{#unless hasLists}}disabled{{/unless}}") diff --git a/client/components/boards/boardHeader.js b/client/components/boards/boardHeader.js index bafee9b94..865bb2121 100644 --- a/client/components/boards/boardHeader.js +++ b/client/components/boards/boardHeader.js @@ -195,6 +195,14 @@ BlazeComponent.extendComponent({ return this.currentBoard.subtasksDefaultBoardId === this.currentData()._id; }, + presentParentTask() { + let result = this.currentBoard.presentParentTask; + if ((result === null) || (result === undefined)) { + result = 'no-parent'; + } + return result; + }, + events() { return [{ 'click .js-field-has-subtasks'(evt) { @@ -217,6 +225,25 @@ BlazeComponent.extendComponent({ this.currentBoard.setSubtasksDefaultListId(evt.target.value); evt.preventDefault(); }, + 'click .js-field-show-parent-in-minicard'(evt) { + const value = evt.target.id || $(evt.target).parent()[0].id || $(evt.target).parent()[0].parent()[0].id; + const options = [ + 'prefix-with-full-path', + 'prefix-with-parent', + 'subtext-with-full-path', + 'subtext-with-parent', + 'no-parent']; + options.forEach(function(element) { + if (element !== value) { + $(`#${element} .materialCheckBox`).toggleClass('is-checked', false); + $(`#${element}`).toggleClass('is-checked', false); + } + }); + $(`#${value} .materialCheckBox`).toggleClass('is-checked', true); + $(`#${value}`).toggleClass('is-checked', true); + this.currentBoard.setPresentParentTask(value); + evt.preventDefault(); + }, }]; }, }).register('boardSubtaskSettingsPopup'); diff --git a/client/components/boards/boardHeader.styl b/client/components/boards/boardHeader.styl index 0abdb5bda..402b4f1ea 100644 --- a/client/components/boards/boardHeader.styl +++ b/client/components/boards/boardHeader.styl @@ -1,3 +1,22 @@ .integration-form padding: 5px border-bottom: 1px solid #ccc + +.flex + display: -webkit-box + display: -moz-box + display: -webkit-flex + display: -moz-flex + display: -ms-flexbox + display: flex + +.option + @extends .flex + -webkit-border-radius: 3px; + border-radius: 3px; + background: #fff; + text-decoration: none; + -webkit-box-shadow: 0 1px 2px rgba(0,0,0,0.2); + box-shadow: 0 1px 2px rgba(0,0,0,0.2); + margin-top: 5px; + padding: 5px; diff --git a/client/components/cards/cardDetails.jade b/client/components/cards/cardDetails.jade index 789cc4b13..a5b8a2b3e 100644 --- a/client/components/cards/cardDetails.jade +++ b/client/components/cards/cardDetails.jade @@ -13,6 +13,12 @@ template(name="cardDetails") = title if isWatching i.fa.fa-eye.card-details-watch + .card-details-path + each parentList + |   >   + a.js-parent-card {{title}} + // else + {{_ 'top-level-card'}} if archived p.warning {{_ 'card-archived'}} diff --git a/client/components/cards/cardDetails.js b/client/components/cards/cardDetails.js index 4731e448f..1c85580fc 100644 --- a/client/components/cards/cardDetails.js +++ b/client/components/cards/cardDetails.js @@ -70,6 +70,14 @@ BlazeComponent.extendComponent({ } }, + presentParentTask() { + let result = this.currentBoard.presentParentTask; + if ((result === null) || (result === undefined)) { + result = 'no-parent'; + } + return result; + }, + onRendered() { if (!Utils.isMiniScreen()) this.scrollParentContainer(); const $checklistsDom = this.$('.card-checklist-items'); diff --git a/client/components/cards/minicard.jade b/client/components/cards/minicard.jade index 2a8e95abd..9a9b897f7 100644 --- a/client/components/cards/minicard.jade +++ b/client/components/cards/minicard.jade @@ -8,7 +8,21 @@ template(name="minicard") .minicard-label(class="card-label-{{color}}" title="{{name}}") .minicard-title +viewer - = title + if isTopLevel + = title + else + if $eq 'prefix-with-full-path' currentBoard.presentParentTask + [{{ parentString ' > ' }}] {{ title }} + else + if $eq 'prefix-with-parent' currentBoard.presentParentTask + [{{ parentCardName }}] {{ title }} + else + = title + if $eq 'subtext-with-full-path' currentBoard.presentParentTask + .small {{ parentString ' > ' }} + if $eq 'subtext-with-parent' currentBoard.presentParentTask + .small {{ parentCardName }} + .dates if receivedAt unless startAt diff --git a/i18n/en.i18n.json b/i18n/en.i18n.json index e410572f3..ed2c45afe 100644 --- a/i18n/en.i18n.json +++ b/i18n/en.i18n.json @@ -485,7 +485,14 @@ "queue": "Queue", "subtask-settings": "Subtasks Settings", "boardSubtaskSettingsPopup-title": "Board Subtasks Settings", - "show-subtasks-field": "Cards can have subtasks:", + "show-subtasks-field": "Cards can have subtasks", "deposit-subtasks-board": "Deposit subtasks to this board:", - "deposit-subtasks-list": "Landing list for subtasks deposited here:" + "deposit-subtasks-list": "Landing list for subtasks deposited here:", + "show-parent-in-minicard": "Show parent in minicard:", + "prefix-with-full-path": "Prefix with full path", + "prefix-with-parent": "Prefix with parent", + "subtext-with-full-path": "Subtext with full path", + "subtext-with-parent": "Subtext with full parent", + "no-parent": "Don't show parent" + } diff --git a/models/boards.js b/models/boards.js index b5b0b0fce..2d80a56a9 100644 --- a/models/boards.js +++ b/models/boards.js @@ -165,6 +165,18 @@ Boards.attachSchema(new SimpleSchema({ type: Boolean, defaultValue: true, }, + presentParentTask: { + type: String, + allowedValues: [ + 'prefix-with-full-path', + 'prefix-with-parent', + 'subtext-with-full-path', + 'subtext-with-parent', + 'no-parent', + ], + optional: true, + defaultValue: 'no-parent', + }, })); @@ -489,6 +501,10 @@ Boards.mutations({ setSubtasksDefaultListId(subtasksDefaultListId) { return { $set: { subtasksDefaultListId } }; }, + + setPresentParentTask(presentParentTask) { + return { $set: { presentParentTask } }; + }, }); if (Meteor.isServer) { diff --git a/models/cards.js b/models/cards.js index 8d7a93d05..323ec407b 100644 --- a/models/cards.js +++ b/models/cards.js @@ -326,6 +326,59 @@ Cards.helpers({ return Cards.findOne(this.parentId); }, + parentCardName() { + if (this.parentId === '') { + return ''; + } + return Cards.findOne(this.parentId).title; + }, + + parentListId() { + const result = []; + let crtParentId = this.parentId; + while (crtParentId !== '') { + const crt = Cards.findOne(crtParentId); + if ((crt === null) || (crt === undefined)) { + // maybe it has been deleted + break; + } + if (crtParentId in result) { + // circular reference + break; + } + result.unshift(crtParentId); + crtParentId = crt.parentId; + } + return result; + }, + + parentList() { + const resultId = []; + const result = []; + let crtParentId = this.parentId; + while (crtParentId !== '') { + const crt = Cards.findOne(crtParentId); + if ((crt === null) || (crt === undefined)) { + // maybe it has been deleted + break; + } + if (crtParentId in resultId) { + // circular reference + break; + } + resultId.unshift(crtParentId); + result.unshift(crt); + crtParentId = crt.parentId; + } + return result; + }, + + parentString(sep) { + return this.parentList().map(function(elem){ + return elem.title; + }).join(sep); + }, + isTopLevel() { return this.parentId === ''; }, diff --git a/server/migrations.js b/server/migrations.js index c3da32216..5194b79fe 100644 --- a/server/migrations.js +++ b/server/migrations.js @@ -294,7 +294,19 @@ Migrations.add('add-subtasks-allowed', () => { }, }, { $set: { - allowsSubtasks: -1, + allowsSubtasks: true, + }, + }, noValidateMulti); +}); + +Migrations.add('add-subtasks-allowed', () => { + Boards.update({ + presentParentTask: { + $exists: false, + }, + }, { + $set: { + presentParentTask: 'no-parent', }, }, noValidateMulti); }); From 3a4a075dbadba8c1ce12fa86730a4507985729f7 Mon Sep 17 00:00:00 2001 From: Nicu Tofan Date: Tue, 26 Jun 2018 13:22:51 +0300 Subject: [PATCH 21/24] Fix minicard parents display --- client/components/cards/minicard.jade | 27 +++++++++++++-------------- client/components/cards/minicard.styl | 7 +++++++ i18n/en.i18n.json | 2 +- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/client/components/cards/minicard.jade b/client/components/cards/minicard.jade index 9a9b897f7..579136696 100644 --- a/client/components/cards/minicard.jade +++ b/client/components/cards/minicard.jade @@ -7,21 +7,20 @@ template(name="minicard") each labels .minicard-label(class="card-label-{{color}}" title="{{name}}") .minicard-title + if $eq 'prefix-with-full-path' currentBoard.presentParentTask + .parent-prefix + | {{ parentString ' > ' }} + if $eq 'prefix-with-parent' currentBoard.presentParentTask + .parent-prefix + | {{ parentCardName }} +viewer - if isTopLevel - = title - else - if $eq 'prefix-with-full-path' currentBoard.presentParentTask - [{{ parentString ' > ' }}] {{ title }} - else - if $eq 'prefix-with-parent' currentBoard.presentParentTask - [{{ parentCardName }}] {{ title }} - else - = title - if $eq 'subtext-with-full-path' currentBoard.presentParentTask - .small {{ parentString ' > ' }} - if $eq 'subtext-with-parent' currentBoard.presentParentTask - .small {{ parentCardName }} + {{ title }} + if $eq 'subtext-with-full-path' currentBoard.presentParentTask + .parent-subtext + | {{ parentString ' > ' }} + if $eq 'subtext-with-parent' currentBoard.presentParentTask + .parent-subtext + | {{ parentCardName }} .dates if receivedAt diff --git a/client/components/cards/minicard.styl b/client/components/cards/minicard.styl index 38f829d0d..6c9414a7b 100644 --- a/client/components/cards/minicard.styl +++ b/client/components/cards/minicard.styl @@ -162,6 +162,13 @@ margin-bottom: 20px overflow-y: auto +.parent-prefix + color: darken(white, 30%) + font-size: 0.9em +.parent-subtext + color: darken(white, 30%) + font-size: 0.9em + @media screen and (max-width: 800px) .minicard .is-selected & diff --git a/i18n/en.i18n.json b/i18n/en.i18n.json index ed2c45afe..e89d69282 100644 --- a/i18n/en.i18n.json +++ b/i18n/en.i18n.json @@ -492,7 +492,7 @@ "prefix-with-full-path": "Prefix with full path", "prefix-with-parent": "Prefix with parent", "subtext-with-full-path": "Subtext with full path", - "subtext-with-parent": "Subtext with full parent", + "subtext-with-parent": "Subtext with parent", "no-parent": "Don't show parent" } From bac490d2f3b5531125694ff0cd9fa1e55d255c80 Mon Sep 17 00:00:00 2001 From: Nicu Tofan Date: Tue, 26 Jun 2018 14:10:58 +0300 Subject: [PATCH 22/24] Links for parents in card details. --- client/components/cards/cardDetails.jade | 2 +- client/components/cards/cardDetails.js | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/client/components/cards/cardDetails.jade b/client/components/cards/cardDetails.jade index a5b8a2b3e..0110d12ec 100644 --- a/client/components/cards/cardDetails.jade +++ b/client/components/cards/cardDetails.jade @@ -16,7 +16,7 @@ template(name="cardDetails") .card-details-path each parentList |   >   - a.js-parent-card {{title}} + a.js-parent-card(href=linkForCard) {{title}} // else {{_ 'top-level-card'}} diff --git a/client/components/cards/cardDetails.js b/client/components/cards/cardDetails.js index 1c85580fc..d49579641 100644 --- a/client/components/cards/cardDetails.js +++ b/client/components/cards/cardDetails.js @@ -20,10 +20,11 @@ BlazeComponent.extendComponent({ }, onCreated() { + this.currentBoard = Boards.findOne(Session.get('currentBoard')); this.isLoaded = new ReactiveVar(false); const boardBody = this.parentComponent().parentComponent(); //in Miniview parent is Board, not BoardBody. - if (boardBody !== null){ + if (boardBody !== null) { boardBody.showOverlay.set(true); boardBody.mouseHasEnterCardDetails = false; } @@ -78,6 +79,22 @@ BlazeComponent.extendComponent({ return result; }, + linkForCard() { + const card = this.currentData(); + let result = '#'; + if (card) { + const board = Boards.findOne(card.boardId); + if (board) { + result = FlowRouter.url('card', { + boardId: card.boardId, + slug: board.slug, + cardId: card._id, + }); + } + } + return result; + }, + onRendered() { if (!Utils.isMiniScreen()) this.scrollParentContainer(); const $checklistsDom = this.$('.card-checklist-items'); From 439d7c3dbc38e6b8165b3d65f78d0f90e7e5d7db Mon Sep 17 00:00:00 2001 From: Nicu Tofan Date: Tue, 26 Jun 2018 14:49:21 +0300 Subject: [PATCH 23/24] Fix conflict in migrations (Error: title is required by removing find() from all of migrations.) --- server/migrations.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/server/migrations.js b/server/migrations.js index 5194b79fe..10097d41f 100644 --- a/server/migrations.js +++ b/server/migrations.js @@ -55,7 +55,7 @@ Migrations.add('lowercase-board-permission', () => { // Security migration: see https://github.com/wekan/wekan/issues/99 Migrations.add('change-attachments-type-for-non-images', () => { const newTypeForNonImage = 'application/octet-stream'; - Attachments.find().forEach((file) => { + Attachments.forEach((file) => { if (!file.isImage()) { Attachments.update(file._id, { $set: { @@ -68,7 +68,7 @@ Migrations.add('change-attachments-type-for-non-images', () => { }); Migrations.add('card-covers', () => { - Cards.find().forEach((card) => { + Cards.forEach((card) => { const cover = Attachments.findOne({ cardId: card._id, cover: true }); if (cover) { Cards.update(card._id, {$set: {coverId: cover._id}}, noValidate); @@ -86,7 +86,7 @@ Migrations.add('use-css-class-for-boards-colors', () => { '#2C3E50': 'midnight', '#E67E22': 'pumpkin', }; - Boards.find().forEach((board) => { + Boards.forEach((board) => { const oldBoardColor = board.background.color; const newBoardColor = associationTable[oldBoardColor]; Boards.update(board._id, { @@ -97,7 +97,7 @@ Migrations.add('use-css-class-for-boards-colors', () => { }); Migrations.add('denormalize-star-number-per-board', () => { - Boards.find().forEach((board) => { + Boards.forEach((board) => { const nStars = Users.find({'profile.starredBoards': board._id}).count(); Boards.update(board._id, {$set: {stars: nStars}}, noValidate); }); @@ -132,7 +132,7 @@ Migrations.add('add-member-isactive-field', () => { }); Migrations.add('add-sort-checklists', () => { - Checklists.find().forEach((checklist, index) => { + Checklists.forEach((checklist, index) => { if (!checklist.hasOwnProperty('sort')) { Checklists.direct.update( checklist._id, @@ -153,9 +153,8 @@ Migrations.add('add-sort-checklists', () => { }); Migrations.add('add-swimlanes', () => { - Boards.find().forEach((board) => { + Boards.forEach((board) => { const swimlaneId = board.getDefaultSwimline()._id; - Cards.find({ boardId: board._id }).forEach((card) => { if (!card.hasOwnProperty('swimlaneId')) { Cards.direct.update( @@ -169,7 +168,7 @@ Migrations.add('add-swimlanes', () => { }); Migrations.add('add-views', () => { - Boards.find().forEach((board) => { + Boards.forEach((board) => { if (!board.hasOwnProperty('view')) { Boards.direct.update( { _id: board._id }, @@ -181,7 +180,7 @@ Migrations.add('add-views', () => { }); Migrations.add('add-checklist-items', () => { - Checklists.find().forEach((checklist) => { + Checklists.forEach((checklist) => { // Create new items _.sortBy(checklist.items, 'sort').forEach((item, index) => { ChecklistItems.direct.insert({ @@ -202,7 +201,7 @@ Migrations.add('add-checklist-items', () => { }); Migrations.add('add-profile-view', () => { - Users.find().forEach((user) => { + Users.forEach((user) => { if (!user.hasOwnProperty('profile.boardView')) { // Set default view Users.direct.update( From b7d508e8c4cf858559e144053d119ceaebfa9697 Mon Sep 17 00:00:00 2001 From: Nicu Tofan Date: Tue, 26 Jun 2018 17:39:31 +0300 Subject: [PATCH 24/24] Added ability to change card's parent. --- client/components/cards/cardDetails.jade | 27 +++++ client/components/cards/cardDetails.js | 139 ++++++++++++++++++----- i18n/en.i18n.json | 3 + models/boards.js | 4 + models/cards.js | 15 ++- 5 files changed, 157 insertions(+), 31 deletions(-) diff --git a/client/components/cards/cardDetails.jade b/client/components/cards/cardDetails.jade index 0110d12ec..aaad7c7c4 100644 --- a/client/components/cards/cardDetails.jade +++ b/client/components/cards/cardDetails.jade @@ -283,10 +283,37 @@ template(name="cardMorePopup") button.js-copy-card-link-to-clipboard(class="btn") {{_ 'copy-card-link-to-clipboard'}} span.clearfix br + h2 {{_ 'change-card-parent'}} + label {{_ 'source-board'}}: + select.js-field-parent-board + each boards + if isParentBoard + option(value="{{_id}}" selected) {{title}} + else + option(value="{{_id}}") {{title}} + if isTopLevel + option(value="none" selected) {{_ 'custom-field-dropdown-none'}} + else + option(value="none") {{_ 'custom-field-dropdown-none'}} + + label {{_ 'parent-card'}}: + select.js-field-parent-card + if isTopLevel + option(value="none" selected) {{_ 'custom-field-dropdown-none'}} + else + each cards + if isParentCard + option(value="{{_id}}" selected) {{title}} + else + option(value="{{_id}}") {{title}} + option(value="none") {{_ 'custom-field-dropdown-none'}} + br | {{_ 'added'}} span.date(title=card.createdAt) {{ moment createdAt 'LLL' }} a.js-delete(title="{{_ 'card-delete-notice'}}") {{_ 'delete'}} + + template(name="cardDeletePopup") p {{_ "card-delete-pop"}} unless archived diff --git a/client/components/cards/cardDetails.js b/client/components/cards/cardDetails.js index d49579641..5fee16807 100644 --- a/client/components/cards/cardDetails.js +++ b/client/components/cards/cardDetails.js @@ -390,7 +390,6 @@ Template.moveCardPopup.events({ Popup.close(); }, }); - BlazeComponent.extendComponent({ onCreated() { subManager.subscribe('board', Session.get('currentBoard')); @@ -427,6 +426,7 @@ BlazeComponent.extendComponent({ }, }).register('boardsAndLists'); + function cloneCheckList(_id, checklist) { 'use strict'; const checklistId = checklist._id; @@ -558,36 +558,119 @@ Template.copyChecklistToManyCardsPopup.events({ }, }); - -Template.cardMorePopup.events({ - 'click .js-copy-card-link-to-clipboard' () { - // Clipboard code from: - // https://stackoverflow.com/questions/6300213/copy-selected-text-to-the-clipboard-without-using-flash-must-be-cross-browser - const StringToCopyElement = document.getElementById('cardURL'); - StringToCopyElement.select(); - if (document.execCommand('copy')) { - StringToCopyElement.blur(); +BlazeComponent.extendComponent({ + onCreated() { + this.currentCard = this.currentData(); + this.parentCard = this.currentCard.parentCard(); + if (this.parentCard) { + this.parentBoard = this.parentCard.board(); } else { - document.getElementById('cardURL').selectionStart = 0; - document.getElementById('cardURL').selectionEnd = 999; - document.execCommand('copy'); - if (window.getSelection) { - if (window.getSelection().empty) { // Chrome - window.getSelection().empty(); - } else if (window.getSelection().removeAllRanges) { // Firefox - window.getSelection().removeAllRanges(); - } - } else if (document.selection) { // IE? - document.selection.empty(); - } + this.parentBoard = null; } }, - 'click .js-delete': Popup.afterConfirm('cardDelete', function () { - Popup.close(); - Cards.remove(this._id); - Utils.goBoardId(this.boardId); - }), -}); + + boards() { + const boards = Boards.find({ + archived: false, + 'members.userId': Meteor.userId(), + }, { + sort: ['title'], + }); + return boards; + }, + + cards() { + if (this.parentBoard) { + return this.parentBoard.cards(); + } else { + return []; + } + }, + + isParentBoard() { + const board = this.currentData(); + if (this.parentBoard) { + return board._id === this.parentBoard; + } + return false; + }, + + isParentCard() { + const card = this.currentData(); + if (this.parentCard) { + return card._id === this.parentCard; + } + return false; + }, + + setParentCardId(cardId) { + if (cardId === 'null') { + cardId = null; + this.parentCard = null; + } else { + this.parentCard = Cards.findOne(cardId); + } + this.currentCard.setParentId(cardId); + }, + + events() { + return [{ + 'click .js-copy-card-link-to-clipboard' () { + // Clipboard code from: + // https://stackoverflow.com/questions/6300213/copy-selected-text-to-the-clipboard-without-using-flash-must-be-cross-browser + const StringToCopyElement = document.getElementById('cardURL'); + StringToCopyElement.select(); + if (document.execCommand('copy')) { + StringToCopyElement.blur(); + } else { + document.getElementById('cardURL').selectionStart = 0; + document.getElementById('cardURL').selectionEnd = 999; + document.execCommand('copy'); + if (window.getSelection) { + if (window.getSelection().empty) { // Chrome + window.getSelection().empty(); + } else if (window.getSelection().removeAllRanges) { // Firefox + window.getSelection().removeAllRanges(); + } + } else if (document.selection) { // IE? + document.selection.empty(); + } + } + }, + 'click .js-delete': Popup.afterConfirm('cardDelete', function () { + Popup.close(); + Cards.remove(this._id); + Utils.goBoardId(this.boardId); + }), + 'change .js-field-parent-board'(evt) { + const selection = $(evt.currentTarget).val(); + const list = $('.js-field-parent-card'); + list.empty(); + if (selection === 'none') { + this.parentBoard = null; + list.prop('disabled', true); + } else { + this.parentBoard = Boards.findOne(selection); + this.parentBoard.cards().forEach(function(card) { + list.append( + $('').val(card._id).html(card.title) + ); + }); + list.prop('disabled', false); + } + list.append( + `` + ); + this.setParentCardId('null'); + }, + 'change .js-field-parent-card'(evt) { + const selection = $(evt.currentTarget).val(); + this.setParentCardId(selection); + }, + }]; + }, +}).register('cardMorePopup'); + // Close the card details pane by pressing escape EscapeActions.register('detailsPane', diff --git a/i18n/en.i18n.json b/i18n/en.i18n.json index e89d69282..42dbd2d5e 100644 --- a/i18n/en.i18n.json +++ b/i18n/en.i18n.json @@ -493,6 +493,9 @@ "prefix-with-parent": "Prefix with parent", "subtext-with-full-path": "Subtext with full path", "subtext-with-parent": "Subtext with parent", + "change-card-parent": "Change card's parent", + "parent-card": "Parent card", + "source-board": "Source board", "no-parent": "Don't show parent" } diff --git a/models/boards.js b/models/boards.js index 2d80a56a9..c83050c00 100644 --- a/models/boards.js +++ b/models/boards.js @@ -220,6 +220,10 @@ Boards.helpers({ return Swimlanes.find({ boardId: this._id, archived: false }, { sort: { sort: 1 } }); }, + cards() { + return Cards.find({ boardId: this._id, archived: false }, { sort: { sort: 1 } }); + }, + hasOvertimeCards(){ const card = Cards.findOne({isOvertime: true, boardId: this._id, archived: false} ); return card !== undefined; diff --git a/models/cards.js b/models/cards.js index 323ec407b..b6a7b4c61 100644 --- a/models/cards.js +++ b/models/cards.js @@ -327,10 +327,14 @@ Cards.helpers({ }, parentCardName() { - if (this.parentId === '') { - return ''; + let result = ''; + if (this.parentId !== '') { + const card = Cards.findOne(this.parentId); + if (card) { + result = card.title; + } } - return Cards.findOne(this.parentId).title; + return result; }, parentListId() { @@ -541,6 +545,11 @@ Cards.mutations({ unsetSpentTime() { return {$unset: {spentTime: '', isOvertime: false}}; }, + + setParentId(parentId) { + return {$set: {parentId}}; + }, + });