Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { MarkdownRenderChild, Plugin, TFile } from "obsidian";
import { defaultSettings, SimpleTimeTrackerSettings } from "./settings";
import { SimpleTimeTrackerSettingsTab } from "./settings-tab";
import { displayStatisticsDay, displayStatisticsMonth } from "./statistics";
import { displayTracker, Entry, formatDuration, formatTimestamp, getDuration, getDurationToday, getRunningEntry, getTotalDuration, getTotalDurationToday, isRunning, loadAllTrackers, loadTracker, orderedEntries } from "./tracker";

export default class SimpleTimeTrackerPlugin extends Plugin {
Expand Down Expand Up @@ -41,13 +42,56 @@ export default class SimpleTimeTrackerPlugin extends Plugin {
i.addChild(component);
});

this.registerMarkdownCodeBlockProcessor("simple-time-tracker-statistics-day", (s, e, i) => {
e.empty();
const component = new MarkdownRenderChild(e);

displayStatisticsDay(e, this, i.sourcePath, s);

i.addChild(component);
});

this.registerMarkdownCodeBlockProcessor("simple-time-tracker-statistics-month", (s, e, i) => {
e.empty();
const component = new MarkdownRenderChild(e);

displayStatisticsMonth(e, this, i.sourcePath, s);

i.addChild(component);
});

this.addCommand({
id: `insert`,
name: `Insert Time Tracker`,
editorCallback: (e, _) => {
e.replaceSelection("```simple-time-tracker\n```\n");
}
});

this.addCommand({
id: `insert-stats-day`,
name: `Insert Time Tracker Statistics Day`,
editorCallback: (e, _) => {
e.replaceSelection("```simple-time-tracker-statistics-day\n```\n");
}
});

this.addCommand({
id: `insert-stats-month`,
name: `Insert Time Tracker Statistics Month`,
editorCallback: (e, _) => {
const block = `\`\`\`simple-time-tracker-statistics-month
deviation = 0
vacationDays = []
sickDays = []
daysOff = []
\`\`\`
`;
e.replaceSelection(block);
}
});


}

async loadSettings(): Promise<void> {
Expand Down
59 changes: 59 additions & 0 deletions src/settings-tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,65 @@ export class SimpleTimeTrackerSettingsTab extends PluginSettingTab {
this.containerEl.empty();
this.containerEl.createEl("h2", { text: "Super Simple Time Tracker Settings" });

this.containerEl.createEl("h5", { text: "Statistics" });

this.plugin.settings.categories.forEach((category, index) => {
const setting = new Setting(this.containerEl)
.addText(text => text
.setPlaceholder("Category name")
.setValue(category.name)
.onChange(async (value) => {
category.name = value;
await this.plugin.saveSettings();
}))
.addText(text => text
.setPlaceholder("Tags (comma-separated)")
.setValue(category.tags.join(", "))
.onChange(async (value) => {
category.tags = value.split(",").map(tag => tag.trim()).filter(tag => tag.length > 0);
await this.plugin.saveSettings();
}))
.addText(text => text
.setPlaceholder("Target time (HH:mm:ss)")
.setValue(category.target)
.onChange(async (value) => {
category.target = value ? value : "00:00:00"
await this.plugin.saveSettings();
}))
.addButton(button => button
.setButtonText("Remove")
.onClick(async () => {
this.plugin.settings.categories.splice(index, 1);
await this.plugin.saveSettings();
this.display();
}));
});

new Setting(this.containerEl)
.addButton(button => button
.setButtonText("Add New Category")
.onClick(async () => {
this.plugin.settings.categories.push({ name: "", tags: [] });
await this.plugin.saveSettings();
this.display();
}));

new Setting(this.containerEl)
.setName('First Day of Week')
.setDesc('Set the first day of the week for statistics calculation.')
.addDropdown(dropdown => {
dropdown
.addOption('0', 'Sunday')
.addOption('1', 'Monday')
.setValue(String(this.plugin.settings.firstDayOfWeek))
.onChange(async (value) => {
this.plugin.settings.firstDayOfWeek = Number(value);
await this.plugin.saveSettings();
});
});

this.containerEl.createEl("h5", { text: "General" });

new Setting(this.containerEl)
.setName("Timestamp Display Format")
.setDesc(createFragment(f => {
Expand Down
21 changes: 21 additions & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
export interface Category {
name: string;
tags: string[];
target: string;
}

export const defaultSettings: SimpleTimeTrackerSettings = {
timestampFormat: "YY-MM-DD HH:mm:ss",
editableTimestampFormat: "YYYY-MM-DD HH:mm:ss",
Expand All @@ -6,6 +12,19 @@ export const defaultSettings: SimpleTimeTrackerSettings = {
reverseSegmentOrder: false,
timestampDurations: false,
showToday: false,
firstDayOfWeek: 1, //Monday
categories : [
{
name: "Work",
tags: ['#work'],
target: "08:00:00"
},
{
name: "Leisure",
tags: ['#leisure'],
target: "00:00:00"
}
]
};

export interface SimpleTimeTrackerSettings {
Expand All @@ -17,4 +36,6 @@ export interface SimpleTimeTrackerSettings {
reverseSegmentOrder: boolean;
timestampDurations: boolean;
showToday: boolean;
firstDayOfWeek: number;
categories: Category[];
}
Loading