diff --git a/app/coffee/modules/common.coffee b/app/coffee/modules/common.coffee
index dc764e4c..ec0653e4 100644
--- a/app/coffee/modules/common.coffee
+++ b/app/coffee/modules/common.coffee
@@ -19,4 +19,322 @@
# File: modules/common.coffee
###
+taiga = @.taiga
+
+trim = @.taiga.trim
+typeIsArray = @.taiga.typeIsArray
+textToColor = @.taiga.textToColor
+
module = angular.module("taigaCommon", [])
+
+
+#############################################################################
+## TagLine (possible should be moved as generic directive)
+#############################################################################
+
+TagLineDirective = ($log) ->
+ # Main directive template (rendered by angular)
+ template = """
+
+
+ """
+
+ # Tags template (rendered manually using lodash)
+ templateTags = _.template("""
+ <% _.each(tags, function(tag) { %>
+
+
<%- tag.name %>
+ <% if (editable) { %>
+
+ <% } %>
+
+ <% }); %>""")
+
+ 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("""
+
+
+ """)
+ changeBaseTemplate = _.template("""
+
+
+ """)
+ standardChangeFromToTemplate = _.template("""
+
+
+ <%- name %>
+
+
+
+ from
+ <%= from %>
+
+
+ to
+ <%= to %>
+
+
+
+ """)
+ descriptionChangeTemplate = _.template("""
+
+ """)
+ pointsChangeTemplate = _.template("""
+ <% _.each(points, function(point, name) { %>
+
+
+ <%- name %> points
+
+
+
+ from
+ <%= point[0] %>
+
+
+ to
+ <%= point[1] %>
+
+
+
+ <% }); %>
+ """)
+ attachmentTemplate = _.template("""
+
+
+ <%- name %>
+
+
+ <%- description %>
+
+
+ """)
+ 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)
diff --git a/app/coffee/modules/issues/detail.coffee b/app/coffee/modules/issues/detail.coffee
index 48ca4feb..61525d64 100644
--- a/app/coffee/modules/issues/detail.coffee
+++ b/app/coffee/modules/issues/detail.coffee
@@ -22,13 +22,10 @@
taiga = @.taiga
mixOf = @.taiga.mixOf
-trim = @.taiga.trim
toString = @.taiga.toString
joinStr = @.taiga.joinStr
groupBy = @.taiga.groupBy
bindOnce = @.taiga.bindOnce
-typeIsArray = @.taiga.typeIsArray
-textToColor = @.taiga.textToColor
module = angular.module("taigaIssues")
@@ -86,13 +83,13 @@ class IssueDetailController extends mixOf(taiga.Controller, taiga.PageMixin, tai
loadHistory: ->
return @rs.issues.history(@scope.issueId).then (history) =>
- for item in history.results
- # If description was modified take only the description_html field
- if item.values_diff.description?
- item.values_diff.description = historyResult.values_diff.description_html
+ _.each history.results, (historyResult) ->
+ #If description was modified take only the description_html field
+ if historyResult.values_diff.description?
+ historyResult.values_diff.description = historyResult.values_diff.description_diff
- delete item.values_diff.description_html
- delete item.values_diff.description_diff
+ delete historyResult.values_diff.description_html
+ delete historyResult.values_diff.description_diff
@scope.history = history.results
@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])
-#############################################################################
-## TagLine (possible should be moved as generic directive)
-#############################################################################
-
-TagLineDirective = ($log) ->
- # Main directive template (rendered by angular)
- template = """
-
-
- """
-
- # Tags template (rendered manually using lodash)
- templateTags = _.template("""
- <% _.each(tags, function(tag) { %>
-
-
<%- tag.name %>
- <% if (editable) { %>
-
- <% } %>
-
- <% }); %>""")
-
- 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
#############################################################################
@@ -384,355 +297,3 @@ IssueStatusDirective = () ->
return {link:link, require:"ngModel"}
module.directive("tgIssueStatus", IssueStatusDirective)
-
-
-#############################################################################
-## Comment directive
-#############################################################################
-
-CommentDirective = ->
- # TODO: i18n
- commentBaseTemplate = _.template("""
-
-
- """)
- standardChangeFromToTemplate = _.template("""
-
-
- <%- name %>
-
-
-
- from
- <%= from %>
-
-
- to
- <%= to %>
-
-
-
- """)
- descriptionChangeTemplate = _.template("""
-
- """)
- pointsChangeTemplate = _.template("""
- <% _.each(points, function(point, name) { %>
-
-
- <%- name %> points
-
-
-
- from
- <%= point[0] %>
-
-
- to
- <%= point[1] %>
-
-
-
- <% }); %>
- """)
- attachmentTemplate = _.template("""
-
-
- <%- name %>
-
-
- <%- description %>
-
-
- """)
- 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("""
-
-
- """)
- standardChangeFromToTemplate = _.template("""
-
-
- <%- name %>
-
-
-
- from
- <%= from %>
-
-
- to
- <%= to %>
-
-
-
- """)
- descriptionChangeTemplate = _.template("""
-
- """)
- pointsChangeTemplate = _.template("""
- <% _.each(points, function(point, name) { %>
-
-
- <%- name %> points
-
-
-
- from
- <%= point[0] %>
-
-
- to
- <%= point[1] %>
-
-
-
- <% }); %>
- """)
- attachmentTemplate = _.template("""
-
-
- <%- name %>
-
-
- <%- description %>
-
-
- """)
- 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)
diff --git a/app/coffee/modules/tasks/detail.coffee b/app/coffee/modules/tasks/detail.coffee
index 945ddd27..fab1c15e 100644
--- a/app/coffee/modules/tasks/detail.coffee
+++ b/app/coffee/modules/tasks/detail.coffee
@@ -74,7 +74,7 @@ class TaskDetailController extends mixOf(taiga.Controller, taiga.PageMixin, taig
_.each history.results, (historyResult) ->
#If description was modified take only the description_html field
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
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(=> @.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: ->
@rootscope.$broadcast("block", @scope.task)
diff --git a/app/coffee/modules/userstories/detail.coffee b/app/coffee/modules/userstories/detail.coffee
index 94fcbd27..e419a6cd 100644
--- a/app/coffee/modules/userstories/detail.coffee
+++ b/app/coffee/modules/userstories/detail.coffee
@@ -113,29 +113,6 @@ class UserStoryDetailController extends mixOf(taiga.Controller, taiga.PageMixin,
.then(=> @.loadTasks())
.then(=> @.loadAttachments(@scope.usId))
.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: ->
@rootscope.$broadcast("block", @scope.us)
diff --git a/app/partials/views/modules/activity.jade b/app/partials/views/modules/activity.jade
index eb4caa1e..63ed2805 100644
--- a/app/partials/views/modules/activity.jade
+++ b/app/partials/views/modules/activity.jade
@@ -1,5 +1,5 @@
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")
// span show previous activity
diff --git a/app/partials/views/modules/comments.jade b/app/partials/views/modules/comments.jade
index 445df9b1..713a9fc9 100644
--- a/app/partials/views/modules/comments.jade
+++ b/app/partials/views/modules/comments.jade
@@ -3,7 +3,7 @@ section.us-comments
textarea(placeholder="Write here a new commet", ng-model="commentModel.comment")
a.button.button-green(href="", title="Comment") Comment
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")
//span show previous comments