439 lines
18 KiB
HTML
439 lines
18 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>TasGrid Parent App Simulator</title>
|
|
<style>
|
|
body {
|
|
font-family: system-ui;
|
|
padding: 20px;
|
|
background: #f4f4f5;
|
|
max-width: 1200px;
|
|
margin: 0 auto;
|
|
}
|
|
|
|
.container {
|
|
display: flex;
|
|
gap: 20px;
|
|
margin-top: 20px;
|
|
}
|
|
|
|
.iframe-container {
|
|
flex: 1;
|
|
border: 1px solid #ddd;
|
|
background: white;
|
|
border-radius: 8px;
|
|
overflow: hidden;
|
|
display: flex;
|
|
flex-direction: column;
|
|
height: 600px;
|
|
}
|
|
|
|
.controls {
|
|
background: white;
|
|
padding: 20px;
|
|
border-radius: 8px;
|
|
border: 1px solid #ddd;
|
|
margin-bottom: 20px;
|
|
}
|
|
|
|
.login-form {
|
|
display: grid;
|
|
gap: 10px;
|
|
max-width: 400px;
|
|
}
|
|
|
|
.login-form input {
|
|
padding: 10px;
|
|
border: 1px solid #ccc;
|
|
border-radius: 4px;
|
|
}
|
|
|
|
.login-form button {
|
|
padding: 10px;
|
|
background: #007bff;
|
|
color: white;
|
|
border: none;
|
|
border-radius: 4px;
|
|
cursor: pointer;
|
|
font-weight: bold;
|
|
}
|
|
|
|
.login-form button:hover {
|
|
background: #0056b3;
|
|
}
|
|
|
|
.status {
|
|
margin-top: 10px;
|
|
padding: 10px;
|
|
border-radius: 4px;
|
|
display: none;
|
|
}
|
|
|
|
.status.success {
|
|
background: #d4edda;
|
|
color: #155724;
|
|
display: block;
|
|
}
|
|
|
|
.status.error {
|
|
background: #f8d7da;
|
|
color: #721c24;
|
|
display: block;
|
|
}
|
|
|
|
iframe {
|
|
border: none;
|
|
width: 100%;
|
|
height: 100%;
|
|
}
|
|
|
|
button.send-manual {
|
|
padding: 8px 16px;
|
|
cursor: pointer;
|
|
margin-top: 10px;
|
|
}
|
|
|
|
input.manual-token {
|
|
padding: 8px;
|
|
width: 100%;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
h1 {
|
|
margin-top: 0;
|
|
}
|
|
</style>
|
|
<script src="https://cdn.jsdelivr.net/npm/pocketbase/dist/pocketbase.umd.js"></script>
|
|
</head>
|
|
|
|
<body>
|
|
<h1>TasGrid Parent App Simulator</h1>
|
|
|
|
<div class="controls">
|
|
<div id="env-settings" style="margin-bottom: 20px; padding-bottom: 20px; border-bottom: 1px solid #eee;">
|
|
<p style="font-size: 13px; color: #666; margin-top: 0;"><strong>Target Environment:</strong></p>
|
|
<label style="margin-right: 15px; cursor: pointer;">
|
|
<input type="radio" name="envToggle" value="https://tasgrid.ccllc.pro" checked onchange="updateEnv()">
|
|
Production (tasgrid.ccllc.pro)
|
|
</label>
|
|
<label style="margin-right: 15px; cursor: pointer;">
|
|
<input type="radio" name="envToggle" value="http://localhost:4000" onchange="updateEnv()">
|
|
Localhost:4000
|
|
</label>
|
|
<label style="cursor: pointer;">
|
|
<input type="radio" name="envToggle" value="http://localhost:4001" onchange="updateEnv()">
|
|
Localhost:4001
|
|
</label>
|
|
</div>
|
|
|
|
<div id="login-section">
|
|
<h3>Login to Parent Application</h3>
|
|
<p>This simulates the parent application authenticating with the shared backend.</p>
|
|
<div class="login-form">
|
|
<input type="email" id="email" placeholder="Email" value="">
|
|
<input type="password" id="password" placeholder="Password" value="">
|
|
<button onclick="login()">Login & Sync Iframes</button>
|
|
</div>
|
|
<div id="status" class="status"></div>
|
|
</div>
|
|
|
|
<div id="manual-section" style="margin-top: 30px; border-top: 1px solid #eee; padding-top: 20px;">
|
|
<p style="font-size: 13px; color: #666;"><strong>Test Deep Linking:</strong></p>
|
|
<div style="display: flex; gap: 10px; margin-bottom: 10px;">
|
|
<input type="text" id="note-id-input" style="flex: 1; padding: 8px;"
|
|
placeholder="Paste Note ID here...">
|
|
<button onclick="loadSpecificNote()" style="padding: 8px 16px; cursor: pointer;">Load Note</button>
|
|
</div>
|
|
|
|
<p style="font-size: 13px; color: #666; margin-top: 20px;"><strong>Test Headless SDK (Centralized
|
|
Logic):</strong></p>
|
|
<div style="display: flex; flex-direction: column; gap: 10px; margin-bottom: 10px;">
|
|
<div style="display: flex; gap: 10px;">
|
|
<input type="text" id="sdk-task-title" style="flex: 1; padding: 8px;"
|
|
placeholder="New Task Title...">
|
|
<button onclick="createTaskViaSDK()"
|
|
style="padding: 8px 16px; cursor: pointer; background: #6f42c1; color: white; border: none; border-radius: 4px; font-weight: bold;">Create
|
|
Task via SDK</button>
|
|
</div>
|
|
<div style="display: flex; gap: 10px;">
|
|
<input type="text" id="sdk-note-title" style="flex: 1; padding: 8px;"
|
|
placeholder="New Note Title...">
|
|
<button onclick="createNoteViaSDK()"
|
|
style="padding: 8px 16px; cursor: pointer; background: #fd7e14; color: white; border: none; border-radius: 4px; font-weight: bold;">Create
|
|
Note via SDK</button>
|
|
</div>
|
|
</div>
|
|
|
|
<p style="font-size: 13px; color: #666; margin-top: 20px;"><strong>Manual Auth:</strong></p>
|
|
<input type="text" id="token" class="manual-token" placeholder="Paste PB Token here...">
|
|
<button class="send-manual" onclick="sendAuthFromInput()">Send Manual Token</button>
|
|
</div>
|
|
|
|
<div id="docs-section" style="margin-top: 30px; border-top: 1px solid #eee; padding-top: 20px;">
|
|
<details>
|
|
<summary style="cursor: pointer; font-weight: bold; color: #007bff;">Developer Integration Guide
|
|
</summary>
|
|
<div style="font-size: 14px; line-height: 1.6; margin-top: 15px;">
|
|
<p><strong>1. Available Routes:</strong></p>
|
|
<ul>
|
|
<li><code>/embed/notes</code>: Renders the full notepad/editor.</li>
|
|
<li><code>/embed/notes?noteId=XXX</code>: Renders a specific note directly.</li>
|
|
<li><code>/embed/quick-add</code>: Renders a standalone task creation form.</li>
|
|
</ul>
|
|
|
|
<p><strong>2. Programmatic Creation (TasGrid SDK):</strong></p>
|
|
<p>The recommended way to create entries is using the <code>tasgrid-sdk.js</code> module. This
|
|
ensures all TasGrid-specific defaults and date logic (like urgency decay) are handled correctly.
|
|
</p>
|
|
|
|
<p><em>Setup:</em></p>
|
|
<pre
|
|
style="background: #f8f9fa; padding: 15px; border-radius: 4px; border: 1px solid #e9ecef; overflow-x: auto; font-size: 12px;">
|
|
import { createTasgridTask, createTasgridNote } from 'https://tasgrid.ccllc.pro/tasgrid-sdk.js';</pre>
|
|
|
|
<div style="border-left: 4px solid #6f42c1; padding-left: 15px; margin: 20px 0;">
|
|
<p><strong>A. Creating a TASK:</strong></p>
|
|
<p style="font-size: 12px; color: #666; margin-top: -10px;">Use this for items that need status,
|
|
priority, and automated due date calculation.</p>
|
|
<pre
|
|
style="background: #f8f9fa; padding: 15px; border-radius: 4px; border: 1px solid #e9ecef; overflow-x: auto; font-size: 12px;">
|
|
const task = await createTasgridTask(pb, {
|
|
title: "Urgent Task",
|
|
urgency: 10, // Automated: 10=Today, 5=Next Week, 1=Six Months
|
|
priority: 8, // 1-10
|
|
size: 3, // Default: 3 (1 hour). Range 0-10.
|
|
tags: ["external"],
|
|
owner: "USER_ID" // Optional
|
|
});</pre>
|
|
</div>
|
|
|
|
<div style="border-left: 4px solid #fd7e14; padding-left: 15px; margin: 20px 0;">
|
|
<p><strong>B. Creating a NOTE:</strong></p>
|
|
<p style="font-size: 12px; color: #666; margin-top: -10px;">Use this for long-form content or
|
|
documentation without a deadline.</p>
|
|
<pre
|
|
style="background: #f8f9fa; padding: 15px; border-radius: 4px; border: 1px solid #e9ecef; overflow-x: auto; font-size: 12px;">
|
|
const note = await createTasgridNote(pb, {
|
|
title: "Project Brief",
|
|
content: "<p>HTML content here...</p>",
|
|
tags: ["documentation"],
|
|
isPrivate: false,
|
|
tasks: [] // Optional: Array of Task IDs to link
|
|
});</pre>
|
|
</div>
|
|
|
|
<p><strong>3. Authentication Protocol:</strong></p>
|
|
<p>The parent application must send a <code>postMessage</code> to the iframe immediately after the
|
|
iframe loads (or whenever auth state changes). Since iframes reset their internal state on
|
|
navigation,
|
|
you should always sync auth on the <code>onload</code> event.</p>
|
|
<p><em>Example using vanilla JS:</em></p>
|
|
<pre
|
|
style="background: #f8f9fa; padding: 15px; border-radius: 4px; border: 1px solid #e9ecef; overflow-x: auto; font-size: 12px;">
|
|
// 1. Define sync function
|
|
function syncAuth(iframe) {
|
|
iframe.contentWindow.postMessage({
|
|
type: "TASGRID_AUTH",
|
|
token: pb.authStore.token,
|
|
user: pb.authStore.model
|
|
}, "*");
|
|
}
|
|
|
|
// 2. Attach to iframe (either in HTML or via JS)
|
|
// <iframe onload="syncAuth(this)" src="..."></iframe>
|
|
</pre>
|
|
|
|
<p><strong>4. Responsiveness:</strong></p>
|
|
<p>Both routes are designed to be fluid. Ensure your iframe container has defined dimensions; the
|
|
content will expand to fill it.</p>
|
|
</div>
|
|
</details>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="container">
|
|
<div class="iframe-container">
|
|
<div
|
|
style="padding: 10px; background: #eee; border-bottom: 1px solid #ddd; font-weight: bold; font-size: 12px; display: flex; justify-content: space-between;">
|
|
<span>Notes Embed</span>
|
|
<code style="font-size: 10px;">/embed/notes</code>
|
|
</div>
|
|
<iframe id="notes-iframe" onload="syncAuthOnLoad(this)"></iframe>
|
|
</div>
|
|
|
|
<div class="iframe-container">
|
|
<div
|
|
style="padding: 10px; background: #eee; border-bottom: 1px solid #ddd; font-weight: bold; font-size: 12px; display: flex; justify-content: space-between;">
|
|
<span>Quick Add Embed</span>
|
|
<code style="font-size: 10px;">/embed/quick-add</code>
|
|
</div>
|
|
<iframe id="quick-add-iframe" onload="syncAuthOnLoad(this)"></iframe>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
const pb = new PocketBase('https://pocketbase.ccllc.pro');
|
|
const statusEl = document.getElementById('status');
|
|
let ENV_URL = 'https://tasgrid.ccllc.pro';
|
|
|
|
function updateEnv() {
|
|
const selected = document.querySelector('input[name="envToggle"]:checked').value;
|
|
ENV_URL = selected;
|
|
|
|
// Reload iframes with new base URL
|
|
const notesIframe = document.getElementById('notes-iframe');
|
|
const noteId = document.getElementById('note-id-input')?.value.trim();
|
|
if (noteId) {
|
|
notesIframe.src = `${ENV_URL}/embed/notes?noteId=${noteId}`;
|
|
} else {
|
|
notesIframe.src = `${ENV_URL}/embed/notes`;
|
|
}
|
|
|
|
document.getElementById('quick-add-iframe').src = `${ENV_URL}/embed/quick-add`;
|
|
console.log(`Switched target environment to: ${ENV_URL}`);
|
|
}
|
|
|
|
// Initialize iframes on load
|
|
window.addEventListener('DOMContentLoaded', () => {
|
|
updateEnv();
|
|
});
|
|
|
|
function syncAuthOnLoad(iframe) {
|
|
console.log(`Iframe ${iframe.id} loaded, checking auth sync...`);
|
|
if (pb.authStore.isValid) {
|
|
console.log(`Syncing existing auth to ${iframe.id}`);
|
|
sendAuthToIframes();
|
|
}
|
|
}
|
|
|
|
function loadSpecificNote() {
|
|
const id = document.getElementById('note-id-input').value.trim();
|
|
const iframe = document.getElementById('notes-iframe');
|
|
if (id) {
|
|
iframe.src = `${ENV_URL}/embed/notes?noteId=${id}`;
|
|
} else {
|
|
iframe.src = `${ENV_URL}/embed/notes`;
|
|
}
|
|
}
|
|
|
|
async function createTaskViaSDK() {
|
|
const title = document.getElementById('sdk-task-title').value.trim() || 'SDK Generated Task';
|
|
if (!pb.authStore.isValid) {
|
|
alert("Please log in first before creating a task via SDK.");
|
|
return;
|
|
}
|
|
|
|
statusEl.className = 'status';
|
|
statusEl.textContent = 'Importing SDK and creating task...';
|
|
statusEl.style.display = 'block';
|
|
|
|
try {
|
|
const { createTasgridTask } = await import(`${ENV_URL}/tasgrid-sdk.js`);
|
|
|
|
const record = await createTasgridTask(pb, {
|
|
title: title,
|
|
priority: 8,
|
|
urgency: 4,
|
|
tags: ["sdk_test"],
|
|
content: "This task was created by a sister app using the imported Headless SDK!"
|
|
});
|
|
|
|
statusEl.className = 'status success';
|
|
statusEl.textContent = `Task created successfully via SDK (ID: ${record.id})!`;
|
|
} catch (err) {
|
|
statusEl.className = 'status error';
|
|
statusEl.textContent = 'Failed to create task via SDK: ' + err.message;
|
|
}
|
|
}
|
|
|
|
async function createNoteViaSDK() {
|
|
const title = document.getElementById('sdk-note-title').value.trim() || 'SDK Generated Note';
|
|
if (!pb.authStore.isValid) {
|
|
alert("Please log in first before creating a note via SDK.");
|
|
return;
|
|
}
|
|
|
|
statusEl.className = 'status';
|
|
statusEl.textContent = 'Importing SDK and creating note...';
|
|
statusEl.style.display = 'block';
|
|
|
|
try {
|
|
const { createTasgridNote } = await import(`${ENV_URL}/tasgrid-sdk.js`);
|
|
|
|
const record = await createTasgridNote(pb, {
|
|
title: title,
|
|
content: "<p>This note was created headlessly via the SDK!</p>",
|
|
tags: ["sdk_test"],
|
|
isPrivate: false
|
|
});
|
|
|
|
statusEl.className = 'status success';
|
|
statusEl.textContent = `Note created successfully via SDK (ID: ${record.id})!`;
|
|
} catch (err) {
|
|
statusEl.className = 'status error';
|
|
statusEl.textContent = 'Failed to create note via SDK: ' + err.message;
|
|
}
|
|
}
|
|
|
|
async function login() {
|
|
const email = document.getElementById('email').value;
|
|
const password = document.getElementById('password').value;
|
|
|
|
statusEl.className = 'status';
|
|
statusEl.textContent = 'Logging in...';
|
|
statusEl.style.display = 'block';
|
|
|
|
try {
|
|
const authData = await pb.collection('users').authWithPassword(email, password);
|
|
|
|
statusEl.className = 'status success';
|
|
statusEl.textContent = `Logged in as ${authData.record.email}! Syncing iframes...`;
|
|
|
|
// Automatically send auth to iframes
|
|
sendAuth(pb.authStore.token, authData.record);
|
|
} catch (err) {
|
|
statusEl.className = 'status error';
|
|
statusEl.textContent = 'Login failed: ' + err.message;
|
|
}
|
|
}
|
|
|
|
function sendAuthFromInput() {
|
|
const token = document.getElementById('token').value;
|
|
if (!token) {
|
|
alert("Please enter a token first");
|
|
return;
|
|
}
|
|
sendAuth(token, null);
|
|
}
|
|
|
|
function sendAuth(token, user) {
|
|
const payload = {
|
|
type: "TASGRID_AUTH",
|
|
token: token,
|
|
user: user
|
|
};
|
|
|
|
const notesIframe = document.getElementById('notes-iframe').contentWindow;
|
|
const quickAddIframe = document.getElementById('quick-add-iframe').contentWindow;
|
|
|
|
console.log("Sending auth to iframes...", payload);
|
|
notesIframe.postMessage(payload, "*");
|
|
quickAddIframe.postMessage(payload, "*");
|
|
}
|
|
|
|
// Handle case where user refreshed but is still logged in to the parent
|
|
window.addEventListener('load', () => {
|
|
if (pb.authStore.isValid && pb.authStore.model) {
|
|
document.getElementById('email').value = pb.authStore.model.email || "";
|
|
statusEl.className = 'status success';
|
|
statusEl.textContent = 'Session restored. Click login or send manual token to sync.';
|
|
statusEl.style.display = 'block';
|
|
}
|
|
});
|
|
</script>
|
|
</body>
|
|
|
|
</html> |