diff --git a/api/openapi-v2.json b/api/openapi-v2.json index ebd964217..5a9e09bd5 100644 --- a/api/openapi-v2.json +++ b/api/openapi-v2.json @@ -30809,6 +30809,7 @@ }, "project_id": { "description": "The project id value.", + "nullable": true, "type": "integer" }, "project_name": { @@ -30848,7 +30849,6 @@ "created_at", "description", "id", - "project_id", "start_time_utc", "user_id", "workspace_id" @@ -30861,6 +30861,251 @@ ], "type": "object" }, + "GetTimeWorklogDraftsDraftIdResult": { + "additionalProperties": false, + "properties": { + "data": { + "additionalProperties": false, + "properties": { + "created_at": { + "description": "The created at value.", + "type": "integer" + }, + "customer_builtin_key": { + "description": "The customer builtin key value.", + "type": "string" + }, + "customer_name": { + "description": "The customer name value.", + "type": "string" + }, + "date": { + "description": "The date value.", + "nullable": true, + "type": "integer" + }, + "description": { + "description": "The description value.", + "type": "string" + }, + "duration_minutes": { + "description": "The duration minutes value.", + "nullable": true, + "type": "integer" + }, + "end_time": { + "description": "The end time value.", + "nullable": true, + "type": "integer" + }, + "id": { + "description": "The id value.", + "type": "integer" + }, + "item_id": { + "description": "The item id value.", + "nullable": true, + "type": "integer" + }, + "item_title": { + "description": "The item title value.", + "type": "string" + }, + "project_id": { + "description": "The project id value.", + "nullable": true, + "type": "integer" + }, + "project_name": { + "description": "The project name value.", + "type": "string" + }, + "source": { + "description": "The source value.", + "type": "string" + }, + "source_timer_id": { + "description": "The source timer id value.", + "nullable": true, + "type": "integer" + }, + "start_time": { + "description": "The start time value.", + "nullable": true, + "type": "integer" + }, + "updated_at": { + "description": "The updated at value.", + "type": "integer" + }, + "user_id": { + "description": "The user id value.", + "type": "integer" + }, + "version": { + "description": "The version value.", + "type": "integer" + }, + "workspace_id": { + "description": "The workspace id value.", + "nullable": true, + "type": "integer" + }, + "workspace_key": { + "description": "The workspace key value.", + "type": "string" + }, + "workspace_name": { + "description": "The workspace name value.", + "type": "string" + } + }, + "required": [ + "created_at", + "customer_name", + "description", + "id", + "item_title", + "project_name", + "source", + "updated_at", + "user_id", + "version", + "workspace_key", + "workspace_name" + ], + "type": "object" + } + }, + "required": [ + "data" + ], + "type": "object" + }, + "GetTimeWorklogDraftsResult": { + "additionalProperties": false, + "properties": { + "data": { + "items": { + "additionalProperties": false, + "properties": { + "created_at": { + "description": "The created at value.", + "type": "integer" + }, + "customer_builtin_key": { + "description": "The customer builtin key value.", + "type": "string" + }, + "customer_name": { + "description": "The customer name value.", + "type": "string" + }, + "date": { + "description": "The date value.", + "nullable": true, + "type": "integer" + }, + "description": { + "description": "The description value.", + "type": "string" + }, + "duration_minutes": { + "description": "The duration minutes value.", + "nullable": true, + "type": "integer" + }, + "end_time": { + "description": "The end time value.", + "nullable": true, + "type": "integer" + }, + "id": { + "description": "The id value.", + "type": "integer" + }, + "item_id": { + "description": "The item id value.", + "nullable": true, + "type": "integer" + }, + "item_title": { + "description": "The item title value.", + "type": "string" + }, + "project_id": { + "description": "The project id value.", + "nullable": true, + "type": "integer" + }, + "project_name": { + "description": "The project name value.", + "type": "string" + }, + "source": { + "description": "The source value.", + "type": "string" + }, + "source_timer_id": { + "description": "The source timer id value.", + "nullable": true, + "type": "integer" + }, + "start_time": { + "description": "The start time value.", + "nullable": true, + "type": "integer" + }, + "updated_at": { + "description": "The updated at value.", + "type": "integer" + }, + "user_id": { + "description": "The user id value.", + "type": "integer" + }, + "version": { + "description": "The version value.", + "type": "integer" + }, + "workspace_id": { + "description": "The workspace id value.", + "nullable": true, + "type": "integer" + }, + "workspace_key": { + "description": "The workspace key value.", + "type": "string" + }, + "workspace_name": { + "description": "The workspace name value.", + "type": "string" + } + }, + "required": [ + "created_at", + "customer_name", + "description", + "id", + "item_title", + "project_name", + "source", + "updated_at", + "user_id", + "version", + "workspace_key", + "workspace_name" + ], + "type": "object" + }, + "type": "array" + } + }, + "required": [ + "data" + ], + "type": "object" + }, "GetTimeWorklogsAggregateResult": { "additionalProperties": false, "properties": { @@ -59523,6 +59768,185 @@ ], "type": "object" }, + "PatchTimeWorklogDraftsDraftIdPayload": { + "additionalProperties": false, + "properties": { + "date": { + "description": "The date value.", + "nullable": true, + "type": "string" + }, + "description": { + "description": "The description value.", + "nullable": true, + "type": "string" + }, + "duration": { + "description": "The duration value.", + "nullable": true, + "type": "string" + }, + "duration_minutes": { + "description": "The duration minutes value.", + "nullable": true, + "type": "integer" + }, + "end_time": { + "description": "The end time value.", + "nullable": true, + "type": "string" + }, + "item_id": { + "description": "The item id value.", + "nullable": true, + "type": "integer" + }, + "project_id": { + "description": "The project id value.", + "nullable": true, + "type": "integer" + }, + "start_time": { + "description": "The start time value.", + "nullable": true, + "type": "string" + }, + "timezone": { + "description": "The timezone value.", + "nullable": true, + "type": "string" + }, + "version": { + "description": "The version value.", + "type": "integer" + } + }, + "required": [ + "version" + ], + "type": "object" + }, + "PatchTimeWorklogDraftsDraftIdResult": { + "additionalProperties": false, + "properties": { + "data": { + "additionalProperties": false, + "properties": { + "created_at": { + "description": "The created at value.", + "type": "integer" + }, + "customer_builtin_key": { + "description": "The customer builtin key value.", + "type": "string" + }, + "customer_name": { + "description": "The customer name value.", + "type": "string" + }, + "date": { + "description": "The date value.", + "nullable": true, + "type": "integer" + }, + "description": { + "description": "The description value.", + "type": "string" + }, + "duration_minutes": { + "description": "The duration minutes value.", + "nullable": true, + "type": "integer" + }, + "end_time": { + "description": "The end time value.", + "nullable": true, + "type": "integer" + }, + "id": { + "description": "The id value.", + "type": "integer" + }, + "item_id": { + "description": "The item id value.", + "nullable": true, + "type": "integer" + }, + "item_title": { + "description": "The item title value.", + "type": "string" + }, + "project_id": { + "description": "The project id value.", + "nullable": true, + "type": "integer" + }, + "project_name": { + "description": "The project name value.", + "type": "string" + }, + "source": { + "description": "The source value.", + "type": "string" + }, + "source_timer_id": { + "description": "The source timer id value.", + "nullable": true, + "type": "integer" + }, + "start_time": { + "description": "The start time value.", + "nullable": true, + "type": "integer" + }, + "updated_at": { + "description": "The updated at value.", + "type": "integer" + }, + "user_id": { + "description": "The user id value.", + "type": "integer" + }, + "version": { + "description": "The version value.", + "type": "integer" + }, + "workspace_id": { + "description": "The workspace id value.", + "nullable": true, + "type": "integer" + }, + "workspace_key": { + "description": "The workspace key value.", + "type": "string" + }, + "workspace_name": { + "description": "The workspace name value.", + "type": "string" + } + }, + "required": [ + "created_at", + "customer_name", + "description", + "id", + "item_title", + "project_name", + "source", + "updated_at", + "user_id", + "version", + "workspace_key", + "workspace_name" + ], + "type": "object" + } + }, + "required": [ + "data" + ], + "type": "object" + }, "PatchTimeWorklogsWorklogIdPayload": { "additionalProperties": false, "properties": { @@ -89531,16 +89955,36 @@ ], "type": "object" }, + "PostTimeTimersActiveStopPayload": { + "additionalProperties": false, + "properties": { + "timer_id": { + "description": "The timer id value.", + "nullable": true, + "type": "integer" + } + }, + "type": "object" + }, "PostTimeTimersActiveStopResult": { "additionalProperties": false, "properties": { "data": { "additionalProperties": false, "properties": { + "booked": { + "description": "The booked value.", + "type": "boolean" + }, "description": { "description": "The description value.", "type": "string" }, + "draft_id": { + "description": "The draft id value.", + "nullable": true, + "type": "integer" + }, "duration_minutes": { "description": "The duration minutes value.", "type": "integer" @@ -89557,18 +90001,19 @@ "description": "The timer id value.", "type": "integer" }, - "worklog_created": { - "description": "The worklog created value.", - "type": "boolean" + "worklog_id": { + "description": "The worklog id value.", + "nullable": true, + "type": "integer" } }, "required": [ + "booked", "description", "duration_minutes", "duration_seconds", "stopped", - "timer_id", - "worklog_created" + "timer_id" ], "type": "object" } @@ -89592,6 +90037,7 @@ }, "project_id": { "description": "The project id value.", + "nullable": true, "type": "integer" }, "workspace_id": { @@ -89601,7 +90047,6 @@ }, "required": [ "description", - "project_id", "workspace_id" ], "type": "object" @@ -89647,6 +90092,7 @@ }, "project_id": { "description": "The project id value.", + "nullable": true, "type": "integer" }, "project_name": { @@ -89686,7 +90132,6 @@ "created_at", "description", "id", - "project_id", "start_time_utc", "user_id", "workspace_id" @@ -89699,6 +90144,202 @@ ], "type": "object" }, + "PostTimeWorklogDraftsDraftIdBookPayload": { + "additionalProperties": false, + "properties": { + "date": { + "description": "The date value.", + "type": "string" + }, + "description": { + "description": "The description value.", + "type": "string" + }, + "duration": { + "description": "The duration value.", + "type": "string" + }, + "duration_minutes": { + "description": "The duration minutes value.", + "type": "integer" + }, + "end_time": { + "description": "The end time value.", + "type": "string" + }, + "idempotency_key": { + "description": "The idempotency key value.", + "type": "string" + }, + "item_id": { + "description": "The item id value.", + "nullable": true, + "type": "integer" + }, + "project_id": { + "description": "The project id value.", + "nullable": true, + "type": "integer" + }, + "start_time": { + "description": "The start time value.", + "type": "string" + }, + "timezone": { + "description": "The timezone value.", + "type": "string" + }, + "version": { + "description": "The version value.", + "type": "integer" + } + }, + "required": [ + "date", + "description", + "duration", + "duration_minutes", + "end_time", + "idempotency_key", + "start_time", + "timezone", + "version" + ], + "type": "object" + }, + "PostTimeWorklogDraftsDraftIdBookResult": { + "additionalProperties": false, + "properties": { + "data": { + "additionalProperties": false, + "properties": { + "created_at": { + "description": "The created at value.", + "type": "integer" + }, + "customer_builtin_key": { + "description": "The customer builtin key value.", + "type": "string" + }, + "customer_id": { + "description": "The customer id value.", + "type": "integer" + }, + "customer_name": { + "description": "The customer name value.", + "type": "string" + }, + "date": { + "description": "The date value.", + "type": "integer" + }, + "description": { + "description": "The description value.", + "type": "string" + }, + "duration_minutes": { + "description": "The duration minutes value.", + "type": "integer" + }, + "end_time": { + "description": "The end time value.", + "type": "integer" + }, + "id": { + "description": "The id value.", + "type": "integer" + }, + "item_id": { + "description": "The item id value.", + "nullable": true, + "type": "integer" + }, + "item_title": { + "description": "The item title value.", + "type": "string" + }, + "project_id": { + "description": "The project id value.", + "type": "integer" + }, + "project_max_hours": { + "description": "The project max hours value.", + "nullable": true, + "type": "number" + }, + "project_name": { + "description": "The project name value.", + "type": "string" + }, + "project_total_hours": { + "description": "The project total hours value.", + "nullable": true, + "type": "number" + }, + "start_time": { + "description": "The start time value.", + "type": "integer" + }, + "updated_at": { + "description": "The updated at value.", + "type": "integer" + }, + "user_id": { + "description": "The user id value.", + "nullable": true, + "type": "integer" + }, + "user_name": { + "description": "The user name value.", + "type": "string" + }, + "warnings": { + "description": "The warnings value.", + "items": { + "type": "string" + }, + "type": "array" + }, + "workspace_id": { + "description": "The workspace id value.", + "nullable": true, + "type": "integer" + }, + "workspace_item_number": { + "description": "The workspace item number value.", + "type": "integer" + }, + "workspace_key": { + "description": "The workspace key value.", + "type": "string" + } + }, + "required": [ + "created_at", + "customer_id", + "customer_name", + "date", + "description", + "duration_minutes", + "end_time", + "id", + "item_title", + "project_id", + "project_name", + "start_time", + "updated_at", + "user_name", + "workspace_item_number", + "workspace_key" + ], + "type": "object" + } + }, + "required": [ + "data" + ], + "type": "object" + }, "PostTimeWorklogsPayload": { "additionalProperties": false, "properties": { @@ -120913,6 +121554,16 @@ "description": "Stop timer. The server validates resource ownership and command preconditions before persisting changes. Unknown JSON fields are rejected when the operation accepts a body.", "operationId": "postTimeTimersActiveStop", "parameters": [], + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/PostTimeTimersActiveStopPayload" + } + } + }, + "required": true + }, "responses": { "200": { "content": { @@ -120924,6 +121575,9 @@ }, "description": "Stop timer response." }, + "400": { + "$ref": "#/components/responses/InvalidRequestError" + }, "401": { "$ref": "#/components/responses/AuthenticationError" }, @@ -120933,6 +121587,12 @@ "404": { "$ref": "#/components/responses/NotFoundError" }, + "413": { + "$ref": "#/components/responses/PayloadTooLargeError" + }, + "415": { + "$ref": "#/components/responses/UnsupportedMediaTypeError" + }, "429": { "$ref": "#/components/responses/RateLimitError" }, @@ -120954,6 +121614,304 @@ ] } }, + "/time/worklog-drafts": { + "get": { + "description": "List draft worklogs. Results include only resources visible to the authenticated caller; collections use their documented stable order and bounds.", + "operationId": "getTimeWorklogDrafts", + "parameters": [], + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/GetTimeWorklogDraftsResult" + } + } + }, + "description": "List draft worklogs response." + }, + "401": { + "$ref": "#/components/responses/AuthenticationError" + }, + "403": { + "$ref": "#/components/responses/PermissionError" + }, + "429": { + "$ref": "#/components/responses/RateLimitError" + }, + "500": { + "$ref": "#/components/responses/InternalError" + } + }, + "security": [ + { + "BearerAuth": [] + } + ], + "summary": "List draft worklogs", + "tags": [ + "Time tracking" + ], + "x-required-scopes": [ + "time:read" + ] + } + }, + "/time/worklog-drafts/{draft_id}": { + "delete": { + "description": "Delete a draft worklog. The server verifies resource ownership and deletion preconditions before removing the resource.", + "operationId": "deleteTimeWorklogDraftsDraftId", + "parameters": [ + { + "description": "The draft worklog identifier.", + "in": "path", + "name": "draft_id", + "required": true, + "schema": { + "minimum": 1, + "type": "integer" + } + } + ], + "responses": { + "204": { + "description": "Request completed successfully with no response body." + }, + "401": { + "$ref": "#/components/responses/AuthenticationError" + }, + "403": { + "$ref": "#/components/responses/PermissionError" + }, + "404": { + "$ref": "#/components/responses/NotFoundError" + }, + "429": { + "$ref": "#/components/responses/RateLimitError" + }, + "500": { + "$ref": "#/components/responses/InternalError" + } + }, + "security": [ + { + "BearerAuth": [] + } + ], + "summary": "Delete a draft worklog", + "tags": [ + "Time tracking" + ], + "x-required-scopes": [ + "time:write" + ] + }, + "get": { + "description": "Get a draft worklog. Results include only resources visible to the authenticated caller; collections use their documented stable order and bounds.", + "operationId": "getTimeWorklogDraftsDraftId", + "parameters": [ + { + "description": "The draft worklog identifier.", + "in": "path", + "name": "draft_id", + "required": true, + "schema": { + "minimum": 1, + "type": "integer" + } + } + ], + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/GetTimeWorklogDraftsDraftIdResult" + } + } + }, + "description": "Get a draft worklog response." + }, + "401": { + "$ref": "#/components/responses/AuthenticationError" + }, + "403": { + "$ref": "#/components/responses/PermissionError" + }, + "404": { + "$ref": "#/components/responses/NotFoundError" + }, + "429": { + "$ref": "#/components/responses/RateLimitError" + }, + "500": { + "$ref": "#/components/responses/InternalError" + } + }, + "security": [ + { + "BearerAuth": [] + } + ], + "summary": "Get a draft worklog", + "tags": [ + "Time tracking" + ], + "x-required-scopes": [ + "time:read" + ] + }, + "patch": { + "description": "Update a draft worklog. The operation uses JSON Merge Patch: omitted fields remain unchanged and documented nullable fields accept null. Unknown fields are rejected.", + "operationId": "patchTimeWorklogDraftsDraftId", + "parameters": [ + { + "description": "The draft worklog identifier.", + "in": "path", + "name": "draft_id", + "required": true, + "schema": { + "minimum": 1, + "type": "integer" + } + } + ], + "requestBody": { + "content": { + "application/merge-patch+json": { + "schema": { + "$ref": "#/components/schemas/PatchTimeWorklogDraftsDraftIdPayload" + } + } + }, + "required": true + }, + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/PatchTimeWorklogDraftsDraftIdResult" + } + } + }, + "description": "Update a draft worklog response." + }, + "400": { + "$ref": "#/components/responses/InvalidRequestError" + }, + "401": { + "$ref": "#/components/responses/AuthenticationError" + }, + "403": { + "$ref": "#/components/responses/PermissionError" + }, + "404": { + "$ref": "#/components/responses/NotFoundError" + }, + "413": { + "$ref": "#/components/responses/PayloadTooLargeError" + }, + "415": { + "$ref": "#/components/responses/UnsupportedMediaTypeError" + }, + "429": { + "$ref": "#/components/responses/RateLimitError" + }, + "500": { + "$ref": "#/components/responses/InternalError" + } + }, + "security": [ + { + "BearerAuth": [] + } + ], + "summary": "Update a draft worklog", + "tags": [ + "Time tracking" + ], + "x-required-scopes": [ + "time:write" + ] + } + }, + "/time/worklog-drafts/{draft_id}/book": { + "post": { + "description": "Book a draft worklog. The server validates resource ownership and command preconditions before persisting changes. Unknown JSON fields are rejected when the operation accepts a body.", + "operationId": "postTimeWorklogDraftsDraftIdBook", + "parameters": [ + { + "description": "The draft worklog identifier.", + "in": "path", + "name": "draft_id", + "required": true, + "schema": { + "minimum": 1, + "type": "integer" + } + } + ], + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/PostTimeWorklogDraftsDraftIdBookPayload" + } + } + }, + "required": true + }, + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/PostTimeWorklogDraftsDraftIdBookResult" + } + } + }, + "description": "Book a draft worklog response." + }, + "400": { + "$ref": "#/components/responses/InvalidRequestError" + }, + "401": { + "$ref": "#/components/responses/AuthenticationError" + }, + "403": { + "$ref": "#/components/responses/PermissionError" + }, + "404": { + "$ref": "#/components/responses/NotFoundError" + }, + "413": { + "$ref": "#/components/responses/PayloadTooLargeError" + }, + "415": { + "$ref": "#/components/responses/UnsupportedMediaTypeError" + }, + "429": { + "$ref": "#/components/responses/RateLimitError" + }, + "500": { + "$ref": "#/components/responses/InternalError" + } + }, + "security": [ + { + "BearerAuth": [] + } + ], + "summary": "Book a draft worklog", + "tags": [ + "Time tracking" + ], + "x-required-scopes": [ + "time:write" + ] + } + }, "/time/worklogs": { "get": { "description": "List worklogs. Results include only resources visible to the authenticated caller; collections use their documented stable order and bounds.", diff --git a/frontend/src/lib/api/time.js b/frontend/src/lib/api/time.js index 057073d9a..82e114c44 100644 --- a/frontend/src/lib/api/time.js +++ b/frontend/src/lib/api/time.js @@ -90,6 +90,25 @@ export const time = { getByItem: (itemId, requestOptions = {}) => fetchAllV2Pages(`/items/${itemId}/worklogs`, requestOptions), }, + + // Draft worklogs: incomplete, user-owned entries produced when a timer stops + // without booking information. Booked entries leave this list. + worklogDrafts: { + getAll: (requestOptions = {}) => fetchV2Data('/time/worklog-drafts', requestOptions), + get: (id, requestOptions = {}) => fetchV2Data(`/time/worklog-drafts/${id}`, requestOptions), + update: (id, data) => + fetchV2Data(`/time/worklog-drafts/${id}`, { + method: 'PATCH', + headers: { 'Content-Type': 'application/merge-patch+json' }, + body: JSON.stringify(data), + }), + book: (id, data) => + fetchV2Data(`/time/worklog-drafts/${id}/book`, { + method: 'POST', + body: JSON.stringify(data), + }), + delete: (id) => fetchV2Data(`/time/worklog-drafts/${id}`, { method: 'DELETE' }), + }, }; export const timer = { @@ -99,8 +118,9 @@ export const timer = { body: JSON.stringify(data), }), getActive: () => fetchV2Data('/time/timers/active'), - stop: () => + stop: (timerId = null) => fetchV2Data('/time/timers/active/stop', { method: 'POST', + body: JSON.stringify(timerId ? { timer_id: timerId } : {}), }), }; diff --git a/frontend/src/lib/commands/providers/timeProvider.js b/frontend/src/lib/commands/providers/timeProvider.js index 91bd28693..c81206a94 100644 --- a/frontend/src/lib/commands/providers/timeProvider.js +++ b/frontend/src/lib/commands/providers/timeProvider.js @@ -1,4 +1,5 @@ -import { navigate } from '../../router.js'; +import { stopTimerAndReview } from '../../features/time/stopTimerAndReview.js'; +import { timeLogStore } from '../../stores/timeLogStore.svelte.js'; import { timerStore } from '../../stores/timerStore.svelte.js'; import { errorToast, infoToast, warningToast } from '../../stores/toasts.svelte.js'; import { BUCKET } from '../buckets.js'; @@ -40,10 +41,7 @@ export function timeProvider(ctx) { bucket: BUCKET.MODULE_ACTIONS, keywords: ['log', 'time', 'entry', 'hours', 'work', 'track', 'add'], execute: () => { - navigate('/time'); - setTimeout(() => { - window.dispatchEvent(new CustomEvent('focus-time-entry-form')); - }, 100); + timeLogStore.open(); }, }), ]; @@ -76,7 +74,7 @@ export function timeProvider(ctx) { execute: async () => { if (timerStore.canStop) { try { - await timerStore.stop(); + await stopTimerAndReview(timerStore, timeLogStore); } catch (err) { errorToast(t('dialogs.alerts.stopTimerFailed', { error: err.message })); } diff --git a/frontend/src/lib/dialogs/TimeLogModal.svelte b/frontend/src/lib/dialogs/TimeLogModal.svelte index 9a4821499..844c5dc6e 100644 --- a/frontend/src/lib/dialogs/TimeLogModal.svelte +++ b/frontend/src/lib/dialogs/TimeLogModal.svelte @@ -35,8 +35,10 @@ workItems = [], workspaces = [], editingWorklog = null, + draft = null, onsave = () => {}, - oncancel = () => {} + oncancel = () => {}, + ondiscard = null } = $props(); // One explicit timezone populates and interprets every form control, so @@ -55,18 +57,22 @@ } const durationSync = createDurationSync(); // Guarded updates to avoid recursive time sync + // Worklogs and drafts share the same field names (absolute unix timestamps + // plus duration_minutes), so one source record drives the editable form. + const sourceRecord = editingWorklog ?? draft ?? null; + const isDraft = $derived(!!draft && !editingWorklog); // Snapshot props for the editable form; updates are then user-driven, not prop-driven. // svelte-ignore state_referenced_locally let formData = $state({ - project_id: editingWorklog?.project_id ?? defaultProjectId, - item_id: editingWorklog?.item_id ?? defaultItemId, - description: editingWorklog?.description ?? '', - date: editingWorklog - ? dateKeyInZone(editingWorklog.start_time, formTimezone) + project_id: sourceRecord?.project_id ?? defaultProjectId, + item_id: sourceRecord?.item_id ?? defaultItemId, + description: sourceRecord?.description ?? '', + date: sourceRecord + ? dateKeyInZone(sourceRecord.date ?? sourceRecord.start_time, formTimezone) : (defaultDate ?? dateKeyInZone(Date.now() / 1000, formTimezone)), - start_time: editingWorklog ? formatClockInZone(editingWorklog.start_time, formTimezone) : (defaultStartTime ?? ''), - end_time: editingWorklog ? formatClockInZone(editingWorklog.end_time, formTimezone) : '', - duration: editingWorklog ? formatDurationFromMinutes(editingWorklog.duration_minutes) : '' + start_time: sourceRecord?.start_time != null ? formatClockInZone(sourceRecord.start_time, formTimezone) : (defaultStartTime ?? ''), + end_time: sourceRecord?.end_time != null ? formatClockInZone(sourceRecord.end_time, formTimezone) : '', + duration: sourceRecord?.duration_minutes != null ? formatDurationFromMinutes(sourceRecord.duration_minutes) : '' }); // Time fields the form was opened with; an edit that leaves them untouched @@ -244,7 +250,7 @@ > {#snippet children(submitHint)} - +
@@ -394,10 +400,23 @@ + > + {#snippet extra()} + {#if isDraft && ondiscard} + + {/if} + {/snippet} + {/snippet} diff --git a/frontend/src/lib/features/items/ItemDetail.svelte b/frontend/src/lib/features/items/ItemDetail.svelte index eb4c3d16d..629a71aa4 100644 --- a/frontend/src/lib/features/items/ItemDetail.svelte +++ b/frontend/src/lib/features/items/ItemDetail.svelte @@ -17,6 +17,7 @@ import { publicBaseURL } from '../../runtime/contextPath.js'; import { workspacePermissions } from '../../stores/workspacePermissions.svelte.js'; import { itemDetailStore } from '../../stores/itemDetailStore.svelte.js'; + import { timeLogStore } from '../../stores/timeLogStore.svelte.js'; import { t } from '../../stores/i18n.svelte.js'; import { getShortcut, matchesShortcut, isTypingInField } from '../../utils/keyboardShortcuts.js'; import Trash2 from '@lucide/svelte/icons/trash-2'; @@ -58,7 +59,6 @@ import ItemSplitDialog from './ItemSplitDialog.svelte'; // Import the shared content component import ItemDetailContent from '../items/ItemDetailContent.svelte'; -import TimeLogModal from '../../dialogs/TimeLogModal.svelte'; import TestCaseViewModal from '../../dialogs/TestCaseViewModal.svelte'; import RecurrenceEditor from '../../editors/RecurrenceEditor.svelte'; import Button from '../../components/Button.svelte'; @@ -643,13 +643,20 @@ import NativeSelect from '../../components/NativeSelect.svelte'; } async function handleLogTime() { - await itemDetailStore.loadTimeModalData(); - itemDetailStore.openTimeLogModal(); + await timeLogStore.open({ + itemId: parseInt(itemId), + defaultProjectId: getDefaultProjectForTimeLogging(), + showWorkItemField: false, + }); } async function handleEditWorklog(detail) { - await itemDetailStore.loadTimeModalData(); - itemDetailStore.openTimeLogModal(detail); + await timeLogStore.open({ + itemId: parseInt(itemId), + defaultProjectId: getDefaultProjectForTimeLogging(), + showWorkItemField: false, + editingWorklog: detail, + }); } async function handleDeleteWorklog(detail) { @@ -664,28 +671,6 @@ import NativeSelect from '../../components/NativeSelect.svelte'; } } - async function handleModalSave(event) { - try { - const data = event.detail; - if (itemDetailStore.editingWorklog) { - await time.worklogs.update(itemDetailStore.editingWorklog.id, data); - } else { - await time.worklogs.create(data); - } - - // Reload worklogs - await itemDetailStore.reloadWorklogs(); - itemDetailStore.closeTimeLogModal(); - } catch (error) { - console.error('Failed to save worklog:', error); - showError(t('items.failedToSaveTimeEntry'), error.message || t('errors.UNKNOWN')); - } - } - - function handleModalCancel() { - itemDetailStore.closeTimeLogModal(); - } - // Get default project for time logging function getDefaultProjectForTimeLogging() { return itemDetailStore.getDefaultProjectForTimeLogging(); @@ -1182,16 +1167,12 @@ import NativeSelect from '../../components/NativeSelect.svelte'; description: 'Add a time entry for this work item', keywords: ['log', 'time', 'hours', 'work', 'track', 'entry'], action: () => { - // Trigger the time entry form in the tabs component - if (tab !== 'time') { - tab = 'time'; - } - // Use a small delay to ensure tab is switched - setTimeout(() => { - window.dispatchEvent(new CustomEvent('item-detail-show-time-entry', { - detail: { itemId: item.id } - })); - }, 100); + // Open the shared time-log surface prefilled with this item. + void timeLogStore.open({ + itemId: item.id, + defaultProjectId: getDefaultProjectForTimeLogging(), + showWorkItemField: false, + }); }, priority: COMMAND_PRIORITIES.HIGH, category: 'time' @@ -1263,6 +1244,18 @@ import NativeSelect from '../../components/NativeSelect.svelte'; itemDetailStore.item && populateDropdownItems(); }); + // Reload worklogs after the shared time-log host saves or books an entry. + let lastTimeLogRevision = 0; + $effect(() => { + const revision = timeLogStore.revision; + if (revision !== lastTimeLogRevision) { + lastTimeLogRevision = revision; + itemDetailStore.reloadWorklogs().catch((err) => { + surfaceError(err, { context: 'reloadWorklogsAfterTimeLog' }); + }); + } + }); + // Reload worklogs when timer stops (activeTimer becomes null from non-null) let previousActiveTimer; // Plain variable, not reactive - prevents self-invalidation $effect(() => { @@ -1592,23 +1585,7 @@ import NativeSelect from '../../components/NativeSelect.svelte'; {/if} {/if} - -{#if itemDetailStore.showTimeLogModal} - -{/if} + + import Button from '../../components/Button.svelte'; + import Card from '../../components/Card.svelte'; + import { t } from '../../stores/i18n.svelte.js'; + import { errorToast } from '../../stores/toasts.svelte.js'; + import { timeLogStore } from '../../stores/timeLogStore.svelte.js'; + + let { class: className = '' } = $props(); + + function formatDuration(minutes) { + if (!minutes) return ''; + const hours = Math.floor(minutes / 60); + const mins = minutes % 60; + if (hours === 0) return `${mins}m`; + if (mins === 0) return `${hours}h`; + return `${hours}h ${mins}m`; + } + + function draftLabel(draft) { + return draft.item_title || draft.description || draft.project_name || t('time.drafts'); + } + + async function complete(draft) { + try { + await timeLogStore.openDraft(draft.id); + } catch (error) { + console.error('Failed to open draft:', error); + errorToast(t('time.bookFailed')); + } + } + + async function discard(draft) { + try { + await timeLogStore.removeDraft(draft.id); + } catch (error) { + console.error('Failed to discard draft:', error); + errorToast(t('time.discardFailed')); + } + } + + +{#if timeLogStore.drafts.length > 0} +
+ +

+ {t('time.drafts')} ({timeLogStore.drafts.length}) +

+
    + {#each timeLogStore.drafts as draft (draft.id)} +
  • +
    +
    {draftLabel(draft)}
    +
    + {#if draft.project_name}{draft.project_name} · {/if} + {formatDuration(draft.duration_minutes)} +
    +
    + + +
  • + {/each} +
+
+
+{/if} diff --git a/frontend/src/lib/features/time/TimeEntry.svelte b/frontend/src/lib/features/time/TimeEntry.svelte index 625ee868b..0a7c4e996 100644 --- a/frontend/src/lib/features/time/TimeEntry.svelte +++ b/frontend/src/lib/features/time/TimeEntry.svelte @@ -7,6 +7,7 @@ import AlertBox from '../../components/AlertBox.svelte'; import { navigate } from '../../router.js'; import { timeEntryStore } from '../../stores/timeEntryStore.svelte.js'; + import { timeLogStore } from '../../stores/timeLogStore.svelte.js'; import { permissionStore, isSystemAdmin } from '../../stores/permissions.svelte.js'; import Button from '../../components/Button.svelte'; import Input from '../../components/Input.svelte'; @@ -14,11 +15,10 @@ import DataTable from '../../components/DataTable.svelte'; import Card from '../../components/Card.svelte'; import TimeTrackingOnboarding from './TimeTrackingOnboarding.svelte'; - import TimeLogModal from '../../dialogs/TimeLogModal.svelte'; + import TimeDraftsCard from './TimeDraftsCard.svelte'; import { toHotkeyString } from '../../utils/keyboardShortcuts.js'; import { t } from '../../stores/i18n.svelte.js'; import { customerOrganisationName, realCustomers } from '../../utils/customerLabel.js'; - import { errorToast } from '../../stores/toasts.svelte.js'; import { confirm } from '../../composables/useConfirm.js'; import { formatDateOnly, getUserTimezone } from '../../utils/dateFormatter.js'; import { dateKeyInZone } from '../../utils/worklogTimezone.js'; @@ -28,12 +28,7 @@ // Bind to store values let worklogs = $derived(timeEntryStore.worklogs); let customers = $derived(timeEntryStore.customers); - let projects = $derived(timeEntryStore.projects); - let workItems = $derived(timeEntryStore.workItems); - let workspaces = $derived(timeEntryStore.workspaces); - let editingWorklog = $derived(timeEntryStore.editingWorklog); let showOnboarding = $derived(timeEntryStore.showOnboarding); - let showTimeLogModal = $derived(timeEntryStore.showTimeLogModal); let filters = $derived(timeEntryStore.filters); let activeProjects = $derived(timeEntryStore.activeProjects); let filteredProjects = $derived(timeEntryStore.filteredProjects); @@ -51,6 +46,7 @@ onMount(async () => { await timeEntryStore.init(); + void timeLogStore.refreshDrafts(); }); function buildWorklogDropdownItems(worklog) { @@ -62,7 +58,7 @@ title: t('common.edit'), testid: 'worklog-edit', hoverClass: 'hover-bg', - onClick: () => timeEntryStore.editWorklog(worklog) + onClick: () => timeLogStore.open({ editingWorklog: worklog }) }, { id: 'delete', @@ -76,24 +72,20 @@ ]; } - async function handleModalSave(event) { - try { - const data = event.detail; - await timeEntryStore.saveWorklog(data); - } catch (error) { - console.error('Failed to save worklog:', error); - errorToast(t('time.entry.failedToSave')); - } - } - - function handleModalCancel() { - timeEntryStore.closeTimeLogModal(); - } - function openLogTimeModal() { - timeEntryStore.openTimeLogModal(); + timeLogStore.open(); } + // Reload the page list after the shared host saves or books an entry. + let lastTimeLogRevision = 0; + $effect(() => { + const revision = timeLogStore.revision; + if (revision !== lastTimeLogRevision) { + lastTimeLogRevision = revision; + timeEntryStore.loadWorklogs(); + } + }); + async function deleteWorklog(worklog) { const confirmed = await confirm({ title: t('common.delete'), @@ -162,7 +154,7 @@ icon={Plus} onclick={openLogTimeModal} keyboardHint="A" - hotkeyConfig={{ key: toHotkeyString('timeEntry', 'openLog'), guard: () => !showTimeLogModal }} + hotkeyConfig={{ key: toHotkeyString('timeEntry', 'openLog'), guard: () => !timeLogStore.show }} title={t('time.entry.addTimeEntry')} dataTestid="time-log-open" > @@ -301,15 +293,6 @@ {/if} - -{#if showTimeLogModal} - -{/if} + + + diff --git a/frontend/src/lib/features/time/TimeLogHost.svelte b/frontend/src/lib/features/time/TimeLogHost.svelte new file mode 100644 index 000000000..0336fbac4 --- /dev/null +++ b/frontend/src/lib/features/time/TimeLogHost.svelte @@ -0,0 +1,63 @@ + + +{#if timeLogStore.show} + timeLogStore.close()} + ondiscard={handleDiscard} + /> +{/if} diff --git a/frontend/src/lib/features/time/stopTimerAndReview.js b/frontend/src/lib/features/time/stopTimerAndReview.js new file mode 100644 index 000000000..6b44c731d --- /dev/null +++ b/frontend/src/lib/features/time/stopTimerAndReview.js @@ -0,0 +1,19 @@ +import { t } from '../../stores/i18n.svelte.js'; +import { successToast } from '../../stores/toasts.svelte.js'; + +/** + * Stop the active timer and route the result: a complete entry is booked + * silently, an incomplete one is persisted as a draft and opened in the shared + * time-log modal for completion. Shared by the floating timer, the palette + * stop command, and the mobile timer view. + */ +export async function stopTimerAndReview(timerStore, timeLogStore) { + const result = await timerStore.stop(); + if (!result) return null; + if (result.booked) { + successToast(t('time.timeBooked')); + } else if (result.draft_id) { + await timeLogStore.openDraft(result.draft_id); + } + return result; +} diff --git a/frontend/src/lib/layout/MainSidebar.svelte b/frontend/src/lib/layout/MainSidebar.svelte index 49c73fa28..3c23c113b 100644 --- a/frontend/src/lib/layout/MainSidebar.svelte +++ b/frontend/src/lib/layout/MainSidebar.svelte @@ -5,6 +5,7 @@ import { uiStore } from '../stores/ui.svelte.js'; import { workspacesStore } from '../stores/workspaces.svelte.js'; import { homepageStore } from '../stores/homepageStore.svelte.js'; + import { timeLogStore } from '../stores/timeLogStore.svelte.js'; import { t } from '../stores/i18n.svelte.js'; import { themeStore } from '../stores/theme.svelte.js'; import { brandStore, resolveBrandLockup } from '../stores/brand.svelte.js'; @@ -13,6 +14,7 @@ import { workspaceMenuItems } from '../navigation/workspaceMenu.js'; import { isTauri as getIsTauri } from '../utils/isTauri.js'; import DropdownMenu from './DropdownMenu.svelte'; + import TimeNavMenu from './TimeNavMenu.svelte'; import Tooltip from '../components/Tooltip.svelte'; import NavLink from './NavLink.svelte'; import UserAvatar from '../components/UserAvatar.svelte'; @@ -86,6 +88,7 @@ // recency order. onOpen still refreshes it so recent navigation is reflected. onMount(() => { void loadRecentWorkspaceOrder(); + void timeLogStore.refreshDrafts(); }); function onWorkspaceSearchInput(value) { @@ -220,15 +223,19 @@ {#each filteredMainNav as item (item.id)} - + {#if item.id === 'time'} + + {:else} + + {/if} {/each} + + + diff --git a/frontend/src/lib/mobile/TimerView.svelte b/frontend/src/lib/mobile/TimerView.svelte index 28fd43ee8..b6b069c2b 100644 --- a/frontend/src/lib/mobile/TimerView.svelte +++ b/frontend/src/lib/mobile/TimerView.svelte @@ -9,11 +9,13 @@ import CommandIcon from '@lucide/svelte/icons/command'; import { timerStore } from '../stores/timerStore.svelte.js'; import { timeEntryStore } from '../stores/timeEntryStore.svelte.js'; + import { timeLogStore } from '../stores/timeLogStore.svelte.js'; import { confirm } from '../composables/useConfirm.js'; import { t } from '../stores/i18n.svelte.js'; import { formatItemKey } from '../utils/itemKey.js'; import MobileHeader from './MobileHeader.svelte'; - import TimeLogModal from '../dialogs/TimeLogModal.svelte'; + import TimeDraftsCard from '../features/time/TimeDraftsCard.svelte'; + import { stopTimerAndReview } from '../features/time/stopTimerAndReview.js'; import { formatAuthenticatedInstant } from '../utils/authenticatedDateFormatter.js'; import { mobilePalette } from './mobilePalette.svelte.js'; @@ -31,7 +33,7 @@ async function stopTimer() { try { - await timerStore.stop(); + await stopTimerAndReview(timerStore, timeLogStore); await timeEntryStore.loadWorklogs(); } catch (err) { console.error('Failed to stop timer:', err); @@ -52,6 +54,7 @@ onMount(() => { timeEntryStore.init(); + void timeLogStore.refreshDrafts(); }); @@ -97,7 +100,7 @@

{t('mobile.timer.recentWorklogs')}

-
@@ -110,7 +113,7 @@
    {#each worklogs as w (w.id)}
  • -
{/if}
-
- -{#if timeEntryStore.showTimeLogModal} - timeEntryStore.saveWorklog(e.detail)} - oncancel={() => timeEntryStore.closeTimeLogModal()} - /> -{/if} + + +