<commit_before>{% extends 'base.html' %}
{% load staticfiles %}
{% block scripts %}
    <script type="application/javascript">
        var ViewModel = function() {
            var self = this;

            self.submitting = ko.observable(false);
            self.submitSuccess = ko.observable(false);
            self.coursesLoading = ko.observable(true);
            self.courses = ko.observableArray();
            self.enrollments = ko.observableArray();
            self.filteredCourses = ko.computed(function() {
                return self.courses().filter(function(course) {
                    var result = true
                    self.enrollments().forEach(function(enrollment) {
                        if (enrollment.course.id === course.course.id) {
                            result = false;
                        }
                    });
                    return result;
                });
            }, self);

            self.distinctTimeSlots = ko.dependentObservable(function() {
              var types = ko.utils.arrayMap(self.filteredCourses(), function(item){ return item.time})
              return ko.utils.arrayGetDistinctValues(types).sort();
            });

            self.add = function(data, model) {
                if(model['timeblock_' + data.timeblock.id]() != null) {
                    model.enrollments.remove(model['timeblock_' + data.timeblock.id]());
                }
                model.enrollments.push(data);
                model['timeblock_' + data.timeblock.id](data);
            };
            self.remove = function(data, model) {
                model.enrollments.remove(data);
                model['timeblock_' + data.timeblock.id](null);
            };
            self.submit = function() {
                self.submitting(true);
                $.ajax({
                    type: 'POST',
                    contentType: 'application/json',
                    url: '/api/enrollments',
                    data: JSON.stringify(self.enrollments()).toString(),
                    success: function (response) {
                        self.submitting(false);
                        self.submitSuccess(true);
                    }
                }).fail(function() { self.submitting(false)});
            }
        {% for timeblock in timeblocks %}; self.timeblock_{{ timeblock.pk }} = ko.observable(){%  endfor %}
        };
        var vm = new ViewModel();
        $.getJSON('/api/courses', function(data) {
            data.courses.forEach(function(course) {
                var start = moment(course.timeblock.start_time).format('hh:mm A');
                var end = moment(course.timeblock.end_time).format('hh:mm A');
                course.time = start + ' - ' + end;
                vm.courses.push(course);
            });
            vm.coursesLoading(false);
        });
        $.getJSON('/api/enrollments', function(data) {
            data.enrollments.forEach(function(enrollment) {
                var start = moment(enrollment.timeblock.start_time).format('hh:mm A');
                var end = moment(enrollment.timeblock.end_time).format('hh:mm A');
                enrollment.time = start + ' - ' + end;
                vm['timeblock_' + enrollment.timeblock.id](enrollment);
                vm.enrollments.push(enrollment);
            })
        });
        ko.applyBindings(vm);
    </script>
{% endblock %}
{% block content %}
    <div data-bind="text: name"></div>
    <div class="row schedule">
        <div class="col-md-7">
            <table class="table table-striped">
                <thead>
                  <tr>
                    <th>Time</th>
                    <th>Class Name</th>
                  </tr>
                </thead>
                <tbody>
                    {% for timeblock in timeblocks %}
                    <tr style="height: 97px">
                        <td class="col-md-2">{{ timeblock.start_time|date:"h:i A" }} - {{ timeblock.end_time|date:"h:i A" }}</td>
                        <td class="col-md-5" data-bind="with: timeblock_{{ timeblock.pk }}, dropZone: {accepts: 'enrollment_{{ timeblock.pk }}', drop: add }">
                            <div class="row" data-bind="dragZone: { name: 'enrollment' }">
                                <div class="course-icon">
                                    <img data-bind="attr: {'src': '/static/images/badges/' + course.image_name}" class="mb-course"/>
                                </div>
                                <div class="course-desc">
                                    <div data-bind="text: course.name"></div>
                                    <div data-bind="text: time"></div>
                                    <div data-bind="text: location"></div>
                                </div>
                            </div>
                        </td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>

        <h4>Filter by time slot(s)</h4>
        <div data-bind="foreach: distinctTimeSlots">
            <div class="checkbox">
                <label>
                  <input type="checkbox"><span data-bind="text: $data"/>
                </label>
            </div>
        </div>

        <div class="col-md-5 class-list" data-bind="css: {loading: coursesLoading()}">
            <div data-bind="foreach:filteredCourses, dropZone: {accepts: 'enrollment', drop: remove}">
                <div class="row" data-bind="dragZone: {name: 'enrollment_' + timeblock.id}">
                    <div class="course-icon">
                        <img data-bind="attr: {'src': '/static/images/badges/' + course.image_name}" class="mb-course"/>
                    </div>
                    <div class="course-desc">
                        <div data-bind="text: course.name"></div>
                        <div data-bind="text: time"></div>
                        <div data-bind="text: location"></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-md-12">
            <button class="btn btn-primary" data-bind="click: submit">Submit</button>
            <span data-bind="if: submitting">
                <img src="{% static 'images/ajax-loader.gif' %}" />
            </span>
            <span data-bind="if: submitSuccess">
                <i class="fa fa-check fa-lg"></i>
            </span>
        </div>
    </div>
{% endblock %}
<commit_msg>Added search bar on add/edit classes to search for merit classes<commit_after>{% extends 'base.html' %}
{% load staticfiles %}
{% block scripts %}
    <script type="application/javascript">
        var ViewModel = function() {
            var self = this;

            self.submitting = ko.observable(false);
            self.submitSuccess = ko.observable(false);
            self.coursesLoading = ko.observable(true);
            self.courses = ko.observableArray();
            self.enrollments = ko.observableArray();
            self.filteredCourses = ko.computed(function() {
                return self.courses().filter(function(course) {
                    var result = true
                    self.enrollments().forEach(function(enrollment) {
                        if (enrollment.course.id === course.course.id) {
                            result = false;
                        }
                    });
                    return course.course.name.toLowerCase().indexOf(self.searchQuery().toLowerCase()) !== -1;
                });
            }, self);
            self.searchQuery = ko.observable('');

            self.distinctTimeSlots = ko.dependentObservable(function() {
              var types = ko.utils.arrayMap(self.filteredCourses(), function(item){ return item.time})
              return ko.utils.arrayGetDistinctValues(types).sort();
            });

            self.add = function(data, model) {
                if(model['timeblock_' + data.timeblock.id]() != null) {
                    model.enrollments.remove(model['timeblock_' + data.timeblock.id]());
                }
                model.enrollments.push(data);
                model['timeblock_' + data.timeblock.id](data);
            };
            self.remove = function(data, model) {
                model.enrollments.remove(data);
                model['timeblock_' + data.timeblock.id](null);
            };
            self.submit = function() {
                self.submitting(true);
                $.ajax({
                    type: 'POST',
                    contentType: 'application/json',
                    url: '/api/enrollments',
                    data: JSON.stringify(self.enrollments()).toString(),
                    success: function (response) {
                        self.submitting(false);
                        self.submitSuccess(true);
                    }
                }).fail(function() { self.submitting(false)});
            }
        {% for timeblock in timeblocks %}; self.timeblock_{{ timeblock.pk }} = ko.observable(){%  endfor %}
        };
        var vm = new ViewModel();
        $.getJSON('/api/courses', function(data) {
            data.courses.forEach(function(course) {
                var start = moment(course.timeblock.start_time).format('hh:mm A');
                var end = moment(course.timeblock.end_time).format('hh:mm A');
                course.time = start + ' - ' + end;
                vm.courses.push(course);
            });
            vm.coursesLoading(false);
        });
        $.getJSON('/api/enrollments', function(data) {
            data.enrollments.forEach(function(enrollment) {
                var start = moment(enrollment.timeblock.start_time).format('hh:mm A');
                var end = moment(enrollment.timeblock.end_time).format('hh:mm A');
                enrollment.time = start + ' - ' + end;
                vm['timeblock_' + enrollment.timeblock.id](enrollment);
                vm.enrollments.push(enrollment);
            })
        });
        ko.applyBindings(vm);
    </script>
{% endblock %}
{% block content %}
    <div data-bind="text: name"></div>
    <div class="row schedule">
        <div class="col-md-7">
            <table class="table table-striped">
                <thead>
                  <tr>
                    <th>Time</th>
                    <th>Class Name</th>
                  </tr>
                </thead>
                <tbody>
                    {% for timeblock in timeblocks %}
                    <tr style="height: 97px">
                        <td class="col-md-2">{{ timeblock.start_time|date:"h:i A" }} - {{ timeblock.end_time|date:"h:i A" }}</td>
                        <td class="col-md-5" data-bind="with: timeblock_{{ timeblock.pk }}, dropZone: {accepts: 'enrollment_{{ timeblock.pk }}', drop: add }">
                            <div class="row" data-bind="dragZone: { name: 'enrollment' }">
                                <div class="course-icon">
                                    <img data-bind="attr: {'src': '/static/images/badges/' + course.image_name}" class="mb-course"/>
                                </div>
                                <div class="course-desc">
                                    <div data-bind="text: course.name"></div>
                                    <div data-bind="text: time"></div>
                                    <div data-bind="text: location"></div>
                                </div>
                            </div>
                        </td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>

        <div class="form-group">
            <input placeholder="Search..." type="text" data-bind="value: searchQuery, valueUpdate: 'keyup'">
        </div>

        <h4>Filter by time slot(s)</h4>
        <div data-bind="foreach: distinctTimeSlots">
            <div class="checkbox">
                <label>
                  <input type="checkbox"><span data-bind="text: $data"/>
                </label>
            </div>
        </div>

        <div class="col-md-5 class-list" data-bind="css: {loading: coursesLoading()}">
            <div data-bind="foreach:filteredCourses, dropZone: {accepts: 'enrollment', drop: remove}">
                <div class="row" data-bind="dragZone: {name: 'enrollment_' + timeblock.id}">
                    <div class="course-icon">
                        <img data-bind="attr: {'src': '/static/images/badges/' + course.image_name}" class="mb-course"/>
                    </div>
                    <div class="course-desc">
                        <div data-bind="text: course.name"></div>
                        <div data-bind="text: time"></div>
                        <div data-bind="text: location"></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-md-12">
            <button class="btn btn-primary" data-bind="click: submit">Submit</button>
            <span data-bind="if: submitting">
                <img src="{% static 'images/ajax-loader.gif' %}" />
            </span>
            <span data-bind="if: submitSuccess">
                <i class="fa fa-check fa-lg"></i>
            </span>
        </div>
    </div>
{% endblock %}

{'fraction_non_alphanumeric': 0.14614809274495139, 'fraction_numerical': 0.0015706806282722514, 'mean_word_length': 1.3787582280732966, 'pattern_counts': {'":': 0, '<': 164, '<?xml version=': 0, '>': 164, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1866203', 'n_tokens_mistral': 3667, 'n_tokens_neox': 3467, 'n_words': 629}