Browse Source

adding date and time to database

master
analuizaff 4 years ago
parent
commit
7ec01b7de6
  1. 18
      src/app/database/databaseLoader.js
  2. 8
      src/app/screens/RainSharingDataScreen.js
  3. 6
      src/app/screens/RiverFloodSharingDataScreen.js
  4. 12
      src/app/screens/SharingFloodZonesScreen.js

18
src/app/database/databaseLoader.js

@ -18,8 +18,8 @@ function transaction(db, query, values) {
});
}
function insertFloodZone({ images, description, passable, location }) {
const query = `INSERT INTO FloodZones(Description, Images, Latitude, Longitude, Passable) VALUES(?, ?, ?, ?, ?);`;
function insertFloodZone({ images, description, passable, location, date, time }) {
const query = `INSERT INTO FloodZones(Description, Images, Latitude, Longitude, Passable, Date, Time) VALUES(?, ?, ?, ?, ?, ?, ?);`;
if (location === undefined) {
console.debug("undefined location");
return;
@ -31,6 +31,8 @@ function insertFloodZone({ images, description, passable, location }) {
parseFloat(location["latitude"]),
parseFloat(location["longitude"]),
parseInt(passable),
moment(date).format("DD/MM/YYYY"),
moment(time).format("HH:MM"),
];
transaction(global.userDataBase, query, values);
@ -55,8 +57,8 @@ function insertPluviometerData({ pluviometer, images, dateTime, time, location }
transaction(global.userDataBase, query, values);
}
function insertRainData({ images, description, rain, location }) {
const query = `INSERT INTO RainLevel(RainIdx, Description, Images, Latitude, Longitude) VALUES(?, ?, ?, ?, ?);`;
function insertRainData({ images, description, rain, location, date, time }) {
const query = `INSERT INTO RainLevel(RainIdx, Description, Images, Latitude, Longitude, Date, Time) VALUES(?, ?, ?, ?, ?, ?, ?);`;
if (location === undefined) {
console.debug("undefined location");
@ -69,6 +71,8 @@ function insertRainData({ images, description, rain, location }) {
JSON.stringify(images),
parseFloat(location["latitude"]),
parseFloat(location["longitude"]),
moment(date).format("DD/MM/YYYY"),
moment(time).format("HH:MM"),
];
console.log(values);
@ -76,8 +80,8 @@ function insertRainData({ images, description, rain, location }) {
transaction(global.userDataBase, query, values);
}
function insertRiverData({ images, description, riverScale, location }) {
const query = `INSERT INTO RiverLevel(RiverIdx, Description, Images, Latitude, Longitude) VALUES(?, ?, ?, ?, ?);`;
function insertRiverData({ images, description, riverScale, location, date, time }) {
const query = `INSERT INTO RiverLevel(RiverIdx, Description, Images, Latitude, Longitude, Date, Time) VALUES(?, ?, ?, ?, ?, ?, ?);`;
if (location === undefined) {
console.debug("undefined location");
@ -90,6 +94,8 @@ function insertRiverData({ images, description, riverScale, location }) {
JSON.stringify(images),
parseFloat(location["latitude"]),
parseFloat(location["longitude"]),
moment(date).format("DD/MM/YYYY"),
moment(time).format("HH:MM"),
];
console.log(values);

8
src/app/screens/RainSharingDataScreen.js

@ -34,7 +34,7 @@ function RainSharingDataScreen(props) {
const [error, setError] = useState(false);
const location = useLocation();
const [dateTime, setDateTime] = useState(moment());
const [date, setDate] = useState(moment());
const [time, setTime] = useState(moment());
return (
@ -60,7 +60,7 @@ function RainSharingDataScreen(props) {
setError(true);
return;
}
insertRainData({ ...values, rain, location });
insertRainData({ ...values, rain, location, date, time });
showMessage({
message: "Informação enviada!",
duration: 1950,
@ -171,13 +171,15 @@ function RainSharingDataScreen(props) {
borderWidth: 3,
}}
defaultDate={new Date()}
onDateChange={(value) => setDateTime(value)}
onDateChange={(value) => setDate(value)}
onTimeChange={(value) => setTime(value)}
/>
</View>
{/*Local do evento:*/}
<View style={{ flex: 0.48 }}>
<TouchableOpacity onPress={() => props.navigation.navigate("FormMap")}>
<FormLocationPicker />
</TouchableOpacity>
</View>
</View>

6
src/app/screens/RiverFloodSharingDataScreen.js

@ -35,7 +35,7 @@ function RiverFloodSharingDataScreen(props) {
const location = useLocation();
const [error, setError] = useState(false);
const [dateTime, setDateTime] = useState(moment());
const [date, setDate] = useState(moment());
const [time, setTime] = useState(moment());
return (
@ -65,7 +65,7 @@ function RiverFloodSharingDataScreen(props) {
setError(true);
return;
}
insertRiverData({ ...values, riverScale, location });
insertRiverData({ ...values, riverScale, location, date, time });
showMessage({
message: "Informação enviada!",
duration: 1950,
@ -149,7 +149,7 @@ function RiverFloodSharingDataScreen(props) {
borderWidth: 3,
}}
defaultDate={new Date()}
onDateChange={(value) => setDateTime(value)}
onDateChange={(value) => setDate(value)}
onTimeChange={(value) => setTime(value)}
/>
</View>

12
src/app/screens/SharingFloodZonesScreen.js

@ -7,7 +7,7 @@ import FormImagePicker from "../components/forms/FormImagePicker";
import useLocation from "../hooks/useLocation";
import colors from "../config/colors";
import { scaleDimsFromWidth, dimensions } from "../config/dimensions";
import { TouchableNativeFeedback } from "react-native-gesture-handler";
import { TouchableNativeFeedback, TouchableOpacity } from "react-native-gesture-handler";
import { insertFloodZone } from "../database/databaseLoader";
import { showMessage } from "react-native-flash-message";
import { KeyboardAwareScrollView } from "react-native-keyboard-aware-scroll-view";
@ -32,7 +32,7 @@ function SharingFloodZonesScreen(props) {
const [error, setError] = useState(false);
const location = useLocation();
const [dateTime, setDateTime] = useState(moment());
const [date, setDate] = useState(moment());
const [time, setTime] = useState(moment());
return (
@ -62,7 +62,9 @@ function SharingFloodZonesScreen(props) {
setError(true);
return;
}
submitForm({ ...values, passable, location });
submitForm({ ...values, passable, location, date, time });
console.log("DATA: " + moment(date).format("DD/MM/YYYY"));
console.log("HORA: " + moment(time).format("HH:MM"));
showMessage({
message: "Informação enviada!",
duration: 1950,
@ -116,13 +118,15 @@ function SharingFloodZonesScreen(props) {
borderWidth: 3,
}}
defaultDate={new Date()}
onDateChange={(value) => setDateTime(value)}
onDateChange={(value) => setDate(value)}
onTimeChange={(value) => setTime(value)}
/>
</View>
{/*Local do evento:*/}
<View style={{ flex: 0.48 }}>
<TouchableOpacity onPress={() => props.navigation.navigate("FormMap")}>
<FormLocationPicker />
</TouchableOpacity>
</View>
</View>

Loading…
Cancel
Save