Simplify tgColorizeTags directive.
parent
c08282fade
commit
9c1dff28ec
|
@ -21,6 +21,7 @@
|
||||||
|
|
||||||
taiga = @.taiga
|
taiga = @.taiga
|
||||||
trim = @.taiga.trim
|
trim = @.taiga.trim
|
||||||
|
bindOnce = @.taiga.bindOnce
|
||||||
|
|
||||||
module = angular.module("taigaCommon")
|
module = angular.module("taigaCommon")
|
||||||
|
|
||||||
|
@ -53,38 +54,34 @@ module.directive("tgTags", TagsDirective)
|
||||||
ColorizeTagsDirective = ->
|
ColorizeTagsDirective = ->
|
||||||
templates = {
|
templates = {
|
||||||
backlog: _.template("""
|
backlog: _.template("""
|
||||||
<% _.each(tags, function(tag) { %>
|
<% _.each(tags, function(tag) { %>
|
||||||
<span class="tag" style="border-left: 5px solid <%- tag.color %>"><%- tag.name %></span>
|
<span class="tag" style="border-left: 5px solid <%- tag.color %>"><%- tag.name %></span>
|
||||||
<% }) %>
|
<% }) %>
|
||||||
""")
|
""")
|
||||||
kanban: _.template("""
|
kanban: _.template("""
|
||||||
<% _.each(tags, function(tag) { %>
|
<% _.each(tags, function(tag) { %>
|
||||||
<a class="kanban-tag" href="" style="background: <%- tag.color %>" title="<%- tag.name %>" />
|
<a class="kanban-tag" href="" style="background: <%- tag.color %>" title="<%- tag.name %>" />
|
||||||
<% }) %>
|
<% }) %>
|
||||||
""")
|
""")
|
||||||
taskboard: _.template("""
|
taskboard: _.template("""
|
||||||
<% _.each(tags, function(tag) { %>
|
<% _.each(tags, function(tag) { %>
|
||||||
<a class="taskboard-tag" href="" style="background: <%- tag.color %>" title="<%- tag.name %>" />
|
<a class="taskboard-tag" href="" style="background: <%- tag.color %>" title="<%- tag.name %>" />
|
||||||
<% }) %>
|
<% }) %>
|
||||||
""")
|
""")
|
||||||
}
|
}
|
||||||
|
|
||||||
link = ($scope, $el, $attrs, $ctrl) ->
|
link = ($scope, $el, $attrs, $ctrl) ->
|
||||||
render = (srcTags) ->
|
render = (srcTags) ->
|
||||||
template = templates[$attrs.tgColorizeTagsType]
|
template = templates[$attrs.tgColorizeTagsType]
|
||||||
tags = []
|
tags = _.map srcTags, (tag) ->
|
||||||
for tag in srcTags
|
|
||||||
color = $scope.project.tags_colors[tag]
|
color = $scope.project.tags_colors[tag]
|
||||||
tags.push({name: tag, color: color})
|
return {name: tag, color: color}
|
||||||
$el.html template({tags: tags})
|
|
||||||
|
|
||||||
$scope.$watch $attrs.tgColorizeTags, ->
|
html = template({tags: tags})
|
||||||
tags = $scope.$eval($attrs.tgColorizeTags)
|
$el.html(html)
|
||||||
if tags?
|
|
||||||
render(tags)
|
|
||||||
|
|
||||||
tags = $scope.$eval($attrs.tgColorizeTags)
|
$scope.$watch $attrs.tgColorizeTags, (tags) ->
|
||||||
if tags?
|
render(tags) if tags?
|
||||||
render(tags)
|
|
||||||
|
|
||||||
return {link: link}
|
return {link: link}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue