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,25 +77,27 @@ 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
let table = element.createEl("table", { cls: "simple-time-tracker-table" }); if (tracker.entries.length > 0) {
table.createEl("tr").append( let table = element.createEl("table", { cls: "simple-time-tracker-table" });
createEl("th", { text: "Segment" }), table.createEl("tr").append(
createEl("th", { text: "Start time" }), createEl("th", { text: "Segment" }),
createEl("th", { text: "End time" }), createEl("th", { text: "Start time" }),
createEl("th", { text: "Total" })); createEl("th", { text: "End time" }),
createEl("th", { text: "Total" }));
for (let entry of tracker.entries) { for (let entry of tracker.entries) {
let row = table.createEl("tr"); let row = table.createEl("tr");
row.createEl("td", { text: entry.name }); row.createEl("td", { text: entry.name });
row.createEl("td", { text: moment.unix(entry.startTime).format("YY-MM-DD hh:mm:ss") }); row.createEl("td", { text: moment.unix(entry.startTime).format("YY-MM-DD hh:mm:ss") });
if (entry.endTime) { if (entry.endTime) {
row.createEl("td", { text: moment.unix(entry.endTime).format("YY-MM-DD hh:mm:ss") }); row.createEl("td", { text: moment.unix(entry.endTime).format("YY-MM-DD hh:mm:ss") });
let duration = moment.unix(entry.endTime).diff(moment.unix(entry.startTime)); let duration = moment.unix(entry.endTime).diff(moment.unix(entry.startTime));
row.createEl("td", { text: getCountdownDisplay(moment.duration(duration)) }); row.createEl("td", { text: getCountdownDisplay(moment.duration(duration)) });
}
} }
} }

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}]}
```