Browse Source

adding event address to database

master
analuizaff 4 years ago
parent
commit
989ba50128
  1. 5
      src/app/context/CurrentLocationContext.js
  2. 20
      src/app/database/databaseLoader.js
  3. 12
      src/app/database/db.js
  4. 3
      src/app/screens/PluviometerSharingDataScreen.js
  5. 3
      src/app/screens/RainSharingDataScreen.js
  6. 3
      src/app/screens/RiverFloodSharingDataScreen.js
  7. 3
      src/app/screens/SharingFloodZonesScreen.js

5
src/app/context/CurrentLocationContext.js

@ -38,7 +38,12 @@ const CurrentLocationProvider = ({ children }) => {
Location.setGoogleApiKey("AIzaSyD_wuuokS3SVczc8qSASrsBq0E5qIpdyMc");
const address = await Location.reverseGeocodeAsync(coordenadas);
if (address[0] != undefined) {
setCurrentLocation(address[0].street + ", " + address[0].name + "\n" + address[0].district, coordenadas.x);
}
else{//Quando o usuário não da permissão de acesso da localização o geoCode retorna um array vazio
setCurrentLocation("Erro ao carregar localização", coordenadas.x);
}
//console.log(currentLocation);
};

20
src/app/database/databaseLoader.js

@ -18,8 +18,8 @@ function transaction(db, query, values) {
});
}
function insertFloodZone({ images, description, passable, location, date, time }) {
const query = `INSERT INTO FloodZones(Description, Images, Latitude, Longitude, Passable, Date, Time) VALUES(?, ?, ?, ?, ?, ?, ?);`;
function insertFloodZone({ images, description, passable, location, date, time, address }) {
const query = `INSERT INTO FloodZones(Description, Images, Latitude, Longitude, Passable, Date, Time, Address) VALUES(?, ?, ?, ?, ?, ?, ?, ?);`;
if (location === undefined) {
console.debug("undefined location");
return;
@ -33,13 +33,14 @@ function insertFloodZone({ images, description, passable, location, date, time }
parseInt(passable),
moment(date).format("DD/MM/YYYY"),
moment(time).format("HH:MM"),
address,
];
transaction(global.userDataBase, query, values);
}
function insertPluviometerData({ pluviometer, images, dateTime, time, location }) {
const query = `INSERT INTO Pluviometer(Date, Images, Latitude, Longitude, Precipitation) VALUES(?, ?, ?, ?, ?);`;
function insertPluviometerData({ pluviometer, images, dateTime, time, location, address }) {
const query = `INSERT INTO Pluviometer(Date, Images, Latitude, Longitude, Precipitation, Address) VALUES(?, ?, ?, ?, ?, ?);`;
if (location === undefined) {
console.debug("undefined location");
@ -52,13 +53,14 @@ function insertPluviometerData({ pluviometer, images, dateTime, time, location }
parseFloat(location["latitude"]),
parseFloat(location["longitude"]),
parseFloat(pluviometer),
address,
];
transaction(global.userDataBase, query, values);
}
function insertRainData({ images, description, rain, location, date, time }) {
const query = `INSERT INTO RainLevel(RainIdx, Description, Images, Latitude, Longitude, Date, Time) VALUES(?, ?, ?, ?, ?, ?, ?);`;
function insertRainData({ images, description, rain, location, date, time, address }) {
const query = `INSERT INTO RainLevel(RainIdx, Description, Images, Latitude, Longitude, Date, Time, Address) VALUES(?, ?, ?, ?, ?, ?, ?, ?);`;
if (location === undefined) {
console.debug("undefined location");
@ -73,6 +75,7 @@ function insertRainData({ images, description, rain, location, date, time }) {
parseFloat(location["longitude"]),
moment(date).format("DD/MM/YYYY"),
moment(time).format("HH:MM"),
address,
];
console.log(values);
@ -80,8 +83,8 @@ function insertRainData({ images, description, rain, location, date, time }) {
transaction(global.userDataBase, query, values);
}
function insertRiverData({ images, description, riverScale, location, date, time }) {
const query = `INSERT INTO RiverLevel(RiverIdx, Description, Images, Latitude, Longitude, Date, Time) VALUES(?, ?, ?, ?, ?, ?, ?);`;
function insertRiverData({ images, description, riverScale, location, date, time, address }) {
const query = `INSERT INTO RiverLevel(RiverIdx, Description, Images, Latitude, Longitude, Date, Time, Address) VALUES(?, ?, ?, ?, ?, ?, ?, ?);`;
if (location === undefined) {
console.debug("undefined location");
@ -96,6 +99,7 @@ function insertRiverData({ images, description, riverScale, location, date, time
parseFloat(location["longitude"]),
moment(date).format("DD/MM/YYYY"),
moment(time).format("HH:MM"),
address,
];
console.log(values);

12
src/app/database/db.js

@ -9,7 +9,8 @@ const init_queries = [
Longitude real NOT NULL,
Passable INTERGER NOT NULL,
Date text,
Time text
Time text,
Address text
);`,
`CREATE TABLE IF NOT EXISTS Pluviometer (
Id integer PRIMARY KEY autoincrement,
@ -18,7 +19,8 @@ const init_queries = [
Latitude real NOT NULL,
Longitude real NOT NULL,
Precipitation real NOT NULL,
Time text
Time text,
Address text
);`,
`CREATE TABLE IF NOT EXISTS RainLevel (
Id integer PRIMARY KEY autoincrement,
@ -28,7 +30,8 @@ const init_queries = [
Latitude real NOT NULL,
Longitude real NOT NULL,
Date text,
Time text
Time text,
Address text
);`,
`CREATE TABLE IF NOT EXISTS RiverLevel (
Id integer PRIMARY KEY autoincrement,
@ -38,7 +41,8 @@ const init_queries = [
Latitude real NOT NULL,
Longitude real NOT NULL,
Date text,
Time text
Time text,
Address text
);`,
];

3
src/app/screens/PluviometerSharingDataScreen.js

@ -39,6 +39,7 @@ function PluviometerSharingDataScreen(props) {
context.defaultLocation();
}, []);
const location = context.eventCoordinates;
const address = context.eventLocation;
const [dateTime, setDateTime] = useState(moment());
const [time, setTime] = useState(moment());
@ -52,7 +53,7 @@ function PluviometerSharingDataScreen(props) {
images: [],
}}
onSubmit={(values) => {
insertPluviometerData({ ...values, dateTime, time, location });
insertPluviometerData({ ...values, dateTime, time, location, address });
console.log("DATA:" + dateTime);
console.log("HORA:" + time);
showMessage({

3
src/app/screens/RainSharingDataScreen.js

@ -40,6 +40,7 @@ function RainSharingDataScreen(props) {
}, []);
const location = context.eventCoordinates;
const address = context.eventLocation;
return (
<Screen style={styles.container}>
@ -53,7 +54,7 @@ function RainSharingDataScreen(props) {
setError(true);
return;
}
insertRainData({ ...values, rain, location, date, time });
insertRainData({ ...values, rain, location, date, time, address });
showMessage({
message: "Informação enviada!",
duration: 1950,

3
src/app/screens/RiverFloodSharingDataScreen.js

@ -40,6 +40,7 @@ function RiverFloodSharingDataScreen(props) {
context.defaultLocation();
}, []);
const location = context.eventCoordinates;
const address = context.eventLocation;
const [error, setError] = useState(false);
@ -64,7 +65,7 @@ function RiverFloodSharingDataScreen(props) {
setError(true);
return;
}
insertRiverData({ ...values, riverScale, location, date, time });
insertRiverData({ ...values, riverScale, location, date, time, address });
showMessage({
message: "Informação enviada!",
duration: 1950,

3
src/app/screens/SharingFloodZonesScreen.js

@ -38,6 +38,7 @@ function SharingFloodZonesScreen(props) {
const [time, setTime] = useState(moment());
const context = useContext(EventLocationContext);
const address = context.eventLocation;
useEffect(() => {
context.defaultLocation();
@ -60,7 +61,7 @@ function SharingFloodZonesScreen(props) {
setError(true);
return;
}
submitForm({ ...values, passable, location, date, time });
submitForm({ ...values, passable, location, date, time, address });
console.log("DATA: " + moment(date).format("DD/MM/YYYY"));
console.log("HORA: " + moment(time).format("HH:MM"));
showMessage({

Loading…
Cancel
Save