<commit_before>'use strict';

function TopBarCtrl($rootScope, $scope, $location, resource, userService) {

    $scope.$on('$routeChangeSuccess', function (event, current, previous) {
        var path = $location.path().split('/')[1];
        $scope.mapButton = (path === 'concept' || path === 'article' || path === 'resource');
        $scope.resourceButton = (current.$route.controller.name === "MapCtrl");

        $scope.resourceId = current.params.id;

        // Load Karma if necessary
        if ($rootScope.user != null && $rootScope.user.karma == null) {
            userService.getLoggedUserKarma($rootScope.user).success(function (response) {
                $rootScope.user.karma = response.karma;
            });
        }
    });

    $scope.$on('searchResultSelected', function (event, result) {
        event.stopPropagation();
        switch (result.type) {
            case 'Link to Resource':
                delete result.type; // type is used only client-side, should not be persisted
                resource.create(result).then(function (createdResource) {
                    $location.path('/resource/' + createdResource.KN_ID);
                });
                break;
            case 'Wikipedia Article':
                $location.path('/wikipedia/' + result.id);
                break;
            case 'Resource':
                $location.path('/resource/' + result.KN_ID);
                break;
        }
    });

    $scope.$on('mapNavigated', function (event, result) {
        event.stopPropagation();
        $scope.resourceId = result;
    });
}

function NotificationsCtrl($scope, notification) {

    notification.getNotifications(function (result) {
        $scope.notifications = result;
        var isReadCount = _.countBy(result, function (notification) {
            return notification.alreadyRead;
        });
        $scope.unreadCount = isReadCount.false;
    });

    $scope.getStyle = function (isRead) {
        if (isRead)
            return 'background-color:lightgrey';
        else
            return '';
    };

    $scope.markAllAsRead = function () {
        $scope.unreadCount = 0;
        notification.markAllAsRead();
    }
}

function CreateResourceModalCtrl($scope, dialog, resource) {

    $scope.resourceToCreate = {title: dialog.options.title};

    $scope.close = function () {
        dialog.close();
    };

    $scope.submit = function () {
        $scope.submitted = true;
        $scope.resourceToCreate.title = capitaliseFirstLetter($scope.resourceToCreate.title);
        resource.create($scope.resourceToCreate).then(function (createdResource) {
            dialog.close(createdResource);
        });
    };
    function capitaliseFirstLetter(string)
    {
        return string.charAt(0).toUpperCase() + string.slice(1);
    }
}

function LoginCtrl($scope, $location, $rootScope, $window, loginModal, userService) {

    $scope.loginForm = {};
    $scope.userForm = {};
    $scope.newUser;
    $scope.submitUser = function (userForm) {
        userService.create(userForm).
            success(function (data, status, headers, config) {
                $scope.loginForm.email = userForm.email;
                $scope.loginForm.password = <PASSWORD>;
                $scope.newUser = true;
                return $scope.performLogin();
            });
    };

    $scope.performLogin = function () {
        userService.login($scope.loginForm).
            then(function (data, status, headers, config) {
                if (data === 'ERROR') {
                    return $scope.loginerror = true;
                }
                $rootScope.user = data;
                if ($scope.newUser === true) {
                    $location.path('/');
                } else {
                    $window.history.back();
                }
            });
    };

    $scope.closeLoginModal = function () {
        loginModal.close();
    };

}


function LogoutCtrl($location, $rootScope, userService) {
    userService.logout().
        success(function (data) {
            if (data.success === 'Logout') {
                $rootScope.user = null;
                $rootScope.userDisplayName = null;
                $location.path('/');
            }
        });
}


function MapCtrl($scope, $routeParams) {
    $(document).ready(function () {
        var css = jQuery("<link>");
        css.attr({
            rel: "stylesheet",
            type: "text/css",
            href: "http://fonts.googleapis.com/css?family=Roboto"
        });
        $("head").append(css);

        function navigationListener(resourceId) {
            $scope.$emit("mapNavigated", resourceId);
        };

        Renderer.init("viewport", $routeParams.id, navigationListener);
        PanelsHandler.initPanels();
    });
}

function GraphCtrl($scope) {

    $scope.$on('$viewContentLoaded', function() {

        var sigInst = sigma.init(document.getElementById('sigma-example')).drawingProperties({
            defaultLabelColor: '#fff',
            defaultLabelSize: 14,
            defaultLabelBGColor: '#fff',
            defaultLabelHoverColor: '#000',
            labelThreshold: 6,
            defaultEdgeType: 'curve'
        }).graphProperties({
                minNodeSize: 0.5,
                maxNodeSize: 5,
                minEdgeSize: 1,
                maxEdgeSize: 1,
                sideMargin: 50
            }).mouseProperties({
                maxRatio: 32
            });

        // Parse a GEXF encoded file to fill the graph
        // (requires "sigma.parseGexf.js" to be included)
        sigInst.parseGexf('/gexf/userTriplets/69bd8aaa-cb59-4143-9e71-455a98c244c0.gexf');

        // Draw the graph :

        sigInst.draw();
        requestAnimationFrame(sigInst.resize.bind());

    });

}


function TripletListCtrl($scope, $routeParams, $location, userService, resource, wikipedia, wikinode) {
    $scope.goToUrl = function (something) {
        $location.path(something);
    };

    // Sort triplets by default the most recent ones at the top

    $scope.orderProp = "-connection.__CreatedOn__";

    // $scope.orderProp = "-(upvotes-downvotes)";


    // First, check whether the resource is a KN Resource or a Wikipedia Article
    if ($routeParams.id != null) {
        // KN Resource
        resource.get($routeParams.id).then(function (resource) {
            $scope.concept = resource;

            $scope.rootNodeExists = true;
            if ($scope.concept.url != null && $scope.concept.url.match(/youtube.com/ig)) {
                var search = $scope.concept.url.split('?')[1];
                var video_id = search.split('v=')[1];
                var ampersandPosition = video_id.indexOf('&');
                if (ampersandPosition != -1) {
                    video_id = video_id.substring(0, ampersandPosition);
                }
                $scope.videoLink = video_id;
            }

            $scope.knownodeList = resource.relations;
        });
    } else if ($routeParams.title != null) {
        // Check if a Wikinode exists for this Wikipedia article
        wikinode.get($routeParams.title)
            .success(function (data) {
                $location.path('/resource/' + data.KN_ID);
            })
            .error(function (data, status) {
                if (status != 404) console.log('Unexpected Error', data);
                // No Wikinode, just a plain Wikipedia article
                wikipedia.getArticle($routeParams.title).then(function (article) {
                    $scope.concept = {
                        type: 'Wikipedia Article',
                        title: article.title,
                        bodyText: article.extract,
                        wikipediaLinks: article.links
                    };
                    $scope.rootNodeExists = true;
                });
            });
    } else throw 'No id nor title found in URL';

    $scope.addNode = false;
    $scope.currentKnownode = {};
    $scope.isUserLoggedIn = userService.isUserLoggedIn();

    $scope.$broadcast('rootNodeExists', {rootNodeExists: true});

}


function IndexCtrl($scope, userService, $location, triplets) {

    $scope.goToUrl = function (something) {
        $location.path(something);
    };

    $scope.isUserLoggedIn = userService.isUserLoggedIn();
    $scope.knownodeList = {};
    $scope.orderProp = "-(upvotes - downvotes)";
    triplets.hottest().success(function (data, status, headers, config) {
        $scope.knownodeList = data;
    });
}

function DeleteUserCtrl($scope, $http, $location, $routeParams) {
    $http.get('/users/' + $routeParams.id).
        success(function (data) {
            $scope.post = data.post;
        });

    $scope.deleteUser = function () {
        $http.delete('/users/:' + $routeParams.id).
            success(function (data, status, headers, config) {
                $location.url('/');
            });
    };

    $scope.home = function () {
        $location.url('/');
    };
}


function commentCtrl($scope, $routeParams, broadcastService, comment) {
    var objectId = $routeParams.id;
    $scope.comments = [];

    comment.findByConnectionId(objectId)
        .success(function (data, status, headers, config) {
            $scope.comments = data;
        });

    $scope.addComment = function () {

    };

    $scope.$on('handleBroadcast', function () {
        $scope.comments.push(broadcastService.message);
    });
}


function addCommentCtrl($scope, $routeParams, userService, broadcastService, comment) {
    var objectId = $routeParams.id;
    $scope.isUserLoggedIn = userService.isUserLoggedIn();

    $scope.form = $scope.form || {};
    $scope.form.comment = {};
    $scope.form.originalObject = {};
    $scope.form.originalObject.id = objectId;

    $scope.submitComment = function (originalObjectId) {
        $scope.submitMade = false;
        $scope.submitNotMade = false;

        $scope.form.originalObject.id = originalObjectId || $scope.form.originalObject.id;

        comment.create($scope.form.comment.bodyText, $scope.form.originalObject.id)
            .success(function (data, status, headers, config) {
                    var comment = data;
                    comment.user = userService.getConnectedUser();
                    broadcastService.prepForBroadcast(comment);
                    $scope.submitMade = true;
                    $scope.form.comment.bodyText = "";
                }).error(function (data, status, headers, config) {
                    console.log("error", data.error);
                    $scope.submitNotMade = false;
                    $scope.error = data.error;
            });
    };
}


function StaticPageCtrl($scope) {
}


function ConnectionPageCtrl($scope, $routeParams, userService, triplet) {
    $scope.isUserLoggedIn = userService.isUserLoggedIn();
    $scope.knownodeList = {};
    triplet.findByConnectionId($routeParams.id).success(function (data) {
        $scope.knownodeList = [data];
    });

}

function TripletInputCtrl($scope, $rootScope, $route, wikinode, resource, connection) {

    $scope.reversedDirection = false;

    $scope.$watch('concept', function (newValue) {
<<<<<<< HEAD
        if ($scope.startResource == null)
            $scope.startResource = newValue;
=======
            if(!newValue) return;
            $scope.startResource = $scope.startResource || newValue;
            $scope.tutorialText = $scope.tutorialText || {};
            $scope.tutorialText.startResource = "This is the resource " + $scope.startResource.title;
            $scope.tutorialText.connection = "Here you describe how "+ $scope.startResource.title+" is connected to the second resource.";
            $scope.tutorialText.endResource = "Here you enter the name of the resource to connect with " + $scope.startResource.title;

>>>>>>> master
    });
<commit_msg>fixed inconsistencies with master in controllerjs<commit_after>'use strict';

function TopBarCtrl($rootScope, $scope, $location, resource, userService) {

    $scope.$on('$routeChangeSuccess', function (event, current, previous) {
        var path = $location.path().split('/')[1];
        $scope.mapButton = (path === 'concept' || path === 'article' || path === 'resource');
        $scope.resourceButton = (current.$route.controller.name === "MapCtrl");

        $scope.resourceId = current.params.id;

        // Load Karma if necessary
        if ($rootScope.user != null && $rootScope.user.karma == null) {
            userService.getLoggedUserKarma($rootScope.user).success(function (response) {
                $rootScope.user.karma = response.karma;
            });
        }
    });

    $scope.$on('searchResultSelected', function (event, result) {
        event.stopPropagation();
        switch (result.type) {
            case 'Link to Resource':
                delete result.type; // type is used only client-side, should not be persisted
                resource.create(result).then(function (createdResource) {
                    $location.path('/resource/' + createdResource.KN_ID);
                });
                break;
            case 'Wikipedia Article':
                $location.path('/wikipedia/' + result.id);
                break;
            case 'Resource':
                $location.path('/resource/' + result.KN_ID);
                break;
        }
    });

    $scope.$on('mapNavigated', function (event, result) {
        event.stopPropagation();
        $scope.resourceId = result;
    });
}

function NotificationsCtrl($scope, notification) {

    notification.getNotifications(function (result) {
        $scope.notifications = result;
        var isReadCount = _.countBy(result, function (notification) {
            return notification.alreadyRead;
        });
        $scope.unreadCount = isReadCount.false;
    });

    $scope.getStyle = function (isRead) {
        if (isRead)
            return 'background-color:lightgrey';
        else
            return '';
    };

    $scope.markAllAsRead = function () {
        $scope.unreadCount = 0;
        notification.markAllAsRead();
    }
}

function CreateResourceModalCtrl($scope, dialog, resource) {

    $scope.resourceToCreate = {title: dialog.options.title};

    $scope.close = function () {
        dialog.close();
    };

    $scope.submit = function () {
        $scope.submitted = true;
        $scope.resourceToCreate.title = capitaliseFirstLetter($scope.resourceToCreate.title);
        resource.create($scope.resourceToCreate).then(function (createdResource) {
            dialog.close(createdResource);
        });
    };
    function capitaliseFirstLetter(string)
    {
        return string.charAt(0).toUpperCase() + string.slice(1);
    }
}

function LoginCtrl($scope, $location, $rootScope, $window, loginModal, userService) {

    $scope.loginForm = {};
    $scope.userForm = {};
    $scope.newUser;
    $scope.submitUser = function (userForm) {
        userService.create(userForm).
            success(function (data, status, headers, config) {
                $scope.loginForm.email = userForm.email;
                $scope.loginForm.password = userForm.password;
                $scope.newUser = true;
                return $scope.performLogin();
            });
    };

    $scope.performLogin = function () {
        userService.login($scope.loginForm).
            then(function (data, status, headers, config) {
                if (data === 'ERROR') {
                    return $scope.loginerror = true;
                }
                $rootScope.user = data;
                if ($scope.newUser === true) {
                    $location.path('/');
                } else {
                    $window.history.back();
                }
            });
    };

    $scope.closeLoginModal = function () {
        loginModal.close();
    };

}


function LogoutCtrl($location, $rootScope, userService) {
    userService.logout().
        success(function (data) {
            if (data.success === 'Logout') {
                $rootScope.user = null;
                $rootScope.userDisplayName = null;
                $location.path('/');
            }
        });
}


function MapCtrl($scope, $routeParams) {
    $(document).ready(function () {
        var css = jQuery("<link>");
        css.attr({
            rel: "stylesheet",
            type: "text/css",
            href: "http://fonts.googleapis.com/css?family=Roboto"
        });
        $("head").append(css);

        function navigationListener(resourceId) {
            $scope.$emit("mapNavigated", resourceId);
        };

        Renderer.init("viewport", $routeParams.id, navigationListener);
        PanelsHandler.initPanels();
    });
}

function GraphCtrl($scope) {

    $scope.$on('$viewContentLoaded', function() {

        var sigInst = sigma.init(document.getElementById('sigma-example')).drawingProperties({
            defaultLabelColor: '#fff',
            defaultLabelSize: 14,
            defaultLabelBGColor: '#fff',
            defaultLabelHoverColor: '#000',
            labelThreshold: 6,
            defaultEdgeType: 'curve'
        }).graphProperties({
                minNodeSize: 0.5,
                maxNodeSize: 5,
                minEdgeSize: 1,
                maxEdgeSize: 1,
                sideMargin: 50
            }).mouseProperties({
                maxRatio: 32
            });

        // Parse a GEXF encoded file to fill the graph
        // (requires "sigma.parseGexf.js" to be included)
        sigInst.parseGexf('/gexf/userTriplets/69bd8aaa-cb59-4143-9e71-455a98c244c0.gexf');

        // Draw the graph :

        sigInst.draw();
        requestAnimationFrame(sigInst.resize.bind());

    });

}


function TripletListCtrl($scope, $routeParams, $location, userService, resource, wikipedia, wikinode) {
    $scope.goToUrl = function (something) {
        $location.path(something);
    };

    // Sort triplets by default the most recent ones at the top

    $scope.orderProp = "-connection.__CreatedOn__";

    // $scope.orderProp = "-(upvotes-downvotes)";


    // First, check whether the resource is a KN Resource or a Wikipedia Article
    if ($routeParams.id != null) {
        // KN Resource
        resource.get($routeParams.id).then(function (resource) {
            $scope.concept = resource;

            $scope.rootNodeExists = true;
            if ($scope.concept.url != null && $scope.concept.url.match(/youtube.com/ig)) {
                var search = $scope.concept.url.split('?')[1];
                var video_id = search.split('v=')[1];
                var ampersandPosition = video_id.indexOf('&');
                if (ampersandPosition != -1) {
                    video_id = video_id.substring(0, ampersandPosition);
                }
                $scope.videoLink = video_id;
            }

            $scope.knownodeList = resource.relations;
        });
    } else if ($routeParams.title != null) {
        // Check if a Wikinode exists for this Wikipedia article
        wikinode.get($routeParams.title)
            .success(function (data) {
                $location.path('/resource/' + data.KN_ID);
            })
            .error(function (data, status) {
                if (status != 404) console.log('Unexpected Error', data);
                // No Wikinode, just a plain Wikipedia article
                wikipedia.getArticle($routeParams.title).then(function (article) {
                    $scope.concept = {
                        type: 'Wikipedia Article',
                        title: article.title,
                        bodyText: article.extract,
                        wikipediaLinks: article.links
                    };
                    $scope.rootNodeExists = true;
                });
            });
    } else throw 'No id nor title found in URL';

    $scope.addNode = false;
    $scope.currentKnownode = {};
    $scope.isUserLoggedIn = userService.isUserLoggedIn();

    $scope.$broadcast('rootNodeExists', {rootNodeExists: true});

}


function IndexCtrl($scope, userService, $location, triplets) {

    $scope.goToUrl = function (something) {
        $location.path(something);
    };

    $scope.isUserLoggedIn = userService.isUserLoggedIn();
    $scope.knownodeList = {};
    $scope.orderProp = "-(upvotes - downvotes)";
    triplets.hottest().success(function (data, status, headers, config) {
        $scope.knownodeList = data;
    });
}

function DeleteUserCtrl($scope, $http, $location, $routeParams) {
    $http.get('/users/' + $routeParams.id).
        success(function (data) {
            $scope.post = data.post;
        });

    $scope.deleteUser = function () {
        $http.delete('/users/:' + $routeParams.id).
            success(function (data, status, headers, config) {
                $location.url('/');
            });
    };

    $scope.home = function () {
        $location.url('/');
    };
}


function commentCtrl($scope, $routeParams, broadcastService, comment) {
    var objectId = $routeParams.id;
    $scope.comments = [];

    comment.findByConnectionId(objectId)
        .success(function (data, status, headers, config) {
            $scope.comments = data;
        });

    $scope.addComment = function () {

    };

    $scope.$on('handleBroadcast', function () {
        $scope.comments.push(broadcastService.message);
    });
}


function addCommentCtrl($scope, $routeParams, userService, broadcastService, comment) {
    var objectId = $routeParams.id;
    $scope.isUserLoggedIn = userService.isUserLoggedIn();

    $scope.form = $scope.form || {};
    $scope.form.comment = {};
    $scope.form.originalObject = {};
    $scope.form.originalObject.id = objectId;

    $scope.submitComment = function (originalObjectId) {
        $scope.submitMade = false;
        $scope.submitNotMade = false;

        $scope.form.originalObject.id = originalObjectId || $scope.form.originalObject.id;

        comment.create($scope.form.comment.bodyText, $scope.form.originalObject.id)
            .success(function (data, status, headers, config) {
                    var comment = data;
                    comment.user = userService.getConnectedUser();
                    broadcastService.prepForBroadcast(comment);
                    $scope.submitMade = true;
                    $scope.form.comment.bodyText = "";
                }).error(function (data, status, headers, config) {
                    console.log("error", data.error);
                    $scope.submitNotMade = false;
                    $scope.error = data.error;
            });
    };
}


function StaticPageCtrl($scope) {
}


function ConnectionPageCtrl($scope, $routeParams, userService, triplet) {
    $scope.isUserLoggedIn = userService.isUserLoggedIn();
    $scope.knownodeList = {};
    triplet.findByConnectionId($routeParams.id).success(function (data) {
        $scope.knownodeList = [data];
    });

}

function TripletInputCtrl($scope, $rootScope, $route, wikinode, resource, connection) {

    $scope.reversedDirection = false;

    $scope.$watch('concept', function (newValue) {
            if(!newValue) return;
            $scope.startResource = $scope.startResource || newValue;
            $scope.tutorialText = $scope.tutorialText || {};
            $scope.tutorialText.startResource = "This is the resource " + $scope.startResource.title;
            $scope.tutorialText.connection = "Here you describe how "+ $scope.startResource.title+" is connected to the second resource.";
            $scope.tutorialText.endResource = "Here you enter the name of the resource to connect with " + $scope.startResource.title;

    });

{'fraction_non_alphanumeric': 0.13440312446934963, 'fraction_numerical': 0.003990490745457633, 'mean_word_length': 2.0829734327967544, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '1178035', 'n_tokens_mistral': 6696, 'n_tokens_neox': 6318, 'n_words': 1228}