PCO Plan 1.10.0: follow several service types in priority order, and read any of them from any dashboard
An account runs more than one service type — a Sunday morning, a Wednesday night, a youth service, a second campus — and until now that meant one ProdDash per type. The module now follows as many as are configured. Admin picks them in priority order. Shell 1.12.0 gives `multiselect` an `orderable: true` that stops being a ticklist: the picks sit in a numbered list with a nudge either way and a remove, over a dropdown holding what is left. Forty switches to read past is not a picker, and a ticklist cannot carry an order anyway. The order is the setting — when two types have a plan at the same date and time, the one higher up wins. The server gathers candidate plans from every ticked type and tiers them: today's plan first, then the next upcoming, then the most recent past, with the configured order breaking a tie. A type that fails is skipped rather than failing the read, unless it is an auth or rate-limit answer, which belongs to the whole connection. The types not being followed are read on a slower lane (45 s) into `state.others`, so they are there to look at without a second connection. Every tile's title bar carries a service-type control. Picking one moves every PCO Plan tile on that browser's dashboard — plan, teams and song key together — onto its plan, over a small page bus in `viewed-type.js`; the choice is per browser and survives a reload. The control hides itself when only one type is configured. Live machinery stays with the type being followed: another type's plan shows its running order with no now marker, no AbleSet and no service clock — it shows that plan's own scheduled time instead, since borrowing the running clock of a different service is exactly the misreading the amber top-bar stripe exists to prevent. Old configs carry `serviceTypeId`; it is read once into the new array and saved, and plan pins still resolve bare, so nothing has to be re-entered. `tools/pco-mock.js` takes `--types N` to pad the list out, for trying the picker against an account with dozens of them. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
f9cd292693
commit
7bb1131378
+38
-20
@@ -14,6 +14,7 @@
|
||||
|
||||
import createTeams from "./teams-client.js";
|
||||
import createKey from "./key-client.js";
|
||||
import { viewOf, onViewedType, addServiceTypeSwitch } from "./viewed-type.js";
|
||||
import { prettyKey } from "./key-notation.js";
|
||||
|
||||
const REFRESH_SVG = '<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12a9 9 0 1 1-2.64-6.36"/><path d="M21 3v6h-6"/></svg>';
|
||||
@@ -38,6 +39,10 @@ function createPlan({ root, moduleApi }) {
|
||||
let lastCurrentId = null;
|
||||
let lastListKey = '';
|
||||
let absView = null; // what the server says AbleSet is doing, if anything
|
||||
// The plan this dashboard is looking at — usually the one the server
|
||||
// follows, otherwise one of the others it also reads.
|
||||
let view = viewOf(null);
|
||||
let offViewed = null;
|
||||
let userScrolledAt = 0;
|
||||
|
||||
root.innerHTML = `
|
||||
@@ -89,6 +94,7 @@ function createPlan({ root, moduleApi }) {
|
||||
moduleApi.saveInstanceSettings({ textSize: Math.min(40, Math.max(9, size + delta)) });
|
||||
applyPrefs();
|
||||
}
|
||||
const switcher = addServiceTypeSwitch({ moduleApi, getState: () => state });
|
||||
moduleApi.header.addButton({ icon: MINUS_SVG, title: 'Smaller text', onClick: () => bumpTextSize(-1) });
|
||||
moduleApi.header.addButton({ icon: PLUS_SVG, title: 'Larger text', onClick: () => bumpTextSize(1) });
|
||||
|
||||
@@ -144,7 +150,7 @@ function createPlan({ root, moduleApi }) {
|
||||
/* ── which items to show ────────────────────────────────────────── */
|
||||
|
||||
function visibleItems() {
|
||||
const items = Array.isArray(state?.items) ? state.items : [];
|
||||
const items = Array.isArray(view.items) ? view.items : [];
|
||||
return items.filter((it) => {
|
||||
if (it.itemType === 'header' && !on('showHeaders')) return false;
|
||||
if (it.servicePosition === 'pre' && !on('showPreService')) return false;
|
||||
@@ -194,14 +200,14 @@ function createPlan({ root, moduleApi }) {
|
||||
|
||||
/** Placeholder → text; a hidden or empty value resolves to '' and drops its segment. */
|
||||
function templateValues() {
|
||||
const plan = state?.plan || {};
|
||||
const plan = view.plan || {};
|
||||
const items = state?.items || [];
|
||||
const planned = plannedLength();
|
||||
return {
|
||||
series: on('showSeries') ? plan.seriesTitle || '' : '',
|
||||
part: on('showPart') ? plan.title || '' : '',
|
||||
title: on('showPart') ? plan.title || '' : '',
|
||||
servicetype: on('showServiceType') ? state?.serviceType?.name || '' : '',
|
||||
servicetype: on('showServiceType') ? view.name || '' : '',
|
||||
date: on('showDate') ? plan.dates || '' : '',
|
||||
shortdate: on('showDate') ? plan.shortDates || plan.dates || '' : '',
|
||||
time: on('showServiceTime') && plan.serviceStartsAt
|
||||
@@ -239,12 +245,12 @@ function createPlan({ root, moduleApi }) {
|
||||
}
|
||||
|
||||
function renderHead() {
|
||||
const plan = state?.plan;
|
||||
const plan = view.plan;
|
||||
const show = on('showTopBar') && plan;
|
||||
headEl.hidden = !show;
|
||||
if (!show) return;
|
||||
const [line1, line2] = renderTemplate(cfg().headerTemplate, templateValues());
|
||||
planTitleEl.textContent = line1 || line2 || state.serviceType?.name || 'Plan';
|
||||
planTitleEl.textContent = line1 || line2 || view.name || 'Plan';
|
||||
planSubEl.textContent = line1 ? line2 || '' : '';
|
||||
planSubEl.hidden = !planSubEl.textContent;
|
||||
renderClock();
|
||||
@@ -258,9 +264,12 @@ function createPlan({ root, moduleApi }) {
|
||||
* time once it has ended.
|
||||
*/
|
||||
function renderClock() {
|
||||
const plan = state?.plan;
|
||||
const live = state?.live || {};
|
||||
const svc = state?.service || {};
|
||||
const plan = view.plan;
|
||||
const live = view.live ? (state?.live || {}) : {};
|
||||
// The service window belongs to the type being followed. Another type's
|
||||
// plan must not borrow its clock — it would read as that service running.
|
||||
// With none, the fall-through below shows that plan's own start time.
|
||||
const svc = view.live ? (state?.service || {}) : {};
|
||||
clockLabelEl.textContent = '';
|
||||
clockValueEl.textContent = '';
|
||||
clockValueEl.className = 'pp-clock-value';
|
||||
@@ -272,7 +281,7 @@ function createPlan({ root, moduleApi }) {
|
||||
clockValueEl.textContent = fmtDur((now - startedAt) / 1000);
|
||||
if (live.following) {
|
||||
// Ahead of / behind the plan: elapsed minus what the completed items were planned to take.
|
||||
const done = state.items.filter((it) => live.history?.[it.id]?.endedAt);
|
||||
const done = view.items.filter((it) => live.history?.[it.id]?.endedAt);
|
||||
const planned = done.reduce((sum, it) => sum + (it.length || 0), 0);
|
||||
const actual = done.reduce((sum, it) => sum + (live.history[it.id].endedAt - live.history[it.id].startedAt) / 1000, 0);
|
||||
const drift = actual - planned;
|
||||
@@ -321,13 +330,13 @@ function createPlan({ root, moduleApi }) {
|
||||
link: { href: '/admin', text: 'Open Admin' },
|
||||
};
|
||||
}
|
||||
if (!state.reachable && !state.plan) {
|
||||
if (!state.reachable && !view.plan) {
|
||||
return { title: state.lastFetched ? 'Planning Center unavailable' : 'Reading the plan…', hint: state.lastError || '' };
|
||||
}
|
||||
if (!state.plan) {
|
||||
if (!view.plan) {
|
||||
return {
|
||||
title: 'No plan found',
|
||||
hint: `${state.serviceType?.name || 'This service type'} has no upcoming or recent plans in Planning Center.`,
|
||||
hint: `${view.name || 'This service type'} has no upcoming or recent plans in Planning Center.`,
|
||||
};
|
||||
}
|
||||
if (!visibleItems().length) return { title: 'Nothing to show', hint: 'Every item is hidden by this tile’s settings (gear menu).' };
|
||||
@@ -483,7 +492,7 @@ function createPlan({ root, moduleApi }) {
|
||||
|
||||
// Rebuild rows only when the plan content or the display settings
|
||||
// changed; live highlighting and timers are applied in place.
|
||||
const key = JSON.stringify([state.plan.id, state.items, cfg(), state.live?.following]);
|
||||
const key = JSON.stringify([view.id, view.plan.id, view.items, cfg(), view.live && state.live?.following]);
|
||||
if (key !== lastListKey) {
|
||||
lastListKey = key;
|
||||
listEl.innerHTML = '';
|
||||
@@ -523,6 +532,7 @@ function createPlan({ root, moduleApi }) {
|
||||
/** The row AbleSet's song belongs to — only ever the current one. */
|
||||
function absRow() {
|
||||
const a = absView;
|
||||
if (!view.live) return null; // another service type is on screen
|
||||
if (!a || !a.available || !a.reachable || !a.song || !a.itemId) return null;
|
||||
if (a.itemId !== lastCurrentId) return null;
|
||||
return listEl.querySelector(`.pp-row[data-id="${CSS.escape(a.itemId)}"]`) || null;
|
||||
@@ -627,15 +637,17 @@ function createPlan({ root, moduleApi }) {
|
||||
|
||||
/** Current / done classes and the elapsed timers, without rebuilding rows. */
|
||||
function renderLiveMarks() {
|
||||
const live = state?.live || {};
|
||||
// Only the followed service type has a live item: this dashboard may be
|
||||
// looking at another one, which has no ProPresenter and no clock.
|
||||
const live = view.live ? (state?.live || {}) : {};
|
||||
const now = serverNow();
|
||||
const currentId = live.following ? live.currentItemId || '' : '';
|
||||
const history = live.history || {};
|
||||
const byId = new Map(state.items.map((it) => [it.id, it]));
|
||||
const byId = new Map(view.items.map((it) => [it.id, it]));
|
||||
// Everything before the current item counts as done, matched or not.
|
||||
const doneIds = new Set();
|
||||
if (currentId) {
|
||||
for (const it of state.items) {
|
||||
for (const it of view.items) {
|
||||
if (it.id === currentId) break;
|
||||
if (it.itemType !== 'header') doneIds.add(it.id);
|
||||
}
|
||||
@@ -676,8 +688,8 @@ function createPlan({ root, moduleApi }) {
|
||||
/* ── footer: what ProPresenter is doing ─────────────────────────── */
|
||||
|
||||
function renderFoot() {
|
||||
const live = state?.live;
|
||||
const show = on('showLiveFooter') && live?.following && state?.plan;
|
||||
const live = view.live ? state?.live : null;
|
||||
const show = on('showLiveFooter') && live?.following && view.plan;
|
||||
footEl.hidden = !show;
|
||||
footEl.className = 'pp-foot';
|
||||
if (!show) return;
|
||||
@@ -713,7 +725,10 @@ function createPlan({ root, moduleApi }) {
|
||||
/* ── render + ticking ───────────────────────────────────────────── */
|
||||
|
||||
function render() {
|
||||
view = viewOf(state);
|
||||
switcher.sync();
|
||||
wrap.classList.toggle('is-offline', feedOffline);
|
||||
wrap.classList.toggle('is-other-type', Boolean(state) && !view.live);
|
||||
wrap.classList.toggle('tint-types', Boolean(cfg().tintByType));
|
||||
wrap.classList.toggle('header-gradient', cfg().headerGradient !== false);
|
||||
const color = (value, fallback) => {
|
||||
@@ -744,9 +759,9 @@ function createPlan({ root, moduleApi }) {
|
||||
|
||||
function tick() {
|
||||
renderAbleSet();
|
||||
if (!state?.plan) return;
|
||||
if (!view.plan) return;
|
||||
renderClock();
|
||||
if (state.live?.following && on('showItemRuntime')) renderLiveMarks();
|
||||
if (view.live && state.live?.following && on('showItemRuntime')) renderLiveMarks();
|
||||
}
|
||||
|
||||
/* ── live feed ──────────────────────────────────────────────────── */
|
||||
@@ -805,11 +820,14 @@ function createPlan({ root, moduleApi }) {
|
||||
.then((body) => { if (body && !state) accept(body); })
|
||||
.catch(() => { /* the stream will cover it */ });
|
||||
connect();
|
||||
offViewed = onViewedType(() => { lastListKey = ''; render(); });
|
||||
listEl.addEventListener('wheel', onUserScroll, { passive: true });
|
||||
listEl.addEventListener('touchmove', onUserScroll, { passive: true });
|
||||
ticker = setInterval(tick, 1000);
|
||||
},
|
||||
stop() {
|
||||
offViewed?.();
|
||||
offViewed = null;
|
||||
clearInterval(ticker);
|
||||
ticker = null;
|
||||
stream?.close();
|
||||
|
||||
Reference in New Issue
Block a user