-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
94 lines (86 loc) · 3.53 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
var selectElementPais = document.querySelector('#selectElementPais');
var btnElementBuscar = document.querySelector('#btnElementBuscar');
var tableRegioesElement = document.querySelector('#tableElementStates tbody');
var tableElementPais = document.querySelector('#tableElementPais');
btnElementBuscar.onclick = function () {
searchPais(selectElementPais.value);
}
main();
function searchPais(pais) {
axios.get('https://covid19-brazil-api.now.sh/api/report/v1/' + pais)
.then(function (response) {
tableElementPais.setAttribute('style', 'opacity:1;');
var pais = response.data.data;
pais.updated_at = pais.updated_at.replace(/T/g, " ");
var date = pais.updated_at.replace(/.000Z/g, "");
var array = [
pais.country,
pais.cases,
pais.confirmed,
pais.deaths,
pais.recovered,
date
];
var trElement = document.createElement('tr');
for (data of array) {
var celula = document.createElement('td');
var textCelula = document.createTextNode(data);
celula.setAttribute('class', 'text-uppercase');
celula.appendChild(textCelula);
trElement.appendChild(celula);
}
tableElementPais.appendChild(trElement);
})
.catch(function (error) {
console.log(error);
})
}
function main() {
axios.get('https://covid19-brazil-api.now.sh/api/report/v1')
.then(function (response) {
for (regiao of response.data.data) {
var trElement = document.createElement('tr');
array = [
regiao.uf,
regiao.state,
regiao.cases,
regiao.deaths,
];
for (data of array) {
if (data === array[0]) {
var celula = document.createElement('th');
var textCelula = document.createTextNode(' ' + data);
var icon = document.createElement('img');
icon.setAttribute('src', 'static/flags/' + data + '.png');
icon.setAttribute('width', '20px');
celula.appendChild(icon);
} else {
var celula = document.createElement('th');
var textCelula = document.createTextNode(data);
if (data === array[3]) {
celula.setAttribute('class', 'text-danger');
} else { }
}
celula.appendChild(textCelula);
trElement.appendChild(celula);
}
tableRegioesElement.appendChild(trElement);
}
})
.catch(function (error) {
console.log(error);
});
axios.get('https://covid19-brazil-api.now.sh/api/report/v1/countries')
.then(function (response) {
for (pais of response.data.data) {
optionElement = document.createElement('option');
optionElement.setAttribute('value', pais.country);
textElement = document.createTextNode(pais.country);
optionElement.appendChild(textElement);
selectElementPais.appendChild(optionElement);
}
})
.catch(function (error) {
console.log(error);
});
}