Correção e Adição do filtro ao vivo

This commit is contained in:
2026-06-29 20:50:07 -03:00
parent 7f21a16327
commit 6b899ebafa
9 changed files with 279 additions and 74 deletions

View File

@@ -1,32 +1,51 @@
<%# locals: cabecalhos (Array), linhas (Array de Array), vazio (String), total (opcional) %>
<%# locals:
cabecalhos (Array), linhas (Array de Array), vazio (String),
total (opcional) — linha de rodapé "Total"
filtro (opcional) — nome do param (ex.: 'f_driver') que torna a 1ª coluna
clicável para cross-filter %>
<% total_rodape = local_assigns[:total] %>
<% filtro = local_assigns[:filtro] %>
<% base = request.query_parameters %>
<% if linhas.blank? %>
<p class="text-center py-6 text-gray-500 text-sm"><%= vazio %></p>
<% else %>
<table class="w-full text-sm">
<thead>
<tr class="text-gray-400 text-left border-b border-white/5">
<% cabecalhos.each_with_index do |c, i| %>
<th class="pb-2 font-medium <%= 'text-right' if i.positive? %>"><%= c %></th>
<% end %>
</tr>
</thead>
<tbody>
<% linhas.each do |celulas| %>
<tr class="border-b border-white/5">
<% celulas.each_with_index do |cel, i| %>
<td class="py-2 <%= i.positive? ? 'text-right font-semibold text-white' : 'text-gray-300' %>"><%= cel %></td>
<div class="overflow-x-auto">
<table class="w-full text-sm">
<thead>
<tr class="text-gray-400 text-left border-b border-white/5">
<% cabecalhos.each_with_index do |c, i| %>
<th class="pb-2 font-medium <%= i.zero? ? 'pr-3' : 'pl-4 text-right whitespace-nowrap' %>"><%= c %></th>
<% end %>
</tr>
</thead>
<tbody>
<% linhas.each do |celulas| %>
<% ativo = filtro && base[filtro].to_s == celulas.first.to_s %>
<tr class="border-b border-white/5 <%= 'bg-orange-500/10' if ativo %>">
<% celulas.each_with_index do |cel, i| %>
<td class="py-2 align-top <%= i.zero? ? 'pr-3 text-gray-300' : 'pl-4 text-right whitespace-nowrap font-semibold text-white' %>">
<% if i.zero? && filtro %>
<%= link_to cel,
operacoes_dashboard_path(base.merge(filtro => cel.to_s)),
data: { turbo: false },
title: "Filtrar por #{cel}",
class: "inline-flex items-center gap-1 hover:text-orange-400 #{'text-orange-400 font-semibold' if ativo}" %>
<% else %>
<%= cel %>
<% end %>
</td>
<% end %>
</tr>
<% end %>
</tbody>
<% if total_rodape %>
<tfoot>
<tr class="text-white font-bold">
<td class="pt-2 pr-3">Total</td>
<td class="pt-2 pl-4 text-right whitespace-nowrap" colspan="<%= cabecalhos.size - 1 %>"><%= total_rodape %></td>
</tr>
</tfoot>
<% end %>
</tbody>
<% if total_rodape %>
<tfoot>
<tr class="text-white font-bold">
<td class="pt-2">Total</td>
<td class="pt-2 text-right" colspan="<%= cabecalhos.size - 1 %>"><%= total_rodape %></td>
</tr>
</tfoot>
<% end %>
</table>
</table>
</div>
<% end %>