Merge pull request #1 from taigaio/backlog-sortable-refactor

Backlog sortable refactor
stable
David Barragán Merino 2014-07-26 18:31:21 +02:00
commit 553096c496
7 changed files with 1205 additions and 1126 deletions

View File

@ -450,7 +450,7 @@ BacklogDirective = ($repo, $rootscope) ->
linkToolbar($scope, $el, $attrs, $ctrl) linkToolbar($scope, $el, $attrs, $ctrl)
linkFilters($scope, $el, $attrs, $ctrl) linkFilters($scope, $el, $attrs, $ctrl)
linkDoomLine($scope, $el, $attrs, $ctrl) # linkDoomLine($scope, $el, $attrs, $ctrl)
$el.find(".backlog-table-body").disableSelection() $el.find(".backlog-table-body").disableSelection()

View File

@ -34,67 +34,51 @@ module = angular.module("taigaBacklog")
## Sortable Directive ## Sortable Directive
############################################################################# #############################################################################
BacklogSortableDirective = ($repo, $rs, $rootscope) -> deleteElement = (el) ->
el.scope().$destroy()
el.off()
el.remove()
#########################
## Drag & Drop Link BacklogSortableDirective = ($repo, $rs, $rootscope) ->
######################### # Notes about jquery bug:
# http://stackoverflow.com/questions/5791886/jquery-draggable-shows- # http://stackoverflow.com/questions/5791886/jquery-draggable-shows-
# helper-in-wrong-place-when-scrolled-down-page # helper-in-wrong-place-when-scrolled-down-page
linkSortable = ($scope, $el, $attrs, $ctrl) -> link = ($scope, $el, $attrs) ->
# State $el.sortable({
oldParentScope = null connectWith: ".sprint-table"
newParentScope = null handle: ".icon-drag-v",
itemEl = null containment: ".wrapper"
tdom = $el dropOnEmpty: true
# With scroll activated, it has strange behavior
deleteElement = (itemEl) -> # with not full screen browser window.
# Completelly remove item and its scope from dom scroll: false
itemEl.scope().$destroy() # A consequence of length of backlog user story item
itemEl.off() # the default tolerance ("intersection") not works properly.
itemEl.remove() tolerance: "pointer"
# Revert on backlog is disabled bacause it works bad. Something
tdom.sortable({ # on the current taiga backlog structure or style makes jquery ui
# handle: ".icon-drag-v", # works unexpectly (in some circumstances calculates wrong
items: "div.sprint-table > div.row, .backlog-table-body > div.row" # position for revert).
revert: false
}) })
tdom.on "sortstop", (event, ui) -> $el.on "sortreceive", (event, ui) ->
# Common state for stop event handler itemUs = ui.item.scope().us
parentEl = ui.item.parent() itemIndex = ui.item.index()
itemEl = ui.item
itemUs = itemEl.scope().us
itemIndex = itemEl.index()
newParentScope = parentEl.scope()
if itemEl.is(".milestone-us-item-row") and parentEl.is(".backlog-table-body") deleteElement(ui.item)
deleteElement(itemEl) $scope.$emit("sprint:us:move", itemUs, itemIndex, null)
$scope.$broadcast("sprint:us:move", itemUs, itemIndex, null)
else if itemEl.is(".us-item-row") and parentEl.is(".sprint-table") $el.on "sortstop", (event, ui) ->
deleteElement(itemEl) # When parent not exists, do nothing
$scope.$broadcast("sprint:us:move", itemUs, itemIndex, newParentScope.sprint.id) if ui.item.parent().length == 0
return
else if parentEl.is(".sprint-table") and newParentScope.sprint.id != oldParentScope.sprint.id itemUs = ui.item.scope().us
deleteElement(itemEl) itemIndex = ui.item.index()
$scope.$broadcast("sprint:us:move", itemUs, itemIndex, newParentScope.sprint.id) $scope.$emit("sprint:us:move", itemUs, itemIndex, null)
else
$scope.$broadcast("sprint:us:move", itemUs, itemIndex, itemUs.milestone)
tdom.on "sortstart", (event, ui) ->
oldParentScope = ui.item.parent().scope()
tdom.on "sort", (event, ui) ->
ui.helper.css("background-color", "#ddd")
tdom.on "sortbeforestop", (event, ui) ->
ui.helper.css("background-color", "transparent")
link = ($scope, $el, $attrs) ->
$ctrl = $el.controller()
linkSortable($scope, $el, $attrs, $ctrl)
$scope.$on "$destroy", -> $scope.$on "$destroy", ->
$el.off() $el.off()
@ -102,9 +86,43 @@ BacklogSortableDirective = ($repo, $rs, $rootscope) ->
return {link: link} return {link: link}
SprintSortableDirective = ($repo, $rs, $rootscope) ->
link = ($scope, $el, $attrs) ->
$el.sortable({
dropOnEmpty: true
connectWith: ".sprint-table,.backlog-table-body"
})
$el.on "sortreceive", (event, ui) ->
itemUs = ui.item.scope().us
itemIndex = ui.item.index()
deleteElement(ui.item)
$scope.$emit("sprint:us:move", itemUs, itemIndex, $scope.sprint.id)
$el.on "sortstop", (event, ui) ->
# When parent not exists, do nothing
if ui.item.parent().length == 0
return
itemUs = ui.item.scope().us
itemIndex = ui.item.index()
$scope.$emit("sprint:us:move", itemUs, itemIndex, $scope.sprint.id)
return {link:link}
module.directive("tgBacklogSortable", [ module.directive("tgBacklogSortable", [
"$tgRepo", "$tgRepo",
"$tgResources", "$tgResources",
"$rootScope", "$rootScope",
BacklogSortableDirective BacklogSortableDirective
]) ])
module.directive("tgSprintSortable", [
"$tgRepo",
"$tgResources",
"$rootScope",
SprintSortableDirective
])

2195
app/js/jquery.ui.git.js vendored

File diff suppressed because it is too large Load Diff

View File

@ -5,7 +5,7 @@ block head
block content block content
div.wrapper(tg-backlog, ng-controller="BacklogController as ctrl", div.wrapper(tg-backlog, ng-controller="BacklogController as ctrl",
ng-init="section='backlog'", tg-backlog-sortable) ng-init="section='backlog'")
sidebar.menu-secondary.extrabar.filters-bar(tg-backlog-filters) sidebar.menu-secondary.extrabar.filters-bar(tg-backlog-filters)
include views/modules/backlog-filters include views/modules/backlog-filters
section.main.backlog section.main.backlog

View File

@ -6,5 +6,5 @@ section.backlog-table-header
span.header-points Points span.header-points Points
span.icon.icon-arrow-bottom span.icon.icon-arrow-bottom
section.backlog-table-body section.backlog-table-body(tg-backlog-sortable)
include ../components/backlog-row include ../components/backlog-row

View File

@ -10,7 +10,8 @@ section.sprints
a.button.button-green(ng-click="ctrl.addNewSprint()", href="", title="Add New US") a.button.button-green(ng-click="ctrl.addNewSprint()", href="", title="Add New US")
span.text + New sprint span.text + New sprint
section.sprint(ng-repeat="sprint in sprints track by sprint.id", tg-backlog-sprint="sprint") section.sprint(ng-repeat="sprint in sprints track by sprint.id"
tg-backlog-sprint="sprint")
header header
div.sprint-name div.sprint-name
a.icon.icon-arrow-up(href="", title="compact Sprint") a.icon.icon-arrow-up(href="", title="compact Sprint")
@ -27,7 +28,7 @@ section.sprints
span.description total span.description total
div.sprint-progress-bar div.sprint-progress-bar
div.current-progress(tg-sprint-progressbar="sprint") div.current-progress(tg-sprint-progressbar="sprint")
div.sprint-table div.sprint-table(tg-sprint-sortable)
div.row.milestone-us-item-row(ng-repeat="us in sprint.user_stories|orderBy:order track by us.id") div.row.milestone-us-item-row(ng-repeat="us in sprint.user_stories|orderBy:order track by us.id")
div.column-us.width-8 div.column-us.width-8
a.us-name.clickable(tg-nav="project-userstories-detail:project=project.slug,ref=us.ref", title="") a.us-name.clickable(tg-nav="project-userstories-detail:project=project.slug,ref=us.ref", title="")

View File

@ -116,6 +116,9 @@
} }
.sprint-table { .sprint-table {
@include slide(1000px, overflow-y); @include slide(1000px, overflow-y);
&.open {
min-height: 50px;
}
.row { .row {
@include table-flex(); @include table-flex();
border-bottom: 1px solid $gray-light; border-bottom: 1px solid $gray-light;