From 0325b14b577c1c9c4f08e38ad65717634588ea21 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 1 Jul 2014 18:03:34 +0200 Subject: [PATCH] Add tag line. --- app/coffee/modules/issues/detail.coffee | 45 ++++++++++++++++++++++--- app/partials/issues-detail.jade | 9 +++-- 2 files changed, 44 insertions(+), 10 deletions(-) diff --git a/app/coffee/modules/issues/detail.coffee b/app/coffee/modules/issues/detail.coffee index 4c761f3e..8c2767c6 100644 --- a/app/coffee/modules/issues/detail.coffee +++ b/app/coffee/modules/issues/detail.coffee @@ -93,9 +93,6 @@ module.controller("IssueDetailController", IssueDetailController) IssueDirective = ($log, $location) -> linkSidebar = ($scope, $el, $attrs, $ctrl) -> - - - link = ($scope, $el, $attrs) -> $ctrl = $el.controller() linkSidebar($scope, $el, $attrs, $ctrl) @@ -111,8 +108,46 @@ module.directive("tgIssueDetail", ["$log", "$tgLocation", IssueDirective]) ############################################################################# TagLineDirective = ($log) -> - link = ($scope, $el, $attrs) -> + template = _.template(""" + <% _.each(tags, function(tag) { %> + <%= tag.name %> + <% }); %>""") - return {link:link} + renderTags = ($el, tags) -> + tags = _.map(tags, (t) -> {name: t}) + html = template({tags: tags}) + $el.find("span.tags-container").html(html) + + normalizeTags = (tags) -> + tags = _.map(tags, trim) + tags = _.map(tags, (x) -> x.toLowerCase()) + return _.uniq(tags) + + link = ($scope, $el, $attrs, $model) -> + $scope.$watch $attrs.ngModel, (val) -> + return if not val + renderTags($el, val) + + if $attrs.tgTagLine != "editable" + $el.find("input").remove() + + $el.on "keyup", "input", (event) -> + return if event.keyCode != 13 + target = angular.element(event.currentTarget) + value = trim(target.val()) + + if value.length <= 0 + return + + tags = _.clone($model.$modelValue, false) + tags.push(value) + + target.val("") + + $scope.$apply -> + $model.$setViewValue(normalizeTags(tags)) + + + return {link:link, require:"ngModel"} module.directive("tgTagLine", ["$log", TagLineDirective]) diff --git a/app/partials/issues-detail.jade b/app/partials/issues-detail.jade index a757c95f..5f7dcc27 100644 --- a/app/partials/issues-detail.jade +++ b/app/partials/issues-detail.jade @@ -21,11 +21,10 @@ block content // p We need Pilar to make a prototype out of this or we are not sure // a.button.button-red.button-block(href="", title="Unblock US") Unblock - div.user-story-tags(tg-tag-line, ng-model="issue.tags") - span - - for(var y = 0; y < 6; y++) - include views/components/tag - input(type="text", placeholder="Write tag...") + div.user-story-tags(tg-tag-line="editable", ng-model="issue.tags") + span.tags-container + input.hidden(type="text", placeholder="Write tag...") + section.us-content(tg-bind-html="issue.description_html") // include views/modules/attachments