diff --git a/app/evaluation/[days]/[...ical-link]/page.tsx b/app/evaluation/[days]/[...ical-link]/page.tsx new file mode 100644 index 0000000..e717b0c --- /dev/null +++ b/app/evaluation/[days]/[...ical-link]/page.tsx @@ -0,0 +1,211 @@ +import ical, { VEvent } from 'node-ical'; +import CategoryChart from '@/components/CategoryChart'; + +interface PageProps { + params: Promise<{ + 'days': string; + 'ical-link': string[]; + }>; +} + +function getIcalText(field: any): string { + if (!field) return ''; + if (typeof field === 'string') return field; + if (typeof field === 'object' && 'val' in field) return field.val as string; + return String(field); +} + +function getIcalDate(dateValue: any): Date { + if (!dateValue) return new Date(0); + if (dateValue instanceof Date) return dateValue; + return new Date(dateValue); +} + +function getCategories(categoriesField: any): string[] { + if (!categoriesField) return []; + if (Array.isArray(categoriesField)) { + return categoriesField.map((cat) => getIcalText(cat)); + } + return [getIcalText(categoriesField)]; +} + +type TimeMap = Record; + +export default async function EvaluationPage({ params }: PageProps) { + const times: TimeMap = {}; + let total = 0; + + const resolvedParams = await params; + const daysToFetch = Number(resolvedParams['days']) || 7; + + const pathSegments = resolvedParams['ical-link']; + let rawUrl = pathSegments.join('/'); + rawUrl = decodeURIComponent(rawUrl); + const icalUrl = rawUrl.replace(/^(https?):\/+/, '$1://'); + + const response = await fetch(icalUrl, { next: { revalidate: 3600 } }); + if (!response.ok) { + return ( +
+ Fehler beim Laden der Kalenderdaten. Status: {response.status} +
+ ); + } + + const icalData = await response.text(); + const parsedData = ical.sync.parseICS(icalData); + + const now = new Date(); + const cutoffDate = new Date(); + cutoffDate.setDate(now.getDate() - daysToFetch); + + 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()); + + 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; + }); + + total += durationInMinutes; + }); + + return ( +
+
+

Gesamtdauer pro Kategorie

+ {Object.keys(times).length === 0 ? ( +

Keine Zeiten erfasst.

+ ) : ( + <> + + + {/* Responsive Container für die Tabelle */} +
+ + + + + + + + + + {Object.entries(times).map(([category, minutes]) => ( + + + + + + ))} + + + + + + + + +
KategorieDauerAnteil
{category} + {Math.floor(minutes / 60)} Std. {Math.round(minutes % 60)} Min. ({Math.round(minutes)} Min. gesamt) + + {total > 0 ? Math.round((minutes / total) * 1000) / 10 : 0}% +
Total + {Math.floor(total / 60)} Std. {Math.round(total % 60)} Min. ({Math.round(total)} Min. gesamt) + 100%
+
+ + )} +
+ +

Termine ({events.length})

+ {events.length === 0 ? ( +

Keine Termine gefunden.

+ ) : ( + + )} +
+ ); +} \ No newline at end of file diff --git a/components/CategoryChart.tsx b/components/CategoryChart.tsx new file mode 100644 index 0000000..2af171e --- /dev/null +++ b/components/CategoryChart.tsx @@ -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; +} + +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 ( +
+ +
+ ); +} \ No newline at end of file diff --git a/package.json b/package.json index a1874f3..060069d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "temp-next", - "version": "0.1.0", + "version": "0.3.0", "private": true, "scripts": { "dev": "next dev", @@ -9,8 +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": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 973b73b..81aeb6a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,12 +8,21 @@ 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) + node-ical: + specifier: ^0.27.1 + version: 0.27.1 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) @@ -355,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} @@ -862,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==} @@ -1598,6 +1614,10 @@ packages: resolution: {integrity: sha512-kXs9Go0cah0qHVV2v389IXQLdLCeE1xfFtjOAF+iobu0OIoG1pje8At2vMHyaPMiPMnG/LWP50twML21eMcAag==} engines: {node: '>= 0.4'} + node-ical@0.27.1: + resolution: {integrity: sha512-5fiKuh/h2HrWKzFt20LtRQdjtjdGfijGfDnCfdAEc++SFX9gA6sa7xwj7/BJmRfWtW/NJWBenN4tOJhg0vM3pg==} + engines: {node: '>=22'} + node-releases@2.0.51: resolution: {integrity: sha512-wRNIrw4DmVLKQlbgOMdkMx27Wrpzes2hh5Jtbi2bjPd+4wJstWIqP5A+lscnqbm0xxmT5Bpg8Lec5ItEBwx6BQ==} engines: {node: '>=18'} @@ -1702,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: @@ -1738,6 +1764,9 @@ packages: resolution: {integrity: sha512-g6QUff04oZpHs0eG5p83rFLhHeV00ug/Yf9nZM6fLeUrPguBTkTQOdpAWWspMh55TZfVQDPaN3NQJfbVRAxdIw==} engines: {iojs: '>=1.0.0', node: '>=0.10.0'} + rrule-temporal@2.0.2: + resolution: {integrity: sha512-pwe7+pWXKUotQgdudN8W36tFHWf8eH+FbcB5Tl4Zftb4RYpl1hnqMRapizv0s8QlOlC6GEKcVSmITurpSOVZfQ==} + run-parallel@1.2.0: resolution: {integrity: sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==} @@ -1875,6 +1904,15 @@ packages: resolution: {integrity: sha512-uxc/zpqFg6x7C8vOE7lh6Lbda8eEL9zmVm/PLeTPBRhh1xCgdWaQ+J1CUieGpIfm2HdtsUpRv+HshiasBMcc6A==} engines: {node: '>=6'} + temporal-polyfill@1.0.2: + resolution: {integrity: sha512-pTyp/7kfStJQbJ8YOHmcJItkxvOGCZHu3PaVgLvLnxFS7O12EPiWLElnRre/rw77z4TGZX/gvdqMXWn6ispQvA==} + + temporal-spec@1.0.1: + resolution: {integrity: sha512-wxVoanmDeavXie1vu2JaQ3WIc3JZnWAOYFBsJyATaVsXsycKYUflGsyBmrRSnoCpZJpwPyr38VpgSUlQ8CbFxg==} + + temporal-utils@1.0.1: + resolution: {integrity: sha512-HAixuesxFQIUaQk3ptX2jhfO/FsOkgVkDDMawvp6n/fkB1q6BKfs3lURw9I+pK/2e2e/q/vrLrxmeqauBoyGMQ==} + tinyglobby@0.2.17: resolution: {integrity: sha512-wXR/dYpcqKmfWpEdZjiKJOwCNFndD0DMnrW/cYjVGttEkBfVgcLFHoNrlj47mjOVic9yyNu65alsgF4NQyTa2g==} engines: {node: '>=12.0.0'} @@ -2290,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 @@ -2753,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: @@ -3618,6 +3662,11 @@ snapshots: object.entries: 1.1.9 semver: 6.3.1 + node-ical@0.27.1: + dependencies: + rrule-temporal: 2.0.2 + temporal-polyfill: 1.0.2 + node-releases@2.0.51: {} object-assign@4.1.1: {} @@ -3728,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 @@ -3772,6 +3826,10 @@ snapshots: reusify@1.1.0: {} + rrule-temporal@2.0.2: + dependencies: + temporal-spec: 1.0.1 + run-parallel@1.2.0: dependencies: queue-microtask: 1.2.3 @@ -3970,6 +4028,15 @@ snapshots: tapable@2.3.3: {} + temporal-polyfill@1.0.2: + dependencies: + temporal-spec: 1.0.1 + temporal-utils: 1.0.1 + + temporal-spec@1.0.1: {} + + temporal-utils@1.0.1: {} + tinyglobby@0.2.17: dependencies: fdir: 6.5.0(picomatch@4.0.5)