diff options
-rw-r--r-- | CHANGELOG.md | 8 | ||||
-rw-r--r-- | client/components/cards/checklists.jade | 2 | ||||
-rw-r--r-- | client/components/cards/checklists.js | 24 | ||||
-rw-r--r-- | client/components/lists/list.styl | 5 | ||||
-rw-r--r-- | client/components/lists/listHeader.jade | 7 | ||||
-rw-r--r-- | client/components/lists/listHeader.js | 15 | ||||
-rw-r--r-- | models/checklists.js | 65 | ||||
-rw-r--r-- | server/migrations.js | 7 |
8 files changed, 79 insertions, 54 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c7add5d..27470c6e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,13 +3,15 @@ This release adds the following new features: * [Add translations (en/de/fi) for email notifications regarding checklists and checklist - items](https://github.com/wekan/wekan/pull/1238). + items](https://github.com/wekan/wekan/pull/1238); +* [Added plus button to add card on top of the list](https://github.com/wekan/wekan/pull/1244). and fixes the following bugs: -* [Checklist items are lost when moving items to another checklist](https://github.com/wekan/wekan/pull/1240). +* [Checklist items are lost when moving items to another checklist](https://github.com/wekan/wekan/pull/1240); +* [Keep state of checklist items when moved to another checklist](https://github.com/wekan/wekan/pull/1242). -Thanks to GitHub users GhassenRjab, umbertooo and xet7 for their contributions. +Thanks to GitHub users GhassenRjab, mario-orlicky, umbertooo and xet7 for their contributions. # v0.39 2017-09-18 Wekan release diff --git a/client/components/cards/checklists.jade b/client/components/cards/checklists.jade index 7ecc5dd3..e1dd1d14 100644 --- a/client/components/cards/checklists.jade +++ b/client/components/cards/checklists.jade @@ -47,7 +47,7 @@ template(name="editChecklistItemForm") template(name="checklistItems") .checklist-items.js-checklist-items - each item in checklist.getItems + each item in checklist.getItemsSorted +inlinedForm(classNames="js-edit-checklist-item" item = item checklist = checklist) +editChecklistItemForm(type = 'item' item = item checklist = checklist) else diff --git a/client/components/cards/checklists.js b/client/components/cards/checklists.js index bd9d275a..ba3384a9 100644 --- a/client/components/cards/checklists.js +++ b/client/components/cards/checklists.js @@ -20,24 +20,26 @@ function initSorting(items) { }); items.sortable('cancel'); const formerParent = ui.item.parents('.js-checklist-items'); - let checklist = Blaze.getData(parent.get(0)).checklist; + const checklist = Blaze.getData(parent.get(0)).checklist; const oldChecklist = Blaze.getData(formerParent.get(0)).checklist; if (oldChecklist._id !== checklist._id) { const currentItem = Blaze.getData(ui.item.get(0)).item; for (let i = 0; i < orderedItems.length; i++) { - let itemId = orderedItems[i]; + const itemId = orderedItems[i]; if (itemId !== currentItem._id) continue; - checklist.addItem(currentItem.title); - checklist = Checklists.findOne({_id: checklist._id}); - itemId = checklist._id + (checklist.newItemIndex - 1); - if (currentItem.finished) { - checklist.finishItem(itemId); - } - orderedItems[i] = itemId; - oldChecklist.removeItem(currentItem._id); + const newItem = { + _id: checklist.getNewItemId(), + title: currentItem.title, + sort: i, + isFinished: currentItem.isFinished, + }; + checklist.addFullItem(newItem); + orderedItems[i] = currentItem._id; + oldChecklist.removeItem(itemId); } + } else { + checklist.sortItems(orderedItems); } - checklist.sortItems(orderedItems); }, }); } diff --git a/client/components/lists/list.styl b/client/components/lists/list.styl index cf939a6e..5e20476e 100644 --- a/client/components/lists/list.styl +++ b/client/components/lists/list.styl @@ -69,13 +69,16 @@ padding-left: 10px color: #a6a6a6 - .list-header-menu-icon + .list-header-menu position: absolute padding: 7px margin-top: 1px top: -@padding right: -@padding + .list-header-plus-icon + color: #a6a6a6 + .list-body flex: 1 display: flex diff --git a/client/components/lists/listHeader.jade b/client/components/lists/listHeader.jade index 11905586..68336320 100644 --- a/client/components/lists/listHeader.jade +++ b/client/components/lists/listHeader.jade @@ -13,7 +13,9 @@ template(name="listHeader") if currentUser.isBoardMember if isWatching i.list-header-watch-icon.fa.fa-eye - a.list-header-menu-icon.fa.fa-navicon.js-open-list-menu + div.list-header-menu + a.js-add-card.fa.fa-plus.list-header-plus-icon + a.fa.fa-navicon.js-open-list-menu template(name="editListTitleForm") .list-composer @@ -28,10 +30,9 @@ template(name="listActionPopup") unless currentUser.isCommentOnly hr ul.pop-over-list - li: a.js-add-card {{_ 'add-card'}} if cards.count li: a.js-select-cards {{_ 'list-select-cards'}} - hr + hr ul.pop-over-list li: a.js-close-list {{_ 'archive-list'}} hr diff --git a/client/components/lists/listHeader.js b/client/components/lists/listHeader.js index 1ad9f9dd..7fe42884 100644 --- a/client/components/lists/listHeader.js +++ b/client/components/lists/listHeader.js @@ -24,6 +24,13 @@ BlazeComponent.extendComponent({ events() { return [{ 'click .js-open-list-menu': Popup.open('listAction'), + 'click .js-add-card' () { + const listDom = document.getElementById(`js-list-${this.currentData()._id}`); + const listComponent = BlazeComponent.getComponentForElement(listDom); + listComponent.openForm({ + position: 'top', + }); + }, submit: this.editTitle, }]; }, @@ -36,14 +43,6 @@ Template.listActionPopup.helpers({ }); Template.listActionPopup.events({ - 'click .js-add-card' () { - const listDom = document.getElementById(`js-list-${this._id}`); - const listComponent = BlazeComponent.getComponentForElement(listDom); - listComponent.openForm({ - position: 'top', - }); - Popup.close(); - }, 'click .js-list-subscribe' () {}, 'click .js-select-cards' () { const cardIds = this.allCards().map((card) => card._id); diff --git a/models/checklists.js b/models/checklists.js index 35ef8ae1..b90656e4 100644 --- a/models/checklists.js +++ b/models/checklists.js @@ -44,11 +44,6 @@ Checklists.attachSchema(new SimpleSchema({ type: Number, decimal: true, }, - newItemIndex: { - type: Number, - decimal: true, - defaultValue: 0, - }, })); const self = Checklists; @@ -57,16 +52,8 @@ Checklists.helpers({ itemCount() { return this.items.length; }, - getItems() { - return this.items.sort(function (itemA, itemB) { - if (itemA.sort < itemB.sort) { - return -1; - } - if (itemA.sort > itemB.sort) { - return 1; - } - return 0; - }); + getItemsSorted() { + return _.sortBy(this.items, 'sort'); }, finishedCount() { return this.items.filter((item) => { @@ -83,6 +70,16 @@ Checklists.helpers({ const items = self.findOne({_id : this._id}).items; return _.pluck(items, '_id').indexOf(itemId); }, + getNewItemId() { + const itemCount = this.itemCount(); + let idx = 0; + if (itemCount > 0) { + const lastId = this.items[itemCount - 1]._id; + const lastIdSuffix = lastId.substr(this._id.length); + idx = parseInt(lastIdSuffix, 10) + 1; + } + return `${this._id}${idx}`; + }, }); Checklists.allow({ @@ -112,14 +109,40 @@ Checklists.mutations({ }, //for items in checklist addItem(title) { - const itemCount = this.itemCount(); - const _id = `${this._id}${this.newItemIndex}`; + const _id = this.getNewItemId(); return { - $addToSet: { items: { _id, title, isFinished: false, sort: itemCount } }, - $set: { newItemIndex: this.newItemIndex + 1}, + $addToSet: { + items: { + _id, title, + isFinished: false, + sort: this.itemCount(), + }, + }, }; }, + addFullItem(item) { + const itemsUpdate = {}; + this.items.forEach(function(iterItem, index) { + if (iterItem.sort >= item.sort) { + itemsUpdate[`items.${index}.sort`] = iterItem.sort + 1; + } + }); + if (!_.isEmpty(itemsUpdate)) { + self.direct.update({ _id: this._id }, { $set: itemsUpdate }); + } + return { $addToSet: { items: item } }; + }, removeItem(itemId) { + const item = this.getItem(itemId); + const itemsUpdate = {}; + this.items.forEach(function(iterItem, index) { + if (iterItem.sort > item.sort) { + itemsUpdate[`items.${index}.sort`] = iterItem.sort - 1; + } + }); + if (!_.isEmpty(itemsUpdate)) { + self.direct.update({ _id: this._id }, { $set: itemsUpdate }); + } return { $pull: { items: { _id: itemId } } }; }, editItem(itemId, title) { @@ -169,11 +192,11 @@ Checklists.mutations({ }, sortItems(itemIDs) { const validItems = []; - for (const itemID of itemIDs) { + itemIDs.forEach((itemID) => { if (this.getItem(itemID)) { validItems.push(this.itemIndex(itemID)); } - } + }); const modifiedValues = {}; for (let i = 0; i < validItems.length; i++) { modifiedValues[`items.${validItems[i]}.sort`] = i; diff --git a/server/migrations.js b/server/migrations.js index 40420e8e..76721623 100644 --- a/server/migrations.js +++ b/server/migrations.js @@ -136,12 +136,7 @@ Migrations.add('add-sort-checklists', () => { if (!checklist.hasOwnProperty('sort')) { Checklists.direct.update( checklist._id, - { - $set: { - sort: index, - newItemIndex: checklist.items.length, - }, - }, + { $set: { sort: index } }, noValidate ); } |