<commit_before>define(['jquery', 'underscore', 'moment', 'handlebars', 'bloodhound', 'text!templates/loadModal.html', 'typeahead'],
    function ($, _, moment, Handlebars, Bloodhound, loadModal) {
        'use strict';

        var courseCollection = [];
        var load = $(loadModal);

        var engine = new Bloodhound(
            {
                datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
                queryTokenizer: Bloodhound.tokenizers.whitespace,
                remote: {
                    url: '/rest/cnames/%QUERY',
                    filter: function (response) {
                        mapResponse(response);
                        return _.uniq(courseCollection, function (item) {
                            return item.title + item.code;
                        });
                    }
                },
                limit: 10
            }
        );

        var mapResponse = function (response) {
            courseCollection = $.map(response, function (course) {
                return {
                    title: course.courseName,
                    code: course.courseCode,
                    tof: course.timeOfDay,
                    wd: course.weekDay,
                    wn: course.weekNumber,
                    cr: course.classroom,
                    t: course.type
                };
            });
        };

        var searchBox = function (eventCal) {
            var that = this;
            $('#courseSearchBox').typeahead({
                    hint: true,
                    highlight: true,
                    minLength: 2
                },
                {
                    name: 'courses',
                    displayKey: 'name',
                    source: this.engine.ttAdapter(),
                    templates: {
                        empty: [
                            '<p><strong>',
                            'Unable to find any courses that match the current query',
                            '</strong></p>'
                        ].join('\n'),
                        suggestion: Handlebars.compile('<p><strong>{{title}}</strong> - {{code}}</p>')
                    }
                }
            ).on('typeahead:selected', function (evt, item) {
                    courseCollection = courseCollection.filter(function (el) {
                        return el.code === item.code;
                    });
                    if (courseCollection[0].title.length !== 0) {
                        addCourseLink(courseCollection[0].title, courseCollection[0].code);
                    }
                    load.modal('toggle');
                    setTimeout(function () {
                        addDataToCalendar(eventCal);
                    }, 300);
                    addUrlParameter(courseCollection[0].title, courseCollection[0].code);
                });
        };

        var addUrlParameter = function (courseName, courseCode) {
            var params = window.location.search;
            if (params.length > 0) {
                history.pushState(
                    {
                        name: courseName,
                        code: courseCode
                    }, "", "index.html?" + params.substring(1, params.length) + '+' + courseCode);
            } else {
                history.pushState(
                    {
                        name: courseName,
                        code: courseCode
                    }, "", "index.html?" + params + courseCode);
            }
        };

        var refresh = function (calendar) {
            var params = window.location.search;
            var courseCodes = params.substring(1, params.length).split(/[+]/);
            console.log('courseCodes=' + typeof courseCodes);
            load.modal('toggle');
            if (courseCodes.length > 0) {
                courseCodes.forEach(function (cc) {
                    if (typeof cc !== 'undefined') {
                        $.ajax({
                            url: '/rest/code/' + cc,
                            type: 'GET',
                            dataType: 'json',
                            success: function (data) {
                                mapResponse(data);
                                addCourseLink(data[0].courseName, data[0].courseCode);
                                addDataToCalendar(calendar);
                            },
                            error: function (xhr, status, error) {
                                console.log('xhr' + xhr + ', status=' + status + ', error=' + error);
                            }
                        });
                    } else {
                        console.log('Not a valid course code');
                    }
                });
            }
            load.modal('hide');
        };

        var addCourseLink = function (courseName, courseCode) {
            var noppa = 'https://noppa.lut.fi/noppa/opintojakso/';
            courseCode = courseCode.replace('+', '');
            console.log('update courseCode=' + courseCode);
            $('#courseList').append('<li id="+' + courseCode + '+" data-filtertext="' + courseName + '"><a href=' + noppa + courseCode + ' target="_blank">' + courseName + '</a></li>');
        };

        var removeCourseItem = function (courseCode) {
            $('#' + courseCode).remove();
        };

        var addDataToCalendar = function (calendar) {
            courseCollection.forEach(function (course) {
                function processWeekNumbers(weekNumber) {
                    var dateStart = moment().lang('fi').day(course.wd).week(weekNumber).hours(course.tof.split('-')[0] || 6).minutes(0).second(0).format('YYYY-MM-DDTHH:mm:ssZ');
                    var dateEnd = moment().lang('fi').day(course.wd).week(weekNumber).hours(course.tof.split('-')[1] || 6).minutes(0).second(0).format('YYYY-MM-DDTHH:mm:ssZ');
                    calendar.createCalendarEvent(course, dateStart, dateEnd);
                }

                JSON.parse('[' + course.wn + ']').forEach(processWeekNumbers);
            });
            load.modal('hide');<commit_msg>Irrelevant logging removed<commit_after>define(['jquery', 'underscore', 'moment', 'handlebars', 'bloodhound', 'text!templates/loadModal.html', 'typeahead'],
    function ($, _, moment, Handlebars, Bloodhound, loadModal) {
        'use strict';

        var courseCollection = [];
        var load = $(loadModal);

        var engine = new Bloodhound({
            datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
            queryTokenizer: Bloodhound.tokenizers.whitespace,
            remote: {
                url: '/rest/cnames/%QUERY',
                filter: function (response) {
                    mapResponse(response);
                    return _.uniq(courseCollection, function (item) {
                        return item.title + item.code;
                    });
                }
            },
            limit: 10
        });

        var mapResponse = function (response) {
            courseCollection = $.map(response, function (course) {
                return {
                    title: course.courseName,
                    code: course.courseCode,
                    tof: course.timeOfDay,
                    wd: course.weekDay,
                    wn: course.weekNumber,
                    cr: course.classroom,
                    t: course.type
                };
            });
        };

        var searchBox = function (eventCal) {
            var that = this;
            $('#courseSearchBox').typeahead({
                    hint: true,
                    highlight: true,
                    minLength: 2
                },
                {
                    name: 'courses',
                    displayKey: 'name',
                    source: this.engine.ttAdapter(),
                    templates: {
                        empty: [
                            '<p><strong>',
                            'Unable to find any courses that match the current query',
                            '</strong></p>'
                        ].join('\n'),
                        suggestion: Handlebars.compile('<p><strong>{{title}}</strong> - {{code}}</p>')
                    }
                }
            ).on('typeahead:selected', function (evt, item) {
                    courseCollection = courseCollection.filter(function (el) {
                        return el.code === item.code;
                    });
                    if (courseCollection[0].title.length !== 0) {
                        addCourseLink(courseCollection[0].title, courseCollection[0].code);
                    }
                    load.modal('toggle');
                    setTimeout(function () {
                        addDataToCalendar(eventCal);
                    }, 300);
                    addUrlParameter(courseCollection[0].title, courseCollection[0].code);
                });
        };

        var addUrlParameter = function (courseName, courseCode) {
            var params = window.location.search;
            if (params.length > 0) {
                history.pushState(
                    {
                        name: courseName,
                        code: courseCode
                    }, "", "index.html?" + params.substring(1, params.length) + '+' + courseCode);
            } else {
                history.pushState(
                    {
                        name: courseName,
                        code: courseCode
                    }, "", "index.html?" + params + courseCode);
            }
        };

        var refresh = function (calendar) {
            var params = window.location.search;
            var courseCodes = params.substring(1, params.length).split(/[+]/);
            load.modal('toggle');
            if (courseCodes.length > 0) {
                courseCodes.forEach(function (cc) {
                    if (typeof cc !== 'undefined') {
                        $.ajax({
                            url: '/rest/code/' + cc,
                            type: 'GET',
                            dataType: 'json',
                            success: function (data) {
                                mapResponse(data);
                                addCourseLink(data[0].courseName, data[0].courseCode);
                                addDataToCalendar(calendar);
                            },
                            error: function (xhr, status, error) {
                                console.log('xhr' + xhr + ', status=' + status + ', error=' + error);
                            }
                        });
                    } else {
                        console.log('Not a valid course code');
                    }
                });
            }
            load.modal('hide');
        };

        var addCourseLink = function (courseName, courseCode) {
            var noppa = 'https://noppa.lut.fi/noppa/opintojakso/';
            $('#courseList').append('<li id="' + courseCode + '" data-filtertext="' + courseName + '">' +
                    '<a href=' + noppa + courseCode + ' target="_blank">' + courseName + '</a></li>');
        };

        var removeCourseItem = function (courseCode) {
            $('#' + courseCode).remove();

        };

        var addDataToCalendar = function (calendar) {
            courseCollection.forEach(function (course) {
                function processWeekNumbers(weekNumber) {
                    var dateStart = moment().lang('fi').day(course.wd).week(weekNumber).hours(course.tof.split('-')[0] || 6).minutes(0).second(0).format('YYYY-MM-DDTHH:mm:ssZ');
                    var dateEnd = moment().lang('fi').day(course.wd).week(weekNumber).hours(course.tof.split('-')[1] || 6).minutes(0).second(0).format('YYYY-MM-DDTHH:mm:ssZ');
                    calendar.createCalendarEvent(course, dateStart, dateEnd);
                }

                JSON.parse('[' + course.wn + ']').forEach(processWeekNumbers);
            });
            load.modal('hide');
{'fraction_non_alphanumeric': 0.12567354721047833, 'fraction_numerical': 0.004310702147061262, 'mean_word_length': 1.183529411764706, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 31, 'https://': 2, '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': '6431247', 'n_tokens_mistral': 2992, 'n_tokens_neox': 2779, 'n_words': 521}