mirror of
https://github.com/Ellpeck/ObsidianSimpleTimeTracker.git
synced 2024-11-24 10:08:35 +01:00
added command to insert tracker
This commit is contained in:
parent
d001d7887a
commit
18cdda3e9b
4 changed files with 50 additions and 28 deletions
|
@ -17,6 +17,14 @@ export default class SimpleTimeTrackerPlugin extends Plugin {
|
|||
e.empty();
|
||||
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() {
|
||||
|
|
|
@ -77,25 +77,27 @@ export function displayTracker(tracker: Tracker, element: HTMLElement, getSectio
|
|||
let current = currentDiv.createEl("span", { cls: "simple-time-tracker-timer-time" });
|
||||
currentDiv.createEl("span", { text: "Current" });
|
||||
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" });
|
||||
|
||||
// add list
|
||||
let table = element.createEl("table", { cls: "simple-time-tracker-table" });
|
||||
table.createEl("tr").append(
|
||||
createEl("th", { text: "Segment" }),
|
||||
createEl("th", { text: "Start time" }),
|
||||
createEl("th", { text: "End time" }),
|
||||
createEl("th", { text: "Total" }));
|
||||
// add table
|
||||
if (tracker.entries.length > 0) {
|
||||
let table = element.createEl("table", { cls: "simple-time-tracker-table" });
|
||||
table.createEl("tr").append(
|
||||
createEl("th", { text: "Segment" }),
|
||||
createEl("th", { text: "Start time" }),
|
||||
createEl("th", { text: "End time" }),
|
||||
createEl("th", { text: "Total" }));
|
||||
|
||||
for (let entry of tracker.entries) {
|
||||
let row = table.createEl("tr");
|
||||
row.createEl("td", { text: entry.name });
|
||||
row.createEl("td", { text: moment.unix(entry.startTime).format("YY-MM-DD hh:mm:ss") });
|
||||
if (entry.endTime) {
|
||||
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));
|
||||
row.createEl("td", { text: getCountdownDisplay(moment.duration(duration)) });
|
||||
for (let entry of tracker.entries) {
|
||||
let row = table.createEl("tr");
|
||||
row.createEl("td", { text: entry.name });
|
||||
row.createEl("td", { text: moment.unix(entry.startTime).format("YY-MM-DD hh:mm:ss") });
|
||||
if (entry.endTime) {
|
||||
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));
|
||||
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
3
test-vault/test2.md
Normal 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}]}
|
||||
```
|
Loading…
Reference in a new issue