diff --git a/app/coffee/modules/backlog/sprints.coffee b/app/coffee/modules/backlog/sprints.coffee index 5dba9b92..fcdcd8b6 100644 --- a/app/coffee/modules/backlog/sprints.coffee +++ b/app/coffee/modules/backlog/sprints.coffee @@ -21,44 +21,25 @@ taiga = @.taiga -mixOf = @.taiga.mixOf -toggleText = @.taiga.toggleText -scopeDefer = @.taiga.scopeDefer -bindOnce = @.taiga.bindOnce -groupBy = @.taiga.groupBy - module = angular.module("taigaBacklog") + ############################################################################# -## Sprint Directive +## Sprint Actions Directive ############################################################################# BacklogSprintDirective = ($repo, $rootscope) -> - ## Common parts - linkCommon = ($scope, $el, $attrs, $ctrl) -> - sprint = $scope.$eval($attrs.tgBacklogSprint) - if $scope.$first - $el.addClass("sprint-current") - $el.find(".sprint-table").addClass('open') - - else if sprint.closed - $el.addClass("sprint-closed") - - else if not $scope.$first and not sprint.closed - $el.addClass("sprint-old-open") - - # Update progress bars - $scope.$watch $attrs.tgBacklogSprint, (value) -> + link = ($scope, $el, $attrs) -> + $scope.$watch $attrs.tgBacklogSprint, (sprint) -> sprint = $scope.$eval($attrs.tgBacklogSprint) - 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() + if $scope.$first + $el.addClass("sprint-current") + $el.find(".sprint-table").addClass('open') + else if sprint.closed + $el.addClass("sprint-closed") + else if not $scope.$first and not sprint.closed + $el.addClass("sprint-old-open") # Event Handlers $el.on "click", ".sprint-name > .icon-arrow-up", (event) -> @@ -67,15 +48,92 @@ BacklogSprintDirective = ($repo, $rootscope) -> $el.find(".sprint-table").toggleClass('open') $el.on "click", ".sprint-name > .icon-edit", (event) -> + sprint = $scope.$eval($attrs.tgBacklogSprint) $rootscope.$broadcast("sprintform:edit", sprint) - link = ($scope, $el, $attrs) -> - $ctrl = $el.closest("div.wrapper").controller() - linkCommon($scope, $el, $attrs, $ctrl) - $scope.$on "$destroy", -> $el.off() return {link: link} module.directive("tgBacklogSprint", ["$tgRepo", "$rootScope", BacklogSprintDirective]) + + +############################################################################# +## Sprint Header Directive +############################################################################# + +BacklogSprintHeaderDirective = ($navUrls) -> + template = _.template(""" +
+ + + <% if(isVisible){ %> + + <%- name %> + + <% } %> + + <% if(isEditable){ %> + + <% } %> +
+ +
+
<%- estimatedDateRange %>
+ +
+ """) + + link = ($scope, $el, $attrs, $model) -> + isEditable = -> + return $scope.project.my_permissions.indexOf("modify_milestone") != -1 + + isVisible = -> + return $scope.project.my_permissions.indexOf("view_milestones") != -1 + + render = (sprint) -> + taskboardUrl = $navUrls.resolve("project-taskboard", + {project: $scope.project.slug, sprint: sprint.slug}) + + start = moment(sprint.estimated_start).format("DD MMM YYYY") + finish = moment(sprint.estimated_finish).format("DD MMM YYYY") + estimatedDateRange = "#{start}-#{finish}" + + ctx = { + name: sprint.name + taskboardUrl: taskboardUrl + estimatedDateRange: estimatedDateRange + closedPoints: sprint.closed_points or 0 + totalPoints: sprint.total_points or 0 + isVisible: isVisible() + isEditable: isEditable() + } + $el.html(template(ctx)) + + + $scope.$watch $attrs.ngModel, (sprint) -> + render(sprint) + + $scope.$on "sprintform:edit:success", -> + render($model.$modelValue) + + $scope.$on "$destroy", -> + $el.off() + + return { + link: link + restrict: "EA" + require: "ngModel" + } + +module.directive("tgBacklogSprintHeader", ["$tgNavUrls", "$tgRepo", "$rootScope", BacklogSprintHeaderDirective]) diff --git a/app/partials/views/modules/sprints.jade b/app/partials/views/modules/sprints.jade index b6168715..4a39c413 100644 --- a/app/partials/views/modules/sprints.jade +++ b/app/partials/views/modules/sprints.jade @@ -12,39 +12,23 @@ section.sprints tg-check-permission="add_milestone") span.text + New sprint - section.sprint(ng-repeat="sprint in sprints track by sprint.id" - tg-backlog-sprint="sprint") - header - div.sprint-name - a.icon.icon-arrow-up(href="", title="Compact Sprint") - a(href="", tg-bo-title="'Go to Taskboard of ' + sprint.name", - tg-nav="project-taskboard:project=project.slug,sprint=sprint.slug", - tg-check-permission="view_milestones") - span {{ sprint.name }} - a.icon.icon-edit(tg-check-permission="modify_milestone", href="", title="Edit Sprint") + section.sprint(ng-repeat="sprint in sprints track by sprint.id" tg-backlog-sprint="sprint") + header(tg-backlog-sprint-header, ng-model="sprint") - div.sprint-summary - div.sprint-date(tg-date-range="sprint.estimated_start,sprint.estimated_finish") - ul - li - span.number(ng-bind="sprint.closed_points|default:''") -- - span.description closed - li - span.number(ng-bind="sprint.total_points|default:''") - span.description total - - div.sprint-progress-bar(tg-progress-bar="100 * sprint.closed_points / total_points") + div.sprint-progress-bar(tg-progress-bar="100 * sprint.closed_points / sprint.total_points") div.sprint-table(tg-sprint-sortable) div.row.milestone-us-item-row(ng-repeat="us in sprint.user_stories track by us.id") div.column-us.width-8 a.us-name.clickable(tg-nav="project-userstories-detail:project=project.slug,ref=us.ref", - tg-bo-title="'#' + us.ref + ' ' + us.subject", ng-class="{closed: us.is_closed}") + tg-bo-title="'#' + us.ref + ' ' + us.subject", + ng-class="{closed: us.is_closed}") span(tg-bo-ref="us.ref") span(tg-bo-bind="us.subject") div.column-points.width-1(tg-bo-bind="us.total_points", ng-class="{closed: us.is_closed}") - a.button.button-gray(href="", tg-bo-title="'Go to Taskboard of ' + sprint.name", + a.button.button-gray(tg-bo-title="'Go to Taskboard of ' + sprint.name", tg-nav="project-taskboard:project=project.slug,sprint=sprint.slug", tg-check-permission="view_milestones") + span Sprint Taskboard