taiga-front/app/coffee/modules/taskboard.coffee

140 lines
4.8 KiB
CoffeeScript

###
# Copyright (C) 2014 Andrey Antukh <niwi@niwi.be>
# Copyright (C) 2014 Jesús Espino Garcia <jespinog@gmail.com>
# Copyright (C) 2014 David Barragán Merino <bameda@dbarragan.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# File: modules/taskboard.coffee
###
taiga = @.taiga
mixOf = @.taiga.mixOf
class TaskboardController extends mixOf(taiga.Controller, taiga.PageMixin)
@.$inject = [
"$scope",
"$rootScope",
"$tgRepo",
"$tgConfirm",
"$tgResources",
"$routeParams",
"$q"
]
constructor: (@scope, @rootscope, @repo, @confirm, @rs, @params, @q) ->
@scope.sprintId = @params.id
promise = @.loadInitialData()
promise.then null, ->
console.log "FAIL" #TODO
loadSprintStats: ->
return @rs.sprints.stats(@scope.projectId, @scope.sprintId).then (stats) =>
totalPointsSum =_.reduce(_.values(stats.total_points), ((res, n) -> res + n), 0)
completedPointsSum = _.reduce(_.values(stats.completed_points), ((res, n) -> res + n), 0)
remainingPointsSum = totalPointsSum - completedPointsSum
remainingTasks = stats.total_tasks - stats.completed_tasks
@scope.stats = stats
@scope.stats.totalPointsSum = totalPointsSum
@scope.stats.completedPointsSum = completedPointsSum
@scope.stats.remainingPointsSum = remainingPointsSum
@scope.stats.remainingTasks = remainingTasks
return stats
loadSprint: ->
return @rs.sprints.get(@scope.projectId, @scope.sprintId).then (sprint) =>
@scope.sprint = sprint
@scope.userstories = sprint.user_stories
return sprint
loadTasks: ->
return @rs.tasks.list(@scope.projectId, @scope.sprintId).then (tasks) =>
@scope.tasks = tasks
@scope.tasksByStatus = _.groupBy(tasks, "status")
return tasks
loadProject: ->
return @rs.projects.get(@scope.projectId).then (project) =>
@scope.project = project
@scope.points = _.sortBy(project.points, "order")
@scope.taskStatusList = _.sortBy(project.task_statuses, "order")
@scope.usStatusList = _.sortBy(project.us_statuses, "order")
return project
loadTaskboard: ->
return @q.all([
@.loadSprintStats(),
@.loadSprint()
# @.loadTasks(),
]).then(=> @.loadTasks())
loadInitialData: ->
promise = @repo.resolve({pslug: @params.pslug}).then (data) =>
@scope.projectId = data.project
return data
return promise.then(=> @.loadProject())
.then(=> @.loadUsersAndRoles())
.then(=> @.loadTaskboard())
#############################################################################
## TaskboardDirective
#############################################################################
TaskboardDirective = ->
#########################
## Drag & Drop Link
#########################
linkSortable = ($scope, $el, $attrs, $ctrl) ->
console.log "TaskboardDirective.linkSortable" #TODO
link = ($scope, $el, $attrs) ->
$ctrl = $el.controller()
linkSortable($scope, $el, $attrs, $ctrl)
$scope.$on "$destroy", ->
$el.off()
return {link: link}
TaskboardTaskrowDirective = ->
link = ($scope, $el, $attrs) ->
taiga.bindOnce $scope, "taskStatusList", (statuses) ->
itemSize = 300 + (10 * statuses.length)
size = (1 + statuses.length) * itemSize
$el.css("width", size + "px")
return {link: link}
UsStatus = ->
link = ($scope, $el, $attrs) ->
$scope.$watch "#{$attrs.tgTaskboardUsStatus}.status", (status_id) ->
if status_id is undefined
return
status_name = $scope.usStatusList[status_id].name
$el.html(status_name)
return {link:link}
module = angular.module("taigaTaskboard", [])
module.controller("TaskboardController", TaskboardController)
module.directive("tgTaskboard", TaskboardDirective)
module.directive("tgTaskboardTaskrow", TaskboardTaskrowDirective)
module.directive("tgTaskboardUsStatus", UsStatus)