Handle active timer with no end value

This commit is contained in:
Matt Wiseley 2023-07-11 22:17:42 -04:00
parent 3d9e6163e7
commit a6727bb879
3 changed files with 80 additions and 32 deletions

View file

@ -309,35 +309,51 @@ class EditableField {
class EditableTimestampField extends EditableField {
settings: SimpleTimeTrackerSettings;
constructor(row: HTMLTableRowElement, indent: number, value: string, settings: SimpleTimeTrackerSettings) {
if (value) {
const timestamp = Number(value);
value = timestamp > 0 ? formatTimestamp(timestamp, settings) : "";
}
super(row, indent, value);
this.settings = settings;
}
beginEdit(value: string) {
if (value) {
value = formatEditableTimestamp(Number(value), this.settings);
}
super.beginEdit(value);
}
endEdit(): string {
const value = this.box.getValue();
let displayValue = value;
if (value) {
const timestamp = unformatEditableTimestamp(value, this.settings);
const displayValue = formatTimestamp(timestamp, this.settings);
displayValue = formatTimestamp(timestamp, this.settings);
}
this.label.setText(displayValue);
this.box.inputEl.hide();
this.label.hidden = false;
return value;
}
getTimestamp(): number {
if (this.box.getValue()) {
return unformatEditableTimestamp(this.box.getValue(), this.settings);
} else {
return null;
}
}
}
function nullableNumberToString(value: number) {
if (value == null) return '';
return String(value);
}
function addEditableTableRow(tracker: Tracker, entry: Entry, table: HTMLTableElement, newSegmentNameBox: TextComponent, running: boolean, file: string, getSectionInfo: () => MarkdownSectionInformation, settings: SimpleTimeTrackerSettings, indent: number) {
let row = table.createEl("tr");
let nameField = new EditableField(row, indent, entry.name);
let startField = new EditableTimestampField(row, indent, String(entry.startTime), settings);
let endField = new EditableTimestampField(row, indent, String(entry.endTime), settings);
let startField = new EditableTimestampField(row, indent, nullableNumberToString(entry.startTime), settings);
let endField = new EditableTimestampField(row, indent, nullableNumberToString(entry.endTime), settings);
row.createEl("td", { text: entry.endTime || entry.subEntries ? formatDuration(getDuration(entry), settings) : "" });
@ -367,8 +383,8 @@ function addEditableTableRow(tracker: Tracker, entry: Entry, table: HTMLTableEle
editButton.setIcon("lucide-pencil");
} else {
nameField.beginEdit(entry.name);
startField.beginEdit(String(entry.startTime));
endField.beginEdit(String(entry.endTime));
startField.beginEdit(nullableNumberToString(entry.startTime));
endField.beginEdit(nullableNumberToString(entry.endTime));
editButton.setIcon("lucide-check");
}
});

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long