<commit_before>angular.module('pcApp.common.directives.common', [])

    .directive("scroll", function ($window) {
        return function (scope, element, attrs) {
            angular.element($window).bind("scroll", function () {
                if (this.pageYOffset >= 1) {
                    scope.CreateMenu = true;
                } else {
                    scope.CreateMenu = false;
                }
                scope.$apply();
            });
        };
    })

    .directive('editButtons', [
        'Auth', function (Auth) {
            return {
                restrict: 'E',
                rep1ace: true,
                scope: {
                    userpath: '@',
                    editurl: '@',
                    deletefunction: '='
                },
                template: '\
        <div class="button-group">\
        <a type="button" ng-if="allowEdit()" class="btn btn-primary btn-create" href="{{editurl}}">Edit</a>\
        <a type="button" ng-if="allowEdit()" class="btn btn-danger" ng-click="deletefunction();">Delete</a></div>\
        </div>',
                link: function (scope) {

                    var isOwner = function () {
                        return Auth.state.userPath === scope.userpath;
                    };

                    var isAdmin = function () {
                        if (Auth.state.isAdmin) {
                            return true;
                        } else {
                            return false;
                        }
                    };

                    scope.allowEdit = function () {
                        return (isAdmin() || isOwner());
                    };
                }
            };
        }
    ])

    .directive('username', [
        '$http', function ($http) {
            return {
                restrict: 'E',
                scope: {
                    userpath: '@'
                },
                template: '{{ username }}',
                link: function (scope) {
                    var url = scope.userpath;
                    $http({
                            url: url,
                            method: 'get',
                        }).then(function (response) {
                            scope.username = response.data.data["adhocracy_core.sheets.principal.IUserBasic"].name;
                        }, function (response) {
                            scope.username = "";
                    });
                }
            };
        }<commit_msg>Fix username directive Make sure it's an adhocracy response https://github.com/policycompass/policycompass/issues/499<commit_after>angular.module('pcApp.common.directives.common', [])

    .directive("scroll", function ($window) {
        return function (scope, element, attrs) {
            angular.element($window).bind("scroll", function () {
                if (this.pageYOffset >= 1) {
                    scope.CreateMenu = true;
                } else {
                    scope.CreateMenu = false;
                }
                scope.$apply();
            });
        };
    })

    .directive('editButtons', [
        'Auth', function (Auth) {
            return {
                restrict: 'E',
                rep1ace: true,
                scope: {
                    userpath: '@',
                    editurl: '@',
                    deletefunction: '='
                },
                template: '\
        <div class="button-group">\
        <a type="button" ng-if="allowEdit()" class="btn btn-primary btn-create" href="{{editurl}}">Edit</a>\
        <a type="button" ng-if="allowEdit()" class="btn btn-danger" ng-click="deletefunction();">Delete</a></div>\
        </div>',
                link: function (scope) {

                    var isOwner = function () {
                        return Auth.state.userPath === scope.userpath;
                    };

                    var isAdmin = function () {
                        if (Auth.state.isAdmin) {
                            return true;
                        } else {
                            return false;
                        }
                    };

                    scope.allowEdit = function () {
                        return (isAdmin() || isOwner());
                    };
                }
            };
        }
    ])

    .directive('username', [
        '$http', function ($http) {
            return {
                restrict: 'E',
                scope: {
                    userpath: '@'
                },
                template: '{{ username }}',
                link: function (scope) {
                    var url = scope.userpath;
                    $http({
                            url: url,
                            method: 'get'
                        }).then(function (response) {
                            if(response.data && response.data.content_type == "adhocracy_core.resources.principal.IUser") {
                                scope.username = response.data.data["adhocracy_core.sheets.principal.IUserBasic"].name;
                            } else {
                                scope.username = "Unknown User";
                            }
                        }, function (response) {
                            scope.username = "Deleted User";
                    });
                }
            };
        }
{'fraction_non_alphanumeric': 0.12418544032768572, 'fraction_numerical': 0.0013032954757028485, 'mean_word_length': 0.9484947406601378, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, 'https://': 1, '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': '7543588', 'n_tokens_mistral': 1304, 'n_tokens_neox': 1202, 'n_words': 224}