Finishing activity and comments refactor
parent
60739cfdce
commit
6d5bf9e2aa
|
@ -19,4 +19,322 @@
|
||||||
# File: modules/common.coffee
|
# File: modules/common.coffee
|
||||||
###
|
###
|
||||||
|
|
||||||
|
taiga = @.taiga
|
||||||
|
|
||||||
|
trim = @.taiga.trim
|
||||||
|
typeIsArray = @.taiga.typeIsArray
|
||||||
|
textToColor = @.taiga.textToColor
|
||||||
|
|
||||||
module = angular.module("taigaCommon", [])
|
module = angular.module("taigaCommon", [])
|
||||||
|
|
||||||
|
|
||||||
|
#############################################################################
|
||||||
|
## TagLine (possible should be moved as generic directive)
|
||||||
|
#############################################################################
|
||||||
|
|
||||||
|
TagLineDirective = ($log) ->
|
||||||
|
# Main directive template (rendered by angular)
|
||||||
|
template = """
|
||||||
|
<div class="tags-container"></div>
|
||||||
|
<input type="text" placeholder="Write tag..." class="hidden"/>
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Tags template (rendered manually using lodash)
|
||||||
|
templateTags = _.template("""
|
||||||
|
<% _.each(tags, function(tag) { %>
|
||||||
|
<div class="tag" style="background: <%- tag.color %>;">
|
||||||
|
<span class="tag-name"><%- tag.name %></span>
|
||||||
|
<% if (editable) { %>
|
||||||
|
<a href="" title="delete tag" class="icon icon-delete"></a>
|
||||||
|
<% } %>
|
||||||
|
</div>
|
||||||
|
<% }); %>""")
|
||||||
|
|
||||||
|
renderTags = ($el, tags, editable) ->
|
||||||
|
ctx = {
|
||||||
|
tags: _.map(tags, (t) -> {name: t, color: textToColor(t)})
|
||||||
|
editable: editable
|
||||||
|
}
|
||||||
|
html = templateTags(ctx)
|
||||||
|
$el.find("div.tags-container").html(html)
|
||||||
|
|
||||||
|
normalizeTags = (tags) ->
|
||||||
|
tags = _.map(tags, trim)
|
||||||
|
tags = _.map(tags, (x) -> x.toLowerCase())
|
||||||
|
return _.uniq(tags)
|
||||||
|
|
||||||
|
link = ($scope, $el, $attrs, $model) ->
|
||||||
|
editable = if $attrs.editable == "true" then true else false
|
||||||
|
|
||||||
|
$scope.$watch $attrs.ngModel, (val) ->
|
||||||
|
return if not val
|
||||||
|
renderTags($el, val, editable)
|
||||||
|
|
||||||
|
$el.find("input").remove() if not editable
|
||||||
|
|
||||||
|
$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 = [] if not tags?
|
||||||
|
tags.push(value)
|
||||||
|
|
||||||
|
target.val("")
|
||||||
|
|
||||||
|
$scope.$apply ->
|
||||||
|
$model.$setViewValue(normalizeTags(tags))
|
||||||
|
|
||||||
|
$el.on "click", ".icon-delete", (event) ->
|
||||||
|
event.preventDefault()
|
||||||
|
target = angular.element(event.currentTarget)
|
||||||
|
value = trim(target.siblings(".tag-name").text())
|
||||||
|
|
||||||
|
if value.length <= 0
|
||||||
|
return
|
||||||
|
|
||||||
|
tags = _.clone($model.$modelValue, false)
|
||||||
|
tags = _.pull(tags, value)
|
||||||
|
|
||||||
|
$scope.$apply ->
|
||||||
|
$model.$setViewValue(normalizeTags(tags))
|
||||||
|
|
||||||
|
return {
|
||||||
|
link:link,
|
||||||
|
require:"ngModel"
|
||||||
|
template: template
|
||||||
|
}
|
||||||
|
|
||||||
|
module.directive("tgTagLine", ["$log", TagLineDirective])
|
||||||
|
|
||||||
|
#############################################################################
|
||||||
|
## Change (comment and history mode) directive
|
||||||
|
#############################################################################
|
||||||
|
|
||||||
|
ChangeDirective = ->
|
||||||
|
# TODO: i18n
|
||||||
|
commentBaseTemplate = _.template("""
|
||||||
|
<div class="comment-user">
|
||||||
|
<a class="avatar" href="" title="<%- userFullName %>">
|
||||||
|
<img src="<%- avatar %>" alt="<%- userFullName %>">
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<div class="comment-content">
|
||||||
|
<a class="username" href="TODO" title="<%- userFullName %>">
|
||||||
|
<%- userFullName %>
|
||||||
|
</a>
|
||||||
|
<% if(hasChanges){ %>
|
||||||
|
<div class="us-activity">
|
||||||
|
<a class="activity-title" href="" title="Show activity">
|
||||||
|
<span>
|
||||||
|
<%- changesText %>
|
||||||
|
</span>
|
||||||
|
<span class="icon icon-arrow-up">
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<% } %>
|
||||||
|
|
||||||
|
<p class="comment">
|
||||||
|
<%- comment %>
|
||||||
|
</p>
|
||||||
|
<p class="date">
|
||||||
|
<%- creationDate %>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
""")
|
||||||
|
changeBaseTemplate = _.template("""
|
||||||
|
<div class="activity-user">
|
||||||
|
<a class="avatar" href="" title="<%- userFullName %>">
|
||||||
|
<img src="<%- avatar %>" alt="<%- userFullName %>">
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<div class="activity-content">
|
||||||
|
<div class="activity-username">
|
||||||
|
<a class="username" href="TODO" title="<%- userFullName %>">
|
||||||
|
<%- userFullName %>
|
||||||
|
</a>
|
||||||
|
<span class="date">
|
||||||
|
<%- creationDate %>
|
||||||
|
</span>
|
||||||
|
<%- comment %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
""")
|
||||||
|
standardChangeFromToTemplate = _.template("""
|
||||||
|
<div class="activity-inner">
|
||||||
|
<div class="activity-changed">
|
||||||
|
<span><%- name %></span>
|
||||||
|
</div>
|
||||||
|
<div class="activity-fromto">
|
||||||
|
<p>
|
||||||
|
<strong> from </strong> <br />
|
||||||
|
<span><%= from %></span>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<strong> to </strong> <br />
|
||||||
|
<span><%= to %></span>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
""")
|
||||||
|
descriptionChangeTemplate = _.template("""
|
||||||
|
<div class="activity-inner">
|
||||||
|
<div class="activity-changed">
|
||||||
|
<span><%- name %></span>
|
||||||
|
</div>
|
||||||
|
<div class="activity-fromto">
|
||||||
|
<p>
|
||||||
|
<span><%= diff %></span>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
""")
|
||||||
|
pointsChangeTemplate = _.template("""
|
||||||
|
<% _.each(points, function(point, name) { %>
|
||||||
|
<div class="activity-inner">
|
||||||
|
<div class="activity-changed">
|
||||||
|
<span><%- name %> points</span>
|
||||||
|
</div>
|
||||||
|
<div class="activity-fromto">
|
||||||
|
<p>
|
||||||
|
<strong> from </strong> <br />
|
||||||
|
<span><%= point[0] %></span>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<strong> to </strong> <br />
|
||||||
|
<span><%= point[1] %></span>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<% }); %>
|
||||||
|
""")
|
||||||
|
attachmentTemplate = _.template("""
|
||||||
|
<div class="activity-inner">
|
||||||
|
<div class="activity-changed">
|
||||||
|
<span><%- name %></span>
|
||||||
|
</div>
|
||||||
|
<div class="activity-fromto">
|
||||||
|
<%- description %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
""")
|
||||||
|
link = ($scope, $el, $attrs, $model) ->
|
||||||
|
countChanges = (comment) ->
|
||||||
|
return _.keys(comment.values_diff).length
|
||||||
|
|
||||||
|
buildChangesText = (comment) ->
|
||||||
|
size = countChanges(comment)
|
||||||
|
# TODO: i18n
|
||||||
|
if size == 1
|
||||||
|
return "Made #{size} change"
|
||||||
|
return "Made #{size} changes"
|
||||||
|
|
||||||
|
renderEntries = (change, parentDomNode) ->
|
||||||
|
_.each change.values_diff, (modification, name) ->
|
||||||
|
if name == "description"
|
||||||
|
parentDomNode.append(descriptionChangeTemplate({
|
||||||
|
name: name
|
||||||
|
diff: modification[1]
|
||||||
|
}))
|
||||||
|
else if name == "points"
|
||||||
|
parentDomNode.append(pointsChangeTemplate({
|
||||||
|
points: modification
|
||||||
|
}))
|
||||||
|
else if name == "attachments"
|
||||||
|
_.each modification, (attachmentChanges, attachmentType) ->
|
||||||
|
if attachmentType == "new"
|
||||||
|
_.each attachmentChanges, (attachmentChange) ->
|
||||||
|
parentDomNode.append(attachmentTemplate({
|
||||||
|
name: "New attachment"
|
||||||
|
description: attachmentChange.filename
|
||||||
|
}))
|
||||||
|
else if attachmentType == "deleted"
|
||||||
|
_.each attachmentChanges, (attachmentChange) ->
|
||||||
|
parentDomNode.append(attachmentTemplate({
|
||||||
|
name: "Deleted attachment"
|
||||||
|
description: attachmentChange.filename
|
||||||
|
}))
|
||||||
|
else
|
||||||
|
name = "Updated attachment"
|
||||||
|
_.each attachmentChanges, (attachmentChange) ->
|
||||||
|
parentDomNode.append(attachmentTemplate({
|
||||||
|
name: "Updated attachment"
|
||||||
|
description: attachmentChange[0].filename
|
||||||
|
}))
|
||||||
|
|
||||||
|
else
|
||||||
|
parentDomNode.append(standardChangeFromToTemplate({
|
||||||
|
name: name
|
||||||
|
from: prettyPrintModification(modification[0])
|
||||||
|
to: prettyPrintModification(modification[1])
|
||||||
|
}))
|
||||||
|
|
||||||
|
renderComment = (comment) ->
|
||||||
|
html = commentBaseTemplate({
|
||||||
|
avatar: getUserAvatar(comment.user.pk)
|
||||||
|
userFullName: getUserFullName(comment.user.pk)
|
||||||
|
creationDate: moment(comment.created_at).format("YYYY/MM/DD HH:mm")
|
||||||
|
comment: comment.comment
|
||||||
|
changesText: buildChangesText(comment)
|
||||||
|
hasChanges: countChanges(comment) > 0
|
||||||
|
})
|
||||||
|
|
||||||
|
$el.html(html)
|
||||||
|
activityContentDom = $el.find(".comment-content .us-activity")
|
||||||
|
renderEntries(comment, activityContentDom)
|
||||||
|
|
||||||
|
renderChange = (change) ->
|
||||||
|
html = changeBaseTemplate({
|
||||||
|
avatar: getUserAvatar(change.user.pk)
|
||||||
|
userFullName: getUserFullName(change.user.pk)
|
||||||
|
creationDate: moment(change.created_at).format("YYYY/MM/DD HH:mm")
|
||||||
|
comment: change.comment
|
||||||
|
})
|
||||||
|
|
||||||
|
$el.html(html)
|
||||||
|
activityContentDom = $el.find(".activity-content")
|
||||||
|
renderEntries(change, activityContentDom)
|
||||||
|
|
||||||
|
getUserFullName = (userId) ->
|
||||||
|
return $scope.usersById[userId]?.full_name_display
|
||||||
|
|
||||||
|
getUserAvatar = (userId) ->
|
||||||
|
return $scope.usersById[userId]?.photo
|
||||||
|
|
||||||
|
prettyPrintModification = (value) ->
|
||||||
|
if typeIsArray(value)
|
||||||
|
if value.length == 0
|
||||||
|
#TODO i18n
|
||||||
|
return "None"
|
||||||
|
else
|
||||||
|
return value.join(", ")
|
||||||
|
|
||||||
|
if value == ""
|
||||||
|
return "None"
|
||||||
|
|
||||||
|
return value
|
||||||
|
|
||||||
|
$scope.$watch $attrs.ngModel, (change) ->
|
||||||
|
if not change?
|
||||||
|
return
|
||||||
|
|
||||||
|
if $attrs.mode == "comment"
|
||||||
|
renderComment(change)
|
||||||
|
else
|
||||||
|
renderChange(change)
|
||||||
|
|
||||||
|
$el.on "click", ".activity-title", (event) ->
|
||||||
|
event.preventDefault()
|
||||||
|
$el.find(".activity-inner").toggleClass("active")
|
||||||
|
|
||||||
|
$scope.$on "$destroy", ->
|
||||||
|
$el.off()
|
||||||
|
|
||||||
|
return {link:link, require:"ngModel"}
|
||||||
|
|
||||||
|
module.directive("tgChange", ChangeDirective)
|
||||||
|
|
|
@ -22,13 +22,10 @@
|
||||||
taiga = @.taiga
|
taiga = @.taiga
|
||||||
|
|
||||||
mixOf = @.taiga.mixOf
|
mixOf = @.taiga.mixOf
|
||||||
trim = @.taiga.trim
|
|
||||||
toString = @.taiga.toString
|
toString = @.taiga.toString
|
||||||
joinStr = @.taiga.joinStr
|
joinStr = @.taiga.joinStr
|
||||||
groupBy = @.taiga.groupBy
|
groupBy = @.taiga.groupBy
|
||||||
bindOnce = @.taiga.bindOnce
|
bindOnce = @.taiga.bindOnce
|
||||||
typeIsArray = @.taiga.typeIsArray
|
|
||||||
textToColor = @.taiga.textToColor
|
|
||||||
|
|
||||||
module = angular.module("taigaIssues")
|
module = angular.module("taigaIssues")
|
||||||
|
|
||||||
|
@ -86,13 +83,13 @@ class IssueDetailController extends mixOf(taiga.Controller, taiga.PageMixin, tai
|
||||||
|
|
||||||
loadHistory: ->
|
loadHistory: ->
|
||||||
return @rs.issues.history(@scope.issueId).then (history) =>
|
return @rs.issues.history(@scope.issueId).then (history) =>
|
||||||
for item in history.results
|
_.each history.results, (historyResult) ->
|
||||||
#If description was modified take only the description_html field
|
#If description was modified take only the description_html field
|
||||||
if item.values_diff.description?
|
if historyResult.values_diff.description?
|
||||||
item.values_diff.description = historyResult.values_diff.description_html
|
historyResult.values_diff.description = historyResult.values_diff.description_diff
|
||||||
|
|
||||||
delete item.values_diff.description_html
|
delete historyResult.values_diff.description_html
|
||||||
delete item.values_diff.description_diff
|
delete historyResult.values_diff.description_diff
|
||||||
|
|
||||||
@scope.history = history.results
|
@scope.history = history.results
|
||||||
@scope.comments = _.filter(history.results, (item) -> item.comment != "")
|
@scope.comments = _.filter(history.results, (item) -> item.comment != "")
|
||||||
|
@ -166,90 +163,6 @@ IssueDirective = ($tgrepo, $log, $location, $confirm) ->
|
||||||
module.directive("tgIssueDetail", ["$tgRepo", "$log", "$tgLocation", "$tgConfirm", IssueDirective])
|
module.directive("tgIssueDetail", ["$tgRepo", "$log", "$tgLocation", "$tgConfirm", IssueDirective])
|
||||||
|
|
||||||
|
|
||||||
#############################################################################
|
|
||||||
## TagLine (possible should be moved as generic directive)
|
|
||||||
#############################################################################
|
|
||||||
|
|
||||||
TagLineDirective = ($log) ->
|
|
||||||
# Main directive template (rendered by angular)
|
|
||||||
template = """
|
|
||||||
<div class="tags-container"></div>
|
|
||||||
<input type="text" placeholder="Write tag..." class="hidden"/>
|
|
||||||
"""
|
|
||||||
|
|
||||||
# Tags template (rendered manually using lodash)
|
|
||||||
templateTags = _.template("""
|
|
||||||
<% _.each(tags, function(tag) { %>
|
|
||||||
<div class="tag" style="background: <%- tag.color %>;">
|
|
||||||
<span class="tag-name"><%- tag.name %></span>
|
|
||||||
<% if (editable) { %>
|
|
||||||
<a href="" title="delete tag" class="icon icon-delete"></a>
|
|
||||||
<% } %>
|
|
||||||
</div>
|
|
||||||
<% }); %>""")
|
|
||||||
|
|
||||||
renderTags = ($el, tags, editable) ->
|
|
||||||
ctx = {
|
|
||||||
tags: _.map(tags, (t) -> {name: t, color: textToColor(t)})
|
|
||||||
editable: editable
|
|
||||||
}
|
|
||||||
html = templateTags(ctx)
|
|
||||||
$el.find("div.tags-container").html(html)
|
|
||||||
|
|
||||||
normalizeTags = (tags) ->
|
|
||||||
tags = _.map(tags, trim)
|
|
||||||
tags = _.map(tags, (x) -> x.toLowerCase())
|
|
||||||
return _.uniq(tags)
|
|
||||||
|
|
||||||
link = ($scope, $el, $attrs, $model) ->
|
|
||||||
editable = if $attrs.editable == "true" then true else false
|
|
||||||
|
|
||||||
$scope.$watch $attrs.ngModel, (val) ->
|
|
||||||
return if not val
|
|
||||||
renderTags($el, val, editable)
|
|
||||||
|
|
||||||
$el.find("input").remove() if not editable
|
|
||||||
|
|
||||||
$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 = [] if not tags?
|
|
||||||
tags.push(value)
|
|
||||||
|
|
||||||
target.val("")
|
|
||||||
|
|
||||||
$scope.$apply ->
|
|
||||||
$model.$setViewValue(normalizeTags(tags))
|
|
||||||
|
|
||||||
$el.on "click", ".icon-delete", (event) ->
|
|
||||||
event.preventDefault()
|
|
||||||
target = angular.element(event.currentTarget)
|
|
||||||
value = trim(target.siblings(".tag-name").text())
|
|
||||||
|
|
||||||
if value.length <= 0
|
|
||||||
return
|
|
||||||
|
|
||||||
tags = _.clone($model.$modelValue, false)
|
|
||||||
tags = _.pull(tags, value)
|
|
||||||
|
|
||||||
$scope.$apply ->
|
|
||||||
$model.$setViewValue(normalizeTags(tags))
|
|
||||||
|
|
||||||
return {
|
|
||||||
link:link,
|
|
||||||
require:"ngModel"
|
|
||||||
template: template
|
|
||||||
}
|
|
||||||
|
|
||||||
module.directive("tgTagLine", ["$log", TagLineDirective])
|
|
||||||
|
|
||||||
|
|
||||||
#############################################################################
|
#############################################################################
|
||||||
## Issue status directive
|
## Issue status directive
|
||||||
#############################################################################
|
#############################################################################
|
||||||
|
@ -384,355 +297,3 @@ IssueStatusDirective = () ->
|
||||||
return {link:link, require:"ngModel"}
|
return {link:link, require:"ngModel"}
|
||||||
|
|
||||||
module.directive("tgIssueStatus", IssueStatusDirective)
|
module.directive("tgIssueStatus", IssueStatusDirective)
|
||||||
|
|
||||||
|
|
||||||
#############################################################################
|
|
||||||
## Comment directive
|
|
||||||
#############################################################################
|
|
||||||
|
|
||||||
CommentDirective = ->
|
|
||||||
# TODO: i18n
|
|
||||||
commentBaseTemplate = _.template("""
|
|
||||||
<div class="comment-user">
|
|
||||||
<a class="avatar" href="" title="<%- userFullName %>">
|
|
||||||
<img src="<%- avatar %>" alt="<%- userFullName %>">
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
<div class="comment-content">
|
|
||||||
<a class="username" href="TODO" title="<%- userFullName %>">
|
|
||||||
<%- userFullName %>
|
|
||||||
</a>
|
|
||||||
<% if(hasChanges){ %>
|
|
||||||
<div class="us-activity">
|
|
||||||
<a class="activity-title" href="" title="Show activity">
|
|
||||||
<span>
|
|
||||||
<%- changesText %>
|
|
||||||
</span>
|
|
||||||
<span class="icon icon-arrow-up">
|
|
||||||
</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
<% } %>
|
|
||||||
|
|
||||||
<p class="comment">
|
|
||||||
<%- comment %>
|
|
||||||
</p>
|
|
||||||
<p class="date">
|
|
||||||
<%- creationDate %>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
""")
|
|
||||||
standardChangeFromToTemplate = _.template("""
|
|
||||||
<div class="activity-inner">
|
|
||||||
<div class="activity-changed">
|
|
||||||
<span><%- name %></span>
|
|
||||||
</div>
|
|
||||||
<div class="activity-fromto">
|
|
||||||
<p>
|
|
||||||
<strong> from </strong> <br />
|
|
||||||
<span><%= from %></span>
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
<strong> to </strong> <br />
|
|
||||||
<span><%= to %></span>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
""")
|
|
||||||
descriptionChangeTemplate = _.template("""
|
|
||||||
<div class="activity-inner">
|
|
||||||
<div class="activity-changed">
|
|
||||||
<span><%- name %></span>
|
|
||||||
</div>
|
|
||||||
<div class="activity-fromto">
|
|
||||||
<p>
|
|
||||||
<span><%= diff %></span>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
""")
|
|
||||||
pointsChangeTemplate = _.template("""
|
|
||||||
<% _.each(points, function(point, name) { %>
|
|
||||||
<div class="activity-inner">
|
|
||||||
<div class="activity-changed">
|
|
||||||
<span><%- name %> points</span>
|
|
||||||
</div>
|
|
||||||
<div class="activity-fromto">
|
|
||||||
<p>
|
|
||||||
<strong> from </strong> <br />
|
|
||||||
<span><%= point[0] %></span>
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
<strong> to </strong> <br />
|
|
||||||
<span><%= point[1] %></span>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<% }); %>
|
|
||||||
""")
|
|
||||||
attachmentTemplate = _.template("""
|
|
||||||
<div class="activity-inner">
|
|
||||||
<div class="activity-changed">
|
|
||||||
<span><%- name %></span>
|
|
||||||
</div>
|
|
||||||
<div class="activity-fromto">
|
|
||||||
<%- description %>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
""")
|
|
||||||
link = ($scope, $el, $attrs, $model) ->
|
|
||||||
countChanges = (comment) ->
|
|
||||||
return _.keys(comment.values_diff).length
|
|
||||||
|
|
||||||
buildChangesText = (comment) ->
|
|
||||||
size = countChanges(comment)
|
|
||||||
# TODO: i18n
|
|
||||||
if size == 1
|
|
||||||
return "Made #{size} change"
|
|
||||||
return "Made #{size} changes"
|
|
||||||
|
|
||||||
renderComment = (comment) ->
|
|
||||||
html = commentBaseTemplate({
|
|
||||||
avatar: getUserAvatar(comment.user.pk)
|
|
||||||
userFullName: getUserFullName(comment.user.pk)
|
|
||||||
creationDate: moment(comment.created_at).format("YYYY/MM/DD")
|
|
||||||
comment: comment.comment
|
|
||||||
changesText: buildChangesText(comment)
|
|
||||||
hasChanges: countChanges(comment) > 0
|
|
||||||
})
|
|
||||||
|
|
||||||
$el.html(html)
|
|
||||||
activityContentDom = $el.find(".comment-content .us-activity")
|
|
||||||
_.each comment.values_diff, (modification, name) ->
|
|
||||||
if name == "description"
|
|
||||||
activityContentDom.append(descriptionChangeTemplate({
|
|
||||||
name: name
|
|
||||||
diff: modification[1]
|
|
||||||
}))
|
|
||||||
else if name == "points"
|
|
||||||
activityContentDom.append(pointsChangeTemplate({
|
|
||||||
points: modification
|
|
||||||
}))
|
|
||||||
else if name == "attachments"
|
|
||||||
_.each modification, (attachmentChanges, attachmentType) ->
|
|
||||||
if attachmentType == "new"
|
|
||||||
_.each attachmentChanges, (attachmentChange) ->
|
|
||||||
activityContentDom.append(attachmentTemplate({
|
|
||||||
name: "New attachment"
|
|
||||||
description: attachmentChange.filename
|
|
||||||
}))
|
|
||||||
else if attachmentType == "deleted"
|
|
||||||
_.each attachmentChanges, (attachmentChange) ->
|
|
||||||
activityContentDom.append(attachmentTemplate({
|
|
||||||
name: "Deleted attachment"
|
|
||||||
description: attachmentChange.filename
|
|
||||||
}))
|
|
||||||
else
|
|
||||||
name = "Updated attachment"
|
|
||||||
_.each attachmentChanges, (attachmentChange) ->
|
|
||||||
activityContentDom.append(attachmentTemplate({
|
|
||||||
name: "Updated attachment"
|
|
||||||
description: attachmentChange[0].filename
|
|
||||||
}))
|
|
||||||
|
|
||||||
else
|
|
||||||
activityContentDom.append(standardChangeFromToTemplate({
|
|
||||||
name: name
|
|
||||||
from: prettyPrintModification(modification[0])
|
|
||||||
to: prettyPrintModification(modification[1])
|
|
||||||
}))
|
|
||||||
|
|
||||||
getUserFullName = (userId) ->
|
|
||||||
return $scope.usersById[userId]?.full_name_display
|
|
||||||
|
|
||||||
getUserAvatar = (userId) ->
|
|
||||||
return $scope.usersById[userId]?.photo
|
|
||||||
|
|
||||||
prettyPrintModification = (value) ->
|
|
||||||
if typeIsArray(value)
|
|
||||||
if value.length == 0
|
|
||||||
#TODO i18n
|
|
||||||
return "None"
|
|
||||||
else
|
|
||||||
return value.join(", ")
|
|
||||||
|
|
||||||
if value == ""
|
|
||||||
return "None"
|
|
||||||
|
|
||||||
return value
|
|
||||||
|
|
||||||
$scope.$watch $attrs.ngModel, (comment) ->
|
|
||||||
if comment?
|
|
||||||
renderComment(comment)
|
|
||||||
|
|
||||||
$el.on "click", ".activity-title", (event) ->
|
|
||||||
event.preventDefault()
|
|
||||||
$el.find(".activity-inner").toggleClass("active")
|
|
||||||
|
|
||||||
$scope.$on "$destroy", ->
|
|
||||||
$el.off()
|
|
||||||
|
|
||||||
return {link:link, require:"ngModel"}
|
|
||||||
|
|
||||||
module.directive("tgComment", CommentDirective)
|
|
||||||
|
|
||||||
|
|
||||||
#############################################################################
|
|
||||||
## Change directive
|
|
||||||
#############################################################################
|
|
||||||
|
|
||||||
ChangeDirective = ->
|
|
||||||
# TODO: i18n
|
|
||||||
changeBaseTemplate = _.template("""
|
|
||||||
<div class="activity-user">
|
|
||||||
<a class="avatar" href="" title="<%- userFullName %>">
|
|
||||||
<img src="<%- avatar %>" alt="<%- userFullName %>">
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
<div class="activity-content">
|
|
||||||
<div class="activity-username">
|
|
||||||
<a class="username" href="TODO" title="<%- userFullName %>">
|
|
||||||
<%- userFullName %>
|
|
||||||
</a>
|
|
||||||
<span class="date">
|
|
||||||
<%- creationDate %>
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
""")
|
|
||||||
standardChangeFromToTemplate = _.template("""
|
|
||||||
<div class="activity-inner">
|
|
||||||
<div class="activity-changed">
|
|
||||||
<span><%- name %></span>
|
|
||||||
</div>
|
|
||||||
<div class="activity-fromto">
|
|
||||||
<p>
|
|
||||||
<strong> from </strong> <br />
|
|
||||||
<span><%= from %></span>
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
<strong> to </strong> <br />
|
|
||||||
<span><%= to %></span>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
""")
|
|
||||||
descriptionChangeTemplate = _.template("""
|
|
||||||
<div class="activity-inner">
|
|
||||||
<div class="activity-changed">
|
|
||||||
<span><%- name %></span>
|
|
||||||
</div>
|
|
||||||
<div class="activity-fromto">
|
|
||||||
<p>
|
|
||||||
<span><%= diff %></span>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
""")
|
|
||||||
pointsChangeTemplate = _.template("""
|
|
||||||
<% _.each(points, function(point, name) { %>
|
|
||||||
<div class="activity-inner">
|
|
||||||
<div class="activity-changed">
|
|
||||||
<span><%- name %> points</span>
|
|
||||||
</div>
|
|
||||||
<div class="activity-fromto">
|
|
||||||
<p>
|
|
||||||
<strong> from </strong> <br />
|
|
||||||
<span><%= point[0] %></span>
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
<strong> to </strong> <br />
|
|
||||||
<span><%= point[1] %></span>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<% }); %>
|
|
||||||
""")
|
|
||||||
attachmentTemplate = _.template("""
|
|
||||||
<div class="activity-inner">
|
|
||||||
<div class="activity-changed">
|
|
||||||
<span><%- name %></span>
|
|
||||||
</div>
|
|
||||||
<div class="activity-fromto">
|
|
||||||
<%- description %>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
""")
|
|
||||||
link = ($scope, $el, $attrs, $model) ->
|
|
||||||
renderChange = (change) ->
|
|
||||||
html = changeBaseTemplate({
|
|
||||||
avatar: getUserAvatar(change.user.pk)
|
|
||||||
userFullName: getUserFullName(change.user.pk)
|
|
||||||
creationDate: moment(change.created_at).format("YYYY/MM/DD")
|
|
||||||
})
|
|
||||||
|
|
||||||
$el.html(html)
|
|
||||||
activityContentDom = $el.find(".activity-content")
|
|
||||||
_.each change.values_diff, (modification, name) ->
|
|
||||||
if name == "description"
|
|
||||||
activityContentDom.append(descriptionChangeTemplate({
|
|
||||||
name: name
|
|
||||||
diff: modification[1]
|
|
||||||
}))
|
|
||||||
else if name == "points"
|
|
||||||
activityContentDom.append(pointsChangeTemplate({
|
|
||||||
points: modification
|
|
||||||
}))
|
|
||||||
else if name == "attachments"
|
|
||||||
_.each modification, (attachmentChanges, attachmentType) ->
|
|
||||||
if attachmentType == "new"
|
|
||||||
_.each attachmentChanges, (attachmentChange) ->
|
|
||||||
activityContentDom.append(attachmentTemplate({
|
|
||||||
name: "New attachment"
|
|
||||||
description: attachmentChange.filename
|
|
||||||
}))
|
|
||||||
else if attachmentType == "deleted"
|
|
||||||
_.each attachmentChanges, (attachmentChange) ->
|
|
||||||
activityContentDom.append(attachmentTemplate({
|
|
||||||
name: "Deleted attachment"
|
|
||||||
description: attachmentChange.filename
|
|
||||||
}))
|
|
||||||
else
|
|
||||||
name = "Updated attachment"
|
|
||||||
_.each attachmentChanges, (attachmentChange) ->
|
|
||||||
activityContentDom.append(attachmentTemplate({
|
|
||||||
name: "Updated attachment"
|
|
||||||
description: attachmentChange[0].filename
|
|
||||||
}))
|
|
||||||
|
|
||||||
else
|
|
||||||
activityContentDom.append(standardChangeFromToTemplate({
|
|
||||||
name: name
|
|
||||||
from: prettyPrintModification(modification[0])
|
|
||||||
to: prettyPrintModification(modification[1])
|
|
||||||
}))
|
|
||||||
|
|
||||||
getUserFullName = (userId) ->
|
|
||||||
return $scope.usersById[userId]?.full_name_display
|
|
||||||
|
|
||||||
getUserAvatar = (userId) ->
|
|
||||||
return $scope.usersById[userId]?.photo
|
|
||||||
|
|
||||||
prettyPrintModification = (value) ->
|
|
||||||
if typeIsArray(value)
|
|
||||||
if value.length == 0
|
|
||||||
#TODO i18n
|
|
||||||
return "None"
|
|
||||||
else
|
|
||||||
return value.join(", ")
|
|
||||||
|
|
||||||
if value == ""
|
|
||||||
return "None"
|
|
||||||
|
|
||||||
return value
|
|
||||||
|
|
||||||
$scope.$watch $attrs.ngModel, (change) ->
|
|
||||||
if change?
|
|
||||||
renderChange(change)
|
|
||||||
|
|
||||||
$scope.$on "$destroy", ->
|
|
||||||
$el.off()
|
|
||||||
|
|
||||||
return {link:link, require:"ngModel"}
|
|
||||||
|
|
||||||
module.directive("tgChange", ChangeDirective)
|
|
||||||
|
|
|
@ -74,7 +74,7 @@ class TaskDetailController extends mixOf(taiga.Controller, taiga.PageMixin, taig
|
||||||
_.each history.results, (historyResult) ->
|
_.each history.results, (historyResult) ->
|
||||||
#If description was modified take only the description_html field
|
#If description was modified take only the description_html field
|
||||||
if historyResult.values_diff.description?
|
if historyResult.values_diff.description?
|
||||||
historyResult.values_diff.description = historyResult.values_diff.description_html
|
historyResult.values_diff.description = historyResult.values_diff.description_diff
|
||||||
|
|
||||||
if historyResult.values_diff.is_iocaine
|
if historyResult.values_diff.is_iocaine
|
||||||
historyResult.values_diff.is_iocaine = _.map(historyResult.values_diff.is_iocaine, (v) -> {true: 'Yes', false: 'No'}[v])
|
historyResult.values_diff.is_iocaine = _.map(historyResult.values_diff.is_iocaine, (v) -> {true: 'Yes', false: 'No'}[v])
|
||||||
|
@ -102,28 +102,6 @@ class TaskDetailController extends mixOf(taiga.Controller, taiga.PageMixin, taig
|
||||||
.then(=> @.loadAttachments(@scope.taskId))
|
.then(=> @.loadAttachments(@scope.taskId))
|
||||||
.then(=> @.loadHistory())
|
.then(=> @.loadHistory())
|
||||||
|
|
||||||
getUserFullName: (userId) ->
|
|
||||||
return @scope.usersById[userId]?.full_name_display
|
|
||||||
|
|
||||||
getUserAvatar: (userId) ->
|
|
||||||
return @scope.usersById[userId]?.photo
|
|
||||||
|
|
||||||
countChanges: (comment) ->
|
|
||||||
return Object.keys(comment.values_diff).length
|
|
||||||
|
|
||||||
getChangeText: (change) ->
|
|
||||||
if _.isArray(change)
|
|
||||||
return change.join(", ")
|
|
||||||
return change
|
|
||||||
|
|
||||||
buildChangesText: (comment) ->
|
|
||||||
size = @.countChanges(comment)
|
|
||||||
#TODO: i18n
|
|
||||||
if size == 1
|
|
||||||
return "Made #{size} change"
|
|
||||||
|
|
||||||
return "Made #{size} changes"
|
|
||||||
|
|
||||||
block: ->
|
block: ->
|
||||||
@rootscope.$broadcast("block", @scope.task)
|
@rootscope.$broadcast("block", @scope.task)
|
||||||
|
|
||||||
|
|
|
@ -113,29 +113,6 @@ class UserStoryDetailController extends mixOf(taiga.Controller, taiga.PageMixin,
|
||||||
.then(=> @.loadTasks())
|
.then(=> @.loadTasks())
|
||||||
.then(=> @.loadAttachments(@scope.usId))
|
.then(=> @.loadAttachments(@scope.usId))
|
||||||
.then(=> @.loadHistory())
|
.then(=> @.loadHistory())
|
||||||
|
|
||||||
getUserFullName: (userId) ->
|
|
||||||
return @scope.usersById[userId]?.full_name_display
|
|
||||||
|
|
||||||
getUserAvatar: (userId) ->
|
|
||||||
return @scope.usersById[userId]?.photo
|
|
||||||
|
|
||||||
countChanges: (comment) ->
|
|
||||||
return Object.keys(comment.values_diff).length
|
|
||||||
|
|
||||||
getChangeText: (change) ->
|
|
||||||
if _.isArray(change)
|
|
||||||
return change.join(", ")
|
|
||||||
return change
|
|
||||||
|
|
||||||
buildChangesText: (comment) ->
|
|
||||||
size = @.countChanges(comment)
|
|
||||||
#TODO: i18n
|
|
||||||
if size == 1
|
|
||||||
return "Made #{size} change"
|
|
||||||
|
|
||||||
return "Made #{size} changes"
|
|
||||||
|
|
||||||
block: ->
|
block: ->
|
||||||
@rootscope.$broadcast("block", @scope.us)
|
@rootscope.$broadcast("block", @scope.us)
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
section.us-activity.hidden
|
section.us-activity.hidden
|
||||||
div.activity-single(tg-change, ng-model="change", ng-repeat="change in history")
|
div.activity-single(tg-change, ng-model="change", mode="activity", ng-repeat="change in history")
|
||||||
|
|
||||||
//a.more-activity(href="", title="show more comments")
|
//a.more-activity(href="", title="show more comments")
|
||||||
// span show previous activity
|
// span show previous activity
|
||||||
|
|
|
@ -3,7 +3,7 @@ section.us-comments
|
||||||
textarea(placeholder="Write here a new commet", ng-model="commentModel.comment")
|
textarea(placeholder="Write here a new commet", ng-model="commentModel.comment")
|
||||||
a.button.button-green(href="", title="Comment") Comment
|
a.button.button-green(href="", title="Comment") Comment
|
||||||
div.comment-list
|
div.comment-list
|
||||||
div.comment-single(tg-comment, ng-model="comment", ng-repeat="comment in comments")
|
div.comment-single(tg-change, mode="comment", ng-model="comment", ng-repeat="comment in comments")
|
||||||
|
|
||||||
//a.more-comments(href="", title="show more comments")
|
//a.more-comments(href="", title="show more comments")
|
||||||
//span show previous comments
|
//span show previous comments
|
||||||
|
|
Loading…
Reference in New Issue