<commit_before>var myAppModule = angular.module('App', ['ui.rCalendar', 'ngToast', 'ui.bootstrap', 'ngMaterial', 'ngMessages', 'ngCookies', 'ngRoute', 'angularSpinners']);

myAppModule.config(['$httpProvider', '$routeProvider', function($httpProvider, $routeProvider) {
        $httpProvider.defaults.useXDomain = true;
        $httpProvider.defaults.withCredentials = true;
        delete $httpProvider.defaults.headers.common['X-Requested-With'];

        $routeProvider
            .when("/users", {
                templateUrl: "templates/users.html"
            })
            .otherwise({
                templateUrl: "templates/calendar.html"
            });
    }
]);

myAppModule.constant("CONFIG", {
    "API_ENDPOINT": "http://localhost:5000"
});

myAppModule.constant("COOKIE_KEYS", {
    "USERNAME":"username",
    "AUTHENTICATED": "authenticated",
    "IS_ADMIN": "isAdmin"
});

myAppModule.service('AuthService', function($http, CONFIG){
    this.checkUniqueValue = function(property, value) {
        return $http.get(CONFIG.API_ENDPOINT + "/users/checkUnique", {'params':{'key': property, 'value':value}}).then( function(result) {
            return result.data.unique;
        });
    }
});

myAppModule.directive("ngUnique", function(AuthService) {
    return {
        restrict: 'A',
        require: 'ngModel',
        link: function (scope, element, attrs, ngModel) {
            element.bind('blur', function (e) {
            if (!ngModel || !element.val()) return;
                var keyProperty = scope.$eval(attrs.ngUnique);
                var currentValue = element.val();
                AuthService.checkUniqueValue(keyProperty.property, currentValue)
                    .then(function (unique) {
                        if (currentValue == element.val()) {
                            ngModel.$setValidity('unique', unique);
                            scope.$broadcast('show-errors-check-validity');
                        }
                });
            });
        }
    }
});

myAppModule.directive("compareTo", function() {
   return {
       require: "ngModel",
       scope: {
           otherModelValue: "=compareTo"
       },
       link: function(scope, element, attributes, ngModel) {

           ngModel.$validators.compareTo = function(modelValue) {
               return modelValue === scope.otherModelValue;
           };

           scope.$watch("otherModelValue", function() {
               ngModel.$validate();
           });
       }
   };
});

myAppModule.directive("datepicker", function () {
    return {
        restrict: "A",
        require: "ngModel",

        link: function (scope, elem, attrs, ngModelCtrl) {
            var updateModel = function (event) {

            scope.$apply(function () {
                ngModelCtrl.$modelValue = elem.val();
                var ngModelNameArray = elem["0"].attributes["ng-model"].value.split(".");
                if(!scope.event){
                    scope.event = {};
                }
                scope.event[ngModelNameArray[1]] = event.date.toDate();
            });
        };

        elem.datetimepicker({
            inline: true,
            sideBySide: true,
            locale: 'de',
            toolbarPlacement: 'top',
            showClear: true,
            format: "DD.MM.YYYY HH:mm Z",
            showTodayButton: true
        });

        elem.on("dp.change",function (e) {
            updateModel(e);
        });
    }
}
});

myAppModule.run(function($rootScope, $cookies){
    $rootScope.currentUser = $cookies.get("username");
});

myAppModule.controller('CalendarCtrl', function ($scope, $rootScope, $http, $sce, ngToast, $timeout, CONFIG, COOKIE_KEYS, spinnerService) {
    'use strict';
    $scope.changeMode = function (mode) {
        $scope.mode = mode;
    };

    $scope.today = function () {
        $scope.currentDate = new Date();
    };

    $scope.initEvents = function () {
        $http.get(CONFIG.API_ENDPOINT + '/reservations')
            .then(function(response) {
                $scope.displayEvents(response.data);
            }, function() {
                $scope.showErrorToast("Cannot load reservations, please try again later!");
            }
        );
    };

    $scope.isAuthenticated = function() {
        return $cookies.get(COOKIE_KEYS.AUTHENTICATED);
    };

    $scope.displayEvents = function (events) {
        var allEvents = [];
        for(var i = 0; i < events.length; i++){
            var data = events[i];
            allEvents.push({ id: data.id, title: data.title, startTime: new Date(data.startTime), endTime: new Date(data.endTime), allDay: data.allDay, description: data.description, userId: data.userId });
        }
        $rootScope.eventSource = allEvents;
        $scope.eventSource = $rootScope.eventSource;
    };

    $scope.isToday = function () {
        var today = new Date(),
            currentCalendarDate = new Date($scope.currentDate);

        today.setHours(0, 0, 0, 0);
        currentCalendarDate.setHours(0, 0, 0, 0);
        return today.getTime() === currentCalendarDate.getTime();
    };

    $scope.onEventSelected = function (event) {
    };

    $scope.onTimeSelected = function (selectedTime) {
    };<commit_msg>Set default date to last selected<commit_after>var myAppModule = angular.module('App', ['ui.rCalendar', 'ngToast', 'ui.bootstrap', 'ngMaterial', 'ngMessages', 'ngCookies', 'ngRoute', 'angularSpinners']);

myAppModule.config(['$httpProvider', '$routeProvider', function($httpProvider, $routeProvider) {
        $httpProvider.defaults.useXDomain = true;
        $httpProvider.defaults.withCredentials = true;
        delete $httpProvider.defaults.headers.common['X-Requested-With'];

        $routeProvider
            .when("/users", {
                templateUrl: "templates/users.html"
            })
            .otherwise({
                templateUrl: "templates/calendar.html"
            });
    }
]);

myAppModule.constant("CONFIG", {
    "API_ENDPOINT": "http://localhost:5000"
});

myAppModule.constant("COOKIE_KEYS", {
    "USERNAME":"username",
    "AUTHENTICATED": "authenticated",
    "IS_ADMIN": "isAdmin"
});

myAppModule.service('AuthService', function($http, CONFIG){
    this.checkUniqueValue = function(property, value) {
        return $http.get(CONFIG.API_ENDPOINT + "/users/checkUnique", {'params':{'key': property, 'value':value}}).then( function(result) {
            return result.data.unique;
        });
    }
});

myAppModule.directive("ngUnique", function(AuthService) {
    return {
        restrict: 'A',
        require: 'ngModel',
        link: function (scope, element, attrs, ngModel) {
            element.bind('blur', function (e) {
            if (!ngModel || !element.val()) return;
                var keyProperty = scope.$eval(attrs.ngUnique);
                var currentValue = element.val();
                AuthService.checkUniqueValue(keyProperty.property, currentValue)
                    .then(function (unique) {
                        if (currentValue == element.val()) {
                            ngModel.$setValidity('unique', unique);
                            scope.$broadcast('show-errors-check-validity');
                        }
                });
            });
        }
    }
});

myAppModule.directive("compareTo", function() {
   return {
       require: "ngModel",
       scope: {
           otherModelValue: "=compareTo"
       },
       link: function(scope, element, attributes, ngModel) {

           ngModel.$validators.compareTo = function(modelValue) {
               return modelValue === scope.otherModelValue;
           };

           scope.$watch("otherModelValue", function() {
               ngModel.$validate();
           });
       }
   };
});

myAppModule.directive("datepicker", function ($rootScope) {
    return {
        restrict: "A",
        require: "ngModel",

        link: function (scope, elem, attrs, ngModelCtrl) {
            var updateModel = function (event) {

            scope.$apply(function () {
                ngModelCtrl.$modelValue = elem.val();
                var ngModelNameArray = elem["0"].attributes["ng-model"].value.split(".");
                if(!scope.event){
                    scope.event = {};
                }
                scope.event[ngModelNameArray[1]] = event.date.toDate();
            });
        };

        elem.datetimepicker({
            inline: true,
            sideBySide: true,
            locale: 'de',
            toolbarPlacement: 'top',
            showClear: true,
            defaultDate: $rootScope.selectedDate,
            format: "DD.MM.YYYY HH:mm Z",
            showTodayButton: true
        });

        elem.on("dp.change",function (e) {
            updateModel(e);
        });
    }
}
});

myAppModule.run(function($rootScope, $cookies){
    $rootScope.currentUser = $cookies.get("username");
    $rootScope.selectedDate = false;
});

myAppModule.controller('CalendarCtrl', function ($scope, $rootScope, $http, $sce, ngToast, $timeout, CONFIG, COOKIE_KEYS, spinnerService) {
    'use strict';
    $scope.changeMode = function (mode) {
        $scope.mode = mode;
    };

    $scope.today = function () {
        $scope.currentDate = new Date();
    };

    $scope.initEvents = function () {
        $http.get(CONFIG.API_ENDPOINT + '/reservations')
            .then(function(response) {
                $scope.displayEvents(response.data);
            }, function() {
                $scope.showErrorToast("Cannot load reservations, please try again later!");
            }
        );
    };

    $scope.isAuthenticated = function() {
        return $cookies.get(COOKIE_KEYS.AUTHENTICATED);
    };

    $scope.displayEvents = function (events) {
        var allEvents = [];
        for(var i = 0; i < events.length; i++){
            var data = events[i];
            allEvents.push({ id: data.id, title: data.title, startTime: new Date(data.startTime), endTime: new Date(data.endTime), allDay: data.allDay, description: data.description, userId: data.userId });
        }
        $rootScope.eventSource = allEvents;
        $scope.eventSource = $rootScope.eventSource;
    };

    $scope.isToday = function () {
        var today = new Date(),
            currentCalendarDate = new Date($scope.currentDate);

        today.setHours(0, 0, 0, 0);
        currentCalendarDate.setHours(0, 0, 0, 0);
        return today.getTime() === currentCalendarDate.getTime();
    };

    $scope.onEventSelected = function (event) {
    };

    $scope.onTimeSelected = function (selectedTime) {
        $rootScope.selectedDate = selectedTime;
    };
{'fraction_non_alphanumeric': 0.14476530900197535, 'fraction_numerical': 0.0028219358479917222, 'mean_word_length': 2.144631765749778, 'pattern_counts': {'":': 8, '<': 5, '<?xml version=': 0, '>': 3, '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': '872695', 'n_tokens_mistral': 3038, 'n_tokens_neox': 2945, 'n_words': 536}