fixed some issues with how and when entry content is displayed

closes #36
This commit is contained in:
Ell 2024-02-26 14:39:48 +01:00
parent 92b2a287aa
commit 3469232d3b
2 changed files with 25 additions and 16 deletions

View file

@ -237,7 +237,7 @@ function formatDuration(totalTime: number, settings: SimpleTimeTrackerSettings):
function fixLegacyTimestamps(entries: Entry[]): void { function fixLegacyTimestamps(entries: Entry[]): void {
for (let entry of entries) { for (let entry of entries) {
if (!isNaN(+entry.startTime)) if (entry.startTime && !isNaN(+entry.startTime))
entry.startTime = moment.unix(+entry.startTime).toISOString(); entry.startTime = moment.unix(+entry.startTime).toISOString();
if (entry.endTime && !isNaN(+entry.endTime)) if (entry.endTime && !isNaN(+entry.endTime))
entry.endTime = moment.unix(+entry.endTime).toISOString(); 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 row = table.createEl("tr");
let nameField = new EditableField(row, indent, entry.name); 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) : ""}); row.createEl("td", {text: entry.endTime || entry.subEntries ? formatDuration(getDuration(entry), settings) : ""});
let entryButtons = row.createEl("td"); let entryButtons = row.createEl("td");
if (!running) { new ButtonComponent(entryButtons)
new ButtonComponent(entryButtons) .setClass("clickable-icon")
.setClass("clickable-icon") .setIcon(`lucide-play`)
.setIcon(`lucide-play`) .setTooltip("Continue")
.setTooltip("Continue") .setDisabled(trackerRunning)
.onClick(async () => { .onClick(async () => {
startSubEntry(entry, newSegmentNameBox.getValue()); startSubEntry(entry, newSegmentNameBox.getValue());
await saveTracker(tracker, this.app, file, getSectionInfo()); await saveTracker(tracker, this.app, file, getSectionInfo());
}); });
}
let editButton = new ButtonComponent(entryButtons) let editButton = new ButtonComponent(entryButtons)
.setClass("clickable-icon") .setClass("clickable-icon")
.setTooltip("Edit") .setTooltip("Edit")
.setIcon("lucide-pencil") .setIcon("lucide-pencil")
.setDisabled(entryRunning)
.onClick(async () => { .onClick(async () => {
if (nameField.editing()) { if (nameField.editing()) {
entry.name = nameField.endEdit(); entry.name = nameField.endEdit();
@ -397,8 +398,11 @@ function addEditableTableRow(tracker: Tracker, entry: Entry, table: HTMLTableEle
editButton.setIcon("lucide-pencil"); editButton.setIcon("lucide-pencil");
} else { } else {
nameField.beginEdit(entry.name); nameField.beginEdit(entry.name);
startField.beginEdit((entry.startTime)); // only allow editing start and end times if we don't have sub entries
endField.beginEdit((entry.endTime)); if (!entry.subEntries) {
startField.beginEdit(entry.startTime);
endField.beginEdit(entry.endTime);
}
editButton.setIcon("lucide-check"); editButton.setIcon("lucide-check");
} }
}); });
@ -406,6 +410,7 @@ function addEditableTableRow(tracker: Tracker, entry: Entry, table: HTMLTableEle
.setClass("clickable-icon") .setClass("clickable-icon")
.setTooltip("Remove") .setTooltip("Remove")
.setIcon("lucide-trash") .setIcon("lucide-trash")
.setDisabled(entryRunning)
.onClick(async () => { .onClick(async () => {
removeEntry(tracker.entries, entry); removeEntry(tracker.entries, entry);
await saveTracker(tracker, this.app, file, getSectionInfo()); await saveTracker(tracker, this.app, file, getSectionInfo());
@ -413,6 +418,6 @@ function addEditableTableRow(tracker: Tracker, entry: Entry, table: HTMLTableEle
if (entry.subEntries) { if (entry.subEntries) {
for (let sub of orderedEntries(entry.subEntries, settings)) 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);
} }
} }

View file

@ -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! 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 ```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}]}]}
``` ```