- ConfiguracaoPolicy (e UserPolicy) chamavam admin_ou_gerente?/admin? que não existiam -> helpers movidos para ApplicationPolicy (toda policy herda) - View de usuários usava helper badge_role inexistente -> criado em ApplicationHelper (badge por papel, cores do navbar) Spec: ConfiguracaoPolicy. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
61 lines
2.4 KiB
Ruby
61 lines
2.4 KiB
Ruby
# app/helpers/application_helper.rb
|
|
module ApplicationHelper
|
|
# Link de navegação com estado ativo
|
|
def nav_link_to(label, path, **opts)
|
|
active = current_page?(path)
|
|
css = [
|
|
"flex items-center gap-3 px-3 py-2.5 rounded-lg text-sm font-medium transition-all min-h-[44px]",
|
|
active ? "bg-orange-500 text-black" : "text-gray-400 hover:bg-[#1a1a1a] hover:text-white"
|
|
].join(" ")
|
|
link_to label, path, class: css
|
|
end
|
|
|
|
# Formata moeda BR
|
|
def moeda(valor)
|
|
"R$ #{"%.2f" % valor.to_f}".gsub('.', ',')
|
|
end
|
|
|
|
# Badge de status de consolidação
|
|
def badge_status(status)
|
|
cfg = case status.to_s
|
|
when 'rascunho' then { cor: 'bg-yellow-500 text-black', icone: '📝', label: 'Rascunho' }
|
|
when 'finalizada' then { cor: 'bg-green-600 text-white', icone: '✅', label: 'Finalizada' }
|
|
when 'arquivada' then { cor: 'bg-gray-700 text-gray-300', icone: '📁', label: 'Arquivada' }
|
|
else { cor: 'bg-gray-800 text-gray-400', icone: '❓', label: status.humanize }
|
|
end
|
|
|
|
tag.span class: "inline-flex items-center gap-1 px-2.5 py-1 rounded-full text-xs font-bold #{cfg[:cor]}" do
|
|
"#{cfg[:icone]} #{cfg[:label]}"
|
|
end
|
|
end
|
|
|
|
# Badge de papel do usuário (admin/gerente/operador/motorista)
|
|
def badge_role(role)
|
|
cfg = case role.to_s
|
|
when 'admin' then { cor: 'bg-orange-500 text-black' }
|
|
when 'gerente' then { cor: 'bg-orange-800 text-white' }
|
|
when 'operador' then { cor: 'bg-gray-700 text-white' }
|
|
when 'motorista' then { cor: 'bg-gray-900 text-orange-400 border border-orange-500' }
|
|
else { cor: 'bg-gray-800 text-gray-400' }
|
|
end
|
|
label = User::ROLES_LABEL[role.to_s] || role.to_s.humanize
|
|
|
|
tag.span label, class: "inline-flex items-center px-2.5 py-1 rounded-full text-xs font-bold #{cfg[:cor]}"
|
|
end
|
|
|
|
# Barra de progresso laranja
|
|
def progress_bar(percentual, label: nil)
|
|
pct = percentual.to_i.clamp(0, 100)
|
|
tag.div class: "w-full" do
|
|
concat tag.div(class: "flex justify-between text-xs text-gray-400 mb-1") {
|
|
concat tag.span(label || "#{pct}% classificado")
|
|
concat tag.span("#{pct}%")
|
|
}
|
|
concat tag.div(class: "w-full bg-[#2a2a2a] rounded-full h-2") {
|
|
tag.div style: "width: #{pct}%",
|
|
class: "h-2 rounded-full bg-orange-500 transition-all duration-500"
|
|
}
|
|
end
|
|
end
|
|
end
|