<commit_before>'use strict';

/**
 * @ngdoc directive
 * @name oncokb.directive:comments
 * @description
 * # comments
 */
angular.module('oncokbApp')
    .directive('commentsDict', function(DatabaseConnector, users, $timeout) {
        return {
            templateUrl: 'views/comments.html',
            restrict: 'AE',
            scope: {
                object: '=',
                addComment: '&addComment',
                comments: '=',
                fileEditable: '=',
                parentEvent: '='
            },
            replace: true,
            link: function postLink(scope, element, attrs) {
                scope.mouseLeaveTimeout = '';
                scope.key = attrs.key;
                scope.params = {};
                scope.status = {
                    hasComment: false,
                    allResolved: false
                };
                scope.userRole = users.getMe().role;

                if (attrs.geneName) {
                    scope.geneName = attrs.geneName;
                }

                if (attrs.mutation) {
                    scope.mutation = attrs.mutation;
                }

                if (attrs.tumorType) {
                    scope.tumorType = attrs.tumorType;
                }

                if (attrs.therapy) {
                    scope.therapy = attrs.therapy;
                }

                if (attrs.displayName) {
                    scope.displayName = attrs.displayName;
                }

                // create a copy of comments. The original comments is a big
                // object, has too many methods, cannot use scope watch on the
                // whole object.
                scope.commentsCopy = [];

                scope.$watch('comments.length', function() {
                    if (scope.fileEditable || scope.comments.length > 0) {
                        element.find('i').off('mouseenter');
                        element.find('i').bind('mouseenter', function() {
                            if (scope.mouseLeaveTimeout) {
                                $timeout.cancel(scope.mouseLeaveTimeout);
                                scope.mouseLeaveTimeout = '';
                            }
                            element.find('commentsBody').show();
                        });

                        element.find('i').off('mouseleave');
                        element.find('i').bind('mouseleave', function() {
                            scope.mouseLeaveTimeout = $timeout(function() {
                                element.find('commentsBody').hide();
                            }, 500);
                        });
                    } else {
                        element.find('i').off('mouseenter');
                        element.find('i').off('mouseleave');
                    }

                    var commentsCopy = {
                        resolved: [],
                        content: []
                    };
                    for (var i = 0; i < scope.comments.length; i++) {
                        commentsCopy.resolved.push(scope.comments.get(i).resolved.getText());
                        commentsCopy.content.push(scope.comments.get(i).content.getText());
                    }
                    scope.commentsCopy = commentsCopy;
                });

                scope.$watch('commentsCopy.resolved', function() {
                    var allResolved = true;
                    if (scope.commentsCopy.resolved.length > 0) {
                        scope.status.hasComment = true;
                        for (var i = 0; i < scope.commentsCopy.resolved.length; i++) {
                            if (scope.commentsCopy.resolved[i] !== 'true') {
                                allResolved = false;
                                break;
                            }
                        }
                        scope.status.allResolved = allResolved;
                    } else {
                        scope.status = {
                            hasComment: false,
                            allResolved: false<commit_msg>Comment button update<commit_after>'use strict';

/**
 * @ngdoc directive
 * @name oncokb.directive:comments
 * @description
 * # comments
 */
angular.module('oncokbApp')
    .directive('commentsDict', function(DatabaseConnector, users, $timeout) {
        return {
            templateUrl: 'views/comments.html',
            restrict: 'AE',
            scope: {
                object: '=',
                addComment: '&addComment',
                comments: '=',
                fileEditable: '=',
                parentEvent: '='
            },
            replace: true,
            link: function postLink(scope, element, attrs) {
                scope.mouseLeaveTimeout = '';
                scope.key = attrs.key;
                scope.params = {};
                scope.status = {
                    hasComment: false,
                    allResolved: false
                };
                scope.userRole = users.getMe().role;

                if (attrs.geneName) {
                    scope.geneName = attrs.geneName;
                }

                if (attrs.mutation) {
                    scope.mutation = attrs.mutation;
                }

                if (attrs.tumorType) {
                    scope.tumorType = attrs.tumorType;
                }

                if (attrs.therapy) {
                    scope.therapy = attrs.therapy;
                }

                if (attrs.displayName) {
                    scope.displayName = attrs.displayName;
                }

                // create a copy of comments. The original comments is a big
                // object, has too many methods, cannot use scope watch on the
                // whole object.
                scope.commentsCopy = [];

                element.find('i').off('mouseenter');
                element.find('i').bind('mouseenter', function() {
                    if (scope.mouseLeaveTimeout) {
                        $timeout.cancel(scope.mouseLeaveTimeout);
                        scope.mouseLeaveTimeout = '';
                    }
                    element.find('commentsBody').show();
                });

                element.find('i').off('mouseleave');
                element.find('i').bind('mouseleave', function() {
                    scope.mouseLeaveTimeout = $timeout(function() {
                        element.find('commentsBody').hide();
                    }, 500);
                });

                scope.$watch('comments.length', function() {
                    var commentsCopy = {
                        resolved: [],
                        content: []
                    };
                    for (var i = 0; i < scope.comments.length; i++) {
                        commentsCopy.resolved.push(scope.comments.get(i).resolved.getText());
                        commentsCopy.content.push(scope.comments.get(i).content.getText());
                    }
                    scope.commentsCopy = commentsCopy;
                });

                scope.$watch('commentsCopy.resolved', function() {
                    var allResolved = true;
                    if (scope.commentsCopy.resolved.length > 0) {
                        scope.status.hasComment = true;
                        for (var i = 0; i < scope.commentsCopy.resolved.length; i++) {
                            if (scope.commentsCopy.resolved[i] !== 'true') {
                                allResolved = false;
                                break;
                            }
                        }
                        scope.status.allResolved = allResolved;
                    } else {
                        scope.status = {
                            hasComment: false,
                            allResolved: false
{'fraction_non_alphanumeric': 0.10663265306122449, 'fraction_numerical': 0.0016581632653061224, 'mean_word_length': 1.006910673150755, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 6, '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': '3820758', 'n_tokens_mistral': 1867, 'n_tokens_neox': 1693, 'n_words': 312}