summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrés Manelli <andresmanelli@gmail.com>2018-03-19 16:47:07 -0300
committerAndrés Manelli <andresmanelli@gmail.com>2018-03-19 16:47:07 -0300
commit243af32fc798f161e72eddf9e43053b1ba89d98a (patch)
tree0fca4c42907e17887eb491ff6f5b9cdb17840e5f
parentca89442f3a62a7a97044a6e572eea70158edadbd (diff)
downloadwekan-243af32fc798f161e72eddf9e43053b1ba89d98a.tar.gz
wekan-243af32fc798f161e72eddf9e43053b1ba89d98a.tar.bz2
wekan-243af32fc798f161e72eddf9e43053b1ba89d98a.zip
Add checklist ordering capability
-rw-r--r--client/components/cards/cardDetails.js46
-rw-r--r--client/components/cards/checklists.jade35
-rw-r--r--client/components/cards/checklists.js42
-rw-r--r--models/cards.js2
4 files changed, 89 insertions, 36 deletions
diff --git a/client/components/cards/cardDetails.js b/client/components/cards/cardDetails.js
index ab8a6288..066e52ec 100644
--- a/client/components/cards/cardDetails.js
+++ b/client/components/cards/cardDetails.js
@@ -1,4 +1,5 @@
const subManager = new SubsManager();
+const { calculateIndexData } = Utils;
BlazeComponent.extendComponent({
mixins() {
@@ -66,6 +67,51 @@ BlazeComponent.extendComponent({
onRendered() {
if (!Utils.isMiniScreen()) this.scrollParentContainer();
+ const $checklistsDom = this.$('.card-checklist-items');
+
+ $checklistsDom.sortable({
+ tolerance: 'pointer',
+ helper: 'clone',
+ handle: '.checklist-title',
+ items: '.js-checklist',
+ placeholder: 'js-checklist 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-checklist').get(0);
+ if (prevChecklist) {
+ prevChecklist = Blaze.getData(prevChecklist).checklist;
+ }
+ let nextChecklist = ui.item.next('.js-checklist').get(0);
+ if (nextChecklist) {
+ nextChecklist = Blaze.getData(nextChecklist).checklist;
+ }
+ const sortIndex = calculateIndexData(prevChecklist, nextChecklist, 1);
+
+ $checklistsDom.sortable('cancel');
+ const checklist = Blaze.getData(ui.item.get(0)).checklist;
+
+ Checklists.update(checklist._id, {
+ $set: {
+ sort: sortIndex.base,
+ },
+ });
+ },
+ });
+
+ function userIsMember() {
+ return Meteor.user() && Meteor.user().isBoardMember();
+ }
+
+ // Disable sorting if the current user is not a board member
+ this.autorun(() => {
+ if ($checklistsDom.data('sortable')) {
+ $checklistsDom.sortable('option', 'disabled', !userIsMember());
+ }
+ });
},
onDestroyed() {
diff --git a/client/components/cards/checklists.jade b/client/components/cards/checklists.jade
index c73602b5..4753c2c6 100644
--- a/client/components/cards/checklists.jade
+++ b/client/components/cards/checklists.jade
@@ -18,24 +18,25 @@ template(name="checklists")
| {{_ 'add-checklist'}}...
template(name="checklistDetail")
- +inlinedForm(classNames="js-edit-checklist-title" checklist = checklist)
- +editChecklistItemForm(checklist = checklist)
- else
- .checklist-title
- .checkbox.fa.fa-check-square-o
- 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
- = checklist.title
- else
- h2.title
- +viewer
+ .js-checklist
+ +inlinedForm(classNames="js-edit-checklist-title" checklist = checklist)
+ +editChecklistItemForm(checklist = checklist)
+ else
+ .checklist-title
+ .checkbox.fa.fa-check-square-o
+ 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
= checklist.title
- +checklistItems(checklist = checklist)
+ else
+ h2.title
+ +viewer
+ = checklist.title
+ +checklistItems(checklist = checklist)
template(name="checklistDeleteDialog")
.js-confirm-checklist-delete
diff --git a/client/components/cards/checklists.js b/client/components/cards/checklists.js
index 232cc6e4..d68a1e47 100644
--- a/client/components/cards/checklists.js
+++ b/client/components/cards/checklists.js
@@ -38,26 +38,32 @@ function initSorting(items) {
});
}
-Template.checklists.onRendered(function () {
- const self = BlazeComponent.getComponentForElement(this.firstNode);
- self.itemsDom = this.$('.card-checklist-items');
- initSorting(self.itemsDom);
- self.itemsDom.mousedown(function(evt) {
- evt.stopPropagation();
- });
+BlazeComponent.extendComponent({
+ onRendered() {
+ const self = this;
+ self.itemsDom = this.$('.js-checklist-items');
+ initSorting(self.itemsDom);
+ self.itemsDom.mousedown(function(evt) {
+ evt.stopPropagation();
+ });
+
+ function userIsMember() {
+ return Meteor.user() && Meteor.user().isBoardMember();
+ }
- function userIsMember() {
- return Meteor.user() && Meteor.user().isBoardMember();
- }
+ // Disable sorting if the current user is not a board member
+ self.autorun(() => {
+ const $itemsDom = $(self.itemsDom);
+ if ($itemsDom.data('sortable')) {
+ $(self.itemsDom).sortable('option', 'disabled', !userIsMember());
+ }
+ });
+ },
- // Disable sorting if the current user is not a board member
- self.autorun(() => {
- const $itemsDom = $(self.itemsDom);
- if ($itemsDom.data('sortable')) {
- $(self.itemsDom).sortable('option', 'disabled', !userIsMember());
- }
- });
-});
+ canModifyCard() {
+ return Meteor.user() && Meteor.user().isBoardMember() && !Meteor.user().isCommentOnly();
+ },
+}).register('checklistDetail');
BlazeComponent.extendComponent({
diff --git a/models/cards.js b/models/cards.js
index 544afca5..8fd15488 100644
--- a/models/cards.js
+++ b/models/cards.js
@@ -155,7 +155,7 @@ Cards.helpers({
},
checklists() {
- return Checklists.find({cardId: this._id}, {sort: {createdAt: 1}});
+ return Checklists.find({cardId: this._id}, {sort: { sort: 1 } });
},
checklistItemCount() {