-
Notifications
You must be signed in to change notification settings - Fork 0
/
view.js
226 lines (194 loc) · 9.69 KB
/
view.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
226
'use strict';
class View{
constructor() {
}
registerClickListener(listener){
// document.getElementById("xxxxxxx").addEventListener("click", listener);
}
// when called by controller will update the number of new cases in glasgow
updateUserDefinedLocationNewCases(cases, yesterday) {
if(document.getElementById("user-defined-location-new-cases")!==null){ //checks that the page actually has the div so it doesnt try it on the wrong page
if(cases > yesterday){
document.getElementById("user-defined-location-new-cases").innerHTML = cases + " <span class='material-icons-outlined opposite__color'>trending_up</span>";
}
else if(cases === yesterday){
document.getElementById("user-defined-location-new-cases").innerHTML = cases + " <span class='material-icons-outlined grey__color'>arrow_right_alt</span>";
}
else{
document.getElementById("user-defined-location-new-cases").innerHTML = cases + " <span class='material-icons-outlined green__color'>trending_down</span>";
}
}
}
updateUserDefinedLocationNewDeaths(cases, yesterday) {
if(document.getElementById("user-defined-location-new-deaths")!==null){
if(cases > yesterday){
document.getElementById("user-defined-location-new-deaths").innerHTML = cases + " <span class='material-icons-outlined opposite__color'>trending_up</span>";
}
else if(cases === yesterday){
document.getElementById("user-defined-location-new-deaths").innerHTML = cases + " <span class='material-icons-outlined grey__color'>arrow_right_alt</span>";
}
else{
document.getElementById("user-defined-location-new-deaths").innerHTML = cases + " <span class='material-icons-outlined green__color'>trending_down</span>";
}
}
}
updateUserDefinedLocationAlertLevel(level){
if(document.getElementById("local-alert-level")!==null){
document.getElementById("local-alert-level").innerText = level;
}
}
updateUserDefinedTotalCases(cases){
if(document.getElementById("user-defined-total-cases")!==null){
document.getElementById("user-defined-total-cases").innerHTML = cases + " <span class='material-icons-outlined opposite__color'>trending_up</span>";
}
}
updateUserDefinedTotalDeaths(deaths){
if(document.getElementById("user-defined-total-deaths")!==null){
document.getElementById("user-defined-total-deaths").innerHTML = deaths + " <span class='material-icons-outlined opposite__color'>trending_up</span>";
}
}
updateNationalNewCases(cases, yesterday){
if(document.getElementById("national-new-cases")!==null){
if(cases > yesterday){
document.getElementById("national-new-cases").innerHTML = cases + " <span class='material-icons-outlined opposite__color'>trending_up</span>";
}
else if(cases === yesterday){
document.getElementById("national-new-cases").innerHTML = cases + " <span class='material-icons-outlined grey__color'>arrow_right_alt</span>";
}
else{
document.getElementById("national-new-cases").innerHTML = cases + " <span class='material-icons-outlined green__color'>trending_down</span>";
}
}
}
updateNationalTotalCases(cases){
if(document.getElementById("fourth-box-data")!==null){
document.getElementById("fourth-box-data").innerHTML = cases + " <span class='material-icons-outlined opposite__color'>trending_up</span>";
}
}
updateNationalNewDeaths(cases, yesterday){
if(document.getElementById("national-new-deaths")!==null){
if(cases > yesterday){
document.getElementById("national-new-deaths").innerHTML = cases + " <span class='material-icons-outlined opposite__color'>trending_up</span>";
}
else if(cases === yesterday){
document.getElementById("national-new-deaths").innerHTML = cases + " <span class='material-icons-outlined grey__color'>arrow_right_alt</span>";
}
else{
document.getElementById("national-new-deaths").innerHTML = cases + " <span class='material-icons-outlined green__color'>trending_down</span>";
}
}
}
updateFirstDoseVaccinated(total, yesterday){
if(document.getElementById("first-dose-vaccinated")!==null){
document.getElementById("first-dose-vaccinated").innerHTML = total + " <span class='material-icons-outlined green__color'>trending_up</span>";
}
}
//for global data we are just modifying the existing boxes for national so ids are wrongly names but work
updateGlobalNewCases(cases, yesterday){
if(document.getElementById("global-new-cases") !== null){
if(cases > yesterday){
document.getElementById("global-new-cases").innerHTML = cases + " <span class='material-icons-outlined opposite__color'>trending_up</span>";
}
else if(cases === yesterday){
document.getElementById("global-new-cases").innerHTML = cases + " <span class='material-icons-outlined grey__color'>arrow_right_alt</span>";
}
else{
document.getElementById("global-new-cases").innerHTML = cases + " <span class='material-icons-outlined green__color'>trending_down</span>";
}
}
}
updateGlobalNewDeaths(deaths, yesterday){
if(document.getElementById("global-new-deaths") !== null){
if(deaths > yesterday){
document.getElementById("global-new-deaths").innerHTML = deaths + " <span class='material-icons-outlined opposite__color'>trending_up</span>";
}
else if(deaths === yesterday){
document.getElementById("global-new-deaths").innerHTML = deaths + " <span class='material-icons-outlined grey__color'>arrow_right_alt</span>";
}
else{
document.getElementById("global-new-deaths").innerHTML = deaths + " <span class='material-icons-outlined green__color'>trending_down</span>";
}
}
}
updateGlobalTotalDeaths(deaths){
if(document.getElementById("global-total-deaths") !== null){
document.getElementById("global-total-deaths").innerHTML = deaths + " <span class='material-icons-outlined opposite__color'>trending_up</span>";
}
}
updateGlobalTotalCases(cases){
if(document.getElementById("global-total-cases") !== null){
document.getElementById("global-total-cases").innerHTML = cases + " <span class='material-icons-outlined opposite__color'>trending_up</span>";
}
}
//INDEX
loadFirstTimeSetup(){
if (localStorage.getItem("userName") === null || localStorage.getItem("userName") === "Your Name" ){
location.replace("signup.html");
}
}
loadName(){
if (localStorage.getItem("userName") === null) {
localStorage.setItem("userName","Your Name");
}
document.getElementById("profile-name").innerHTML = localStorage.getItem("userName");
}
loadToggleLocalStats(){
if(localStorage.getItem("localBox") === "false" || localStorage.getItem("userLocality") === null){
document.getElementById("profile-location").style.display = "none";
}
let x = document.getElementById("local-stats");
if(localStorage.getItem("localBox") === "false"){
x.style.display = "none";
}
else{
x.style.display = "block";
}
}
//SETTINGS
loadThemeSettings(){
let checked = JSON.parse(localStorage.getItem("theme-btn"));
document.getElementById("theme-btn").checked = checked;
if (localStorage.getItem("theme-text") === null){
localStorage.setItem("theme-text","Light");
}
document.getElementById("theme-Text").innerHTML = localStorage.getItem("theme-text");
}
loadLocation(element){
let city = localStorage.getItem("userLocality");
let country = localStorage.getItem("userCountry");
element.innerHTML = city + ", " + country;
}
loadLocalStatSettings(){
let setting1 = JSON.parse(localStorage.getItem("localBox"));
if (setting1 === null){
setting1 = false;
}
document.getElementById("localstats-setting-btn").checked = setting1;
if (setting1 === false){
document.getElementById("active-location").style.display = "none";
document.getElementById("localSettingLine").style.display= "none";
}
if (localStorage.getItem("localText") === null){
localStorage.setItem("localText","Disabled");
}
document.getElementById("localstats-setting-text").innerHTML = localStorage.getItem("localText");
}
loadWeeklyCheckSetting(){
let setting2 = JSON.parse(localStorage.getItem("weeklySymptomsBox"));
if (setting2 === null){
setting2 = true;
}
document.getElementById("weeklysymptomscheck-settings-btn").checked = setting2;
if (localStorage.getItem("weeklySymptomsText") === null){
localStorage.setItem("weeklySymptomsText","Enabled");
}
document.getElementById("weeklysymptomscheck-settings-text").innerHTML = localStorage.getItem("weeklySymptomsText") ;
}
loaduserName(){
let username = localStorage.getItem("userName");
if (username === null){
username = "Your Name";
}
document.getElementById("profile__first-name").value = username;
}
}