From ffed61dfeb57cdf4091224ba5b2cfa60189cd2af Mon Sep 17 00:00:00 2001 From: Juanfran Date: Tue, 19 Aug 2014 12:08:08 +0200 Subject: [PATCH] fix sprint progress bar directive --- app/coffee/modules/backlog/sprints.coffee | 7 ++++- app/coffee/modules/common/components.coffee | 29 +++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/app/coffee/modules/backlog/sprints.coffee b/app/coffee/modules/backlog/sprints.coffee index 3f4fdc09..c4f6f91b 100644 --- a/app/coffee/modules/backlog/sprints.coffee +++ b/app/coffee/modules/backlog/sprints.coffee @@ -54,7 +54,12 @@ BacklogSprintDirective = ($repo, $rootscope) -> # Update progress bars $scope.$watch $attrs.tgBacklogSprint, (value) -> sprint = $scope.$eval($attrs.tgBacklogSprint) - progressPercentage = Math.round(100 * (sprint.closed_points / sprint.total_points)) + + if sprint.total_points + progressPercentage = Math.round(100 * (sprint.closed_points / sprint.total_points)) + else + progressPercentage = 0 + $el.find(".current-progress").css("width", "#{progressPercentage}%") $el.find(".sprint-table").disableSelection() diff --git a/app/coffee/modules/common/components.coffee b/app/coffee/modules/common/components.coffee index b0fcd153..1ad39fff 100644 --- a/app/coffee/modules/common/components.coffee +++ b/app/coffee/modules/common/components.coffee @@ -46,6 +46,35 @@ DateRangeDirective = -> module.directive("tgDateRange", DateRangeDirective) +############################################################################# +## Sprint Progress Bar Directive +############################################################################# + +SprintProgressBarDirective = -> + renderProgress = ($el, percentage, visual_percentage) -> + if $el.hasClass(".current-progress") + $el.css("width", "#{percentage}%") + else + $el.find(".current-progress").css("width", "#{visual_percentage}%") + $el.find(".number").html("#{percentage} %") + + link = ($scope, $el, $attrs) -> + bindOnce $scope, $attrs.tgSprintProgressbar, (sprint) -> + closedPoints = sprint.closed_points + totalPoints = sprint.total_points + percentage = 0 + percentage = Math.round(100 * (closedPoints/totalPoints)) if totalPoints != 0 + visual_percentage = 0 + #Visual hack for .current-progress bar + visual_percentage = Math.round(98 * (closedPoints/totalPoints)) if totalPoints != 0 + + renderProgress($el, percentage, visual_percentage) + + return {link: link} + +module.directive("tgSprintProgressbar", SprintProgressBarDirective) + + ############################################################################# ## Date Selector Directive (using pikaday) #############################################################################