|
@ -3,7 +3,7 @@ import React from "react"; |
|
|
import { View, Text } from "react-native"; |
|
|
import { View, Text } from "react-native"; |
|
|
import getFieldsAnswers from "../api/RequestFieldsAnswers/getFieldsAnswers"; |
|
|
import getFieldsAnswers from "../api/RequestFieldsAnswers/getFieldsAnswers"; |
|
|
import assets from "../config/assets"; |
|
|
import assets from "../config/assets"; |
|
|
//---1/3: melhorar código
|
|
|
|
|
|
|
|
|
//----- 1/3: melhorar código (URGENTE)
|
|
|
const custom_assets = { |
|
|
const custom_assets = { |
|
|
pluviometer: assets.PluviometerIcon, |
|
|
pluviometer: assets.PluviometerIcon, |
|
|
officialPluviometer: assets.OfficialPluviometer, |
|
|
officialPluviometer: assets.OfficialPluviometer, |
|
@ -72,10 +72,10 @@ function verifymeasureDates(labels, measureDate, day) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const getCurrentPluviometer = (pluvForm, userId, data, datapluv) => { |
|
|
const getCurrentPluviometer = (pluvForm, userId, data, datapluv) => { |
|
|
//console.log("\nuserid: "+ userId + "\n\n");
|
|
|
|
|
|
//console.log(pluvForm);
|
|
|
|
|
|
var day = { label: null, values: [] }; |
|
|
var day = { label: null, values: [] }; |
|
|
|
|
|
|
|
|
|
|
|
var time = null; |
|
|
|
|
|
var dt = null; |
|
|
|
|
|
var measure = { rainGauge: null, dateTime: null, comment: null }; |
|
|
var measureDate = null; |
|
|
var measureDate = null; |
|
|
if (pluvForm.formsanswersuserinformer == userId) { |
|
|
if (pluvForm.formsanswersuserinformer == userId) { |
|
|
pluvForm.array_to_json.find((field) => { |
|
|
pluvForm.array_to_json.find((field) => { |
|
@ -83,28 +83,38 @@ const getCurrentPluviometer = (pluvForm, userId, data, datapluv) => { |
|
|
measureDate = moment(field.fieldsanswersvalue, "DD-MM-YYYY").format( |
|
|
measureDate = moment(field.fieldsanswersvalue, "DD-MM-YYYY").format( |
|
|
"DD/MM" |
|
|
"DD/MM" |
|
|
); |
|
|
); |
|
|
//data.labels.push(moment(f.fieldsanswersdtfilling).format("DD/MM/YYYY"));
|
|
|
|
|
|
|
|
|
dt = moment(field.fieldsanswersvalue, "DD-MM-YYYY").format( |
|
|
|
|
|
"DD-MM-YYYY" |
|
|
|
|
|
); |
|
|
|
|
|
} else if (field.fieldname == "eventtime") { |
|
|
|
|
|
time = moment(field.fieldsanswersvalue, "HH:mm").format("HH:mm"); |
|
|
|
|
|
} else if (field.fieldname == "comments") { |
|
|
|
|
|
measure.comment = field.fieldsanswersvalue; |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
measure.dateTime = moment(dt + "T" + time, "DD-MM-YYYYTHH:mm").format( |
|
|
|
|
|
"DD-MM-YYYYTHH:mm" |
|
|
|
|
|
); |
|
|
|
|
|
// console.log("dt: " + day.dateTime);
|
|
|
|
|
|
|
|
|
pluvForm.array_to_json.find((field) => { |
|
|
pluvForm.array_to_json.find((field) => { |
|
|
if (field.fieldname == "rainamount") { |
|
|
if (field.fieldname == "rainamount") { |
|
|
if (verifymeasureDates(data.labels, measureDate, day)) { |
|
|
|
|
|
day.values.push( |
|
|
|
|
|
field.fieldsanswersvalue |
|
|
|
|
|
|
|
|
measure.rainGauge = field.fieldsanswersvalue |
|
|
? parseFloat(field.fieldsanswersvalue) |
|
|
? parseFloat(field.fieldsanswersvalue) |
|
|
: null |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
: null; |
|
|
|
|
|
if (verifymeasureDates(data.labels, measureDate, day)) { |
|
|
|
|
|
// day.values.push(
|
|
|
|
|
|
// field.fieldsanswersvalue
|
|
|
|
|
|
// ? parseFloat(field.fieldsanswersvalue)
|
|
|
|
|
|
// : null
|
|
|
|
|
|
// );
|
|
|
|
|
|
day.values.push(measure); |
|
|
datapluv.push(day); |
|
|
datapluv.push(day); |
|
|
} else { |
|
|
} else { |
|
|
datapluv.forEach((d) => { |
|
|
datapluv.forEach((d) => { |
|
|
if (d.label === measureDate) { |
|
|
if (d.label === measureDate) { |
|
|
d.values.push( |
|
|
|
|
|
field.fieldsanswersvalue |
|
|
|
|
|
? parseFloat(field.fieldsanswersvalue) |
|
|
|
|
|
: null |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
d.values.push(measure); |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
@ -126,6 +136,7 @@ async function getPluviometerStatio_informations(id) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const AssembleModalObject = async (response, name, userId, formId) => { |
|
|
const AssembleModalObject = async (response, name, userId, formId) => { |
|
|
|
|
|
// console.log(response);
|
|
|
var situation = null; |
|
|
var situation = null; |
|
|
var user = null; |
|
|
var user = null; |
|
|
var institution = null; |
|
|
var institution = null; |
|
@ -140,33 +151,69 @@ const AssembleModalObject = async (response, name, userId, formId) => { |
|
|
|
|
|
|
|
|
var datapluv = []; |
|
|
var datapluv = []; |
|
|
|
|
|
|
|
|
|
|
|
if (name == "pluviometer") { |
|
|
|
|
|
situation = "PLUVIÔMETRO"; |
|
|
|
|
|
const pluv_sation = await getPluviometerStatio_informations(formId); |
|
|
|
|
|
if (pluv_sation) { |
|
|
|
|
|
pluv_sation.forEach((field) => { |
|
|
|
|
|
if (field.fieldname == "institutename") { |
|
|
|
|
|
institution = |
|
|
|
|
|
field.fieldsanswersvalue != "None" |
|
|
|
|
|
? field.fieldsanswersvalue |
|
|
|
|
|
: "Não há vínculo institucional"; |
|
|
|
|
|
} else if (field.fieldname == "eventaddress") { |
|
|
|
|
|
address = field.fieldsanswersvalue; |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
if (response) { |
|
|
if (JSON.parse(response).array_to_json) { |
|
|
if (JSON.parse(response).array_to_json) { |
|
|
const r = JSON.parse(response).array_to_json; |
|
|
const r = JSON.parse(response).array_to_json; |
|
|
|
|
|
|
|
|
//(waiting for issue #16) user = r[0].formsanswersuserinformer;
|
|
|
|
|
|
|
|
|
const currentPluv = JSON.parse(response).array_to_json.filter( |
|
|
|
|
|
(pluvForm) => getCurrentPluviometer(pluvForm, userId, data, datapluv) |
|
|
|
|
|
); |
|
|
|
|
|
if (datapluv) { |
|
|
|
|
|
datapluv.sort(function (dataPluv, dataPluvB) { |
|
|
|
|
|
return dataPluv.label.localeCompare(dataPluvB.label); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
datapluv.forEach((measureDay) => { |
|
|
|
|
|
measureDay.values.sort(function (a, b) { |
|
|
|
|
|
return a.dateTime.localeCompare(b.dateTime); |
|
|
|
|
|
}); |
|
|
|
|
|
}); |
|
|
|
|
|
dtlength = datapluv.length - 1; |
|
|
|
|
|
val_length = datapluv[dtlength].values.length - 1; |
|
|
|
|
|
|
|
|
|
|
|
comments = datapluv[dtlength].values[val_length].comment; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} else if (JSON.parse(response).array_to_json) { |
|
|
|
|
|
const r = JSON.parse(response).array_to_json; |
|
|
if (name == "automaticPluviometer") { |
|
|
if (name == "automaticPluviometer") { |
|
|
situation = "PLUVIÔMETRO"; |
|
|
situation = "PLUVIÔMETRO"; |
|
|
r[0].array_to_json.forEach(function (f) { |
|
|
r[0].array_to_json.forEach(function (f) { |
|
|
var day = { label: null, values: [] }; |
|
|
var day = { label: null, values: [] }; |
|
|
|
|
|
var measure = { rainGauge: null }; |
|
|
if (f.fieldname == "medicao") { |
|
|
if (f.fieldname == "medicao") { |
|
|
var measureDate = moment( |
|
|
var measureDate = moment( |
|
|
f.fieldsanswersdtfilling, |
|
|
f.fieldsanswersdtfilling, |
|
|
"YYYY-MM-DDTHH:mm:ss" |
|
|
"YYYY-MM-DDTHH:mm:ss" |
|
|
).format("DD/MM"); |
|
|
).format("DD/MM"); |
|
|
|
|
|
|
|
|
|
|
|
measure.rainGauge = f.fieldsanswersvalue ? parseFloat(f.fieldsanswersvalue) : null; |
|
|
|
|
|
|
|
|
if (verifymeasureDates(data.labels, measureDate, day)) { |
|
|
if (verifymeasureDates(data.labels, measureDate, day)) { |
|
|
day.values.push( |
|
|
|
|
|
f.fieldsanswersvalue ? parseFloat(f.fieldsanswersvalue) : null |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
day.values.push(measure); |
|
|
day.label = measureDate; |
|
|
day.label = measureDate; |
|
|
datapluv.push(day); |
|
|
datapluv.push(day); |
|
|
} else { |
|
|
} else { |
|
|
datapluv.forEach((d) => { |
|
|
datapluv.forEach((d) => { |
|
|
if (d.label == measureDate) { |
|
|
if (d.label == measureDate) { |
|
|
d.values.push( |
|
|
d.values.push( |
|
|
f.fieldsanswersvalue ? parseFloat(f.fieldsanswersvalue) : null |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
measure); |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
@ -187,36 +234,6 @@ const AssembleModalObject = async (response, name, userId, formId) => { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// console.log(datapluv);
|
|
|
// console.log(datapluv);
|
|
|
} else if (name == "pluviometer") { |
|
|
|
|
|
situation = "PLUVIÔMETRO"; |
|
|
|
|
|
r[r.length - 1].array_to_json.forEach(function (f) { |
|
|
|
|
|
if (f.fieldname == "comments") { |
|
|
|
|
|
comments = f.fieldsanswersvalue; |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
const pluv_sation = await getPluviometerStatio_informations(formId); |
|
|
|
|
|
if (pluv_sation) { |
|
|
|
|
|
pluv_sation.forEach((field) => { |
|
|
|
|
|
if (field.fieldname == "institutename") { |
|
|
|
|
|
institution = |
|
|
|
|
|
field.fieldsanswersvalue != "None" |
|
|
|
|
|
? field.fieldsanswersvalue |
|
|
|
|
|
: "Não há vínculo institucional"; |
|
|
|
|
|
} else if (field.fieldname == "eventaddress") { |
|
|
|
|
|
address = field.fieldsanswersvalue; |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const currentPluv = JSON.parse(response).array_to_json.filter( |
|
|
|
|
|
(pluvForm) => getCurrentPluviometer(pluvForm, userId, data, datapluv) |
|
|
|
|
|
); |
|
|
|
|
|
if (datapluv) { |
|
|
|
|
|
datapluv.sort(function (dataPluv, dataPluvB) { |
|
|
|
|
|
return dataPluv.label.localeCompare(dataPluvB.label); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
} else { |
|
|
if (r[0].array_to_json) { |
|
|
if (r[0].array_to_json) { |
|
|
user = r[0].formsanswersuserinformer; |
|
|
user = r[0].formsanswersuserinformer; |
|
@ -228,7 +245,9 @@ const AssembleModalObject = async (response, name, userId, formId) => { |
|
|
address = f.fieldsanswersvalue; |
|
|
address = f.fieldsanswersvalue; |
|
|
} |
|
|
} |
|
|
if (f.fieldname == "eventdate") { |
|
|
if (f.fieldname == "eventdate") { |
|
|
date = f.fieldsanswersvalue; |
|
|
|
|
|
|
|
|
date = moment(f.fieldsanswersvalue, "DD-MM-YYYY").format( |
|
|
|
|
|
"DD/MM/YYYY" |
|
|
|
|
|
);; |
|
|
} |
|
|
} |
|
|
if (f.fieldname == "eventtime") { |
|
|
if (f.fieldname == "eventtime") { |
|
|
time = f.fieldsanswersvalue; |
|
|
time = f.fieldsanswersvalue; |
|
|