From 47b94f95d757f0eba01807c51f761c295a827fa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Espino?= Date: Wed, 17 Sep 2014 12:05:11 +0200 Subject: [PATCH] Fix bug #1017 --- app/coffee/modules/backlog/lightboxes.coffee | 26 ++++++++++++-------- app/coffee/modules/common/components.coffee | 9 +++---- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/app/coffee/modules/backlog/lightboxes.coffee b/app/coffee/modules/backlog/lightboxes.coffee index 399d7dbd..15802013 100644 --- a/app/coffee/modules/backlog/lightboxes.coffee +++ b/app/coffee/modules/backlog/lightboxes.coffee @@ -49,7 +49,6 @@ CreateEditSprint = ($repo, $confirm, $rs, $rootscope, lightboxService, $loading) newSprint.estimated_start = moment(newSprint.estimated_start).format("YYYY-MM-DD") newSprint.estimated_finish = moment(newSprint.estimated_finish).format("YYYY-MM-DD") promise = $repo.create("milestones", newSprint) - else newSprint.setAttr("estimated_start", moment(newSprint.estimated_start).format("YYYY-MM-DD")) newSprint.setAttr("estimated_finish", moment(newSprint.estimated_finish).format("YYYY-MM-DD")) @@ -91,19 +90,26 @@ CreateEditSprint = ($repo, $confirm, $rs, $rootscope, lightboxService, $loading) $scope.sprint.project = projectId $scope.sprint.name = null $scope.sprint.slug = null + + lastSprint = $scope.sprints[0] + + estimatedStart = moment() if $scope.sprint.estimated_start - $scope.sprint.estimated_start = moment($scope.sprint.estimated_start).format("DD MMM YYYY") - else - $scope.sprint.estimated_start = moment().format("DD MMM YYYY") + estimatedStart = moment($scope.sprint.estimated_start) + else if lastSprint? + estimatedStart = moment(lastSprint.estimated_finish) + $scope.sprint.estimated_start = estimatedStart.format("DD MMM YYYY") + + estimatedFinish = moment().add(2, "weeks") if $scope.sprint.estimated_finish - $scope.sprint.estimated_finish = moment($scope.sprint.estimated_finish).format("DD MMM YYYY") - else - $scope.sprint.estimated_finish = moment().format("DD MMM YYYY") + estimatedFinish = moment($scope.sprint.estimated_finish) + else if lastSprint? + estimatedFinish = moment(lastSprint.estimated_finish).add(2, "weeks") + $scope.sprint.estimated_finish = estimatedFinish.format("DD MMM YYYY") lastSprintNameDom = $el.find(".last-sprint-name") - sprintName = $scope.sprints?[0]?.name - if sprintName? - lastSprintNameDom.html(" last sprint is #{sprintName} ;-) ") + if lastSprint?.name? + lastSprintNameDom.html(" last sprint is #{lastSprint.name} ;-) ") $el.find(".delete-sprint").hide() $el.find(".title").text("New sprint") #TODO i18n diff --git a/app/coffee/modules/common/components.coffee b/app/coffee/modules/common/components.coffee index 098e4fea..1ca1381c 100644 --- a/app/coffee/modules/common/components.coffee +++ b/app/coffee/modules/common/components.coffee @@ -99,12 +99,9 @@ DateSelectorDirective =-> $scope.$watch $attrs.lessThan, (val) -> $el.picker.setMaxDate(moment(val)) - $scope.$on "sprints:loaded", (ctx, sprints) => - if sprints.length > 0 - estimatedStart = sprints[0].estimated_finish - selectedDate = estimatedStart - $el.val(moment(estimatedStart).format("DD MMM YYYY")) - $el.picker.setDate(estimatedStart) + + $scope.$watch $attrs.ngModel, (val) -> + $el.picker.setDate(val) if val? return { link: link