diff --git a/README.md b/README.md
index f6d710e..ba20a7c 100644
--- a/README.md
+++ b/README.md
@@ -8,6 +8,8 @@ Zeiterfassung mit [Kimai](https://www.kimai.org) direkt aus Raycast.
| --- | --- |
| **Tätigkeit starten** | Formular mit »Von« (vorbelegt mit jetzt) und Tätigkeitsauswahl. Favoriten und zuletzt genutzte Tätigkeiten stehen oben, Kunde und Projekt ergeben sich aus der Tätigkeit. Optional Beschreibung und Tags. |
| **Tätigkeit stoppen** | Listet alle laufenden Tätigkeiten. `↵` öffnet das Stopp-Formular, die Beschreibung ist Pflicht. |
+| **Notiz hinzufügen** | Stichpunkte zur laufenden Tätigkeit notieren, ohne zu stoppen. Direkt aus der Suche: `Notiz hinzufügen` ⇥ Text ↵ (bei genau einer laufenden Tätigkeit wird sofort angehängt). Ohne Text öffnet sich das Notiz-Formular: ↵ speichert den Stichpunkt und leert das Feld für den nächsten, die gesamte Beschreibung ist darunter editierbar. Auch über die Menüleiste und mit `⌘N` in »Tätigkeit stoppen« und »Timesheets verwalten«. Beim Stoppen ist die Beschreibung mit den Stichpunkten vorbefüllt. |
+| **Manuelles Timesheet** | Timesheet nachträglich erfassen: Datum, Von, Bis (z. B. `8:30`, `0830`), Pause, Tätigkeit, Beschreibung (Pflicht) und Tags. Die Tätigkeitsauswahl funktioniert wie bei »Tätigkeit starten« (Suche, Favoriten und zuletzt genutzte oben, Kunde und Projekt ergeben sich daraus). Die Dauer wird live angezeigt. Bleibt die Pause leer, setzt Kimai sie nach seinen Regeln. `⌘⇧↵` speichert und öffnet direkt den nächsten Eintrag (Von = letztes Bis). |
| **Timesheets verwalten** | Alle Timesheets des Monats, nach Tagen gruppiert mit Tagessummen (Monatsauswahl oben rechts). `↵` öffnet das Bearbeiten-Formular mit Von, Bis, Dauer, Pause, Kunde, Projekt, Tätigkeit, Beschreibung und Tags. Weitere Aktionen: stoppen bzw. erneut starten, als Favorit markieren, löschen, in Kimai öffnen. |
| **Kimai Menu Bar** | Menüleisten-Eintrag mit laufender Zeit. »Stoppen…« öffnet das Stopp-Formular mit Pflicht-Beschreibung. Favoriten, zuletzt genutzte und alle Tätigkeiten (nach Kunde) starten. Mehrere Tätigkeiten können parallel laufen. |
diff --git a/package.json b/package.json
index 57e9ad2..afb1bf1 100644
--- a/package.json
+++ b/package.json
@@ -5,7 +5,9 @@
"description": "Zeiterfassung mit Kimai: Tätigkeiten starten, stoppen und Timesheets verwalten",
"icon": "icon.png",
"author": "meirjann",
- "categories": ["Productivity"],
+ "categories": [
+ "Productivity"
+ ],
"license": "MIT",
"commands": [
{
@@ -22,6 +24,28 @@
"description": "Zeigt alle laufenden Tätigkeiten und stoppt sie mit Beschreibung",
"mode": "view"
},
+ {
+ "name": "add-note",
+ "title": "Notiz hinzufügen",
+ "subtitle": "Kimai",
+ "description": "Stichpunkt zur laufenden Tätigkeit notieren, ohne zu stoppen",
+ "mode": "view",
+ "arguments": [
+ {
+ "name": "note",
+ "placeholder": "Stichpunkt",
+ "type": "text",
+ "required": false
+ }
+ ]
+ },
+ {
+ "name": "add-timesheet",
+ "title": "Manuelles Timesheet",
+ "subtitle": "Kimai",
+ "description": "Timesheet nachträglich mit Datum, Von, Bis und Pause erfassen",
+ "mode": "view"
+ },
{
"name": "manage-timesheets",
"title": "Timesheets verwalten",
diff --git a/src/add-note.tsx b/src/add-note.tsx
new file mode 100644
index 0000000..e95ccc3
--- /dev/null
+++ b/src/add-note.tsx
@@ -0,0 +1,88 @@
+import {
+ Action,
+ ActionPanel,
+ closeMainWindow,
+ Detail,
+ Icon,
+ LaunchProps,
+ List,
+ PopToRootType,
+ showHUD,
+} from "@raycast/api";
+import { useEffect, useRef } from "react";
+import { Timesheet } from "./lib/api";
+import { useActive } from "./lib/hooks";
+import { appendNote, NoteForm } from "./lib/note-form";
+import { colorIcon, formatTime, showError, timesheetSubtitle, timesheetTitle } from "./lib/utils";
+
+type Props = LaunchProps<{
+ arguments: Arguments.AddNote;
+ launchContext?: { timesheetId?: number };
+}>;
+
+async function quickAppend(ts: Timesheet, note: string) {
+ try {
+ await appendNote(ts.id, note);
+ await showHUD(`Notiz zu »${ts.activity.name}« hinzugefügt`);
+ await closeMainWindow({ popToRootType: PopToRootType.Immediate });
+ } catch (e) {
+ await showError("Notiz konnte nicht gespeichert werden", e);
+ }
+}
+
+export default function AddNote({ arguments: args, launchContext }: Props) {
+ const { data, isLoading, revalidate } = useActive();
+ const active = data ?? [];
+ const note = args.note?.trim() ?? "";
+ const done = useRef(false);
+
+ const target =
+ launchContext?.timesheetId !== undefined
+ ? active.find((ts) => ts.id === launchContext.timesheetId)
+ : active.length === 1
+ ? active[0]
+ : undefined;
+
+ // note typed as argument and exactly one target: append right away
+ const quick = note !== "" && target !== undefined && !isLoading;
+ useEffect(() => {
+ if (!quick || done.current) return;
+ done.current = true;
+ quickAppend(target, note);
+ }, [quick]);
+
+ if (isLoading && !data) return ;
+ if (quick) return ;
+ if (target) return ;
+
+ return (
+
+
+ {active.map((ts) => (
+
+ {note ? (
+ quickAppend(ts, note)} />
+ ) : (
+ }
+ />
+ )}
+
+ }
+ />
+ ))}
+
+ );
+}
diff --git a/src/add-timesheet.tsx b/src/add-timesheet.tsx
new file mode 100644
index 0000000..7f1caf5
--- /dev/null
+++ b/src/add-timesheet.tsx
@@ -0,0 +1,196 @@
+import { Action, ActionPanel, Form, Icon, popToRoot, showToast, Toast } from "@raycast/api";
+import { useEffect, useMemo, useState } from "react";
+import { api } from "./lib/api";
+import { ChoiceDropdown, choiceKeyOf, firstChoiceValue } from "./lib/choice-dropdown";
+import { useCatalog, useStartOptions } from "./lib/hooks";
+import { formatDuration, kimaiDateAt, parseDuration, parseChoiceKey, parseTime, showError } from "./lib/utils";
+
+export default function AddTimesheet() {
+ const { data: catalog, isLoading: catalogLoading } = useCatalog();
+ const { favorites, recent, isLoading: optionsLoading } = useStartOptions(catalog);
+
+ const all = useMemo(() => catalog?.choices ?? [], [catalog]);
+ const byKey = useMemo(() => new Map(all.map((c) => [c.key, c])), [all]);
+
+ const [date, setDate] = useState(new Date());
+ const [beginStr, setBeginStr] = useState("");
+ const [endStr, setEndStr] = useState("");
+ const [breakStr, setBreakStr] = useState("");
+ const [choice, setChoice] = useState("");
+ const [description, setDescription] = useState("");
+ const [tags, setTags] = useState("");
+ const [errors, setErrors] = useState>({});
+
+ const choiceKey = choiceKeyOf(choice);
+ const selected = byKey.get(choiceKey ?? "");
+
+ // preselect the first favorite (or recent) entry once loaded
+ useEffect(() => {
+ if (choice || optionsLoading || catalogLoading) return;
+ const first = firstChoiceValue(favorites, recent, all);
+ if (first) setChoice(first);
+ }, [favorites, recent, all, optionsLoading, catalogLoading]);
+
+ const clearError = (field: string) => setErrors((e) => ({ ...e, [field]: undefined }));
+
+ const begin = parseTime(beginStr);
+ const end = parseTime(endStr);
+ const breakSec = parseDuration(breakStr);
+ const duration =
+ begin !== undefined && end !== undefined && end > begin && breakSec !== undefined
+ ? (end - begin) * 60 - breakSec
+ : undefined;
+
+ function onTimeChange(field: "begin" | "end", v: string) {
+ (field === "begin" ? setBeginStr : setEndStr)(v);
+ if (v.trim() !== "" && parseTime(v) === undefined) {
+ setErrors((e) => ({ ...e, [field]: "Format z. B. 8:30" }));
+ } else {
+ clearError(field);
+ }
+ }
+
+ function onBreakChange(v: string) {
+ setBreakStr(v);
+ if (parseDuration(v) === undefined) setErrors((e) => ({ ...e, break: "Format z. B. 0:30" }));
+ else clearError("break");
+ }
+
+ /** returns true when saved */
+ async function submit(): Promise {
+ const errs: Record = {};
+ if (!date) errs.date = "Pflichtfeld";
+ if (begin === undefined) errs.begin = beginStr.trim() ? "Format z. B. 8:30" : "Pflichtfeld";
+ if (end === undefined) errs.end = endStr.trim() ? "Format z. B. 17:00" : "Pflichtfeld";
+ else if (begin !== undefined && end <= begin) errs.end = "Bis muss nach Von liegen";
+ if (breakSec === undefined) errs.break = "Format z. B. 0:30";
+ else if (duration !== undefined && duration <= 0) errs.break = "Pause ist länger als die Arbeitszeit";
+ if (!choiceKey) errs.choice = "Bitte Tätigkeit wählen";
+ if (!description.trim()) errs.description = "Beschreibung ist Pflicht";
+ if (Object.keys(errs).length) {
+ setErrors(errs);
+ return false;
+ }
+
+ const toast = await showToast({ style: Toast.Style.Animated, title: "Speichere…" });
+ try {
+ // times are entered as wall-clock time of the Kimai user, so no timezone conversion
+ const ts = await api.create({
+ begin: kimaiDateAt(date!, begin!),
+ end: kimaiDateAt(date!, end!),
+ ...parseChoiceKey(choiceKey!),
+ description,
+ tags: tags.trim() || undefined,
+ // without a value Kimai applies its own break rules
+ ...(breakStr.trim() ? { break: formatDuration(breakSec ?? 0) } : {}),
+ });
+ toast.style = Toast.Style.Success;
+ toast.title = `Timesheet erstellt: ${ts.activity.name}`;
+ toast.message = formatDuration(ts.duration);
+ return true;
+ } catch (e) {
+ toast.hide();
+ await showError("Speichern fehlgeschlagen", e);
+ return false;
+ }
+ }
+
+ async function saveAndClose() {
+ if (await submit()) await popToRoot();
+ }
+
+ // keep date and assignment, continue where the last entry ended
+ async function saveAndNext() {
+ if (!(await submit())) return;
+ setBeginStr(endStr);
+ setEndStr("");
+ setBreakStr("");
+ setDescription("");
+ }
+
+ return (
+ {
+ setDate(v);
+ clearError("date");
+ }}
+ error={errors.date}
+ />
+ onTimeChange("begin", v)}
+ error={errors.begin}
+ />
+ onTimeChange("end", v)}
+ error={errors.end}
+ />
+
+ {duration !== undefined && duration > 0 && }
+
+ {
+ setChoice(v);
+ clearError("choice");
+ }}
+ error={errors.choice}
+ />
+ {selected && (
+ <>
+
+
+ >
+ )}
+
+ {
+ setDescription(v);
+ clearError("description");
+ }}
+ error={errors.description}
+ />
+
+
+ );
+}
diff --git a/src/lib/choice-dropdown.tsx b/src/lib/choice-dropdown.tsx
new file mode 100644
index 0000000..6743e68
--- /dev/null
+++ b/src/lib/choice-dropdown.tsx
@@ -0,0 +1,59 @@
+import { Form } from "@raycast/api";
+import { ActivityChoice, colorIcon } from "./utils";
+
+/** Dropdown values are "|" so a choice can appear in several sections */
+export const choiceKeyOf = (value: string): string | undefined => value.split("|")[1] || undefined;
+
+/** Value of the first favorite, else recent, else any choice */
+export function firstChoiceValue(favorites: ActivityChoice[], recent: ActivityChoice[], all: ActivityChoice[]) {
+ if (favorites[0]) return `fav|${favorites[0].key}`;
+ if (recent[0]) return `rec|${recent[0].key}`;
+ if (all[0]) return `all|${all[0].key}`;
+ return undefined;
+}
+
+function ChoiceItem({ choice, prefix }: { choice: ActivityChoice; prefix: string }) {
+ return (
+
+ );
+}
+
+interface Props {
+ favorites: ActivityChoice[];
+ recent: ActivityChoice[];
+ all: ActivityChoice[];
+ value: string;
+ onChange: (value: string) => void;
+ error?: string;
+}
+
+export function ChoiceDropdown({ favorites, recent, all, value, onChange, error }: Props) {
+ return (
+
+ {favorites.length > 0 && (
+
+ {favorites.map((c) => (
+
+ ))}
+
+ )}
+ {recent.length > 0 && (
+
+ {recent.map((c) => (
+
+ ))}
+
+ )}
+
+ {all.map((c) => (
+
+ ))}
+
+
+ );
+}
diff --git a/src/lib/note-form.tsx b/src/lib/note-form.tsx
new file mode 100644
index 0000000..eb8c773
--- /dev/null
+++ b/src/lib/note-form.tsx
@@ -0,0 +1,93 @@
+import { Action, ActionPanel, closeMainWindow, Form, Icon, PopToRootType, showToast, Toast } from "@raycast/api";
+import { useState } from "react";
+import { api, Timesheet } from "./api";
+import { formatTime, showError, timesheetSubtitle } from "./utils";
+
+/** Appends a note as markdown bullet point to a description */
+export function appendBullet(description: string | null | undefined, note: string): string {
+ const bullet = `- ${note.trim().replace(/^[-*•]\s*/, "")}`;
+ const current = (description ?? "").trimEnd();
+ return current ? `${current}\n${bullet}` : bullet;
+}
+
+/**
+ * Appends a note to the description of a running timesheet without stopping it.
+ * The latest description is fetched first, so notes written elsewhere in the meantime are kept.
+ */
+export async function appendNote(timesheetId: number, note: string): Promise {
+ const current = (await api.active()).find((ts) => ts.id === timesheetId);
+ if (!current) throw new Error("Die Tätigkeit läuft nicht mehr");
+ const description = appendBullet(current.description, note);
+ await api.update(timesheetId, { description });
+ return description;
+}
+
+interface Props {
+ timesheet: Timesheet;
+ onSaved?: () => void;
+ /** opened directly via launch context: close Raycast with "save and close" */
+ isRoot?: boolean;
+}
+
+/** Write down notes while a task is running: new bullet point plus the editable full description */
+export function NoteForm({ timesheet, onSaved, isRoot }: Props) {
+ const [note, setNote] = useState("");
+ const [description, setDescription] = useState(timesheet.description ?? "");
+
+ async function save(close: boolean) {
+ const next = note.trim() ? appendBullet(description, note) : description;
+ const toast = await showToast({ style: Toast.Style.Animated, title: "Speichere Notiz…" });
+ try {
+ await api.update(timesheet.id, { description: next });
+ setDescription(next);
+ setNote("");
+ toast.style = Toast.Style.Success;
+ toast.title = "Notiz gespeichert";
+ onSaved?.();
+ if (close && isRoot) await closeMainWindow({ popToRootType: PopToRootType.Immediate });
+ } catch (e) {
+ toast.hide();
+ await showError("Speichern fehlgeschlagen", e);
+ }
+ }
+
+ return (
+
+ );
+}
diff --git a/src/lib/utils.ts b/src/lib/utils.ts
index 21c997d..cd3c933 100644
--- a/src/lib/utils.ts
+++ b/src/lib/utils.ts
@@ -42,6 +42,22 @@ export function parseDuration(input: string): number | undefined {
return undefined;
}
+/** Parses times like "8", "8:30", "08.30", "0830" into minutes since midnight; undefined if invalid */
+export function parseTime(input: string): number | undefined {
+ const m = input.trim().match(/^(\d{1,2})(?:[:.]?(\d{2}))?$/);
+ if (!m) return undefined;
+ const h = Number(m[1]);
+ const min = Number(m[2] ?? 0);
+ if (h > 23 || min > 59) return undefined;
+ return h * 60 + min;
+}
+
+/** Kimai local datetime ("YYYY-MM-DDTHH:mm:ss") from a calendar day and minutes since midnight */
+export function kimaiDateAt(day: Date, minutes: number): string {
+ const pad = (n: number) => String(n).padStart(2, "0");
+ return `${day.getFullYear()}-${pad(day.getMonth() + 1)}-${pad(day.getDate())}T${pad(Math.floor(minutes / 60))}:${pad(minutes % 60)}:00`;
+}
+
export function elapsedSeconds(ts: Timesheet, now = Date.now()): number {
if (ts.end) return ts.duration;
return Math.max(0, (now - new Date(ts.begin).getTime()) / 1000 - (ts.break ?? 0));
diff --git a/src/manage-timesheets.tsx b/src/manage-timesheets.tsx
index 29d18ad..bc701d7 100644
--- a/src/manage-timesheets.tsx
+++ b/src/manage-timesheets.tsx
@@ -5,6 +5,7 @@ import { startTimesheet } from "./lib/actions";
import { api, kimaiUrl, Timesheet } from "./lib/api";
import { TimesheetEditForm } from "./lib/edit-form";
import { useCatalog } from "./lib/hooks";
+import { NoteForm } from "./lib/note-form";
import { StopForm } from "./lib/stop-form";
import {
choiceKey,
@@ -145,6 +146,14 @@ export default function ManageTimesheets() {
icon={Icon.Pencil}
target={}
/>
+ {running && (
+ }
+ />
+ )}
{running ? (
- {ts.description ? : null}
+ {(ts.description ?? "")
+ .split("\n")
+ .filter((line) => line.trim())
+ .slice(-8)
+ .map((line, i) => (
+
+ ))}
+
+ launchCommand({
+ name: "add-note",
+ type: LaunchType.UserInitiated,
+ context: { timesheetId: ts.id },
+ })
+ }
+ />
- );
-}
-
export default function StartActivity() {
const { data: catalog, isLoading: catalogLoading } = useCatalog();
const { favorites, recent, isLoading: optionsLoading } = useStartOptions(catalog);
@@ -30,14 +19,13 @@ export default function StartActivity() {
const all = useMemo(() => catalog?.choices ?? [], [catalog]);
const byKey = useMemo(() => new Map(all.map((c) => [c.key, c])), [all]);
- const selected = choice ? byKey.get(choice.split("|")[1]) : undefined;
+ const selected = byKey.get(choiceKeyOf(choice) ?? "");
// preselect the first favorite (or recent) entry once loaded
useEffect(() => {
if (choice || optionsLoading || catalogLoading) return;
- const first = favorites[0] ? `fav|${favorites[0].key}` : recent[0] ? `rec|${recent[0].key}` : undefined;
+ const first = firstChoiceValue(favorites, recent, all);
if (first) setChoice(first);
- else if (all[0]) setChoice(`all|${all[0].key}`);
}, [favorites, recent, all, optionsLoading, catalogLoading]);
async function handleSubmit(values: Values) {
@@ -45,7 +33,7 @@ export default function StartActivity() {
setBeginError("Bitte Startzeit angeben");
return false;
}
- const key = values.choice.split("|")[1];
+ const key = choiceKeyOf(values.choice);
if (!key) {
await showToast({ style: Toast.Style.Failure, title: "Bitte eine Tätigkeit auswählen" });
return false;
@@ -78,27 +66,7 @@ export default function StartActivity() {
error={beginError}
onChange={() => setBeginError(undefined)}
/>
-
- {favorites.length > 0 && (
-
- {favorites.map((c) => (
-
- ))}
-
- )}
- {recent.length > 0 && (
-
- {recent.map((c) => (
-
- ))}
-
- )}
-
- {all.map((c) => (
-
- ))}
-
-
+
{selected && (
<>
diff --git a/src/stop-activity.tsx b/src/stop-activity.tsx
index 56c5809..012e73e 100644
--- a/src/stop-activity.tsx
+++ b/src/stop-activity.tsx
@@ -2,6 +2,7 @@ import { Action, ActionPanel, Detail, Icon, LaunchProps, List } from "@raycast/a
import { useEffect, useState } from "react";
import { kimaiUrl } from "./lib/api";
import { useActive } from "./lib/hooks";
+import { NoteForm } from "./lib/note-form";
import { StopForm } from "./lib/stop-form";
import { colorIcon, elapsedSeconds, formatDuration, formatTime, timesheetSubtitle, timesheetTitle } from "./lib/utils";
@@ -51,6 +52,12 @@ export default function StopActivity({ launchContext }: Props) {
icon={Icon.Stop}
target={}
/>
+ }
+ />