From a3a84a06c12afaa82291b63fab834fd69c7e073c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Barrag=C3=A1n=20Merino?= Date: Mon, 15 Sep 2014 16:16:19 +0200 Subject: [PATCH] Make improvements in the history of changes (Issue #913) --- app/coffee/modules/common/history.coffee | 75 +++++++++++++++++++++--- 1 file changed, 66 insertions(+), 9 deletions(-) diff --git a/app/coffee/modules/common/history.coffee b/app/coffee/modules/common/history.coffee index 18269d9b..a4a38440 100644 --- a/app/coffee/modules/common/history.coffee +++ b/app/coffee/modules/common/history.coffee @@ -25,10 +25,12 @@ bindOnce = @.taiga.bindOnce module = angular.module("taigaCommon") + ############################################################################# ## History Directive (Main) ############################################################################# + class HistoryController extends taiga.Controller @.$inject = ["$scope", "$tgRepo"] @@ -73,7 +75,7 @@ HistoryDirective = ($log) -> <% _.each(points, function(point, name) { %>
- points (<%- name.toLowerCase() %>) + US points (<%- name.toLowerCase() %>)

@@ -106,6 +108,25 @@ HistoryDirective = ($log) ->

""") + templateChangeAttachment = _.template(""" +
+
+ <%- name %> +
+
+ <% _.each(diff, function(change) { %> +

+ <%= change.name %> from
+ <%= change.from %> +

+

+ <%= change.name %> to
+ <%= change.to %> +

+ <% }) %> +
+
+ """) templateActivity = _.template("""
@@ -208,6 +229,23 @@ HistoryDirective = ($log) -> $ctrl.loadHistory() # Helpers + getHumanizedFieldName = (field) -> + humanizedFieldNames = { + # US + is_closed: "is closed" + finish_date: "finish date" + client_requirement: "client requirement" + team_requirement: "team requirement" + + # Task + milestone: "spreint" + user_story: "user story" + is_iocaine: "is iocaine" + + # Attachment + is_deprecated: "is deprecated" + } # TODO i18n + return humanizedFieldNames[field] or field getUserFullName = (userId) -> return $scope.usersById[userId]?.full_name_display @@ -227,39 +265,58 @@ HistoryDirective = ($log) -> if change == "" return "nil" + if change == true + return "yes" + + if change == false + return "no" + return change # Render into string (operations without mutability) - renderAttachmentEntry = (field, value) -> + renderAttachmentEntry = (value) -> attachments = _.map value, (changes, type) -> if type == "new" return _.map changes, (change) -> - return templateChangeDiff({name: "New attachment", diff: change.filename}) + # TODO: i18n + return templateChangeDiff({name: "new attachment", diff: change.filename}) else if type == "deleted" return _.map changes, (change) -> - return templateChangeDiff({name: "Deleted attachment", diff: change.filename}) + # TODO: i18n + return templateChangeDiff({name: "deleted attachment", diff: change.filename}) else return _.map changes, (change) -> - return templateChangeDiff({name: "Updated attachment", diff: change[0].filename}) + # TODO: i18n + name = "updated attachment #{change.filename}" + diff = _.map change.changes, (values, name) -> + return { + name: getHumanizedFieldName(name) + from: formatChange(values[0]) + to: formatChange(values[1]) + } + return templateChangeAttachment({name: name, diff: diff}) return _.flatten(attachments).join("\n") renderChangeEntry = (field, value) -> if field == "description" - return templateChangeDiff({name: field, diff: value[1]}) + # TODO: i18n + return templateChangeDiff({name: "description", diff: value[1]}) else if field == "points" return templateChangePoints({points: value}) else if field == "attachments" - return renderAttachmentEntry(field, value) + return renderAttachmentEntry(value) else if field == "assigned_to" + name = getHumanizedFieldName(field) from = formatChange(value[0] or "Unassigned") to = formatChange(value[1] or "Unassigned") - return templateChangeGeneric({name:field, from:from, to: to}) + return templateChangeGeneric({name:name, from:from, to: to}) else + name = getHumanizedFieldName(field) from = formatChange(value[0]) to = formatChange(value[1]) - return templateChangeGeneric({name:field, from:from, to: to}) + return templateChangeGeneric({name:name, from:from, to: to}) renderChangeEntries = (change, join=true) -> entries = _.map(change.values_diff, (value, field) -> renderChangeEntry(field, value))