mirror of
https://github.com/Ellpeck/ObsidianSimpleTimeTracker.git
synced 2024-12-18 19:39:22 +01:00
added timestamp format setting
This commit is contained in:
parent
f694dfcc57
commit
10251de71c
7 changed files with 46 additions and 15 deletions
|
@ -15,7 +15,6 @@ The tracker's information is stored in the code block as JSON data. The names, s
|
|||
|
||||
# 🛣️ Roadmap
|
||||
Super Simple Time Tracker is still in its early stages! There are a lot of plans for it, including:
|
||||
- A setting to allow users to decide what format timestamps should be displayed in
|
||||
- A setting to link segments to corresponding daily notes automatically
|
||||
- A neat interface to edit previous segments' names and time stamps
|
||||
- The ability to copy the table in various formats, including as text, markdown, and csv
|
||||
|
|
|
@ -15,7 +15,7 @@ export default class SimpleTimeTrackerPlugin extends Plugin {
|
|||
this.registerMarkdownCodeBlockProcessor("simple-time-tracker", (s, e, i) => {
|
||||
let tracker = loadTracker(s);
|
||||
e.empty();
|
||||
displayTracker(tracker, e, () => i.getSectionInfo(e));
|
||||
displayTracker(tracker, e, () => i.getSectionInfo(e), this.settings);
|
||||
});
|
||||
|
||||
this.addCommand({
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { App, PluginSettingTab } from "obsidian";
|
||||
import { App, PluginSettingTab, Setting } from "obsidian";
|
||||
import SimpleTimeTrackerPlugin from "./main";
|
||||
import { defaultSettings } from "./settings";
|
||||
|
||||
export class SimpleTimeTrackerSettingsTab extends PluginSettingTab {
|
||||
|
||||
|
@ -14,7 +15,20 @@ export class SimpleTimeTrackerSettingsTab extends PluginSettingTab {
|
|||
this.containerEl.empty();
|
||||
this.containerEl.createEl("h2", { text: "Super Simple Time Tracker Settings" });
|
||||
|
||||
this.containerEl.createEl("p", { text: "Settings coming soon!" });
|
||||
new Setting(this.containerEl)
|
||||
.setName("Timestamp Display Format")
|
||||
.setDesc(createFragment(f => {
|
||||
f.createSpan({ text: "The way that timestamps in time tracker tables should be displayed. Uses " });
|
||||
f.createEl("a", { text: "moment.js", href: "https://momentjs.com/docs/#/parsing/string-format/" });
|
||||
f.createSpan({ text: " syntax. Clear to reset to default." });
|
||||
}))
|
||||
.addText(t => {
|
||||
t.setValue(String(this.plugin.settings.timestampFormat));
|
||||
t.onChange(async v => {
|
||||
this.plugin.settings.timestampFormat = v.length ? v : defaultSettings.timestampFormat;
|
||||
await this.plugin.saveSettings();
|
||||
});
|
||||
});
|
||||
|
||||
this.containerEl.createEl("hr");
|
||||
this.containerEl.createEl("p", { text: "If you like this plugin and want to support its development, you can do so through my website by clicking this fancy image!" });
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
export const defaultSettings: SimpleTimeTrackerSettings = {
|
||||
|
||||
timestampFormat: "YY-MM-DD hh:mm:ss"
|
||||
};
|
||||
|
||||
export interface SimpleTimeTrackerSettings {
|
||||
|
||||
timestampFormat: string;
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { moment, App, MarkdownSectionInformation, ButtonComponent, TextComponent } from "obsidian";
|
||||
import { SimpleTimeTrackerSettings } from "./settings";
|
||||
|
||||
export class Tracker {
|
||||
entries: Entry[];
|
||||
|
@ -52,7 +53,7 @@ export function loadTracker(json: string): Tracker {
|
|||
return { entries: [] };
|
||||
}
|
||||
|
||||
export function displayTracker(tracker: Tracker, element: HTMLElement, getSectionInfo: () => MarkdownSectionInformation): void {
|
||||
export function displayTracker(tracker: Tracker, element: HTMLElement, getSectionInfo: () => MarkdownSectionInformation, settings: SimpleTimeTrackerSettings): void {
|
||||
// add start/stop controls
|
||||
let running = isRunning(tracker);
|
||||
let btn = new ButtonComponent(element)
|
||||
|
@ -92,9 +93,9 @@ export function displayTracker(tracker: Tracker, element: HTMLElement, getSectio
|
|||
for (let entry of tracker.entries) {
|
||||
let row = table.createEl("tr");
|
||||
row.createEl("td", { text: entry.name });
|
||||
row.createEl("td", { text: moment.unix(entry.startTime).format("YY-MM-DD hh:mm:ss") });
|
||||
row.createEl("td", { text: moment.unix(entry.startTime).format(settings.timestampFormat) });
|
||||
if (entry.endTime) {
|
||||
row.createEl("td", { text: moment.unix(entry.endTime).format("YY-MM-DD hh:mm:ss") });
|
||||
row.createEl("td", { text: moment.unix(entry.endTime).format(settings.timestampFormat) });
|
||||
let duration = moment.unix(entry.endTime).diff(moment.unix(entry.startTime));
|
||||
row.createEl("td", { text: getCountdownDisplay(moment.duration(duration)) });
|
||||
}
|
||||
|
|
3
test-vault/.obsidian/plugins/obsidian-simple-time-tracker/data.json
vendored
Normal file
3
test-vault/.obsidian/plugins/obsidian-simple-time-tracker/data.json
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"timestampFormat": "YY-MM-DD hh:mm:ss"
|
||||
}
|
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue