first commit
This commit is contained in:
+211
@@ -0,0 +1,211 @@
|
||||
const fileInput = document.getElementById("file-input");
|
||||
const fileNameEl = document.getElementById("file-name");
|
||||
const importBtn = document.getElementById("import-btn");
|
||||
const dropZone = document.getElementById("drop-zone");
|
||||
const progress = document.getElementById("progress");
|
||||
const alertSection = document.getElementById("alert-section");
|
||||
const alertMessage = document.getElementById("alert-message");
|
||||
const summarySection = document.getElementById("summary-section");
|
||||
const summaryGrid = document.getElementById("summary-grid");
|
||||
const mappingSection = document.getElementById("mapping-section");
|
||||
const mappingList = document.getElementById("mapping-list");
|
||||
const previewSection = document.getElementById("preview-section");
|
||||
const previewTable = document.getElementById("preview-table");
|
||||
const resultsSection = document.getElementById("results-section");
|
||||
const resultsTable = document.getElementById("results-table");
|
||||
const healthBanner = document.getElementById("health-banner");
|
||||
const healthMessage = document.getElementById("health-message");
|
||||
|
||||
let selectedFile = null;
|
||||
|
||||
function showAlert(text, type = "error") {
|
||||
alertSection.hidden = false;
|
||||
alertMessage.textContent = text;
|
||||
alertMessage.className = `alert ${type}`;
|
||||
}
|
||||
|
||||
function hideAlert() {
|
||||
alertSection.hidden = true;
|
||||
}
|
||||
|
||||
function setFile(file) {
|
||||
selectedFile = file;
|
||||
fileNameEl.textContent = file ? file.name : "Nenhum arquivo selecionado";
|
||||
importBtn.disabled = !file;
|
||||
}
|
||||
|
||||
fileInput.addEventListener("change", () => {
|
||||
const file = fileInput.files?.[0];
|
||||
if (file) setFile(file);
|
||||
});
|
||||
|
||||
dropZone.addEventListener("dragover", (e) => {
|
||||
e.preventDefault();
|
||||
dropZone.classList.add("dragover");
|
||||
});
|
||||
|
||||
dropZone.addEventListener("dragleave", () => {
|
||||
dropZone.classList.remove("dragover");
|
||||
});
|
||||
|
||||
dropZone.addEventListener("drop", (e) => {
|
||||
e.preventDefault();
|
||||
dropZone.classList.remove("dragover");
|
||||
const file = e.dataTransfer?.files?.[0];
|
||||
if (file) {
|
||||
setFile(file);
|
||||
const dt = new DataTransfer();
|
||||
dt.items.add(file);
|
||||
fileInput.files = dt.files;
|
||||
}
|
||||
});
|
||||
|
||||
function renderPreview(preview) {
|
||||
if (!preview?.headers?.length) return;
|
||||
previewSection.hidden = false;
|
||||
const thead = previewTable.querySelector("thead");
|
||||
const tbody = previewTable.querySelector("tbody");
|
||||
thead.innerHTML = `<tr>${preview.headers.map((h) => `<th>${escapeHtml(h)}</th>`).join("")}</tr>`;
|
||||
tbody.innerHTML = (preview.rows ?? [])
|
||||
.map(
|
||||
(row) =>
|
||||
`<tr>${row.map((cell) => `<td>${escapeHtml(formatCell(cell))}</td>`).join("")}</tr>`,
|
||||
)
|
||||
.join("");
|
||||
}
|
||||
|
||||
function renderHeaderMapping(headerMapping) {
|
||||
const entries = Object.entries(headerMapping ?? {});
|
||||
if (!entries.length) return;
|
||||
mappingSection.hidden = false;
|
||||
mappingList.innerHTML = entries
|
||||
.map(
|
||||
([excel, api]) =>
|
||||
`<li><span class="excel-col">${escapeHtml(excel)}</span><span class="arrow">→</span><span class="api-col">${escapeHtml(api)}</span></li>`,
|
||||
)
|
||||
.join("");
|
||||
}
|
||||
|
||||
function renderSummary(summary) {
|
||||
summarySection.hidden = false;
|
||||
const items = [
|
||||
{ label: "Total", value: summary.total },
|
||||
{ label: "Criados", value: summary.created },
|
||||
{ label: "Atualizados", value: summary.updated },
|
||||
{ label: "Erros", value: summary.errors },
|
||||
];
|
||||
summaryGrid.innerHTML = items
|
||||
.map(
|
||||
(item) =>
|
||||
`<li><strong>${item.value}</strong><span>${item.label}</span></li>`,
|
||||
)
|
||||
.join("");
|
||||
}
|
||||
|
||||
function statusLabel(status) {
|
||||
const map = { created: "Criado", updated: "Atualizado", error: "Erro" };
|
||||
return map[status] ?? status;
|
||||
}
|
||||
|
||||
function renderResults(results) {
|
||||
if (!results?.length) return;
|
||||
resultsSection.hidden = false;
|
||||
const tbody = resultsTable.querySelector("tbody");
|
||||
tbody.innerHTML = results
|
||||
.map((r) => {
|
||||
const idPart = [r.id, r.externalId].filter(Boolean).join(" / ") || "—";
|
||||
return `<tr>
|
||||
<td>${r.row}</td>
|
||||
<td><span class="badge ${r.status}">${statusLabel(r.status)}</span></td>
|
||||
<td>${escapeHtml(idPart)}</td>
|
||||
<td>${escapeHtml(r.message)}</td>
|
||||
</tr>`;
|
||||
})
|
||||
.join("");
|
||||
}
|
||||
|
||||
function escapeHtml(str) {
|
||||
return String(str)
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">")
|
||||
.replace(/"/g, """);
|
||||
}
|
||||
|
||||
function formatCell(cell) {
|
||||
if (cell === null || cell === undefined) return "";
|
||||
return String(cell);
|
||||
}
|
||||
|
||||
importBtn.addEventListener("click", async () => {
|
||||
if (!selectedFile) return;
|
||||
|
||||
hideAlert();
|
||||
previewSection.hidden = true;
|
||||
summarySection.hidden = true;
|
||||
mappingSection.hidden = true;
|
||||
resultsSection.hidden = true;
|
||||
progress.hidden = false;
|
||||
importBtn.disabled = true;
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append("file", selectedFile);
|
||||
|
||||
try {
|
||||
const res = await fetch("/api/import", {
|
||||
method: "POST",
|
||||
body: formData,
|
||||
});
|
||||
|
||||
const data = await res.json().catch(() => ({}));
|
||||
|
||||
if (!res.ok) {
|
||||
showAlert(data.error ?? `Erro ${res.status} ao importar`);
|
||||
return;
|
||||
}
|
||||
|
||||
renderSummary(data.summary);
|
||||
renderHeaderMapping(data.headerMapping);
|
||||
renderPreview(data.preview);
|
||||
renderResults(data.results);
|
||||
|
||||
const { errors, total } = data.summary ?? {};
|
||||
if (errors === 0) {
|
||||
showAlert(`Importação concluída: ${total} linha(s) processada(s).`, "success");
|
||||
} else {
|
||||
showAlert(
|
||||
`Importação concluída com ${errors} erro(s) em ${total} linha(s).`,
|
||||
"error",
|
||||
);
|
||||
}
|
||||
} catch (err) {
|
||||
showAlert(err instanceof Error ? err.message : "Falha de rede ao importar");
|
||||
} finally {
|
||||
progress.hidden = true;
|
||||
importBtn.disabled = !selectedFile;
|
||||
}
|
||||
});
|
||||
|
||||
async function checkHealth() {
|
||||
try {
|
||||
const res = await fetch("/api/health");
|
||||
const data = await res.json();
|
||||
healthBanner.hidden = false;
|
||||
|
||||
if (data.ok) {
|
||||
healthBanner.className = "card banner-ok";
|
||||
healthMessage.textContent = `Conectado ao Clarizen (usuário: ${data.userId})`;
|
||||
} else {
|
||||
healthBanner.className = "card banner-warn";
|
||||
healthMessage.textContent =
|
||||
data.error ?? "Não foi possível autenticar no Clarizen";
|
||||
}
|
||||
} catch {
|
||||
healthBanner.hidden = false;
|
||||
healthBanner.className = "card banner-warn";
|
||||
healthMessage.textContent =
|
||||
"Servidor indisponível. Inicie com npm start.";
|
||||
}
|
||||
}
|
||||
|
||||
checkHealth();
|
||||
@@ -0,0 +1,99 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="pt-BR">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>ARCO — Importação Excel → Adaptive Work</title>
|
||||
<link rel="stylesheet" href="/styles.css" />
|
||||
</head>
|
||||
<body>
|
||||
<div class="page">
|
||||
<header class="header">
|
||||
<p class="eyebrow">Planview Adaptive Work</p>
|
||||
<h1>Importação Excel → WorkItem</h1>
|
||||
<p class="subtitle">
|
||||
Envie um arquivo <code>.xlsx</code> para criar ou atualizar WorkItems no Clarizen.
|
||||
Os cabeçalhos podem usar o <strong>nome do campo</strong> ou o <strong>rótulo (label)</strong> do Adaptive Work.
|
||||
</p>
|
||||
</header>
|
||||
|
||||
<main class="main">
|
||||
<section class="card" id="health-banner" hidden>
|
||||
<p class="banner-text" id="health-message"></p>
|
||||
</section>
|
||||
|
||||
<section class="card upload-card">
|
||||
<label class="upload-zone" id="drop-zone" for="file-input">
|
||||
<input
|
||||
type="file"
|
||||
id="file-input"
|
||||
name="file"
|
||||
accept=".xlsx,.xls"
|
||||
hidden
|
||||
/>
|
||||
<span class="upload-icon" aria-hidden="true">📄</span>
|
||||
<span class="upload-title">Arraste o Excel aqui ou clique para escolher</span>
|
||||
<span class="upload-hint">Apenas .xlsx — linha 1 = nome ou label do campo</span>
|
||||
<span class="file-name" id="file-name">Nenhum arquivo selecionado</span>
|
||||
</label>
|
||||
|
||||
<div class="actions">
|
||||
<button type="button" class="btn btn-primary" id="import-btn" disabled>
|
||||
Importar
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="progress" id="progress" hidden>
|
||||
<div class="progress-bar"></div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="card" id="alert-section" hidden>
|
||||
<p id="alert-message" class="alert"></p>
|
||||
</section>
|
||||
|
||||
<section class="card" id="summary-section" hidden>
|
||||
<h2>Resumo</h2>
|
||||
<ul class="summary-grid" id="summary-grid"></ul>
|
||||
</section>
|
||||
|
||||
<section class="card" id="mapping-section" hidden>
|
||||
<h2>Colunas reconhecidas</h2>
|
||||
<ul class="mapping-list" id="mapping-list"></ul>
|
||||
</section>
|
||||
|
||||
<section class="card" id="preview-section" hidden>
|
||||
<h2>Prévia dos dados</h2>
|
||||
<div class="table-wrap">
|
||||
<table id="preview-table">
|
||||
<thead></thead>
|
||||
<tbody></tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="card" id="results-section" hidden>
|
||||
<h2>Resultado por linha</h2>
|
||||
<div class="table-wrap">
|
||||
<table id="results-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Linha</th>
|
||||
<th>Status</th>
|
||||
<th>ID / ExternalID</th>
|
||||
<th>Mensagem</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody></tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
</main>
|
||||
|
||||
<footer class="footer">
|
||||
<span>MVP — entidade fixa: WorkItem</span>
|
||||
</footer>
|
||||
</div>
|
||||
<script src="/app.js" type="module"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,358 @@
|
||||
:root {
|
||||
--bg: #f4f6f9;
|
||||
--surface: #ffffff;
|
||||
--text: #1a2332;
|
||||
--muted: #5c6b7a;
|
||||
--border: #e2e8f0;
|
||||
--primary: #2563eb;
|
||||
--primary-hover: #1d4ed8;
|
||||
--success: #059669;
|
||||
--success-bg: #ecfdf5;
|
||||
--warning: #d97706;
|
||||
--warning-bg: #fffbeb;
|
||||
--error: #dc2626;
|
||||
--error-bg: #fef2f2;
|
||||
--updated: #7c3aed;
|
||||
--updated-bg: #f5f3ff;
|
||||
--radius: 12px;
|
||||
--shadow: 0 4px 24px rgba(15, 23, 42, 0.06);
|
||||
font-family:
|
||||
system-ui,
|
||||
-apple-system,
|
||||
"Segoe UI",
|
||||
Roboto,
|
||||
sans-serif;
|
||||
}
|
||||
|
||||
*,
|
||||
*::before,
|
||||
*::after {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
line-height: 1.5;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.page {
|
||||
max-width: 960px;
|
||||
margin: 0 auto;
|
||||
padding: 2rem 1.25rem 3rem;
|
||||
}
|
||||
|
||||
.header {
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.eyebrow {
|
||||
margin: 0 0 0.5rem;
|
||||
font-size: 0.8rem;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.06em;
|
||||
text-transform: uppercase;
|
||||
color: var(--primary);
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
margin: 0 0 0.5rem;
|
||||
font-size: clamp(1.5rem, 4vw, 2rem);
|
||||
font-weight: 700;
|
||||
letter-spacing: -0.02em;
|
||||
}
|
||||
|
||||
.subtitle {
|
||||
margin: 0;
|
||||
color: var(--muted);
|
||||
max-width: 36rem;
|
||||
}
|
||||
|
||||
.subtitle code {
|
||||
font-size: 0.9em;
|
||||
background: var(--border);
|
||||
padding: 0.1em 0.4em;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.main {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1.25rem;
|
||||
}
|
||||
|
||||
.card {
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius);
|
||||
padding: 1.5rem;
|
||||
box-shadow: var(--shadow);
|
||||
}
|
||||
|
||||
.card h2 {
|
||||
margin: 0 0 1rem;
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
|
||||
#health-banner.banner-warn {
|
||||
background: var(--warning-bg);
|
||||
border-color: #fcd34d;
|
||||
}
|
||||
|
||||
#health-banner.banner-ok {
|
||||
background: var(--success-bg);
|
||||
border-color: #6ee7b7;
|
||||
}
|
||||
|
||||
.banner-text {
|
||||
margin: 0;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.upload-zone {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
padding: 2rem 1.5rem;
|
||||
border: 2px dashed var(--border);
|
||||
border-radius: var(--radius);
|
||||
cursor: pointer;
|
||||
transition:
|
||||
border-color 0.15s,
|
||||
background 0.15s;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.upload-zone:hover,
|
||||
.upload-zone.dragover {
|
||||
border-color: var(--primary);
|
||||
background: #eff6ff;
|
||||
}
|
||||
|
||||
.upload-icon {
|
||||
font-size: 2rem;
|
||||
}
|
||||
|
||||
.upload-title {
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.upload-hint,
|
||||
.file-name {
|
||||
font-size: 0.875rem;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.file-name {
|
||||
margin-top: 0.25rem;
|
||||
}
|
||||
|
||||
.actions {
|
||||
margin-top: 1.25rem;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.btn {
|
||||
font: inherit;
|
||||
font-weight: 600;
|
||||
padding: 0.65rem 1.5rem;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
transition: background 0.15s, opacity 0.15s;
|
||||
}
|
||||
|
||||
.btn:disabled {
|
||||
opacity: 0.45;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background: var(--primary);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.btn-primary:hover:not(:disabled) {
|
||||
background: var(--primary-hover);
|
||||
}
|
||||
|
||||
.progress {
|
||||
margin-top: 1rem;
|
||||
height: 4px;
|
||||
background: var(--border);
|
||||
border-radius: 2px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.progress-bar {
|
||||
height: 100%;
|
||||
width: 40%;
|
||||
background: var(--primary);
|
||||
border-radius: 2px;
|
||||
animation: indeterminate 1.2s ease-in-out infinite;
|
||||
}
|
||||
|
||||
@keyframes indeterminate {
|
||||
0% {
|
||||
transform: translateX(-100%);
|
||||
}
|
||||
100% {
|
||||
transform: translateX(350%);
|
||||
}
|
||||
}
|
||||
|
||||
.alert {
|
||||
margin: 0;
|
||||
padding: 0.75rem 1rem;
|
||||
border-radius: 8px;
|
||||
font-size: 0.95rem;
|
||||
}
|
||||
|
||||
.alert.success {
|
||||
background: var(--success-bg);
|
||||
color: var(--success);
|
||||
}
|
||||
|
||||
.alert.error {
|
||||
background: var(--error-bg);
|
||||
color: var(--error);
|
||||
}
|
||||
|
||||
.summary-grid {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.summary-grid li {
|
||||
text-align: center;
|
||||
padding: 0.75rem;
|
||||
background: var(--bg);
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.summary-grid strong {
|
||||
display: block;
|
||||
font-size: 1.5rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.summary-grid span {
|
||||
font-size: 0.8rem;
|
||||
color: var(--muted);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.04em;
|
||||
}
|
||||
|
||||
.mapping-list {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.mapping-list li {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
padding: 0.5rem 0.75rem;
|
||||
background: var(--bg);
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.mapping-list .excel-col {
|
||||
color: var(--text);
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.mapping-list .arrow {
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.mapping-list .api-col {
|
||||
font-family: ui-monospace, monospace;
|
||||
font-size: 0.8rem;
|
||||
color: var(--primary);
|
||||
}
|
||||
|
||||
.table-wrap {
|
||||
overflow-x: auto;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
th,
|
||||
td {
|
||||
padding: 0.6rem 0.75rem;
|
||||
text-align: left;
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
|
||||
th {
|
||||
background: var(--bg);
|
||||
font-weight: 600;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
tbody tr:last-child td {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.badge {
|
||||
display: inline-block;
|
||||
padding: 0.2em 0.55em;
|
||||
border-radius: 999px;
|
||||
font-size: 0.75rem;
|
||||
font-weight: 600;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.03em;
|
||||
}
|
||||
|
||||
.badge.created {
|
||||
background: var(--success-bg);
|
||||
color: var(--success);
|
||||
}
|
||||
|
||||
.badge.updated {
|
||||
background: var(--updated-bg);
|
||||
color: var(--updated);
|
||||
}
|
||||
|
||||
.badge.error {
|
||||
background: var(--error-bg);
|
||||
color: var(--error);
|
||||
}
|
||||
|
||||
.footer {
|
||||
margin-top: 2.5rem;
|
||||
text-align: center;
|
||||
font-size: 0.8rem;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
@media (max-width: 600px) {
|
||||
.page {
|
||||
padding: 1.25rem 1rem 2rem;
|
||||
}
|
||||
|
||||
.card {
|
||||
padding: 1rem;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user