ikuseiGmbH/smart-village-app-cms

View on GitHub
app/views/waste_calendar/new.html.erb

Summary

Maintainability
Test Coverage
<div class="text-center">
  <h1 class="h3 mb-0 font-weight-bold">Touren und Adressen konfigurieren</h1>
</div>

<div class="row justify-content-center">
  <div class="col-lg-8">
    <p>
      Hier werden Touren geplant. Zu einer Tour gehören mehrere Abholorte und eine Abfallart.
      Es können neue Touren eingepflegt werden sowie bestehende Touren bearbeitet werden.
      Die Termine für eine Tour werden an einer anderen Stelle festgelegt.
    </p>

    <%= render partial: "waste_calendar/new_tour_address" %>

    <% if @waste_locations && @waste_locations.any? %>
      <%= form_with(url: "#", method: :post, remote: true) do |f| %>
        <table class="table table-hover table-striped table-sm data_table_matrix nowrap">
          <thead class="thead-light">
            <tr>
              <th class="sticky-column">Adresse</th>
              <% @waste_tours.each do |tour| %>
                <th class="matrix-header nosort" align="left">
                    <%= link_to tour.title, edit_tour_waste_calendar_index_path(tour_id: tour.id) %>
                    <%= link_to remove_tour_waste_calendar_index_path(id: tour.id), class: "close", "data-confirm": "Tour löschen?" do %>
                      <span aria-hidden="true">&times;</span>
                    <% end %>
                    <br>
                    (<%= @waste_types.fetch(tour.waste_type, {}).fetch("label", "") %>)
                  </div>
                </th>
              <% end %>
            </tr>
          </thead>
          <% @waste_locations.each do |location| %>
            <tr>
              <td class="sticky-column">
                <%= link_to location.street, edit_location_waste_calendar_index_path(location_id: location.id) %>
                <em class="small">(<%= location.zip %> <%= location.city %>)</em>
                <%= link_to remove_location_waste_calendar_index_path(id: location.id), class: "close", "data-confirm": "Adresse löschen?" do %>
                  <span aria-hidden="true">&times;</span>
                <% end %>
              </td>
              <% selected_tour_ids = location.waste_location_types.map{ |waste_location_type| waste_location_type.waste_tour }.compact.map { |waste_location_type| waste_location_type.id }.compact %>
              <% @waste_tours.each do |tour| %>
                <td>
                  <%= hidden_field_tag "location_tour[#{location.id}][#{tour.id}]", false %>
                  <%= check_box_tag "location_tour[#{location.id}][#{tour.id}]", true, selected_tour_ids.include?(tour.id), class: "matrix-checkbox", data: { address_id: location.id, tour_id: tour.id } %>
                </td>
              <% end %>
            </tr>
          <% end %>
        </table>
      <% end %>
    <% end %>
  </div>
</div>