<commit_before>Application.Directives.directive("homeCalendar", homeCalendarDirective);
function homeCalendarDirective() {
    return {
        restrict: "A",
        controller: 'homeCalendarController',
        scope: {
            project: '=project'
        },
        templateUrl: 'application/core/projects/project/home/directives/home-calendar.html'
    };
}

Application.Controllers.controller("homeCalendarController",
    ["$scope", "Events", "uiCalendarConfig",
        "$compile", "$timeout", "ui",
        homeCalendarController]);
function homeCalendarController($scope, Events, uiCalendarConfig, $compile, $timeout, ui) {
    $scope.project = Events.addConvertedTime($scope.project);

    $scope.event_reviews = {
        color: '#4884b8',
        events: Events.prepareCalendarEvent($scope.project.reviews, "reviews")
    };
    $scope.event_notes = {
        color: '#3ea7a0',
        events: Events.prepareCalendarEvent($scope.project.notes, "notes")
    };
    $scope.event_processes = {
        color: '#e26a6a',
        events: Events.prepareCalendarEvent($scope.project.processes, "processes")
    };
    $scope.event_samples = {
        color: '#f0ad4e',
        events: Events.prepareCalendarEvent($scope.project.samples, "samples")
    };

    var previous = '';
    $scope.alertOnDayClick = function (date, jsEvent, view, type) {
        if (previous !== '') {
            previous.css('background-color', '');
        }
        $(this).css('background-color', 'lightgrey');
        var d = date._d;
        var clicked_date = Date.UTC(d.getUTCFullYear(), (d.getUTCMonth()), d.getUTCDate());
        var day = d.getUTCDate() + 1;
        var next_date = Date.UTC(d.getUTCFullYear(), (d.getUTCMonth()), day);
        if (!type) {
            var temp = new Date(next_date);
            $scope.alertMessage = ( 'Showing items for ' + temp.toDateString());
        }
        $scope.project = Events.updateDate($scope.project, clicked_date, next_date);
        previous = $(this);
    };

    $scope.alertOnEventClick = function (event, jsEvent, view) {
        var date = event.start;
        $scope.alertMessage = ('Showing ' + event.title + ' created on  ' + date._d.toDateString());
        //Mask other panels
        var what = event.title.split(' ')[1];
        ui.showPanelByCalendarEvent($scope.project.id, what);
        $scope.alertOnDayClick(date, jsEvent, view, 'eventclick');
    };

    $scope.changeView = function (view, calendar) {
        uiCalendarConfig.calendars[calendar].fullCalendar('changeView', view);
    };

    $scope.eventRender = function (event, element) {
        $timeout(function () {
            $(element).attr('tooltip', event.description);
            $compile(element)($scope);
        });
    };

    $scope.closeAlert = function () {
        $scope.alertMessage = '';
    };

    $scope.goHome = function () {
        //When they clear the filter it should reset the panel state
        // and day click should be today's date
        ui.resetPanels($scope.project.id);
        var date = {'_d': new Date()};
        $scope.alertOnDayClick(date, '', '', '');
        $scope.closeAlert();
    };

    $scope.eventSources = [$scope.event_reviews, $scope.event_notes, $scope.event_processes, $scope.event_samples];

    $scope.ready = false;
    $scope.uiConfig = {
        calendar: {
            height: 450,
            editable: true,
            header: {
                left: 'title',
                center: '',
                right: 'today prev,next'
            },
            dayClick: $scope.alertOnDayClick,
            eventClick: $scope.alertOnEventClick,
            eventRender: $scope.eventRender
        }
    };

    $timeout(function () {
        // Make sure the calendar directive has loaded, but running the ng event loop
        // before setting ready to true which then renders in the ng-if.
        $scope.ready = true;
    });
}<commit_msg>Change to IIFE. Move functions out of $scope that don't need to be in $scope. I would have removed $scope all together but $compile isn't working with (this), rather than ($scope).<commit_after>(function (module) {
    module.directive("homeCalendar", homeCalendarDirective);
    function homeCalendarDirective() {
        return {
            restrict: "A",
            controller: 'HomeCalendarController',
            scope: {
                project: '=project'
            },
            templateUrl: 'application/core/projects/project/home/directives/home-calendar.html'
        };
    }

    ///////////////////////////////////////////

    module.controller("HomeCalendarController", HomeCalendarController);

    HomeCalendarController.$inject = ["$scope", "Events", "uiCalendarConfig",
        "$compile", "$timeout", "ui"];

    /* @ngInject */
    function HomeCalendarController($scope, Events, uiCalendarConfig, $compile, $timeout, ui) {
        $scope.project = Events.addConvertedTime($scope.project);

        var eventReviews = {
            color: '#4884b8',
            events: Events.prepareCalendarEvent($scope.project.reviews, "reviews")
        };
        var eventNotes = {
            color: '#3ea7a0',
            events: Events.prepareCalendarEvent($scope.project.notes, "notes")
        };
        var eventProcesses = {
            color: '#e26a6a',
            events: Events.prepareCalendarEvent($scope.project.processes, "processes")
        };
        var eventSamples = {
            color: '#f0ad4e',
            events: Events.prepareCalendarEvent($scope.project.samples, "samples")
        };

        var previous = '';


        $scope.goHome = function () {
            //When they clear the filter it should reset the panel state
            // and day click should be today's date
            ui.resetPanels($scope.project.id);
            var date = {'_d': new Date()};
            alertOnDayClick(date, '', '', '');
            closeAlert();
        };

        $scope.eventSources = [eventReviews, eventNotes, eventProcesses, eventSamples];

        $scope.ready = false;
        $scope.uiConfig = {
            calendar: {
                height: 450,
                editable: true,
                header: {
                    left: 'title',
                    center: '',
                    right: 'today prev,next'
                },
                dayClick: alertOnDayClick,
                eventClick: alertOnEventClick,
                eventRender: eventRender
            }
        };

        $timeout(function () {
            // Make sure the calendar directive has loaded, but running the ng event loop
            // before setting ready to true which then renders in the ng-if.
            $scope.ready = true;
        });

        /////////////////

        function alertOnDayClick(date, jsEvent, view, type) {
            if (previous !== '') {
                previous.css('background-color', '');
            }
            $(this).css('background-color', 'lightgrey');
            var d = date._d;
            var clicked_date = Date.UTC(d.getUTCFullYear(), (d.getUTCMonth()), d.getUTCDate());
            var day = d.getUTCDate() + 1;
            var next_date = Date.UTC(d.getUTCFullYear(), (d.getUTCMonth()), day);
            if (!type) {
                var temp = new Date(next_date);
                $scope.alertMessage = ( 'Showing items for ' + temp.toDateString());
            }
            $scope.project = Events.updateDate($scope.project, clicked_date, next_date);
            previous = $(this);
        }

        function alertOnEventClick(event, jsEvent, view) {
            var date = event.start;
            $scope.alertMessage = ('Showing ' + event.title + ' created on  ' + date._d.toDateString());
            //Mask other panels
            var what = event.title.split(' ')[1];
            ui.showPanelByCalendarEvent($scope.project.id, what);
            alertOnDayClick(date, jsEvent, view, 'eventclick');
        }

        function changeView(view, calendar) {
            uiCalendarConfig.calendars[calendar].fullCalendar('changeView', view);
        }

        function eventRender(event, element) {
            $timeout(function () {
                $(element).attr('tooltip', event.description);
                $compile(element)($scope);
            });
        }

        function closeAlert() {
            $scope.alertMessage = '';
        }
    }
}(angular.module('materialscommons')));
{'fraction_non_alphanumeric': 0.1394327756022309, 'fraction_numerical': 0.004271982912068352, 'mean_word_length': 2.053623188405797, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3231447', 'n_tokens_mistral': 2319, 'n_tokens_neox': 2257, 'n_words': 489}