Compare commits

..

No commits in common. "3d9e6163e7e08763eb92b364d684e8e4a3e3e178" and "5677e02243c75e68062c4c15d4418f6b62088c18" have entirely different histories.

4 changed files with 40 additions and 126 deletions

View file

@ -1,6 +1,5 @@
export const defaultSettings: SimpleTimeTrackerSettings = {
timestampFormat: "YY-MM-DD HH:mm:ss",
editableTimestampFormat: "YYYY-MM-DD HH:mm:ss",
timestampFormat: "YY-MM-DD hh:mm:ss",
csvDelimiter: ",",
fineGrainedDurations: true
};
@ -8,7 +7,6 @@ export const defaultSettings: SimpleTimeTrackerSettings = {
export interface SimpleTimeTrackerSettings {
timestampFormat: string;
editableTimestampFormat: string;
csvDelimiter: string;
fineGrainedDurations: boolean;

View file

@ -202,12 +202,8 @@ function formatTimestamp(timestamp: number, settings: SimpleTimeTrackerSettings)
return moment.unix(timestamp).format(settings.timestampFormat);
}
function formatEditableTimestamp(timestamp: number, settings: SimpleTimeTrackerSettings) {
return moment.unix(timestamp).format(settings.editableTimestampFormat);
}
function unformatEditableTimestamp(formatted: string, settings: SimpleTimeTrackerSettings): number {
return moment(formatted, settings.editableTimestampFormat).unix();
function unFormatTimestamp(formatted: string, settings: SimpleTimeTrackerSettings): number {
return moment(formatted, settings.timestampFormat).unix();
}
function formatDuration(totalTime: number, settings: SimpleTimeTrackerSettings): string {
@ -298,7 +294,7 @@ class EditableField {
this.box.inputEl.show();
}
endEdit(): string {
const value = this.box.getValue();
let value = this.box.getValue()
this.label.setText(value);
this.box.inputEl.hide();
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) {
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 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) : "" });
@ -359,16 +333,14 @@ function addEditableTableRow(tracker: Tracker, entry: Entry, table: HTMLTableEle
.onClick(async () => {
if (nameField.editing()) {
entry.name = nameField.endEdit();
startField.endEdit();
entry.startTime = startField.getTimestamp();
endField.endEdit();
entry.endTime = endField.getTimestamp();
entry.startTime = unFormatTimestamp(startField.endEdit(), settings);
entry.endTime = unFormatTimestamp(endField.endEdit(), settings);
await saveTracker(tracker, this.app, file, getSectionInfo());
editButton.setIcon("lucide-pencil");
} else {
nameField.beginEdit(entry.name);
startField.beginEdit(String(entry.startTime));
endField.beginEdit(String(entry.endTime));
startField.beginEdit(formatTimestamp(entry.startTime, settings));
endField.beginEdit(formatTimestamp(entry.endTime, settings));
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