From 3469232d3bd053b3894372e43396b0d6f4cf6d5e Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Mon, 26 Feb 2024 14:39:48 +0100 Subject: [PATCH] fixed some issues with how and when entry content is displayed closes #36 --- src/tracker.ts | 35 ++++++++++++++---------- test-vault/duration_accumulation_test.md | 6 +++- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/tracker.ts b/src/tracker.ts index b18890b..eac1728 100644 --- a/src/tracker.ts +++ b/src/tracker.ts @@ -237,7 +237,7 @@ function formatDuration(totalTime: number, settings: SimpleTimeTrackerSettings): function fixLegacyTimestamps(entries: Entry[]): void { for (let entry of entries) { - if (!isNaN(+entry.startTime)) + if (entry.startTime && !isNaN(+entry.startTime)) entry.startTime = moment.unix(+entry.startTime).toISOString(); if (entry.endTime && !isNaN(+entry.endTime)) entry.endTime = moment.unix(+entry.endTime).toISOString(); @@ -362,7 +362,8 @@ class EditableTimestampField extends EditableField { } } -function addEditableTableRow(tracker: Tracker, entry: Entry, table: HTMLTableElement, newSegmentNameBox: TextComponent, running: boolean, file: string, getSectionInfo: () => MarkdownSectionInformation, settings: SimpleTimeTrackerSettings, indent: number): void { +function addEditableTableRow(tracker: Tracker, entry: Entry, table: HTMLTableElement, newSegmentNameBox: TextComponent, trackerRunning: boolean, file: string, getSectionInfo: () => MarkdownSectionInformation, settings: SimpleTimeTrackerSettings, indent: number): void { + let entryRunning = getRunningEntry(tracker.entries) == entry; let row = table.createEl("tr"); let nameField = new EditableField(row, indent, entry.name); @@ -372,20 +373,20 @@ function addEditableTableRow(tracker: Tracker, entry: Entry, table: HTMLTableEle row.createEl("td", {text: entry.endTime || entry.subEntries ? formatDuration(getDuration(entry), settings) : ""}); let entryButtons = row.createEl("td"); - if (!running) { - new ButtonComponent(entryButtons) - .setClass("clickable-icon") - .setIcon(`lucide-play`) - .setTooltip("Continue") - .onClick(async () => { - startSubEntry(entry, newSegmentNameBox.getValue()); - await saveTracker(tracker, this.app, file, getSectionInfo()); - }); - } + new ButtonComponent(entryButtons) + .setClass("clickable-icon") + .setIcon(`lucide-play`) + .setTooltip("Continue") + .setDisabled(trackerRunning) + .onClick(async () => { + startSubEntry(entry, newSegmentNameBox.getValue()); + await saveTracker(tracker, this.app, file, getSectionInfo()); + }); let editButton = new ButtonComponent(entryButtons) .setClass("clickable-icon") .setTooltip("Edit") .setIcon("lucide-pencil") + .setDisabled(entryRunning) .onClick(async () => { if (nameField.editing()) { entry.name = nameField.endEdit(); @@ -397,8 +398,11 @@ function addEditableTableRow(tracker: Tracker, entry: Entry, table: HTMLTableEle editButton.setIcon("lucide-pencil"); } else { nameField.beginEdit(entry.name); - startField.beginEdit((entry.startTime)); - endField.beginEdit((entry.endTime)); + // only allow editing start and end times if we don't have sub entries + if (!entry.subEntries) { + startField.beginEdit(entry.startTime); + endField.beginEdit(entry.endTime); + } editButton.setIcon("lucide-check"); } }); @@ -406,6 +410,7 @@ function addEditableTableRow(tracker: Tracker, entry: Entry, table: HTMLTableEle .setClass("clickable-icon") .setTooltip("Remove") .setIcon("lucide-trash") + .setDisabled(entryRunning) .onClick(async () => { removeEntry(tracker.entries, entry); await saveTracker(tracker, this.app, file, getSectionInfo()); @@ -413,6 +418,6 @@ function addEditableTableRow(tracker: Tracker, entry: Entry, table: HTMLTableEle if (entry.subEntries) { for (let sub of orderedEntries(entry.subEntries, settings)) - addEditableTableRow(tracker, sub, table, newSegmentNameBox, running, file, getSectionInfo, settings, indent + 1); + addEditableTableRow(tracker, sub, table, newSegmentNameBox, trackerRunning, file, getSectionInfo, settings, indent + 1); } } diff --git a/test-vault/duration_accumulation_test.md b/test-vault/duration_accumulation_test.md index 4a760b0..c5773f2 100644 --- a/test-vault/duration_accumulation_test.md +++ b/test-vault/duration_accumulation_test.md @@ -2,5 +2,9 @@ More notes for my cool project! This note shows that we can correctly display accumulated time that lasts longer than a 24 hour day! ```simple-time-tracker -{"entries":[{"name":"test","startTime":"2020-08-01T07:00:00.000Z","endTime":"2021-08-02T07:00:00.000Z","subEntries":null},{"name":"test","startTime":"2021-08-01T07:00:00.000Z","endTime":"2021-10-02T07:00:00.000Z","subEntries":null},{"name":"test","startTime":"1970-01-01T00:00:00.000Z","endTime":null,"subEntries":[{"name":"Part 1","startTime":"2022-08-01T07:00:00.000Z","endTime":"2022-08-02T07:00:00.000Z","subEntries":null},{"name":"Part 2","startTime":"2024-02-26T13:19:40.629Z","endTime":"2024-02-26T13:19:43.713Z","subEntries":null},{"name":"Part 3","startTime":"2024-02-26T13:23:51.939Z","endTime":"2024-02-26T13:23:54.232Z","subEntries":null}]},{"name":"test","startTime":"2022-10-01T12:30:10.000Z","endTime":"2022-10-01T13:40:05.000Z","subEntries":null},{"name":"Segment 5","startTime":"2023-05-23T16:16:56.000Z","endTime":"2023-05-23T16:16:59.000Z","subEntries":null}]} +{"entries":[{"name":"test","startTime":"2020-08-01T07:00:00.000Z","endTime":"2021-08-02T07:00:00.000Z","subEntries":null},{"name":"test","startTime":"2021-08-01T07:00:00.000Z","endTime":"2021-10-02T07:00:00.000Z","subEntries":null},{"name":"test","startTime":"1970-01-01T00:00:00.000Z","endTime":null,"subEntries":[{"name":"Part 1","startTime":"2022-08-01T07:00:00.000Z","endTime":"2022-08-02T07:00:00.000Z","subEntries":null},{"name":"Part 2","startTime":"2024-02-26T13:19:40.629Z","endTime":"2024-02-26T13:19:43.713Z","subEntries":null},{"name":"Part 3","startTime":"1970-01-01T00:00:00.000Z","endTime":null,"subEntries":[{"name":"Part 1","startTime":"2024-02-26T13:23:51.939Z","endTime":"2024-02-26T13:23:54.232Z","subEntries":null},{"name":"Part 2","startTime":"2024-02-26T13:27:34.397Z","endTime":"2024-02-26T13:27:49.282Z","subEntries":null}]},{"name":"Part 4","startTime":"2024-02-26T13:29:06.983Z","endTime":"2024-02-26T13:29:20.770Z","subEntries":null}]},{"name":"test","startTime":"2022-10-01T12:30:10.000Z","endTime":"2022-10-01T13:40:05.000Z","subEntries":null},{"name":"Segment 5","startTime":"1970-01-01T00:00:00.000Z","endTime":null,"subEntries":[{"name":"Part 1","startTime":"2023-05-23T16:16:56.000Z","endTime":"2023-05-23T16:16:59.000Z","subEntries":null},{"name":"Part 2","startTime":"1970-01-01T00:00:00.000Z","endTime":null,"subEntries":[{"name":"Part 1","startTime":"2024-02-26T13:30:39.632Z","endTime":"2024-02-26T13:30:56.290Z","subEntries":null},{"name":"Part 2","startTime":"2024-02-26T13:30:57.000Z","endTime":"2024-02-26T13:31:00.000Z","subEntries":null}]},{"name":"Part 3","startTime":"2024-02-26T13:34:18.537Z","endTime":"2024-02-26T13:34:21.169Z","subEntries":null}]}]} +``` + +```simple-time-tracker +{"entries":[{"name":"Segment 1","startTime":null,"endTime":null,"subEntries":[{"name":"Part 1","startTime":"2024-02-26T13:37:59.292Z","endTime":"2024-02-26T13:38:01.437Z","subEntries":null},{"name":"Part 2","startTime":"2024-02-26T13:38:16.235Z","endTime":"2024-02-26T13:38:18.895Z","subEntries":null}]}]} ```