Refactor tg-us-estimation. Fuck Yeah!!! 👏 🤘 👏 🤘
parent
8032b37773
commit
2627a03e29
|
@ -263,7 +263,7 @@ UsEstimationDirective = ($rootScope, $repo, $confirm) ->
|
||||||
<span class="role">total</span>
|
<span class="role">total</span>
|
||||||
</li>
|
</li>
|
||||||
<% _.each(roles, function(role) { %>
|
<% _.each(roles, function(role) { %>
|
||||||
<li class="total clickable" data-role-id="<%- role.id %>">
|
<li class="total <% if(editable){ %>clickable<% } %>" data-role-id="<%- role.id %>">
|
||||||
<span class="points"><%- role.points %></span>
|
<span class="points"><%- role.points %></span>
|
||||||
<span class="role"><%- role.name %></span></li>
|
<span class="role"><%- role.name %></span></li>
|
||||||
<% }); %>
|
<% }); %>
|
||||||
|
@ -289,6 +289,11 @@ UsEstimationDirective = ($rootScope, $repo, $confirm) ->
|
||||||
link = ($scope, $el, $attrs, $model) ->
|
link = ($scope, $el, $attrs, $model) ->
|
||||||
saveAfterModify = $attrs.saveAfterModify or false
|
saveAfterModify = $attrs.saveAfterModify or false
|
||||||
|
|
||||||
|
isEditable = ->
|
||||||
|
if $model.$modelValue.id
|
||||||
|
return $scope.project.my_permissions.indexOf("modify_us") != -1
|
||||||
|
return $scope.project.my_permissions.indexOf("add_us") != -1
|
||||||
|
|
||||||
render = (us) ->
|
render = (us) ->
|
||||||
totalPoints = us.total_points or 0
|
totalPoints = us.total_points or 0
|
||||||
computableRoles = _.filter($scope.project.roles, "computable")
|
computableRoles = _.filter($scope.project.roles, "computable")
|
||||||
|
@ -301,7 +306,12 @@ UsEstimationDirective = ($rootScope, $repo, $confirm) ->
|
||||||
role.points = if pointObj? and pointObj.name? then pointObj.name else "?"
|
role.points = if pointObj? and pointObj.name? then pointObj.name else "?"
|
||||||
return role
|
return role
|
||||||
|
|
||||||
html = mainTemplate({totalPoints: totalPoints, roles: roles})
|
ctx = {
|
||||||
|
totalPoints: totalPoints
|
||||||
|
roles: roles
|
||||||
|
editable: isEditable()
|
||||||
|
}
|
||||||
|
html = mainTemplate(ctx)
|
||||||
$el.html(html)
|
$el.html(html)
|
||||||
|
|
||||||
renderPoints = (target, us, roleId) ->
|
renderPoints = (target, us, roleId) ->
|
||||||
|
@ -337,6 +347,8 @@ UsEstimationDirective = ($rootScope, $repo, $confirm) ->
|
||||||
$el.on "click", ".total.clickable", (event) ->
|
$el.on "click", ".total.clickable", (event) ->
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
event.stopPropagation()
|
event.stopPropagation()
|
||||||
|
return if not isEditable()
|
||||||
|
|
||||||
target = angular.element(event.currentTarget)
|
target = angular.element(event.currentTarget)
|
||||||
roleId = target.data("role-id")
|
roleId = target.data("role-id")
|
||||||
|
|
||||||
|
@ -349,6 +361,7 @@ UsEstimationDirective = ($rootScope, $repo, $confirm) ->
|
||||||
$el.on "click", ".point", (event) ->
|
$el.on "click", ".point", (event) ->
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
event.stopPropagation()
|
event.stopPropagation()
|
||||||
|
return if not isEditable()
|
||||||
|
|
||||||
target = angular.element(event.currentTarget)
|
target = angular.element(event.currentTarget)
|
||||||
roleId = target.data("role-id")
|
roleId = target.data("role-id")
|
||||||
|
@ -356,28 +369,24 @@ UsEstimationDirective = ($rootScope, $repo, $confirm) ->
|
||||||
|
|
||||||
$el.find(".popover").popover().close()
|
$el.find(".popover").popover().close()
|
||||||
|
|
||||||
us = $model.$modelValue
|
us = angular.copy($model.$modelValue)
|
||||||
|
us.points[roleId] = pointId
|
||||||
points = _.clone(us.points, true)
|
|
||||||
points[roleId] = pointId
|
|
||||||
|
|
||||||
# NOTE: your past self wants that you make a refactor of this
|
|
||||||
$scope.$apply ->
|
|
||||||
us.points = points
|
|
||||||
us.total_points = calculateTotalPoints(us)
|
us.total_points = calculateTotalPoints(us)
|
||||||
|
$model.$setViewValue(us)
|
||||||
|
|
||||||
if saveAfterModify
|
if saveAfterModify
|
||||||
|
# Edit in the detail page
|
||||||
onSuccess = ->
|
onSuccess = ->
|
||||||
$repo.refresh(us).then ->
|
$confirm.notify("success")
|
||||||
render(us)
|
|
||||||
$rootScope.$broadcast("history:reload")
|
$rootScope.$broadcast("history:reload")
|
||||||
onError = ->
|
onError = ->
|
||||||
$repo.refresh(us).then ->
|
|
||||||
render(us)
|
|
||||||
$confirm.notify("error")
|
$confirm.notify("error")
|
||||||
$repo.save(us).then(onSuccess, onError)
|
us.revert()
|
||||||
|
$model.$setViewValue(us)
|
||||||
|
$repo.save($model.$modelValue).then(onSuccess, onError)
|
||||||
else
|
else
|
||||||
render(us)
|
# Create or eedit in the lightbox
|
||||||
|
render($model.$modelValue)
|
||||||
|
|
||||||
$scope.$watch $attrs.ngModel, (us) ->
|
$scope.$watch $attrs.ngModel, (us) ->
|
||||||
render(us) if us
|
render(us) if us
|
||||||
|
|
Loading…
Reference in New Issue