Scroll-Pfeile, abschliessbare Termine, mehr Zeilenabstand
This commit is contained in:
1 parent
b98ddc33fb
commit
550a28eef9
3 files changed
+112
-8
No files matched your search
@@ -11,6 +11,7 @@ Kalenderansicht für Obsidian Bases. Jeder Termin ist eine eigene Notiz.
|
|||||||
- Farbige Termine
|
- Farbige Termine
|
||||||
- Status-Flags (frei wählbar, mehrere pro Termin) als farbige Pillen
|
- Status-Flags (frei wählbar, mehrere pro Termin) als farbige Pillen
|
||||||
- Aufgaben (`- [ ]`) in der Beschreibung werden als Checkboxen angezeigt und lassen sich im Kalender abhaken
|
- Aufgaben (`- [ ]`) in der Beschreibung werden als Checkboxen angezeigt und lassen sich im Kalender abhaken
|
||||||
|
- Optional abschließbare Termine: erledigte werden durchgestrichen und verlieren an Farbe; vergangene Termine ohne Abschluss-Funktion verlieren ebenfalls an Farbe
|
||||||
|
|
||||||
## Voraussetzungen
|
## Voraussetzungen
|
||||||
|
|
||||||
@@ -67,6 +68,8 @@ Agenda
|
|||||||
| `allDay` | `true` für ganztägige Termine |
|
| `allDay` | `true` für ganztägige Termine |
|
||||||
| `color` | Hex-Farbe, optional |
|
| `color` | Hex-Farbe, optional |
|
||||||
| `status` | Liste frei wählbarer Status-Namen, optional |
|
| `status` | Liste frei wählbarer Status-Namen, optional |
|
||||||
|
| `completable` | `true`, wenn der Termin abgeschlossen werden kann, optional |
|
||||||
|
| `done` | `true`, wenn der abschließbare Termin erledigt ist, optional |
|
||||||
|
|
||||||
Titel und Beschreibung stehen unter den Überschriften `## Titel` und `## Beschreibung` und werden im Kalender angezeigt.
|
Titel und Beschreibung stehen unter den Überschriften `## Titel` und `## Beschreibung` und werden im Kalender angezeigt.
|
||||||
|
|
||||||
|
|||||||
@@ -146,6 +146,8 @@ function normStatus(v) {
|
|||||||
return [String(v).trim()];
|
return [String(v).trim()];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const truthy = (v) => v === true || String(v).toLowerCase() === 'true';
|
||||||
|
|
||||||
function fmStrings(start, end, allDay) {
|
function fmStrings(start, end, allDay) {
|
||||||
return allDay
|
return allDay
|
||||||
? { start: fmtDate(start), end: fmtDate(addDays(end, -1)) }
|
? { start: fmtDate(start), end: fmtDate(addDays(end, -1)) }
|
||||||
@@ -168,6 +170,7 @@ function readEvent(file, fm, content) {
|
|||||||
start = s.date;
|
start = s.date;
|
||||||
end = e && e.date > start ? e.date : new Date(start.getTime() + 60 * MIN);
|
end = e && e.date > start ? e.date : new Date(start.getTime() + 60 * MIN);
|
||||||
}
|
}
|
||||||
|
const completable = truthy(fm.completable);
|
||||||
return {
|
return {
|
||||||
file,
|
file,
|
||||||
title: (content && content.title) || file.basename,
|
title: (content && content.title) || file.basename,
|
||||||
@@ -177,6 +180,8 @@ function readEvent(file, fm, content) {
|
|||||||
allDay,
|
allDay,
|
||||||
color: typeof fm.color === 'string' ? fm.color : '',
|
color: typeof fm.color === 'string' ? fm.color : '',
|
||||||
status: normStatus(fm.status),
|
status: normStatus(fm.status),
|
||||||
|
completable,
|
||||||
|
done: completable && truthy(fm.done),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -208,6 +213,8 @@ class EventModal extends Modal {
|
|||||||
eTime: fmtTime(data.end),
|
eTime: fmtTime(data.end),
|
||||||
color: data.color || '',
|
color: data.color || '',
|
||||||
status: [...data.status],
|
status: [...data.status],
|
||||||
|
completable: !!data.completable,
|
||||||
|
done: !!data.done,
|
||||||
};
|
};
|
||||||
this.f = f;
|
this.f = f;
|
||||||
|
|
||||||
@@ -228,6 +235,18 @@ class EventModal extends Modal {
|
|||||||
eTime.style.display = v ? 'none' : '';
|
eTime.style.display = v ? 'none' : '';
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
new Setting(contentEl)
|
||||||
|
.setName('Abschließbar')
|
||||||
|
.setDesc('Der Termin kann als erledigt markiert werden.')
|
||||||
|
.addToggle((t) => t.setValue(f.completable).onChange((v) => {
|
||||||
|
f.completable = v;
|
||||||
|
doneSetting.settingEl.style.display = v ? '' : 'none';
|
||||||
|
}));
|
||||||
|
const doneSetting = new Setting(contentEl)
|
||||||
|
.setName('Erledigt')
|
||||||
|
.addToggle((t) => t.setValue(f.done).onChange((v) => { f.done = v; }));
|
||||||
|
doneSetting.settingEl.style.display = f.completable ? '' : 'none';
|
||||||
|
|
||||||
contentEl.createDiv({ cls: 'bc-field-label', text: 'Zeitraum' });
|
contentEl.createDiv({ cls: 'bc-field-label', text: 'Zeitraum' });
|
||||||
const mkRow = (label, dateKey, timeKey) => {
|
const mkRow = (label, dateKey, timeKey) => {
|
||||||
const row = contentEl.createDiv('bc-row');
|
const row = contentEl.createDiv('bc-row');
|
||||||
@@ -338,6 +357,8 @@ class EventModal extends Modal {
|
|||||||
allDay: f.allDay,
|
allDay: f.allDay,
|
||||||
color: f.color,
|
color: f.color,
|
||||||
status: f.status,
|
status: f.status,
|
||||||
|
completable: f.completable,
|
||||||
|
done: f.completable && f.done,
|
||||||
});
|
});
|
||||||
this.close();
|
this.close();
|
||||||
}
|
}
|
||||||
@@ -622,6 +643,7 @@ class CalendarView extends (BasesView || Object) {
|
|||||||
el.style.gridRow = String(offset + s.lane + 1);
|
el.style.gridRow = String(offset + s.lane + 1);
|
||||||
if (s.contL) el.classList.add('is-cont-l');
|
if (s.contL) el.classList.add('is-cont-l');
|
||||||
if (s.contR) el.classList.add('is-cont-r');
|
if (s.contR) el.classList.add('is-cont-r');
|
||||||
|
el.classList.add(...this.stateClasses(ev));
|
||||||
el.setAttribute('title', [timeRange(ev), ev.title, ev.description].filter(Boolean).join('\n'));
|
el.setAttribute('title', [timeRange(ev), ev.title, ev.description].filter(Boolean).join('\n'));
|
||||||
this.fillEvent(el, ev, { time: !bar ? fmtTime(ev.start) : '' });
|
this.fillEvent(el, ev, { time: !bar ? fmtTime(ev.start) : '' });
|
||||||
el.addEventListener('pointerdown', (e) => this.beginMove(e, ev, el));
|
el.addEventListener('pointerdown', (e) => this.beginMove(e, ev, el));
|
||||||
@@ -657,9 +679,22 @@ class CalendarView extends (BasesView || Object) {
|
|||||||
return ends.length;
|
return ends.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stateClasses(ev) {
|
||||||
|
if (ev.done) return ['is-done'];
|
||||||
|
// Abschließbare Termine bleiben auffällig, bis sie erledigt sind
|
||||||
|
return !ev.completable && ev.end <= new Date() ? ['is-past'] : [];
|
||||||
|
}
|
||||||
|
|
||||||
fillEvent(el, ev, o) {
|
fillEvent(el, ev, o) {
|
||||||
setColor(el, ev.color);
|
setColor(el, ev.color);
|
||||||
const head = el.createDiv('bc-ev-head');
|
const head = el.createDiv('bc-ev-head');
|
||||||
|
if (ev.completable) {
|
||||||
|
const cb = head.createEl('input', { type: 'checkbox', cls: 'bc-done-cb' });
|
||||||
|
cb.checked = ev.done;
|
||||||
|
cb.addEventListener('pointerdown', (e) => e.stopPropagation());
|
||||||
|
cb.addEventListener('click', (e) => e.stopPropagation());
|
||||||
|
cb.addEventListener('change', () => this.plugin.setDone(ev, cb.checked));
|
||||||
|
}
|
||||||
if (o.time) head.createSpan({ cls: 'bc-ev-time', text: o.time });
|
if (o.time) head.createSpan({ cls: 'bc-ev-time', text: o.time });
|
||||||
head.createSpan({ cls: 'bc-ev-title', text: ev.title });
|
head.createSpan({ cls: 'bc-ev-title', text: ev.title });
|
||||||
if (ev.status.length) {
|
if (ev.status.length) {
|
||||||
@@ -705,6 +740,7 @@ class CalendarView extends (BasesView || Object) {
|
|||||||
const scroll = body.createDiv('bc-tg');
|
const scroll = body.createDiv('bc-tg');
|
||||||
scroll.style.setProperty('--bc-hh', `${hh}px`);
|
scroll.style.setProperty('--bc-hh', `${hh}px`);
|
||||||
this.scrollEl = scroll;
|
this.scrollEl = scroll;
|
||||||
|
this.thumbs = [];
|
||||||
|
|
||||||
const sticky = scroll.createDiv('bc-tg-sticky');
|
const sticky = scroll.createDiv('bc-tg-sticky');
|
||||||
const hrow = sticky.createDiv('bc-tg-head');
|
const hrow = sticky.createDiv('bc-tg-head');
|
||||||
@@ -747,6 +783,9 @@ class CalendarView extends (BasesView || Object) {
|
|||||||
scroll.scrollTop = prevScroll !== null && prevScroll !== undefined
|
scroll.scrollTop = prevScroll !== null && prevScroll !== undefined
|
||||||
? prevScroll
|
? prevScroll
|
||||||
: Math.max(0, (8 - startH) * hh);
|
: Math.max(0, (8 - startH) * hh);
|
||||||
|
|
||||||
|
// Erst nach dem Layout messbar: Scroll-Indikatoren der Termine setzen
|
||||||
|
this.thumbs.forEach((update) => update());
|
||||||
}
|
}
|
||||||
|
|
||||||
layoutDay(col, day, startH, endH) {
|
layoutDay(col, day, startH, endH) {
|
||||||
@@ -785,13 +824,26 @@ class CalendarView extends (BasesView || Object) {
|
|||||||
|
|
||||||
for (const it of items) {
|
for (const it of items) {
|
||||||
const ev = it.ev;
|
const ev = it.ev;
|
||||||
const el = col.createDiv({ cls: ['bc-event', 'bc-tevent'] });
|
const el = col.createDiv({ cls: ['bc-event', 'bc-tevent', ...this.stateClasses(ev)] });
|
||||||
el.style.top = `${((it.vs - dayStartMin) * hh) / 60}px`;
|
el.style.top = `${((it.vs - dayStartMin) * hh) / 60}px`;
|
||||||
el.style.height = `${Math.max(((it.ve - it.vs) * hh) / 60 - 1, 18)}px`;
|
el.style.height = `${Math.max(((it.ve - it.vs) * hh) / 60 - 1, 18)}px`;
|
||||||
el.style.left = `calc(${it.col} / ${it.cols} * 100% + 1px)`;
|
el.style.left = `calc(${it.col} / ${it.cols} * 100% + 1px)`;
|
||||||
el.style.width = `calc(100% / ${it.cols} - 3px)`;
|
el.style.width = `calc(100% / ${it.cols} - 3px)`;
|
||||||
el.setAttribute('title', [timeRange(ev), ev.title, ev.description].filter(Boolean).join('\n'));
|
el.setAttribute('title', [timeRange(ev), ev.title, ev.description].filter(Boolean).join('\n'));
|
||||||
this.fillEvent(el, ev, { time: timeRange(ev), block: true });
|
setColor(el, ev.color);
|
||||||
|
const inner = el.createDiv('bc-tcontent');
|
||||||
|
this.fillEvent(inner, ev, { time: timeRange(ev), block: true });
|
||||||
|
const up = el.createDiv({ cls: ['bc-more', 'bc-more-up'] });
|
||||||
|
const down = el.createDiv({ cls: ['bc-more', 'bc-more-down'] });
|
||||||
|
setIcon(up, 'chevron-up');
|
||||||
|
setIcon(down, 'chevron-down');
|
||||||
|
const update = () => {
|
||||||
|
const over = inner.scrollHeight - inner.clientHeight;
|
||||||
|
up.style.display = over > 1 && inner.scrollTop > 1 ? '' : 'none';
|
||||||
|
down.style.display = over > 1 && inner.scrollTop < over - 1 ? '' : 'none';
|
||||||
|
};
|
||||||
|
inner.addEventListener('scroll', update, { passive: true });
|
||||||
|
this.thumbs.push(update);
|
||||||
el.addEventListener('pointerdown', (e) => this.beginMove(e, ev, el));
|
el.addEventListener('pointerdown', (e) => this.beginMove(e, ev, el));
|
||||||
if (it.canResize) {
|
if (it.canResize) {
|
||||||
const h = el.createDiv('bc-resize');
|
const h = el.createDiv('bc-resize');
|
||||||
@@ -808,7 +860,7 @@ class CalendarView extends (BasesView || Object) {
|
|||||||
|
|
||||||
openCreate(start, end, allDay) {
|
openCreate(start, end, allDay) {
|
||||||
new EventModal(this.plugin.app, this.plugin, {
|
new EventModal(this.plugin.app, this.plugin, {
|
||||||
isNew: true, title: '', description: '', start, end, allDay, color: '', status: [],
|
isNew: true, title: '', description: '', start, end, allDay, color: '', status: [], completable: false, done: false,
|
||||||
}, {
|
}, {
|
||||||
onSave: (d) => this.plugin.createEvent(d),
|
onSave: (d) => this.plugin.createEvent(d),
|
||||||
}).open();
|
}).open();
|
||||||
@@ -1222,6 +1274,7 @@ module.exports = class BasesCalendarPlugin extends Plugin {
|
|||||||
const t = fmStrings(d.start, d.end, d.allDay);
|
const t = fmStrings(d.start, d.end, d.allDay);
|
||||||
const yaml = ['---', `start: ${t.start}`, `end: ${t.end}`, `allDay: ${d.allDay}`];
|
const yaml = ['---', `start: ${t.start}`, `end: ${t.end}`, `allDay: ${d.allDay}`];
|
||||||
if (hexToRgb(d.color)) yaml.push(`color: ${JSON.stringify(d.color)}`);
|
if (hexToRgb(d.color)) yaml.push(`color: ${JSON.stringify(d.color)}`);
|
||||||
|
if (d.completable) yaml.push('completable: true', `done: ${!!d.done}`);
|
||||||
if (d.status.length) {
|
if (d.status.length) {
|
||||||
yaml.push('status:');
|
yaml.push('status:');
|
||||||
d.status.forEach((s) => yaml.push(` - ${JSON.stringify(s)}`));
|
d.status.forEach((s) => yaml.push(` - ${JSON.stringify(s)}`));
|
||||||
@@ -1237,17 +1290,31 @@ module.exports = class BasesCalendarPlugin extends Plugin {
|
|||||||
const t = fmStrings(d.start, d.end, d.allDay);
|
const t = fmStrings(d.start, d.end, d.allDay);
|
||||||
const color = hexToRgb(d.color) ? d.color : '';
|
const color = hexToRgb(d.color) ? d.color : '';
|
||||||
this.contentCache.set(file.path, { mtime: 0, title: d.title, description: d.description });
|
this.contentCache.set(file.path, { mtime: 0, title: d.title, description: d.description });
|
||||||
this.setPending(file.path, { start: t.start, end: t.end, allDay: d.allDay, color, status: d.status });
|
this.setPending(file.path, {
|
||||||
|
start: t.start, end: t.end, allDay: d.allDay, color, status: d.status, completable: d.completable, done: d.done,
|
||||||
|
});
|
||||||
await this.app.fileManager.processFrontMatter(file, (fm) => {
|
await this.app.fileManager.processFrontMatter(file, (fm) => {
|
||||||
fm.start = t.start;
|
fm.start = t.start;
|
||||||
fm.end = t.end;
|
fm.end = t.end;
|
||||||
fm.allDay = d.allDay;
|
fm.allDay = d.allDay;
|
||||||
if (color) fm.color = color; else delete fm.color;
|
if (color) fm.color = color; else delete fm.color;
|
||||||
if (d.status.length) fm.status = d.status; else delete fm.status;
|
if (d.status.length) fm.status = d.status; else delete fm.status;
|
||||||
|
if (d.completable) {
|
||||||
|
fm.completable = true;
|
||||||
|
fm.done = !!d.done;
|
||||||
|
} else {
|
||||||
|
delete fm.completable;
|
||||||
|
delete fm.done;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
await this.app.vault.process(file, (text) => applyBody(text, d.title, d.description));
|
await this.app.vault.process(file, (text) => applyBody(text, d.title, d.description));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async setDone(ev, done) {
|
||||||
|
this.setPending(ev.file.path, { done });
|
||||||
|
await this.app.fileManager.processFrontMatter(ev.file, (fm) => { fm.done = done; });
|
||||||
|
}
|
||||||
|
|
||||||
async toggleTask(file, index, done) {
|
async toggleTask(file, index, done) {
|
||||||
const mark = done ? '[x]' : '[ ]';
|
const mark = done ? '[x]' : '[ ]';
|
||||||
await this.app.vault.process(file, (text) => {
|
await this.app.vault.process(file, (text) => {
|
||||||
|
|||||||
+38
-4
@@ -98,7 +98,7 @@
|
|||||||
user-select: none;
|
user-select: none;
|
||||||
background: var(--bc-color, var(--interactive-accent));
|
background: var(--bc-color, var(--interactive-accent));
|
||||||
color: var(--bc-fg, var(--text-on-accent));
|
color: var(--bc-fg, var(--text-on-accent));
|
||||||
line-height: 1.3;
|
line-height: 1.45;
|
||||||
}
|
}
|
||||||
.bc-event.bc-dragging {
|
.bc-event.bc-dragging {
|
||||||
opacity: 0.8;
|
opacity: 0.8;
|
||||||
@@ -107,6 +107,14 @@
|
|||||||
cursor: grabbing;
|
cursor: grabbing;
|
||||||
box-shadow: var(--shadow-s);
|
box-shadow: var(--shadow-s);
|
||||||
}
|
}
|
||||||
|
.bc-event.is-past,
|
||||||
|
.bc-event.is-done { filter: saturate(0.3); opacity: 0.7; }
|
||||||
|
.bc-event.is-done .bc-ev-time,
|
||||||
|
.bc-event.is-done .bc-ev-title,
|
||||||
|
.bc-event.is-done .bc-desc-text,
|
||||||
|
.bc-event.is-done .bc-desc-line,
|
||||||
|
.bc-event.is-done .bc-pill { text-decoration: line-through; }
|
||||||
|
.bc-done-cb { flex: none; margin: 0; cursor: pointer; }
|
||||||
.bc-event.is-cont-l { border-top-left-radius: 0; border-bottom-left-radius: 0; margin-left: 0; }
|
.bc-event.is-cont-l { border-top-left-radius: 0; border-bottom-left-radius: 0; margin-left: 0; }
|
||||||
.bc-event.is-cont-r { border-top-right-radius: 0; border-bottom-right-radius: 0; margin-right: 0; }
|
.bc-event.is-cont-r { border-top-right-radius: 0; border-bottom-right-radius: 0; margin-right: 0; }
|
||||||
|
|
||||||
@@ -116,8 +124,9 @@
|
|||||||
.bc-ev-desc {
|
.bc-ev-desc {
|
||||||
opacity: 0.95;
|
opacity: 0.95;
|
||||||
font-size: var(--font-smallest);
|
font-size: var(--font-smallest);
|
||||||
|
margin-top: 2px;
|
||||||
}
|
}
|
||||||
.bc-desc-line { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
.bc-desc-line { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 1px 0; }
|
||||||
.bc-task { display: flex; align-items: center; gap: 4px; }
|
.bc-task { display: flex; align-items: center; gap: 4px; }
|
||||||
.bc-task input[type="checkbox"] { flex: none; margin: 0; cursor: pointer; }
|
.bc-task input[type="checkbox"] { flex: none; margin: 0; cursor: pointer; }
|
||||||
.bc-task.is-done .bc-desc-text { text-decoration: line-through; opacity: 0.7; }
|
.bc-task.is-done .bc-desc-text { text-decoration: line-through; opacity: 0.7; }
|
||||||
@@ -211,15 +220,40 @@
|
|||||||
.bc-tevent {
|
.bc-tevent {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 2px 5px;
|
padding: 0;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
white-space: normal;
|
white-space: normal;
|
||||||
}
|
}
|
||||||
.bc-tevent .bc-ev-head { flex-wrap: wrap; row-gap: 0; }
|
.bc-tevent .bc-ev-head { flex-wrap: wrap; row-gap: 0; }
|
||||||
.bc-tevent .bc-ev-title { white-space: normal; }
|
.bc-tevent .bc-ev-title { white-space: normal; }
|
||||||
.bc-tevent .bc-pills { margin-top: 2px; }
|
.bc-tevent .bc-pills { margin-top: 2px; }
|
||||||
.bc-tevent .bc-ev-desc { margin-top: 2px; }
|
.bc-tevent .bc-ev-desc { margin-top: 3px; }
|
||||||
.bc-tevent .bc-desc-line { white-space: normal; }
|
.bc-tevent .bc-desc-line { white-space: normal; }
|
||||||
|
.bc-tcontent {
|
||||||
|
position: absolute;
|
||||||
|
inset: 0;
|
||||||
|
box-sizing: border-box;
|
||||||
|
padding: 2px 18px 2px 5px;
|
||||||
|
overflow-y: auto;
|
||||||
|
scrollbar-width: none;
|
||||||
|
}
|
||||||
|
.bc-tcontent::-webkit-scrollbar { display: none; }
|
||||||
|
.bc-more {
|
||||||
|
position: absolute;
|
||||||
|
right: 2px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
width: 14px;
|
||||||
|
height: 14px;
|
||||||
|
border-radius: 50%;
|
||||||
|
pointer-events: none;
|
||||||
|
background: var(--bc-fg, var(--text-on-accent));
|
||||||
|
color: var(--bc-color, var(--interactive-accent));
|
||||||
|
}
|
||||||
|
.bc-more .svg-icon { width: 12px; height: 12px; stroke-width: 3; }
|
||||||
|
.bc-more-up { top: 2px; }
|
||||||
|
.bc-more-down { bottom: 8px; }
|
||||||
.bc-resize {
|
.bc-resize {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
left: 0;
|
left: 0;
|
||||||
|
|||||||
Reference in new issue
Block a user