-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
225 lines (203 loc) · 6.29 KB
/
main.js
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
var api_key = "AIzaSyBX9nWaFWJ86YDMgm4gCGtsyoC4joY17mg";
var spreadsheet_id = "1O3v5jAmt_8JUyyK2NT_h33bFraTcYPHjmtD5Lkuk6VE";
var sheet1_name = "mumbaivaccinationcenters";
var sheet1_range = "A2:Y932";
var sheet2_name = "infoo";
var sheet2_range = "A1:D7";
$(document).ready(function () {
// Hide Search
$(document).on("preInit.dt", function (e, settings) {
$("#data-table_filter").hide();
});
var groupColumn = 1; // Grouping Ward
var table = $("#data-table").DataTable({
ajax: {
url:
"https://sheets.googleapis.com/v4/spreadsheets/" +
spreadsheet_id +
"/values/" +
sheet1_name +
"!" +
sheet1_range +
"?alt=json&key=" +
api_key,
dataSrc: "values",
},
searching: true, // Enable Search
// scrollY: '70vh', // Scrollable table fixed top - display vertical height
// scrollCollapse: true, // Scrollable table fixed top
paging: false, // Remove Paging
fixedHeader: true, // Sticky Header
ordering: true,
info: false, // Remove info "Data Page 1 of 100"
autoWidth: false,
columns: [
{
data: 0, // Sr No
searchable: false,
// className: "text-center col-1",
orderable: false,
visible: false,
},
{
data: 1, // Ward
searchable: false,
},
{
data: 2, // Location
searchable: true,
className: "col",
orderable: false,
},
{
data: 3, // Name of active vaccination centre
searchable: true,
className: "col",
orderable: false,
},
{
data: 4, // Facility Category
searchable: false,
className: "col-lg-1 text-center",
orderable: false,
},
{
data: 5, // Functional on (Date)?
searchable: false,
className: "col-lg-1 text-center status",
orderable: false,
},
{
data: 7, // Vaccine
searchable: false,
className: "col-lg-1",
orderable: false,
render: function (data, type, row) {
return '<span class="vaccine-text">' + data + "</span>";
},
},
{
data: 8, // Remarks
searchable: false,
className: "col",
orderable: false,
},
],
// Grouping Ward Starts //
columnDefs: [
{
visible: false,
targets: groupColumn,
},
],
// order: [[groupColumn, 'asc']],
rowGroup: {
dataSrc: 1,
className: "group text-center",
emptyDataGroup: null,
endRender: null,
startRender: function (rows, group) {
var count = 0;
rows.every(function () {
if (!$(this.node()).hasClass("d-none")) {
count++;
}
});
return count === 0
? $("<tr hidden />")
: $("<tr/>").append('<td colspan="6">Ward <span class="ward-name">' + group + "</span></td>");
},
},
// Grouping Ward Ends //
// Search Start //
initComplete: function () {
$("#data-table_filter").detach().appendTo("#search-area");
$("#data-table_filter").show();
},
language: {
search: "",
searchPlaceholder: "Search Location or Center Name...",
processing: true,
emptyTable: "No Data Available",
// zeroRecords: "No Data Available",
},
// Search End //
// Not Available = Yes, No, EMPTY, 18-44
createdRow: function (row, data, dataIndex) {
if (data[6] === "No") {
$(row).addClass("text-muted status-no d-none");
}
if (data[6] === "Stock Exhausted") {
$(row).addClass("status-exhausted");
}
if (data[6] === "") {
$(row).addClass("d-none");
}
if (data[6] === "18+") {
$(row).addClass("status-age18");
}
// Covishield, Covaxin and Both
if (data[7] === "Covishield") {
$("td", row).eq(4).addClass("vaccine-covishield");
}
if (data[7] === "Covaxin") {
$("td", row).eq(4).addClass("vaccine-covaxin");
}
if (data[7] === "Both") {
$("td", row).eq(4).addClass("vaccine-both");
}
},
});
});
// Location change of Search input
$(document).ready(function () {
$("#data-table").dataTable();
$("#data-table_filter input").removeClass("form-control-sm");
});
// Information Gathering from Google Sheet - Start
// ID of the Google Spreadsheet
// Google Sheets - URL
var url2 =
"https://sheets.googleapis.com/v4/spreadsheets/" +
spreadsheet_id +
"/values/" +
sheet2_name +
"!" +
sheet2_range +
"?alt=json&key=" +
api_key;
$.getJSON(url2, function (data) {
var sentry = data.values;
var centers_functional_status = document.getElementById("centers-functional-status");
for (var i = 1; i < 4; i++) {
if (data.values[1][i] !== "") {
centers_functional_status.innerHTML +=
'<ul class="centers-details"><li class="centers-details-item">' + data.values[1][i] + "</li></ul>";
}
}
$(sentry).each(function () {
var todays_date = document.getElementById("todays-date");
if (data.values[0][1] !== "") {
todays_date.innerHTML = data.values[0][1]; //Today's Date
}
var last_updated_date = document.getElementById("last-updated-date");
if (data.values[2][1] !== "") {
last_updated_date.innerHTML = "Last Updated: " + data.values[2][1]; // Last Updated
}
var source_details = document.getElementById("source-details");
if (data.values[3][1] !== "") {
source_details.innerHTML = '<a class="nav-link" href="' + data.values[3][1] + '" target="_blank">Source</a>';
}
if (data.values[4][1] !== "") {
source_details.innerHTML += '<a class="nav-link" href="' + data.values[4][1] + '" target="_blank">Update 1</a>';
}
if (data.values[5][1] !== "") {
source_details.innerHTML += '<a class="nav-link" href="' + data.values[5][1] + '" target="_blank">Update 2</a>';
}
if (data.values[6][1] !== "") {
source_details.innerHTML += '<a class="nav-link" href="' + data.values[6][1] + '" target="_blank">Update 3</a>';
}
});
});
// Information Gathering from Google Sheet - End
//check