ikuseiGmbH/smart-village-app-cms

View on GitHub
app/views/news_items/index.html.erb

Summary

Maintainability
Test Coverage
<div class="d-flex flex-wrap align-items-center row-gap justify-content-between mb-5">
  <h1 class="h3 mb-0 pb-0 font-weight-bold mr-3">Nachrichten</h1>
  <%= link_to new_news_item_path, class: "btn btn-sm btn-primary shadow-sm" do %>
    <i class="fas fa-plus fa-sm text-white-50"></i>
    Neue Nachricht erstellen
  <% end %>
</div>

<div class="table-responsive pb-4">
  <table class="table data_table bg-white">
    <thead>
      <tr>
        <th scope="col">ID</th>
        <th scope="col">Überschrift</th>
        <th scope="col">Kategorie</th>
        <th scope="col">Änderungsdatum</th>
        <th scope="col">Erstellungsdatum</th>
        <% if editor? || extended_user? %>
          <th>Datenquelle</th>
        <% end %>
        <% if editor?  %>
          <th scope="col" class="nosort">Sichtbarkeit</th>
        <% end %>
        <th scope="col" class="nosort">Aktionen</th>
      </tr>
    </thead>
    <tbody>
      <% @news_items.each do |news_item| %>
        <tr>
          <th scope="row"><%= news_item.id %></th>
          <% if news_item.push_notifications_sent_at.blank? %>
            <td>
              <%= link_to(
                    news_item.title.presence || news_item.content_blocks.first.try(:title) || "",
                    edit_news_item_path(news_item.id)
                  )%>
            </td>
          <% else %>
            <td><%= news_item.title.presence || news_item.content_blocks.first.try(:title) %></td>
          <% end %>
          <td><%= news_item.categories.first.try(:name) %></td>
          <td data-sort="<%= DateTime.parse(news_item.updated_at).to_i %>">
            <%= to_local_date_time(news_item.updated_at) %>
          </td>
          <td data-sort="<%= DateTime.parse(news_item.created_at).to_i %>">
            <%= to_local_date_time(news_item.created_at) %>
          </td>
          <% if editor? || extended_user? %>
            <td><%= news_item.data_provider.try(:name) %></td>
          <% end %>
          <% if editor? %>
            <td align="center"><%= visibility_switch(news_item, "NewsItem") %></td>
          <% end %>
          <td align="right" class="text-nowrap">
            <% edit_label = editable_by_user?(news_item) ? "Bearbeiten" : "Ansehen" %>
            <%= link_to edit_label, edit_news_item_path(news_item.id), class: "btn btn-sm btn-secondary" if news_item.push_notifications_sent_at.blank? %>
            <% if editable_by_user?(news_item) %>
              <%= link_to news_item_path(news_item.id), method: :delete, "data-confirm" => "Diesen Eintrag wirklich löschen?", class: "btn btn-sm btn-danger", title: "Löschen" do %>
                <i class="fas fa-trash"></i>
              <% end %>
            <% end %>
          </td>
        </tr>
      <% end %>
    </tbody>
  </table>
</div>