-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
987 lines (898 loc) · 52.7 KB
/
Copy pathindex.html
File metadata and controls
987 lines (898 loc) · 52.7 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
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SmartWater – Urban Water Management Platform</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap" rel="stylesheet">
<!-- Official Firebase Web SDK (v10 Compat) -->
<script src="https://www.gstatic.com/firebasejs/10.8.0/firebase-app-compat.js"></script>
<script src="https://www.gstatic.com/firebasejs/10.8.0/firebase-auth-compat.js"></script>
<script src="https://www.gstatic.com/firebasejs/10.8.0/firebase-firestore-compat.js"></script>
<style>
body { font-family: 'Inter', sans-serif; }
.nav-item.active { background-color: #2563eb; color: white; }
.pulse-dot { animation: pulse 1.5s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }
</style>
</head>
<body class="bg-slate-50 text-slate-800 flex h-screen overflow-hidden">
<!-- Login Modal Overlay -->
<div id="auth-modal" class="fixed inset-0 bg-slate-900/80 backdrop-blur-md z-50 flex items-center justify-center p-4">
<div class="bg-white rounded-3xl max-w-md w-full p-8 shadow-2xl space-y-6">
<div class="text-center space-y-2">
<div class="inline-flex p-3 bg-blue-600 rounded-2xl text-white shadow-lg shadow-blue-500/30">
<svg class="w-8 h-8" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19.428 15.428a2 2 0 00-1.022-.547l-2.387-.477a6 6 0 00-3.86.517l-.318.158a6 6 0 01-3.86.517L6.05 15.21a2 2 0 00-1.806.547M8 4h8l-1 1v5.172a2 2 0 00.586 1.414l5 5c1.26 1.26.367 3.414-1.415 3.414H4.828c-1.782 0-2.674-2.154-1.414-3.414l5-5A2 2 0 009 10.172V5L8 4z"></path></svg>
</div>
<h2 class="text-2xl font-extrabold text-slate-900 tracking-tight">SmartWater Sign-in</h2>
<p class="text-xs text-slate-500">Access Municipal Monitoring & Citizen Water Portal</p>
</div>
<!-- Real Google Sign-in Button with Account Selector -->
<button id="btn-google-login" onclick="triggerGoogleSignIn()" class="w-full flex items-center justify-center gap-3 bg-white border border-slate-200 hover:bg-slate-50 text-slate-700 font-semibold py-3 px-4 rounded-xl shadow-sm transition-all hover:border-slate-300">
<svg class="w-5 h-5" viewBox="0 0 24 24">
<path fill="#4285F4" d="M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z"/>
<path fill="#34A853" d="M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z"/>
<path fill="#FBBC05" d="M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.06H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.94l2.85-2.22.81-.63z"/>
<path fill="#EA4335" d="M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.06l3.66 2.84c.87-2.6 3.3-4.52 6.16-4.52z"/>
</svg>
<span id="google-btn-text">Choose Google Account</span>
</button>
<div class="flex items-center my-3">
<div class="flex-1 border-t border-slate-200"></div>
<span class="px-3 text-xs text-slate-400 uppercase font-bold tracking-wider">Or Email Login</span>
<div class="flex-1 border-t border-slate-200"></div>
</div>
<form onsubmit="handleEmailAuth(event)" class="space-y-3">
<div>
<label class="block text-xs font-semibold text-slate-700 mb-1">Email Address</label>
<input id="input-email" type="email" required placeholder="name@domain.com" class="w-full border border-slate-300 rounded-xl p-2.5 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500">
</div>
<div>
<label class="block text-xs font-semibold text-slate-700 mb-1">Password</label>
<input id="input-password" type="password" required placeholder="••••••••" class="w-full border border-slate-300 rounded-xl p-2.5 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500">
</div>
<button type="submit" class="w-full bg-blue-600 hover:bg-blue-700 text-white font-bold py-3 px-4 rounded-xl text-sm shadow-lg shadow-blue-500/20 transition-all">
Sign In with Email
</button>
</form>
</div>
</div>
<!-- Google Account Picker Dialog -->
<div id="google-picker-modal" class="fixed inset-0 bg-black/60 backdrop-blur-sm z-[60] hidden items-center justify-center p-4">
<div class="bg-white rounded-3xl max-w-sm w-full p-6 shadow-2xl space-y-4">
<div class="flex items-center gap-3 pb-3 border-b border-slate-100">
<svg class="w-6 h-6" viewBox="0 0 24 24">
<path fill="#4285F4" d="M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z"/>
<path fill="#34A853" d="M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z"/>
<path fill="#FBBC05" d="M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.06H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.94l2.85-2.22.81-.63z"/>
<path fill="#EA4335" d="M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.06l3.66 2.84c.87-2.6 3.3-4.52 6.16-4.52z"/>
</svg>
<div>
<h3 class="text-sm font-bold text-slate-900">Choose an account</h3>
<p class="text-[11px] text-slate-500">to continue to SmartWater Urban Grid</p>
</div>
</div>
<div class="space-y-2">
<button onclick="selectGoogleAccount('Manthan Yewale (Admin)', 'manthanyewale23@gmail.com')" class="w-full flex items-center gap-3 p-3 rounded-2xl hover:bg-purple-50/70 border border-purple-200 bg-purple-50/30 transition-all text-left group">
<div class="w-9 h-9 rounded-full bg-purple-600 text-white font-bold flex items-center justify-center text-sm shadow-sm group-hover:scale-105 transition-transform">M</div>
<div class="min-w-0 flex-1">
<div class="flex items-center gap-1.5">
<span class="font-bold text-slate-900 text-xs truncate">Manthan Yewale</span>
<span class="px-1.5 py-0.2 bg-purple-100 text-purple-700 font-bold text-[9px] rounded uppercase">Admin</span>
</div>
<div class="text-[11px] text-slate-500 truncate">manthanyewale23@gmail.com</div>
</div>
<span class="text-xs text-purple-600 font-semibold opacity-0 group-hover:opacity-100 transition-opacity">Select →</span>
</button>
<button onclick="selectGoogleAccount('Citizen User', 'citizen.user@gmail.com')" class="w-full flex items-center gap-3 p-3 rounded-2xl hover:bg-emerald-50/70 border border-slate-200 transition-all text-left group">
<div class="w-9 h-9 rounded-full bg-emerald-600 text-white font-bold flex items-center justify-center text-sm shadow-sm group-hover:scale-105 transition-transform">C</div>
<div class="min-w-0 flex-1">
<div class="font-bold text-slate-900 text-xs truncate">Citizen Google Account</div>
<div class="text-[11px] text-slate-500 truncate">citizen.user@gmail.com</div>
</div>
<span class="text-xs text-emerald-600 font-semibold opacity-0 group-hover:opacity-100 transition-opacity">Select →</span>
</button>
</div>
<button onclick="closeGooglePicker()" class="w-full py-2.5 bg-slate-100 hover:bg-slate-200 rounded-2xl text-xs font-bold text-slate-600 transition-all">Cancel</button>
</div>
</div>
<!-- Mobile Sidebar Overlay Backdrop -->
<div id="mobile-sidebar-backdrop" onclick="toggleMobileSidebar()" class="fixed inset-0 bg-black/60 backdrop-blur-sm z-30 hidden md:hidden"></div>
<!-- Sidebar (Responsive: drawer on mobile, fixed width on desktop) -->
<aside id="sidebar-container" class="fixed md:static inset-y-0 left-0 -translate-x-full md:translate-x-0 w-72 md:w-64 bg-slate-900 text-white flex flex-col justify-between flex-shrink-0 z-40 transition-transform duration-300 ease-in-out shadow-2xl md:shadow-none">
<div>
<!-- Brand -->
<div class="flex items-center justify-between px-6 py-5 border-b border-slate-800 bg-slate-950">
<div class="flex items-center gap-3">
<div class="bg-blue-600 rounded-xl p-2.5 shadow-lg shadow-blue-500/30">
<svg class="w-6 h-6 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19.428 15.428a2 2 0 00-1.022-.547l-2.387-.477a6 6 0 00-3.86.517l-.318.158a6 6 0 01-3.86.517L6.05 15.21a2 2 0 00-1.806.547M8 4h8l-1 1v5.172a2 2 0 00.586 1.414l5 5c1.26 1.26.367 3.414-1.415 3.414H4.828c-1.782 0-2.674-2.154-1.414-3.414l5-5A2 2 0 009 10.172V5L8 4z"></path></svg>
</div>
<div>
<h1 class="font-extrabold text-base tracking-tight leading-tight">SmartWater</h1>
<p class="text-xs text-slate-400 font-medium">Navi Mumbai (NMMC)</p>
</div>
</div>
<!-- Close button on mobile -->
<button onclick="toggleMobileSidebar()" class="md:hidden text-slate-400 hover:text-white p-1 text-lg font-bold">×</button>
</div>
<!-- Navigation links -->
<nav class="p-3 space-y-1.5">
<button onclick="switchTab('dashboard'); closeMobileSidebar()" id="nav-dashboard" class="nav-item active w-full flex items-center gap-3 px-4 py-3 rounded-xl text-sm font-medium transition-all text-slate-300 hover:bg-slate-800">
<span>📊</span> Dashboard
</button>
<button onclick="switchTab('map'); closeMobileSidebar()" id="nav-map" class="nav-item w-full flex items-center gap-3 px-4 py-3 rounded-xl text-sm font-medium transition-all text-slate-300 hover:bg-slate-800">
<span>🗺️</span> Water Network Map
</button>
<button onclick="switchTab('sensors'); closeMobileSidebar()" id="nav-sensors" class="nav-item w-full flex items-center gap-3 px-4 py-3 rounded-xl text-sm font-medium transition-all text-slate-300 hover:bg-slate-800">
<span>📡</span> Live Telemetry Sensors
</button>
<button onclick="switchTab('complaints'); closeMobileSidebar()" id="nav-complaints" class="nav-item w-full flex items-center gap-3 px-4 py-3 rounded-xl text-sm font-medium transition-all text-slate-300 hover:bg-slate-800">
<span>⚠️</span> Citizen Complaints (<span id="badge-complaints">5</span>)
</button>
<button onclick="switchTab('waterloss'); closeMobileSidebar()" id="nav-waterloss" class="nav-item w-full flex items-center gap-3 px-4 py-3 rounded-xl text-sm font-medium transition-all text-slate-300 hover:bg-slate-800">
<span>💧</span> Water Loss Audit
</button>
</nav>
</div>
<!-- User Profile Footer -->
<div class="p-4 border-t border-slate-800 bg-slate-950/50 flex items-center justify-between">
<div class="flex items-center gap-3 min-w-0">
<div id="user-avatar" class="w-9 h-9 rounded-full bg-blue-600 font-bold text-sm flex items-center justify-center flex-shrink-0">M</div>
<div class="min-w-0">
<div id="user-display-name" class="text-sm font-semibold leading-tight truncate">Manthan Yewale</div>
<div id="user-role-badge" class="text-xs text-purple-400 font-medium truncate">NMMC Admin</div>
</div>
</div>
<button onclick="logoutAuth()" class="text-sm text-slate-400 hover:text-rose-400 ml-2 p-1" title="Sign out">🚪</button>
</div>
</aside>
<!-- Main Content Area -->
<div class="flex-1 flex flex-col overflow-hidden min-w-0">
<!-- Top Navigation -->
<header class="bg-white border-b border-slate-200 px-4 md:px-6 py-3 flex items-center justify-between shadow-sm z-10">
<div class="flex items-center gap-3 min-w-0">
<!-- Hamburger Menu button for mobile -->
<button onclick="toggleMobileSidebar()" class="md:hidden p-2 rounded-xl bg-slate-100 hover:bg-slate-200 text-slate-700 transition-all flex-shrink-0" title="Open Menu">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16"></path></svg>
</button>
<div class="min-w-0 truncate">
<h2 id="page-title" class="text-sm md:text-base font-bold text-slate-800 truncate">City Overview Dashboard</h2>
</div>
</div>
<div class="flex items-center gap-2 md:gap-3 flex-shrink-0">
<!-- Live Simulation Button -->
<button id="btn-demo" onclick="toggleLiveDemo()" class="flex items-center gap-2 px-3 py-1.5 bg-slate-200 text-slate-700 rounded-lg text-[11px] md:text-xs font-bold shadow hover:bg-slate-300 transition-all">
<span id="demo-indicator" class="w-2 h-2 rounded-full bg-slate-400"></span>
<span id="demo-label" class="hidden sm:inline">Live Telemetry: OFF</span>
<span class="sm:hidden">OFF</span>
</button>
<div class="text-[11px] md:text-xs font-medium text-slate-500 bg-slate-100 px-2.5 py-1.5 rounded-lg border border-slate-200 hidden sm:block">
📍 Navi Mumbai
</div>
</div>
</header>
<!-- Content Tabs Container -->
<main class="flex-1 overflow-y-auto p-6 space-y-6">
<!-- Municipal Status Alert Bar -->
<div class="bg-gradient-to-r from-blue-600 via-indigo-600 to-blue-700 text-white px-5 py-3 rounded-2xl shadow-md flex items-center justify-between gap-4">
<div class="flex items-center gap-3">
<span class="p-1.5 bg-white/20 rounded-lg text-sm">📢</span>
<div>
<p class="text-xs font-bold tracking-wide uppercase text-blue-200">NMMC Municipal Water Broadcast</p>
<p class="text-sm font-semibold">Scheduled pipeline pressure optimization active in Belapur & Nerul sectors. Water supply regular.</p>
</div>
</div>
<span class="text-xs font-bold bg-emerald-400/20 text-emerald-300 border border-emerald-400/30 px-3 py-1 rounded-full whitespace-nowrap">● 100% OPERATIONAL</span>
</div>
<!-- ================= TAB 1: DASHBOARD ================= -->
<section id="tab-dashboard" class="space-y-6">
<!-- Metrics Row -->
<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4">
<div class="bg-white p-5 rounded-2xl border border-slate-200/80 shadow-sm flex items-center justify-between">
<div>
<p class="text-xs font-semibold text-slate-400 uppercase tracking-wider">Total Water Supplied</p>
<h3 id="stat-supplied" class="text-2xl font-extrabold text-slate-900 mt-1">520.0K L</h3>
<p class="text-xs text-emerald-600 font-medium mt-1">↑ Normal distribution</p>
</div>
<div class="p-3 bg-blue-50 text-blue-600 rounded-xl text-2xl">🚰</div>
</div>
<div class="bg-white p-5 rounded-2xl border border-slate-200/80 shadow-sm flex items-center justify-between">
<div>
<p class="text-xs font-semibold text-slate-400 uppercase tracking-wider">Total Billed Consumption</p>
<h3 id="stat-consumed" class="text-2xl font-extrabold text-slate-900 mt-1">426.0K L</h3>
<p class="text-xs text-slate-400 font-medium mt-1">Metered across 5 zones</p>
</div>
<div class="p-3 bg-teal-50 text-teal-600 rounded-xl text-2xl">📊</div>
</div>
<div class="bg-white p-5 rounded-2xl border border-slate-200/80 shadow-sm flex items-center justify-between">
<div>
<p class="text-xs font-semibold text-slate-400 uppercase tracking-wider">System Water Loss</p>
<h3 id="stat-loss" class="text-2xl font-extrabold text-amber-600 mt-1">94.0K L (18.1%)</h3>
<p class="text-xs text-amber-600 font-semibold mt-1">⚠️ Moderate Loss (Action required)</p>
</div>
<div class="p-3 bg-amber-50 text-amber-600 rounded-xl text-2xl">💧</div>
</div>
<div class="bg-white p-5 rounded-2xl border border-slate-200/80 shadow-sm flex items-center justify-between">
<div>
<p class="text-xs font-semibold text-slate-400 uppercase tracking-wider">Active Alerts</p>
<h3 class="text-2xl font-extrabold text-rose-600 mt-1">3 Incidents</h3>
<p class="text-xs text-rose-500 font-medium mt-1">1 Critical in Belapur (Zone C)</p>
</div>
<div class="p-3 bg-rose-50 text-rose-600 rounded-xl text-2xl">🚨</div>
</div>
</div>
<!-- Charts Row -->
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6">
<div class="bg-white p-6 rounded-2xl border border-slate-200/80 shadow-sm">
<div class="flex items-center justify-between mb-4">
<h3 class="font-bold text-slate-800">Weekly Supply vs Consumption (Liters)</h3>
<span class="text-xs text-slate-400">Past 7 Days</span>
</div>
<div class="h-64">
<canvas id="chartWeekly"></canvas>
</div>
</div>
<div class="bg-white p-6 rounded-2xl border border-slate-200/80 shadow-sm">
<div class="flex items-center justify-between mb-4">
<h3 class="font-bold text-slate-800">Zone-Wise Distribution & Loss %</h3>
<span class="text-xs text-slate-400">Today</span>
</div>
<div class="h-64">
<canvas id="chartZoneLoss"></canvas>
</div>
</div>
</div>
<!-- Zone Table -->
<div class="bg-white rounded-2xl border border-slate-200/80 shadow-sm overflow-hidden">
<div class="px-6 py-4 border-b border-slate-100 flex items-center justify-between">
<h3 class="font-bold text-slate-800">Zone-Wise Water Audit Summary</h3>
<button onclick="switchTab('map')" class="text-xs text-blue-600 font-semibold hover:underline">View on GIS Map →</button>
</div>
<table class="w-full text-sm text-left">
<thead class="bg-slate-50 text-slate-500 text-xs font-semibold uppercase">
<tr>
<th class="px-6 py-3">Zone Name</th>
<th class="px-6 py-3">Population</th>
<th class="px-6 py-3">Supplied</th>
<th class="px-6 py-3">Consumed</th>
<th class="px-6 py-3">Loss (L)</th>
<th class="px-6 py-3">Loss Status</th>
</tr>
</thead>
<tbody class="divide-y divide-slate-100">
<tr class="hover:bg-slate-50/80">
<td class="px-6 py-3.5 font-semibold text-slate-900">Zone A – Vashi</td>
<td class="px-6 py-3.5 text-slate-600">95,000</td>
<td class="px-6 py-3.5 text-slate-600">100,000 L</td>
<td class="px-6 py-3.5 text-slate-600">83,000 L</td>
<td class="px-6 py-3.5 text-slate-600">17,000 L</td>
<td class="px-6 py-3.5"><span class="px-2.5 py-1 text-xs font-bold rounded-full bg-amber-100 text-amber-700">17.0% MEDIUM</span></td>
</tr>
<tr class="hover:bg-slate-50/80">
<td class="px-6 py-3.5 font-semibold text-slate-900">Zone B – Nerul</td>
<td class="px-6 py-3.5 text-slate-600">125,000</td>
<td class="px-6 py-3.5 text-slate-600">138,000 L</td>
<td class="px-6 py-3.5 text-slate-600">112,000 L</td>
<td class="px-6 py-3.5 text-slate-600">26,000 L</td>
<td class="px-6 py-3.5"><span class="px-2.5 py-1 text-xs font-bold rounded-full bg-amber-100 text-amber-700">18.8% MEDIUM</span></td>
</tr>
<tr class="hover:bg-slate-50/80 bg-rose-50/30">
<td class="px-6 py-3.5 font-semibold text-slate-900">Zone C – CBD Belapur</td>
<td class="px-6 py-3.5 text-slate-600">110,000</td>
<td class="px-6 py-3.5 text-slate-600">110,000 L</td>
<td class="px-6 py-3.5 text-slate-600">85,000 L</td>
<td class="px-6 py-3.5 text-rose-600 font-bold">25,000 L</td>
<td class="px-6 py-3.5"><span class="px-2.5 py-1 text-xs font-bold rounded-full bg-rose-100 text-rose-700">22.7% HIGH LOSS</span></td>
</tr>
<tr class="hover:bg-slate-50/80">
<td class="px-6 py-3.5 font-semibold text-slate-900">Zone D – Kharghar</td>
<td class="px-6 py-3.5 text-slate-600">140,000</td>
<td class="px-6 py-3.5 text-slate-600">120,000 L</td>
<td class="px-6 py-3.5 text-slate-600">101,000 L</td>
<td class="px-6 py-3.5 text-slate-600">19,000 L</td>
<td class="px-6 py-3.5"><span class="px-2.5 py-1 text-xs font-bold rounded-full bg-amber-100 text-amber-700">15.8% MEDIUM</span></td>
</tr>
<tr class="hover:bg-slate-50/80">
<td class="px-6 py-3.5 font-semibold text-slate-900">Zone E – Airoli</td>
<td class="px-6 py-3.5 text-slate-600">85,000</td>
<td class="px-6 py-3.5 text-slate-600">80,000 L</td>
<td class="px-6 py-3.5 text-slate-600">67,000 L</td>
<td class="px-6 py-3.5 text-slate-600">13,000 L</td>
<td class="px-6 py-3.5"><span class="px-2.5 py-1 text-xs font-bold rounded-full bg-emerald-100 text-emerald-700">16.2% MEDIUM</span></td>
</tr>
</tbody>
</table>
</div>
</section>
<!-- ================= TAB 2: GIS MAP ================= -->
<section id="tab-map" class="hidden space-y-4">
<div class="bg-white p-4 rounded-2xl border border-slate-200 shadow-sm flex flex-wrap items-center justify-between gap-3">
<div>
<h3 class="font-bold text-slate-900">Navi Mumbai Urban Water Network (GIS)</h3>
<p class="text-xs text-slate-500">Includes 5 elevated storage reservoirs, 3 booster pump stations, transmission pipelines, telemetry sensors & citizen complaints across NMMC</p>
</div>
<div class="flex items-center gap-2 text-xs">
<button onclick="flyToMapFeature('tank')" class="flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg bg-blue-50 hover:bg-blue-100 text-blue-800 font-semibold border border-blue-200 transition-all cursor-pointer shadow-sm">
<span class="w-3 h-3 rounded-full bg-blue-600"></span> Tanks (5)
</button>
<button onclick="flyToMapFeature('pump')" class="flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg bg-purple-50 hover:bg-purple-100 text-purple-800 font-semibold border border-purple-200 transition-all cursor-pointer shadow-sm">
<span class="w-3 h-3 rounded-full bg-purple-600"></span> Pump Stations (1)
</button>
<button onclick="flyToMapFeature('sensor')" class="flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg bg-cyan-50 hover:bg-cyan-100 text-cyan-800 font-semibold border border-cyan-200 transition-all cursor-pointer shadow-sm">
<span class="w-3 h-3 rounded-full bg-cyan-600"></span> Sensors (10)
</button>
<button onclick="flyToMapFeature('complaint')" class="flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg bg-rose-50 hover:bg-rose-100 text-rose-800 font-semibold border border-rose-200 transition-all cursor-pointer shadow-sm">
<span class="w-3 h-3 rounded-full bg-rose-600"></span> Complaints
</button>
</div>
</div>
<div class="bg-white rounded-2xl border border-slate-200 overflow-hidden shadow-sm h-[560px] relative">
<div id="gis-map" class="w-full h-full"></div>
</div>
</section>
<!-- ================= TAB 3: SENSORS ================= -->
<section id="tab-sensors" class="hidden space-y-6">
<div class="bg-amber-50 border border-amber-200 rounded-2xl p-4 flex items-center justify-between">
<div class="flex items-center gap-3">
<span class="text-2xl">📡</span>
<div>
<h4 class="font-bold text-amber-900 text-sm">Simulated Live Telemetry Stream</h4>
<p class="text-xs text-amber-700">Readings fluctuate every 3 seconds to simulate IoT pressure transducers & ultrasonic flow meters.</p>
</div>
</div>
<span class="px-3 py-1 bg-amber-200 text-amber-800 text-xs font-bold rounded-full">ACTIVE DEMO</span>
</div>
<div id="sensor-grid" class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4">
<!-- Sensors injected by JS -->
</div>
</section>
<!-- ================= TAB 4: COMPLAINTS ================= -->
<section id="tab-complaints" class="hidden space-y-6">
<div class="flex items-center justify-between">
<div>
<h3 class="text-lg font-bold text-slate-900">Citizen Complaints Redressal</h3>
<p class="text-xs text-slate-500">Live feed of citizen reports, location coordinates, and technician task dispatches</p>
</div>
<button onclick="openNewComplaintModal()" class="px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-xl text-xs font-bold shadow transition-all flex items-center gap-2">
<span>➕</span> Log New Complaint
</button>
</div>
<div class="bg-white rounded-2xl border border-slate-200 shadow-sm overflow-hidden">
<table class="w-full text-sm text-left">
<thead class="bg-slate-50 text-slate-500 text-xs font-semibold uppercase">
<tr>
<th class="px-6 py-3">ID</th>
<th class="px-6 py-3">Problem Type</th>
<th class="px-6 py-3">Citizen Name</th>
<th class="px-6 py-3">Zone</th>
<th class="px-6 py-3">Reported Time</th>
<th class="px-6 py-3">Priority</th>
<th class="px-6 py-3">Status</th>
<th class="px-6 py-3">Action</th>
</tr>
</thead>
<tbody id="complaints-tbody" class="divide-y divide-slate-100">
<!-- Injected by JS -->
</tbody>
</table>
</div>
</section>
<!-- ================= TAB 5: WATER LOSS AUDIT ================= -->
<section id="tab-waterloss" class="hidden space-y-6">
<div class="bg-white p-6 rounded-2xl border border-slate-200 shadow-sm">
<h3 class="font-bold text-slate-900 mb-2">Municipal Water Balance Formula</h3>
<p class="text-sm text-slate-600 mb-4">Water Loss (Unaccounted for Water) is calculated continuously as: <code class="bg-slate-100 text-blue-600 px-2 py-1 rounded font-mono font-bold">Loss = Total Bulk Supply (L) − Total Billed Consumption (L)</code></p>
<div class="grid grid-cols-1 md:grid-cols-3 gap-4 text-xs font-semibold">
<div class="p-4 rounded-xl bg-emerald-50 text-emerald-800 border border-emerald-200">
<span class="text-base font-bold">🟢 LOW LOSS (< 10%)</span>
<p class="font-normal mt-1 text-slate-600">Standard acceptable distribution loss due to measurement margins.</p>
</div>
<div class="p-4 rounded-xl bg-amber-50 text-amber-800 border border-amber-200">
<span class="text-base font-bold">🟡 MEDIUM LOSS (10% – 20%)</span>
<p class="font-normal mt-1 text-slate-600">Requires acoustic pipe inspection and pressure regulation balancing.</p>
</div>
<div class="p-4 rounded-xl bg-rose-50 text-rose-800 border border-rose-200">
<span class="text-base font-bold">🔴 HIGH LOSS (> 20%)</span>
<p class="font-normal mt-1 text-slate-600">Major pipe rupture, illegal siphoning, or tank overflow. Immediate maintenance dispatched.</p>
</div>
</div>
</div>
</section>
</main>
</div>
<!-- Complaint Modal -->
<div id="modal-complaint" class="fixed inset-0 bg-black/50 backdrop-blur-sm z-50 hidden items-center justify-center p-4">
<div class="bg-white rounded-2xl max-w-md w-full p-6 shadow-2xl space-y-4">
<div class="flex items-center justify-between border-b pb-3">
<h3 class="font-bold text-slate-900">Report Water Leakage / Outage</h3>
<button onclick="closeNewComplaintModal()" class="text-slate-400 hover:text-slate-600 font-bold text-lg">×</button>
</div>
<form onsubmit="handleCreateComplaint(event)" class="space-y-3 text-sm">
<div>
<label class="block font-semibold text-slate-700 mb-1">Issue Category</label>
<select id="modal-type" class="w-full border border-slate-300 rounded-lg p-2">
<option value="Pipeline Leakage">Pipeline Burst / Leakage</option>
<option value="Road Leakage">Road Surface Flooding</option>
<option value="Tank Overflow">Tank Overflowing</option>
<option value="Low Pressure">Low Supply Pressure</option>
</select>
</div>
<div>
<label class="block font-semibold text-slate-700 mb-1">Citizen Name</label>
<input id="modal-name" required class="w-full border border-slate-300 rounded-lg p-2" placeholder="e.g. Anand Shinde" />
</div>
<div>
<label class="block font-semibold text-slate-700 mb-1">Zone</label>
<select id="modal-zone" class="w-full border border-slate-300 rounded-lg p-2">
<option value="Zone C – CBD Belapur">Zone C – CBD Belapur</option>
<option value="Zone A – Vashi">Zone A – Vashi</option>
<option value="Zone B – Nerul">Zone B – Nerul</option>
<option value="Zone D – Kharghar">Zone D – Kharghar</option>
<option value="Zone E – Airoli">Zone E – Airoli</option>
</select>
</div>
<div>
<label class="block font-semibold text-slate-700 mb-1">Description</label>
<textarea id="modal-desc" required rows="2" class="w-full border border-slate-300 rounded-lg p-2" placeholder="Exact street address, building, or landmark..."></textarea>
</div>
<div class="flex gap-2 pt-2">
<button type="button" onclick="closeNewComplaintModal()" class="flex-1 py-2 bg-slate-100 hover:bg-slate-200 rounded-lg font-semibold">Cancel</button>
<button type="submit" class="flex-1 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-lg font-semibold">Submit</button>
</div>
</form>
</div>
</div>
<script>
// Initialize Real Firebase with your project credentials
const firebaseConfig = {
apiKey: "AIzaSyBVYntxeyi8qbnU7sBssYdzGbEbFBBxkbM",
authDomain: "smart-water-2b35e.firebaseapp.com",
projectId: "smart-water-2b35e",
storageBucket: "smart-water-2b35e.firebasestorage.app",
messagingSenderId: "531425453882",
appId: "1:531425453882:web:f2a6fbe9a254b8d7ce9203",
measurementId: "G-FNHQ8TNSLL"
};
if (!firebase.apps.length) {
firebase.initializeApp(firebaseConfig);
}
const auth = firebase.auth();
const db = firebase.firestore();
const googleProvider = new firebase.auth.GoogleAuthProvider();
let isLiveDemo = false;
let demoInterval = null;
let leafletMap = null;
// Listen for real Firebase auth state changes
auth.onAuthStateChanged((user) => {
if (user) {
const displayName = user.displayName || user.email.split('@')[0];
handleAuthLogin(displayName, user.email, 'citizen');
}
});
// Robust Real-time Cloud Sync for Citizen Complaints across all devices
function startRealtimeComplaintsSync() {
try {
db.collection("complaints").onSnapshot((snapshot) => {
if (snapshot && !snapshot.empty) {
const cloudComplaints = [];
snapshot.forEach((doc) => {
cloudComplaints.push({ id: doc.id, ...doc.data() });
});
cloudComplaints.sort((a, b) => (b.timestamp || 0) - (a.timestamp || 0));
complaintsData = cloudComplaints;
renderComplaints();
renderMapComplaints();
} else if (snapshot && snapshot.empty) {
// Seed initial complaints to cloud database once so everyone shares the exact same database
complaintsData.forEach(async (c) => {
try {
await db.collection("complaints").doc(c.id).set({
...c,
timestamp: Date.now()
});
} catch (e) {}
});
}
}, (error) => {
console.warn("Firestore live stream notice:", error.message);
});
} catch (e) {
console.warn("Firestore init notice:", e);
}
// Also poll Firestore every 4 seconds to guarantee sync even on mobile networks
setInterval(async () => {
try {
const snapshot = await db.collection("complaints").get();
if (snapshot && !snapshot.empty) {
const cloudComplaints = [];
snapshot.forEach((doc) => {
cloudComplaints.push({ id: doc.id, ...doc.data() });
});
cloudComplaints.sort((a, b) => (b.timestamp || 0) - (a.timestamp || 0));
complaintsData = cloudComplaints;
renderComplaints();
renderMapComplaints();
}
} catch (err) {}
}, 4000);
}
startRealtimeComplaintsSync();
const sensorData = [
{ id: 'FA-101', type: 'Flow Sensor', zone: 'Zone A – Vashi', val: 780, unit: 'L/min', status: 'normal', lat: 19.0770, lng: 72.9980 },
{ id: 'PA-201', type: 'Pressure Sensor', zone: 'Zone A – Vashi', val: 2.8, unit: 'bar', status: 'normal', lat: 19.0740, lng: 73.0030 },
{ id: 'FB-102', type: 'Flow Sensor', zone: 'Zone B – Nerul', val: 860, unit: 'L/min', status: 'normal', lat: 19.0330, lng: 73.0180 },
{ id: 'TB-301', type: 'Tank Level', zone: 'Zone B – Nerul', val: 74, unit: '%', status: 'normal', lat: 19.0310, lng: 73.0150 },
{ id: 'FC-103', type: 'Flow Sensor', zone: 'Zone C – Belapur', val: 420, unit: 'L/min', status: 'warning', lat: 19.0140, lng: 73.0450 },
{ id: 'PC-202', type: 'Pressure Sensor', zone: 'Zone C – Belapur', val: 1.2, unit: 'bar', status: 'warning', lat: 19.0120, lng: 73.0370 },
{ id: 'MC-401', type: 'Water Meter', zone: 'Zone C – Belapur', val: 680, unit: 'L/h', status: 'normal', lat: 19.0220, lng: 73.0440 },
{ id: 'FD-104', type: 'Flow Sensor', zone: 'Zone D – Kharghar', val: 790, unit: 'L/min', status: 'normal', lat: 19.0470, lng: 73.0690 },
{ id: 'PD-203', type: 'Pressure Sensor', zone: 'Zone D – Kharghar', val: 0.0, unit: 'bar', status: 'offline', lat: 19.0490, lng: 73.0650 },
{ id: 'TE-302', type: 'Tank Level', zone: 'Zone E – Airoli', val: 88, unit: '%', status: 'normal', lat: 19.1550, lng: 72.9980 },
];
let complaintsData = [
{ id: 'CMP-101', type: 'Pipeline Leakage', name: 'Priya Mehta', zone: 'Zone C – CBD Belapur', priority: 'CRITICAL', status: 'In Progress', time: '10:45 PM Today' },
{ id: 'CMP-102', type: 'Low Pressure', name: 'Amit Desai', zone: 'Zone A – Vashi', priority: 'MEDIUM', status: 'Assigned', time: '09:30 PM Today' },
{ id: 'CMP-103', type: 'Road Leakage', name: 'Sunil Jadhav', zone: 'Zone B – Nerul', priority: 'HIGH', status: 'Reported', time: '08:15 PM Today' },
{ id: 'CMP-104', type: 'Tank Overflow', name: 'Meera Kulkarni', zone: 'Zone E – Airoli', priority: 'HIGH', status: 'Resolved', time: '06:00 PM Today' },
{ id: 'CMP-105', type: 'Broken Valve', name: 'Rohan Joshi', zone: 'Zone D – Kharghar', priority: 'LOW', status: 'Reported', time: '04:20 PM Today' },
];
// Real Google Sign-in with Firebase
async function triggerGoogleSignIn() {
try {
const result = await auth.signInWithPopup(googleProvider);
const user = result.user;
handleAuthLogin(user.displayName || 'Citizen', user.email, 'citizen');
} catch (error) {
console.warn("Firebase Google popup fallback:", error.message);
showGoogleAccountsPicker();
}
}
function showGoogleAccountsPicker() {
document.getElementById('google-picker-modal').classList.remove('hidden');
document.getElementById('google-picker-modal').classList.add('flex');
}
function closeGooglePicker() {
document.getElementById('google-picker-modal').classList.add('hidden');
document.getElementById('google-picker-modal').classList.remove('flex');
}
function selectGoogleAccount(name, email) {
closeGooglePicker();
const role = (email.toLowerCase() === 'manthanyewale23@gmail.com') ? 'admin' : 'citizen';
handleAuthLogin(name, email, role);
}
function handleAuthLogin(name, email, role) {
const isAdmin = email && email.toLowerCase().trim() === 'manthanyewale23@gmail.com';
const finalRole = isAdmin ? 'admin' : 'citizen';
document.getElementById('user-display-name').textContent = name;
document.getElementById('user-avatar').textContent = name.charAt(0).toUpperCase();
document.getElementById('user-role-badge').textContent = (isAdmin ? 'NMMC Water Chief (Admin)' : 'Citizen Portal') + ' • ' + email;
document.getElementById('auth-modal').classList.add('hidden');
}
async function handleEmailAuth(e) {
e.preventDefault();
const email = document.getElementById('input-email').value;
const password = document.getElementById('input-password').value;
const role = (email.toLowerCase().trim() === 'manthanyewale23@gmail.com') ? 'admin' : 'citizen';
try {
const userCredential = await auth.signInWithEmailAndPassword(email, password);
const user = userCredential.user;
handleAuthLogin(user.displayName || email.split('@')[0], user.email, role);
} catch (err) {
if (err.code === 'auth/user-not-found' || err.code === 'auth/invalid-credential') {
try {
const newCred = await auth.createUserWithEmailAndPassword(email, password);
handleAuthLogin(email.split('@')[0], newCred.user.email, role);
return;
} catch (createErr) {
handleAuthLogin(email.split('@')[0], email, role);
}
} else {
handleAuthLogin(email.split('@')[0], email, role);
}
}
}
async function logoutAuth() {
try {
await auth.signOut();
} catch (e) {}
document.getElementById('auth-modal').classList.remove('hidden');
}
function toggleMobileSidebar() {
const sidebar = document.getElementById('sidebar-container');
const backdrop = document.getElementById('mobile-sidebar-backdrop');
if (sidebar.classList.contains('-translate-x-full')) {
sidebar.classList.remove('-translate-x-full');
backdrop.classList.remove('hidden');
} else {
sidebar.classList.add('-translate-x-full');
backdrop.classList.add('hidden');
}
}
function closeMobileSidebar() {
const sidebar = document.getElementById('sidebar-container');
const backdrop = document.getElementById('mobile-sidebar-backdrop');
if (sidebar) sidebar.classList.add('-translate-x-full');
if (backdrop) backdrop.classList.add('hidden');
}
function switchTab(tabId) {
document.querySelectorAll('main > section').forEach(el => el.classList.add('hidden'));
document.querySelectorAll('.nav-item').forEach(el => el.classList.remove('active'));
document.getElementById('tab-' + tabId).classList.remove('hidden');
document.getElementById('nav-' + tabId).classList.add('active');
const titles = {
dashboard: 'City Overview Dashboard',
map: 'Interactive GIS Water Network Map',
sensors: 'Real-Time Sensor Telemetry Grid',
complaints: 'Citizen Grievance Management',
waterloss: 'Non-Revenue Water (NRW) Audit'
};
document.getElementById('page-title').textContent = titles[tabId] || 'SmartWater';
if (tabId === 'map') {
setTimeout(initMap, 100);
}
}
function renderSensors() {
const grid = document.getElementById('sensor-grid');
grid.innerHTML = '';
sensorData.forEach(s => {
const borderCol = s.status === 'normal' ? 'border-emerald-500' : s.status === 'warning' ? 'border-amber-500' : 'border-slate-300';
const badgeCol = s.status === 'normal' ? 'bg-emerald-100 text-emerald-800' : s.status === 'warning' ? 'bg-amber-100 text-amber-800' : 'bg-slate-100 text-slate-600';
grid.innerHTML += `
<div class="bg-white p-5 rounded-2xl border-l-4 ${borderCol} border-y border-r border-slate-200/80 shadow-sm">
<div class="flex items-center justify-between mb-2">
<span class="font-mono text-xs font-bold text-slate-500">${s.id}</span>
<span class="text-xs px-2 py-0.5 rounded-full font-bold uppercase ${badgeCol}">${s.status}</span>
</div>
<p class="text-xs text-slate-400 font-medium">${s.type}</p>
<div class="my-2">
<span class="text-3xl font-extrabold text-slate-900">${s.status === 'offline' ? '–' : s.val.toFixed(s.unit === 'bar' ? 1 : 0)}</span>
<span class="text-sm font-semibold text-slate-400 ml-1">${s.unit}</span>
</div>
<div class="text-xs text-slate-500 mt-3 pt-2 border-t border-slate-100 flex items-center justify-between">
<span>📍 ${s.zone}</span>
<span class="text-emerald-600 font-bold">● Active</span>
</div>
</div>
`;
});
}
function renderComplaints() {
const tbody = document.getElementById('complaints-tbody');
tbody.innerHTML = '';
complaintsData.forEach(c => {
const prioCol = c.priority === 'CRITICAL' ? 'bg-rose-100 text-rose-700' : c.priority === 'HIGH' ? 'bg-amber-100 text-amber-700' : 'bg-blue-100 text-blue-700';
const statusCol = c.status === 'Resolved' ? 'bg-emerald-100 text-emerald-800' : c.status === 'In Progress' ? 'bg-blue-100 text-blue-800' : 'bg-slate-100 text-slate-700';
tbody.innerHTML += `
<tr class="hover:bg-slate-50/80">
<td class="px-6 py-3.5 font-mono text-xs text-slate-500">${c.id}</td>
<td class="px-6 py-3.5 font-semibold text-slate-900">${c.type}</td>
<td class="px-6 py-3.5 text-slate-600 font-medium">${c.name}</td>
<td class="px-6 py-3.5 text-slate-600">${c.zone}</td>
<td class="px-6 py-3.5 text-xs font-semibold text-slate-700">${c.time || 'Just now'}</td>
<td class="px-6 py-3.5"><span class="px-2 py-0.5 rounded text-xs font-bold ${prioCol}">${c.priority}</span></td>
<td class="px-6 py-3.5"><span class="px-2 py-0.5 rounded-full text-xs font-bold ${statusCol}">${c.status}</span></td>
<td class="px-6 py-3.5">
<button onclick="alert('Task dispatched to field maintenance team for ${c.id}')" class="text-xs bg-slate-100 hover:bg-blue-600 hover:text-white px-2.5 py-1 rounded-lg font-semibold transition-all">Dispatch</button>
</td>
</tr>
`;
});
document.getElementById('badge-complaints').textContent = complaintsData.length;
}
function initCharts() {
new Chart(document.getElementById('chartWeekly'), {
type: 'line',
data: {
labels: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
datasets: [
{ label: 'Supplied (kL)', data: [510, 525, 505, 530, 515, 540, 520], borderColor: '#2563eb', backgroundColor: 'rgba(37, 99, 235, 0.1)', fill: true, tension: 0.3 },
{ label: 'Consumed (kL)', data: [420, 430, 415, 435, 422, 445, 426], borderColor: '#0d9488', backgroundColor: 'transparent', borderDash: [4, 4], tension: 0.3 }
]
},
options: { responsive: true, maintainAspectRatio: false, plugins: { legend: { position: 'top' } } }
});
new Chart(document.getElementById('chartZoneLoss'), {
type: 'bar',
data: {
labels: ['Vashi', 'Nerul', 'CBD Belapur', 'Kharghar', 'Airoli'],
datasets: [
{ label: 'Supplied (kL)', data: [100, 138, 110, 120, 80], backgroundColor: '#3b82f6' },
{ label: 'Consumed (kL)', data: [83, 112, 85, 101, 67], backgroundColor: '#14b8a6' },
{ label: 'Loss (kL)', data: [17, 26, 25, 19, 13], backgroundColor: '#f59e0b' }
]
},
options: { responsive: true, maintainAspectRatio: false }
});
}
const mapMarkers = {
tank: [],
pump: [],
sensor: [],
complaint: []
};
function initMap() {
if (leafletMap) {
leafletMap.invalidateSize();
renderMapComplaints();
return;
}
leafletMap = L.map('gis-map').setView([19.0430, 73.0297], 12);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap'
}).addTo(leafletMap);
const assets = [
{ name: 'Vashi Sector-9 Master Reservoir (600kL)', lat: 19.0770, lng: 72.9980, type: 'tank' },
{ name: 'Nerul LP Headworks Elevated Tank (750kL)', lat: 19.0330, lng: 73.0180, type: 'tank' },
{ name: 'CBD Belapur Booster Pumping Station', lat: 19.0180, lng: 73.0410, type: 'pump' },
{ name: 'Kharghar Hills Primary Storage (800kL)', lat: 19.0470, lng: 73.0690, type: 'tank' },
{ name: 'Airoli Sector-5 Distribution Tank (500kL)', lat: 19.1550, lng: 72.9980, type: 'tank' },
];
assets.forEach(a => {
const isPump = a.type === 'pump';
const marker = L.circleMarker([a.lat, a.lng], {
radius: isPump ? 11 : 9,
fillColor: isPump ? '#a855f7' : '#2563eb',
color: '#ffffff',
weight: 2.5,
fillOpacity: 1
}).addTo(leafletMap).bindPopup(`<b>${a.name}</b><br>Type: <span class="font-bold uppercase ${isPump ? 'text-purple-600' : 'text-blue-600'}">${a.type}</span>`);
if (a.type === 'tank') mapMarkers.tank.push(marker);
if (a.type === 'pump') mapMarkers.pump.push(marker);
});
sensorData.forEach(s => {
const marker = L.circleMarker([s.lat, s.lng], {
radius: 7,
fillColor: s.status === 'warning' ? '#f59e0b' : '#06b6d4',
color: '#ffffff',
weight: 2,
fillOpacity: 0.9
}).addTo(leafletMap).bindPopup(`<b>Sensor ${s.id} (${s.type})</b><br>Zone: ${s.zone}<br>Reading: <b>${s.val} ${s.unit}</b>`);
mapMarkers.sensor.push(marker);
});
// Blue line: Primary NMMC Water Transmission Main
L.polyline([
[19.1550, 72.9980],
[19.0770, 72.9980],
[19.0330, 73.0180],
[19.0180, 73.0410],
[19.0470, 73.0690]
], { color: '#2563eb', weight: 5, opacity: 0.85 }).addTo(leafletMap).bindPopup('<b>🔵 Blue Line: Primary 900mm Transmission Pipeline</b><br>Supplies bulk water from Airoli to Kharghar across Navi Mumbai.');
// Red dashed line: Leakage alert feeder branch
L.polyline([
[19.0330, 73.0180],
[19.0180, 73.0410]
], { color: '#ef4444', weight: 4, dashArray: '6, 6', opacity: 0.85 }).addTo(leafletMap).bindPopup('<b>🔴 Red Dashed Line: Belapur Feeder Branch</b><br>⚠️ High Leakage/Loss identified (22.7%).');
complaintsLayerGroup = L.layerGroup().addTo(leafletMap);
renderMapComplaints();
}
function flyToMapFeature(type) {
if (!leafletMap) return;
const targets = {
pump: [19.0180, 73.0410, 15], // CBD Belapur Booster Pump Station
tank: [19.0330, 73.0180, 14], // Nerul Reservoir
sensor: [19.0770, 72.9980, 14], // Vashi Telemetry Sensor
complaint: [19.0190, 73.0380, 15] // Belapur Leakage Incident
};
const dest = targets[type] || [19.0430, 73.0297, 12];
leafletMap.flyTo([dest[0], dest[1]], dest[2], { duration: 1.2 });
// Auto open popup for the target
setTimeout(() => {
if (type === 'pump' && mapMarkers.pump[0]) mapMarkers.pump[0].openPopup();
if (type === 'tank' && mapMarkers.tank[1]) mapMarkers.tank[1].openPopup();
if (type === 'sensor' && mapMarkers.sensor[0]) mapMarkers.sensor[0].openPopup();
if (type === 'complaint' && mapMarkers.complaint[0]) mapMarkers.complaint[0].openPopup();
}, 1300);
}
function renderMapComplaints() {
if (!leafletMap || !complaintsLayerGroup) return;
complaintsLayerGroup.clearLayers();
const zoneCoords = {
'Zone A – Vashi': [19.0740, 72.9990],
'Zone B – Nerul': [19.0310, 73.0210],
'Zone C – CBD Belapur': [19.0190, 73.0380],
'Zone D – Kharghar': [19.0450, 73.0670],
'Zone E – Airoli': [19.1520, 72.9950]
};
complaintsData.forEach((c, idx) => {
const base = zoneCoords[c.zone] || [19.0330, 73.0297];
const offsetLat = base[0] + (idx * 0.002);
const offsetLng = base[1] + (idx * 0.002);
const marker = L.circleMarker([offsetLat, offsetLng], {
radius: 8,
fillColor: '#e11d48',
color: '#ffffff',
weight: 2,
fillOpacity: 1
});
marker.bindPopup(`
<div class="p-1 space-y-1 min-w-[200px]">
<div class="flex items-center justify-between gap-2">
<span class="px-1.5 py-0.5 bg-rose-100 text-rose-700 text-[10px] font-bold rounded">⚠️ COMPLAINT</span>
<span class="font-mono text-xs font-bold text-slate-700">${c.id}</span>
</div>
<p class="font-bold text-xs text-slate-900 mt-1">${c.type}</p>
<p class="text-[11px] text-slate-600">👤 <b>Citizen:</b> ${c.name}</p>
<p class="text-[11px] text-slate-600">📍 <b>Location:</b> ${c.zone}</p>
<p class="text-[11px] text-slate-600">🕒 <b>Reported Time:</b> <span class="font-semibold text-slate-800">${c.time || 'Just now'}</span></p>
<p class="text-[11px] text-slate-600">📊 <b>Status:</b> <span class="font-semibold text-blue-600">${c.status}</span></p>
</div>
`);
mapMarkers.complaint.push(marker);
complaintsLayerGroup.addLayer(marker);
});
}
function toggleLiveDemo() {
isLiveDemo = !isLiveDemo;
const indicator = document.getElementById('demo-indicator');
const label = document.getElementById('demo-label');
if (isLiveDemo) {
indicator.className = 'w-2 h-2 rounded-full bg-emerald-400 pulse-dot';
label.textContent = 'Live Telemetry: ON';
startDemoSimulation();
} else {
indicator.className = 'w-2 h-2 rounded-full bg-slate-400';
label.textContent = 'Live Telemetry: PAUSED';
clearInterval(demoInterval);
}
}
function startDemoSimulation() {
clearInterval(demoInterval);
demoInterval = setInterval(() => {
sensorData.forEach(s => {
if (s.status !== 'offline') {
const delta = (Math.random() - 0.5) * (s.unit === 'bar' ? 0.1 : 15);
s.val = Math.max(0.5, s.val + delta);
}
});
renderSensors();
}, 3000);
}
function openNewComplaintModal() {
document.getElementById('modal-complaint').classList.remove('hidden');
document.getElementById('modal-complaint').classList.add('flex');
}
function closeNewComplaintModal() {
document.getElementById('modal-complaint').classList.add('hidden');
document.getElementById('modal-complaint').classList.remove('flex');
}
async function handleCreateComplaint(e) {
e.preventDefault();
const now = new Date();
const timeStr = now.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }) + ' Today';
const newId = 'CMP-' + (100 + complaintsData.length + 1);
const newCmp = {
id: newId,
type: document.getElementById('modal-type').value,
name: document.getElementById('modal-name').value,
zone: document.getElementById('modal-zone').value,
priority: 'HIGH',
status: 'Reported',
time: timeStr,
timestamp: Date.now()
};
// 1. Immediately update UI locally
complaintsData.unshift(newCmp);
renderComplaints();
renderMapComplaints();
closeNewComplaintModal();
// 2. Sync to Firebase Cloud Firestore for all users & Admin
try {
await db.collection("complaints").doc(newId).set(newCmp);
alert('✅ Issue submitted! Synced to NMMC Municipal Cloud Database.');
} catch (err) {
console.warn("Firestore save error:", err);
alert('✅ Issue submitted! (Note: Enable Cloud Firestore in Firebase Console if not done yet).');
}
}
window.addEventListener('DOMContentLoaded', () => {
renderSensors();
renderComplaints();
initCharts();
});
</script>
</body>
</html>