<commit_before><div class="small-12 columns">
  <% if @commandes.first %>
  <%= form_for @commandes.first do %>
  <fieldset>
    <legend>Adresse Courante</legend>
    <input type="text" id="adresse_courante" value="4777 Avenue Pierre-de Coubertin, Montréal, QC H1V 1B3">
    <input type="button" value="confirmer" class="button tiny radius right" onclick="set_distance_adresses()">
    <a class="etape_1 next hide"></a>
  </fieldset>
  <fieldset>
    <% @commandes.each do |commande| %>
    <div class="small-12 medium-6 large-4 columns">
      <div class="data commande panel radius" onclick="get_map(this);" data-id="<%= commande.id %>" data-restaurant="<%= commande.restaurant.adresse %>">
        <p>
          <%= commande.restaurant.nom %><br>
          <span>Distance : </span><b class="distance"></b><br>
          <small><%= commande.numero %></small>
        </p>
        <span class="adresse"><%= commande.adresse.value %></span><br>
        <div class="date-de-livraison">Date de Livraison : <%= l commande.date_de_livraison, format: :short %></div>
      </div>
    </div>
    <% end %>
    <div class="small-12 columns">
      <a class="etape_2 next hide">Next</a>
      <a class="etape_2 previous left button tiny radius">Prev</a>
    </div>
  </fieldset>
  <fieldset>
    <iframe id="GMapLivraison" width="100%" height="450" frameborder="0" style="border:0" src=""></iframe>
    <div class="form_livraison"></div>
    <a class="button tiny radius previous">Prev</a>
  </fieldset>

  <% end %>
  <% else %>
    <h2>Aucune Commande n'est pretes</h2>
  <% end %>
</div>
<script type="text/javascript"
      src="https://maps.googleapis.com/maps/api/js?key=<KEY>">
    </script>
<script>
  function set_distance_adresses(){
    if (!$("#adresse_courante").val()) {
      return
    }
    var adresse_courante = $("#adresse_courante").val();
    var destinations = $(".commande .adresse").map(function() {return $(this).text();}).get();
    var distanceService = new google.maps.DistanceMatrixService();
    distanceService.getDistanceMatrix({
        origins: [adresse_courante],
        destinations: destinations,
        travelMode: google.maps.TravelMode.DRIVING,
        unitSystem: google.maps.UnitSystem.METRIC,
        durationInTraffic: true,
        avoidHighways: false,
        avoidTolls: false
      },
      function (response, status) {
        if (status !== google.maps.DistanceMatrixStatus.OK) {
            console.log('Error:', status);
            return;
        } else {
          console.log(response);
          var distanceFields = $(".commande .distance");
          $.each(response.rows[0].elements, function(index, elm){
            $(distanceFields[index]).text(elm.distance.text);
          });
          $('.etape_1.next').click();
        }
    });
  };
<commit_msg>FIX : prise en compte de la distance du restaurant dans le calcule de la distance<commit_after><div class="small-12 columns">
  <% if @commandes.first %>
  <%= form_for @commandes.first do %>
  <fieldset>
    <legend>Adresse Courante</legend>
    <input type="text" id="adresse_courante" value="4777 Avenue Pierre-de Coubertin, Montréal, QC H1V 1B3">
    <input type="button" value="confirmer" class="button tiny radius right" onclick="set_distance_adresses()">
    <a class="etape_1 next hide"></a>
  </fieldset>
  <fieldset>
    <div id="commandes-pretes"></div>
    <% @commandes.each do |commande| %>
    <div class="small-12 medium-6 large-4 columns js-commande-wrapper">
      <div class="data commande panel radius" onclick="get_map(this);" data-id="<%= commande.id %>" data-restaurant="<%= commande.restaurant.adresse %>">
        <p>
          <%= commande.restaurant.nom %><br>
          <span>Distance : </span><b class="distance"></b><br>
          <small><%= commande.numero %></small>
        </p>
        <span class="adresse"><%= commande.adresse.value %></span><br>
        <div class="date-de-livraison">Date de Livraison : <%= l commande.date_de_livraison, format: :short %></div>
      </div>
    </div>
    <% end %>
    <div class="small-12 columns">
      <a class="etape_2 next hide">Next</a>
      <a class="etape_2 previous left button tiny radius">Prev</a>
    </div>
  </fieldset>
  <fieldset>
    <iframe id="GMapLivraison" width="100%" height="450" frameborder="0" style="border:0" src=""></iframe>
    <div class="form_livraison"></div>
    <a class="button tiny radius previous">Prev</a>
  </fieldset>

  <% end %>
  <% else %>
    <h2>Aucune Commande n'est pretes</h2>
  <% end %>
</div>
<script type="text/javascript"
      src="https://maps.googleapis.com/maps/api/js?key=<KEY>">
    </script>
<script>
  function set_distance_adresses(){
    if (!$("#adresse_courante").val()) {
      return
    }
    var adresse_courante = $("#adresse_courante").val();
    var restaurants = $(".commande").map(function() {return $(this).data('restaurant');}).get();
    var destinations = $(".commande .adresse").map(function() {return $(this).text();}).get();
    var distanceRestaurant = new google.maps.DistanceMatrixService();
    distanceRestaurant.getDistanceMatrix({
      origins: [adresse_courante],
      destinations: restaurants,
      travelMode: google.maps.TravelMode.DRIVING,
      unitSystem: google.maps.UnitSystem.METRIC,
      durationInTraffic: true,
      avoidHighways: false,
      avoidTolls: false
    },
    function (response, status) {
      if (status !== google.maps.DistanceMatrixStatus.OK) {
        console.log('Error:', status);
        return;
      } else {
        var distanceFields = $(".commande");
        $.each(response.rows[0].elements, function(index, elm){
          $(distanceFields[index]).data('distance-restaurant', parseFloat(elm.distance.text));
        });
        var distanceService = new google.maps.DistanceMatrixService();
        distanceService.getDistanceMatrix({
          origins: [adresse_courante],
          destinations: destinations,
          travelMode: google.maps.TravelMode.DRIVING,
          unitSystem: google.maps.UnitSystem.METRIC,
          durationInTraffic: true,
          avoidHighways: false,
          avoidTolls: false
        },
        function (response, status) {
          if (status !== google.maps.DistanceMatrixStatus.OK) {
            console.log('Error:', status);
            return;
          } else {
            console.log(response);
            var distanceFields = $(".commande .distance");
            $.each(response.rows[0].elements, function(index, elm){
              distance = parseFloat(elm.distance.text) + $(distanceFields[index]).parents(".commande").data('distance-restaurant')
              $(distanceFields[index]).parents(".commande").data('full-distance', distance);
              $(distanceFields[index]).text(""+ distance + " Km");
            });
            $('.etape_1.next').click();
            $('.js-commande-wrapper').sort(function (a, b) {

              var contentA = $(a).find('.commande').data('full-distance');
              var contentB = $(b).find('.commande').data('full-distance');
              return (contentA < contentB) ? -1 : (contentA > contentB) ? 1 : 0;
           }).appendTo('#commandes-pretes');
          }
        });
      }
    });
};

{'fraction_non_alphanumeric': 0.1723421926910299, 'fraction_numerical': 0.008859357696566999, 'mean_word_length': 2.97196261682243, 'pattern_counts': {'":': 0, '<': 134, '<?xml version=': 0, '>': 134, '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': '4992908', 'n_tokens_mistral': 2344, 'n_tokens_neox': 2242, 'n_words': 440}