added command to insert tracker

This commit is contained in:
Ell 2022-09-27 21:52:02 +02:00
parent d001d7887a
commit 18cdda3e9b
4 changed files with 50 additions and 28 deletions

View file

@ -17,6 +17,14 @@ export default class SimpleTimeTrackerPlugin extends Plugin {
e.empty(); e.empty();
displayTracker(tracker, e, () => i.getSectionInfo(e)); displayTracker(tracker, e, () => i.getSectionInfo(e));
}); });
this.addCommand({
id: `insert-simple-time-tracker`,
name: `Insert Simple Time Tracker`,
editorCallback: (e, _) => {
e.replaceSelection("```simple-time-tracker\n```\n");
}
});
} }
async loadSettings() { async loadSettings() {

View file

@ -77,10 +77,11 @@ export function displayTracker(tracker: Tracker, element: HTMLElement, getSectio
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" }); let total = totalDiv.createEl("span", { cls: "simple-time-tracker-timer-time", text: "0s" });
totalDiv.createEl("span", { text: "Total" }); totalDiv.createEl("span", { text: "Total" });
// add list // add table
if (tracker.entries.length > 0) {
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" }),
@ -98,6 +99,7 @@ export function displayTracker(tracker: Tracker, element: HTMLElement, getSectio
row.createEl("td", { text: getCountdownDisplay(moment.duration(duration)) }); row.createEl("td", { text: getCountdownDisplay(moment.duration(duration)) });
} }
} }
}
setCountdownValues(tracker, current, total, currentDiv); setCountdownValues(tracker, current, total, currentDiv);
let intervalId = window.setInterval(() => { let intervalId = window.setInterval(() => {

File diff suppressed because one or more lines are too long

3
test-vault/test2.md Normal file
View file

@ -0,0 +1,3 @@
```simple-time-tracker
{"entries":[{"name":"Segment 1","startTime":1664308278,"endTime":1664308284},{"name":"Segment 2","startTime":1664308285,"endTime":1664308286},{"name":"Segment 3","startTime":1664308299,"endTime":1664308312}]}
```