Browse Source

adding date and time to database

master
analuizaff 4 years ago
parent
commit
7ec01b7de6
  1. 18
      src/app/database/databaseLoader.js
  2. 10
      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) { if (location === undefined) {
console.debug("undefined location"); console.debug("undefined location");
return; return;
@ -31,6 +31,8 @@ function insertFloodZone({ images, description, passable, location }) {
parseFloat(location["latitude"]), parseFloat(location["latitude"]),
parseFloat(location["longitude"]), parseFloat(location["longitude"]),
parseInt(passable), parseInt(passable),
moment(date).format("DD/MM/YYYY"),
moment(time).format("HH:MM"),
]; ];
transaction(global.userDataBase, query, values); transaction(global.userDataBase, query, values);
@ -55,8 +57,8 @@ function insertPluviometerData({ pluviometer, images, dateTime, time, location }
transaction(global.userDataBase, query, values); 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) { if (location === undefined) {
console.debug("undefined location"); console.debug("undefined location");
@ -69,6 +71,8 @@ function insertRainData({ images, description, rain, location }) {
JSON.stringify(images), JSON.stringify(images),
parseFloat(location["latitude"]), parseFloat(location["latitude"]),
parseFloat(location["longitude"]), parseFloat(location["longitude"]),
moment(date).format("DD/MM/YYYY"),
moment(time).format("HH:MM"),
]; ];
console.log(values); console.log(values);
@ -76,8 +80,8 @@ function insertRainData({ images, description, rain, location }) {
transaction(global.userDataBase, query, values); 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) { if (location === undefined) {
console.debug("undefined location"); console.debug("undefined location");
@ -90,6 +94,8 @@ function insertRiverData({ images, description, riverScale, location }) {
JSON.stringify(images), JSON.stringify(images),
parseFloat(location["latitude"]), parseFloat(location["latitude"]),
parseFloat(location["longitude"]), parseFloat(location["longitude"]),
moment(date).format("DD/MM/YYYY"),
moment(time).format("HH:MM"),
]; ];
console.log(values); console.log(values);

10
src/app/screens/RainSharingDataScreen.js

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

6
src/app/screens/RiverFloodSharingDataScreen.js

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

12
src/app/screens/SharingFloodZonesScreen.js

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

Loading…
Cancel
Save