First fully working model with data from 2025 and 2026

This commit is contained in:
2026-07-16 07:00:42 +02:00
parent 78fed1be3e
commit 27dbd344d6
12 changed files with 1196 additions and 0 deletions
+248
View File
@@ -0,0 +1,248 @@
(() => {
const weeksEl = document.querySelector("#weeks");
if (!weeksEl) return;
const appShell = document.querySelector(".app-shell");
const today = fromISO(appShell.dataset.today);
const saveUrl = appShell.dataset.saveUrl;
const statusUrl = appShell.dataset.statusUrl;
const deleteUrl = appShell.dataset.deleteUrl;
const savedChoices = JSON.parse(document.querySelector("#saved-choices").textContent);
const savedStatuses = JSON.parse(document.querySelector("#saved-statuses").textContent);
const monthLabel = document.querySelector("#visible-month");
const selectedLabel = document.querySelector("#selected-date");
const amountControls = document.querySelector("#amount-controls");
const customAmount = document.querySelector("#custom-amount");
const saveStatus = document.querySelector("#save-status");
const dayFormatter = new Intl.DateTimeFormat(undefined, { weekday: "long", month: "long", day: "numeric", year: "numeric" });
const monthFormatter = new Intl.DateTimeFormat(undefined, { month: "long", year: "numeric" });
let firstSunday = startOfWeek(addDays(today, -14));
let lastSunday = addDays(firstSunday, 7 * 13);
let selectedButton = null;
let loading = false;
let previousScrollTop = 0;
let lastExpansionAt = 0;
function fromISO(value) {
const [year, month, day] = value.split("-").map(Number);
return new Date(year, month - 1, day, 12);
}
function addDays(date, count) {
const next = new Date(date);
next.setDate(next.getDate() + count);
return next;
}
function startOfWeek(date) { return addDays(date, -date.getDay()); }
function iso(date) {
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, "0");
const day = String(date.getDate()).padStart(2, "0");
return `${year}-${month}-${day}`;
}
function createWeek(sunday) {
const row = document.createElement("div");
row.className = "week";
row.dataset.sunday = iso(sunday);
row.setAttribute("role", "row");
for (let index = 0; index < 7; index += 1) {
const date = addDays(sunday, index);
const button = document.createElement("button");
button.type = "button";
button.className = `day${index === 0 || index === 6 ? " is-weekend" : ""}${iso(date) === iso(today) ? " is-today" : ""}`;
button.dataset.date = iso(date);
button.innerHTML = `<span class="day-number">${date.getDate()}</span><span class="day-amount"></span>`;
button.setAttribute("role", "gridcell");
button.setAttribute("aria-label", dayFormatter.format(date));
if (iso(date) === iso(today)) button.setAttribute("aria-current", "date");
applySavedChoice(button);
applySavedStatus(button);
button.addEventListener("click", () => selectDate(button, date));
row.appendChild(button);
}
return row;
}
function appendWeeks(count) {
const fragment = document.createDocumentFragment();
for (let i = 0; i < count; i += 1) {
lastSunday = addDays(lastSunday, 7);
fragment.appendChild(createWeek(lastSunday));
}
weeksEl.appendChild(fragment);
}
function prependWeeks(count) {
const oldHeight = weeksEl.scrollHeight;
const fragment = document.createDocumentFragment();
for (let i = count; i >= 1; i -= 1) fragment.appendChild(createWeek(addDays(firstSunday, -7 * i)));
firstSunday = addDays(firstSunday, -7 * count);
weeksEl.prepend(fragment);
weeksEl.scrollTop += weeksEl.scrollHeight - oldHeight;
}
function selectDate(button, date) {
selectedButton?.classList.remove("is-selected");
selectedButton?.removeAttribute("aria-selected");
selectedButton = button;
button.classList.add("is-selected");
button.setAttribute("aria-selected", "true");
selectedLabel.textContent = dayFormatter.format(date);
amountControls.hidden = false;
saveStatus.textContent = savedChoices[iso(date)] === undefined ? "Choose an amount." : `${formatAmount(savedChoices[iso(date)])} saved.`;
customAmount.value = "";
updateStatusButtons(savedStatuses[iso(date)] || "worked");
}
function formatAmount(cents) {
return new Intl.NumberFormat(undefined, { style: "currency", currency: "EUR" }).format(cents / 100);
}
function applySavedChoice(button) {
const cents = savedChoices[button.dataset.date];
button.classList.toggle("has-amount", cents !== undefined);
const amountLabel = button.querySelector(".day-amount");
if (amountLabel) amountLabel.textContent = cents === undefined ? "" : formatAmount(cents);
}
function applySavedStatus(button) {
const status = savedStatuses[button.dataset.date] || "worked";
button.classList.toggle("is-vacation", status === "vacation");
button.classList.toggle("is-sick", status === "sick");
}
function updateStatusButtons(status) {
document.querySelectorAll("[data-status]").forEach((button) => {
const selected = button.dataset.status === status;
button.classList.toggle("is-active", selected);
button.setAttribute("aria-pressed", String(selected));
});
}
async function saveAmount(amount) {
if (!selectedButton) return;
saveStatus.textContent = "Saving…";
try {
const response = await fetch(saveUrl, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ date: selectedButton.dataset.date, amount }),
});
const result = await response.json();
if (!response.ok) throw new Error(result.error || "Could not save the amount.");
savedChoices[result.date] = result.amount_cents;
applySavedChoice(selectedButton);
saveStatus.textContent = `${formatAmount(result.amount_cents)} saved.`;
} catch (error) {
saveStatus.textContent = error.message;
}
}
async function saveDayStatus(status) {
if (!selectedButton) return;
saveStatus.textContent = "Saving…";
try {
const response = await fetch(statusUrl, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ date: selectedButton.dataset.date, status }),
});
const result = await response.json();
if (!response.ok) throw new Error(result.error || "Could not save the day status.");
savedStatuses[result.date] = result.status;
applySavedStatus(selectedButton);
updateStatusButtons(result.status);
saveStatus.textContent = `${result.status[0].toUpperCase()}${result.status.slice(1)} saved.`;
} catch (error) {
saveStatus.textContent = error.message;
}
}
async function deleteDateData() {
if (!selectedButton) return;
const selectedDate = selectedButton.dataset.date;
if (!window.confirm(`Delete all saved data for ${dayFormatter.format(fromISO(selectedDate))}?`)) return;
saveStatus.textContent = "Deleting…";
try {
const response = await fetch(deleteUrl, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ date: selectedDate }),
});
const result = await response.json();
if (!response.ok) throw new Error(result.error || "Could not delete the date data.");
delete savedChoices[result.date];
delete savedStatuses[result.date];
applySavedChoice(selectedButton);
applySavedStatus(selectedButton);
updateStatusButtons("worked");
customAmount.value = "";
saveStatus.textContent = "All saved data for this date was deleted.";
} catch (error) {
saveStatus.textContent = error.message;
}
}
function updateMonth() {
const rows = [...weeksEl.querySelectorAll(".week")];
const marker = weeksEl.getBoundingClientRect().top + Math.min(100, weeksEl.clientHeight / 3);
const visible = rows.find((row) => row.getBoundingClientRect().bottom >= marker) || rows[0];
if (visible) monthLabel.textContent = monthFormatter.format(addDays(fromISO(visible.dataset.sunday), 3));
}
for (let i = 0; i < 14; i += 1) weeksEl.appendChild(createWeek(addDays(firstSunday, i * 7)));
lastSunday = addDays(firstSunday, 13 * 7);
updateMonth();
weeksEl.addEventListener("scroll", () => {
if (loading) return;
const currentScrollTop = weeksEl.scrollTop;
const direction = currentScrollTop > previousScrollTop ? "down" : "up";
previousScrollTop = currentScrollTop;
loading = true;
requestAnimationFrame(() => {
const now = Date.now();
const canExpand = now - lastExpansionAt > 250;
if (canExpand && direction === "up" && weeksEl.scrollTop < 80) {
prependWeeks(3);
previousScrollTop = weeksEl.scrollTop;
lastExpansionAt = now;
} else if (canExpand && direction === "down" && weeksEl.scrollHeight - weeksEl.scrollTop - weeksEl.clientHeight < 160) {
appendWeeks(3);
lastExpansionAt = now;
}
updateMonth();
loading = false;
});
}, { passive: true });
document.querySelectorAll("[data-today-button]").forEach((button) => {
button.addEventListener("click", () => {
const target = weeksEl.querySelector(`[data-date="${iso(today)}"]`);
if (target) {
target.scrollIntoView({ block: "center", behavior: "smooth" });
selectDate(target, today);
} else {
window.location.reload();
}
});
});
document.querySelectorAll("[data-amount]").forEach((button) => {
button.addEventListener("click", () => saveAmount(button.dataset.amount));
});
document.querySelectorAll("[data-status]").forEach((button) => {
button.addEventListener("click", () => saveDayStatus(button.dataset.status));
});
document.querySelector("#custom-amount-form").addEventListener("submit", (event) => {
event.preventDefault();
if (customAmount.reportValidity()) saveAmount(customAmount.value);
});
document.querySelector("#delete-date-button").addEventListener("click", deleteDateData);
})();
+256
View File
@@ -0,0 +1,256 @@
:root {
color-scheme: light;
--paper: #f6f4ef;
--ink: #17211d;
--muted: #6c756f;
--line: #dcded8;
--accent: #d7603e;
--green: #274e42;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
background: var(--paper);
color: var(--ink);
font-family: ui-rounded, "SF Pro Rounded", "SF Pro Display", -apple-system, BlinkMacSystemFont, sans-serif;
-webkit-font-smoothing: antialiased;
}
button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
.eyebrow {
margin: 0 0 4px;
color: var(--accent);
font-size: 11px;
font-weight: 800;
letter-spacing: .11em;
text-transform: uppercase;
}
.login-page {
background: var(--green);
min-height: 100dvh;
}
.login-shell {
display: grid;
min-height: 100dvh;
place-items: center;
padding: max(24px, env(safe-area-inset-top)) 22px max(24px, env(safe-area-inset-bottom));
}
.login-card {
width: min(100%, 390px);
padding: 32px 24px 28px;
border-radius: 26px;
background: var(--paper);
box-shadow: 0 24px 70px #0b1c174d;
}
.brand-mark {
display: grid;
width: 52px;
height: 52px;
margin-bottom: 24px;
place-items: center;
border-radius: 16px;
background: var(--accent);
color: white;
font-size: 20px;
font-weight: 850;
}
.login-card h1 { margin: 0; font-size: 32px; letter-spacing: -.04em; }
.login-copy { margin: 8px 0 24px; color: var(--muted); }
.login-card label { display: block; margin: 16px 0 7px; font-size: 13px; font-weight: 750; }
.login-card input {
width: 100%;
min-height: 50px;
padding: 0 14px;
border: 1px solid var(--line);
border-radius: 13px;
background: white;
color: var(--ink);
font-size: 16px;
outline: none;
}
.login-card input:focus { border-color: var(--green); box-shadow: 0 0 0 3px #274e421f; }
.login-card button {
width: 100%;
min-height: 52px;
margin-top: 24px;
border: 0;
border-radius: 14px;
background: var(--green);
color: white;
font-weight: 800;
}
.form-error { padding: 11px 12px; border-radius: 10px; background: #f8ded7; color: #8b2e18; font-size: 13px; }
.app-shell { height: 100dvh; overflow: hidden; }
.calendar-panel { height: 70dvh; display: flex; flex-direction: column; }
.calendar-header {
display: flex;
flex: 0 0 auto;
align-items: center;
justify-content: space-between;
padding: max(14px, env(safe-area-inset-top)) 16px 10px;
}
.calendar-header h1 { margin: 0; font-size: 25px; letter-spacing: -.035em; }
.header-actions { display: flex; align-items: center; gap: 7px; }
.header-actions form { margin: 0; }
.logout-button, .today-button {
min-height: 36px;
padding: 0 13px;
border: 1px solid var(--line);
border-radius: 999px;
background: transparent;
color: var(--ink);
font-size: 12px;
font-weight: 750;
}
.weekday-row, .week { display: grid; grid-template-columns: repeat(7, 1fr); }
.weekday-row { flex: 0 0 auto; padding: 7px 9px; border-bottom: 1px solid var(--line); }
.weekday-row span { color: var(--muted); font-size: 10px; font-weight: 800; text-align: center; text-transform: uppercase; }
.weeks { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior-y: contain; scroll-behavior: auto; scroll-snap-type: y proximity; -webkit-overflow-scrolling: touch; }
.week { min-height: 76px; border-bottom: 1px solid var(--line); scroll-snap-align: start; }
.day {
position: relative;
display: flex;
min-width: 0;
padding: 12px 2px;
flex-direction: column;
align-items: center;
justify-content: center;
border: 0;
border-right: 1px solid var(--line);
background: transparent;
color: var(--ink);
font-size: 16px;
font-weight: 650;
}
.day-number { line-height: 1; }
.day-amount { min-height: 12px; margin-top: 6px; font-size: 9px; font-weight: 800; letter-spacing: -.02em; }
.day.has-amount { background: #ccebd6; color: #173d2c; }
.day.has-amount.is-weekend { color: #9b432d; }
.day.is-vacation, .day.has-amount.is-vacation { background: #f8d5ad; color: #643912; }
.day.is-sick, .day.has-amount.is-sick { background: #fff0a8; color: #594a09; }
.day:last-child { border-right: 0; }
.day.is-weekend { color: var(--accent); }
.day.is-today::after { content: ""; position: absolute; bottom: 10px; width: 5px; height: 5px; border-radius: 50%; background: var(--accent); }
.day.is-selected, .day.has-amount.is-selected, .day.is-vacation.is-selected, .day.is-sick.is-selected { background: var(--green); color: white; }
.day.is-selected::after { background: white; }
.day:active { background: #e8e9e3; }
.day.is-selected:active { background: var(--green); }
.detail-panel {
height: 30dvh;
padding: 14px 16px max(10px, env(safe-area-inset-bottom));
border-top: 1px solid #355e51;
background: var(--green);
color: white;
}
.detail-panel .eyebrow { color: #f19c7f; }
.selected-date { margin: 4px 0 2px; font-family: ui-serif, Georgia, serif; font-size: clamp(21px, 6vw, 30px); line-height: 1.05; letter-spacing: -.03em; }
.today-button { border-color: #6d897f; color: white; }
.calendar-header .today-button { border-color: var(--green); color: var(--green); }
.amount-controls[hidden] { display: none; }
.status-options { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.amount-row { display: grid; grid-template-columns: auto auto auto minmax(0, 1fr); gap: 5px; margin-top: 7px; }
.amount-row > button, .status-options button, .custom-amount-form > button {
min-height: 34px;
border: 1px solid #789187;
border-radius: 10px;
background: #345f51;
color: white;
font-size: 12px;
font-weight: 800;
}
.status-options button { background: transparent; }
.status-options button.is-active { border-color: white; background: white; color: var(--green); }
.amount-row > button { padding: 0 8px; }
.custom-amount-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 5px; align-items: center; }
.amount-input { display: flex; height: 34px; align-items: center; border-radius: 10px; background: white; color: var(--ink); overflow: hidden; }
.amount-input span { padding-left: 9px; font-size: 13px; }
.amount-input input { width: 100%; min-width: 0; height: 100%; padding: 0 8px 0 3px; border: 0; outline: 0; background: transparent; color: var(--ink); font-size: 16px; }
.custom-amount-form > button { padding: 0 13px; }
.report-row { display: flex; justify-content: flex-end; margin-bottom: 7px; }
.delete-row { display: flex; justify-content: flex-end; margin-top: 7px; }
.report-button {
display: flex;
min-height: 32px;
padding: 0 14px;
align-items: center;
justify-content: center;
border: 1px solid #9bb1a9;
border-radius: 10px;
background: #466f61;
color: white;
font-size: 11px;
font-weight: 800;
text-decoration: none;
}
.report-row .report-button { min-width: 92px; }
.delete-row button {
min-height: 28px;
padding: 0 10px;
border: 1px solid #8e6f66;
border-radius: 8px;
background: transparent;
color: #d9b1a5;
font-size: 10px;
font-weight: 650;
}
.delete-row button:active { background: #623d33; color: white; }
.save-status { min-height: 14px; margin: 5px 0 0; color: #c9d6d1; font-size: 10px; }
.report-page { min-height: 100dvh; background: var(--paper); }
.report-shell { width: min(100%, 560px); min-height: 100dvh; margin: 0 auto; padding: max(14px, env(safe-area-inset-top)) 18px max(24px, env(safe-area-inset-bottom)); }
.report-header { display: flex; align-items: center; justify-content: space-between; }
.report-header form { margin: 0; }
.back-button { color: var(--green); font-size: 13px; font-weight: 800; text-decoration: none; }
.report-intro { padding: 36px 2px 22px; }
.report-intro h1 { margin: 0; font-family: ui-serif, Georgia, serif; font-size: 38px; letter-spacing: -.04em; }
.report-intro > p:last-child { margin: 8px 0 0; color: var(--muted); font-size: 14px; }
.year-navigation { display: grid; grid-template-columns: 42px 1fr 42px; gap: 8px; align-items: center; }
.year-navigation h1 { text-align: center; }
.year-navigation a {
display: grid;
width: 42px;
height: 42px;
place-items: center;
border: 1px solid var(--line);
border-radius: 50%;
background: white;
color: var(--green);
font-size: 20px;
font-weight: 800;
text-decoration: none;
}
.year-navigation a:active { background: #e8e9e3; }
.report-categories { display: grid; gap: 10px; }
.report-card { padding: 18px; border: 1px solid var(--line); border-radius: 18px; }
.report-card--worked { background: white; }
.report-card--vacation { background: #f8d5ad; border-color: #efbd84; }
.report-card--sick { background: #fff0a8; border-color: #ead66f; }
.category-title { display: flex; align-items: center; gap: 8px; }
.category-title h2 { margin: 0; font-size: 14px; }
.category-swatch { width: 10px; height: 10px; border-radius: 50%; background: var(--paper); border: 1px solid var(--line); }
.report-card--vacation .category-swatch { background: #e98b3d; border: 0; }
.report-card--sick .category-swatch { background: #d8b91f; border: 0; }
.category-amount { margin: 14px 0 2px; font-family: ui-serif, Georgia, serif; font-size: 30px; font-weight: 700; letter-spacing: -.03em; }
.category-days { margin: 0; color: #59635e; font-size: 12px; }
.report-total { display: flex; align-items: end; justify-content: space-between; margin-top: 16px; padding: 20px; border-radius: 18px; background: var(--green); color: white; }
.report-total .eyebrow { color: #f19c7f; }
.total-amount { margin: 4px 0 0; font-family: ui-serif, Georgia, serif; font-size: 32px; }
.total-days { margin: 0 0 5px; color: #c9d6d1; font-size: 12px; }
@media (min-width: 700px) {
.app-shell { width: min(100%, 520px); margin: 0 auto; border-inline: 1px solid var(--line); }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }