From 037a3d462fe36981b27f2205be900bd9d750cc10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Barrag=C3=A1n=20Merino?= Date: Fri, 2 Sep 2016 13:55:21 +0200 Subject: [PATCH] Sort epics --- .../epic-sortable.directive.coffee | 35 ----------- .../epics-sortable.directive.coffee | 61 +++++++++++++++++++ .../epics-table/epics-table.controller.coffee | 5 +- .../dashboard/epics-table/epics-table.jade | 7 ++- 4 files changed, 69 insertions(+), 39 deletions(-) delete mode 100644 app/modules/epics/dashboard/epic-sortable/epic-sortable.directive.coffee create mode 100644 app/modules/epics/dashboard/epics-sortable/epics-sortable.directive.coffee diff --git a/app/modules/epics/dashboard/epic-sortable/epic-sortable.directive.coffee b/app/modules/epics/dashboard/epic-sortable/epic-sortable.directive.coffee deleted file mode 100644 index b0d70468..00000000 --- a/app/modules/epics/dashboard/epic-sortable/epic-sortable.directive.coffee +++ /dev/null @@ -1,35 +0,0 @@ -### -# Copyright (C) 2014-2016 Taiga Agile LLC -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -# File: epic-sortable.directive.coffee -### - -EpicSortableDirective = ($parse) -> - link = (scope, el, attrs) -> - - drake = dragula([el[0]]) - - scope.$on "$destroy", -> - el.off() - drake.destroy() - - return { - link: link - } - -EpicSortableDirective.$inject = [] - -angular.module("taigaComponents").directive("tgEpicSortable", EpicSortableDirective) diff --git a/app/modules/epics/dashboard/epics-sortable/epics-sortable.directive.coffee b/app/modules/epics/dashboard/epics-sortable/epics-sortable.directive.coffee new file mode 100644 index 00000000..d9063f7a --- /dev/null +++ b/app/modules/epics/dashboard/epics-sortable/epics-sortable.directive.coffee @@ -0,0 +1,61 @@ +### +# Copyright (C) 2014-2016 Taiga Agile LLC +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +# File: epics-sortable.directive.coffee +### + +EpicsSortableDirective = ($parse) -> + link = (scope, el, attrs) -> + callback = $parse(attrs.tgEpicsSortable) + + drake = dragula([el[0]], { + copySortSource: false + copy: false + mirrorContainer: el[0] + moves: (item) -> + return $(item).is('div.epics-table-body-row') + }) + + drake.on 'dragend', (item) -> + itemEl = $(item) + + epic = itemEl.scope().epic + newIndex = itemEl.index() + + scope.$apply () -> + callback(scope, {epic: epic, newIndex: newIndex}) + + scroll = autoScroll(window, { + margin: 20, + pixels: 30, + scrollWhenOutside: true, + autoScroll: () -> + return this.down && drake.dragging + }) + + scope.$on "$destroy", -> + el.off() + drake.destroy() + + return { + link: link + } + +EpicsSortableDirective.$inject = [ + "$parse" +] + +angular.module("taigaComponents").directive("tgEpicsSortable", EpicsSortableDirective) diff --git a/app/modules/epics/dashboard/epics-table/epics-table.controller.coffee b/app/modules/epics/dashboard/epics-table/epics-table.controller.coffee index a2032a99..37eb275b 100644 --- a/app/modules/epics/dashboard/epics-table/epics-table.controller.coffee +++ b/app/modules/epics/dashboard/epics-table/epics-table.controller.coffee @@ -42,7 +42,8 @@ class EpicsTableController toggleEpicTableOptions: () -> @.displayOptions = !@.displayOptions - reorderEpics: (epic, index) -> - console.log epic, index + reorderEpic: (epic, newIndex) -> + console.log epic, newIndex + module.controller("EpicsTableCtrl", EpicsTableController) diff --git a/app/modules/epics/dashboard/epics-table/epics-table.jade b/app/modules/epics/dashboard/epics-table/epics-table.jade index 1056460c..baaad4e6 100644 --- a/app/modules/epics/dashboard/epics-table/epics-table.jade +++ b/app/modules/epics/dashboard/epics-table/epics-table.jade @@ -88,8 +88,11 @@ mixin epicSwitch(name, model) for="switch-progress" ) +epicSwitch('switch-progress', 'vm.column.progress') - .epics-table-body(tg-epic-sortable) - .epics-table-body-row(tg-repeat="epic in vm.epics track by epic.get('id')") + .epics-table-body(tg-epics-sortable="vm.reorderEpic(epic, newIndex)") + .epics-table-body-row( + tg-repeat="epic in vm.epics track by epic.get('id')" + tg-bind-scope + ) tg-epic-row.e2e-epic( epic="epic" project="vm.project"