Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 2 additions & 150 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ const SUPABASE_KEY = "sb_publishable_rIcKdaflOvJ0DLTJDcOrxA_bpTGG2hA";
const supabaseClient = window.supabase.createClient(SUPABASE_URL, SUPABASE_KEY);

const STORAGE_KEY = "dts-store-v3";
const USERS_KEY = "users-store-v1";
const SESSION_KEY = "users-session-v1";

const STAR_PRODUCTS = [
["20104425", "PANO SCOTT DURAMAX 58X03X08 BRANCO"],
Expand Down Expand Up @@ -57,8 +55,6 @@ const STATUS_BASE = {
};

let store = loadStore();
let users = loadUsers();
let currentUser = loadSession();

const tabButtons = document.querySelectorAll(".tab-btn");
const panels = document.querySelectorAll(".tab-panel");
Expand All @@ -79,106 +75,7 @@ function saveStore() {
localStorage.setItem(STORAGE_KEY, JSON.stringify(store));
}

function loadUsers() {
const raw = localStorage.getItem(USERS_KEY);
const parsed = raw ? JSON.parse(raw) : [];
const hasMaster = parsed.some((u) => u.role === "mestre");
if (!hasMaster) {
parsed.push({ username: "mestre", password: "123456", role: "mestre" });
localStorage.setItem(USERS_KEY, JSON.stringify(parsed));
}
return parsed;
}

function saveUsers() {
localStorage.setItem(USERS_KEY, JSON.stringify(users));
}

function loadSession() {
const raw = localStorage.getItem(SESSION_KEY);
return raw ? JSON.parse(raw) : null;
}

function saveSession(user) {
localStorage.setItem(SESSION_KEY, JSON.stringify(user));
}

function clearSession() {
localStorage.removeItem(SESSION_KEY);
}

function setupAuth() {
const authScreen = document.getElementById("auth-screen");
const appShell = document.getElementById("app-shell");
const loginForm = document.getElementById("login-form");
const registerForm = document.getElementById("register-form");
const authStatus = document.getElementById("auth-status");

document.getElementById("show-login").addEventListener("click", () => {
loginForm.classList.remove("hidden");
registerForm.classList.add("hidden");
});

document.getElementById("show-register").addEventListener("click", () => {
registerForm.classList.remove("hidden");
loginForm.classList.add("hidden");
});

loginForm.addEventListener("submit", (event) => {
event.preventDefault();
const username = document.getElementById("login-user").value.trim();
const password = document.getElementById("login-pass").value;
const found = users.find((u) => u.username === username && u.password === password);
if (!found) {
authStatus.textContent = "Usuário ou senha inválidos.";
return;
}
currentUser = { username: found.username, role: found.role };
saveSession(currentUser);
authStatus.textContent = "";
authScreen.classList.add("hidden");
appShell.classList.remove("hidden");
onAuthenticated();
});

registerForm.addEventListener("submit", (event) => {
event.preventDefault();
const username = document.getElementById("register-user").value.trim();
const password = document.getElementById("register-pass").value;
if (!username || !password) {
authStatus.textContent = "Preencha usuário e senha.";
return;
}
if (users.some((u) => u.username === username)) {
authStatus.textContent = "Usuário já existe.";
return;
}
users.push({ username, password, role: "padrao" });
saveUsers();
authStatus.textContent = "Registro concluído. Agora faça login.";
registerForm.reset();
loginForm.classList.remove("hidden");
registerForm.classList.add("hidden");
});

document.getElementById("logout-btn").addEventListener("click", () => {
clearSession();
currentUser = null;
appShell.classList.add("hidden");
authScreen.classList.remove("hidden");
});

if (currentUser) {
authScreen.classList.add("hidden");
appShell.classList.remove("hidden");
onAuthenticated();
}
}

function onAuthenticated() {
document.getElementById("current-user").textContent = `Usuário: ${currentUser.username} (${currentUser.role})`;
applyRoleVisibility();
setupAdminPanel();
function initApp() {
bindAppEvents();
renderResumoImportacao();
pesquisarPorFinalDT();
Expand All @@ -188,51 +85,6 @@ function onAuthenticated() {
renderStarProducts();
}

function applyRoleVisibility() {
const role = currentUser?.role || "padrao";
document.querySelectorAll(".role-protected").forEach((el) => {
const allowed = String(el.dataset.roles || "").split(",").map((v) => v.trim());
el.classList.toggle("hidden", !allowed.includes(role));
});

if (document.querySelector(".tab-btn.active.hidden")) {
const first = document.querySelector(".tab-btn:not(.hidden)");
if (first) first.click();
}
}

function setupAdminPanel() {
const panel = document.getElementById("admin-panel");
const select = document.getElementById("promote-user");
const adminStatus = document.getElementById("admin-status");
if (currentUser?.role !== "mestre") {
panel.classList.add("hidden");
return;
}

panel.classList.remove("hidden");
select.innerHTML = "";
users.filter((u) => u.role !== "mestre" && u.role !== "analista").forEach((u) => {
const opt = document.createElement("option");
opt.value = u.username;
opt.textContent = u.username;
select.appendChild(opt);
});

document.getElementById("promote-btn").onclick = () => {
const username = select.value;
const found = users.find((u) => u.username === username);
if (!found) {
adminStatus.textContent = "Nenhum usuário padrão disponível para promoção.";
return;
}
found.role = "analista";
saveUsers();
adminStatus.textContent = `${username} promovido para analista.`;
setupAdminPanel();
};
}

let appEventsBound = false;
function bindAppEvents() {
if (appEventsBound) return;
Expand Down Expand Up @@ -672,4 +524,4 @@ function renderStarProducts() {
});
}

setupAuth();
initApp();
52 changes: 2 additions & 50 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,57 +7,18 @@
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<section id="auth-screen" class="auth-screen">
<div class="auth-card">
<h1>Painel Logístico</h1>
<p>Acesse com seu usuário ou faça um novo registro.</p>

<div class="auth-toggle">
<button id="show-login" class="primary" type="button">Login</button>
<button id="show-register" type="button">Registro</button>
</div>

<form id="login-form" class="auth-form">
<label>Usuário
<input id="login-user" required />
</label>
<label>Senha
<input id="login-pass" type="password" required />
</label>
<button class="primary" type="submit">Entrar</button>
</form>

<form id="register-form" class="auth-form hidden">
<label>Usuário
<input id="register-user" required />
</label>
<label>Senha
<input id="register-pass" type="password" required />
</label>
<button class="primary" type="submit">Registrar</button>
</form>

<p class="hint">Novo registro entra como usuário padrão. Somente mestre pode promover para analista.</p>
<p id="auth-status" aria-live="polite"></p>
</div>
</section>

<div id="app-shell" class="hidden">
<div id="app-shell">
<header>
<h1>Painel Logístico</h1>
<p>Importação em lote, grade de carregamento, dashboard de pátio e status operacional.</p>
<div class="user-bar">
<span id="current-user"></span>
<button id="logout-btn" type="button">Sair</button>
</div>
</header>

<nav class="tabs">
<button class="tab-btn active" data-tab="zles002">ZLES002</button>
<button class="tab-btn" data-tab="grade">Grade</button>
<button class="tab-btn" data-tab="dashboard">Dashboard</button>
<button class="tab-btn" data-tab="status-page">Status</button>
<button class="tab-btn role-protected" data-roles="mestre,analista" data-tab="mb51">MB51</button>
<button class="tab-btn" data-tab="mb51">MB51</button>
<button class="tab-btn" data-tab="relatorio">Relatório</button>
<button class="tab-btn" data-tab="produtos-estrela">Produtos Estrela</button>
</nav>
Expand All @@ -66,15 +27,6 @@ <h1>Painel Logístico</h1>
<section id="zles002" class="tab-panel active">
<h2>Detalhes de Materiais</h2>

<div id="admin-panel" class="sub-card hidden">
<h3>Administração de usuários</h3>
<label>Promover usuário para analista
<select id="promote-user"></select>
</label>
<button id="promote-btn" type="button">Promover para analista</button>
<p id="admin-status"></p>
</div>

<div class="sub-card">
<label>
Cole as linhas do SAP (uma linha por item/remessa)
Expand Down
32 changes: 0 additions & 32 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,6 @@ main {
display: none !important;
}

.auth-screen {
min-height: 100vh;
display: grid;
place-items: center;
padding: 1rem;
}

.auth-card {
width: min(440px, 95vw);
background: #fff;
border: 1px solid #d8dce1;
border-radius: 14px;
padding: 1rem;
}

.auth-toggle {
display: flex;
gap: 0.5rem;
margin-bottom: 0.8rem;
}

.auth-form {
display: grid;
gap: 0.6rem;
}

.user-bar {
display: flex;
gap: 0.75rem;
align-items: center;
}

.tabs {
display: flex;
gap: 0.5rem;
Expand Down