dataview js widgets
helpful tips
- {today} is how you make it reference the current day's thing
- example:
const file3 = await dv.io.load(folder structure/${today} shift);
progress bars
const content = await dv.io.load("BB Docs/j2j.md");
const lines = content.split("\n");
const total = lines.filter(l => l.match(/^- [[ x]]/)).length;
const done = lines.filter(l => l.match(/^- [x]/)).length;
const pct = total === 0 ? 0 : Math.round((done / total) * 100);
dv.el("div", <div style="font-size:12px;color:var(--text-muted);margin-bottom:4px">${done} of ${total} items complete</div> <div style="background:var(--background-modifier-border);border-radius:6px;height:10px;width:100%"> <div style="background:var(--interactive-accent);width:${pct}%;height:10px;border-radius:6px;transition:width 0.3s"></div> </div> <div style="font-size:11px;color:var(--text-muted);margin-top:4px">${pct}%</div> );
reset for new week button
const { vault } = app;
const filePath = "BB Docs/bb weekly dashboard.md";
const getWeekRange = () => {
const now = new Date();
const day = now.getDay();
const monday = new Date(now);
monday.setDate(now.getDate() - (day === 0 ? 6 : day - 1));
const sunday = new Date(monday);
sunday.setDate(monday.getDate() + 6);
const fmt = d => d.toLocaleDateString('en-US', {month:'short', day:'numeric'});
return ${fmt(monday)} – ${fmt(sunday)};
};
const button = this.container.createEl("button", {
text: "🔄 reset for new week",
attr: {style: "background:var(--interactive-accent);color:var(--text-on-accent);border:none;border-radius:6px;padding:8px 16px;font-size:13px;cursor:pointer;margin-bottom:16px;"}
});
button.addEventListener("click", async () => {
const file = vault.getAbstractFileByPath(filePath);
let content = await vault.read(file);
// Update week date range
content = content.replace(
/## this week *[.*?]*/,
## this week *[${getWeekRange()}]*
);
// Reset on our radar — wipe bullets between header and next ---
content = content.replace(
/(### 🗓️ on our radar\s*\n*things coming up.?*\s\n)([\s\S]*?)(\n---)/,
$1\n$3
);
await vault.modify(file, content);
new Notice("✅ Weekly dashboard reset!");
});
list recent notes
const pages = dv.pages('"BB Docs/Medical Appointments"')
.sort(p => p.Date, 'desc')
.slice(0, 6);
const container = this.container;
const wrapper = container.createEl("div");
for (const p of pages) {
const date = p.Date ? new Date(p.Date).toLocaleDateString('en-US', {month:'short', day:'numeric', year:'numeric'}) : '—';
const person = p.Person || '';
const tag = p.Tags ? (Array.isArray(p.Tags) ? p.Tags[0] : p.Tags) : '';
const category = p["medical category"] || p["medical cate"] || '';
const card = wrapper.createEl("div", {attr: {style: "border:1px solid var(--background-modifier-border);border-radius:8px;padding:12px 14px;margin-bottom:8px;cursor:pointer;"}});
card.addEventListener("click", () => app.workspace.openLinkText(p.file.path, ""));
const top = card.createEl("div", {attr: {style: "display:flex;justify-content:space-between;align-items:flex-start;margin-bottom:6px"}});
top.createEl("span", {text: p.file.name, attr: {style: "font-size:14px;font-weight:500;color:var(--text-normal)"}});
top.createEl("span", {text: date, attr: {style: "font-size:11px;color:var(--text-muted);white-space:nowrap;margin-left:12px"}});
const pills = card.createEl("div", {attr: {style: "display:flex;gap:6px;flex-wrap:wrap"}});
const pillStyle = "font-size:11px;background:var(--background-secondary);border-radius:4px;padding:1px 7px;color:var(--text-muted)";
if (person) pills.createEl("span", {text: person, attr: {style: pillStyle}});
if (tag) pills.createEl("span", {text: tag, attr: {style: pillStyle}});
if (category && category !== tag) pills.createEl("span", {text: category, attr: {style: pillStyle}});
}