mirror of
https://github.com/Ellpeck/ObsidianSimpleTimeTracker.git
synced 2024-11-22 01:23:28 +01:00
Handle active timer with no end value
This commit is contained in:
parent
3d9e6163e7
commit
a6727bb879
3 changed files with 80 additions and 32 deletions
|
@ -309,35 +309,51 @@ class EditableField {
|
||||||
class EditableTimestampField extends EditableField {
|
class EditableTimestampField extends EditableField {
|
||||||
settings: SimpleTimeTrackerSettings;
|
settings: SimpleTimeTrackerSettings;
|
||||||
constructor(row: HTMLTableRowElement, indent: number, value: string, settings: SimpleTimeTrackerSettings) {
|
constructor(row: HTMLTableRowElement, indent: number, value: string, settings: SimpleTimeTrackerSettings) {
|
||||||
|
if (value) {
|
||||||
const timestamp = Number(value);
|
const timestamp = Number(value);
|
||||||
value = timestamp > 0 ? formatTimestamp(timestamp, settings) : "";
|
value = timestamp > 0 ? formatTimestamp(timestamp, settings) : "";
|
||||||
|
}
|
||||||
super(row, indent, value);
|
super(row, indent, value);
|
||||||
this.settings = settings;
|
this.settings = settings;
|
||||||
}
|
}
|
||||||
beginEdit(value: string) {
|
beginEdit(value: string) {
|
||||||
|
if (value) {
|
||||||
value = formatEditableTimestamp(Number(value), this.settings);
|
value = formatEditableTimestamp(Number(value), this.settings);
|
||||||
|
}
|
||||||
super.beginEdit(value);
|
super.beginEdit(value);
|
||||||
}
|
}
|
||||||
endEdit(): string {
|
endEdit(): string {
|
||||||
const value = this.box.getValue();
|
const value = this.box.getValue();
|
||||||
|
let displayValue = value;
|
||||||
|
if (value) {
|
||||||
const timestamp = unformatEditableTimestamp(value, this.settings);
|
const timestamp = unformatEditableTimestamp(value, this.settings);
|
||||||
const displayValue = formatTimestamp(timestamp, this.settings);
|
displayValue = formatTimestamp(timestamp, this.settings);
|
||||||
|
}
|
||||||
this.label.setText(displayValue);
|
this.label.setText(displayValue);
|
||||||
this.box.inputEl.hide();
|
this.box.inputEl.hide();
|
||||||
this.label.hidden = false;
|
this.label.hidden = false;
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
getTimestamp(): number {
|
getTimestamp(): number {
|
||||||
|
if (this.box.getValue()) {
|
||||||
return unformatEditableTimestamp(this.box.getValue(), this.settings);
|
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) {
|
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 row = table.createEl("tr");
|
||||||
|
|
||||||
let nameField = new EditableField(row, indent, entry.name);
|
let nameField = new EditableField(row, indent, entry.name);
|
||||||
let startField = new EditableTimestampField(row, indent, String(entry.startTime), settings);
|
let startField = new EditableTimestampField(row, indent, nullableNumberToString(entry.startTime), settings);
|
||||||
let endField = new EditableTimestampField(row, indent, String(entry.endTime), settings);
|
let endField = new EditableTimestampField(row, indent, nullableNumberToString(entry.endTime), settings);
|
||||||
|
|
||||||
row.createEl("td", { text: entry.endTime || entry.subEntries ? formatDuration(getDuration(entry), 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");
|
editButton.setIcon("lucide-pencil");
|
||||||
} else {
|
} else {
|
||||||
nameField.beginEdit(entry.name);
|
nameField.beginEdit(entry.name);
|
||||||
startField.beginEdit(String(entry.startTime));
|
startField.beginEdit(nullableNumberToString(entry.startTime));
|
||||||
endField.beginEdit(String(entry.endTime));
|
endField.beginEdit(nullableNumberToString(entry.endTime));
|
||||||
editButton.setIcon("lucide-check");
|
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
Loading…
Reference in a new issue