Browse Source

sending user id as value for user forms answers informer

master
analuizaff 3 years ago
parent
commit
4c4b88b14e
  1. 1
      src/app/components/AssembleModalObject.js
  2. 5
      src/app/components/MapModal.js
  3. 26
      src/app/components/forms/AssembleIngestionObject.js
  4. 12
      src/app/hooks/useFiltering.js
  5. 42
      src/app/hooks/useSocketMarkers.js
  6. 5
      src/app/screens/MapFormScreen.js
  7. 33
      src/app/screens/PluviometerRegisterScreen.js
  8. 3
      src/app/screens/PluviometerSharingDataScreen.js
  9. 3
      src/app/screens/RainSharingDataScreen.js
  10. 2
      src/app/screens/RiverFloodSharingDataScreen.js
  11. 11
      src/app/screens/SharingDataScreen.js
  12. 2
      src/app/screens/SharingFloodZonesScreen.js

1
src/app/components/AssembleModalObject.js

@ -66,6 +66,7 @@ function verifyMeasureDates(labels, measureDate) {
} }
const AssembleModalObject = (response, name) => { const AssembleModalObject = (response, name) => {
console.log(response);
var situation = null; var situation = null;
var user = null; var user = null;
var institution = null; var institution = null;

5
src/app/components/MapModal.js

@ -240,7 +240,7 @@ function componentBody(props) {
<View style={styles.bodyInfo}> <View style={styles.bodyInfo}>
{!isOfficialPluviometer(props.name) && {!isOfficialPluviometer(props.name) &&
iconTextRow({ name: "account", description: user })} iconTextRow({ name: "account", description: user })}
{props.institution && iconInstitutionTextRow({
{iconInstitutionTextRow({
name: "university", name: "university",
description: institution, description: institution,
})} })}
@ -282,11 +282,14 @@ function MapModal({ showModal, setShowModal, markers }) {
var timeFilter = null; var timeFilter = null;
const getAnswers = async (id, name) => { const getAnswers = async (id, name) => {
// console.log("----------id:"+id);
if (isPluviometer(name)) { if (isPluviometer(name)) {
const initialDate = moment().format("YYYY-MM-DD"); const initialDate = moment().format("YYYY-MM-DD");
const finalDate = moment().subtract(5, "days").format("YYYY-MM-DD"); const finalDate = moment().subtract(5, "days").format("YYYY-MM-DD");
timeFilter = finalDate + "/" + initialDate; timeFilter = finalDate + "/" + initialDate;
// console.log(timeFilter);
} }
const result = await getFieldsAnswers.fieldsAnswers(timeFilter, id); const result = await getFieldsAnswers.fieldsAnswers(timeFilter, id);

26
src/app/components/forms/AssembleIngestionObject.js

@ -1,9 +1,10 @@
import moment from "moment"; import moment from "moment";
import React from "react";
import sendFormAnswer from "../../api/Ingestion/sendFormAnswer"; import sendFormAnswer from "../../api/Ingestion/sendFormAnswer";
const AssembleIngestionObject = ( const AssembleIngestionObject = (
{ images, description }, { images, description },
user,
situation, situation,
code, code,
location, location,
@ -16,7 +17,7 @@ const AssembleIngestionObject = (
array_to_json: [ array_to_json: [
{ {
formcode: code, formcode: code,
formsanswersuserinformer: "admin@wpd.com",
formsanswersuserinformer: user.id,
fieldsanswerslongitude: location["longitude"], fieldsanswerslongitude: location["longitude"],
fieldsanswerslatitude: location["latitude"], fieldsanswerslatitude: location["latitude"],
fields: [ fields: [
@ -39,6 +40,7 @@ const AssembleIngestionPluviometer = ({
pluviometer, pluviometer,
description, description,
images, images,
user,
date, date,
time, time,
}) => { }) => {
@ -47,7 +49,7 @@ const AssembleIngestionPluviometer = ({
array_to_json: [ array_to_json: [
{ {
formcode: "PLUVIOMETERS_FORM", formcode: "PLUVIOMETERS_FORM",
formsanswersuserinformer: "admin@wpd.com",
formsanswersuserinformer: user.id,
fias: [ fias: [
{ {
fieldsanswersdate: moment(date).format("DD-MM-YYYY"), fieldsanswersdate: moment(date).format("DD-MM-YYYY"),
@ -62,29 +64,31 @@ const AssembleIngestionPluviometer = ({
}; };
}; };
const AssembleIngestionPluvRegistration = ({ date, time, user }) => {
const AssembleIngestionPluvRegistration = ( date, time, user, address, coordinates ) => {
console.log(user);
console.log(coordinates);
const pluvResgistrationObject = { const pluvResgistrationObject = {
responseData: { responseData: {
array_to_json: [ array_to_json: [
{ {
formcode: "PLUVIOMETER_REGISTRATION", formcode: "PLUVIOMETER_REGISTRATION",
formsanswersuserinformer: "admin@wpd.com", //user
fieldsanswerslongitude: -46.5637, //location["longitude"],
fieldsanswerslatitude: -23.623, //location["latitude"],
formsanswersuserinformer: user.id,
fieldsanswerslongitude: coordinates["longitude"],
fieldsanswerslatitude: coordinates["latitude"],
fields: [ fields: [
{ {
fieldsanswerseventaddress: "Rua Rio de Janeiros, 81", //address
fieldsanswerseventaddress: address,
fieldsanswerseventdate: moment(date).format("DD-MM-YYYY"), fieldsanswerseventdate: moment(date).format("DD-MM-YYYY"),
fieldsanswerseventtime: moment(time).format("HH:mm"), fieldsanswerseventtime: moment(time).format("HH:mm"),
fieldsanswersinstitutename: "E. E. Vagner",
fieldsanswerrinstitutetype: "Escola",
fieldsanswersinstitutename: user.institutionName ? user.institutionName : null,
fieldsanswerrinstitutetype: user.institutionType ? user.institutionType : null
}, },
], ],
}, },
], ],
}, },
}; };
const a = sendFormAnswer(ingestionObject);
const a = sendFormAnswer(pluvResgistrationObject);
}; };
export { export {
AssembleIngestionObject, AssembleIngestionObject,

12
src/app/hooks/useFiltering.js

@ -13,42 +13,42 @@ function useFiltering(location) {
name: "floodZones", name: "floodZones",
socketUrl: new WebSocket( socketUrl: new WebSocket(
endpoint + endpoint +
`type=FLOODZONES_FORM&time=${finalDate}/${initialDate}&lat=${location.lat}&lon=${location.long}&buffer=5000&limit=5`
`type=FLOODZONES_FORM&time=${finalDate}/${initialDate}&lat=${location.lat}&lon=${location.long}&buffer=50000&limit=15`
), ),
}, },
{ {
name: "rain", name: "rain",
socketUrl: new WebSocket( socketUrl: new WebSocket(
endpoint + endpoint +
`type=RAIN_FORM&time=${finalDate}/${initialDate}&lat=${location.lat}&lon=${location.long}&buffer=50000&limit=30`
`type=RAIN_FORM&time=${finalDate}/${initialDate}&lat=${location.lat}&lon=${location.long}&buffer=50000&limit=15`
), ),
}, },
{ {
name: "riverFlood", name: "riverFlood",
socketUrl: new WebSocket( socketUrl: new WebSocket(
endpoint + endpoint +
`type=RIVERFLOOD_FORM&time=${finalDate}/${initialDate}&lat=${location.lat}&lon=${location.long}&buffer=50000&limit=5`
`type=RIVERFLOOD_FORM&time=${finalDate}/${initialDate}&lat=${location.lat}&lon=${location.long}&buffer=50000&limit=15`
), ),
}, },
{ {
name: "pluviometer", name: "pluviometer",
socketUrl: new WebSocket( socketUrl: new WebSocket(
endpoint + endpoint +
`type=PLUVIOMETER_REGISTRATION&time=${finalDate}/${initialDate}&lat=${location.lat}&lon=${location.long}&buffer=50000&limit=5`
`type=PLUVIOMETER_REGISTRATION&lat=${location.lat}&lon=${location.long}&buffer=50000&limit=15`
), ),
}, },
{ {
name: "susceptibilityAreas", name: "susceptibilityAreas",
socketUrl: new WebSocket( socketUrl: new WebSocket(
endpoint + endpoint +
`type=FLOODZONES_OFFICIAL&lat=${location.lat}&lon=${location.long}&buffer=50000&limit=15`
`type=FLOODZONES_OFFICIAL&lat=${location.lat}&lon=${location.long}&buffer=50000&limit=10`
), ),
}, },
{ {
name: "automaticPluviometer", name: "automaticPluviometer",
socketUrl: new WebSocket( socketUrl: new WebSocket(
endpoint + endpoint +
`type=PLUVIOMETERS_OFFICIAL&lat=${location.lat}&lon=${location.long}&buffer=500000&limit=10`
`type=PLUVIOMETERS_OFFICIAL&lat=${location.lat}&lon=${location.long}&buffer=50000&limit=15`
), ),
}, },
]; ];

42
src/app/hooks/useSocketMarkers.js

@ -82,46 +82,6 @@ function getImage(name, situation) {
} }
} }
function getLogo(name, situation) {
if (name == "automaticPluviometer") {
return custom_assets.officialPluviometer;
}
if (name == "pluviometer") {
return custom_assets.pluviometer;
}
if (name == "rain") {
if (situation == "sem chuva") {
return custom_assets.rainLevel[0];
} else if (situation == "chuva fraca") {
return custom_assets.rainLevel[1];
} else if (situation == "chuva moderada") {
return custom_assets.rainLevel[2];
} else if (situation == "chuva forte") {
return custom_assets.rainLevel[3];
} else {
return custom_assets.rainLevel[3];
}
}
if (name == "riverFlood") {
if (situation == "baixo") {
return custom_assets.riverLevel[0];
} else if (situation == "normal") {
return custom_assets.riverLevel[1];
} else if (situation == "alto") {
return custom_assets.riverLevel[2];
} else if (situation == "inundar") {
return custom_assets.riverLevel[3];
}
return custom_assets.riverLevel[0];
}
if (name == "floodZones") {
return custom_assets.floodZones;
}
}
function buildPolygonsObject(response, name) { function buildPolygonsObject(response, name) {
var r = JSON.parse(response); var r = JSON.parse(response);
var coordinate = []; var coordinate = [];
@ -155,7 +115,7 @@ function buildPolygonsObject(response, name) {
function buildMarkerObject(response, name) { function buildMarkerObject(response, name) {
const r = JSON.parse(response); const r = JSON.parse(response);
console.log(r);
// console.log(r);
const resposta = r.formsanswersgeom; const resposta = r.formsanswersgeom;
const formsanswersgeom = JSON.parse(resposta).coordinates; const formsanswersgeom = JSON.parse(resposta).coordinates;
var situation = null; var situation = null;

5
src/app/screens/MapFormScreen.js

@ -33,8 +33,11 @@ const MapFormScreen = (props) => {
const setLocation = () => { const setLocation = () => {
getAddress(moveEndListener).then((addr) => { getAddress(moveEndListener).then((addr) => {
if (props.route.params && props.route.params.setLocationAddr)
if (props.route.params && props.route.params.setLocationAddr){
props.route.params.setLocationAddr(addr); props.route.params.setLocationAddr(addr);
if(props.route.params.setGeoLocation){
props.route.params.setGeoLocation(moveEndListener);
}}
else else
context.saveNewLocation(addr, moveEndListener); context.saveNewLocation(addr, moveEndListener);
}); });

33
src/app/screens/PluviometerRegisterScreen.js

@ -35,9 +35,12 @@ function Institution({ user }) {
); );
} }
function LocationPicker({ navigation }) {
const [location, setLocationAddr] = useState("Defina o endereço no mapa");
function LocationPicker({
navigation,
location,
setLocationAddr,
setGeoLocation,
}) {
return ( return (
<View <View
style={{ style={{
@ -65,6 +68,7 @@ function LocationPicker({ navigation }) {
onPress={() => onPress={() =>
navigation.navigate("FormMap", { navigation.navigate("FormMap", {
setLocationAddr: setLocationAddr, setLocationAddr: setLocationAddr,
setGeoLocation: setGeoLocation,
}) })
} }
> >
@ -90,6 +94,8 @@ function LocationPicker({ navigation }) {
function PluviometerRegisterScreen(props) { function PluviometerRegisterScreen(props) {
const [date, setDate] = useState(moment()); const [date, setDate] = useState(moment());
const [time, setTime] = useState(moment()); const [time, setTime] = useState(moment());
const [location, setLocationAddr] = useState("Defina o endereço no mapa");
const [coordinates, setCoordinates] = useState(null);
const { user, _ } = useContext(AuthContext); const { user, _ } = useContext(AuthContext);
return ( return (
@ -97,13 +103,13 @@ function PluviometerRegisterScreen(props) {
<Form <Form
initialValues={{}} initialValues={{}}
onSubmit={() => { onSubmit={() => {
showMessage({
message: "Ainda não implementado",
duration: 1950,
icon: "warning",
type: "warning",
onPress: () => {AssembleIngestionPluvRegistration(date, time, user)},
});
AssembleIngestionPluvRegistration(
date,
time,
user,
location,
coordinates
);
}} }}
> >
<View padding={16}> <View padding={16}>
@ -137,7 +143,12 @@ function PluviometerRegisterScreen(props) {
</View> </View>
<Text style={styles.label}>Endereço do pluviômetro*: </Text> <Text style={styles.label}>Endereço do pluviômetro*: </Text>
<LocationPicker navigation={props.navigation} />
<LocationPicker
navigation={props.navigation}
location={location}
setLocationAddr={setLocationAddr}
setGeoLocation={setCoordinates}
/>
{user.institutionType && <Institution user={user} />} {user.institutionType && <Institution user={user} />}

3
src/app/screens/PluviometerSharingDataScreen.js

@ -28,6 +28,7 @@ const validationSchema = Yup.object().shape({
}); });
function PluviometerSharingDataScreen(props) { function PluviometerSharingDataScreen(props) {
const user = props.route.params.user;
const context = useContext(EventLocationContext); const context = useContext(EventLocationContext);
const [date, setDate] = useState(moment()); const [date, setDate] = useState(moment());
const [time, setTime] = useState(moment()); const [time, setTime] = useState(moment());
@ -49,7 +50,7 @@ function PluviometerSharingDataScreen(props) {
}} }}
onSubmit={(values) => { onSubmit={(values) => {
// insertPluviometerData({ ...values, dateTime, time }); // insertPluviometerData({ ...values, dateTime, time });
AssembleIngestionPluviometer({ ...values, date, time})
AssembleIngestionPluviometer({ ...values, user, date, time})
showMessage({ showMessage({
message: "Informação enviada!", message: "Informação enviada!",
duration: 3000, duration: 3000,

3
src/app/screens/RainSharingDataScreen.js

@ -25,9 +25,11 @@ const validationSchema = Yup.object().shape({
}); });
function RainSharingDataScreen(props) { function RainSharingDataScreen(props) {
const user = props.route.params.user;
const [rain, setRain] = useState(-1); const [rain, setRain] = useState(-1);
const [rainSituation, setRainSituation] = useState(null); const [rainSituation, setRainSituation] = useState(null);
const [error, setError] = useState(false); const [error, setError] = useState(false);
;
const dims = scaleDimsFromWidth(85, 85, 27); const dims = scaleDimsFromWidth(85, 85, 27);
@ -61,6 +63,7 @@ function RainSharingDataScreen(props) {
{ {
...values, ...values,
}, },
user,
rainSituation, rainSituation,
code, code,
location, location,

2
src/app/screens/RiverFloodSharingDataScreen.js

@ -25,6 +25,7 @@ const validationSchema = Yup.object().shape({
}); });
function RiverFloodSharingDataScreen(props) { function RiverFloodSharingDataScreen(props) {
const user = props.route.params.user;
const [riverScale, setRiverScale] = useState(-1); const [riverScale, setRiverScale] = useState(-1);
const [riverSituation, setRiverSituation] = useState(null); const [riverSituation, setRiverSituation] = useState(null);
@ -64,6 +65,7 @@ function RiverFloodSharingDataScreen(props) {
{ {
...values, ...values,
}, },
user,
riverSituation, riverSituation,
code, code,
location, location,

11
src/app/screens/SharingDataScreen.js

@ -13,6 +13,7 @@ function SharingDataScreen({ navigation }) {
const [showLog, setShowLog] = useState(false); const [showLog, setShowLog] = useState(false);
const isRegistered = authContext.user?.username != null; const isRegistered = authContext.user?.username != null;
const currentUser = authContext.user;
return ( return (
<View style={styles.container}> <View style={styles.container}>
@ -36,14 +37,16 @@ function SharingDataScreen({ navigation }) {
label={"ÁREA DE \nALAGAMENTO"} label={"ÁREA DE \nALAGAMENTO"}
style={{ marginRight: 24 }} style={{ marginRight: 24 }}
SvgImage={assets.floodZones.FloodZonesIcon} SvgImage={assets.floodZones.FloodZonesIcon}
onPress={() => navigation.navigate("FloodSharingData")}
onPress={() => navigation.navigate("FloodSharingData", { user: currentUser })}
active={isRegistered} active={isRegistered}
inactiveOnPress={() => setShowLog(true)} inactiveOnPress={() => setShowLog(true)}
/> />
<SvgLabeledButton <SvgLabeledButton
label={"CHUVA"} label={"CHUVA"}
onPress={() => navigation.navigate("RainSharingData")}
onPress={() =>
navigation.navigate("RainSharingData", { user: currentUser })
}
SvgImage={assets.rainLevel.RainIcon} SvgImage={assets.rainLevel.RainIcon}
active={isRegistered} active={isRegistered}
inactiveOnPress={() => setShowLog(true)} inactiveOnPress={() => setShowLog(true)}
@ -61,7 +64,7 @@ function SharingDataScreen({ navigation }) {
<SvgLabeledButton <SvgLabeledButton
style={{ marginRight: 24 }} style={{ marginRight: 24 }}
label={"DIÁRIO DO\nPLUVIÔMETRO"} label={"DIÁRIO DO\nPLUVIÔMETRO"}
onPress={() => navigation.navigate("PluviometerSharingData")}
onPress={() => navigation.navigate("PluviometerSharingData", { user: currentUser })}
SvgImage={assets.PluviometerIcon} SvgImage={assets.PluviometerIcon}
active={isRegistered} active={isRegistered}
inactiveOnPress={() => setShowLog(true)} inactiveOnPress={() => setShowLog(true)}
@ -69,7 +72,7 @@ function SharingDataScreen({ navigation }) {
<SvgLabeledButton <SvgLabeledButton
label={"NÍVEL ÁGUA\nNO RIO"} label={"NÍVEL ÁGUA\nNO RIO"}
onPress={() => navigation.navigate("RiverFloodData")}
onPress={() => navigation.navigate("RiverFloodData", { user: currentUser })}
SvgImage={assets.riverLevel.RiverIcon} SvgImage={assets.riverLevel.RiverIcon}
active={isRegistered} active={isRegistered}
inactiveOnPress={() => setShowLog(true)} inactiveOnPress={() => setShowLog(true)}

2
src/app/screens/SharingFloodZonesScreen.js

@ -24,6 +24,7 @@ const validationSchema = Yup.object().shape({
}); });
function SharingFloodZonesScreen(props) { function SharingFloodZonesScreen(props) {
const user = props.route.params.user;
const [passable, setPassable] = useState(-1); const [passable, setPassable] = useState(-1);
const [floodSituation, setFloodSituation] = useState(null); const [floodSituation, setFloodSituation] = useState(null);
@ -62,6 +63,7 @@ function SharingFloodZonesScreen(props) {
{ {
...values, ...values,
}, },
user,
floodSituation, floodSituation,
code, code,
location, location,

Loading…
Cancel
Save