Skip to content

Commit 97a7bf2

Browse files
committed
Major update new query strings, new selects and updatin api
1 parent 2d6a268 commit 97a7bf2

22 files changed

+374
-63
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.

api/options.json

+23-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
11
{
2-
"result": [
3-
"Poliomielite",
4-
"Sarampo",
5-
"COVID-19"
2+
"sicks": [
3+
"Difteria",
4+
"Poliomielite",
5+
"Tetano"
6+
],
7+
"immunizers": [
8+
"Oral Poliomielite (VOP)",
9+
"Pentavalente (DTP+HB+Hib) (PENTA)",
10+
"Poliomielite inativada (VIP)",
11+
"Tetraviral (sarampo, rubéola, caxumbae varicela)",
12+
"Tríplice Bacteriana (DTP)",
13+
"Tríplice Viral (SCR)"
14+
],
15+
"years": [
16+
"2000",
17+
"2022"
18+
],
19+
"doses": [
20+
"1a dose",
21+
"1a reforço",
22+
"2a dose",
23+
"2a reforço",
24+
"3a dos"
625
]
726
}
File renamed without changes.
File renamed without changes.
File renamed without changes.

index.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
<div id="app"></div>
1111
<!-- Main App -->
1212
<script type="module">
13-
import MCT from "./src/main.js";
14-
const dashboard = new MCT("http://localhost:5000/");
13+
import Mct from "./src/main.js";
14+
const dashboard = new Mct("http://localhost:5000/");
1515
</script>
1616
</body>
1717
</html>

server.js

+47-17
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,66 @@ const app = express();
1111
app.use(cors());
1212
const __dirname = path.resolve();
1313

14-
app.get('/:arg', (req, res) => {
14+
app.get('/UF/', (req, res) => {
1515
res.header("Content-Type",'application/json');
16-
if (req.params.arg.includes(",")){
17-
const args = req.params.arg.split(",");
18-
const result = {};
19-
for (let arg of args) {
20-
result[arg] = JSON.parse(fs.readFileSync(path.join(__dirname, `./api/${arg}.json`)));
16+
const sickImmunizer = req.query.sickImmunizer;
17+
const local = req.query.local;
18+
if (sickImmunizer) {
19+
if (sickImmunizer.includes(",")) {
20+
const result = {};
21+
for (let arg of sickImmunizer.split(",")) {
22+
result[arg] =
23+
JSON.parse(fs.readFileSync(
24+
path.join(
25+
__dirname,
26+
`./api/UF/${local}/sicks/${arg}.json`
27+
)
28+
));
29+
}
30+
res.send(result);
31+
} else {
32+
res.sendFile(path.join(__dirname, `./api/UF/${local}/sicks/${sickImmunizer}.json`));
2133
}
22-
res.send(result)
2334

2435
return;
2536
}
37+
38+
const citiesAcronym = req.query.citiesAcronym;
39+
res.sendFile(path.join(__dirname, `./api/UF/${local}/${citiesAcronym}.json`));
40+
});
2641

42+
app.get('/:arg', (req, res) => {
43+
res.header("Content-Type",'application/json');
2744
res.sendFile(path.join(__dirname, `./api/${req.params.arg}.json`));
2845
});
2946

30-
app.get('/UF/:state/:arg', (req, res) => {
47+
app.get('/', (req, res) => {
3148
res.header("Content-Type",'application/json');
32-
if (req.params.arg.includes(",")){
33-
const args = req.params.arg.split(",");
34-
const result = {};
35-
for (let arg of args) {
36-
result[arg] = JSON.parse(fs.readFileSync(path.join(__dirname, `./api/${arg}.json`)));
37-
}
38-
res.send(result)
49+
const sickImmunizer = req.query.sickImmunizer;
50+
if (sickImmunizer) {
51+
if (sickImmunizer.includes(",")) {
52+
const sickImmunizers = sickImmunizer.split(",");
53+
const result = {};
54+
for (let arg of sickImmunizers) {
55+
result[arg] =
56+
JSON.parse(fs.readFileSync(
57+
path.join(
58+
__dirname,
59+
`./api/sicks/${arg}.json`
60+
)
61+
));
62+
}
63+
res.send(result);
3964

65+
} else {
66+
res.sendFile(path.join(__dirname, `./api/sicks/${req.query.sickImmunizer}.json`));
67+
}
4068
return;
4169
}
42-
43-
res.sendFile(path.join(__dirname, `./api/UF/${req.params.state}/${req.params.arg}.json`));
70+
const citiesAcronym = req.query.citiesAcronym;
71+
if (citiesAcronym) {
72+
res.sendFile(path.join(__dirname, `./api/${'citiesAcronym' + citiesAcronym}.json`));
73+
}
4474
});
4575

4676
const port = process.env.SERVER_HOST_PORT;

src/common.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@ export const formatToApi = ({
2020
routerResult[formField] = formatDate(form[formField]);
2121
}
2222
break;
23+
case "doses":
24+
case "granularities":
25+
case "immunizers":
2326
case "locals":
24-
case "sicksImmunizers":
27+
case "sicks":
2528
case "types":
26-
case "granularities":
29+
case "years":
2730
// Do Nothing
2831
break;
2932
default:

src/components/chart.js

+9-6
Original file line numberDiff line numberDiff line change
@@ -246,15 +246,15 @@ export const chart = {
246246

247247
results = await store.dispatch("content/requestBySick");
248248

249+
if (!results || !years) {
250+
return;
251+
}
252+
249253
// TODO: API shoud send correct data fomated and we will not need this fix here
250254
if (!Object.keys(results).find(x => x === sicks[0])) {
251255
results = { [sicks[0]]: results }
252256
};
253257

254-
if (!years) {
255-
return;
256-
}
257-
258258
const resultChart = {};
259259
for(let sick of sicks) {
260260
for(let local of locals) {
@@ -301,10 +301,13 @@ export const chart = {
301301

302302
watch(
303303
() => [
304+
store.state.content.form.granularity,
305+
store.state.content.form.dose,
304306
store.state.content.form.local,
305-
store.state.content.form.sickImmunizer,
307+
store.state.content.form.periodEnd,
306308
store.state.content.form.periodStart,
307-
store.state.content.form.periodEnd
309+
store.state.content.form.sickImmunizer,
310+
store.state.content.form.type,
308311
],
309312
async () => {
310313
await setChartData();

src/components/main-card.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export const mainCard = {
4343
"sickImmunizer",
4444
"sicksImmunizers",
4545
"type",
46+
"dose",
4647
"types",
4748
"local",
4849
"locals",
@@ -51,7 +52,7 @@ export const mainCard = {
5152
"periodStart",
5253
"periodEnd",
5354
"granularity",
54-
"granularities"
55+
"granularities",
5556
],
5657
base: "form",
5758
mutation: "content/UPDATE_FORM"
@@ -127,9 +128,9 @@ export const mainCard = {
127128

128129
watch(
129130
() => [
130-
store.state.content.form,
131131
store.state.content.form.sickImmunizer,
132132
store.state.content.form.type,
133+
store.state.content.form.dose,
133134
store.state.content.form.local,
134135
store.state.content.form.period,
135136
store.state.content.form.periodStart,
@@ -145,7 +146,7 @@ export const mainCard = {
145146

146147
onBeforeMount(async () => {
147148
// Set sicks options
148-
await store.dispatch("content/updateSicksImmunizers", "sicks")
149+
await store.dispatch("content/updateFormSelect", "sicks")
149150
// Set locals options
150151
store.dispatch("content/updateLocals", "sicks")
151152
store.dispatch("content/updateTypes")

src/components/map/map.js

+13-8
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ export const map = {
4848

4949
const setMap = async () => {
5050
const local = store.state.content.form.local;
51-
const sick = store.state.content.form.sickImmunizer;
51+
const sickImmunizer = store.state.content.form.sickImmunizer;
52+
const tab = store.state.content.tabBy;
5253
const period = store.state.content.form.period;
5354

5455
const mapElement = document.querySelector('#map');
@@ -60,11 +61,15 @@ export const map = {
6061
'https://servicodados.ibge.gov.br/api/v3/malhas/paises/BR?formato=image/svg+xml&qualidade=intermediaria&intrarregiao=UF'
6162
);
6263

63-
if (sick && sick.length) {
64+
if (sickImmunizer && sickImmunizer.length) {
6465
datasetCities.value = null;
65-
datasetStates.value = await api.request(sick);
66-
const states = await api.request("statesAcronym");
67-
renderMap({ element: mapElement, map, datasetStates: datasetStates.value[period], states, statesSelected: local });
66+
try {
67+
datasetStates.value = await api.request("?tab=" + tab + "&sickImmunizer=" + sickImmunizer);
68+
const states = await api.request("statesAcronym");
69+
renderMap({ element: mapElement, map, datasetStates: datasetStates.value[period], states, statesSelected: local });
70+
} catch (e) {
71+
renderMap({ element: mapElement, map });
72+
}
6873
return;
6974
}
7075

@@ -76,12 +81,12 @@ export const map = {
7681
const map = await queryMap(
7782
`https://servicodados.ibge.gov.br/api/v3/malhas/estados/${local}?formato=image/svg+xml&qualidade=intermediaria&intrarregiao=municipio`
7883
);
79-
if (!sick) {
84+
if (!sickImmunizer) {
8085
return renderMap({ element: mapElement, map });
8186
}
8287
try {
83-
datasetCities.value = await api.requestState(local + "/" + sick);
84-
const cities = await api.requestState(local + "/" + "citiesAcronym");
88+
datasetCities.value = await api.requestState("?tab=" + tab + "&local=" + local + "&sickImmunizer=" + sickImmunizer);
89+
const cities = await api.request("?citiesAcronym=" + local);
8590
datasetStates.value = null;
8691
renderMap({ element: mapElement, map, datasetCities: datasetCities.value[period], cities });
8792
} catch (e) {

src/components/map/year-slider.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const yearSlider = {
2323
if (period) {
2424
showSlider.value = true;
2525
return timestampToYear(period)
26-
}
26+
}
2727
showSlider.value = false;
2828
return;
2929
}

src/components/sub-buttons.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ export const subButtons = {
158158
<div v-html="svg" style="max-width: 100px"></div>
159159
<div>
160160
<h3>Imagem PNG</h3>
161-
<p>Adequado para a maioria dos usos, amplamento compatível</p>
161+
<p>Adequado para a maioria dos usos, amplamente compatível</p>
162162
</div>
163163
</div>
164164
<n-button quaternary type="primary" style="font-weight: 500" @click="downloadPng">

0 commit comments

Comments
 (0)