timeline item comment

stable
Juanfran 2015-04-14 15:06:11 +02:00
parent 8cc04a7f58
commit 0c00ea31eb
4 changed files with 84 additions and 35 deletions

View File

@ -1,16 +1,23 @@
timelineTitle = (timeline, event) -> timelineType = (timeline, event) ->
title = [ types = [
{ # NewMember { # NewMember
check: (timeline, event) -> check: (timeline, event) ->
return event.obj == 'membership' return event.obj == 'membership'
key: 'TIMELINE.NEW_MEMBER', key: 'TIMELINE.NEW_MEMBER',
translate_params: ['project_name'] translate_params: ['project_name']
member: (timeline) ->
return {
user: timeline.data.user,
role: timeline.data.role
}
}, },
{ # NewProject { # NewProject
check: (timeline, event) -> check: (timeline, event) ->
return event.obj == 'project' && event.type == 'create' return event.obj == 'project' && event.type == 'create'
key: 'TIMELINE.NEW_PROJECT', key: 'TIMELINE.NEW_PROJECT',
translate_params: ['username', 'project_name'] translate_params: ['username', 'project_name'],
description: (timeline) ->
return timeline.data.project.description
}, },
{ # NewAttachment { # NewAttachment
check: (timeline, event) -> check: (timeline, event) ->
@ -46,19 +53,26 @@ timelineTitle = (timeline, event) ->
check: (timeline, event) -> check: (timeline, event) ->
return timeline.data.comment && event.obj == 'userstory' return timeline.data.comment && event.obj == 'userstory'
key: 'TIMELINE.NEW_COMMENT_US', 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 { # NewIssueComment
check: (timeline, event) -> check: (timeline, event) ->
return timeline.data.comment && event.obj == 'issue' return timeline.data.comment && event.obj == 'issue'
key: 'TIMELINE.NEW_COMMENT_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 { # NewTask
check: (timeline, event) -> check: (timeline, event) ->
return timeline.data.comment && event.obj == 'task' return timeline.data.comment && event.obj == 'task'
key: 'TIMELINE.NEW_COMMENT_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 { # UsToMilestone
check: (timeline, event, field_name) -> check: (timeline, event, field_name) ->
@ -85,7 +99,9 @@ timelineTitle = (timeline, event) ->
return false return false
key: 'TIMELINE.BLOCKED', 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 { # UnBlocked
check: (timeline, event) -> check: (timeline, event) ->
@ -131,7 +147,7 @@ timelineTitle = (timeline, event) ->
if timeline.data.values_diff if timeline.data.values_diff
field_name = Object.keys(timeline.data.values_diff)[0] field_name = Object.keys(timeline.data.values_diff)[0]
return _.find title, (obj) -> return _.find types, (obj) ->
return obj.check(timeline, event, field_name) return obj.check(timeline, event, field_name)
TimelineItemDirective = ($tgTemplate, $compile, $navUrls, $translate, $sce) -> TimelineItemDirective = ($tgTemplate, $compile, $navUrls, $translate, $sce) ->
@ -222,13 +238,12 @@ TimelineItemDirective = ($tgTemplate, $compile, $navUrls, $translate, $sce) ->
return params return params
getTitle = (timeline, event) -> getTitle = (timeline, event, type) ->
type = timelineTitle(timeline, event)
return $translate.instant(type.key, getParams(timeline, event, type)) return $translate.instant(type.key, getParams(timeline, event, type))
link = ($scope, $el, $attrs) -> link = ($scope, $el, $attrs) ->
event = parseEventType($scope.timeline.event_type) event = parseEventType($scope.timeline.event_type)
type = timelineType($scope.timeline, event)
$scope.activity = {} $scope.activity = {}
@ -236,9 +251,15 @@ TimelineItemDirective = ($tgTemplate, $compile, $navUrls, $translate, $sce) ->
$scope.activity.user = $scope.timeline.data.user $scope.activity.user = $scope.timeline.data.user
$scope.activity.project = $scope.timeline.data.project $scope.activity.project = $scope.timeline.data.project
$scope.activity.sprint = $scope.timeline.data.milestone $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() $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 if $scope.timeline.data.values_diff?.attachments
$scope.activity.attachments = $scope.timeline.data.values_diff.attachments.new $scope.activity.attachments = $scope.timeline.data.values_diff.attachments.new

View File

@ -140,6 +140,23 @@ sizeFormat = (input, precision=1) ->
size = (input / Math.pow(1024, number)).toFixed(precision) size = (input / Math.pow(1024, number)).toFixed(precision)
return "#{size} #{units[number]}" 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, '</' + replace + '>')
return str
taiga = @.taiga taiga = @.taiga
taiga.nl2br = nl2br taiga.nl2br = nl2br
@ -160,3 +177,5 @@ taiga.debounce = debounce
taiga.debounceLeading = debounceLeading taiga.debounceLeading = debounceLeading
taiga.startswith = startswith taiga.startswith = startswith
taiga.sizeFormat = sizeFormat taiga.sizeFormat = sizeFormat
taiga.stripTags = stripTags
taiga.replaceTags = replaceTags

View File

@ -7,5 +7,16 @@ div.activity-image
p(tg-compile-html="activity.title") 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") div(tg-timeline-attachment="attachment")

View File

@ -69,7 +69,6 @@
} }
} }
} }
.activity-member {
.activity-member-view { .activity-member-view {
display: flex; display: flex;
margin-bottom: .5rem; margin-bottom: .5rem;
@ -93,5 +92,4 @@
width: 100%; width: 100%;
} }
} }
}
} }