Compare commits

..

No commits in common. "7aa91901c6831d15ad1782a333b8ad36a0115fa6" and "05a4710b8a9de1a3675443872418a791c1844421" have entirely different histories.

11 changed files with 181 additions and 184 deletions

View file

@ -4,6 +4,6 @@ root = true
[*] [*]
charset = utf-8 charset = utf-8
insert_final_newline = true insert_final_newline = true
indent_style = space indent_style = tab
indent_size = 4 indent_size = 4
tab_width = 4 tab_width = 4

View file

@ -1,7 +1,7 @@
import { Plugin } from "obsidian"; import { Plugin } from "obsidian";
import { defaultSettings, SimpleTimeTrackerSettings } from "./settings"; import { defaultSettings, SimpleTimeTrackerSettings } from "./settings";
import { SimpleTimeTrackerSettingsTab } from "./settings-tab"; import { SimpleTimeTrackerSettingsTab } from "./settings-tab";
import { displayTracker, loadTracker, Tracker } from "./tracker"; import { displayTracker, loadTracker } from "./tracker";
export default class SimpleTimeTrackerPlugin extends Plugin { export default class SimpleTimeTrackerPlugin extends Plugin {
@ -13,7 +13,7 @@ export default class SimpleTimeTrackerPlugin extends Plugin {
this.addSettingTab(new SimpleTimeTrackerSettingsTab(this.app, this)); this.addSettingTab(new SimpleTimeTrackerSettingsTab(this.app, this));
this.registerMarkdownCodeBlockProcessor("simple-time-tracker", (s, e, i) => { this.registerMarkdownCodeBlockProcessor("simple-time-tracker", (s, e, i) => {
let tracker: Tracker = loadTracker(s); let tracker = loadTracker(s);
e.empty(); e.empty();
displayTracker(tracker, e, () => i.getSectionInfo(e), this.settings); displayTracker(tracker, e, () => i.getSectionInfo(e), this.settings);
}); });
@ -27,11 +27,11 @@ export default class SimpleTimeTrackerPlugin extends Plugin {
}); });
} }
async loadSettings(): Promise<void> { async loadSettings() {
this.settings = Object.assign({}, defaultSettings, await this.loadData()); this.settings = Object.assign({}, defaultSettings, await this.loadData());
} }
async saveSettings(): Promise<void> { async saveSettings() {
await this.saveData(this.settings); await this.saveData(this.settings);
} }
} }

View file

@ -13,14 +13,14 @@ export class SimpleTimeTrackerSettingsTab extends PluginSettingTab {
display(): void { display(): void {
this.containerEl.empty(); this.containerEl.empty();
this.containerEl.createEl("h2", {text: "Super Simple Time Tracker Settings"}); this.containerEl.createEl("h2", { text: "Super Simple Time Tracker Settings" });
new Setting(this.containerEl) new Setting(this.containerEl)
.setName("Timestamp Display Format") .setName("Timestamp Display Format")
.setDesc(createFragment(f => { .setDesc(createFragment(f => {
f.createSpan({text: "The way that timestamps in time tracker tables should be displayed. Uses "}); 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.createEl("a", { text: "moment.js", href: "https://momentjs.com/docs/#/parsing/string-format/" });
f.createSpan({text: " syntax."}); f.createSpan({ text: " syntax." });
})) }))
.addText(t => { .addText(t => {
t.setValue(String(this.plugin.settings.timestampFormat)); t.setValue(String(this.plugin.settings.timestampFormat));
@ -42,11 +42,8 @@ export class SimpleTimeTrackerSettingsTab extends PluginSettingTab {
}); });
this.containerEl.createEl("hr"); 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!"}); 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!" });
this.containerEl.createEl("a", {href: "https://ellpeck.de/support"}) this.containerEl.createEl("a", { href: "https://ellpeck.de/support" })
.createEl("img", { .createEl("img", { attr: { src: "https://ellpeck.de/res/generalsupport.png" }, cls: "simple-time-tracker-support" });
attr: {src: "https://ellpeck.de/res/generalsupport.png"},
cls: "simple-time-tracker-support"
});
} }
} }

View file

@ -36,7 +36,7 @@ export function loadTracker(json: string): Tracker {
console.log(`Failed to parse Tracker from ${json}`); console.log(`Failed to parse Tracker from ${json}`);
} }
} }
return {entries: []}; return { entries: [] };
} }
export function displayTracker(tracker: Tracker, element: HTMLElement, getSectionInfo: () => MarkdownSectionInformation, settings: SimpleTimeTrackerSettings): void { export function displayTracker(tracker: Tracker, element: HTMLElement, getSectionInfo: () => MarkdownSectionInformation, settings: SimpleTimeTrackerSettings): void {
@ -61,29 +61,29 @@ export function displayTracker(tracker: Tracker, element: HTMLElement, getSectio
newSegmentNameBox.inputEl.addClass("simple-time-tracker-txt"); newSegmentNameBox.inputEl.addClass("simple-time-tracker-txt");
// add timers // add timers
let timer = element.createDiv({cls: "simple-time-tracker-timers"}); let timer = element.createDiv({ cls: "simple-time-tracker-timers" });
let currentDiv = timer.createEl("div", {cls: "simple-time-tracker-timer"}); let currentDiv = timer.createEl("div", { cls: "simple-time-tracker-timer" });
let current = currentDiv.createEl("span", {cls: "simple-time-tracker-timer-time"}); let current = currentDiv.createEl("span", { cls: "simple-time-tracker-timer-time" });
currentDiv.createEl("span", {text: "Current"}); currentDiv.createEl("span", { text: "Current" });
let totalDiv = timer.createEl("div", {cls: "simple-time-tracker-timer"}); let totalDiv = timer.createEl("div", { cls: "simple-time-tracker-timer" });
let total = totalDiv.createEl("span", {cls: "simple-time-tracker-timer-time", text: "0s"}); let total = totalDiv.createEl("span", { cls: "simple-time-tracker-timer-time", text: "0s" });
totalDiv.createEl("span", {text: "Total"}); totalDiv.createEl("span", { text: "Total" });
if (tracker.entries.length > 0) { if (tracker.entries.length > 0) {
// add table // add table
let table = element.createEl("table", {cls: "simple-time-tracker-table"}); let table = element.createEl("table", { cls: "simple-time-tracker-table" });
table.createEl("tr").append( table.createEl("tr").append(
createEl("th", {text: "Segment"}), createEl("th", { text: "Segment" }),
createEl("th", {text: "Start time"}), createEl("th", { text: "Start time" }),
createEl("th", {text: "End time"}), createEl("th", { text: "End time" }),
createEl("th", {text: "Duration"}), createEl("th", { text: "Duration" }),
createEl("th")); createEl("th"));
for (let entry of tracker.entries) for (let entry of tracker.entries)
addEditableTableRow(tracker, entry, table, newSegmentNameBox, running, getSectionInfo, settings, 0); addEditableTableRow(tracker, entry, table, newSegmentNameBox, running, getSectionInfo, settings, 0);
// add copy buttons // add copy buttons
let buttons = element.createEl("div", {cls: "simple-time-tracker-bottom"}); let buttons = element.createEl("div", { cls: "simple-time-tracker-bottom" });
new ButtonComponent(buttons) new ButtonComponent(buttons)
.setButtonText("Copy as table") .setButtonText("Copy as table")
.onClick(() => navigator.clipboard.writeText(createMarkdownTable(tracker, settings))); .onClick(() => navigator.clipboard.writeText(createMarkdownTable(tracker, settings)));
@ -107,22 +107,22 @@ export function displayTracker(tracker: Tracker, element: HTMLElement, getSectio
function startSubEntry(entry: Entry, name: string) { function startSubEntry(entry: Entry, name: string) {
// if this entry is not split yet, we add its time as a sub-entry instead // if this entry is not split yet, we add its time as a sub-entry instead
if (!entry.subEntries) { if (!entry.subEntries) {
entry.subEntries = [{...entry, name: `Part 1`}]; entry.subEntries = [{ ...entry, name: `Part 1` }];
entry.startTime = null; entry.startTime = null;
entry.endTime = null; entry.endTime = null;
} }
if (!name) if (!name)
name = `Part ${entry.subEntries.length + 1}`; name = `Part ${entry.subEntries.length + 1}`;
entry.subEntries.push({name: name, startTime: moment().unix(), endTime: null, subEntries: null}); entry.subEntries.push({ name: name, startTime: moment().unix(), endTime: null, subEntries: null });
} }
function startNewEntry(tracker: Tracker, name: string): void { function startNewEntry(tracker: Tracker, name: string): void {
if (!name) if (!name)
name = `Segment ${tracker.entries.length + 1}`; name = `Segment ${tracker.entries.length + 1}`;
let entry: Entry = {name: name, startTime: moment().unix(), endTime: null, subEntries: null}; let entry: Entry = { name: name, startTime: moment().unix(), endTime: null, subEntries: null };
tracker.entries.push(entry); tracker.entries.push(entry);
} };
function endRunningEntry(tracker: Tracker): void { function endRunningEntry(tracker: Tracker): void {
let entry = getRunningEntry(tracker.entries); let entry = getRunningEntry(tracker.entries);
@ -266,14 +266,14 @@ function addEditableTableRow(tracker: Tracker, entry: Entry, table: HTMLTableEle
let row = table.createEl("tr"); let row = table.createEl("tr");
let name = row.createEl("td"); let name = row.createEl("td");
let namePar = name.createEl("span", {text: entry.name}); let namePar = name.createEl("span", { text: entry.name });
namePar.style.marginLeft = `${indent}em`; namePar.style.marginLeft = `${indent}em`;
let nameBox = new TextComponent(name).setValue(entry.name); let nameBox = new TextComponent(name).setValue(entry.name);
nameBox.inputEl.hidden = true; nameBox.inputEl.hidden = true;
row.createEl("td", {text: entry.startTime ? formatTimestamp(entry.startTime, settings) : ""}); row.createEl("td", { text: entry.startTime ? formatTimestamp(entry.startTime, settings) : "" });
row.createEl("td", {text: entry.endTime ? formatTimestamp(entry.endTime, settings) : ""}); row.createEl("td", { text: entry.endTime ? formatTimestamp(entry.endTime, settings) : "" });
row.createEl("td", {text: entry.endTime || entry.subEntries ? formatDuration(getDuration(entry)) : ""}); row.createEl("td", { text: entry.endTime || entry.subEntries ? formatDuration(getDuration(entry)) : "" });
let entryButtons = row.createEl("td"); let entryButtons = row.createEl("td");
if (!running) { if (!running) {