-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
691 lines (611 loc) · 30.3 KB
/
index.html
File metadata and controls
691 lines (611 loc) · 30.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Trusted Data Now – ESIP Disasters Cluster</title>
<!-- GitHub Pages: https://esipfed.github.io/disasters-trusted-data-now/ -->
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
--primary: #0066cc;
--primary-light: #e6f2ff;
--success: #22863a;
--success-light: #dcffe4;
--text: #24292e;
--text-light: #586069;
--border: #e1e4e8;
--bg: #f6f8fa;
--white: #ffffff;
--shadow: 0 1px 3px rgba(0,0,0,0.1);
--shadow-lg: 0 10px 40px rgba(0,0,0,0.1);
--danger: #d73a49;
--danger-light: #ffeef0;
}
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif; color: var(--text); line-height: 1.6; background: var(--white); }
.header { background: var(--white); border-bottom: 1px solid var(--border); padding: 2rem 0; }
.container { max-width: 1200px; margin: 0 auto; padding: 0 1rem; }
h1 { font-size: 2rem; font-weight: 700; margin-bottom: 0.25rem; }
.subtitle { color: var(--text-light); font-size: 1.05rem; }
.toolbar { background: var(--bg); border-bottom: 1px solid var(--border); padding: 1.5rem 0; position: sticky; top: 0; z-index: 100; }
.toolbar-content { display: flex; gap: 1rem; flex-wrap: wrap; align-items: center; }
.search-container { flex: 1; min-width: 280px; }
.search-input { width: 100%; padding: .5rem 1rem; border: 1px solid var(--border); border-radius: 6px; font-size: 1rem; transition: border-color .2s; }
.search-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.filters { display: flex; gap: .5rem; flex-wrap: wrap; }
select { padding: .5rem 1rem; border: 1px solid var(--border); border-radius: 6px; background: var(--white); font-size: .9rem; cursor: pointer; transition: border-color .2s; }
select:hover { border-color: var(--text-light); }
select:focus { outline: none; border-color: var(--primary); }
.btn { padding: .5rem 1rem; border: 1px solid var(--border); border-radius: 6px; background: var(--white); font-size: .9rem; cursor: pointer; transition: all .2s; text-decoration: none; display: inline-flex; align-items: center; gap: .5rem; }
.btn:hover { background: var(--bg); }
.btn-primary { background: var(--primary); color: var(--white); border-color: var(--primary); }
.btn-primary:hover { background: #0052a3; }
.view-toggle { display: flex; gap: .25rem; background: var(--bg); padding: .25rem; border-radius: 6px; }
.view-toggle button { padding: .5rem 1rem; border: none; background: transparent; border-radius: 4px; cursor: pointer; }
.view-toggle button.active { background: var(--white); box-shadow: var(--shadow); }
.stats-bar { padding: 1.5rem 0; border-bottom: 1px solid var(--border); }
.stats { display: flex; gap: 3rem; flex-wrap: wrap; margin-bottom: 1rem; }
.stat { display: flex; flex-direction: column; }
.stat-value { font-size: 1.5rem; font-weight: 600; color: var(--text); }
.stat-label { font-size: .875rem; color: var(--text-light); }
.type-stats { display: flex; gap: 2rem; flex-wrap: wrap; justify-content: flex-start; }
.type-stat { display: flex; flex-direction: column; align-items: center; min-width: 80px; }
.type-emoji { font-size: 1.5rem; margin-bottom: 0.25rem; }
.type-count { font-size: 1.25rem; font-weight: 600; color: var(--text); }
.type-label { font-size: .75rem; color: var(--text-light); text-align: center; }
.main-content { padding: 2rem 0; }
.resource-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.resource-card { background: var(--white); border: 1px solid var(--border); border-radius: 6px; padding: 1.5rem; transition: box-shadow .2s; }
.resource-card:hover { box-shadow: var(--shadow-lg); }
.resource-header { display: flex; justify-content: space-between; align-items: start; margin-bottom: 1rem; }
.resource-title { font-size: 1.25rem; font-weight: 600; color: var(--text); margin-bottom: .25rem; }
.resource-org { color: var(--text-light); font-size: .9rem; }
.resource-badges { display: flex; gap: .5rem; flex-wrap: wrap; }
.badge { padding: .25rem .75rem; border-radius: 20px; font-size: .75rem; font-weight: 500; text-transform: uppercase; letter-spacing: .5px; }
.badge-public { background: var(--success-light); color: var(--success); }
.badge-restricted { background: var(--danger-light); color: var(--danger); }
.badge-active { background: var(--primary-light); color: var(--primary); }
.badge-inactive { background: var(--bg); color: var(--text-light); }
.resource-description { color: var(--text); margin-bottom: 1rem; line-height: 1.5; }
.resource-meta { display: flex; gap: 1.25rem; flex-wrap: wrap; padding-top: 1rem; border-top: 1px solid var(--border); font-size: .9rem; color: var(--text-light); }
.resource-link { color: var(--primary); text-decoration: none; }
.resource-link:hover { text-decoration: underline; }
.type-tag { display: inline-block; padding: .125rem .5rem; background: var(--bg); border-radius: 4px; font-size: .875rem; color: var(--text); }
.edit-link { color: var(--text-light); text-decoration: none; font-size: .875rem; display: inline-flex; align-items: center; gap: .25rem; }
.edit-link:hover { color: var(--primary); text-decoration: underline; }
.table-view { display: none; overflow-x: auto; border: 1px solid var(--border); border-radius: 6px; background: var(--white); }
table { width: 100%; border-collapse: collapse; table-layout: fixed; }
th { background: var(--bg); padding: .75rem 1rem; text-align: left; font-weight: 600; font-size: .875rem; color: var(--text); border-bottom: 1px solid var(--border); }
th:nth-child(1) { width: 19%; } /* Name */
th:nth-child(2) { width: 15%; } /* Type(s) */
th:nth-child(3) { width: 11%; } /* Accessibility */
th:nth-child(4) { width: 10%; text-align: center; } /* Activity */
th:nth-child(5) { width: 21%; } /* Organization */
th:nth-child(6) { width: 8%; } /* Link */
th:nth-child(7) { width: 7%; text-align: center; } /* Website Status */
th:nth-child(8) { width: 9%; text-align: center; } /* Edit */
td { padding: .75rem 1rem; border-bottom: 1px solid var(--border); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
td:first-child { white-space: normal; }
td:nth-child(2) { white-space: normal; }
td:nth-child(5) { white-space: normal; }
td:nth-child(3) { white-space: nowrap; } /* Accessibility column */
td:nth-child(4) { white-space: nowrap; text-align: center; } /* Activity column */
td:nth-child(6) { white-space: nowrap; } /* Link column */
td:nth-child(7) { white-space: nowrap; text-align: center; } /* Website Status column */
td:nth-child(8) { white-space: nowrap; text-align: center; } /* Edit column */
.status-working { color: var(--success); font-weight: bold; }
.status-warning { color: #f59e0b; font-weight: bold; }
.empty-state { text-align: center; padding: 4rem 2rem; color: var(--text-light); }
.empty-state h3 { font-size: 1.25rem; margin-bottom: .5rem; color: var(--text); }
.last-checked-info {
background: var(--bg);
border: 1px solid var(--border);
border-radius: 6px;
padding: 1rem;
margin-bottom: 1rem;
font-size: .9rem;
color: var(--text-light);
}
</style>
</head>
<body>
<header class="header">
<div class="container">
<h1>Trusted Data Now</h1>
<p class="subtitle">ESIP Disasters Cluster project: community-curated tools and datasets for disaster readiness and responses</p>
</div>
</header>
<div class="toolbar">
<div class="container">
<div class="toolbar-content">
<div class="search-container">
<input type="text" class="search-input" id="searchInput" placeholder="Search resources..." aria-label="Search resources"/>
</div>
<div class="filters">
<select id="typeFilter" aria-label="Filter by type">
<option value="">All Types</option>
<option value="flood">Flood</option>
<option value="earthquake">Earthquake</option>
<option value="wildfire">Wildfire</option>
<option value="drought">Drought</option>
<option value="hurricane">Hurricane</option>
<option value="tornado">Tornado</option>
<option value="extreme-weather">Extreme weather</option>
<option value="other">Other</option>
</select>
<select id="statusFilter" aria-label="Filter by accessibility">
<option value="">All Accessibility</option>
<option value="public">Public</option>
</select>
</div>
<!-- Direct link to Google Form -->
<a id="openFormBtn" class="btn btn-primary" href="#" target="_blank" rel="noopener">+ Submit via Google Form</a>
<div class="view-toggle" role="tablist" aria-label="View toggle">
<button id="cardViewBtn" onclick="setView('card')" role="tab" aria-selected="false">Cards</button>
<button id="tableViewBtn" class="active" onclick="setView('table')" role="tab" aria-selected="true">Table</button>
</div>
</div>
</div>
</div>
<div class="stats-bar">
<div class="container">
<div class="stats">
<div class="stat">
<span class="stat-value" id="totalCount">0</span>
<span class="stat-label">Total Resources</span>
</div>
<div class="stat">
<span class="stat-value" id="publicCount">0</span>
<span class="stat-label">Public Access</span>
</div>
<div class="stat">
<span class="stat-value" id="orgCount">0</span>
<span class="stat-label">Organizations</span>
</div>
</div>
<div class="type-stats" id="typeStats" style="display:none;">
<div class="type-stat">
<span class="type-emoji">🌊</span>
<span class="type-count" id="floodCount">0</span>
<span class="type-label">Flood</span>
</div>
<div class="type-stat">
<span class="type-emoji">🌍</span>
<span class="type-count" id="earthquakeCount">0</span>
<span class="type-label">Earthquake</span>
</div>
<div class="type-stat">
<span class="type-emoji">🔥</span>
<span class="type-count" id="wildfireCount">0</span>
<span class="type-label">Wildfire</span>
</div>
<div class="type-stat">
<span class="type-emoji">☀️</span>
<span class="type-count" id="droughtCount">0</span>
<span class="type-label">Drought</span>
</div>
<div class="type-stat">
<span class="type-emoji">🌀</span>
<span class="type-count" id="hurricaneCount">0</span>
<span class="type-label">Hurricane</span>
</div>
<div class="type-stat">
<span class="type-emoji">🌪️</span>
<span class="type-count" id="tornadoCount">0</span>
<span class="type-label">Tornado</span>
</div>
<div class="type-stat">
<span class="type-emoji">⛈️</span>
<span class="type-count" id="extremeWeatherCount">0</span>
<span class="type-label">Extreme Weather</span>
</div>
<div class="type-stat">
<span class="type-emoji">📋</span>
<span class="type-count" id="otherCount">0</span>
<span class="type-label">Other</span>
</div>
</div>
</div>
</div>
<main class="main-content">
<div class="container">
<div id="loadingState" class="empty-state">
<h3>Loading resources…</h3>
<p>Fetching the latest <code>data.json</code> from GitHub Pages</p>
</div>
<div id="lastCheckedInfo" class="last-checked-info" style="display:none;">
<p><strong>Last accessibility check:</strong> <span id="lastCheckedTime">—</span></p>
</div>
<div id="cardView" class="resource-grid" style="display:none;"></div>
<div id="tableView" class="table-view" style="display:block;">
<table aria-label="Resources table">
<thead>
<tr>
<th>Name</th>
<th>Type(s)</th>
<th>Accessibility</th>
<th>Activity</th>
<th>Organization</th>
<th>Link</th>
<th>Website Status</th>
<th>Edit</th>
</tr>
</thead>
<tbody id="tableBody"></tbody>
</table>
</div>
<div id="emptyState" class="empty-state" style="display:none;">
<h3>No resources found</h3>
<p>Try adjusting your search or filters</p>
</div>
</div>
</main>
<script>
// === Replace this with your form's Preview URL (must be /d/e/.../viewform) ===
const GOOGLE_FORM_VIEW_URL = "https://docs.google.com/forms/d/e/1FAIpQLSca1QqteZBgFN0qoY3APbMVH0i-xtmDoUXjCLtgKoT4-9NMeg/viewform";
// === Update Form Configuration ===
// OPTION 1: Use your existing submission form (recommended for simplicity)
// OPTION 2: Create a separate update form (better UX but more work)
// To get ALL field entry IDs for pre-filling:
// 1. Open your Google Form in edit mode
// 2. Click ⋮ (three dots) → "Get pre-filled link"
// 3. Fill in ALL fields with test values (e.g., "TEST_NAME", "TEST_URL", etc.)
// 4. Click "Get link" and copy the URL
// 5. Extract ALL entry IDs from the URL (e.g., entry.123456789)
// 6. Update the FORM_FIELD_MAPPING below with your actual entry IDs
//
// Note: If you see "continue draft?" when clicking edit links:
// - Clear your browser cookies/cache for Google Forms
// - The usp=pp_url parameter should prevent draft conflicts
// OPTION 1: Use existing form (map all fields to their entry IDs)
const UPDATE_FORM_BASE_URL = GOOGLE_FORM_VIEW_URL; // Reuse existing form
// Map resource fields to Google Form entry IDs
// These are the correct entry IDs from your Google Form
const FORM_FIELD_MAPPING = {
'contributorName': 'entry.479540527', // Contributor Name field
'name': 'entry.1602191747', // Data Name field
'description': 'entry.1201995075', // Description field
'type': 'entry.960531407', // Type field (disaster type - checkboxes)
'url': 'entry.1253715788', // URL/Link field
'organization': 'entry.183928982', // Organization field
'contact': 'entry.1491758344', // Contact field
'notes': 'entry.1134850783', // Notes field
'public': 'entry.1063402783', // Publicly available (Yes/No)
'researchOrOps': 'entry.1368198965', // Use case (Research/Operation)
'active': 'entry.1265784590', // Currently active (Yes/No)
};
// OPTION 2: Separate update form (uncomment these lines)
// const UPDATE_FORM_BASE_URL = "https://docs.google.com/forms/d/e/YOUR_UPDATE_FORM_ID/viewform";
// const UPDATE_FORM_URL_FIELD_ID = "entry.123456789";
// Helper to format type values to match Google Form options
function formatTypeForForm(type) {
const typeMap = {
'flood': 'Flood',
'earthquake': 'Earthquake',
'wildfire': 'Wildfire',
'drought': 'Drought',
'hurricane': 'Hurricane',
'tornado': 'Tornado',
'extreme-weather': 'Extreme weather',
'other': 'Other'
};
return typeMap[type] || type;
}
// Generate pre-filled update form URL with ALL resource data
function getUpdateFormURL(resource) {
const params = new URLSearchParams();
params.append('usp', 'pp_url'); // Indicate pre-populated URL to avoid draft conflicts
// Pre-fill all available fields from the resource
for (const [resourceField, formEntryId] of Object.entries(FORM_FIELD_MAPPING)) {
const value = resource[resourceField];
// Skip empty/null/undefined values
if (value === null || value === undefined || value === '') continue;
// Handle array types (e.g., disaster types) - for checkboxes, add multiple entries
if (Array.isArray(value)) {
value.forEach(item => {
if (item) {
// Format type values to match form options
const formattedItem = resourceField === 'type' ? formatTypeForForm(item) : item;
params.append(formEntryId, String(formattedItem));
}
});
}
// Handle single type value (not array)
else if (resourceField === 'type' && value) {
params.append(formEntryId, formatTypeForForm(value));
}
// Handle boolean values
else if (typeof value === 'boolean') {
params.append(formEntryId, value ? 'Yes' : 'No');
}
// Handle regular string/number values
else {
params.append(formEntryId, String(value));
}
}
return `${UPDATE_FORM_BASE_URL}?${params.toString()}`;
}
// Hook the button to open your form
document.addEventListener('DOMContentLoaded', () => {
const btn = document.getElementById('openFormBtn');
btn.href = GOOGLE_FORM_VIEW_URL;
});
// === Load data.json at runtime ===
let resources = [];
let filteredResources = [];
let currentView = 'table';
function getTypeLabelsForUI(types) {
const map = {
'flood': '🌊 Flood', 'earthquake': '🌍 Earthquake', 'wildfire': '🔥 Wildfire',
'drought': '☀️ Drought', 'hurricane': '🌀 Hurricane', 'tornado': '🌪️ Tornado',
'extreme-weather': '⛈️ Extreme weather', 'other': '📋 Other'
};
return types.map(t => map[t] || t.replace(/-/g,' ').replace(/\b\w/g,m=>m.toUpperCase()));
}
function asTypeArray(t) {
if (Array.isArray(t)) return t;
if (!t) return [];
return [String(t)];
}
// Deduplicate resources by URL, keeping the most recent version
function deduplicateResources(resourceList) {
const urlMap = new Map();
// Process each resource
resourceList.forEach((resource, index) => {
const url = resource.url?.trim();
// Skip resources without URLs
if (!url) {
console.warn('Resource without URL found:', resource.name);
return;
}
// Check if we've seen this URL before
if (urlMap.has(url)) {
const existing = urlMap.get(url);
// Increment version number
existing.version = (existing.version || 1) + 1;
// Update with newer data (last one wins)
urlMap.set(url, { ...resource, version: existing.version });
} else {
// First occurrence - version 1 (but don't show v1)
urlMap.set(url, { ...resource, version: 1 });
}
});
// Convert map back to array
const deduplicated = Array.from(urlMap.values());
// Log deduplication stats
const originalCount = resourceList.length;
const uniqueCount = deduplicated.length;
if (originalCount > uniqueCount) {
console.log(`Deduplicated: ${originalCount} entries → ${uniqueCount} unique resources (${originalCount - uniqueCount} duplicates removed)`);
}
return deduplicated;
}
async function loadResources() {
const loading = document.getElementById('loadingState');
const cardView = document.getElementById('cardView');
const tableView = document.getElementById('tableView');
const emptyState = document.getElementById('emptyState');
loading.style.display = 'block';
cardView.style.display = 'none';
tableView.style.display = 'none';
emptyState.style.display = 'none';
try {
const res = await fetch('data.json?cb=' + Date.now(), { cache: 'no-store' });
if (!res.ok) throw new Error('HTTP ' + res.status);
const data = await res.json();
const rawResources = Array.isArray(data) ? data : [];
// Deduplicate resources by URL
resources = deduplicateResources(rawResources);
filteredResources = [...resources];
renderResources();
setView(currentView);
loading.style.display = 'none';
if (filteredResources.length === 0) emptyState.style.display = 'block';
} catch (err) {
console.error('Failed to load data.json', err);
loading.innerHTML = `
<h3>Could not load resources</h3>
<p style="margin-top:.5rem;">Ensure <code>data.json</code> exists at the site root and GitHub Pages is enabled.</p>
`;
}
}
function renderResources() {
const cardContainer = document.getElementById('cardView');
const tableBody = document.getElementById('tableBody');
const emptyState = document.getElementById('emptyState');
if (!filteredResources.length) {
cardContainer.innerHTML = '';
tableBody.innerHTML = '';
emptyState.style.display = 'block';
return;
}
emptyState.style.display = 'none';
cardContainer.innerHTML = filteredResources.map(resource => {
const types = asTypeArray(resource.type);
const labels = getTypeLabelsForUI(types);
const pubBadge = resource.public ? '<span class="badge badge-public">Public</span>' : '<span class="badge badge-restricted">Restricted</span>';
const sub = resource.subscription === true ? ' • Subscription' : '';
const ro = resource.researchOrOps ? ` • ${escapeHTML(resource.researchOrOps)}` : '';
const editURL = getUpdateFormURL(resource);
return `
<div class="resource-card">
<div class="resource-header">
<div>
<div class="resource-title">${escapeHTML(resource.name || 'Untitled')}</div>
<div class="resource-org">${escapeHTML(resource.organization || 'Unknown')}</div>
</div>
<div class="resource-badges">${pubBadge}</div>
</div>
<p class="resource-description">${escapeHTML(resource.description || '')}</p>
<div class="resource-meta">
<div>${labels.map(l => `<span class="type-tag">${escapeHTML(l)}</span>`).join(' ')}</div>
<div><a href="${escapeAttr(resource.url || '#')}" target="_blank" rel="noopener noreferrer" class="resource-link">View Resource →</a></div>
<div><a href="${escapeAttr(editURL)}" target="_blank" rel="noopener noreferrer" class="edit-link">✏️ Suggest Edit</a></div>
${resource.contact ? `<div>📧 ${escapeHTML(resource.contact)}</div>` : ''}
${resource.notes ? `<div>📝 ${escapeHTML(resource.notes)}</div>` : ''}
${(sub || ro) ? `<div>${sub}${ro}</div>` : ''}
</div>
</div>
`;
}).join('');
tableBody.innerHTML = filteredResources.map(resource => {
const types = asTypeArray(resource.type);
const labels = getTypeLabelsForUI(types);
const pubBadge = resource.public ? '<span class="badge badge-public">Public</span>' : '<span class="badge badge-restricted">Restricted</span>';
// Link status - simple emoji with colors
let linkStatus = '—';
if (resource.accessible !== undefined) {
if (resource.accessible) {
linkStatus = '<span class="status-working">✓</span>';
} else {
linkStatus = '<span class="status-warning">⚠️</span>';
}
}
const editURL = getUpdateFormURL(resource);
// Show version only if edited (v2, v3, etc.) - don't show v1
const version = (resource.version && resource.version > 1) ? ` v${resource.version}` : '';
// Active status badge
const activeBadge = resource.active
? '<span class="badge badge-active">Active</span>'
: '<span class="badge badge-inactive">Inactive</span>';
return `
<tr>
<td><strong>${escapeHTML(resource.name || 'Untitled')}</strong></td>
<td>${labels.map(l => `<span class="type-tag">${escapeHTML(l)}</span>`).join(' ')}</td>
<td>${pubBadge}</td>
<td>${activeBadge}</td>
<td>${escapeHTML(resource.organization || '—')}</td>
<td><a href="${escapeAttr(resource.url || '#')}" target="_blank" rel="noopener noreferrer" class="resource-link">View →</a></td>
<td>${linkStatus}</td>
<td><a href="${escapeAttr(editURL)}" target="_blank" rel="noopener noreferrer" class="edit-link" title="Edit resource${version ? ' (' + version.trim() + ')' : ''}">✏️${version}</a></td>
</tr>
`;
}).join('');
updateStats();
updateLastCheckedInfo();
}
function updateStats() {
document.getElementById('totalCount').textContent = resources.length;
document.getElementById('publicCount').textContent = resources.filter(r => r.public).length;
const orgs = new Set(resources.map(r => (r.organization || '').trim()).filter(Boolean));
document.getElementById('orgCount').textContent = orgs.size;
// Update type statistics
updateTypeStats();
}
function updateTypeStats() {
const typeCounts = {
'flood': 0,
'earthquake': 0,
'wildfire': 0,
'drought': 0,
'hurricane': 0,
'tornado': 0,
'extreme-weather': 0,
'other': 0
};
// Count resources by type
resources.forEach(resource => {
const types = asTypeArray(resource.type);
types.forEach(type => {
if (typeCounts.hasOwnProperty(type)) {
typeCounts[type]++;
}
});
});
// Update the display
document.getElementById('floodCount').textContent = typeCounts['flood'];
document.getElementById('earthquakeCount').textContent = typeCounts['earthquake'];
document.getElementById('wildfireCount').textContent = typeCounts['wildfire'];
document.getElementById('droughtCount').textContent = typeCounts['drought'];
document.getElementById('hurricaneCount').textContent = typeCounts['hurricane'];
document.getElementById('tornadoCount').textContent = typeCounts['tornado'];
document.getElementById('extremeWeatherCount').textContent = typeCounts['extreme-weather'];
document.getElementById('otherCount').textContent = typeCounts['other'];
// Show the type stats section
document.getElementById('typeStats').style.display = 'flex';
}
function updateLastCheckedInfo() {
const lastCheckedInfo = document.getElementById('lastCheckedInfo');
const lastCheckedTime = document.getElementById('lastCheckedTime');
// Find the most recent lastChecked timestamp
let mostRecentCheck = null;
for (const resource of resources) {
if (resource.lastChecked) {
if (!mostRecentCheck || resource.lastChecked > mostRecentCheck) {
mostRecentCheck = resource.lastChecked;
}
}
}
if (mostRecentCheck) {
try {
const checkDate = new Date(mostRecentCheck);
const now = new Date();
const diffHours = Math.floor((now - checkDate) / (1000 * 60 * 60));
let timeText;
if (diffHours < 1) {
timeText = 'Just now';
} else if (diffHours < 24) {
timeText = `${diffHours} hours ago`;
} else {
const diffDays = Math.floor(diffHours / 24);
timeText = `${diffDays} days ago`;
}
lastCheckedTime.textContent = timeText;
lastCheckedInfo.style.display = 'block';
} catch (e) {
lastCheckedInfo.style.display = 'none';
}
} else {
lastCheckedInfo.style.display = 'none';
}
}
function filterResources() {
const searchTerm = document.getElementById('searchInput').value.toLowerCase();
const typeFilter = document.getElementById('typeFilter').value;
const statusFilter = document.getElementById('statusFilter').value;
filteredResources = resources.filter(resource => {
const name = (resource.name || '').toLowerCase();
const desc = (resource.description || '').toLowerCase();
const org = (resource.organization || '').toLowerCase();
const matchesSearch = !searchTerm || name.includes(searchTerm) || desc.includes(searchTerm) || org.includes(searchTerm);
const types = asTypeArray(resource.type);
const matchesType = !typeFilter || types.includes(typeFilter);
let matchesStatus = true;
if (statusFilter === 'public') matchesStatus = resource.public === true;
return matchesSearch && matchesType && matchesStatus;
});
renderResources();
setView(currentView);
}
function setView(view) {
currentView = view;
const cardView = document.getElementById('cardView');
const tableView = document.getElementById('tableView');
const cardBtn = document.getElementById('cardViewBtn');
const tableBtn = document.getElementById('tableViewBtn');
if (view === 'card') {
cardView.style.display = 'grid';
tableView.style.display = 'none';
cardBtn.classList.add('active'); cardBtn.setAttribute('aria-selected', 'true');
tableBtn.classList.remove('active'); tableBtn.setAttribute('aria-selected', 'false');
} else {
cardView.style.display = 'none';
tableView.style.display = 'block';
cardBtn.classList.remove('active'); cardBtn.setAttribute('aria-selected', 'false');
tableBtn.classList.add('active'); tableBtn.setAttribute('aria-selected', 'true');
}
}
function escapeHTML(s) {
return String(s).replace(/[&<>"']/g, c => ({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c]));
}
function escapeAttr(s) { return escapeHTML(s); }
document.getElementById('searchInput').addEventListener('input', filterResources);
document.getElementById('typeFilter').addEventListener('change', filterResources);
document.getElementById('statusFilter').addEventListener('change', filterResources);
document.addEventListener('DOMContentLoaded', () => {
loadResources(); // site reads data.json at runtime
setView('table');
});
</script>
</body>
</html>