feat: new layout phase F, Ficha da máquina and Números as on the canvas

Roadmap Novo Layout, phase F step 2 (canvas U2, N1): the machines list as
compact rows with their status line; the machine sheet in the shared
dialog with a fixed head and the tabs Situação, Lançamentos and Dados da
máquina (launch rule unchanged); Números as one scrolling page with the
four headline cards, Metros por dia, Produção, Vendas and Consulta
groups. The people list and roles matrix are untouched. Built by Bobina.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-11-16 11:52:39 -03:00
parent 392a21082e
commit a34d8e1888
4 changed files with 284 additions and 159 deletions

View File

@@ -202,30 +202,38 @@ function renderUsers(){
$('machines-list').replaceChildren(...(machines.length?machines.map(machineTile)
:[emptyState(IC.printer,'Nenhuma máquina cadastrada','Cadastre as máquinas para os pedidos irem para elas.')]));
}
// A machine: its metres open against its limit, its orders by stage, and who is on it.
// A machine, in one compact line: name, products, its open metres and orders,
// who is on it, and the alert mark. The stage breakdown and the limit stay in
// the row's tooltip, so the numbers of the old tile are not lost.
const STAGE_FILL={rec:'var(--tx3)',tra:'var(--ln3)',imp:'var(--ink)',cor:'var(--bad)',rev:'var(--tx2)'};
function machineTile(m){
const tile=node('article',undefined,'mtile'+(m.active?'':' off'));
const head=node('div',undefined,'row');
head.append(node('h3',m.name),node('span',m.products.map(p=>PRODUCT_LABEL[p]).join(' e ')||'Nenhum produto','lbl'));
if(!m.active)head.append(badge('Desativada',''));
head.append(button('Ficha',()=>openMachineSheet(m.id),'btn ghost right'),button('Editar',()=>machineForm(m),'btn ghost'));
const over=!!m.limit_metres&&m.open_metres>m.limit_metres;
const load=node('div',undefined,'row base');
load.append(node('b',metres(m.open_metres),over?'bad':''),node('span','em aberto, '+(m.limit_metres?'limite de '+metres(m.limit_metres)+(over?', acima do limite':''):'sem limite'),'lbl'));
const stages=Object.keys(STAGE_FILL).filter(s=>m.states[s]);
const total=stages.reduce((t,s)=>t+m.states[s],0);
tile.append(head,load);
if(total){
const stack=node('div',undefined,'stack'),list=node('ul');
for(const s of stages){const seg=node('i');seg.style.width=(100*m.states[s]/total)+'%';seg.style.background=STAGE_FILL[s];stack.append(seg);
const li=node('li'),dot=node('i');dot.style.background=STAGE_FILL[s];li.append(dot,board?.states?.[s]||s,node('b',String(m.states[s])));list.append(li);}
tile.append(stack,list);
}else tile.append(node('span','Nenhum pedido em aberto','lbl'));
const people=node('div',undefined,'row people');people.append(svgIcon(IC.user,'i s'),
m.operators?.length?m.operators.map(o=>o.name+(o.since?' desde '+new Date(o.since).toLocaleTimeString('pt-BR',{hour:'2-digit',minute:'2-digit'}):'')).join(', ')+(m.operators.length>1?' estão nela':' está nela'):'Ninguém nela agora');
tile.append(people);
return tile;
const row=node('div',undefined,'mt'+(m.active?'':' off'));
const body=node('div',undefined,'mtbody');
const top=node('div',undefined,'mtname');
top.append(node('b',m.name));
for(const p of m.products||[])top.append(node('span',PRODUCT_LABEL[p],'tag'));
if(!m.active)top.append(node('span','Desativada','tag'));
if((m.alerts||[]).length){const dot=node('span',undefined,'mtwarn');dot.title='Aviso na ficha';top.append(dot);}
const stages=Object.keys(STAGE_FILL).filter(state=>m.states?.[state]);
const stageText=stages.map(state=>(board?.states?.[state]||state)+': '+m.states[state]).join(' · ');
const limit=m.limit_metres?'limite de '+metres(m.limit_metres):'';
if(limit||stageText)row.title=[limit,stageText].filter(Boolean).join(' · ');
const mine=myMachine()?.id===m.id;
const others=(m.operators||[]).filter(op=>op.name!==(ME.name||ME.email));
const who=mine?'Ficha está nela agora':others.length?others.map(op=>op.name).join(', ')+(others.length>1?' estão nela':' está nela'):'ninguém nela agora';
const open=Number(m.open_orders||0)>0||Number(m.open_metres||0)>0;
if(open){
const status=node('div',undefined,'mtstatus');
const amount=node('b',metres(m.open_metres));
if(m.limit_metres&&m.open_metres>m.limit_metres)amount.classList.add('bad');
status.append(amount,' em aberto · ',plural(m.open_orders,'pedido','pedidos'),' · ',who);
body.append(top,status);
}else{
top.append(node('span','Livre · '+who,'mtfree'));
body.append(top);
}
row.append(body,button('Ficha',()=>openMachineSheet(m.id),'btn sm'),button('Editar',()=>machineForm(m),'btn ghost sm'));
return row;
}
function userForm(u){
const editing=!!u;
@@ -302,40 +310,26 @@ function machineEntryLine(entry, catalog){
return [when(entry.created_at),label,detail,entry.created_by].filter(Boolean).join(' · ');
}
async function openMachineSheet(machineId){
async function openMachineSheet(machineId, tab='situacao'){
let data;
try{data=await api('/machines/'+machineId+'/sheet');}
catch(e){say(e.message,true);return;}
const machine=data.machine;
const machineState=(board.machines||[]).find(row=>row.id===machine.id)||null;
const launch=may('print')&&(ME?.role!=='operador'||myMachine()?.id===machine.id);
const body=[];
const manage=may('manage');
let sheetModal=null;
const refresh=async()=>{sheetModal?.close();await load();openMachineSheet(machine.id);};
let activeTab=tab;
const refresh=async(next=activeTab)=>{sheetModal?.close();await load();openMachineSheet(machine.id,next);};
const minimum=value=>Number(value).toLocaleString('pt-BR',{maximumFractionDigits:3});
const counts=node('div',undefined,'mblock');
const fact=(label,value)=>{const row=node('div',undefined,'mfact');row.append(node('span',label),node('b',value));counts.append(row);};
const clean=data.counters.clean, film=data.counters.film;
fact('Desde a última limpeza',m1(clean.metres)+' m'+(clean.since?'':' (nenhuma limpeza lançada ainda)'));
fact('Desde a troca de filme',film.since?m1(film.metres)+' m '+(film.aligned?'(cabeça alinhada)':'(falta alinhar)'):'sem registro');
body.push(node('h4','Contadores','sh'),counts);
const supplies=node('div',undefined,'mblock');
for(const [item,[label,unit]] of Object.entries(data.catalog.supplies)){
const value=data.supplies[item];
const row=node('div',undefined,'mfact');
let text;
if(value){
text='acaba em ~'+m1(value.metres_left)+' m';
if(value.minimum!==null&&value.minimum!==undefined)text+=' · mínimo '+minimum(value.minimum)+' '+unit;
}else text='lance duas reposições para estimar';
row.append(node('span',label),node('b',text));
supplies.append(row);
}
body.push(node('h4','Insumos','sh'),supplies);
const situacao=node('div',undefined,'msheet-pane');situacao.setAttribute('role','tabpanel');
const lancamentos=node('div',undefined,'msheet-pane');lancamentos.setAttribute('role','tabpanel');
const dados=node('div',undefined,'msheet-pane');dados.setAttribute('role','tabpanel');
// Situação: the alerts, the counters and the supplies.
if(data.alerts.length){
const box=node('div',undefined,'mblock');
const box=node('div',undefined,'msheet-alerts');
const done=async alert=>{
if(alert.key.startsWith('supply:')){
const saved=await machineEntryForm(machine.id,{kind:'supply',item:alert.key.slice(7),from_alert:true},data);
@@ -344,55 +338,69 @@ async function openMachineSheet(machineId){
await api('/machines/'+machine.id+'/entries',{kind:'event',item:alert.key,from_alert:true});
}
say('Aviso resolvido.');
await refresh();
await refresh(activeTab);
};
for(const alert of data.alerts){
const row=node('div',undefined,'sheetalert');
const words=node('span',undefined,'grow');
const row=node('div',undefined,'msheet-alert');
const ico=node('span',undefined,'msheet-alertico');ico.append(svgIcon(IC.alert,'i m'));
const words=node('div',undefined,'msheet-alertwords');
words.append(node('b',alert.text),node('span',alert.blocking?'pendente':'adiado neste ciclo','sub'));
row.append(words);
row.append(ico,words);
if(launch){
const actions=node('span',undefined,'prow');
actions.append(button('Marcar como feito',()=>done(alert),'btn'));
if(alert.snoozable)actions.append(button('Adiar uma vez',async()=>{
await api('/machines/'+machine.id+'/alerts/'+encodeURIComponent(alert.key)+'/snooze',{});
say('Aviso adiado: passa um arquivo e ele volta.');
await refresh();
await refresh(activeTab);
},'btn ghost'));
actions.append(button('Marcar como feito',()=>done(alert),'btn'));
row.append(actions);
}
box.append(row);
}
body.push(node('h4','Avisos pendentes','sh'),box);
situacao.append(box);
}
const clean=data.counters.clean, film=data.counters.film;
const counters=node('div',undefined,'msheet-counters');
const counter=(label,value,note)=>{
const card=node('div',undefined,'msheet-ctr');
card.append(node('span',label),node('b',value),node('small',note));counters.append(card);
};
counter('Desde a última limpeza',m1(clean.metres)+' m',
clean.since?'Limpeza lançada em '+when(clean.since):'Nenhuma limpeza lançada ainda');
counter('Desde a troca de filme',film.since?m1(film.metres)+' m':'—',
film.since?'Troca lançada em '+when(film.since)+(film.aligned?', cabeça alinhada':', falta alinhar'):'Sem registro');
situacao.append(counters);
situacao.append(node('h4','Insumos','msheet-h'));
const supplies=node('div',undefined,'msheet-supplies');
for(const [item,[label,unit]] of Object.entries(data.catalog.supplies)){
const value=data.supplies[item];
const typed=data.minimums[item], fallback=data.default_minimums?.[item];
const floor=typed!==null&&typed!==undefined?typed:fallback;
const row=node('div',undefined,'msheet-supply');
row.append(node('b',label),
node('span',value?'acaba em ~'+m1(value.metres_left)+' m':'lance duas reposições para estimar'),
node('em',floor!==null&&floor!==undefined?'mín. '+minimum(floor)+' '+unit:''));
supplies.append(row);
}
situacao.append(supplies);
const entries=node('div',undefined,'mlist sheetentries');
// Lançamentos: the log. The footer's Lançar opens the form.
const entries=node('div',undefined,'mlist');
if(data.entries.length)for(const entry of data.entries)entries.append(node('div',machineEntryLine(entry,data.catalog),'mli'));
else entries.append(node('div','Nenhum lançamento ainda','mli muted'));
body.push(node('h4','Lançamentos','sh'),entries);
lancamentos.append(entries);
if(launch){
const prow=node('div',undefined,'prow');
prow.append(button('Lançar',async()=>{
const saved=await machineEntryForm(machine.id,{},data);
if(!saved)return;
say('Lançamento registrado.');
await refresh();
},'btn pri'));
body.push(prow);
}
if(may('manage')){
// Dados da máquina: price, installation and the minimums (management).
if(manage){
const price=node('input');price.type='number';price.min='0';price.step='0.01';price.inputMode='decimal';
price.value=data.machine.price_cents!==null&&data.machine.price_cents!==undefined?(data.machine.price_cents/100).toFixed(2):'';
const installed=node('input');installed.type='date';installed.value=data.machine.installed_on||'';
price.value=machine.price_cents!==null&&machine.price_cents!==undefined?(machine.price_cents/100).toFixed(2):'';
const installed=node('input');installed.type='date';installed.value=machine.installed_on||'';
const minimums={};
const box=node('div',undefined,'mblock');
box.append(field('Preço de compra (R$)',price),field('Data de instalação',installed));
for(const [item,[label,unit]] of Object.entries(data.catalog.supplies)){
const input=node('input');input.type='number';input.min='0';input.step='0.001';input.inputMode='decimal';
// Dropstar's fixed minimums are the defaults: a machine with none typed
// shows and uses them until Gestão changes them.
const typed=data.minimums[item], fallback=data.default_minimums?.[item];
input.value=typed!==null&&typed!==undefined?Number(typed).toString()
:fallback!==null&&fallback!==undefined?Number(fallback).toString():'';
@@ -410,16 +418,48 @@ async function openMachineSheet(machineId){
minimums:Object.fromEntries(Object.entries(minimums).map(([item,input])=>
[item,input.value.trim()===''?null:Number(input.value)]))});
say('Dados da máquina salvos.');
await refresh();
await refresh('dados');
}catch(e){error.textContent=e.message;error.hidden=false;}
finally{save.disabled=false;}
};
const foot=node('div',undefined,'prow');foot.append(error,save);
box.append(foot,node('small','Preço e data servem para o retorno da máquina em Números.','sub'));
body.push(node('h4','Dados da máquina','sh'),box);
dados.append(box);
}
sheetModal=modal('Ficha da '+machine.name,{host:dialogHost(),width:640,body});
// The tabs keep the fixed head while the active section scrolls.
const tabs=node('div',undefined,'msheet-tabs');tabs.setAttribute('role','tablist');
const panes=node('div',undefined,'msheet-panes');
const labels=[['situacao','Situação',situacao],['lancamentos','Lançamentos',lancamentos],...(manage?[['dados','Dados da máquina',dados]]:[])];
if(!labels.some(([key])=>key===activeTab))activeTab='situacao';
const paintTabs=()=>{
for(const button of tabs.children){const on=button.dataset.tab===activeTab;button.classList.toggle('on',on);button.setAttribute('aria-selected',String(on));}
for(const pane of panes.children)pane.hidden=pane.dataset.tab!==activeTab;
};
for(const [key,label,pane] of labels){
const b=node('button',label,'msheet-tab');b.type='button';b.dataset.tab=key;b.setAttribute('role','tab');
b.onclick=()=>{activeTab=key;paintTabs();};
tabs.append(b);pane.dataset.tab=key;panes.append(pane);
}
paintTabs();
const wrap=node('div',undefined,'msheet');wrap.append(tabs,panes);
const note=node('span','Lançar registra limpeza, filme, alinhamento ou reposição.','msheet-note');
const foot=[note,button('Fechar',()=>sheetModal?.close(),'btn ghost')];
if(launch)foot.push(button('Lançar',async()=>{
const saved=await machineEntryForm(machine.id,{},data);
if(!saved)return;
say('Lançamento registrado.');
await refresh('lancamentos');
},'btn pri'));
const mine=myMachine()?.id===machine.id;
const others=(machineState?.operators||[]).filter(op=>op.name!==(ME.name||ME.email));
const who=mine?'Ficha está nela agora':others.length?others.map(op=>op.name).join(', ')+(others.length>1?' estão nela':' está nela'):'Livre';
const products=(machineState?.products||[]).map(p=>PRODUCT_LABEL[p]).join(' e ')||'Nenhum produto';
const state=[products,machineState?.active===false?'Desativada':null,who,
machineState?.open_orders?plural(machineState.open_orders,'pedido','pedidos')+' em aberto':''].filter(Boolean).join(' · ');
sheetModal=modal('Ficha da '+machine.name,{text:state,host:dialogHost(),width:720,body:[wrap],foot});
sheetModal.box.classList.add('machine-sheet-dlg');
}
// The launch form: type, item, and only the fields that type uses. Resolves