From ec04907d4474885373e7ce4ab7de8d1692380f91 Mon Sep 17 00:00:00 2001 From: Juanfran Date: Tue, 21 Jul 2015 08:21:44 +0200 Subject: [PATCH] issue 3074 - the new sprint date starts at the end of the last open sprint --- app/coffee/modules/backlog/lightboxes.coffee | 27 +++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/app/coffee/modules/backlog/lightboxes.coffee b/app/coffee/modules/backlog/lightboxes.coffee index cd72905e..cf952c4e 100644 --- a/app/coffee/modules/backlog/lightboxes.coffee +++ b/app/coffee/modules/backlog/lightboxes.coffee @@ -105,6 +105,15 @@ CreateEditSprint = ($repo, $confirm, $rs, $rootscope, lightboxService, $loading, $confirm.notify("error") $repo.remove($scope.sprint).then(onSuccess, onError) + getLastSprint = -> + openSprints = _.filter $scope.sprints, (sprint) -> + return !sprint.closed + + sortedSprints = _.sortBy openSprints, (sprint) -> + return moment(sprint.estimated_finish, 'YYYY-MM-DD').format('X') + + return sortedSprints[sortedSprints.length - 1] + $scope.$on "sprintform:create", (event, projectId) -> form = $el.find("form").checksley() form.reset() @@ -115,20 +124,24 @@ CreateEditSprint = ($repo, $confirm, $rs, $rootscope, lightboxService, $loading, $scope.sprint.name = null $scope.sprint.slug = null - lastSprint = $scope.sprints[0] + lastSprint = getLastSprint() estimatedStart = moment() - if $scope.sprint.estimated_start - estimatedStart = moment($scope.sprint.estimated_start) - else if lastSprint? + + if lastSprint estimatedStart = moment(lastSprint.estimated_finish) + else if $scope.sprint.estimated_start + estimatedStart = moment($scope.sprint.estimated_start) + $scope.sprint.estimated_start = estimatedStart.format(prettyDate) estimatedFinish = moment().add(2, "weeks") - if $scope.sprint.estimated_finish - estimatedFinish = moment($scope.sprint.estimated_finish) - else if lastSprint? + + if lastSprint estimatedFinish = moment(lastSprint.estimated_finish).add(2, "weeks") + else if $scope.sprint.estimated_finish + estimatedFinish = moment($scope.sprint.estimated_finish) + $scope.sprint.estimated_finish = estimatedFinish.format(prettyDate) lastSprintNameDom = $el.find(".last-sprint-name")