Add commands for manual timesheets and notes
- Manuelles Timesheet: create a timesheet with date, begin, end, break, activity (search, favorites/recent first), description and tags - Notiz hinzufügen: append notes to a running activity without stopping - Extract the activity choice dropdown shared with Tätigkeit starten Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
358fe5b9c6
commit
9fe73950fd
11 files changed
+518
-39
No files matched your search
@@ -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 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. |
|
| **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. |
|
| **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. |
|
| **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. |
|
||||||
|
|
||||||
|
|||||||
+25
-1
@@ -5,7 +5,9 @@
|
|||||||
"description": "Zeiterfassung mit Kimai: Tätigkeiten starten, stoppen und Timesheets verwalten",
|
"description": "Zeiterfassung mit Kimai: Tätigkeiten starten, stoppen und Timesheets verwalten",
|
||||||
"icon": "icon.png",
|
"icon": "icon.png",
|
||||||
"author": "meirjann",
|
"author": "meirjann",
|
||||||
"categories": ["Productivity"],
|
"categories": [
|
||||||
|
"Productivity"
|
||||||
|
],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"commands": [
|
"commands": [
|
||||||
{
|
{
|
||||||
@@ -22,6 +24,28 @@
|
|||||||
"description": "Zeigt alle laufenden Tätigkeiten und stoppt sie mit Beschreibung",
|
"description": "Zeigt alle laufenden Tätigkeiten und stoppt sie mit Beschreibung",
|
||||||
"mode": "view"
|
"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",
|
"name": "manage-timesheets",
|
||||||
"title": "Timesheets verwalten",
|
"title": "Timesheets verwalten",
|
||||||
|
|||||||
@@ -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 <Detail isLoading markdown="" />;
|
||||||
|
if (quick) return <Detail isLoading markdown={`Speichere Notiz zu **${target.activity.name}**…`} />;
|
||||||
|
if (target) return <NoteForm timesheet={target} onSaved={revalidate} isRoot />;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<List isLoading={isLoading} navigationTitle="Notiz hinzufügen">
|
||||||
|
<List.EmptyView icon={Icon.Clock} title="Keine laufenden Tätigkeiten" />
|
||||||
|
{active.map((ts) => (
|
||||||
|
<List.Item
|
||||||
|
key={ts.id}
|
||||||
|
icon={colorIcon(ts.activity["color-safe"], Icon.Play)}
|
||||||
|
title={timesheetTitle(ts)}
|
||||||
|
subtitle={timesheetSubtitle(ts)}
|
||||||
|
accessories={[
|
||||||
|
...(ts.description ? [{ icon: Icon.Text, tooltip: ts.description }] : []),
|
||||||
|
{ text: `seit ${formatTime(ts.begin)}` },
|
||||||
|
]}
|
||||||
|
actions={
|
||||||
|
<ActionPanel>
|
||||||
|
{note ? (
|
||||||
|
<Action title={`»${note}« hinzufügen`} icon={Icon.Plus} onAction={() => quickAppend(ts, note)} />
|
||||||
|
) : (
|
||||||
|
<Action.Push
|
||||||
|
title="Notizen schreiben"
|
||||||
|
icon={Icon.Pencil}
|
||||||
|
target={<NoteForm timesheet={ts} onSaved={revalidate} />}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</ActionPanel>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</List>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -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<Date | null>(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<Record<string, string | undefined>>({});
|
||||||
|
|
||||||
|
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<boolean> {
|
||||||
|
const errs: Record<string, string> = {};
|
||||||
|
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 (
|
||||||
|
<Form
|
||||||
|
isLoading={catalogLoading || optionsLoading}
|
||||||
|
navigationTitle="Manuelles Timesheet"
|
||||||
|
actions={
|
||||||
|
<ActionPanel>
|
||||||
|
<Action.SubmitForm title="Speichern" icon={Icon.Check} onSubmit={saveAndClose} />
|
||||||
|
<Action.SubmitForm
|
||||||
|
title="Speichern und weiteres erfassen"
|
||||||
|
icon={Icon.Plus}
|
||||||
|
shortcut={{ modifiers: ["cmd", "shift"], key: "enter" }}
|
||||||
|
onSubmit={saveAndNext}
|
||||||
|
/>
|
||||||
|
</ActionPanel>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Form.DatePicker
|
||||||
|
id="date"
|
||||||
|
title="Datum"
|
||||||
|
type={Form.DatePicker.Type.Date}
|
||||||
|
value={date}
|
||||||
|
onChange={(v) => {
|
||||||
|
setDate(v);
|
||||||
|
clearError("date");
|
||||||
|
}}
|
||||||
|
error={errors.date}
|
||||||
|
/>
|
||||||
|
<Form.TextField
|
||||||
|
id="begin"
|
||||||
|
title="Von"
|
||||||
|
placeholder="z. B. 8:30"
|
||||||
|
value={beginStr}
|
||||||
|
onChange={(v) => onTimeChange("begin", v)}
|
||||||
|
error={errors.begin}
|
||||||
|
/>
|
||||||
|
<Form.TextField
|
||||||
|
id="end"
|
||||||
|
title="Bis"
|
||||||
|
placeholder="z. B. 17:00"
|
||||||
|
value={endStr}
|
||||||
|
onChange={(v) => onTimeChange("end", v)}
|
||||||
|
error={errors.end}
|
||||||
|
/>
|
||||||
|
<Form.TextField
|
||||||
|
id="break"
|
||||||
|
title="Pause"
|
||||||
|
placeholder="automatisch"
|
||||||
|
value={breakStr}
|
||||||
|
onChange={onBreakChange}
|
||||||
|
error={errors.break}
|
||||||
|
info="Leer lassen, damit Kimai die Pause nach seinen Regeln setzt"
|
||||||
|
/>
|
||||||
|
{duration !== undefined && duration > 0 && <Form.Description title="Dauer" text={formatDuration(duration)} />}
|
||||||
|
<Form.Separator />
|
||||||
|
<ChoiceDropdown
|
||||||
|
favorites={favorites}
|
||||||
|
recent={recent}
|
||||||
|
all={all}
|
||||||
|
value={choice}
|
||||||
|
onChange={(v) => {
|
||||||
|
setChoice(v);
|
||||||
|
clearError("choice");
|
||||||
|
}}
|
||||||
|
error={errors.choice}
|
||||||
|
/>
|
||||||
|
{selected && (
|
||||||
|
<>
|
||||||
|
<Form.Description title="Kunde" text={selected.customer?.name ?? "–"} />
|
||||||
|
<Form.Description title="Projekt" text={selected.project.name} />
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
<Form.Separator />
|
||||||
|
<Form.TextArea
|
||||||
|
id="description"
|
||||||
|
title="Beschreibung"
|
||||||
|
value={description}
|
||||||
|
onChange={(v) => {
|
||||||
|
setDescription(v);
|
||||||
|
clearError("description");
|
||||||
|
}}
|
||||||
|
error={errors.description}
|
||||||
|
/>
|
||||||
|
<Form.TextField id="tags" title="Tags" placeholder="kommagetrennt" value={tags} onChange={setTags} />
|
||||||
|
</Form>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
import { Form } from "@raycast/api";
|
||||||
|
import { ActivityChoice, colorIcon } from "./utils";
|
||||||
|
|
||||||
|
/** Dropdown values are "<section>|<choice key>" 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 (
|
||||||
|
<Form.Dropdown.Item
|
||||||
|
value={`${prefix}|${choice.key}`}
|
||||||
|
title={`${choice.title} · ${choice.subtitle}`}
|
||||||
|
keywords={[choice.title, choice.project.name, choice.customer?.name ?? ""]}
|
||||||
|
icon={colorIcon(choice.color)}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
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 (
|
||||||
|
<Form.Dropdown id="choice" title="Tätigkeit" value={value} onChange={onChange} error={error}>
|
||||||
|
{favorites.length > 0 && (
|
||||||
|
<Form.Dropdown.Section title="⭐ Favoriten">
|
||||||
|
{favorites.map((c) => (
|
||||||
|
<ChoiceItem key={`fav-${c.key}`} choice={c} prefix="fav" />
|
||||||
|
))}
|
||||||
|
</Form.Dropdown.Section>
|
||||||
|
)}
|
||||||
|
{recent.length > 0 && (
|
||||||
|
<Form.Dropdown.Section title="Zuletzt verwendet">
|
||||||
|
{recent.map((c) => (
|
||||||
|
<ChoiceItem key={`rec-${c.key}`} choice={c} prefix="rec" />
|
||||||
|
))}
|
||||||
|
</Form.Dropdown.Section>
|
||||||
|
)}
|
||||||
|
<Form.Dropdown.Section title="Alle Tätigkeiten">
|
||||||
|
{all.map((c) => (
|
||||||
|
<ChoiceItem key={`all-${c.key}`} choice={c} prefix="all" />
|
||||||
|
))}
|
||||||
|
</Form.Dropdown.Section>
|
||||||
|
</Form.Dropdown>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -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<string> {
|
||||||
|
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 (
|
||||||
|
<Form
|
||||||
|
navigationTitle={`Notizen: ${timesheet.activity.name}`}
|
||||||
|
actions={
|
||||||
|
<ActionPanel>
|
||||||
|
<Action.SubmitForm title="Speichern" icon={Icon.Plus} onSubmit={() => save(false)} />
|
||||||
|
{isRoot && (
|
||||||
|
<Action.SubmitForm
|
||||||
|
title="Speichern und schließen"
|
||||||
|
icon={Icon.Check}
|
||||||
|
shortcut={{ modifiers: ["cmd"], key: "return" }}
|
||||||
|
onSubmit={() => save(true)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</ActionPanel>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Form.Description
|
||||||
|
title={timesheet.activity.name}
|
||||||
|
text={`${timesheetSubtitle(timesheet)} · seit ${formatTime(timesheet.begin)} Uhr`}
|
||||||
|
/>
|
||||||
|
<Form.TextField
|
||||||
|
id="note"
|
||||||
|
title="Neuer Stichpunkt"
|
||||||
|
placeholder="Was hast du gerade gemacht? (↵ speichert)"
|
||||||
|
value={note}
|
||||||
|
onChange={setNote}
|
||||||
|
autoFocus
|
||||||
|
/>
|
||||||
|
<Form.TextArea
|
||||||
|
id="description"
|
||||||
|
title="Beschreibung"
|
||||||
|
placeholder="- erster Punkt"
|
||||||
|
value={description}
|
||||||
|
onChange={setDescription}
|
||||||
|
info="Wird beim Speichern komplett übernommen, ein Stichpunkt pro Zeile"
|
||||||
|
/>
|
||||||
|
</Form>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -42,6 +42,22 @@ export function parseDuration(input: string): number | undefined {
|
|||||||
return 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 {
|
export function elapsedSeconds(ts: Timesheet, now = Date.now()): number {
|
||||||
if (ts.end) return ts.duration;
|
if (ts.end) return ts.duration;
|
||||||
return Math.max(0, (now - new Date(ts.begin).getTime()) / 1000 - (ts.break ?? 0));
|
return Math.max(0, (now - new Date(ts.begin).getTime()) / 1000 - (ts.break ?? 0));
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { startTimesheet } from "./lib/actions";
|
|||||||
import { api, kimaiUrl, Timesheet } from "./lib/api";
|
import { api, kimaiUrl, Timesheet } from "./lib/api";
|
||||||
import { TimesheetEditForm } from "./lib/edit-form";
|
import { TimesheetEditForm } from "./lib/edit-form";
|
||||||
import { useCatalog } from "./lib/hooks";
|
import { useCatalog } from "./lib/hooks";
|
||||||
|
import { NoteForm } from "./lib/note-form";
|
||||||
import { StopForm } from "./lib/stop-form";
|
import { StopForm } from "./lib/stop-form";
|
||||||
import {
|
import {
|
||||||
choiceKey,
|
choiceKey,
|
||||||
@@ -145,6 +146,14 @@ export default function ManageTimesheets() {
|
|||||||
icon={Icon.Pencil}
|
icon={Icon.Pencil}
|
||||||
target={<TimesheetEditForm timesheet={ts} catalog={catalog} onSaved={revalidate} />}
|
target={<TimesheetEditForm timesheet={ts} catalog={catalog} onSaved={revalidate} />}
|
||||||
/>
|
/>
|
||||||
|
{running && (
|
||||||
|
<Action.Push
|
||||||
|
title="Notizen schreiben"
|
||||||
|
icon={Icon.Text}
|
||||||
|
shortcut={{ modifiers: ["cmd"], key: "n" }}
|
||||||
|
target={<NoteForm timesheet={ts} onSaved={revalidate} />}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
{running ? (
|
{running ? (
|
||||||
<Action.Push
|
<Action.Push
|
||||||
title="Stoppen"
|
title="Stoppen"
|
||||||
|
|||||||
+18
-1
@@ -72,8 +72,25 @@ export default function MenuBar() {
|
|||||||
title={`${ts.activity.name} ${formatDuration(elapsedSeconds(ts, now))}`}
|
title={`${ts.activity.name} ${formatDuration(elapsedSeconds(ts, now))}`}
|
||||||
>
|
>
|
||||||
<MenuBarExtra.Item title={timesheetSubtitle(ts)} subtitle={`seit ${formatTime(ts.begin)}`} />
|
<MenuBarExtra.Item title={timesheetSubtitle(ts)} subtitle={`seit ${formatTime(ts.begin)}`} />
|
||||||
{ts.description ? <MenuBarExtra.Item title={truncate(ts.description, 60)} icon={Icon.Text} /> : null}
|
{(ts.description ?? "")
|
||||||
|
.split("\n")
|
||||||
|
.filter((line) => line.trim())
|
||||||
|
.slice(-8)
|
||||||
|
.map((line, i) => (
|
||||||
|
<MenuBarExtra.Item key={i} title={truncate(line.trim(), 60)} icon={Icon.Text} />
|
||||||
|
))}
|
||||||
<MenuBarExtra.Separator />
|
<MenuBarExtra.Separator />
|
||||||
|
<MenuBarExtra.Item
|
||||||
|
title="Notiz hinzufügen…"
|
||||||
|
icon={Icon.Pencil}
|
||||||
|
onAction={() =>
|
||||||
|
launchCommand({
|
||||||
|
name: "add-note",
|
||||||
|
type: LaunchType.UserInitiated,
|
||||||
|
context: { timesheetId: ts.id },
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/>
|
||||||
<MenuBarExtra.Item
|
<MenuBarExtra.Item
|
||||||
title="Stoppen…"
|
title="Stoppen…"
|
||||||
icon={Icon.Stop}
|
icon={Icon.Stop}
|
||||||
|
|||||||
+5
-37
@@ -1,8 +1,8 @@
|
|||||||
import { Action, ActionPanel, Form, Icon, popToRoot, showToast, Toast } from "@raycast/api";
|
import { Action, ActionPanel, Form, Icon, popToRoot, showToast, Toast } from "@raycast/api";
|
||||||
import { useEffect, useMemo, useState } from "react";
|
import { useEffect, useMemo, useState } from "react";
|
||||||
import { startTimesheet } from "./lib/actions";
|
import { startTimesheet } from "./lib/actions";
|
||||||
|
import { ChoiceDropdown, choiceKeyOf, firstChoiceValue } from "./lib/choice-dropdown";
|
||||||
import { useCatalog, useStartOptions } from "./lib/hooks";
|
import { useCatalog, useStartOptions } from "./lib/hooks";
|
||||||
import { ActivityChoice, colorIcon } from "./lib/utils";
|
|
||||||
|
|
||||||
interface Values {
|
interface Values {
|
||||||
begin: Date | null;
|
begin: Date | null;
|
||||||
@@ -11,17 +11,6 @@ interface Values {
|
|||||||
tags: string;
|
tags: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
function ChoiceItem({ choice, prefix }: { choice: ActivityChoice; prefix: string }) {
|
|
||||||
return (
|
|
||||||
<Form.Dropdown.Item
|
|
||||||
value={`${prefix}|${choice.key}`}
|
|
||||||
title={`${choice.title} · ${choice.subtitle}`}
|
|
||||||
keywords={[choice.title, choice.project.name, choice.customer?.name ?? ""]}
|
|
||||||
icon={colorIcon(choice.color)}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function StartActivity() {
|
export default function StartActivity() {
|
||||||
const { data: catalog, isLoading: catalogLoading } = useCatalog();
|
const { data: catalog, isLoading: catalogLoading } = useCatalog();
|
||||||
const { favorites, recent, isLoading: optionsLoading } = useStartOptions(catalog);
|
const { favorites, recent, isLoading: optionsLoading } = useStartOptions(catalog);
|
||||||
@@ -30,14 +19,13 @@ export default function StartActivity() {
|
|||||||
|
|
||||||
const all = useMemo(() => catalog?.choices ?? [], [catalog]);
|
const all = useMemo(() => catalog?.choices ?? [], [catalog]);
|
||||||
const byKey = useMemo(() => new Map(all.map((c) => [c.key, c])), [all]);
|
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
|
// preselect the first favorite (or recent) entry once loaded
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (choice || optionsLoading || catalogLoading) return;
|
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);
|
if (first) setChoice(first);
|
||||||
else if (all[0]) setChoice(`all|${all[0].key}`);
|
|
||||||
}, [favorites, recent, all, optionsLoading, catalogLoading]);
|
}, [favorites, recent, all, optionsLoading, catalogLoading]);
|
||||||
|
|
||||||
async function handleSubmit(values: Values) {
|
async function handleSubmit(values: Values) {
|
||||||
@@ -45,7 +33,7 @@ export default function StartActivity() {
|
|||||||
setBeginError("Bitte Startzeit angeben");
|
setBeginError("Bitte Startzeit angeben");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const key = values.choice.split("|")[1];
|
const key = choiceKeyOf(values.choice);
|
||||||
if (!key) {
|
if (!key) {
|
||||||
await showToast({ style: Toast.Style.Failure, title: "Bitte eine Tätigkeit auswählen" });
|
await showToast({ style: Toast.Style.Failure, title: "Bitte eine Tätigkeit auswählen" });
|
||||||
return false;
|
return false;
|
||||||
@@ -78,27 +66,7 @@ export default function StartActivity() {
|
|||||||
error={beginError}
|
error={beginError}
|
||||||
onChange={() => setBeginError(undefined)}
|
onChange={() => setBeginError(undefined)}
|
||||||
/>
|
/>
|
||||||
<Form.Dropdown id="choice" title="Tätigkeit" value={choice} onChange={setChoice}>
|
<ChoiceDropdown favorites={favorites} recent={recent} all={all} value={choice} onChange={setChoice} />
|
||||||
{favorites.length > 0 && (
|
|
||||||
<Form.Dropdown.Section title="⭐ Favoriten">
|
|
||||||
{favorites.map((c) => (
|
|
||||||
<ChoiceItem key={`fav-${c.key}`} choice={c} prefix="fav" />
|
|
||||||
))}
|
|
||||||
</Form.Dropdown.Section>
|
|
||||||
)}
|
|
||||||
{recent.length > 0 && (
|
|
||||||
<Form.Dropdown.Section title="Zuletzt verwendet">
|
|
||||||
{recent.map((c) => (
|
|
||||||
<ChoiceItem key={`rec-${c.key}`} choice={c} prefix="rec" />
|
|
||||||
))}
|
|
||||||
</Form.Dropdown.Section>
|
|
||||||
)}
|
|
||||||
<Form.Dropdown.Section title="Alle Tätigkeiten">
|
|
||||||
{all.map((c) => (
|
|
||||||
<ChoiceItem key={`all-${c.key}`} choice={c} prefix="all" />
|
|
||||||
))}
|
|
||||||
</Form.Dropdown.Section>
|
|
||||||
</Form.Dropdown>
|
|
||||||
{selected && (
|
{selected && (
|
||||||
<>
|
<>
|
||||||
<Form.Description title="Kunde" text={selected.customer?.name ?? "–"} />
|
<Form.Description title="Kunde" text={selected.customer?.name ?? "–"} />
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { Action, ActionPanel, Detail, Icon, LaunchProps, List } from "@raycast/a
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { kimaiUrl } from "./lib/api";
|
import { kimaiUrl } from "./lib/api";
|
||||||
import { useActive } from "./lib/hooks";
|
import { useActive } from "./lib/hooks";
|
||||||
|
import { NoteForm } from "./lib/note-form";
|
||||||
import { StopForm } from "./lib/stop-form";
|
import { StopForm } from "./lib/stop-form";
|
||||||
import { colorIcon, elapsedSeconds, formatDuration, formatTime, timesheetSubtitle, timesheetTitle } from "./lib/utils";
|
import { colorIcon, elapsedSeconds, formatDuration, formatTime, timesheetSubtitle, timesheetTitle } from "./lib/utils";
|
||||||
|
|
||||||
@@ -51,6 +52,12 @@ export default function StopActivity({ launchContext }: Props) {
|
|||||||
icon={Icon.Stop}
|
icon={Icon.Stop}
|
||||||
target={<StopForm timesheet={ts} onStopped={revalidate} />}
|
target={<StopForm timesheet={ts} onStopped={revalidate} />}
|
||||||
/>
|
/>
|
||||||
|
<Action.Push
|
||||||
|
title="Notizen schreiben"
|
||||||
|
icon={Icon.Pencil}
|
||||||
|
shortcut={{ modifiers: ["cmd"], key: "n" }}
|
||||||
|
target={<NoteForm timesheet={ts} onSaved={revalidate} />}
|
||||||
|
/>
|
||||||
<Action.OpenInBrowser title="In Kimai öffnen" url={kimaiUrl("/de/timesheet/")} />
|
<Action.OpenInBrowser title="In Kimai öffnen" url={kimaiUrl("/de/timesheet/")} />
|
||||||
<Action
|
<Action
|
||||||
title="Aktualisieren"
|
title="Aktualisieren"
|
||||||
|
|||||||
Reference in new issue
Block a user