<commit_before>'use strict';
angular.module('kuulemmaApp')
  .directive('commentListItem', function ($rootScope, CommentListService) {
    return {
      templateUrl: '/static/dist/partials/components/comment-list-item/comment-list-item.html',
      restrict: 'A',
      scope: {
        comment: '=',
        hideComment: '&',
        unhideComment: '&',
        hearingId: '@'
      },
      link: function postLink(scope, element) {
        var editableEntries = ['username', 'body', 'title'];
        var editableEntriesBeforeChanges = _.pick(scope.$parent.comment, editableEntries);

        scope.saveChanges = function() {
          var editableEntriesBackup = angular.copy(editableEntriesBeforeChanges);
          editableEntriesBeforeChanges = _.pick(scope.$parent.comment, editableEntries);
          scope.commentUnderEdit = false;
          CommentListService.editComment({hearingId: scope.hearingId, comment: scope.$parent.comment})
            .success(function() {
              $rootScope.$broadcast('edited-comment-' + scope.$parent.comment.id);
            })
            .error(function() {
              scope.$parent.comment = _.extend(scope.$parent.comment, editableEntriesBackup);
            });
        };

        scope.cancelChanges = function() {
          scope.$parent.comment = _.extend(scope.$parent.comment, editableEntriesBeforeChanges);
          scope.commentUnderEdit = false;
        };

        var eventListenerRemover = $rootScope.$on('edited-comment-' + scope.$parent.comment.id, function() {
          eventListenerRemover();
          postLink(scope, element);
        });

        scope.$on('$destroy', eventListenerRemover);

        function makeContainerTruncatable(params) {
          _.defer(function () {
            var commentBodyContainer = element.find(params.selector);
            commentBodyContainer.dotdotdot({height: 150, after: '<button class="' + params.readmore.slice(1) + '">Lue lisää</button>'});

            commentBodyContainer.find(params.readmore).on('click', function() {
              commentBodyContainer.trigger('destroy.dot');
            });
          });
        }

        makeContainerTruncatable({ selector: '.comment-body', readmore: '.readmore' });<commit_msg>Fix bug where 'Read more' button appears when it shouldn't<commit_after>'use strict';
angular.module('kuulemmaApp')
  .directive('commentListItem', function ($rootScope, CommentListService) {
    return {
      templateUrl: '/static/dist/partials/components/comment-list-item/comment-list-item.html',
      restrict: 'A',
      scope: {
        comment: '=',
        hideComment: '&',
        unhideComment: '&',
        hearingId: '@'
      },
      link: function postLink(scope, element) {
        var editableEntries = ['username', 'body', 'title'];
        var editableEntriesBeforeChanges = _.pick(scope.$parent.comment, editableEntries);

        scope.saveChanges = function() {
          var editableEntriesBackup = angular.copy(editableEntriesBeforeChanges);
          editableEntriesBeforeChanges = _.pick(scope.$parent.comment, editableEntries);
          scope.commentUnderEdit = false;
          CommentListService.editComment({hearingId: scope.hearingId, comment: scope.$parent.comment})
            .success(function() {
              $rootScope.$broadcast('edited-comment-' + scope.$parent.comment.id);
            })
            .error(function() {
              scope.$parent.comment = _.extend(scope.$parent.comment, editableEntriesBackup);
            });
        };

        scope.cancelChanges = function() {
          scope.$parent.comment = _.extend(scope.$parent.comment, editableEntriesBeforeChanges);
          scope.commentUnderEdit = false;
        };

        var eventListenerRemover = $rootScope.$on('edited-comment-' + scope.$parent.comment.id, function() {
          eventListenerRemover();
          postLink(scope, element);
        });

        scope.$on('$destroy', eventListenerRemover);

        function makeContainerTruncatable(params) {
          _.defer(function () {
            var commentBodyContainer = element.find(params.selector);
            commentBodyContainer.dotdotdot({height: 150, watch: true, after: '<button class="' + params.readmore.slice(1) + '">Lue lisää</button>'});

            commentBodyContainer.find(params.readmore).on('click', function() {
              commentBodyContainer.trigger('destroy.dot');
            });
          });
        }

        makeContainerTruncatable({ selector: '.comment-body', readmore: '.readmore' });
{'fraction_non_alphanumeric': 0.13710387323943662, 'fraction_numerical': 0.0017605633802816902, 'mean_word_length': 2.6951219512195124, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1467071', 'n_tokens_mistral': 1206, 'n_tokens_neox': 1168, 'n_words': 191}