-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcities.html
More file actions
509 lines (477 loc) · 27 KB
/
Copy pathcities.html
File metadata and controls
509 lines (477 loc) · 27 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>World Cities - Hindi Tutor Point</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
<script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script>
<style>
:root {
--primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
body {
background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
min-height: 100vh;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
.navbar {
background: white !important;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
.navbar-brand {
font-weight: 700;
background: var(--primary-gradient);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
font-size: 1.5rem;
}
.nav-link {
color: #667eea !important;
font-weight: 500;
transition: all 0.3s ease;
position: relative;
}
.nav-link:hover { color: #764ba2 !important; }
.nav-link::after {
content: '';
position: absolute;
bottom: 0;
left: 50%;
width: 0;
height: 2px;
background: var(--primary-gradient);
transition: all 0.3s ease;
transform: translateX(-50%);
}
.nav-link:hover::after { width: 80%; }
.hero-section {
background: var(--primary-gradient);
color: white;
padding: 4rem 0 3rem;
margin-bottom: 2rem;
box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}
.card {
border: none;
border-radius: 15px;
box-shadow: 0 5px 20px rgba(0,0,0,0.1);
overflow: hidden;
}
.table th { background: var(--primary-gradient); color: white; }
.spinner-overlay {
display: flex;
justify-content: center;
align-items: center;
padding: 3rem;
}
body.print-mode .navbar,
body.print-mode .hero-section,
body.print-mode footer,
body.print-mode .no-print,
body.print-mode .pagination { display: none !important; }
body.print-mode .print-only { display: block !important; }
body.print-mode .card { box-shadow: none; border: 1px solid #ddd; }
.print-only { display: none; }
.empty-state {
text-align: center;
padding: 3rem;
color: #6c757d;
}
.empty-state i { font-size: 3rem; margin-bottom: 1rem; display: block; }
</style>
</head>
<body>
<div x-data="citiesPage()">
<nav class="navbar navbar-expand-lg navbar-light bg-light sticky-top">
<div class="container">
<a class="navbar-brand d-flex align-items-center" href="index.html"><img src="jar.svg" alt="JAR" height="35" class="me-2"><span class="d-flex flex-column"><span>JAR</span><small class="text-muted" style="font-size:0.6rem;font-weight:400;line-height:1;background:none;-webkit-text-fill-color:#6c757d;color:#6c757d;">JSON API Repository</small></span></a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ms-auto">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="demographicDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
<i class="bi bi-globe2 me-1"></i>Demographic
</a>
<ul class="dropdown-menu" aria-labelledby="demographicDropdown">
<li><a class="dropdown-item" href="regions.html"><i class="bi bi-globe me-1"></i>Regions</a></li>
<li><a class="dropdown-item" href="subregions.html"><i class="bi bi-map me-1"></i>Subregions</a></li>
<li><a class="dropdown-item" href="country.html"><i class="bi bi-flag me-1"></i>Countries</a></li>
<li><a class="dropdown-item" href="states.html"><i class="bi bi-building me-1"></i>States</a></li>
<li><a class="dropdown-item" href="cities.html"><i class="bi bi-geo-alt me-1"></i>Cities</a></li>
</ul>
</li>
<li class="nav-item"><a class="nav-link" href="personalities.html"><i class="bi bi-person-badge me-1"></i>Personalities</a></li>
<li class="nav-item"><a class="nav-link" href="quotes.html"><i class="bi bi-quote me-1"></i>Quotes</a></li>
<li class="nav-item"><a class="nav-link" href="blogs.html"><i class="bi bi-file-post me-1"></i>Blogs</a></li>
<li class="nav-item"><a class="nav-link" href="vocabulary.html"><i class="bi bi-book me-1"></i>Vocabulary</a></li>
<li class="nav-item"><a class="nav-link" href="https://github.com/hinditutorpoint/json" target="_blank"><i class="bi bi-github me-1"></i>GitHub</a></li>
</ul>
</div>
</div>
</nav>
<div class="hero-section">
<div class="container text-center">
<h1 class="display-4 fw-bold mb-3"><i class="bi bi-geo-alt me-3"></i>World Cities</h1>
<p class="lead mb-0">Browse cities by state or province</p>
</div>
</div>
<div class="container pb-5">
<div class="card mb-4">
<div class="card-body p-4">
<div class="row g-3 align-items-end">
<div class="col-md-3">
<label class="form-label fw-bold"><i class="bi bi-globe me-1"></i>Region</label>
<select class="form-select" x-model="selectedRegion" @change="onRegionChange">
<option value="">-- Choose --</option>
<template x-for="region in regions" :key="region.id">
<option :value="region.id" x-text="region.region"></option>
</template>
</select>
</div>
<div class="col-md-2">
<label class="form-label fw-bold"><i class="bi bi-map me-1"></i>Subregion</label>
<select class="form-select" x-model="selectedSubregion" @change="onSubregionChange">
<option value="">-- Choose --</option>
<template x-for="sr in filteredSubregions" :key="sr.id">
<option :value="sr.id" x-text="sr.name"></option>
</template>
</select>
</div>
<div class="col-md-2">
<label class="form-label fw-bold"><i class="bi bi-flag me-1"></i>Country</label>
<select class="form-select" x-model="selectedCountry" @change="onCountryChange">
<option value="">-- Choose --</option>
<template x-for="c in filteredCountries" :key="c.id">
<option :value="c.id" x-text="c.name"></option>
</template>
</select>
</div>
<div class="col-md-3">
<label class="form-label fw-bold"><i class="bi bi-building me-1"></i>State</label>
<select class="form-select" x-model="selectedState" @change="onStateChange">
<option value="">-- Choose --</option>
<template x-for="s in filteredStates" :key="s.id">
<option :value="s.id" x-text="s.state"></option>
</template>
</select>
</div>
<div class="col-md-2">
<span class="badge bg-primary fs-6" x-show="filteredCities.length" x-text="filteredCities.length + ' cities'"></span>
</div>
</div>
</div>
</div>
<div class="card">
<div class="card-body p-4">
<h3 class="mb-4"><i class="bi bi-list-columns me-2"></i>Cities</h3>
<div x-show="!selectedState" class="empty-state">
<i class="bi bi-hand-index-thumb"></i>
<p class="fs-5">Please select a region, subregion, country, and state to view cities</p>
</div>
<div x-show="loading" class="spinner-overlay">
<div class="spinner-border text-primary" role="status">
<span class="visually-hidden">Loading cities...</span>
</div>
<span class="ms-3 text-muted">Loading large dataset, please wait...</span>
</div>
<div x-show="error" class="alert alert-danger" x-text="error"></div>
<div x-show="selectedState && !loading && !error">
<div x-show="filteredCities.length === 0" class="alert alert-info mt-3">
No cities found for the selected state.
</div>
<template x-if="filteredCities.length > 0">
<div>
<div class="row g-2 mb-3">
<div class="col-md-5">
<input type="text" class="form-control form-control-sm" placeholder="Search cities..." x-model="searchQuery" @input="page = 1">
</div>
<div class="col-md-3 d-flex align-items-center">
<span class="text-muted small">
Showing <strong x-text="showingFrom"></strong>–<strong x-text="showingTo"></strong>
of <strong x-text="searchedCities.length"></strong>
<template x-if="searchQuery && searchedCities.length !== filteredCities.length">
<span>(filtered from <strong x-text="filteredCities.length"></strong>)</span>
</template>
</span>
</div>
<div class="col-md-4 d-flex align-items-center justify-content-end gap-2">
<div class="d-flex align-items-center gap-2 no-print">
<button class="btn btn-outline-secondary btn-sm" @click="printTable" title="Print / PDF">
<i class="bi bi-printer"></i> Print
</button>
<button class="btn btn-outline-success btn-sm" @click="exportExcel" title="Export to Excel">
<i class="bi bi-file-earmark-excel"></i> Excel
</button>
</div>
<div class="d-flex align-items-center gap-2 no-print">
<label class="form-label mb-0 text-nowrap small">Rows/page:</label>
<select class="form-select form-select-sm" style="width: auto;" x-model="perPage" @change="page = 1">
<option value="10">10</option>
<option value="25">25</option>
<option value="50">50</option>
<option value="100">100</option>
<option value="200">200</option>
</select>
</div>
</div>
</div>
<div class="table-responsive">
<table class="table table-hover align-middle mb-0">
<thead>
<tr>
<th>#</th>
<th>City Name</th>
<th>State ID</th>
<th>Country ID</th>
</tr>
</thead>
<tbody>
<template x-for="city in paginatedCities" :key="city.id">
<tr>
<td x-text="city.id"></td>
<td><strong x-text="city.city"></strong></td>
<td><span class="badge bg-info" x-text="city.state_id"></span></td>
<td><span class="badge bg-secondary" x-text="city.country_id"></span></td>
</tr>
</template>
</tbody>
</table>
</div>
<div class="print-only mt-4" id="print-section">
<table class="table table-bordered">
<thead><tr><th>#</th><th>City Name</th><th>State ID</th><th>Country ID</th></tr></thead>
<tbody>
<template x-for="city in searchedCities" :key="city.id">
<tr><td x-text="city.id"></td><td x-text="city.city"></td><td x-text="city.state_id"></td><td x-text="city.country_id"></td></tr>
</template>
</tbody>
</table>
</div>
<nav class="mt-3 d-flex justify-content-center no-print" x-show="totalPages > 1">
<ul class="pagination pagination-sm mb-0">
<li class="page-item" :class="{ disabled: page === 1 }">
<button class="page-link" @click="goToPage(1)" :disabled="page === 1">«</button>
</li>
<li class="page-item" :class="{ disabled: page === 1 }">
<button class="page-link" @click="goToPage(page - 1)" :disabled="page === 1">‹</button>
</li>
<template x-for="p in getPageNumbers()" :key="p">
<li class="page-item" :class="{ active: p === page, disabled: p === '...' }">
<button class="page-link" x-text="p" @click="goToPage(p)" :disabled="p === '...'"></button>
</li>
</template>
<li class="page-item" :class="{ disabled: page === totalPages }">
<button class="page-link" @click="goToPage(page + 1)" :disabled="page === totalPages">›</button>
</li>
<li class="page-item" :class="{ disabled: page === totalPages }">
<button class="page-link" @click="goToPage(totalPages)" :disabled="page === totalPages">»</button>
</li>
</ul>
</nav>
</div>
</template>
</div>
</div>
</div>
</div>
<footer class="bg-dark text-white py-4 mt-5">
<div class="container text-center">
<p class="mb-2">
<i class="bi bi-github me-2"></i>
<a href="https://github.com/hinditutorpoint/json" target="_blank" class="text-white text-decoration-none">github.com/hinditutorpoint/json</a>
</p>
<p class="mb-0 text-muted">Built with Alpine.js & Bootstrap 5 | © 2026 Hindi Tutor Point</p>
</div>
</footer>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2pdf.js/0.10.1/html2pdf.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
<script>
function citiesPage() {
return {
regions: [],
selectedRegion: '',
filteredSubregions: [],
allSubregions: null,
selectedSubregion: '',
allCountries: null,
filteredCountries: [],
selectedCountry: '',
allStates: null,
filteredStates: [],
selectedState: '',
allCities: null,
filteredCities: [],
searchQuery: '',
page: 1,
perPage: 10,
loading: false,
error: null,
get searchedCities() {
if (!this.searchQuery) return this.filteredCities;
const q = this.searchQuery.toLowerCase();
return this.filteredCities.filter(c => c.city.toLowerCase().includes(q));
},
get totalPages() {
return Math.ceil(this.searchedCities.length / this.perPage) || 1;
},
get paginatedCities() {
const start = (this.page - 1) * this.perPage;
return this.searchedCities.slice(start, start + this.perPage);
},
get showingFrom() {
return this.searchedCities.length ? (this.page - 1) * this.perPage + 1 : 0;
},
get showingTo() {
return Math.min(this.page * this.perPage, this.searchedCities.length);
},
goToPage(p) {
if (p >= 1 && p <= this.totalPages) this.page = p;
},
printTable() {
const opt = {
margin: [5, 5, 5, 5],
filename: 'cities.pdf',
image: { type: 'jpeg', quality: 0.98 },
html2canvas: { scale: 2, useCORS: true },
jsPDF: { unit: 'mm', format: 'a4', orientation: 'portrait' }
};
document.body.classList.add('print-mode');
setTimeout(() => {
html2pdf().set(opt).from(document.getElementById('print-section')).save().then(() => {
document.body.classList.remove('print-mode');
}).catch(() => { document.body.classList.remove('print-mode'); });
}, 300);
},
exportExcel() {
const rows = [['ID', 'City Name', 'State ID', 'Country ID']];
this.searchedCities.forEach(c => rows.push([c.id, c.city, c.state_id, c.country_id]));
const csv = rows.map(r => r.map(v => `"${String(v).replace(/"/g, '""')}"`).join(',')).join('\n');
const blob = new Blob(['\uFEFF' + csv], { type: 'text/csv;charset=utf-8;' });
const a = document.createElement('a');
a.href = URL.createObjectURL(blob);
a.download = 'cities.csv';
a.click();
URL.revokeObjectURL(a.href);
},
getPageNumbers() {
const total = this.totalPages;
const current = this.page;
const pages = [];
if (total <= 7) {
for (let i = 1; i <= total; i++) pages.push(i);
} else {
pages.push(1);
if (current > 3) pages.push('...');
for (let i = Math.max(2, current - 1); i <= Math.min(total - 1, current + 1); i++) pages.push(i);
if (current < total - 2) pages.push('...');
pages.push(total);
}
return pages;
},
async init() {
await this.loadRegions();
},
extractData(json, tableName) {
const table = json.find(item => item.type === 'table' && item.name === tableName);
return table ? table.data : [];
},
async loadRegions() {
try {
const res = await fetch('https://raw.githubusercontent.com/hinditutorpoint/json/main/regions.json');
const json = await res.json();
this.regions = this.extractData(json, 'regions');
} catch (err) {
this.error = 'Failed to load regions.';
console.error(err);
}
},
async onRegionChange() {
this.selectedSubregion = '';
this.selectedCountry = '';
this.selectedState = '';
this.filteredCountries = [];
this.filteredStates = [];
this.filteredCities = [];
if (!this.selectedRegion) { this.filteredSubregions = []; return; }
if (!this.allSubregions) {
this.loading = true;
try {
const res = await fetch('https://raw.githubusercontent.com/hinditutorpoint/json/main/subregions.json');
const json = await res.json();
this.allSubregions = this.extractData(json, 'subregions');
} catch (err) {
this.error = 'Failed to load subregions.';
console.error(err);
} finally { this.loading = false; }
}
this.filteredSubregions = this.allSubregions.filter(sr => sr.region_id === this.selectedRegion);
},
async onSubregionChange() {
this.selectedCountry = '';
this.selectedState = '';
this.filteredStates = [];
this.filteredCities = [];
if (!this.selectedSubregion) { this.filteredCountries = []; return; }
if (!this.allCountries) {
this.loading = true;
try {
const res = await fetch('https://raw.githubusercontent.com/hinditutorpoint/json/main/countries.json');
const json = await res.json();
this.allCountries = this.extractData(json, 'countries');
} catch (err) {
this.error = 'Failed to load countries.';
console.error(err);
} finally { this.loading = false; }
}
this.filteredCountries = this.allCountries.filter(c => c.subregion_id === this.selectedSubregion);
},
async onCountryChange() {
this.selectedState = '';
this.filteredCities = [];
if (!this.selectedCountry) { this.filteredStates = []; return; }
if (!this.allStates) {
this.loading = true;
try {
const res = await fetch('https://raw.githubusercontent.com/hinditutorpoint/json/main/states.json');
const json = await res.json();
this.allStates = this.extractData(json, 'states');
} catch (err) {
this.error = 'Failed to load states.';
console.error(err);
} finally { this.loading = false; }
}
this.filteredStates = this.allStates
.filter(s => s.country_id === this.selectedCountry)
.sort((a, b) => a.state.localeCompare(b.state));
},
async onStateChange() {
this.filteredCities = [];
this.page = 1;
if (!this.selectedState) return;
if (!this.allCities) {
this.loading = true;
this.error = null;
try {
const res = await fetch('https://raw.githubusercontent.com/hinditutorpoint/json/main/cities.json');
const json = await res.json();
this.allCities = this.extractData(json, 'cities');
} catch (err) {
this.error = 'Failed to load cities. The dataset is very large. Please try again.';
console.error(err);
} finally { this.loading = false; }
}
this.filteredCities = this.allCities
.filter(c => c.state_id === this.selectedState)
.sort((a, b) => a.city.localeCompare(b.city));
}
}
}
</script>
</body>
</html>