add move to latest sprint option in backlog

stable
Juanfran 2015-12-10 14:57:37 +01:00 committed by Xavier Julián
parent ceb9cbbe3f
commit 31058d801c
4 changed files with 55 additions and 19 deletions

View File

@ -198,6 +198,9 @@ class BacklogController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.F
@scope.sprintsCounter = sprints.length @scope.sprintsCounter = sprints.length
@scope.sprintsById = groupBy(sprints, (x) -> x.id) @scope.sprintsById = groupBy(sprints, (x) -> x.id)
@rootscope.$broadcast("sprints:loaded", sprints) @rootscope.$broadcast("sprints:loaded", sprints)
@scope.currentSprint = @.findCurrentSprint()
return sprints return sprints
restoreFilters: -> restoreFilters: ->
@ -591,6 +594,15 @@ class BacklogController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.F
addNewSprint: () -> addNewSprint: () ->
@rootscope.$broadcast("sprintform:create", @scope.projectId) @rootscope.$broadcast("sprintform:create", @scope.projectId)
findCurrentSprint: () ->
currentDate = new Date().getTime()
return _.find @scope.sprints, (sprint) ->
start = moment(sprint.estimated_start, 'YYYY-MM-DD').format('x')
end = moment(sprint.estimated_finish, 'YYYY-MM-DD').format('x')
return currentDate >= start && currentDate <= end
module.controller("BacklogController", BacklogController) module.controller("BacklogController", BacklogController)
############################################################################# #############################################################################
@ -641,40 +653,56 @@ BacklogDirective = ($repo, $rootscope, $translate) ->
## Move to current sprint link ## Move to current sprint link
linkToolbar = ($scope, $el, $attrs, $ctrl) -> linkToolbar = ($scope, $el, $attrs, $ctrl) ->
moveToCurrentSprint = (selectedUss) -> getUsToMove = () ->
# Calculating the us's to be modified
ussDom = $el.find(".backlog-table-body input:checkbox:checked")
return _.map ussDom, (item) ->
item = $(item).closest('.tg-scope')
itemScope = item.scope()
itemScope.us.milestone = $scope.sprints[0].id
return itemScope.us
moveUssToSprint = (selectedUss, sprint) ->
ussCurrent = _($scope.userstories) ussCurrent = _($scope.userstories)
# Remove them from backlog # Remove them from backlog
$scope.userstories = ussCurrent.without.apply(ussCurrent, selectedUss).value() #$scope.userstories = ussCurrent.without.apply(ussCurrent, selectedUss).value()
extraPoints = _.map(selectedUss, (v, k) -> v.total_points) extraPoints = _.map(selectedUss, (v, k) -> v.total_points)
totalExtraPoints = _.reduce(extraPoints, (acc, num) -> acc + num) totalExtraPoints = _.reduce(extraPoints, (acc, num) -> acc + num)
# Add them to current sprint # Add them to current sprint
$scope.sprints[0].user_stories = _.union($scope.sprints[0].user_stories, selectedUss) sprint.user_stories = _.union(sprint.user_stories, selectedUss)
# Update the total of points # Update the total of points
$scope.sprints[0].total_points += totalExtraPoints sprint.total_points += totalExtraPoints
$repo.saveAll(selectedUss).then -> $repo.saveAll(selectedUss).then ->
$ctrl.loadSprints() $ctrl.loadSprints()
$ctrl.loadProjectStats() $ctrl.loadProjectStats()
$el.find(".move-to-sprint").hide()
moveToCurrentSprint = (selectedUss) ->
moveUssToSprint(selectedUss, $scope.currentSprint)
moveToLatestSprint = (selectedUss) ->
moveUssToSprint(selectedUss, $scope.sprints[0])
shiftPressed = false shiftPressed = false
lastChecked = null lastChecked = null
checkSelected = (target) -> checkSelected = (target) ->
lastChecked = target.closest(".us-item-row") lastChecked = target.closest(".us-item-row")
moveToCurrentSprintDom = $el.find("#move-to-current-sprint") target.closest('.us-item-row').toggleClass('ui-multisortable-multiple')
moveToSprintDom = $el.find(".move-to-sprint")
selectedUsDom = $el.find(".backlog-table-body input:checkbox:checked") selectedUsDom = $el.find(".backlog-table-body input:checkbox:checked")
if selectedUsDom.length > 0 and $scope.sprints.length > 0 if selectedUsDom.length > 0 and $scope.sprints.length > 0
moveToCurrentSprintDom.show() moveToSprintDom.show()
else else
moveToCurrentSprintDom.hide() moveToSprintDom.hide()
target.closest('.us-item-row').toggleClass('ui-multisortable-multiple')
$(window).on "keydown.shift-pressed keyup.shift-pressed", (event) -> $(window).on "keydown.shift-pressed keyup.shift-pressed", (event) ->
shiftPressed = !!event.shiftKey shiftPressed = !!event.shiftKey
@ -704,15 +732,13 @@ BacklogDirective = ($repo, $rootscope, $translate) ->
target.closest(".us-item-row").toggleClass('is-checked') target.closest(".us-item-row").toggleClass('is-checked')
checkSelected(target) checkSelected(target)
$el.on "click", "#move-to-current-sprint", (event) => $el.on "click", "#move-to-latest-sprint", (event) =>
# Calculating the us's to be modified ussToMove = getUsToMove()
ussDom = $el.find(".backlog-table-body input:checkbox:checked")
ussToMove = _.map ussDom, (item) -> $scope.$apply(_.partial(moveToLatestSprint, ussToMove))
item = $(item).closest('.tg-scope')
itemScope = item.scope() $el.on "click", "#move-to-current-sprint", (event) =>
itemScope.us.milestone = $scope.sprints[0].id ussToMove = getUsToMove()
return itemScope.us
$scope.$apply(_.partial(moveToCurrentSprint, ussToMove)) $scope.$apply(_.partial(moveToCurrentSprint, ussToMove))

View File

@ -952,6 +952,7 @@
"CUSTOMIZE_GRAPH_ADMIN": "Admin", "CUSTOMIZE_GRAPH_ADMIN": "Admin",
"CUSTOMIZE_GRAPH_TITLE": "Set up the points and sprints through the Admin", "CUSTOMIZE_GRAPH_TITLE": "Set up the points and sprints through the Admin",
"MOVE_US_TO_CURRENT_SPRINT": "Move to Current Sprint", "MOVE_US_TO_CURRENT_SPRINT": "Move to Current Sprint",
"MOVE_US_TO_LATEST_SPRINT": "Move to latest Sprint",
"SHOW_FILTERS": "Show filters", "SHOW_FILTERS": "Show filters",
"SHOW_TAGS": "Show tags", "SHOW_TAGS": "Show tags",
"EMPTY": "The backlog is empty!", "EMPTY": "The backlog is empty!",

View File

@ -24,13 +24,22 @@ div.wrapper(tg-backlog, ng-controller="BacklogController as ctrl",
div.backlog-menu div.backlog-menu
div.backlog-table-options div.backlog-table-options
a.trans-button.move-to-current-sprint( a.trans-button.move-to-current-sprint.move-to-sprint(
ng-if="currentSprint"
href="" href=""
title="{{'BACKLOG.MOVE_US_TO_CURRENT_SPRINT' | translate}}" title="{{'BACKLOG.MOVE_US_TO_CURRENT_SPRINT' | translate}}"
id="move-to-current-sprint" id="move-to-current-sprint"
) )
span.icon.icon-move span.icon.icon-move
span.text(translate="BACKLOG.MOVE_US_TO_CURRENT_SPRINT") span.text(translate="BACKLOG.MOVE_US_TO_CURRENT_SPRINT")
a.trans-button.move-to-latest-sprint.move-to-sprint(
ng-if="!currentSprint"
href=""
title="{{'BACKLOG.MOVE_US_TO_LATEST_SPRINT' | translate}}"
id="move-to-latest-sprint"
)
span.icon.icon-move
span.text(translate="BACKLOG.MOVE_US_TO_LATEST_SPRINT")
a.trans-button( a.trans-button(
ng-if="userstories.length" ng-if="userstories.length"
href="" href=""

View File

@ -19,7 +19,7 @@
background: lighten($gray, 30%); background: lighten($gray, 30%);
} }
} }
&.move-to-current-sprint { &.move-to-sprint {
display: none; display: none;
} }
} }