Implementing doom line in backlog

stable
Alejandro Alonso 2014-06-26 15:50:37 +02:00
parent 788f941b1c
commit 2be0f4db07
4 changed files with 68 additions and 13 deletions

View File

@ -19,7 +19,7 @@
# File: modules/backlog/lightboxes.coffee # File: modules/backlog/lightboxes.coffee
### ###
CreateEditUserstoryDirective = ($repo, $model, $rs) -> CreateEditUserstoryDirective = ($repo, $model, $rs, $rootScope) ->
editDescription = ($scope, $el) -> editDescription = ($scope, $el) ->
$el.find('.markdown-preview a').removeClass("active") $el.find('.markdown-preview a').removeClass("active")
@ -40,7 +40,6 @@ CreateEditUserstoryDirective = ($repo, $model, $rs) ->
descriptionPreviewDOM.show() descriptionPreviewDOM.show()
link = ($scope, $el, attrs) -> link = ($scope, $el, attrs) ->
$ctrl = $el.closest("div.wrapper").controller()
isNew = true isNew = true
$scope.$on "usform:new", -> $scope.$on "usform:new", ->
@ -96,12 +95,14 @@ CreateEditUserstoryDirective = ($repo, $model, $rs) ->
event.preventDefault() event.preventDefault()
if isNew if isNew
promise = $repo.create("userstories", $scope.us) promise = $repo.create("userstories", $scope.us)
broadcastEvent = "usform:new:success"
else else
promise = $repo.save($scope.us) promise = $repo.save($scope.us)
broadcastEvent = "usform:edit:success"
promise.then (data) -> promise.then (data) ->
$el.addClass("hidden") $el.addClass("hidden")
$ctrl.loadUserstories() $rootScope.$broadcast(broadcastEvent, data)
$el.on "click", "label.blocked", (event) -> $el.on "click", "label.blocked", (event) ->
event.preventDefault() event.preventDefault()
@ -180,6 +181,6 @@ CreateSprint = ($repo, $rs, $rootscope) ->
module = angular.module("taigaBacklog") module = angular.module("taigaBacklog")
module.directive("tgLbCreateEditUserstory", ["$tgRepo", "$tgModel", "$tgResources", CreateEditUserstoryDirective]) module.directive("tgLbCreateEditUserstory", ["$tgRepo", "$tgModel", "$tgResources", "$rootScope", CreateEditUserstoryDirective])
module.directive("tgLbCreateBulkUserstories", ["$tgRepo", "$tgResources", "$rootScope", CreateBulkUserstroriesDirective]) module.directive("tgLbCreateBulkUserstories", ["$tgRepo", "$tgResources", "$rootScope", CreateBulkUserstroriesDirective])
module.directive("tgLbCreateSprint", ["$tgRepo", "$tgResources", "$rootScope", CreateSprint]) module.directive("tgLbCreateSprint", ["$tgRepo", "$tgResources", "$rootScope", CreateSprint])

View File

@ -22,6 +22,8 @@
taiga = @.taiga taiga = @.taiga
mixOf = @.taiga.mixOf mixOf = @.taiga.mixOf
toggleText = @.taiga.toggleText toggleText = @.taiga.toggleText
scopeDefer = @.taiga.scopeDefer
bindOnce = @.taiga.bindOnce
class BacklogController extends mixOf(taiga.Controller, taiga.PageMixin) class BacklogController extends mixOf(taiga.Controller, taiga.PageMixin)
constructor: (@scope, @rootscope, @repo, @confirm, @rs, @params, @q) -> constructor: (@scope, @rootscope, @repo, @confirm, @rs, @params, @q) ->
@ -30,8 +32,10 @@ class BacklogController extends mixOf(taiga.Controller, taiga.PageMixin)
promise.then null, => promise.then null, =>
console.log "FAIL" console.log "FAIL"
@rootscope.$on("usform:bulk:success", @.loadUserstories) @scope.$on("usform:bulk:success", @.loadUserstories)
@rootscope.$on("sprintform:create:success", @.loadSprints) @scope.$on("sprintform:create:success", @.loadSprints)
@scope.$on("usform:new:success", @.loadUserstories)
@scope.$on("usform:edit:success", @.loadUserstories)
loadProjectStats: -> loadProjectStats: ->
return @rs.projects.stats(@scope.projectId).then (stats) => return @rs.projects.stats(@scope.projectId).then (stats) =>
@ -51,6 +55,9 @@ class BacklogController extends mixOf(taiga.Controller, taiga.PageMixin)
@scope.filters = @.generateFilters() @scope.filters = @.generateFilters()
@.filterVisibleUserstories() @.filterVisibleUserstories()
scopeDefer @scope, =>
@scope.$broadcast("userstories:loaded")
return userstories return userstories
loadBacklog: -> loadBacklog: ->
@ -132,6 +139,48 @@ class BacklogController extends mixOf(taiga.Controller, taiga.PageMixin)
############################################################################# #############################################################################
BacklogDirective = ($repo) -> BacklogDirective = ($repo) ->
#########################
## Doom line Link
#########################
linkDoomLine = ($scope, $el, $attrs, $ctrl) ->
removeDoomlineDom = ->
$el.find(".doom-line").remove()
addDoomLineDom = (element) ->
element?.before($( "<hr>", { class:"doom-line"}))
getUsItems = ->
rowElements = $el.find('.backlog-table-body .us-item-row')
return _.map(rowElements, (x) -> angular.element(x))
reloadDoomlineLocation = () ->
bindOnce $scope, "stats", (project) ->
removeDoomlineDom()
elements = getUsItems()
stats = $scope.stats
total_points = stats.total_points
current_sum = stats.assigned_points
for element in elements
scope = element.scope()
if not scope.us?
continue
current_sum += scope.us.total_points
if current_sum > total_points
addDoomLineDom(element)
break
bindOnce $scope, "stats", (project) ->
reloadDoomlineLocation()
$scope.$on("userstories:loaded", reloadDoomlineLocation)
$scope.$on("doomline:redraw", reloadDoomlineLocation)
######################### #########################
## Drag & Drop Link ## Drag & Drop Link
######################### #########################
@ -268,6 +317,7 @@ BacklogDirective = ($repo) ->
linkSortable($scope, $el, $attrs, $ctrl) linkSortable($scope, $el, $attrs, $ctrl)
linkMoveToCurrentSprint($scope, $el, $attrs, $ctrl) linkMoveToCurrentSprint($scope, $el, $attrs, $ctrl)
linkFilters($scope, $el, $attrs, $ctrl) linkFilters($scope, $el, $attrs, $ctrl)
linkDoomLine($scope, $el, $attrs, $ctrl)
$scope.$on "$destroy", -> $scope.$on "$destroy", ->
$el.off() $el.off()
@ -394,7 +444,7 @@ UsRolePointsSelectorDirective = ($rootscope) ->
</ul> </ul>
""") """)
link = ($scope, $el, $attrs) -> link = ($scope, $el, $attrs) ->
taiga.bindOnce $scope, "project", (project) -> bindOnce $scope, "project", (project) ->
roles = _.filter(project.roles, "computable") roles = _.filter(project.roles, "computable")
$el.append(selectionTemplate({ 'roles': roles })) $el.append(selectionTemplate({ 'roles': roles }))
@ -473,10 +523,10 @@ UsPointsDirective = ($repo) ->
pointsById = $scope.pointsById pointsById = $scope.pointsById
updatePointsValue(usPoints, usTotalPoints, pointsById, pointsDom, selectedRoleId) updatePointsValue(usPoints, usTotalPoints, pointsById, pointsDom, selectedRoleId)
taiga.bindOnce $scope, "project", (project) -> bindOnce $scope, "project", (project) ->
roles = _.filter(project.roles, "computable") roles = _.filter(project.roles, "computable")
$el.append(selectionTemplate({ 'roles': roles })) $el.append(selectionTemplate({ "roles": roles }))
$el.append(pointsTemplate({ 'points': project.points })) $el.append(pointsTemplate({ "points": project.points }))
$scope.$on "uspoints:select", (ctx, roleId,roleName) -> $scope.$on "uspoints:select", (ctx, roleId,roleName) ->
selectedRoleId = roleId selectedRoleId = roleId
@ -557,7 +607,7 @@ UsStatusDirective = ($repo) ->
$ctrl = $el.controller() $ctrl = $el.controller()
us = $scope.$eval($attrs.tgUsStatus) us = $scope.$eval($attrs.tgUsStatus)
taiga.bindOnce $scope, "project", (project) -> bindOnce $scope, "project", (project) ->
$el.append(selectionTemplate({ 'statuses': project.us_statuses })) $el.append(selectionTemplate({ 'statuses': project.us_statuses }))
updateUsStatus($el, us, $scope.usStatusById) updateUsStatus($el, us, $scope.usStatusById)

View File

@ -64,6 +64,11 @@ timeout = (wait, continuation) ->
return window.setTimeout(continuation, wait) return window.setTimeout(continuation, wait)
scopeDefer = (scope, func) ->
_.defer =>
scope.$apply(func)
taiga = @.taiga taiga = @.taiga
taiga.bindOnce = bindOnce taiga.bindOnce = bindOnce
taiga.mixOf = mixOf taiga.mixOf = mixOf
@ -71,3 +76,4 @@ taiga.trim = trim
taiga.toggleText = toggleText taiga.toggleText = toggleText
taiga.groupBy = groupBy taiga.groupBy = groupBy
taiga.timeout = timeout taiga.timeout = timeout
taiga.scopeDefer = scopeDefer

View File

@ -16,5 +16,3 @@ div.row.us-item-row(ng-repeat="us in visibleUserstories track by us.id")
a.us-points(href="", title="Points") 0 a.us-points(href="", title="Points") 0
a.icon.icon-drag-v(href="", title="Drag") a.icon.icon-drag-v(href="", title="Drag")
hr.doom-line