<commit_before>{% extends 'base.html' %}
{% load staticfiles %}

{% block head %}
    <link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.css"/>
    <script src="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.js"></script>
    <script src="{% static 'utils/leaflet.markercluster-src.js' %}"></script>
    <link rel="stylesheet" href="{% static 'utils/MarkerCluster.css' %}" />
    <link rel="stylesheet" href="{% static 'utils/MarkerCluster.Default.css' %}" />
    <script type="text/javascript" src="{% static 'utils/proj4-compressed.js' %}"></script>
    <script type="text/javascript" src="{% static 'utils/proj4leaflet.js' %}"></script>
    <link rel="stylesheet" href="{% static 'utils/easy-button.css' %}"/>
    <script type="text/javascript" src="{% static 'utils/easy-button.js' %}"></script>

{% endblock %}

{% block content %}

    {% include 'feedback_form/stagebar.html' with stage=wizard.steps.step1 %}
    <form method="post" id="location">
        {% csrf_token %}
        {{ wizard.management_form }}

        {{ form.latitude }}
        {{ form.longitude }}
        {{ form.service_object_id }}

        <div class="form-group">
            <div class="row">
                <div class="col-md-12">
                    <div id="map" class="map-form"></div>
                </div>
            </div>
        </div>

        <div class="form-group">
            <div class="row">
                <div class="col-sm-3">
                    <label for="service_selector" class="hidden-xs">Liittyy kohteeseen:</label>
                </div>
                <div class="col-sm-9">
                    <select name="service_object_id" class="form-control" id="service_object_select"></select>
                </div>
            </div>
        </div>

        <div class="form-group">
            <div class="row">
                <div class="col-sm-offset-10 col-sm-2">
                    <button type="submit" id="service_selector" class="btn btn-primary pull-right">Seuraava <span class="glyphicon glyphicon-triangle-right"></span></button>
                </div>
            </div>
        </div>
    </form>

    <script src="{% static 'utils/Leaflet.MakiMarkers.js' %}"></script>
    <script src="{% static 'map.js' %}"></script>
    <script>
        $("body").css("margin", 0);
        map.setZoom(13);
        var newFeedbackLocation = new L.marker(map.getCenter(), {icon: new_feedback_icon, zIndexOffset: 1}).addTo(map);
        storeLocation(newFeedbackLocation.getLatLng());

        // Provide initial list - if the user doesn't allow geolocating
        fetch_service_objects(newFeedbackLocation.getLatLng());

        map.on('move', function (e) {
            newFeedbackLocation.setLatLng(map.getCenter());
            storeLocation(newFeedbackLocation.getLatLng());
        });

        var keep_selected = null;   // Variable to hold service_object_id to keep selected in the list
        map.on("moveend", function (event) {
            fetch_service_objects(newFeedbackLocation.getLatLng());
        });

        $("#location").submit(function (event){
            // Assign the selected service_object_id to form
            var service_object_id = $("#service_object_select").val();
            $("#{{form.service_object_id.id_for_label}}").val(service_object_id);
        });

        $("#service_object_select").change(function () {
            var id = $(this).val();            
            $.each(service_object_results, function(index, value) {
                if(value.id == id) {
                    map.panTo([value.location.coordinates[1], value.location.coordinates[0]]);
                    keep_selected = id;
                    return false; // break
                }
            });
        });

        // Populate the list by nearby service objects. Only shows max 20 (the 1st page)
        var service_object_results;
        function fetch_service_objects(location) {
            var data = {
                "only": "name,location",
                "lat": location.lat,
                "lon": location.lng,
                "distance": 300
            };
            var url = "http://api.hel.fi/servicemap/v1/unit/";
            $.get(url, data, function (data) {
                service_object_results = data.results;
                $("#service_object_select").empty();
                $("#service_object_select").append("<option value=''>Voit valita listalta...</option>");
                $.each(data.results, function (index, value) {
                    var option = $("<option>", {value: value.id});
                    $(option).text(value.name.fi);
                    $("#service_object_select").append(option);
                });
                $("#service_object_select").val(keep_selected);
                keep_selected = null;
            });
        }

        function storeLocation(latlng) {
            $("#{{ form.latitude.id_for_label }}").val(latlng.lat);
            $("#{{ form.longitude.id_for_label }}").val(latlng.lng);
        }
    </script>

    <script type="text/javascript">
        $(function () {
            enable_voting("{{csrf_token}}", "{% url 'vote_feedback' %}");
        });
    </script>

    <script type="text/javascript" src="{% static 'utils/enable_voting.js' %}"></script>
{% endblock %}<commit_msg>Refactored map code in closest<commit_after>{% extends 'base.html' %}
{% load staticfiles %}

{% block head %}
    <link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.css"/>
    <script src="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.js"></script>
    <script src="{% static 'utils/leaflet.markercluster-src.js' %}"></script>
    <link rel="stylesheet" href="{% static 'utils/MarkerCluster.css' %}" />
    <link rel="stylesheet" href="{% static 'utils/MarkerCluster.Default.css' %}" />
    <script type="text/javascript" src="{% static 'utils/proj4-compressed.js' %}"></script>
    <script type="text/javascript" src="{% static 'utils/proj4leaflet.js' %}"></script>
    <link rel="stylesheet" href="{% static 'utils/easy-button.css' %}"/>
    <script type="text/javascript" src="{% static 'utils/easy-button.js' %}"></script>

{% endblock %}

{% block content %}

    {% include 'feedback_form/stagebar.html' with stage=wizard.steps.step1 %}
    <form method="post" id="location">
        {% csrf_token %}
        {{ wizard.management_form }}

        {{ form.latitude }}
        {{ form.longitude }}
        {{ form.service_object_id }}

        <div class="form-group">
            <div class="row">
                <div class="col-md-12">
                    <div id="map" class="map-form"></div>
                </div>
            </div>
        </div>

        <div class="form-group">
            <div class="row">
                <div class="col-sm-3">
                    <label for="service_selector" class="hidden-xs">Liittyy kohteeseen:</label>
                </div>
                <div class="col-sm-9">
                    <select name="service_object_id" class="form-control" id="service_object_select"></select>
                </div>
            </div>
        </div>

        <div class="form-group">
            <div class="row">
                <div class="col-sm-offset-10 col-sm-2">
                    <button type="submit" id="service_selector" class="btn btn-primary pull-right">Seuraava <span class="glyphicon glyphicon-triangle-right"></span></button>
                </div>
            </div>
        </div>
    </form>

    <script src="{% static 'utils/Leaflet.MakiMarkers.js' %}"></script>
    <script src="{% static 'map.js' %}"></script>
    <script>
        var service_object_results;
        var keep_selected = null;   // Variable to hold service_object_id to keep selected in the list

        $("body").css("margin", 0);
        map.setZoom(13);
        var newFeedbackLocation = new L.marker(map.getCenter(), {icon: new_feedback_icon, zIndexOffset: 1}).addTo(map);

        // Provide initial list - if the user doesn't allow geolocating
        fetch_service_objects(newFeedbackLocation.getLatLng());

        // Update marker when the map is being moved
        map.on('move', function (e) {
            newFeedbackLocation.setLatLng(map.getCenter());
        });

        // Fetch new service objects when the map movement stops 
        map.on("moveend", function (event) {
            fetch_service_objects(newFeedbackLocation.getLatLng());
        });

        $("#location").submit(function (event){
            // Assign the selected service_object_id to form
            var service_object_id = $("#service_object_select").val();
            $("#{{form.service_object_id.id_for_label}}").val(service_object_id);

            // Assign selected location to form 
            var latlng = newFeedbackLocation.getLatLng();
            $("#{{ form.latitude.id_for_label }}").val(latlng.lat);
            $("#{{ form.longitude.id_for_label }}").val(latlng.lng);
        });

        $("#service_object_select").change(function () {
            var id = $(this).val();            
            $.each(service_object_results, function(index, value) {
                if(value.id == id) {
                    map.panTo([value.location.coordinates[1], value.location.coordinates[0]]);
                    keep_selected = id;
                    return false; // break from $.each
                }
            });
        });

        // Populate the list by nearby service objects. Only shows max 20 (the 1st page)
        function fetch_service_objects(location) {
            var data = {
                "only": "name,location",    // Fetch service object names and coordinates
                "lat": location.lat,
                "lon": location.lng,
                "distance": 300
            };
            var url = "http://api.hel.fi/servicemap/v1/unit/";
            $.get(url, data, function (data) {
                service_object_results = data.results;
                $("#service_object_select").empty();
                $("#service_object_select").append("<option value=''>Voit valita listalta...</option>");
                $.each(data.results, function (index, value) {
                    var option = $("<option>", {value: value.id});
                    $(option).text(value.name.fi);
                    $("#service_object_select").append(option);
                });
                $("#service_object_select").val(keep_selected);
                keep_selected = null;
            });
        }
    </script>

    <script type="text/javascript">
        $(function () {
            enable_voting("{{csrf_token}}", "{% url 'vote_feedback' %}");
        });
    </script>

    <script type="text/javascript" src="{% static 'utils/enable_voting.js' %}"></script>
{% endblock %}
{'fraction_non_alphanumeric': 0.16401185404704574, 'fraction_numerical': 0.005371365067605112, 'mean_word_length': 2.07927003136584, 'pattern_counts': {'":': 8, '<': 121, '<?xml version=': 0, '>': 121, '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': '3391483', 'n_tokens_mistral': 3250, 'n_tokens_neox': 3052, 'n_words': 587}