Compare commits
7
Commits
811277d149
..
v0.3.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e143b407c6 | ||
|
|
cfa35036ef | ||
|
|
c67080a3ef | ||
|
|
2ed6c7fca9 | ||
|
|
7104dd0771 | ||
|
|
95e09c6d21 | ||
|
|
d74e8b3fcf |
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import ical, { VEvent } from 'node-ical';
|
||||
import CategoryChart from '@/components/CategoryChart';
|
||||
|
||||
interface PageProps {
|
||||
params: Promise<{
|
||||
@@ -15,7 +16,7 @@ function getIcalText(field: any): string {
|
||||
}
|
||||
|
||||
function getIcalDate(dateValue: any): Date {
|
||||
if (!dateValue) return new Date(0); // Fallback: 01.01.1970, falls kein Datum da ist
|
||||
if (!dateValue) return new Date(0);
|
||||
if (dateValue instanceof Date) return dateValue;
|
||||
return new Date(dateValue);
|
||||
}
|
||||
@@ -28,101 +29,177 @@ function getCategories(categoriesField: any): string[] {
|
||||
return [getIcalText(categoriesField)];
|
||||
}
|
||||
|
||||
type TimeMap = Record<string, number>
|
||||
type TimeMap = Record<string, number>;
|
||||
|
||||
export default async function EvaluationPage({ params }: PageProps) {
|
||||
let times: TimeMap = {};
|
||||
const times: TimeMap = {};
|
||||
let total = 0;
|
||||
|
||||
// get all params
|
||||
const resolvedParams = await params;
|
||||
const daysToFetch = Number(resolvedParams['days']) || 7;
|
||||
|
||||
// get amount of days to fetch
|
||||
const daysToFetch = Number(resolvedParams['days']) || 7; //fallback to 7 days
|
||||
|
||||
// get the URL from the own URL (/evaluation/<ics-link>)
|
||||
const pathSegments = resolvedParams['ical-link'];
|
||||
let rawUrl = pathSegments.join('/');
|
||||
rawUrl = decodeURIComponent(rawUrl);
|
||||
const icalUrl = rawUrl.replace(/^(https?):\/+/, '$1://');
|
||||
|
||||
// fetch the file
|
||||
const response = await fetch(icalUrl, { next: { revalidate: 3600 } });
|
||||
if (!response.ok) {
|
||||
return <div>Fehler beim Laden der Kalenderdaten. Status: {response.status}</div>;
|
||||
return (
|
||||
<div style={{ padding: '1rem', color: '#dc2626', fontFamily: 'system-ui, sans-serif' }}>
|
||||
Fehler beim Laden der Kalenderdaten. Status: {response.status}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const icalData = await response.text();
|
||||
const parsedData = ical.sync.parseICS(icalData);
|
||||
|
||||
// calculate range of time
|
||||
const now = new Date();
|
||||
const cutoffDate = new Date();
|
||||
cutoffDate.setDate(now.getDate() - daysToFetch);
|
||||
|
||||
// filter and sort data (needed: "VEVENT"; time range)
|
||||
const events = Object.values(parsedData)
|
||||
.filter((item): item is VEvent => item !== undefined && item.type === 'VEVENT')
|
||||
.filter((event) => {
|
||||
const startDate = getIcalDate(event.start);
|
||||
return startDate >= cutoffDate && startDate <= now;
|
||||
})
|
||||
.sort((a, b) => getIcalDate(b.start).getTime() - getIcalDate(a.start).getTime()); // newest first
|
||||
|
||||
// read time per categorie
|
||||
events.map((event, index) => {
|
||||
.sort((a, b) => getIcalDate(b.start).getTime() - getIcalDate(a.start).getTime());
|
||||
|
||||
events.forEach((event) => {
|
||||
const startDate = getIcalDate(event.start);
|
||||
const endDate = getIcalDate(event.end);
|
||||
const durationInMs = endDate.getTime() - startDate.getTime();
|
||||
const durationInMinutes = durationInMs / (1000 * 60);
|
||||
const categories = getCategories(event.categories);
|
||||
|
||||
|
||||
categories.forEach((cat) => {
|
||||
times[cat] = (times[cat] || 0) + durationInMinutes
|
||||
})
|
||||
})
|
||||
times[cat] = (times[cat] || 0) + durationInMinutes;
|
||||
});
|
||||
|
||||
total += durationInMinutes;
|
||||
});
|
||||
|
||||
return (
|
||||
<main>
|
||||
<h1>Meine Kalender-Events</h1>
|
||||
|
||||
<section>
|
||||
<h2>Gesamtdauer pro Kategorie</h2>
|
||||
<main
|
||||
style={{
|
||||
width: '100%',
|
||||
maxWidth: '800px',
|
||||
margin: '0 auto',
|
||||
padding: '1rem',
|
||||
boxSizing: 'border-box',
|
||||
fontFamily: 'system-ui, sans-serif',
|
||||
}}
|
||||
>
|
||||
<section style={{ marginBottom: '2.5rem' }}>
|
||||
<h2 style={{ fontSize: '1.25rem', fontWeight: 600, marginBottom: '1rem' }}>Gesamtdauer pro Kategorie</h2>
|
||||
{Object.keys(times).length === 0 ? (
|
||||
<p>Keine Zeiten erfasst.</p>
|
||||
) : (
|
||||
<ul>
|
||||
{Object.entries(times).map(([category, minutes]) => (
|
||||
<li key={category}>
|
||||
<strong>{category}:</strong> {Math.floor(minutes / 60)} Std. {minutes % 60} Min. ({minutes} Min. gesamt)
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
<>
|
||||
<CategoryChart times={times} />
|
||||
|
||||
{/* Responsive Container für die Tabelle */}
|
||||
<div style={{ width: '100%', overflowX: 'auto', marginTop: '1.5rem', WebkitOverflowScrolling: 'touch' }}>
|
||||
<table style={{ width: '100%', minWidth: '480px', borderCollapse: 'collapse', textAlign: 'left' }}>
|
||||
<thead>
|
||||
<tr style={{ borderBottom: '2px solid #e5e7eb' }}>
|
||||
<th style={{ padding: '0.5rem' }}>Kategorie</th>
|
||||
<th style={{ padding: '0.5rem' }}>Dauer</th>
|
||||
<th style={{ padding: '0.5rem' }}>Anteil</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{Object.entries(times).map(([category, minutes]) => (
|
||||
<tr key={category} style={{ borderBottom: '1px solid #e5e7eb' }}>
|
||||
<td style={{ padding: '0.5rem' }}>{category}</td>
|
||||
<td style={{ padding: '0.5rem', whiteSpace: 'nowrap' }}>
|
||||
{Math.floor(minutes / 60)} Std. {Math.round(minutes % 60)} Min. ({Math.round(minutes)} Min. gesamt)
|
||||
</td>
|
||||
<td style={{ padding: '0.5rem' }}>
|
||||
{total > 0 ? Math.round((minutes / total) * 1000) / 10 : 0}%
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr style={{ fontWeight: 'bold' }}>
|
||||
<td style={{ padding: '0.5rem' }}>Total</td>
|
||||
<td style={{ padding: '0.5rem', whiteSpace: 'nowrap' }}>
|
||||
{Math.floor(total / 60)} Std. {Math.round(total % 60)} Min. ({Math.round(total)} Min. gesamt)
|
||||
</td>
|
||||
<td style={{ padding: '0.5rem' }}>100%</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</section>
|
||||
|
||||
|
||||
<h2 style={{ fontSize: '1.25rem', fontWeight: 600, marginBottom: '1rem' }}>Termine ({events.length})</h2>
|
||||
{events.length === 0 ? (
|
||||
<p>Keine Termine gefunden.</p>
|
||||
) : (
|
||||
<ul style={{ display: 'flex', flexDirection: 'column', gap: '1rem' }}>
|
||||
<ul style={{ display: 'flex', flexDirection: 'column', gap: '1rem', padding: 0, listStyle: 'none' }}>
|
||||
{events.map((event, index) => {
|
||||
const startDate = getIcalDate(event.start);
|
||||
const endDate = getIcalDate(event.end);
|
||||
|
||||
return (
|
||||
<li key={event.uid || index} style={{ border: '1px solid #ccc', padding: '1rem', borderRadius: '8px' }}>
|
||||
<h2>{getIcalText(event.summary)}</h2>
|
||||
<p>
|
||||
<li
|
||||
key={event.uid || index}
|
||||
style={{
|
||||
border: '1px solid #ccc',
|
||||
padding: '1rem',
|
||||
borderRadius: '8px',
|
||||
wordBreak: 'break-word', // Verhindert Überlaufen von sehr langem Text/URLs
|
||||
}}
|
||||
>
|
||||
<h3 style={{ margin: '0 0 0.5rem 0', wordBreak: 'break-word' }}>{getIcalText(event.summary)}</h3>
|
||||
<p style={{ margin: '0 0 0.5rem 0' }}>
|
||||
<strong>Start:</strong> {startDate.toLocaleString('de-DE')} <br />
|
||||
<strong>Ende:</strong> {endDate.toLocaleString('de-DE')}
|
||||
</p>
|
||||
{event.location && (
|
||||
<p><strong>Ort:</strong> {getIcalText(event.location)}</p>
|
||||
<p style={{ margin: '0 0 0.5rem 0' }}>
|
||||
<strong>Ort:</strong> {getIcalText(event.location)}
|
||||
</p>
|
||||
)}
|
||||
{event.description && (
|
||||
<p><strong>Beschreibung:</strong> {getIcalText(event.description)}</p>
|
||||
<p style={{ margin: '0 0 0.5rem 0', whiteSpace: 'pre-line' }}>
|
||||
<strong>Beschreibung:</strong> {getIcalText(event.description)}
|
||||
</p>
|
||||
)}
|
||||
{event.categories && (
|
||||
<p><strong>Kategorien:</strong> {getIcalText(event.categories)}</p>
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
flexWrap: 'wrap',
|
||||
alignItems: 'center',
|
||||
gap: '0.35rem',
|
||||
marginTop: '0.5rem',
|
||||
}}
|
||||
>
|
||||
<strong>Kategorien: </strong>
|
||||
{getCategories(event.categories).map((cat, i) => (
|
||||
<span
|
||||
key={i}
|
||||
style={{
|
||||
display: 'inline-block',
|
||||
background: '#white',
|
||||
border: '1px solid #e5e7eb',
|
||||
color: 'black',
|
||||
padding: '2px 8px',
|
||||
borderRadius: '4px',
|
||||
fontSize: '0.85rem',
|
||||
}}
|
||||
>
|
||||
{cat}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</li>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
'use client';
|
||||
|
||||
import { Chart as ChartJS, ArcElement, Tooltip, Legend } from 'chart.js';
|
||||
import { Doughnut } from 'react-chartjs-2';
|
||||
|
||||
// Chart.js Module registrieren (wichtig in v3/v4)
|
||||
ChartJS.register(ArcElement, Tooltip, Legend);
|
||||
|
||||
interface CategoryChartProps {
|
||||
times: Record<string, number>;
|
||||
}
|
||||
|
||||
export default function CategoryChart({ times }: CategoryChartProps) {
|
||||
const labels = Object.keys(times);
|
||||
const dataValues = Object.values(times);
|
||||
|
||||
const data = {
|
||||
labels,
|
||||
datasets: [
|
||||
{
|
||||
label: 'Dauer (in Minuten)',
|
||||
data: dataValues,
|
||||
backgroundColor: [
|
||||
'#3b82f6', // Blau
|
||||
'#10b981', // Grün
|
||||
'#f59e0b', // Orange
|
||||
'#ef4444', // Rot
|
||||
'#8b5cf6', // Violett
|
||||
'#ec4899', // Pink
|
||||
'#64748b', // Grau
|
||||
],
|
||||
borderColor: '#ffffff',
|
||||
borderWidth: 2,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const options = {
|
||||
responsive: true,
|
||||
plugins: {
|
||||
legend: {
|
||||
position: 'bottom' as const,
|
||||
},
|
||||
tooltip: {
|
||||
callbacks: {
|
||||
label: (context: any) => {
|
||||
const minutes = context.raw || 0;
|
||||
const hours = Math.floor(minutes / 60);
|
||||
const remainingMins = Math.round(minutes % 60);
|
||||
return ` ${context.label}: ${hours} Std. ${remainingMins} Min. (${minutes} Min.)`;
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
return (
|
||||
<div style={{ maxWidth: '360px', margin: '1.5rem auto' }}>
|
||||
<Doughnut data={data} options={options} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -9,9 +9,11 @@
|
||||
"lint": "eslint"
|
||||
},
|
||||
"dependencies": {
|
||||
"chart.js": "^4.5.1",
|
||||
"next": "16.2.12",
|
||||
"node-ical": "^0.27.1",
|
||||
"react": "19.2.4",
|
||||
"react-chartjs-2": "^5.3.1",
|
||||
"react-dom": "19.2.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
Generated
+30
@@ -8,6 +8,9 @@ importers:
|
||||
|
||||
.:
|
||||
dependencies:
|
||||
chart.js:
|
||||
specifier: ^4.5.1
|
||||
version: 4.5.1
|
||||
next:
|
||||
specifier: 16.2.12
|
||||
version: 16.2.12(@babel/core@7.29.7(supports-color@7.2.0))(react-dom@19.2.4(react@19.2.4))(react@19.2.4)
|
||||
@@ -17,6 +20,9 @@ importers:
|
||||
react:
|
||||
specifier: 19.2.4
|
||||
version: 19.2.4
|
||||
react-chartjs-2:
|
||||
specifier: ^5.3.1
|
||||
version: 5.3.1(chart.js@4.5.1)(react@19.2.4)
|
||||
react-dom:
|
||||
specifier: 19.2.4
|
||||
version: 19.2.4(react@19.2.4)
|
||||
@@ -358,6 +364,9 @@ packages:
|
||||
'@jridgewell/trace-mapping@0.3.31':
|
||||
resolution: {integrity: sha512-zzNR+SdQSDJzc8joaeP8QQoCQr8NuYx2dIIytl1QeBEZHJ9uW6hebsrYgbz8hJwUQao3TWCMtmfV8Nu1twOLAw==}
|
||||
|
||||
'@kurkle/color@0.3.4':
|
||||
resolution: {integrity: sha512-M5UknZPHRu3DEDWoipU6sE8PdkZ6Z/S+v4dD+Ke8IaNlpdSQah50lz1KtcFBa2vsdOnwbbnxJwVM4wty6udA5w==}
|
||||
|
||||
'@napi-rs/wasm-runtime@1.2.2':
|
||||
resolution: {integrity: sha512-JfB4kuJQjaoHuCTseIINHtHWeJnvgEcxjwA5t/Y00ZgaOO1Crz3fjT/p8kT28zA/Caz7oiUMn3d6H2yOVCVwuw==}
|
||||
engines: {node: ^20.19.0 || ^22.13.0 || >=23.5.0}
|
||||
@@ -865,6 +874,10 @@ packages:
|
||||
resolution: {integrity: sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==}
|
||||
engines: {node: '>=10'}
|
||||
|
||||
chart.js@4.5.1:
|
||||
resolution: {integrity: sha512-GIjfiT9dbmHRiYi6Nl2yFCq7kkwdkp1W/lp2J99rX0yo9tgJGn3lKQATztIjb5tVtevcBtIdICNWqlq5+E8/Pw==}
|
||||
engines: {pnpm: '>=8'}
|
||||
|
||||
client-only@0.0.1:
|
||||
resolution: {integrity: sha512-IV3Ou0jSMzZrd3pZ48nLkT9DA7Ag1pnPzaiQhpW7c3RbcqqzvzzVu+L8gfqMp/8IM2MQtSiqaCxrrcfu8I8rMA==}
|
||||
|
||||
@@ -1709,6 +1722,12 @@ packages:
|
||||
queue-microtask@1.2.3:
|
||||
resolution: {integrity: sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==}
|
||||
|
||||
react-chartjs-2@5.3.1:
|
||||
resolution: {integrity: sha512-h5IPXKg9EXpjoBzUfyWJvllMjG2mQ4EiuHQFhms/AjUm0XSZHhyRy2xVmLXHKrtcdrPO4mnGqRtYoD0vp95A0A==}
|
||||
peerDependencies:
|
||||
chart.js: ^4.1.1
|
||||
react: ^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0
|
||||
|
||||
react-dom@19.2.4:
|
||||
resolution: {integrity: sha512-AXJdLo8kgMbimY95O2aKQqsz2iWi9jMgKJhRBAxECE4IFxfcazB2LmzloIoibJI3C12IlY20+KFaLv+71bUJeQ==}
|
||||
peerDependencies:
|
||||
@@ -2309,6 +2328,8 @@ snapshots:
|
||||
'@jridgewell/resolve-uri': 3.1.2
|
||||
'@jridgewell/sourcemap-codec': 1.5.5
|
||||
|
||||
'@kurkle/color@0.3.4': {}
|
||||
|
||||
'@napi-rs/wasm-runtime@1.2.2(@emnapi/core@1.10.0)(@emnapi/runtime@1.10.0)':
|
||||
dependencies:
|
||||
'@emnapi/core': 1.10.0
|
||||
@@ -2772,6 +2793,10 @@ snapshots:
|
||||
ansi-styles: 4.3.0
|
||||
supports-color: 7.2.0
|
||||
|
||||
chart.js@4.5.1:
|
||||
dependencies:
|
||||
'@kurkle/color': 0.3.4
|
||||
|
||||
client-only@0.0.1: {}
|
||||
|
||||
color-convert@2.0.1:
|
||||
@@ -3752,6 +3777,11 @@ snapshots:
|
||||
|
||||
queue-microtask@1.2.3: {}
|
||||
|
||||
react-chartjs-2@5.3.1(chart.js@4.5.1)(react@19.2.4):
|
||||
dependencies:
|
||||
chart.js: 4.5.1
|
||||
react: 19.2.4
|
||||
|
||||
react-dom@19.2.4(react@19.2.4):
|
||||
dependencies:
|
||||
react: 19.2.4
|
||||
|
||||
Reference in new issue
Block a user