feat: real URL routes for tabs (/detection, /court, /trajectory)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Ruslan Bakiev
2026-03-07 12:45:03 +07:00
parent 22c24c0296
commit 08e280d617
2 changed files with 16 additions and 10 deletions

View File

@@ -29,8 +29,9 @@ state = {
@app.route('/') @app.route('/')
def index(): @app.route('/<tab>')
return render_template('index.html') def index(tab='detection'):
return render_template('index.html', active_tab=tab)
@app.route('/frame/<int:sensor_id>') @app.route('/frame/<int:sensor_id>')

View File

@@ -367,7 +367,7 @@
<script> <script>
// ===================== Tab switching ===================== // ===================== Tab switching =====================
var activeTab = 'detection'; var activeTab = '{{ active_tab | default("detection") }}';
function switchTab(target) { function switchTab(target) {
activeTab = target; activeTab = target;
@@ -378,18 +378,23 @@ function switchTab(target) {
document.getElementById('infoPanel').style.display = (target === 'trajectory') ? 'flex' : 'none'; document.getElementById('infoPanel').style.display = (target === 'trajectory') ? 'flex' : 'none';
if (target === 'court' && !courtSceneInitialized) initCourtScene(); if (target === 'court' && !courtSceneInitialized) initCourtScene();
if (target === 'trajectory' && !trajSceneInitialized) initTrajectoryScene(); if (target === 'trajectory' && !trajSceneInitialized) initTrajectoryScene();
history.replaceState(null, '', '#' + target); history.pushState(null, '', '/' + target);
} }
document.querySelectorAll('.tab').forEach(function(tab) { document.querySelectorAll('.tab').forEach(function(tab) {
tab.addEventListener('click', function() { switchTab(this.dataset.tab); }); tab.addEventListener('click', function(e) {
e.preventDefault();
switchTab(this.dataset.tab);
});
}); });
// Init from URL hash window.addEventListener('popstate', function() {
var hash = location.hash.replace('#', ''); var path = location.pathname.replace('/', '') || 'detection';
if (['detection', 'court', 'trajectory'].indexOf(hash) !== -1) { switchTab(path);
switchTab(hash); });
}
// Init active tab from server
if (activeTab !== 'detection') switchTab(activeTab);
// ===================== Calibration ===================== // ===================== Calibration =====================
function doCalibrate() { function doCalibrate() {