fixed the time tracker not saving correctly on a canvas

closes #16
This commit is contained in:
Ell 2023-05-23 18:06:29 +02:00
parent 5baf96571e
commit 175ef1e0d7
14 changed files with 2330 additions and 3047 deletions

View file

@ -2,7 +2,7 @@
"id": "simple-time-tracker", "id": "simple-time-tracker",
"name": "Super Simple Time Tracker", "name": "Super Simple Time Tracker",
"version": "0.1.6", "version": "0.1.6",
"minAppVersion": "0.15.0", "minAppVersion": "1.2.8",
"description": "Multi-purpose time trackers for your notes!", "description": "Multi-purpose time trackers for your notes!",
"author": "Ellpeck", "author": "Ellpeck",
"authorUrl": "https://ellpeck.de", "authorUrl": "https://ellpeck.de",

4733
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -15,7 +15,7 @@ export default class SimpleTimeTrackerPlugin extends Plugin {
this.registerMarkdownCodeBlockProcessor("simple-time-tracker", (s, e, i) => { this.registerMarkdownCodeBlockProcessor("simple-time-tracker", (s, e, i) => {
let tracker: Tracker = loadTracker(s); let tracker: Tracker = loadTracker(s);
e.empty(); e.empty();
displayTracker(tracker, e, () => i.getSectionInfo(e), this.settings); displayTracker(tracker, e, i.sourcePath, () => i.getSectionInfo(e), this.settings);
}); });
this.addCommand({ this.addCommand({

View file

@ -1,4 +1,4 @@
import { moment, App, MarkdownSectionInformation, ButtonComponent, TextComponent } from "obsidian"; import { moment, App, MarkdownSectionInformation, ButtonComponent, TextComponent, TFile } from "obsidian";
import { SimpleTimeTrackerSettings } from "./settings"; import { SimpleTimeTrackerSettings } from "./settings";
export interface Tracker { export interface Tracker {
@ -12,8 +12,8 @@ export interface Entry {
subEntries: Entry[]; subEntries: Entry[];
} }
export async function saveTracker(tracker: Tracker, app: App, section: MarkdownSectionInformation): Promise<void> { export async function saveTracker(tracker: Tracker, app: App, fileName: string, section: MarkdownSectionInformation): Promise<void> {
let file = app.workspace.getActiveFile(); let file = app.vault.getAbstractFileByPath(fileName) as TFile;
if (!file) if (!file)
return; return;
let content = await app.vault.read(file); let content = await app.vault.read(file);
@ -39,7 +39,7 @@ export function loadTracker(json: string): Tracker {
return {entries: []}; return {entries: []};
} }
export function displayTracker(tracker: Tracker, element: HTMLElement, getSectionInfo: () => MarkdownSectionInformation, settings: SimpleTimeTrackerSettings): void { export function displayTracker(tracker: Tracker, element: HTMLElement, file: string, getSectionInfo: () => MarkdownSectionInformation, settings: SimpleTimeTrackerSettings): void {
// add start/stop controls // add start/stop controls
let running = isRunning(tracker); let running = isRunning(tracker);
let btn = new ButtonComponent(element) let btn = new ButtonComponent(element)
@ -52,7 +52,7 @@ export function displayTracker(tracker: Tracker, element: HTMLElement, getSectio
} else { } else {
startNewEntry(tracker, newSegmentNameBox.getValue()); startNewEntry(tracker, newSegmentNameBox.getValue());
} }
await saveTracker(tracker, this.app, getSectionInfo()); await saveTracker(tracker, this.app, file, getSectionInfo());
}); });
btn.buttonEl.addClass("simple-time-tracker-btn"); btn.buttonEl.addClass("simple-time-tracker-btn");
let newSegmentNameBox = new TextComponent(element) let newSegmentNameBox = new TextComponent(element)
@ -80,7 +80,7 @@ export function displayTracker(tracker: Tracker, element: HTMLElement, getSectio
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, file, 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"});
@ -204,12 +204,12 @@ function formatTimestamp(timestamp: number, settings: SimpleTimeTrackerSettings)
function formatDuration(totalTime: number): string { function formatDuration(totalTime: number): string {
let duration = moment.duration(totalTime); let duration = moment.duration(totalTime);
let ret = ""; let ret = "";
if (duration.years() > 0) if (duration.years() > 0)
ret += duration.years() + "y "; ret += duration.years() + "y ";
if (duration.months() > 0) if (duration.months() > 0)
ret += duration.months() + "m "; ret += duration.months() + "m ";
if (duration.days() > 0) if (duration.days() > 0)
ret += duration.days() + "d "; ret += duration.days() + "d ";
if (duration.hours() > 0) if (duration.hours() > 0)
ret += duration.hours() + "h "; ret += duration.hours() + "h ";
if (duration.minutes() > 0) if (duration.minutes() > 0)
@ -262,7 +262,7 @@ function createTableSection(entry: Entry, settings: SimpleTimeTrackerSettings):
return ret; return ret;
} }
function addEditableTableRow(tracker: Tracker, entry: Entry, table: HTMLTableElement, newSegmentNameBox: TextComponent, running: boolean, 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 name = row.createEl("td"); let name = row.createEl("td");
@ -283,7 +283,7 @@ function addEditableTableRow(tracker: Tracker, entry: Entry, table: HTMLTableEle
.setTooltip("Continue") .setTooltip("Continue")
.onClick(async () => { .onClick(async () => {
startSubEntry(entry, newSegmentNameBox.getValue()); startSubEntry(entry, newSegmentNameBox.getValue());
await saveTracker(tracker, this.app, getSectionInfo()); await saveTracker(tracker, this.app, file, getSectionInfo());
}); });
} }
let editButton = new ButtonComponent(entryButtons) let editButton = new ButtonComponent(entryButtons)
@ -298,7 +298,7 @@ function addEditableTableRow(tracker: Tracker, entry: Entry, table: HTMLTableEle
if (nameBox.getValue()) { if (nameBox.getValue()) {
entry.name = nameBox.getValue(); entry.name = nameBox.getValue();
namePar.setText(entry.name); namePar.setText(entry.name);
await saveTracker(tracker, this.app, getSectionInfo()); await saveTracker(tracker, this.app, file, getSectionInfo());
} }
} else { } else {
namePar.hidden = true; namePar.hidden = true;
@ -313,11 +313,11 @@ function addEditableTableRow(tracker: Tracker, entry: Entry, table: HTMLTableEle
.setIcon("lucide-trash") .setIcon("lucide-trash")
.onClick(async () => { .onClick(async () => {
removeEntry(tracker.entries, entry); removeEntry(tracker.entries, entry);
await saveTracker(tracker, this.app, getSectionInfo()); await saveTracker(tracker, this.app, file, getSectionInfo());
}); });
if (entry.subEntries) { if (entry.subEntries) {
for (let sub of entry.subEntries) for (let sub of entry.subEntries)
addEditableTableRow(tracker, sub, table, newSegmentNameBox, running, getSectionInfo, settings, indent + 1); addEditableTableRow(tracker, sub, table, newSegmentNameBox, running, file, getSectionInfo, settings, indent + 1);
} }
} }

View file

@ -0,0 +1,29 @@
{
"file-explorer": true,
"global-search": true,
"switcher": true,
"graph": true,
"backlink": true,
"outgoing-link": true,
"tag-pane": true,
"page-preview": true,
"daily-notes": true,
"templates": true,
"note-composer": true,
"command-palette": true,
"slash-command": false,
"editor-status": true,
"markdown-importer": false,
"zk-prefixer": false,
"random-note": false,
"outline": true,
"word-count": true,
"slides": false,
"audio-recorder": false,
"workspaces": false,
"file-recovery": true,
"publish": false,
"sync": false,
"canvas": true,
"bookmarks": true
}

View file

@ -4,6 +4,7 @@
"switcher", "switcher",
"graph", "graph",
"backlink", "backlink",
"canvas",
"outgoing-link", "outgoing-link",
"tag-pane", "tag-pane",
"page-preview", "page-preview",
@ -12,8 +13,8 @@
"note-composer", "note-composer",
"command-palette", "command-palette",
"editor-status", "editor-status",
"starred", "bookmarks",
"outline", "outline",
"word-count", "word-count",
"file-recovery" "file-recovery"
] ]

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,10 @@
{
"id": "simple-time-tracker",
"name": "Super Simple Time Tracker",
"version": "0.1.6",
"minAppVersion": "1.2.8",
"description": "Multi-purpose time trackers for your notes!",
"author": "Ellpeck",
"authorUrl": "https://ellpeck.de",
"isDesktopOnly": false
}

View file

@ -1,10 +1,10 @@
{ {
"id": "simple-time-tracker", "id": "simple-time-tracker",
"name": "Super Simple Time Tracker", "name": "Super Simple Time Tracker",
"version": "0.1.6", "version": "0.1.6",
"minAppVersion": "0.15.0", "minAppVersion": "1.2.8",
"description": "Multi-purpose time trackers for your notes!", "description": "Multi-purpose time trackers for your notes!",
"author": "Ellpeck", "author": "Ellpeck",
"authorUrl": "https://ellpeck.de", "authorUrl": "https://ellpeck.de",
"isDesktopOnly": false "isDesktopOnly": false
} }

View file

@ -0,0 +1,64 @@
.simple-time-tracker-support {
max-width: 50%;
width: 400px;
height: auto;
}
.simple-time-tracker-btn,
.simple-time-tracker-txt {
display: block;
margin-left: auto;
margin-right: auto;
}
.simple-time-tracker-txt {
text-align: center;
}
.simple-time-tracker-btn {
margin-top: 10px;
margin-bottom: 10px;
}
.simple-time-tracker-btn svg {
width: 32px;
height: 32px;
}
.simple-time-tracker-bottom button {
margin: 10px 5px 10px 5px;
}
.simple-time-tracker-timers,
.simple-time-tracker-bottom {
display: flex;
justify-content: center;
text-align: center;
}
.simple-time-tracker-timers span {
display: block;
}
.simple-time-tracker-timer {
margin: 20px;
}
.simple-time-tracker-timer-time {
font-size: xx-large;
font-weight: bolder;
}
.simple-time-tracker-table {
width: 100%;
margin-top: 20px;
}
.simple-time-tracker-table td,
.simple-time-tracker-table th {
border: none;
}
.simple-time-tracker-table .clickable-icon {
display: inline;
}

View file

@ -1,64 +1,64 @@
.simple-time-tracker-support { .simple-time-tracker-support {
max-width: 50%; max-width: 50%;
width: 400px; width: 400px;
height: auto; height: auto;
} }
.simple-time-tracker-btn, .simple-time-tracker-btn,
.simple-time-tracker-txt { .simple-time-tracker-txt {
display: block; display: block;
margin-left: auto; margin-left: auto;
margin-right: auto; margin-right: auto;
} }
.simple-time-tracker-txt { .simple-time-tracker-txt {
text-align: center; text-align: center;
} }
.simple-time-tracker-btn { .simple-time-tracker-btn {
margin-top: 10px; margin-top: 10px;
margin-bottom: 10px; margin-bottom: 10px;
} }
.simple-time-tracker-btn svg { .simple-time-tracker-btn svg {
width: 32px; width: 32px;
height: 32px; height: 32px;
} }
.simple-time-tracker-bottom button { .simple-time-tracker-bottom button {
margin: 10px 5px 10px 5px; margin: 10px 5px 10px 5px;
} }
.simple-time-tracker-timers, .simple-time-tracker-timers,
.simple-time-tracker-bottom { .simple-time-tracker-bottom {
display: flex; display: flex;
justify-content: center; justify-content: center;
text-align: center; text-align: center;
} }
.simple-time-tracker-timers span { .simple-time-tracker-timers span {
display: block; display: block;
} }
.simple-time-tracker-timer { .simple-time-tracker-timer {
margin: 20px; margin: 20px;
} }
.simple-time-tracker-timer-time { .simple-time-tracker-timer-time {
font-size: xx-large; font-size: xx-large;
font-weight: bolder; font-weight: bolder;
} }
.simple-time-tracker-table { .simple-time-tracker-table {
width: 100%; width: 100%;
margin-top: 20px; margin-top: 20px;
} }
.simple-time-tracker-table td, .simple-time-tracker-table td,
.simple-time-tracker-table th { .simple-time-tracker-table th {
border: none; border: none;
} }
.simple-time-tracker-table .clickable-icon { .simple-time-tracker-table .clickable-icon {
display: inline; display: inline;
} }

View file

@ -2,14 +2,5 @@
These are the notes for my cool project. There's so much left to do! I wish I had a way to track the amount of time I spend on each part of the project. These are the notes for my cool project. There's so much left to do! I wish I had a way to track the amount of time I spend on each part of the project.
```simple-time-tracker ```simple-time-tracker
{"entries":[{"name":"Segment 1","startTime":1666189948,"endTime":1666189951,"subEntries":null},{"name":"Segment 2","startTime":1666189953,"endTime":1666189961,"subEntries":null},{"name":"Segment 3","startTime":null,"endTime":null,"subEntries":[{"name":"Part 1","startTime":1666189962,"endTime":1666189995,"subEntries":null},{"name":"Part 2","startTime":1666190004,"endTime":1666190025,"subEntries":null},{"name":"Part 3","startTime":1666190094,"endTime":1666190101,"subEntries":null}]},{"name":"Segment 4","startTime":1666190088,"endTime":1666190091,"subEntries":null}]} {"entries":[{"name":"Segment 1","startTime":1666189948,"endTime":1666189951,"subEntries":null},{"name":"Segment 2","startTime":1666189953,"endTime":1666189961,"subEntries":null},{"name":"Segment 3","startTime":null,"endTime":null,"subEntries":[{"name":"Part 1","startTime":1666189962,"endTime":1666189995,"subEntries":null},{"name":"Part 2","startTime":1666190004,"endTime":1666190025,"subEntries":null},{"name":"Part 3","startTime":1666190094,"endTime":1666190101,"subEntries":null}]},{"name":"Segment 4","startTime":1666190088,"endTime":1666190091,"subEntries":null},{"name":"Segment 5","startTime":1684857704,"endTime":1684857708,"subEntries":null},{"name":"Segment 6","startTime":1684857710,"endTime":1684857712,"subEntries":null},{"name":"Segment 7","startTime":1684857729,"endTime":1684857732,"subEntries":null},{"name":"Segment 8","startTime":1684857743,"endTime":1684857748,"subEntries":null}]}
``` ```
```
Think about project,22-09-27 09:09:37,22-09-27 09:59:48,50m 11s
Create project note,22-09-27 10:00:10,22-09-27 10:00:15,5s
Work on project,22-09-27 10:00:30,22-09-27 10:08:21,7m 51s
Segment 4,22-09-28 01:27:24,22-09-28 01:27:29,5s
Segment 5,22-09-28 01:28:15,22-09-28 01:28:18,3s
```

View file

@ -0,0 +1,6 @@
{
"nodes":[
{"type":"file","file":"test/Cool Project.md","id":"e41a2deb229880a8","x":-720,"y":-620,"width":1120,"height":1000}
],
"edges":[]
}