From f7507aacbc2f01bce6a07b4cfeb7d507dc423318 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Espino?= Date: Mon, 11 Aug 2014 18:02:44 +0200 Subject: [PATCH] Small refactor on colors --- app/coffee/modules/base/tags.coffee | 50 ++++++++++--------- app/coffee/modules/kanban/main.coffee | 45 +++++++---------- app/coffee/modules/taskboard/main.coffee | 29 ++++++----- .../views/components/backlog-row.jade | 2 +- .../views/components/kanban-task.jade | 3 +- .../views/components/taskboard-task.jade | 3 +- 6 files changed, 66 insertions(+), 66 deletions(-) diff --git a/app/coffee/modules/base/tags.coffee b/app/coffee/modules/base/tags.coffee index 05c84b8c..a69383ce 100644 --- a/app/coffee/modules/base/tags.coffee +++ b/app/coffee/modules/base/tags.coffee @@ -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) { %> - <%- tag.name %> - <% }) %> - """) +ColorizeTagsDirective = -> + templates = { + backlog: _.template(""" + <% _.each(tags, function(tag) { %> + <%- tag.name %> + <% }) %> + """) + kanban: _.template(""" + <% _.each(tags, function(tag) { %> + + <% }) %> + """) + taskboard: _.template(""" + <% _.each(tags, function(tag) { %> + + <% }) %> + """) + } 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) diff --git a/app/coffee/modules/kanban/main.coffee b/app/coffee/modules/kanban/main.coffee index 6e74c71b..7c1acdb7 100644 --- a/app/coffee/modules/kanban/main.coffee +++ b/app/coffee/modules/kanban/main.coffee @@ -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([ diff --git a/app/coffee/modules/taskboard/main.coffee b/app/coffee/modules/taskboard/main.coffee index 8409a06a..22ad2e04 100644 --- a/app/coffee/modules/taskboard/main.coffee +++ b/app/coffee/modules/taskboard/main.coffee @@ -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) => diff --git a/app/partials/views/components/backlog-row.jade b/app/partials/views/components/backlog-row.jade index c3e9df72..73be76ee 100644 --- a/app/partials/views/components/backlog-row.jade +++ b/app/partials/views/components/backlog-row.jade @@ -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", diff --git a/app/partials/views/components/kanban-task.jade b/app/partials/views/components/kanban-task.jade index 86fedacb..59155007 100644 --- a/app/partials/views/components/kanban-task.jade +++ b/app/partials/views/components/kanban-task.jade @@ -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 diff --git a/app/partials/views/components/taskboard-task.jade b/app/partials/views/components/taskboard-task.jade index 872b6061..1815191e 100644 --- a/app/partials/views/components/taskboard-task.jade +++ b/app/partials/views/components/taskboard-task.jade @@ -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