Upload static/pages/help/help.js with huggingface_hub
Browse files- static/pages/help/help.js +57 -21
static/pages/help/help.js
CHANGED
|
@@ -1,43 +1,79 @@
|
|
| 1 |
/**
|
| 2 |
-
* Help Page
|
| 3 |
*/
|
| 4 |
|
|
|
|
|
|
|
| 5 |
class HelpPage {
|
| 6 |
async init() {
|
| 7 |
-
console.log('[Help] Initializing...');
|
| 8 |
this.setupSearch();
|
| 9 |
-
this.
|
|
|
|
|
|
|
| 10 |
console.log('[Help] Ready');
|
| 11 |
}
|
| 12 |
|
| 13 |
setupSearch() {
|
| 14 |
-
const
|
| 15 |
-
if (
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
| 18 |
});
|
| 19 |
-
}
|
| 20 |
}
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
const
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
| 28 |
});
|
| 29 |
});
|
| 30 |
}
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
});
|
| 40 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
}
|
| 42 |
|
| 43 |
export default HelpPage;
|
|
|
|
| 1 |
/**
|
| 2 |
+
* Help Page — live stats, search, copy buttons, smooth navigation
|
| 3 |
*/
|
| 4 |
|
| 5 |
+
const API_BASE = window.location.origin;
|
| 6 |
+
|
| 7 |
class HelpPage {
|
| 8 |
async init() {
|
|
|
|
| 9 |
this.setupSearch();
|
| 10 |
+
this.setupCopyButtons();
|
| 11 |
+
this.setupToc();
|
| 12 |
+
await this.loadLiveStats();
|
| 13 |
console.log('[Help] Ready');
|
| 14 |
}
|
| 15 |
|
| 16 |
setupSearch() {
|
| 17 |
+
const input = document.getElementById('help-search');
|
| 18 |
+
if (!input) return;
|
| 19 |
+
input.addEventListener('input', (e) => {
|
| 20 |
+
const q = e.target.value.toLowerCase().trim();
|
| 21 |
+
document.querySelectorAll('.help-section').forEach((section) => {
|
| 22 |
+
const text = section.textContent.toLowerCase();
|
| 23 |
+
section.style.display = !q || text.includes(q) ? '' : 'none';
|
| 24 |
});
|
| 25 |
+
});
|
| 26 |
}
|
| 27 |
|
| 28 |
+
setupToc() {
|
| 29 |
+
document.querySelectorAll('.help-toc a').forEach((link) => {
|
| 30 |
+
link.addEventListener('click', (e) => {
|
| 31 |
+
const id = link.getAttribute('href')?.slice(1);
|
| 32 |
+
const el = id && document.getElementById(id);
|
| 33 |
+
if (el) {
|
| 34 |
+
e.preventDefault();
|
| 35 |
+
el.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
| 36 |
+
}
|
| 37 |
});
|
| 38 |
});
|
| 39 |
}
|
| 40 |
|
| 41 |
+
setupCopyButtons() {
|
| 42 |
+
document.querySelectorAll('[data-copy]').forEach((btn) => {
|
| 43 |
+
btn.addEventListener('click', async () => {
|
| 44 |
+
const text = btn.getAttribute('data-copy') || btn.closest('.code-wrap')?.querySelector('code')?.textContent;
|
| 45 |
+
if (!text) return;
|
| 46 |
+
try {
|
| 47 |
+
await navigator.clipboard.writeText(text.trim());
|
| 48 |
+
const label = btn.textContent;
|
| 49 |
+
btn.textContent = 'Copied!';
|
| 50 |
+
setTimeout(() => { btn.textContent = label; }, 1500);
|
| 51 |
+
} catch {
|
| 52 |
+
btn.textContent = 'Copy failed';
|
| 53 |
+
}
|
| 54 |
+
});
|
| 55 |
});
|
| 56 |
}
|
| 57 |
+
|
| 58 |
+
async loadLiveStats() {
|
| 59 |
+
const el = document.getElementById('live-stats');
|
| 60 |
+
if (!el) return;
|
| 61 |
+
try {
|
| 62 |
+
const res = await fetch(`${API_BASE}/api/dashboard/overview`, { signal: AbortSignal.timeout(15000) });
|
| 63 |
+
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
| 64 |
+
const data = await res.json();
|
| 65 |
+
const c = data.cards || {};
|
| 66 |
+
el.innerHTML = `
|
| 67 |
+
<div class="stat-pill"><strong>${c.total_resources ?? '—'}</strong><span>Registry entries</span></div>
|
| 68 |
+
<div class="stat-pill"><strong>${c.api_keys_env ?? 0}+${c.api_keys_file ?? 0}</strong><span>API keys (env + file)</span></div>
|
| 69 |
+
<div class="stat-pill"><strong>${c.models_loaded ?? 0}/${c.models_total ?? 0}</strong><span>Models loaded</span></div>
|
| 70 |
+
<div class="stat-pill"><strong>${c.pools_healthy ?? 0}/${c.pools_total ?? 0}</strong><span>Healthy pools</span></div>
|
| 71 |
+
<div class="stat-pill"><strong>${c.providers_online ?? 0}</strong><span>Providers available</span></div>
|
| 72 |
+
`;
|
| 73 |
+
} catch (err) {
|
| 74 |
+
el.innerHTML = `<p class="help-note">Live stats unavailable (${err.message}). Endpoints below still work when the Space is running.</p>`;
|
| 75 |
+
}
|
| 76 |
+
}
|
| 77 |
}
|
| 78 |
|
| 79 |
export default HelpPage;
|