<commit_before>{% extends 'site/base.twig' %}

{% block content %}
    {% import _self as self %}

    <div class="flashmessage alert alert-success fade" id="registered_success">
        <div class="content">
            {{ translate('You were signed in for the selected registration shift!') }}
        </div>
    </div>
    <div class="flashmessage alert alert-success fade" id="sign_out">
        <div class="content">
            {{ translate('You were signed out from the selected registration shift!') }}
        </div>
    </div>
    <div class="flashmessage alert alert-danger fade" id="error">
        <div class="content">
            {{ translate('An error occurred while processing your request!') }}
        </div>
    </div>

    <div id="modalSignInWarning" class="modal fade">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <a class="close" data-dismiss="modal">&times;</a>
                    <h4>{{ translate('Sign In') }}</h4>
                </div>
                <div class="modal-body">
                    <p>
                        {{ translate('You are about to sign yourself in for a registration shift. Do you want to continue?') }}
                    </p>
                </div>
                <div class="modal-footer">
                    <button class="btn btn-primary confirm">{{ translate('Yes') }}</button>
                    <button class="btn btn-default deny">{{ translate('No') }}</button>
                </div>
            </div>
        </div>
    </div>

    <div class="page-header">
        <h1>{{ translate('Registration Shifts') }}</h1>
    </div>



    <div class="row">
        <div class="col-md-4 shiftSearchForms">
            <h2>{{ translate('Search') }}</h2>

            <div class="well">
                <h4>{{ translate('By Date') }}</h4>

                {% if dateSearchForm is defined %}
                    {% do dateSearchForm.prepare() %}
                    {% autoescape false %}
                        {{ form().openTag(dateSearchForm) }}

                        <div class="form-group">
                            <div class="input-group">
                                {{ formElement(dateSearchForm.get('date')) }}
                                <div class="input-group-btn">
                                    <button class="btn btn-default" type="submit">{{ translate('Search') }}</button>
                                </div>
                            </div>
                        </div>

                        {{ form().closeTag() }}
                    {% endautoescape %}
                {% endif %}
            </div>

            <div class="well">
                <h4>{{ translate('By Event') }}</h4>

                {% if eventSearchForm is defined %}
                    {% do eventSearchForm.prepare() %}
                    {% autoescape false %}
                        {{ form().openTag(eventSearchForm) }}

                        <div class="form-group">
                            <div class="input-group">
                                {{ formElement(eventSearchForm.get('event')) }}
                                <div class="input-group-btn">
                                    <button class="btn btn-default" type="submit">{{ translate('Search') }}</button>
                                </div>
                            </div>
                        </div>

                        {{ form().closeTag() }}
                    {% endautoescape %}
                {% endif %}
            </div>

            <div class="well">
                <h4>{{ translate('By Unit') }}</h4>

                {% if unitSearchForm is defined %}
                    {% do unitSearchForm.prepare() %}
                    {% autoescape false %}
                        {{ form().openTag(unitSearchForm) }}

                        <div class="form-group">
                            <div class="input-group">
                                {{ formElement(unitSearchForm.get('unit')) }}
                                <div class="input-group-btn">
                                    <button class="btn btn-default" type="submit">{{ translate('Search') }}</button>
                                </div>
                            </div>
                        </div>

                        {{ form().closeTag() }}
                    {% endautoescape %}
                {% endif %}
            </div>

        </div>
        <div class="col-md-8">
            <h2>
                {{ translate('My Shifts') }}
            </h2>

            {{ self.displayShifts(entityManager, authenticatedPerson, myShifts, 'myShifts') }}

            <h2>{{ resultString }}</h2>
            {% if searchResults is not null %}
                {{ self.displayShifts(entityManager, authenticatedPerson, searchResults, 'search') }}
            {% else %}
                <div class="alert alert-warning">
                    {{ translate('There are no registration shifts to be shown yet; please use the search functions on the left.') }}
                </div>
            {% endif %}
        </div>
    </div>
{% endblock %}

{% block content_script %}
    {% import _self as self %}

    <script type="text/javascript">
        $(document).ready(function () {
            $('.registered').click(function () {
                console.log('Clicked');
                var button = $(this);
                var count = parseInt($(this).data('count'));

                if (!button.hasClass('disabled')) {
                    var id = '#modalSignInWarning';
                    $(id).modal();
                    $(id +' .confirm').one('click', function (){
                        $(id).modal('hide');
                        registeredSignIn(button, count);
                    });
                }

                button.parent().find('button').each(function(i) {
                    $(this).addClass('disabled');
                });

                $(id +' .deny').one('click', function () {
                    $(id).modal('hide');

                    button.parent().find('button').each(function(i) {
                        $(this).removeClass('disabled');
                    });
                });
            });

            $('.signOut').click(function () {
                var button = $(this);
                button.addClass('disabled');

                $.post(
                    '{{ url('registration_shift', {"action": "signOut"}) }}',
                    {"id": $(this).data('id')},
                    function (data) {
                        if (data && 'success' === data.status) {
                            $('.flashmessage').removeClass('in');
                            $('#sign_out').addClass('in');

                            var panel = $(button.data('panel')).clone();
                            panel.find('.buttons').html('').css('display', 'none');

                            $('#shifts-search .alert').remove();
                            $('#shifts-search').prepend(panel);
                            panel.fadeIn();
                            $('#shifts-myShifts ' + button.data('panel')).fadeOut(function () {$(this).remove()});
                        } else {
                            errorSave();
                        }
                    },
                    'json'
                ).error(errorSave);
            });
        });

        function updateButton(button, ratio, count) {
            button.removeClass('btn-success btn-warning btn-danger');

            if (ratio < 0.5) {
                button.addClass('btn-success');
            } else if (ratio < 0.75) {
                button.addClass('btn-warning');
            } else if (ratio == 1) {
                button.addClass('btn-danger');
            }

            button.find('.count').text(ratio == 1 ? button.data('max') : ++count);
        }

        function errorSave() {
            $('.flashmessage').removeClass('in');
            $('#error').addClass('in');
        }

        function registeredSignIn(button, count) {
            $.post(
                '{{ url('registration_shift', {"action": "registered"}) }}',
                {"id": button.data('id')},
                function (data) {
                    if (data && 'success' == data.status) {
                        $('.flashmessage').removeClass('in');
                        $('#registered_success').addClass('in');

                        updateButton(button, parseInt(data.ratio, 10), count);
                        var panel = $(button.data('panel')).clone();
                        panel.find('.buttons').html('').css('display', 'none');

                        $('#shifts-myShifts .alert').remove();
                        $('#shifts-myShifts').prepend(panel);
                        panel.fadeIn();
                        $('#shifts-search ' + button.data('panel')).fadeOut(function () {$(this).remove()});
                    } else {
                        errorSave();
                    }
                },
                'json'
            ).error(errorSave);
        }

    </script>
{% endblock %}

{#TODO: IDK what this is#}
{% macro displayShifts(entityManager, authenticatedPerson, shifts, accordionName) %}
    {% import _self as self %}
    {% set previousShift = null %}
    <div class="panel-group" id="shifts-{{ accordionName }}">
        {% for shift in shifts %}
            {% if previousShift.getStartDate().format('Ymd') < shift.getStartDate().format('Ymd') %}
                <h3>{{translate('Shifts on')}} {{ translate(shift.getStartDate().format('l')) }}  {{ dateLocalized(shift.getStartDate(), 'd/M/y') }}</h3>
            {% endif %}

            {% set previousShift = shift %}

            <div class="panel panel-default" id="group_{{ accordionName }}_shift-{{ shift.getId() }}">
                <div class="panel-heading">
                    <span class="buttons pull-right hidden-xs hidden-sm">
                        {{ self.buttons(entityManager, authenticatedPerson, shift, accordionName) }}
                    </span>
                    <a class="panel-toggle" data-toggle="collapse" data-parent="#shifts-{{ accordionName }}" href="#collapse_{{ accordionName }}_shift-{{ shift.getId() }}" style="overflow: hidden;">
                        {{ dateLocalized(shift.getStartDate(), 'd/M/y HH:mm') }}-{{ dateLocalized(shift.getEndDate(), 'HH:mm') }}&mdash;{{ shift.getName() }}
                    </a>
                </div>
                <div id="collapse_{{ accordionName }}_shift-{{ shift.getId() }}" class="panel-collapse collapse">
                    <div class="panel-body">
                        <div class="buttons hidden-md hidden-lg" style="text-align: right">
                            {{ self.buttons(entityManager, authenticatedPerson, shift, accordionName) }}
                        </div>
                        <div class="row">
                            <div class="col-sm-4">
                                <dl>
                                    <dt>{{ translate('Name') }}</dt>
                                    <dd>{{ shift.getName() }}</dd>
                                    <dt>{{ translate('Start') }}</dt>
                                    <dd>{{ dateLocalized(shift.getStartDate(), 'd/M/y HH:mm') }}</dd>
                                    <dt>{{ translate('End') }}</dt>
                                    <dd>{{ dateLocalized(shift.getEndDate(), 'd/M/y HH:mm') }}</dd>
                                </dl>
                            </div>
                            <div class="col-sm-4">
                                <dl>

                                    {% if shift.getEvent() is not null %}
                                        <dt>{{ translate('Event') }}</dt>
                                        <dd>{{ shift.getEvent().getTitle(language) }}</dd>
                                    {% endif %}

                                    <dt>{{ translate('Unit') }}</dt>
                                    <dd>{{ shift.getUnit().getName() }}</dd>
                                </dl>
                            </div>
                        </div>
                        <dl>
                            <dt>{{ translate('Description') }}</dt>
                            <dd style="text-align: justify;">{{ shift.getDescription() }}</dd>

                            <dt>{{ translate('Location') }}</dt>
                            <dd>
                                {{ shift.getLocation().getName() }}
                            </dd>
                            <dd style="margin-top: 5px;">
                                <img class="img-rounded" src="{{ staticMap(shift.getLocation(), '367x125', '7a43b6') }}" />
                            </dd>
                        </dl>
                    </div>
                </div>
            </div>
        {% else %}
            <div class="alert alert-warning">
                {% if 'search' == accordionName %}
                    {{ translate('No registration shifts were found that match the given query.') }}
                {% else %}
                    {{ translate('You have not yet signed up for any registration shifts. You can use the search functions on the left to look for some!') }}
                {% endif %}
            </div>
        {% endfor %}
    </div>
{% endmacro %}

{% macro buttonStyle(shift, type) %}

    {% set ratio = shift.countRegistered() / shift.getNbRegistered() %}
<commit_msg>Removed map in registration shift<commit_after>{% extends 'site/base.twig' %}

{% block content %}
    {% import _self as self %}

    <div class="flashmessage alert alert-success fade" id="registered_success">
        <div class="content">
            {{ translate('You were signed in for the selected registration shift!') }}
        </div>
    </div>
    <div class="flashmessage alert alert-success fade" id="sign_out">
        <div class="content">
            {{ translate('You were signed out from the selected registration shift!') }}
        </div>
    </div>
    <div class="flashmessage alert alert-danger fade" id="error">
        <div class="content">
            {{ translate('An error occurred while processing your request!') }}
        </div>
    </div>

    <div id="modalSignInWarning" class="modal fade">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <a class="close" data-dismiss="modal">&times;</a>
                    <h4>{{ translate('Sign In') }}</h4>
                </div>
                <div class="modal-body">
                    <p>
                        {{ translate('You are about to sign yourself in for a registration shift. Do you want to continue?') }}
                    </p>
                </div>
                <div class="modal-footer">
                    <button class="btn btn-primary confirm">{{ translate('Yes') }}</button>
                    <button class="btn btn-default deny">{{ translate('No') }}</button>
                </div>
            </div>
        </div>
    </div>

    <div class="page-header">
        <h1>{{ translate('Registration Shifts') }}</h1>
    </div>



    <div class="row">
        <div class="col-md-4 shiftSearchForms">
            <h2>{{ translate('Search') }}</h2>

            <div class="well">
                <h4>{{ translate('By Date') }}</h4>

                {% if dateSearchForm is defined %}
                    {% do dateSearchForm.prepare() %}
                    {% autoescape false %}
                        {{ form().openTag(dateSearchForm) }}

                        <div class="form-group">
                            <div class="input-group">
                                {{ formElement(dateSearchForm.get('date')) }}
                                <div class="input-group-btn">
                                    <button class="btn btn-default" type="submit">{{ translate('Search') }}</button>
                                </div>
                            </div>
                        </div>

                        {{ form().closeTag() }}
                    {% endautoescape %}
                {% endif %}
            </div>

            <div class="well">
                <h4>{{ translate('By Event') }}</h4>

                {% if eventSearchForm is defined %}
                    {% do eventSearchForm.prepare() %}
                    {% autoescape false %}
                        {{ form().openTag(eventSearchForm) }}

                        <div class="form-group">
                            <div class="input-group">
                                {{ formElement(eventSearchForm.get('event')) }}
                                <div class="input-group-btn">
                                    <button class="btn btn-default" type="submit">{{ translate('Search') }}</button>
                                </div>
                            </div>
                        </div>

                        {{ form().closeTag() }}
                    {% endautoescape %}
                {% endif %}
            </div>

            <div class="well">
                <h4>{{ translate('By Unit') }}</h4>

                {% if unitSearchForm is defined %}
                    {% do unitSearchForm.prepare() %}
                    {% autoescape false %}
                        {{ form().openTag(unitSearchForm) }}

                        <div class="form-group">
                            <div class="input-group">
                                {{ formElement(unitSearchForm.get('unit')) }}
                                <div class="input-group-btn">
                                    <button class="btn btn-default" type="submit">{{ translate('Search') }}</button>
                                </div>
                            </div>
                        </div>

                        {{ form().closeTag() }}
                    {% endautoescape %}
                {% endif %}
            </div>

        </div>
        <div class="col-md-8">
            <h2>
                {{ translate('My Shifts') }}
            </h2>

            {{ self.displayShifts(entityManager, authenticatedPerson, myShifts, 'myShifts') }}

            <h2>{{ resultString }}</h2>
            {% if searchResults is not null %}
                {{ self.displayShifts(entityManager, authenticatedPerson, searchResults, 'search') }}
            {% else %}
                <div class="alert alert-warning">
                    {{ translate('There are no registration shifts to be shown yet; please use the search functions on the left.') }}
                </div>
            {% endif %}
        </div>
    </div>
{% endblock %}

{% block content_script %}
    {% import _self as self %}

    <script type="text/javascript">
        $(document).ready(function () {
            $('.registered').click(function () {
                console.log('Clicked');
                var button = $(this);
                var count = parseInt($(this).data('count'));

                if (!button.hasClass('disabled')) {
                    var id = '#modalSignInWarning';
                    $(id).modal();
                    $(id +' .confirm').one('click', function (){
                        $(id).modal('hide');
                        registeredSignIn(button, count);
                    });
                }

                button.parent().find('button').each(function(i) {
                    $(this).addClass('disabled');
                });

                $(id +' .deny').one('click', function () {
                    $(id).modal('hide');

                    button.parent().find('button').each(function(i) {
                        $(this).removeClass('disabled');
                    });
                });
            });

            $('.signOut').click(function () {
                var button = $(this);
                button.addClass('disabled');

                $.post(
                    '{{ url('registration_shift', {"action": "signOut"}) }}',
                    {"id": $(this).data('id')},
                    function (data) {
                        if (data && 'success' === data.status) {
                            $('.flashmessage').removeClass('in');
                            $('#sign_out').addClass('in');

                            var panel = $(button.data('panel')).clone();
                            panel.find('.buttons').html('').css('display', 'none');

                            $('#shifts-search .alert').remove();
                            $('#shifts-search').prepend(panel);
                            panel.fadeIn();
                            $('#shifts-myShifts ' + button.data('panel')).fadeOut(function () {$(this).remove()});
                        } else {
                            errorSave();
                        }
                    },
                    'json'
                ).error(errorSave);
            });
        });

        function updateButton(button, ratio, count) {
            button.removeClass('btn-success btn-warning btn-danger');

            if (ratio < 0.5) {
                button.addClass('btn-success');
            } else if (ratio < 0.75) {
                button.addClass('btn-warning');
            } else if (ratio == 1) {
                button.addClass('btn-danger');
            }

            button.find('.count').text(ratio == 1 ? button.data('max') : ++count);
        }

        function errorSave() {
            $('.flashmessage').removeClass('in');
            $('#error').addClass('in');
        }

        function registeredSignIn(button, count) {
            $.post(
                '{{ url('registration_shift', {"action": "registered"}) }}',
                {"id": button.data('id')},
                function (data) {
                    if (data && 'success' == data.status) {
                        $('.flashmessage').removeClass('in');
                        $('#registered_success').addClass('in');

                        updateButton(button, parseInt(data.ratio, 10), count);
                        var panel = $(button.data('panel')).clone();
                        panel.find('.buttons').html('').css('display', 'none');

                        $('#shifts-myShifts .alert').remove();
                        $('#shifts-myShifts').prepend(panel);
                        panel.fadeIn();
                        $('#shifts-search ' + button.data('panel')).fadeOut(function () {$(this).remove()});
                    } else {
                        errorSave();
                    }
                },
                'json'
            ).error(errorSave);
        }

    </script>
{% endblock %}

{#TODO: IDK what this is#}
{% macro displayShifts(entityManager, authenticatedPerson, shifts, accordionName) %}
    {% import _self as self %}
    {% set previousShift = null %}
    <div class="panel-group" id="shifts-{{ accordionName }}">
        {% for shift in shifts %}
            {% if previousShift.getStartDate().format('Ymd') < shift.getStartDate().format('Ymd') %}
                <h3>{{translate('Shifts on')}} {{ translate(shift.getStartDate().format('l')) }}  {{ dateLocalized(shift.getStartDate(), 'd/M/y') }}</h3>
            {% endif %}

            {% set previousShift = shift %}

            <div class="panel panel-default" id="group_{{ accordionName }}_shift-{{ shift.getId() }}">
                <div class="panel-heading">
                    <span class="buttons pull-right hidden-xs hidden-sm">
                        {{ self.buttons(entityManager, authenticatedPerson, shift, accordionName) }}
                    </span>
                    <a class="panel-toggle" data-toggle="collapse" data-parent="#shifts-{{ accordionName }}" href="#collapse_{{ accordionName }}_shift-{{ shift.getId() }}" style="overflow: hidden;">
                        {{ dateLocalized(shift.getStartDate(), 'd/M/y HH:mm') }}-{{ dateLocalized(shift.getEndDate(), 'HH:mm') }}&mdash;{{ shift.getName() }}
                    </a>
                </div>
                <div id="collapse_{{ accordionName }}_shift-{{ shift.getId() }}" class="panel-collapse collapse">
                    <div class="panel-body">
                        <div class="buttons hidden-md hidden-lg" style="text-align: right">
                            {{ self.buttons(entityManager, authenticatedPerson, shift, accordionName) }}
                        </div>
                        <div class="row">
                            <div class="col-sm-4">
                                <dl>
                                    <dt>{{ translate('Name') }}</dt>
                                    <dd>{{ shift.getName() }}</dd>
                                    <dt>{{ translate('Start') }}</dt>
                                    <dd>{{ dateLocalized(shift.getStartDate(), 'd/M/y HH:mm') }}</dd>
                                    <dt>{{ translate('End') }}</dt>
                                    <dd>{{ dateLocalized(shift.getEndDate(), 'd/M/y HH:mm') }}</dd>
                                </dl>
                            </div>
                            <div class="col-sm-4">
                                <dl>

                                    {% if shift.getEvent() is not null %}
                                        <dt>{{ translate('Event') }}</dt>
                                        <dd>{{ shift.getEvent().getTitle(language) }}</dd>
                                    {% endif %}

                                    <dt>{{ translate('Unit') }}</dt>
                                    <dd>{{ shift.getUnit().getName() }}</dd>
                                </dl>
                            </div>
                        </div>
                        <dl>
                            <dt>{{ translate('Description') }}</dt>
                            <dd style="text-align: justify;">{{ shift.getDescription() }}</dd>

                            <dt>{{ translate('Location') }}</dt>
                            <dd>
                                {{ shift.getLocation().getName() }}
                            </dd>
                        </dl>
                    </div>
                </div>
            </div>
        {% else %}
            <div class="alert alert-warning">
                {% if 'search' == accordionName %}
                    {{ translate('No registration shifts were found that match the given query.') }}
                {% else %}
                    {{ translate('You have not yet signed up for any registration shifts. You can use the search functions on the left to look for some!') }}
                {% endif %}
            </div>
        {% endfor %}
    </div>
{% endmacro %}

{% macro buttonStyle(shift, type) %}

    {% set ratio = shift.countRegistered() / shift.getNbRegistered() %}

{'fraction_non_alphanumeric': 0.1553398058252427, 'fraction_numerical': 0.002705106351441488, 'mean_word_length': 1.1901477032949197, 'pattern_counts': {'":': 8, '<': 312, '<?xml version=': 0, '>': 306, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 38, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2405760', 'n_tokens_mistral': 6879, 'n_tokens_neox': 6225, 'n_words': 1318}