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",
"name": "Super Simple Time Tracker",
"version": "0.1.6",
"minAppVersion": "0.15.0",
"minAppVersion": "1.2.8",
"description": "Multi-purpose time trackers for your notes!",
"author": "Ellpeck",
"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) => {
let tracker: Tracker = loadTracker(s);
e.empty();
displayTracker(tracker, e, () => i.getSectionInfo(e), this.settings);
displayTracker(tracker, e, i.sourcePath, () => i.getSectionInfo(e), this.settings);
});
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";
export interface Tracker {
@ -12,8 +12,8 @@ export interface Entry {
subEntries: Entry[];
}
export async function saveTracker(tracker: Tracker, app: App, section: MarkdownSectionInformation): Promise<void> {
let file = app.workspace.getActiveFile();
export async function saveTracker(tracker: Tracker, app: App, fileName: string, section: MarkdownSectionInformation): Promise<void> {
let file = app.vault.getAbstractFileByPath(fileName) as TFile;
if (!file)
return;
let content = await app.vault.read(file);
@ -39,7 +39,7 @@ export function loadTracker(json: string): Tracker {
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
let running = isRunning(tracker);
let btn = new ButtonComponent(element)
@ -52,7 +52,7 @@ export function displayTracker(tracker: Tracker, element: HTMLElement, getSectio
} else {
startNewEntry(tracker, newSegmentNameBox.getValue());
}
await saveTracker(tracker, this.app, getSectionInfo());
await saveTracker(tracker, this.app, file, getSectionInfo());
});
btn.buttonEl.addClass("simple-time-tracker-btn");
let newSegmentNameBox = new TextComponent(element)
@ -80,7 +80,7 @@ export function displayTracker(tracker: Tracker, element: HTMLElement, getSectio
createEl("th"));
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
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 {
let duration = moment.duration(totalTime);
let ret = "";
if (duration.years() > 0)
ret += duration.years() + "y ";
if (duration.months() > 0)
ret += duration.months() + "m ";
if (duration.days() > 0)
ret += duration.days() + "d ";
if (duration.years() > 0)
ret += duration.years() + "y ";
if (duration.months() > 0)
ret += duration.months() + "m ";
if (duration.days() > 0)
ret += duration.days() + "d ";
if (duration.hours() > 0)
ret += duration.hours() + "h ";
if (duration.minutes() > 0)
@ -262,7 +262,7 @@ function createTableSection(entry: Entry, settings: SimpleTimeTrackerSettings):
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 name = row.createEl("td");
@ -283,7 +283,7 @@ function addEditableTableRow(tracker: Tracker, entry: Entry, table: HTMLTableEle
.setTooltip("Continue")
.onClick(async () => {
startSubEntry(entry, newSegmentNameBox.getValue());
await saveTracker(tracker, this.app, getSectionInfo());
await saveTracker(tracker, this.app, file, getSectionInfo());
});
}
let editButton = new ButtonComponent(entryButtons)
@ -298,7 +298,7 @@ function addEditableTableRow(tracker: Tracker, entry: Entry, table: HTMLTableEle
if (nameBox.getValue()) {
entry.name = nameBox.getValue();
namePar.setText(entry.name);
await saveTracker(tracker, this.app, getSectionInfo());
await saveTracker(tracker, this.app, file, getSectionInfo());
}
} else {
namePar.hidden = true;
@ -313,11 +313,11 @@ function addEditableTableRow(tracker: Tracker, entry: Entry, table: HTMLTableEle
.setIcon("lucide-trash")
.onClick(async () => {
removeEntry(tracker.entries, entry);
await saveTracker(tracker, this.app, getSectionInfo());
await saveTracker(tracker, this.app, file, getSectionInfo());
});
if (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",
"graph",
"backlink",
"canvas",
"outgoing-link",
"tag-pane",
"page-preview",
@ -12,8 +13,8 @@
"note-composer",
"command-palette",
"editor-status",
"starred",
"bookmarks",
"outline",
"word-count",
"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",
"name": "Super Simple Time Tracker",
"version": "0.1.6",
"minAppVersion": "0.15.0",
"description": "Multi-purpose time trackers for your notes!",
"author": "Ellpeck",
"authorUrl": "https://ellpeck.de",
"isDesktopOnly": false
"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

@ -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 {
max-width: 50%;
width: 400px;
height: auto;
max-width: 50%;
width: 400px;
height: auto;
}
.simple-time-tracker-btn,
.simple-time-tracker-txt {
display: block;
margin-left: auto;
margin-right: auto;
display: block;
margin-left: auto;
margin-right: auto;
}
.simple-time-tracker-txt {
text-align: center;
text-align: center;
}
.simple-time-tracker-btn {
margin-top: 10px;
margin-bottom: 10px;
margin-top: 10px;
margin-bottom: 10px;
}
.simple-time-tracker-btn svg {
width: 32px;
height: 32px;
width: 32px;
height: 32px;
}
.simple-time-tracker-bottom button {
margin: 10px 5px 10px 5px;
margin: 10px 5px 10px 5px;
}
.simple-time-tracker-timers,
.simple-time-tracker-bottom {
display: flex;
justify-content: center;
text-align: center;
display: flex;
justify-content: center;
text-align: center;
}
.simple-time-tracker-timers span {
display: block;
display: block;
}
.simple-time-tracker-timer {
margin: 20px;
margin: 20px;
}
.simple-time-tracker-timer-time {
font-size: xx-large;
font-weight: bolder;
font-size: xx-large;
font-weight: bolder;
}
.simple-time-tracker-table {
width: 100%;
margin-top: 20px;
width: 100%;
margin-top: 20px;
}
.simple-time-tracker-table td,
.simple-time-tracker-table th {
border: none;
border: none;
}
.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.
```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":[]
}