From 562e1c7ddd23bcbc0a9da3818ed24d3ae98bc21b Mon Sep 17 00:00:00 2001 From: Juanfran Date: Tue, 2 Feb 2016 14:56:53 +0100 Subject: [PATCH] hide comments & activity if no content --- app/coffee/modules/common/history.coffee | 38 ++++++++++++++----- .../services/check-permissions.service.coffee | 2 + app/partials/common/history/history-base.jade | 6 +++ app/styles/modules/common/history.scss | 3 ++ 4 files changed, 40 insertions(+), 9 deletions(-) diff --git a/app/coffee/modules/common/history.coffee b/app/coffee/modules/common/history.coffee index ef90a356..c650b092 100644 --- a/app/coffee/modules/common/history.coffee +++ b/app/coffee/modules/common/history.coffee @@ -88,7 +88,7 @@ class HistoryController extends taiga.Controller return @rs.history.undeleteComment(type, objectId, activityId).then => @.loadHistory(type, objectId) -HistoryDirective = ($log, $loading, $qqueue, $template, $confirm, $translate, $compile, $navUrls, $rootScope) -> +HistoryDirective = ($log, $loading, $qqueue, $template, $confirm, $translate, $compile, $navUrls, $rootScope, checkPermissionsService) -> templateChangeDiff = $template.get("common/history/history-change-diff.html", true) templateChangePoints = $template.get("common/history/history-change-points.html", true) templateChangeGeneric = $template.get("common/history/history-change-generic.html", true) @@ -343,6 +343,30 @@ HistoryDirective = ($log, $loading, $qqueue, $template, $confirm, $translate, $c # Render into DOM (operations with dom mutability) + renderBase = -> + comments = $scope.comments or [] + changes = $scope.history or [] + + historyVisible = !!changes.length + commentsVisible = (!!comments.length) || checkPermissionsService.check('modify_' + $attrs.type) + + html = templateBase({ + ngmodel: $attrs.ngModel, + type: $attrs.type, + mode: $attrs.mode, + historyVisible: historyVisible, + commentsVisible: commentsVisible + }) + + html = $compile(html)($scope) + + $el.html(html) + + rerender = -> + renderBase() + renderComments() + renderActivity() + renderComments = -> comments = $scope.comments or [] totalComments = comments.length @@ -388,8 +412,8 @@ HistoryDirective = ($log, $loading, $qqueue, $template, $confirm, $translate, $c # Watchers - $scope.$watch("comments", renderComments) - $scope.$watch("history", renderActivity) + $scope.$watch("comments", rerender) + $scope.$watch("history", rerender) $scope.$on("object:updated", -> $ctrl.loadHistory(type, objectId)) @@ -467,14 +491,10 @@ HistoryDirective = ($log, $loading, $qqueue, $template, $confirm, $translate, $c $scope.$on "$destroy", -> $el.off() - templateFn = ($el, $attrs) -> - html = templateBase({ngmodel: $attrs.ngModel, type: $attrs.type, mode: $attrs.mode}) - - return html + renderBase() return { controller: HistoryController - template: templateFn restrict: "AE" link: link # require: ["ngModel", "tgHistory"] @@ -482,4 +502,4 @@ HistoryDirective = ($log, $loading, $qqueue, $template, $confirm, $translate, $c module.directive("tgHistory", ["$log", "$tgLoading", "$tgQqueue", "$tgTemplate", "$tgConfirm", "$translate", - "$compile", "$tgNavUrls", "$rootScope", HistoryDirective]) + "$compile", "$tgNavUrls", "$rootScope", "tgCheckPermissionsService", HistoryDirective]) diff --git a/app/modules/services/check-permissions.service.coffee b/app/modules/services/check-permissions.service.coffee index 5cac0802..5ca652e3 100644 --- a/app/modules/services/check-permissions.service.coffee +++ b/app/modules/services/check-permissions.service.coffee @@ -27,6 +27,8 @@ class ChekcPermissionsService constructor: (@projectService) -> check: (permission) -> + return false if !@projectService.project + return @projectService.project.get('my_permissions').indexOf(permission) != -1 angular.module("taigaCommon").service("tgCheckPermissionsService", ChekcPermissionsService) diff --git a/app/partials/common/history/history-base.jade b/app/partials/common/history/history-base.jade index 5accec64..ceef5a7c 100644 --- a/app/partials/common/history/history-base.jade +++ b/app/partials/common/history/history-base.jade @@ -1,15 +1,21 @@ include ../components/wysiwyg.jade section.history + <% if (commentsVisible || historyVisible) { %> ul.history-tabs + <% if (commentsVisible) { %> li a(href="#", class="active", data-section-class="history-comments") span.icon.icon-comment span.tab-title(translate="COMMENTS.TITLE") + <% } %> + <% if (historyVisible) { %> li a(href="#", data-section-class="history-activity") span.icon.icon-issues span.tab-title(translate="ACTIVITY.TITLE") + <% } %> + <% } %> section.history-comments .comments-list div(tg-editable-wysiwyg, ng-model!="<%- ngmodel %>") diff --git a/app/styles/modules/common/history.scss b/app/styles/modules/common/history.scss index 7145097e..96e4fdf4 100644 --- a/app/styles/modules/common/history.scss +++ b/app/styles/modules/common/history.scss @@ -49,6 +49,9 @@ &:first-child { border-right: 1px solid $gray-light; } + &:last-child { + border-right: 0; + } } a { color: $gray-light;