Refactor tg-us-status directive: Update tg-us-estimations directive to support inline-edition
parent
d3fbfce06d
commit
235a38641e
|
@ -460,7 +460,18 @@ module.directive("tgUsTasksProgressDisplay", UsTasksProgressDisplayDirective)
|
||||||
## User story estimation directive
|
## User story estimation directive
|
||||||
#############################################################################
|
#############################################################################
|
||||||
|
|
||||||
UsEstimationDirective = ($log) ->
|
UsEstimationDirective = ($rootScope, $repo, $confirm) ->
|
||||||
|
# Display the points of a US and you can edit it.
|
||||||
|
#
|
||||||
|
# Example:
|
||||||
|
# tg-us-estimation-progress-bar(ng-model="us")
|
||||||
|
#
|
||||||
|
# Requirements:
|
||||||
|
# - Us object (ng-model)
|
||||||
|
# - scope.project object
|
||||||
|
# Optionals:
|
||||||
|
# - save-after-modify (boolean): save object after modify
|
||||||
|
|
||||||
mainTemplate = _.template("""
|
mainTemplate = _.template("""
|
||||||
<ul class="points-per-role">
|
<ul class="points-per-role">
|
||||||
<li class="total">
|
<li class="total">
|
||||||
|
@ -491,8 +502,11 @@ UsEstimationDirective = ($log) ->
|
||||||
</ul>
|
</ul>
|
||||||
""")
|
""")
|
||||||
|
|
||||||
link = ($scope, $el, $attrs) ->
|
link = ($scope, $el, $attrs, $model) ->
|
||||||
|
saveAfterModify = $attrs.saveAfterModify or false
|
||||||
|
|
||||||
render = (us) ->
|
render = (us) ->
|
||||||
|
console.log us.points
|
||||||
totalPoints = us.total_points or 0
|
totalPoints = us.total_points or 0
|
||||||
computableRoles = _.filter($scope.project.roles, "computable")
|
computableRoles = _.filter($scope.project.roles, "computable")
|
||||||
|
|
||||||
|
@ -537,19 +551,13 @@ UsEstimationDirective = ($log) ->
|
||||||
return "0"
|
return "0"
|
||||||
return _.reduce(values, (acc, num) -> acc + num)
|
return _.reduce(values, (acc, num) -> acc + num)
|
||||||
|
|
||||||
$scope.$watch $attrs.ngModel, (us) ->
|
|
||||||
render(us) if us
|
|
||||||
|
|
||||||
$scope.$on "$destroy", ->
|
|
||||||
$el.off()
|
|
||||||
|
|
||||||
$el.on "click", ".total.clickable", (event) ->
|
$el.on "click", ".total.clickable", (event) ->
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
event.stopPropagation()
|
event.stopPropagation()
|
||||||
target = angular.element(event.currentTarget)
|
target = angular.element(event.currentTarget)
|
||||||
roleId = target.data("role-id")
|
roleId = target.data("role-id")
|
||||||
|
|
||||||
us = $scope.$eval($attrs.ngModel)
|
us = $model.$modelValue
|
||||||
renderPoints(target, us, roleId)
|
renderPoints(target, us, roleId)
|
||||||
|
|
||||||
target.siblings().removeClass('active')
|
target.siblings().removeClass('active')
|
||||||
|
@ -559,28 +567,48 @@ UsEstimationDirective = ($log) ->
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
event.stopPropagation()
|
event.stopPropagation()
|
||||||
|
|
||||||
us = $scope.$eval($attrs.ngModel)
|
|
||||||
|
|
||||||
target = angular.element(event.currentTarget)
|
target = angular.element(event.currentTarget)
|
||||||
roleId = target.data("role-id")
|
roleId = target.data("role-id")
|
||||||
pointId = target.data("point-id")
|
pointId = target.data("point-id")
|
||||||
|
|
||||||
$el.find(".popover").popover().close()
|
$el.find(".popover").popover().close()
|
||||||
|
|
||||||
|
us = $model.$modelValue
|
||||||
|
|
||||||
points = _.clone(us.points, true)
|
points = _.clone(us.points, true)
|
||||||
points[roleId] = pointId
|
points[roleId] = pointId
|
||||||
|
|
||||||
|
# NOTE: your past self wants that you make a refactor of this
|
||||||
$scope.$apply ->
|
$scope.$apply ->
|
||||||
us.points = points
|
us.points = points
|
||||||
us.total_points = calculateTotalPoints(us)
|
us.total_points = calculateTotalPoints(us)
|
||||||
render(us)
|
|
||||||
|
if saveAfterModify
|
||||||
|
onSuccess = ->
|
||||||
|
$repo.refresh(us).then ->
|
||||||
|
render(us)
|
||||||
|
$rootScope.$broadcast("history:reload")
|
||||||
|
onError = ->
|
||||||
|
$repo.refresh(us).then ->
|
||||||
|
render(us)
|
||||||
|
$confirm.notify("error")
|
||||||
|
$repo.save(us).then(onSuccess, onError)
|
||||||
|
else
|
||||||
|
render(us)
|
||||||
|
|
||||||
|
$scope.$watch $attrs.ngModel, (us) ->
|
||||||
|
render(us) if us
|
||||||
|
|
||||||
|
$scope.$on "$destroy", ->
|
||||||
|
$el.off()
|
||||||
|
|
||||||
return {
|
return {
|
||||||
link: link
|
link: link
|
||||||
restrict: "EA"
|
restrict: "EA"
|
||||||
|
require: "ngModel"
|
||||||
}
|
}
|
||||||
|
|
||||||
module.directive("tgUsEstimation", UsEstimationDirective)
|
module.directive("tgUsEstimation", ["$rootScope", "$tgRepo", "$tgConfirm", UsEstimationDirective])
|
||||||
|
|
||||||
|
|
||||||
#############################################################################
|
#############################################################################
|
||||||
|
|
|
@ -54,6 +54,7 @@ block content
|
||||||
h1(tg-us-status-display, ng-model="us")
|
h1(tg-us-status-display, ng-model="us")
|
||||||
div.us-detail-progress-bar(tg-us-tasks-progress-display, ng-model="tasks")
|
div.us-detail-progress-bar(tg-us-tasks-progress-display, ng-model="tasks")
|
||||||
div.us-created-by(tg-created-by-display, ng-model="us")
|
div.us-created-by(tg-created-by-display, ng-model="us")
|
||||||
|
tg-us-estimation(ng-model="us", save-after-modify="true")
|
||||||
|
|
||||||
section.us-assigned-to(tg-assigned-to, ng-model="us")
|
section.us-assigned-to(tg-assigned-to, ng-model="us")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue