Skip to content

Commit c95ec86

Browse files
stackdumpclaude
andcommitted
Link poll to its Petri net model in editor
- Editor handles ?template=<id> param to load template schema on init - Poll View Petri Net Model links now include poll ID - Editor shows poll title and status in toolbar when poll param present Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 5c16a14 commit c95ec86

3 files changed

Lines changed: 43 additions & 3 deletions

File tree

public/bitwrap.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,8 @@ function downloadFile(filename, content) {
338338
// Load model from URL params on page load
339339
(function() {
340340
const params = new URLSearchParams(window.location.search);
341+
342+
// Load by CID: /editor?cid=<cid>
341343
const cid = params.get('cid');
342344
if (cid) {
343345
fetch('/o/' + cid)
@@ -348,5 +350,38 @@ function downloadFile(filename, content) {
348350
}
349351
})
350352
.catch(err => console.error('Failed to load model:', err));
353+
return;
354+
}
355+
356+
// Load by template: /editor?template=<id>&poll=<pollId>
357+
const template = params.get('template');
358+
if (template) {
359+
fetch('/api/templates/' + template)
360+
.then(r => r.ok ? r.json() : null)
361+
.then(data => {
362+
if (data && petriView && petriView.loadModel) {
363+
petriView.loadModel(data);
364+
}
365+
})
366+
.catch(err => console.error('Failed to load template:', err));
367+
368+
// If a poll ID is provided, show poll info in the toolbar
369+
const pollId = params.get('poll');
370+
if (pollId) {
371+
fetch('/api/polls/' + pollId)
372+
.then(r => r.ok ? r.json() : null)
373+
.then(data => {
374+
if (data && data.poll) {
375+
const poll = data.poll;
376+
const info = document.createElement('span');
377+
info.style.cssText = 'color:#aaa;font-size:13px;margin-left:12px;';
378+
info.textContent = `${poll.title} (${poll.status})`;
379+
const toolbar = document.querySelector('.toolbar, nav') || document.body;
380+
toolbar.appendChild(info);
381+
}
382+
})
383+
.catch(() => {});
384+
}
385+
return;
351386
}
352387
})();

public/poll.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ <h2 class="poll-title" id="vote-title"></h2>
211211
<button class="btn-secondary" id="btn-close" onclick="closePoll()" style="display:none; margin-left:0; border-color:#ff8844; color:#ff8844;">Close Poll</button>
212212
</div>
213213

214-
<a class="view-model-link" href="/editor?template=vote">View Petri Net Model &rarr;</a>
214+
<a class="view-model-link" id="view-model-link" href="/editor?template=vote">View Petri Net Model &rarr;</a>
215215
</div>
216216
</div>
217217

@@ -247,7 +247,7 @@ <h3>What you get</h3>
247247

248248
<div style="margin-top:24px;">
249249
<button class="btn-secondary" onclick="showList()" style="margin-left:0;">Back</button>
250-
<a class="view-model-link" href="/editor?template=vote">View Petri Net Model &rarr;</a>
250+
<a class="view-model-link" id="view-model-link" href="/editor?template=vote">View Petri Net Model &rarr;</a>
251251
</div>
252252
</div>
253253
</div>
@@ -265,7 +265,7 @@ <h3>Nullifiers (public audit log)</h3>
265265

266266
<div style="margin-top:24px;">
267267
<button class="btn-secondary" onclick="location.hash=currentPollId" style="margin-left:0;">Back to Poll</button>
268-
<a class="view-model-link" href="/editor?template=vote">View Petri Net Model &rarr;</a>
268+
<a class="view-model-link" id="view-model-link" href="/editor?template=vote">View Petri Net Model &rarr;</a>
269269
</div>
270270
</div>
271271
</div>

public/poll.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,11 @@ async function loadPoll(pollId) {
181181
document.getElementById('vote-title').textContent = poll.title;
182182
document.getElementById('vote-desc').textContent = poll.description || '';
183183

184+
// Update "View Petri Net Model" links to include this poll's ID
185+
document.querySelectorAll('#view-model-link').forEach(el => {
186+
el.href = `/editor?template=vote&poll=${pollId}`;
187+
});
188+
184189
const statusEl = document.getElementById('vote-status');
185190
statusEl.textContent = poll.status;
186191
statusEl.className = 'poll-status ' + poll.status;

0 commit comments

Comments
 (0)