mirror of
https://github.com/Ellpeck/ObsidianSimpleTimeTracker.git
synced 2024-11-27 03:28:35 +01:00
Compare commits
No commits in common. "3d9e6163e7e08763eb92b364d684e8e4a3e3e178" and "5677e02243c75e68062c4c15d4418f6b62088c18" have entirely different histories.
3d9e6163e7
...
5677e02243
4 changed files with 40 additions and 126 deletions
|
@ -1,6 +1,5 @@
|
||||||
export const defaultSettings: SimpleTimeTrackerSettings = {
|
export const defaultSettings: SimpleTimeTrackerSettings = {
|
||||||
timestampFormat: "YY-MM-DD HH:mm:ss",
|
timestampFormat: "YY-MM-DD hh:mm:ss",
|
||||||
editableTimestampFormat: "YYYY-MM-DD HH:mm:ss",
|
|
||||||
csvDelimiter: ",",
|
csvDelimiter: ",",
|
||||||
fineGrainedDurations: true
|
fineGrainedDurations: true
|
||||||
};
|
};
|
||||||
|
@ -8,7 +7,6 @@ export const defaultSettings: SimpleTimeTrackerSettings = {
|
||||||
export interface SimpleTimeTrackerSettings {
|
export interface SimpleTimeTrackerSettings {
|
||||||
|
|
||||||
timestampFormat: string;
|
timestampFormat: string;
|
||||||
editableTimestampFormat: string;
|
|
||||||
csvDelimiter: string;
|
csvDelimiter: string;
|
||||||
fineGrainedDurations: boolean;
|
fineGrainedDurations: boolean;
|
||||||
|
|
||||||
|
|
|
@ -202,12 +202,8 @@ function formatTimestamp(timestamp: number, settings: SimpleTimeTrackerSettings)
|
||||||
return moment.unix(timestamp).format(settings.timestampFormat);
|
return moment.unix(timestamp).format(settings.timestampFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatEditableTimestamp(timestamp: number, settings: SimpleTimeTrackerSettings) {
|
function unFormatTimestamp(formatted: string, settings: SimpleTimeTrackerSettings): number {
|
||||||
return moment.unix(timestamp).format(settings.editableTimestampFormat);
|
return moment(formatted, settings.timestampFormat).unix();
|
||||||
}
|
|
||||||
|
|
||||||
function unformatEditableTimestamp(formatted: string, settings: SimpleTimeTrackerSettings): number {
|
|
||||||
return moment(formatted, settings.editableTimestampFormat).unix();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatDuration(totalTime: number, settings: SimpleTimeTrackerSettings): string {
|
function formatDuration(totalTime: number, settings: SimpleTimeTrackerSettings): string {
|
||||||
|
@ -298,7 +294,7 @@ class EditableField {
|
||||||
this.box.inputEl.show();
|
this.box.inputEl.show();
|
||||||
}
|
}
|
||||||
endEdit(): string {
|
endEdit(): string {
|
||||||
const value = this.box.getValue();
|
let value = this.box.getValue()
|
||||||
this.label.setText(value);
|
this.label.setText(value);
|
||||||
this.box.inputEl.hide();
|
this.box.inputEl.hide();
|
||||||
this.label.hidden = false;
|
this.label.hidden = false;
|
||||||
|
@ -306,38 +302,16 @@ class EditableField {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class EditableTimestampField extends EditableField {
|
|
||||||
settings: SimpleTimeTrackerSettings;
|
|
||||||
constructor(row: HTMLTableRowElement, indent: number, value: string, settings: SimpleTimeTrackerSettings) {
|
|
||||||
const timestamp = Number(value);
|
|
||||||
value = timestamp > 0 ? formatTimestamp(timestamp, settings) : "";
|
|
||||||
super(row, indent, value);
|
|
||||||
this.settings = settings;
|
|
||||||
}
|
|
||||||
beginEdit(value: string) {
|
|
||||||
value = formatEditableTimestamp(Number(value), this.settings);
|
|
||||||
super.beginEdit(value);
|
|
||||||
}
|
|
||||||
endEdit(): string {
|
|
||||||
const value = this.box.getValue();
|
|
||||||
const timestamp = unformatEditableTimestamp(value, this.settings);
|
|
||||||
const displayValue = formatTimestamp(timestamp, this.settings);
|
|
||||||
this.label.setText(displayValue);
|
|
||||||
this.box.inputEl.hide();
|
|
||||||
this.label.hidden = false;
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
getTimestamp(): number {
|
|
||||||
return unformatEditableTimestamp(this.box.getValue(), this.settings);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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 endField = new EditableTimestampField(row, indent, String(entry.endTime), settings);
|
let startValue = entry.startTime ? formatTimestamp(entry.startTime, settings) : "";
|
||||||
|
let startField = new EditableField(row, indent, startValue);
|
||||||
|
|
||||||
|
let endValue = entry.endTime ? formatTimestamp(entry.endTime, settings) : "";
|
||||||
|
let endField = new EditableField(row, indent, endValue);
|
||||||
|
|
||||||
row.createEl("td", { text: entry.endTime || entry.subEntries ? formatDuration(getDuration(entry), settings) : "" });
|
row.createEl("td", { text: entry.endTime || entry.subEntries ? formatDuration(getDuration(entry), settings) : "" });
|
||||||
|
|
||||||
|
@ -359,16 +333,14 @@ function addEditableTableRow(tracker: Tracker, entry: Entry, table: HTMLTableEle
|
||||||
.onClick(async () => {
|
.onClick(async () => {
|
||||||
if (nameField.editing()) {
|
if (nameField.editing()) {
|
||||||
entry.name = nameField.endEdit();
|
entry.name = nameField.endEdit();
|
||||||
startField.endEdit();
|
entry.startTime = unFormatTimestamp(startField.endEdit(), settings);
|
||||||
entry.startTime = startField.getTimestamp();
|
entry.endTime = unFormatTimestamp(endField.endEdit(), settings);
|
||||||
endField.endEdit();
|
|
||||||
entry.endTime = endField.getTimestamp();
|
|
||||||
await saveTracker(tracker, this.app, file, getSectionInfo());
|
await saveTracker(tracker, this.app, file, getSectionInfo());
|
||||||
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(formatTimestamp(entry.startTime, settings));
|
||||||
endField.beginEdit(String(entry.endTime));
|
endField.beginEdit(formatTimestamp(entry.endTime, settings));
|
||||||
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