Small refactor on colors

stable
Jesús Espino 2014-08-11 18:02:44 +02:00
parent db69206231
commit f7507aacbc
6 changed files with 66 additions and 66 deletions

View File

@ -50,38 +50,42 @@ TagsDirective = ->
module.directive("tgTags", TagsDirective)
ColorizeTagBackgroundDirective = ->
link = ($scope, $el, $attrs, $ctrl) ->
text = $scope.$eval($attrs.tgColorizeTagBackground)
color = $scope.project.tags_colors[text]
$el.css("background", color)
return {link: link}
module.directive("tgColorizeTagBackground", ColorizeTagBackgroundDirective)
ColorizeTagsBorderLeftDirective = ->
template = _.template("""
<% _.each(tags, function(tag) { %>
<span class="tag" style="border-left: 5px solid <%- tag.color %>"><%- tag.name %></span>
<% }) %>
""")
ColorizeTagsDirective = ->
templates = {
backlog: _.template("""
<% _.each(tags, function(tag) { %>
<span class="tag" style="border-left: 5px solid <%- tag.color %>"><%- tag.name %></span>
<% }) %>
""")
kanban: _.template("""
<% _.each(tags, function(tag) { %>
<a class="kanban-tag" href="" style="background: <%- tag.color %>" title="<%- tag.name %>" />
<% }) %>
""")
taskboard: _.template("""
<% _.each(tags, function(tag) { %>
<a class="taskboard-tag" href="" style="background: <%- tag.color %>" title="<%- tag.name %>" />
<% }) %>
""")
}
link = ($scope, $el, $attrs, $ctrl) ->
render = (srcTags) ->
template = templates[$attrs.tgColorizeTagsType]
tags = []
for tag in srcTags
color = $scope.project.tags_colors[tag]
tags.push({name: tag, color: color})
$el.html template({tags: tags})
$scope.$watch $attrs.tgColorizeTagsBorderLeft, ->
tags = $scope.$eval($attrs.tgColorizeTagsBorderLeft)
render(tags)
$scope.$watch $attrs.tgColorizeTags, ->
tags = $scope.$eval($attrs.tgColorizeTags)
if tags?
render(tags)
tags = $scope.$eval($attrs.tgColorizeTagsBorderLeft)
render(tags)
tags = $scope.$eval($attrs.tgColorizeTags)
if tags?
render(tags)
return {link: link}
module.directive("tgColorizeTagsBorderLeft", ColorizeTagsBorderLeftDirective)
module.directive("tgColorizeTags", ColorizeTagsDirective)

View File

@ -59,9 +59,9 @@ class KanbanController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.Fi
promise.then null, =>
console.log "FAIL"
@scope.$on("usform:new:success", @.onNewUserstory)
@scope.$on("usform:bulk:success", @.onNewUserstory)
@scope.$on("usform:edit:success", @.onUserstoryEdited)
@scope.$on("usform:new:success", @.loadUserstories)
@scope.$on("usform:bulk:success", @.loadUserstories)
@scope.$on("usform:edit:success", @.loadUserstories)
@scope.$on("assigned-to:added", @.onAssignedToChanged)
@scope.$on("kanban:us:move", @.moveUs)
@ -80,24 +80,12 @@ class KanbanController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.Fi
# Scope Events Handlers
onNewUserstory: (ctx, result) ->
if result.data
items = result.data
else
items = [result]
for us in items
@scope.usByStatus[us.status].splice(0, 0, us)
onAssignedToChanged: (ctx, userid, us) ->
us.assigned_to = userid
promise = @repo.save(us)
promise.then null, ->
console.log "FAIL" # TODO
onUserstoryEdited: (ctx, us) ->
@.loadUserstories()
# Load data methods
loadProjectStats: ->
@ -112,22 +100,27 @@ class KanbanController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.Fi
@scope.stats.completedPercentage = "#{completedPercentage}%"
return stats
refreshTagsColors: ->
return @rs.projects.tagsColors(@scope.projectId).then (tags_colors) =>
@scope.project.tags_colors = tags_colors
loadUserstories: ->
return @rs.userstories.listUnassigned(@scope.projectId).then (userstories) =>
@scope.userstories = userstories
return @.refreshTagsColors().then =>
return @rs.userstories.listUnassigned(@scope.projectId).then (userstories) =>
@scope.userstories = userstories
@scope.usByStatus = _.groupBy(userstories, "status")
@scope.usByStatus = _.groupBy(userstories, "status")
for status in @scope.usStatusList
if not @scope.usByStatus[status.id]?
@scope.usByStatus[status.id] = []
for status in @scope.usStatusList
if not @scope.usByStatus[status.id]?
@scope.usByStatus[status.id] = []
# The broadcast must be executed when the DOM has been fully reloaded.
# We can't assure when this exactly happens so we need a defer
scopeDefer @scope, =>
@scope.$broadcast("userstories:loaded")
# The broadcast must be executed when the DOM has been fully reloaded.
# We can't assure when this exactly happens so we need a defer
scopeDefer @scope, =>
@scope.$broadcast("userstories:loaded")
return userstories
return userstories
loadKanban: ->
return @q.all([

View File

@ -85,6 +85,10 @@ class TaskboardController extends mixOf(taiga.Controller, taiga.PageMixin)
@scope.stats.remainingTasks = remainingTasks
return stats
refreshTagsColors: ->
return @rs.projects.tagsColors(@scope.projectId).then (tags_colors) =>
@scope.project.tags_colors = tags_colors
loadSprint: ->
return @rs.sprints.get(@scope.projectId, @scope.sprintId).then (sprint) =>
@scope.sprint = sprint
@ -92,21 +96,22 @@ class TaskboardController extends mixOf(taiga.Controller, taiga.PageMixin)
return sprint
loadTasks: ->
return @rs.tasks.list(@scope.projectId, @scope.sprintId).then (tasks) =>
@scope.tasks = tasks
@scope.usTasks = {}
return @.refreshTagsColors().then =>
return @rs.tasks.list(@scope.projectId, @scope.sprintId).then (tasks) =>
@scope.tasks = tasks
@scope.usTasks = {}
# Iterate over all userstories and
# null userstory for unassigned tasks
for us in _.union(@scope.userstories, [{id:null}])
@scope.usTasks[us.id] = {}
for status in @scope.taskStatusList
@scope.usTasks[us.id][status.id] = []
# Iterate over all userstories and
# null userstory for unassigned tasks
for us in _.union(@scope.userstories, [{id:null}])
@scope.usTasks[us.id] = {}
for status in @scope.taskStatusList
@scope.usTasks[us.id][status.id] = []
for task in @scope.tasks
@scope.usTasks[task.user_story][task.status].push(task)
for task in @scope.tasks
@scope.usTasks[task.user_story][task.status].push(task)
return tasks
return tasks
loadProject: ->
return @rs.projects.get(@scope.projectId).then (project) =>

View File

@ -1,6 +1,6 @@
div.row.us-item-row(ng-repeat="us in visibleUserstories|orderBy:order track by us.id", tg-draggable, ng-class="{blocked: us.is_blocked}")
div.user-stories
div.user-story-tags(tg-colorize-tags-border-left="us.tags")
div.user-story-tags(tg-colorize-tags="us.tags", tg-colorize-tags-type="backlog")
div.user-story-name
input(tg-check-permission, permission="modify_us", type="checkbox", name="")
a.clickable(tg-nav="project-userstories-detail:project=project.slug,ref=us.ref",

View File

@ -1,5 +1,4 @@
div.kanban-tagline
a.kanban-tag(ng-repeat="tag in us.tags", href="", tg-bo-title="tag", tg-colorize-tag-background="tag")
div.kanban-tagline(tg-colorize-tags="us.tags" tg-colorize-tags-type="kanban")
div.kanban-task-inner
div(tg-kanban-user-avatar="us.assigned_to", ng-model="us", click="ctrl.editUsAssignedTo(task)")
div.task-text

View File

@ -1,5 +1,4 @@
div.taskboard-tagline
a.taskboard-tag(ng-repeat="tag in task.tags", href="", tg-bo-title="tag", tg-colorize-tag-background="tag")
div.taskboard-tagline(tg-colorize-tags="task.tags", tg-colorize-tags-type="taskboard")
div.taskboard-task-inner
div(tg-taskboard-user-avatar="task.assigned_to", ng-model="task", click="ctrl.editTaskAssignedTo(task)")
p.taskboard-text