-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
259 lines (237 loc) · 8.68 KB
/
index.html
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
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
<title>CoWIN | Vaccination Finder</title>
</head>
<body>
<div class="container">
<nav class="navbar navbar-expand-lg navbar-light bg-light fixed-top">
<a class="navbar-brand" href="#"><strong>Vaccination Centers:</strong> 18 - 44 years</a>
<div class="d-flex justify-content-center" id="main-loader">
<div class="spinner-border text-dark" role="status">
<span class="sr-only">Loading...</span>
</div>
</div>
<ul class="navbar-nav ml-auto">
<a class="btn btn-link" href="https://selfregistration.cowin.gov.in/" target="_blank">Go to CoWIN!!</a>
</ul>
</nav>
</div>
<div class="container mt-2">
<div class="row">
<div class="col-12 mt-5">
<div class="accordion" id="states">
</div>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-Piv4xVNRyMGpqkS2by6br4gNJ7DXjqk09RmUpJ8jgGtD7zP9yug3goQfGII0yAns" crossorigin="anonymous"></script>
<script type="text/javascript">
class State{
constructor(id, name){
this.id = id;
this.name = name;
this.districts = [];
this.lastUpdated = 0;
}
addDistrict(district){
this.districts.push(district.id);
}
}
class District{
constructor(id, name, stateId){
this.id = id;
this.name = name;
this.stateId = stateId;
this.centers = []
this.totalSessions = 0;
this.lastUpdated = 0;
}
addCenter(center){
this.centers.push(center.id);
}
increaseTotalSessions(){
this.totalSessions++;
}
decreaseTotalSessions(){
this.totalSessions--;
}
}
class Center{
constructor(id, name, feeType, districtId){
this.id = id;
this.name = name;
this.feeType = feeType;
this.districtId = districtId;
this.sessions = [];
}
addSession(session){
this.sessions.push(session.id);
}
}
class Session{
constructor(id, date, ageLimit, vaccine, capacity, isShowing, centerId){
this.id = id;
this.date = date;
this.ageLimit = ageLimit;
this.vaccine = vaccine;
this.capacity = capacity;
this.centerId = centerId;
this.isShowing = isShowing;
}
}
var strictly18 = true;
var states = {};
var districts = {};
var centers = {};
var sessions = {};
function addState(state){
htmlContent = `
<div class="card">
<div class="card-header" id="state-`+state.id+`">
<h2 class="mb-0">
<button class="btn btn-link state-toggle" type="button" data-toggle="collapse" data-target="#state-collapse-`+state.id+`" aria-expanded="true" aria-controls="state-collapse-`+state.id+`" state-id="`+state.id+`">
`+ state.name +`
</button>
</h2>
</div>
<div id="state-collapse-`+state.id+`" class="collapse" aria-labelledby="state-`+state.id+` " data-parent="#states">
<div class="card-body" id="state-`+state.id+`-districts" last-updated="0">
</div>
</div>
</div>
</div>
`
$('#states').append(htmlContent);
}
function addDistrict(state,district){
htmlContent = `
<div class="card district-card">
<div class="card-header" id="district-`+district.id+`">
<span class="mb-0">
<button class="btn btn-link district-toggle" type="button" data-toggle="collapse" data-target="#district-collapse-`+district.id+`" aria-expanded="true" aria-controls="district-collapse-`+district.id+`" district-id="`+district.id+`">
`+ district.name +`
</button>
</span>
<span class="float-right session-count">Sessions: `+ district.totalSessions +`</span>
</div>
<div id="district-collapse-`+district.id+`" class="collapse" aria-labelledby="district-`+district.id+`" data-parent="#state-`+state.id+`-districts">
<div class="card-body">
<div class="table-responsive">
<div class="text-center text-danger w-100 not-available">Sorry, No centers are available for Vaccination. Please try again later.</div>
<table class="table table-hover table-striped d-none">
<thead class="thead-dark">
<tr>
<th scope="col">Name</th>
<th scope="col">Date</th>
<th scope="col">Capacity</th>
<th scope="col">Age limit</th>
<th scope="col">Vaccine</th>
<th scope="col">Fee</th>
</tr>
</thead>
<tbody id="district-`+district.id+`-centers" last-updated="0">
</tbody>
</table>
</div>
</div>
</div>
</div>
`
$('#state-'+state.id+'-districts').append(htmlContent);
}
function addCenter(district, center){
let htmlContent = '';
if(center.sessions.length > 0){
$('#district-'+center.districtId+'-centers').parents('.table-responsive').find('.not-available').hide();
$('#district-'+center.districtId+'-centers').parents('.table').removeClass('d-none');
}
center.sessions.forEach( sessionId => {
session = sessions[sessionId];
if(session.isShowing){
htmlContent += '<tr class="age-'+session.ageLimit+'" session-id="'+session.id+'">';
}
else{
htmlContent += '<tr class="d-none age-'+session.ageLimit+'" session-id="'+session.id+'">';
}
htmlContent += `
<td><strong>`+center.name+`</strong></td>`;
htmlContent += `<td>`+session.date+`</td>
<td>`+session.capacity+`</td>
<td>`+session.ageLimit+`</td>
<td>`+session.vaccine+`</td>
<td>`+center.feeType+`</td>
</tr>`;
});
$('#district-'+ district.id + '-centers').append(htmlContent);
}
function updateDistrict(districtObj){
let show18 = $('#only-18').is(':checked');
let timestamp = new Date();
let date = timestamp.getDate() + "-" + (timestamp.getMonth() + 1) + "-" + timestamp.getFullYear();
let requestString = `https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/calendarByDistrict?district_id=`+districtObj.id+`&date=`+date;
if(Date.now() - districtObj.lastUpdated > 10000){
$("#main-loader .spinner-border").show();
districts[districtObj.id] = districtObj;
districtObj.totalSessions = 0;
districtObj.lastUpdated = Date.now();
$('#district-'+ districtObj.id + '-centers').html('');
$.get(requestString, function( data ) {
$("#main-loader .spinner-border").hide();
data['centers'].forEach((center) => {
let centerObj = new Center(center['center_id'], center['name'], center['fee_type'], districtObj.id);
centers[centerObj.id] = centerObj;
center['sessions'] = center['sessions'].filter(session => (session['available_capacity'] > 0 && (!strictly18 || session['min_age_limit'] == 18)));
districtObj.totalSessions += center['sessions'].length;
$('#district-' + districtObj.id + ' .session-count').html('Sessions: ' + districtObj.totalSessions);
center['sessions'].forEach(session => {
let isShowing = (!show18 || session['min_age_limit'] == 18);
let sessionObj = new Session(session['session_id'], session['date'], session['min_age_limit'], session['vaccine'], session['available_capacity'], isShowing, centerObj.id);
sessions[sessionObj.id] = sessionObj;
centerObj.addSession(sessionObj);
});
addCenter(districtObj, centerObj);
});
});
}
}
$( document ).ready(function() {
$.get( "https://cdn-api.co-vin.in/api/v2/admin/location/states", function( data ) {
$("#main-loader .spinner-border").hide();
data['states'].forEach(state => {
let stateObj = new State(state['state_id'], state['state_name']);
states[stateObj.id] = stateObj;
addState(stateObj);
});
});
$(document).on('click', '.state-toggle', function(e){
let state_id = $(this).attr('state-id');
let state = states[state_id];
if(Date.now() - state.lastUpdated > 10000){
$("#main-loader .spinner-border").show();
state.lastUpdated = Date.now();
$('#state-'+state.id+'-districts').html('');
state.districts = []
$.get( "https://cdn-api.co-vin.in/api/v2/admin/location/districts/"+state.id, function( data ) {
data['districts'].forEach(district => {
let districtObj = new District(district['district_id'], district['district_name'], state.id);
addDistrict(state, districtObj);
updateDistrict(districtObj);
});
$("#main-loader .spinner-border").hide();
});
}
});
$(document).on('click', '.district-toggle', function(e){
let districtObj = districts[$(this).attr('district-id')];
updateDistrict(districtObj);
});
});
</script>
</body>
</html>