coderuday21 commited on
Commit
f207f6c
·
1 Parent(s): 4dac521

UX: add choose detection type screen and redirect URLs

Browse files
Files changed (3) hide show
  1. app/main.py +12 -0
  2. static/js/app.js +31 -2
  3. templates/index.html +17 -0
app/main.py CHANGED
@@ -564,3 +564,15 @@ def index():
564
  if not index_file.exists():
565
  return HTMLResponse("<h1>Satellite Change Detection</h1><p>Create <code>templates/index.html</code> and <code>static/</code>.</p>")
566
  return FileResponse(index_file)
 
 
 
 
 
 
 
 
 
 
 
 
 
564
  if not index_file.exists():
565
  return HTMLResponse("<h1>Satellite Change Detection</h1><p>Create <code>templates/index.html</code> and <code>static/</code>.</p>")
566
  return FileResponse(index_file)
567
+
568
+
569
+ # --- Detection type landing pages ---
570
+ # These serve the same SPA, but the frontend selects the correct mode based on URL.
571
+ @app.get("/detect/change", response_class=HTMLResponse)
572
+ def detect_change_page():
573
+ return index()
574
+
575
+
576
+ @app.get("/detect/landslide", response_class=HTMLResponse)
577
+ def detect_landslide_page():
578
+ return index()
static/js/app.js CHANGED
@@ -12,6 +12,28 @@ function showView(id) {
12
  if (el) el.classList.add('active');
13
  }
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  function showError(id, msg) {
16
  const el = document.getElementById(id);
17
  if (!el) return;
@@ -140,8 +162,15 @@ async function init() {
140
  try {
141
  const user = await api('GET', '/api/me');
142
  document.getElementById('user-email').textContent = user.email;
143
- showView('dashboard');
144
- loadHistory();
 
 
 
 
 
 
 
145
  } catch (_) { setToken(null); showView('login'); }
146
  }
147
 
 
12
  if (el) el.classList.add('active');
13
  }
14
 
15
+ function getDetectionTypeFromPath() {
16
+ const p = (window.location.pathname || '').toLowerCase();
17
+ if (p.includes('/detect/landslide')) return 'landslide_detection';
18
+ if (p.includes('/detect/change')) return 'change_detection';
19
+ return null;
20
+ }
21
+
22
+ function applyDetectionTypeToUI(type) {
23
+ const typeSel = document.getElementById('detect-type');
24
+ if (!typeSel || !type) return;
25
+ typeSel.value = type;
26
+ typeSel.dispatchEvent(new Event('change'));
27
+ }
28
+
29
+ // ---- Detection type selection buttons ----
30
+ document.getElementById('btn-type-change')?.addEventListener('click', () => {
31
+ window.location.href = '/detect/change';
32
+ });
33
+ document.getElementById('btn-type-landslide')?.addEventListener('click', () => {
34
+ window.location.href = '/detect/landslide';
35
+ });
36
+
37
  function showError(id, msg) {
38
  const el = document.getElementById(id);
39
  if (!el) return;
 
162
  try {
163
  const user = await api('GET', '/api/me');
164
  document.getElementById('user-email').textContent = user.email;
165
+ const preferred = getDetectionTypeFromPath();
166
+ if (preferred) {
167
+ applyDetectionTypeToUI(preferred);
168
+ showView('dashboard');
169
+ loadHistory();
170
+ } else {
171
+ // After login, landing on "/" shows a selection screen.
172
+ showView('detection-type');
173
+ }
174
  } catch (_) { setToken(null); showView('login'); }
175
  }
176
 
templates/index.html CHANGED
@@ -131,6 +131,23 @@
131
  </section>
132
 
133
  <!-- Dashboard view -->
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
134
  <section id="view-dashboard" class="view">
135
  <div class="topbar">
136
  <div class="nav-user">
 
131
  </section>
132
 
133
  <!-- Dashboard view -->
134
+ <section id="view-detection-type" class="view">
135
+ <div class="auth-container">
136
+ <div class="auth-logo">
137
+ <div class="auth-logo-icon">
138
+ <svg width="36" height="36" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><path d="M12 2l9 4.5-9 4.5-9-4.5L12 2z"/><path d="M3 6.5V17.5L12 22l9-4.5V6.5"/><path d="M12 11v11"/></svg>
139
+ </div>
140
+ <span>Choose Detection Type</span>
141
+ </div>
142
+ <div class="card">
143
+ <h2 style="margin-bottom:0.75rem;">Select what you want to detect</h2>
144
+ <button type="button" class="btn btn-primary btn-block" id="btn-type-change">General Change Detection</button>
145
+ <div style="height:0.75rem;"></div>
146
+ <button type="button" class="btn btn-secondary btn-block" id="btn-type-landslide">Landslide Detection (Uttarakhand)</button>
147
+ </div>
148
+ </div>
149
+ </section>
150
+
151
  <section id="view-dashboard" class="view">
152
  <div class="topbar">
153
  <div class="nav-user">