[Backport] fix backlog points

stable
Juanfran 2016-05-17 08:29:09 +02:00
parent b0ab24567a
commit 7a8531ef06
2 changed files with 45 additions and 28 deletions

View File

@ -55,11 +55,12 @@ class BacklogController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.F
"$tgAnalytics", "$tgAnalytics",
"$translate", "$translate",
"$tgLoading", "$tgLoading",
"tgResources" "tgResources",
"$tgQueueModelTransformation"
] ]
constructor: (@scope, @rootscope, @repo, @confirm, @rs, @params, @q, constructor: (@scope, @rootscope, @repo, @confirm, @rs, @params, @q,
@location, @appMetaService, @navUrls, @events, @analytics, @translate, @loading, @rs2) -> @location, @appMetaService, @navUrls, @events, @analytics, @translate, @loading, @rs2, @modelTransform) ->
bindMethods(@) bindMethods(@)
@.page = 1 @.page = 1
@ -958,7 +959,10 @@ UsPointsDirective = ($tgEstimationsService, $repo, $tgTemplate) ->
if estimationProcess.isEditable if estimationProcess.isEditable
bindClickElements() bindClickElements()
estimationProcess.onSelectedPointForRole = (roleId, pointId) -> estimationProcess.onSelectedPointForRole = (roleId, pointId, points) ->
us.points = points
estimationProcess.render()
@save(roleId, pointId).then -> @save(roleId, pointId).then ->
$ctrl.loadProjectStats() $ctrl.loadProjectStats()

View File

@ -45,11 +45,13 @@ LbUsEstimationDirective = ($tgEstimationsService, $rootScope, $repo, $template,
$scope.$watch $attrs.ngModel, (us) -> $scope.$watch $attrs.ngModel, (us) ->
if us if us
estimationProcess = $tgEstimationsService.create($el, us, $scope.project) estimationProcess = $tgEstimationsService.create($el, us, $scope.project)
estimationProcess.onSelectedPointForRole = (roleId, pointId) -> estimationProcess.onSelectedPointForRole = (roleId, pointId, points) ->
us.points = points
estimationProcess.render()
$scope.$apply -> $scope.$apply ->
$model.$setViewValue(us) $model.$setViewValue(us)
estimationProcess.render = () -> estimationProcess.render = () ->
ctx = { ctx = {
totalPoints: @calculateTotalPoints() totalPoints: @calculateTotalPoints()
@ -80,7 +82,7 @@ module.directive("tgLbUsEstimation", ["$tgEstimationsService", "$rootScope", "$t
## User story estimation directive ## User story estimation directive
############################################################################# #############################################################################
UsEstimationDirective = ($tgEstimationsService, $rootScope, $repo, $template, $compile) -> UsEstimationDirective = ($tgEstimationsService, $rootScope, $repo, $template, $compile, $modelTransform, $confirm) ->
# Display the points of a US and you can edit it. # Display the points of a US and you can edit it.
# #
# Example: # Example:
@ -91,14 +93,25 @@ UsEstimationDirective = ($tgEstimationsService, $rootScope, $repo, $template, $c
# - scope.project object # - scope.project object
link = ($scope, $el, $attrs, $model) -> link = ($scope, $el, $attrs, $model) ->
save = (points) ->
transform = $modelTransform.save (us) =>
us.points = points
return us
onError = =>
$confirm.notify("error")
return transform.then(null, onError)
$scope.$watchCollection () -> $scope.$watchCollection () ->
return $model.$modelValue && $model.$modelValue.points return $model.$modelValue && $model.$modelValue.points
, () -> , () ->
us = $model.$modelValue us = $model.$modelValue
if us if us
estimationProcess = $tgEstimationsService.create($el, us, $scope.project) estimationProcess = $tgEstimationsService.create($el, us, $scope.project)
estimationProcess.onSelectedPointForRole = (roleId, pointId) -> estimationProcess.onSelectedPointForRole = (roleId, pointId, points) ->
@save(roleId, pointId).then () -> save(points).then () ->
$rootScope.$broadcast("object:updated") $rootScope.$broadcast("object:updated")
estimationProcess.render = () -> estimationProcess.render = () ->
@ -125,14 +138,15 @@ UsEstimationDirective = ($tgEstimationsService, $rootScope, $repo, $template, $c
} }
module.directive("tgUsEstimation", ["$tgEstimationsService", "$rootScope", "$tgRepo", module.directive("tgUsEstimation", ["$tgEstimationsService", "$rootScope", "$tgRepo",
"$tgTemplate", "$compile", UsEstimationDirective]) "$tgTemplate", "$compile", "$tgQueueModelTransformation",
"$tgConfirm", UsEstimationDirective])
############################################################################# #############################################################################
## Estimations service ## Estimations service
############################################################################# #############################################################################
EstimationsService = ($template, $modelTransform, $repo, $confirm, $q) -> EstimationsService = ($template, $repo, $confirm, $q, $qqueue) ->
pointsTemplate = $template.get("common/estimation/us-estimation-points.html", true) pointsTemplate = $template.get("common/estimation/us-estimation-points.html", true)
class EstimationProcess class EstimationProcess
@ -146,23 +160,17 @@ EstimationsService = ($template, $modelTransform, $repo, $confirm, $q) ->
save: (roleId, pointId) -> save: (roleId, pointId) ->
deferred = $q.defer() deferred = $q.defer()
$qqueue.add () =>
onSuccess = =>
deferred.resolve()
transform = $modelTransform.save (us) => onError = =>
points = _.clone(@us.points, true) $confirm.notify("error")
points[roleId] = pointId @us.revert()
@render()
deferred.reject()
us.points = points $repo.save(@us).then(onSuccess, onError)
return us
onSuccess = =>
deferred.resolve()
onError = =>
$confirm.notify("error")
deferred.reject()
transform.then(onSuccess, onError)
return deferred.promise return deferred.promise
@ -206,7 +214,12 @@ EstimationsService = ($template, $modelTransform, $repo, $confirm, $q) ->
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()
@onSelectedPointForRole(roleId, pointId)
points = _.clone(@us.points, true)
points[roleId] = pointId
@onSelectedPointForRole(roleId, pointId, points)
renderPointsSelector: (roleId, target) -> renderPointsSelector: (roleId, target) ->
points = _.map @points, (point) => points = _.map @points, (point) =>
@ -252,5 +265,5 @@ EstimationsService = ($template, $modelTransform, $repo, $confirm, $q) ->
create: create create: create
} }
module.factory("$tgEstimationsService", ["$tgTemplate", "$tgQueueModelTransformation", "$tgRepo", "$tgConfirm", module.factory("$tgEstimationsService", ["$tgTemplate", "$tgRepo", "$tgConfirm",
"$q", EstimationsService]) "$q", "$tgQqueue", EstimationsService])