From 0c00ea31ebd67d13883917a8d1486d11f4f2535b Mon Sep 17 00:00:00 2001 From: Juanfran Date: Tue, 14 Apr 2015 15:06:11 +0200 Subject: [PATCH] timeline item comment --- .../profile/timeline-item.directive.coffee | 45 ++++++++++++++----- app/coffee/utils.coffee | 19 ++++++++ .../profile/timeline/timeline-item.jade | 13 +++++- .../modules/profile/profile-timeline.scss | 42 +++++++++-------- 4 files changed, 84 insertions(+), 35 deletions(-) diff --git a/app/coffee/modules/profile/timeline-item.directive.coffee b/app/coffee/modules/profile/timeline-item.directive.coffee index 4a3a69b8..88e7083f 100644 --- a/app/coffee/modules/profile/timeline-item.directive.coffee +++ b/app/coffee/modules/profile/timeline-item.directive.coffee @@ -1,16 +1,23 @@ -timelineTitle = (timeline, event) -> - title = [ +timelineType = (timeline, event) -> + types = [ { # NewMember check: (timeline, event) -> return event.obj == 'membership' key: 'TIMELINE.NEW_MEMBER', translate_params: ['project_name'] + member: (timeline) -> + return { + user: timeline.data.user, + role: timeline.data.role + } }, { # NewProject check: (timeline, event) -> return event.obj == 'project' && event.type == 'create' key: 'TIMELINE.NEW_PROJECT', - translate_params: ['username', 'project_name'] + translate_params: ['username', 'project_name'], + description: (timeline) -> + return timeline.data.project.description }, { # NewAttachment check: (timeline, event) -> @@ -46,19 +53,26 @@ timelineTitle = (timeline, event) -> check: (timeline, event) -> return timeline.data.comment && event.obj == 'userstory' key: 'TIMELINE.NEW_COMMENT_US', - translate_params: ['username', 'obj_name'] + translate_params: ['username', 'obj_name'], + description: (timeline) -> + return taiga.stripTags(timeline.data.comment_html, 'br|p') }, { # NewIssueComment check: (timeline, event) -> return timeline.data.comment && event.obj == 'issue' key: 'TIMELINE.NEW_COMMENT_ISSUE', - translate_params: ['username', 'obj_name'] + translate_params: ['username', 'obj_name'], + description: (timeline) -> + text = taiga.replaceTags(timeline.data.comment_html, 'h1|h2|h3', 'p') + return taiga.stripTags(text, 'br|p') }, { # NewTask check: (timeline, event) -> return timeline.data.comment && event.obj == 'task' key: 'TIMELINE.NEW_COMMENT_TASK' - translate_params: ['username', 'obj_name'] + translate_params: ['username', 'obj_name'], + description: (timeline) -> + return taiga.stripTags(timeline.data.comment_html, 'br|p') }, { # UsToMilestone check: (timeline, event, field_name) -> @@ -85,7 +99,9 @@ timelineTitle = (timeline, event) -> return false key: 'TIMELINE.BLOCKED', - translate_params: ['username', 'obj_name'] + translate_params: ['username', 'obj_name'], + description: (timeline) -> + return taiga.stripTags(timeline.data.values_diff.blocked_note_html[1], 'br') }, { # UnBlocked check: (timeline, event) -> @@ -131,7 +147,7 @@ timelineTitle = (timeline, event) -> if timeline.data.values_diff field_name = Object.keys(timeline.data.values_diff)[0] - return _.find title, (obj) -> + return _.find types, (obj) -> return obj.check(timeline, event, field_name) TimelineItemDirective = ($tgTemplate, $compile, $navUrls, $translate, $sce) -> @@ -222,13 +238,12 @@ TimelineItemDirective = ($tgTemplate, $compile, $navUrls, $translate, $sce) -> return params - getTitle = (timeline, event) -> - type = timelineTitle(timeline, event) - + getTitle = (timeline, event, type) -> return $translate.instant(type.key, getParams(timeline, event, type)) link = ($scope, $el, $attrs) -> event = parseEventType($scope.timeline.event_type) + type = timelineType($scope.timeline, event) $scope.activity = {} @@ -236,9 +251,15 @@ TimelineItemDirective = ($tgTemplate, $compile, $navUrls, $translate, $sce) -> $scope.activity.user = $scope.timeline.data.user $scope.activity.project = $scope.timeline.data.project $scope.activity.sprint = $scope.timeline.data.milestone - $scope.activity.title = getTitle($scope.timeline, event) + $scope.activity.title = getTitle($scope.timeline, event, type) $scope.activity.created_formated = moment($scope.timeline.created).fromNow() + if type.description + $scope.activity.description = $sce.trustAsHtml(type.description($scope.timeline)) + + if type.member + $scope.activity.member = type.member($scope.timeline) + if $scope.timeline.data.values_diff?.attachments $scope.activity.attachments = $scope.timeline.data.values_diff.attachments.new diff --git a/app/coffee/utils.coffee b/app/coffee/utils.coffee index dc399ab8..7a0ed706 100644 --- a/app/coffee/utils.coffee +++ b/app/coffee/utils.coffee @@ -140,6 +140,23 @@ sizeFormat = (input, precision=1) -> size = (input / Math.pow(1024, number)).toFixed(precision) return "#{size} #{units[number]}" +stripTags = (str, exception) -> + if exception + pattern = new RegExp('<(?!' + exception + '\s*\/?)[^>]+>', 'gi') + return String(str).replace(pattern, '') + else + return String(str).replace(/<\/?[^>]+>/g, '') + +replaceTags = (str, tags, replace) -> + # open tag + pattern = new RegExp('<(' + tags + ')>', 'gi') + str = str.replace(pattern, '<' + replace + '>') + + # close tag + pattern = new RegExp('<\/(' + tags + ')>', 'gi') + str = str.replace(pattern, '') + + return str taiga = @.taiga taiga.nl2br = nl2br @@ -160,3 +177,5 @@ taiga.debounce = debounce taiga.debounceLeading = debounceLeading taiga.startswith = startswith taiga.sizeFormat = sizeFormat +taiga.stripTags = stripTags +taiga.replaceTags = replaceTags diff --git a/app/partials/profile/timeline/timeline-item.jade b/app/partials/profile/timeline/timeline-item.jade index da03224a..ebf30734 100644 --- a/app/partials/profile/timeline/timeline-item.jade +++ b/app/partials/profile/timeline/timeline-item.jade @@ -7,5 +7,16 @@ div.activity-image p(tg-compile-html="activity.title") - div(ng-repeat="attachment in activity.attachments") + .activity-comment-quote(ng-if="::activity.description") + p(ng-bind-html="activity.description") + + .activity-member-view(ng-if="::activity.member") + .profile-member-picture + img(ng-src="{{::activity.member.user.photo}}", alt="{{::activity.member.user.name}}") + .activity-member-info + a(tg-nav="user-profile:username=activity.member.user.username", title="{{::activity.member.user.name }}") + span {{::activity.member.user.name}} + p {{::activity.member.role.name}} + +div(ng-repeat="attachment in activity.attachments") div(tg-timeline-attachment="attachment") \ No newline at end of file diff --git a/app/styles/modules/profile/profile-timeline.scss b/app/styles/modules/profile/profile-timeline.scss index ebd93633..fcb51bd6 100644 --- a/app/styles/modules/profile/profile-timeline.scss +++ b/app/styles/modules/profile/profile-timeline.scss @@ -69,29 +69,27 @@ } } } - .activity-member { - .activity-member-view { - display: flex; - margin-bottom: .5rem; - margin-left: calc(35px + .5rem); - margin-top: .5rem; - .activity-member-info { - flex: 1; - } - a { - @extend %bold; - } - p { - color: $gray-light; - } + .activity-member-view { + display: flex; + margin-bottom: .5rem; + margin-left: calc(35px + .5rem); + margin-top: .5rem; + .activity-member-info { + flex: 1; } - .profile-member-picture { - img { - margin-right: 1rem; - max-width: 64px; - min-width: 32px; - width: 100%; - } + a { + @extend %bold; + } + p { + color: $gray-light; + } + } + .profile-member-picture { + img { + margin-right: 1rem; + max-width: 64px; + min-width: 32px; + width: 100%; } } }