Adição da função de caixa de ferramentas aglutinando as funções de adição manual

This commit is contained in:
2026-06-26 10:46:42 -03:00
parent 06e287e611
commit 1ca5fc67d7
4 changed files with 60 additions and 23 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 292 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 234 KiB

View File

@@ -0,0 +1,30 @@
// app/javascript/controllers/ferramentas_controller.js
// Stimulus — "caixa de ferramentas": um botão que abre um menu suspenso com as
// ações de lançamento (registrar entrega manual, entrega de termo). Cada item do
// menu dispara o modal correspondente (controllers apontamento-manual /
// apontamento-termo, que vivem no mesmo elemento pai).
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
static targets = ["menu"]
connect() {
// Fecha o menu ao clicar fora dele.
this._fora = (e) => { if (!this.element.contains(e.target)) this.fechar() }
document.addEventListener("click", this._fora)
}
disconnect() {
document.removeEventListener("click", this._fora)
}
toggle(event) {
event.stopPropagation()
this.menuTarget.classList.toggle("hidden")
}
fechar() {
this.menuTarget.classList.add("hidden")
}
}

View File

@@ -116,19 +116,38 @@
</div>
</div>
<%# Apontamento 100% manual — entrega que NÃO está na base de rastreio
(ex.: motorista foi ao local mas a NF ficou com outro no rastreio). %>
<%# Caixa de ferramentas — concentra os lançamentos avulsos (registro manual de
entrega e entrega de termo) num único botão com menu suspenso. Os modais e
controllers existentes são reaproveitados; só o gatilho mudou. %>
<% unless @consolidacao.finalizada? && current_user.operador? %>
<div data-controller="apontamento-manual"
<div class="relative mb-4"
data-controller="ferramentas apontamento-manual apontamento-termo"
data-apontamento-manual-apontar-manual-url-value="<%= apontar_manual_consolidacao_consolidacao_entregas_path(@consolidacao) %>"
class="mb-4">
<button type="button" data-action="apontamento-manual#abrir"
class="w-full md:w-auto inline-flex items-center justify-center gap-2 bg-[#1a1a1a] hover:bg-[#2a2a2a] text-white border border-dashed border-purple-500/60 hover:border-purple-500 font-semibold px-4 py-3 rounded-lg min-h-[48px]">
Registrar entrega manualmente
<span class="text-gray-500 text-xs font-normal hidden md:inline">(fora da base de rastreio)</span>
data-apontamento-termo-apontar-termo-url-value="<%= apontar_termo_consolidacao_consolidacao_entregas_path(@consolidacao) %>"
data-apontamento-termo-motorista-value="<%= @motorista %>">
<%# Botão único + menu suspenso %>
<button type="button" data-action="ferramentas#toggle"
class="w-full md:w-auto inline-flex items-center justify-center gap-2 bg-[#1a1a1a] hover:bg-[#2a2a2a] text-white border border-dashed border-[#3a3a3a] hover:border-orange-500 font-semibold px-4 py-3 rounded-lg min-h-[48px]">
Adicionar lançamento
<span class="text-gray-500">▾</span>
</button>
<%# Modal %>
<div data-ferramentas-target="menu"
class="hidden absolute z-40 mt-2 w-72 bg-[#1a1a1a] border border-[#2a2a2a] rounded-xl shadow-xl overflow-hidden">
<button type="button" data-action="apontamento-manual#abrir ferramentas#fechar"
class="w-full text-left px-4 py-3 hover:bg-[#2a2a2a] border-l-2 border-transparent hover:border-purple-500">
<span class="block text-white font-semibold">📝 Registrar entrega manualmente</span>
<span class="block text-gray-500 text-xs">fora da base de rastreio</span>
</button>
<button type="button" data-action="apontamento-termo#abrir ferramentas#fechar"
class="w-full text-left px-4 py-3 hover:bg-[#2a2a2a] border-t border-[#2a2a2a] border-l-2 border-l-transparent hover:border-l-blue-500">
<span class="block text-white font-semibold">📄 Entrega de termo</span>
<span class="block text-gray-500 text-xs">sem nota/código — só quantidade</span>
</button>
</div>
<%# Modal — registro manual de entrega %>
<div data-apontamento-manual-target="modal" data-action="click->apontamento-manual#fundo"
class="hidden fixed inset-0 z-50 bg-black/70 flex items-center justify-center p-4">
<div class="bg-[#1a1a1a] border border-[#2a2a2a] rounded-2xl w-full max-w-lg p-6 max-h-[90vh] overflow-y-auto">
@@ -196,20 +215,8 @@
</button>
</div>
</div>
</div>
<%# Entrega de termo — entrega SEM nota fiscal nem código; só motorista + quantidade. %>
<div data-controller="apontamento-termo"
data-apontamento-termo-apontar-termo-url-value="<%= apontar_termo_consolidacao_consolidacao_entregas_path(@consolidacao) %>"
data-apontamento-termo-motorista-value="<%= @motorista %>"
class="mb-4">
<button type="button" data-action="apontamento-termo#abrir"
class="w-full md:w-auto inline-flex items-center justify-center gap-2 bg-[#1a1a1a] hover:bg-[#2a2a2a] text-white border border-dashed border-blue-500/60 hover:border-blue-500 font-semibold px-4 py-3 rounded-lg min-h-[48px]">
Entrega de termo
<span class="text-gray-500 text-xs font-normal hidden md:inline">(sem nota/código — só quantidade)</span>
</button>
<%# Modal %>
<%# Modal — entrega de termo %>
<div data-apontamento-termo-target="modal" data-action="click->apontamento-termo#fundo"
class="hidden fixed inset-0 z-50 bg-black/70 flex items-center justify-center p-4">
<div class="bg-[#1a1a1a] border border-[#2a2a2a] rounded-2xl w-full max-w-md p-6">
@@ -239,7 +246,7 @@
<div class="flex items-center justify-center gap-3 mb-5">
<button type="button" data-action="apontamento-termo#menos"
class="w-12 h-12 rounded-lg bg-[#0a0a0a] border border-[#2a2a2a] hover:border-blue-500 text-white text-2xl font-bold leading-none"></button>
<input data-apontamento-termo-target="quantidade" type="number" inputmode="numeric" min="1" value="1" readonly
<input data-apontamento-termo-target="quantidade" type="text" inputmode="numeric" value="1" readonly
class="w-24 text-center bg-[#0a0a0a] border border-[#2a2a2a] text-white text-2xl font-bold rounded-lg py-2.5 focus:outline-none">
<button type="button" data-action="apontamento-termo#mais"
class="w-12 h-12 rounded-lg bg-[#0a0a0a] border border-[#2a2a2a] hover:border-blue-500 text-white text-2xl font-bold leading-none">+</button>