Browse Source
Finishing an MVP from the SharingFloodZone screen with integration on MapFeedScreen.
master
Finishing an MVP from the SharingFloodZone screen with integration on MapFeedScreen.
master
GabrielTrettel
4 years ago
4 changed files with 263 additions and 208 deletions
-
36src/app/database/databaseLoader.js
-
296src/app/database/db.js
-
117src/app/screens/MapFeedScreen.js
-
18src/app/screens/SharingFloodZonesScreen.js
@ -0,0 +1,36 @@ |
|||||
|
import "../config/globals"; |
||||
|
|
||||
|
function transaction(db, query, values) { |
||||
|
db.transaction((tx) => { |
||||
|
tx.executeSql( |
||||
|
query, |
||||
|
values, |
||||
|
(_, results) => { |
||||
|
console.debug("Values inserted successfully" + results.rowsAffected); |
||||
|
}, |
||||
|
(_, err) => { |
||||
|
console.debug("Error while inserting values: " + JSON.stringify(err)); |
||||
|
} |
||||
|
); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
function insertFloodZone({ images, description, passable, location }) { |
||||
|
const query = `INSERT INTO FloodZones(Description, Images, Latitude, Longitude, Passable) VALUES(?, ?, ?, ?, ?);`; |
||||
|
if (location === undefined) { |
||||
|
console.debug("undefined location"); |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
const values = [ |
||||
|
description, |
||||
|
JSON.stringify(images), |
||||
|
parseFloat(location["latitude"]), |
||||
|
parseFloat(location["longitude"]), |
||||
|
parseInt(passable), |
||||
|
]; |
||||
|
|
||||
|
transaction(global.userDataBase, query, values); |
||||
|
} |
||||
|
|
||||
|
export default insertFloodZone; |
@ -1,149 +1,161 @@ |
|||||
const init_queries = [ |
|
||||
`CREATE TABLE IF NOT EXISTS Users (
|
|
||||
Id integer PRIMARY KEY autoincrement, |
|
||||
Email text NOT NULL, |
|
||||
FirstName text NOT NULL, |
|
||||
SurName text NOT NULL, |
|
||||
Avatar text NOT NULL, |
|
||||
Active integer NOT NULL |
|
||||
);`,
|
|
||||
|
|
||||
`CREATE TABLE IF NOT EXISTS Profiles (
|
|
||||
Id integer PRIMARY KEY autoincrement, |
|
||||
Name text NOT NULL, |
|
||||
Active integer NOT NULL |
|
||||
);`,
|
|
||||
|
|
||||
`CREATE TABLE IF NOT EXISTS UsersProfiles (
|
|
||||
Id integer PRIMARY KEY autoincrement, |
|
||||
IdUsers integer NOT NULL, |
|
||||
IdProfiles integer NOT NULL, |
|
||||
Active integer NOT NULL, |
|
||||
FOREIGN KEY (IdUsers) REFERENCES Users (Id), |
|
||||
FOREIGN KEY (IdProfiles) REFERENCES Profiles (Id) |
|
||||
);`,
|
|
||||
|
// FIXME: Refactor to our database ERM already combined
|
||||
|
|
||||
`CREATE TABLE IF NOT EXISTS Permissions (
|
|
||||
Id integer PRIMARY KEY autoincrement, |
|
||||
Name text NOT NULL, |
|
||||
Active integer NOT NULL |
|
||||
);`,
|
|
||||
|
|
||||
`CREATE TABLE IF NOT EXISTS ProfilesPermissions (
|
|
||||
Id integer PRIMARY KEY autoincrement, |
|
||||
IdProfiles integer NOT NULL, |
|
||||
IdPermissions integer NOT NULL, |
|
||||
Active integer NOT NULL, |
|
||||
FOREIGN KEY (IdProfiles) REFERENCES Profiles (Id), |
|
||||
FOREIGN KEY (IdPermissions) REFERENCES Permissions (Id) |
|
||||
);`,
|
|
||||
|
|
||||
`CREATE TABLE IF NOT EXISTS FormsOrigins (
|
|
||||
Id integer PRIMARY KEY autoincrement, |
|
||||
Name text NOT NULL, |
|
||||
Active integer NOT NULL |
|
||||
);`,
|
|
||||
|
|
||||
`CREATE TABLE IF NOT EXISTS Forms (
|
|
||||
Id integer PRIMARY KEY autoincrement, |
|
||||
IdFormsOrigins integer NOT NULL, |
|
||||
Name text NOT NULL, |
|
||||
Description text NOT NULL, |
|
||||
DtCreation TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, |
|
||||
Active integer NOT NULL, |
|
||||
FOREIGN KEY (IdFormsOrigins) REFERENCES FormsOrigins (Id) |
|
||||
);`,
|
|
||||
|
|
||||
`CREATE TABLE IF NOT EXISTS FieldsDataTypes (
|
|
||||
Id integer PRIMARY KEY autoincrement, |
|
||||
Name text NOT NULL, |
|
||||
Description text NOT NULL, |
|
||||
Active integer NOT NULL |
|
||||
);`,
|
|
||||
|
|
||||
`CREATE TABLE IF NOT EXISTS Fields (
|
|
||||
Id integer PRIMARY KEY autoincrement, |
|
||||
IdFieldsDataTypes integer NOT NULL, |
|
||||
Name text NOT NULL, |
|
||||
Description text NOT NULL, |
|
||||
FillingClue text NOT NULL, |
|
||||
Active integer NOT NULL, |
|
||||
FOREIGN KEY (IdFieldsDataTypes) REFERENCES FieldsDataTypes (Id) |
|
||||
);`,
|
|
||||
|
|
||||
`CREATE TABLE IF NOT EXISTS FormsFields (
|
|
||||
Id integer PRIMARY KEY autoincrement, |
|
||||
IdForms integer NOT NULL, |
|
||||
IdFields integer NOT NULL, |
|
||||
Active integer NOT NULL, |
|
||||
FOREIGN KEY (IdForms) REFERENCES Forms (Id), |
|
||||
FOREIGN KEY (IdFields) REFERENCES Fields (Id) |
|
||||
);`,
|
|
||||
|
|
||||
`CREATE TABLE IF NOT EXISTS Alternatives (
|
|
||||
|
const init_queries = [ |
||||
|
`CREATE TABLE IF NOT EXISTS FloodZones (
|
||||
Id integer PRIMARY KEY autoincrement, |
Id integer PRIMARY KEY autoincrement, |
||||
Response text NOT NULL, |
|
||||
ShortResponse text NOT NULL, |
|
||||
Description text NOT NULL, |
Description text NOT NULL, |
||||
Active integer NOT NULL |
|
||||
);`,
|
|
||||
|
|
||||
`CREATE TABLE IF NOT EXISTS FieldsAlternatives (
|
|
||||
Id integer PRIMARY KEY autoincrement, |
|
||||
IdFields integer NOT NULL, |
|
||||
IdAlternatives integer NOT NULL, |
|
||||
Active integer NOT NULL, |
|
||||
FOREIGN KEY (IdFields) REFERENCES Fields (Id), |
|
||||
FOREIGN KEY (IdAlternatives) REFERENCES Alternatives (Id) |
|
||||
);`,
|
|
||||
|
|
||||
`CREATE TABLE IF NOT EXISTS FieldsAnswers (
|
|
||||
Id integer PRIMARY KEY autoincrement, |
|
||||
IdFields integer NOT NULL, |
|
||||
Value text NOT NULL, |
|
||||
DtFilling TIMESTAMP NOT NULL, |
|
||||
Active integer NOT NULL, |
|
||||
FOREIGN KEY (IdFields) REFERENCES Fields (Id) |
|
||||
);`,
|
|
||||
|
|
||||
`CREATE TABLE IF NOT EXISTS UsersInformerFieldsAnswers (
|
|
||||
Id integer PRIMARY KEY autoincrement, |
|
||||
IdUsersInformer integer NOT NULL, |
|
||||
IdFieldsAnswers integer NOT NULL, |
|
||||
Latitude real NULL, |
|
||||
Longitude real NULL, |
|
||||
Active integer NOT NULL, |
|
||||
FOREIGN KEY (IdUsersInformer) REFERENCES Users (Id), |
|
||||
FOREIGN KEY (IdFieldsAnswers) REFERENCES FieldsAnswers (Id) |
|
||||
);`,
|
|
||||
|
|
||||
`CREATE TABLE IF NOT EXISTS UsersEndorsementFieldsAnswers (
|
|
||||
Id integer PRIMARY KEY autoincrement, |
|
||||
IdUsersEndorsement integer NOT NULL, |
|
||||
IdFieldsAnswers integer NOT NULL, |
|
||||
Latitude real NULL, |
|
||||
Longitude real NULL, |
|
||||
IsTrustable integer NOT NULL, |
|
||||
Active integer NOT NULL, |
|
||||
FOREIGN KEY (IdUsersEndorsement) REFERENCES Users (Id), |
|
||||
FOREIGN KEY (IdFieldsAnswers) REFERENCES FieldsAnswers (Id) |
|
||||
);`,
|
|
||||
|
|
||||
`CREATE TABLE IF NOT EXISTS PreliminaryData (
|
|
||||
Id integer PRIMARY KEY autoincrement, |
|
||||
IdFieldsAnswers integer NOT NULL, |
|
||||
DtInsert TIMESTAMP NOT NULL, |
|
||||
Active integer NOT NULL, |
|
||||
FOREIGN KEY (IdFieldsAnswers) REFERENCES FieldsAnswers (Id) |
|
||||
);`,
|
|
||||
|
|
||||
`CREATE TABLE IF NOT EXISTS TrustedData (
|
|
||||
Id integer PRIMARY KEY autoincrement, |
|
||||
IdFieldsAnswers integer NOT NULL, |
|
||||
DtInsert TIMESTAMP NOT NULL, |
|
||||
Active integer NOT NULL, |
|
||||
FOREIGN KEY (IdFieldsAnswers) REFERENCES FieldsAnswers (Id) |
|
||||
|
Images text NOT NULL, |
||||
|
Latitude real NOT NULL, |
||||
|
Longitude real NOT NULL, |
||||
|
Passable INTERGER NOT NULL |
||||
);`,
|
);`,
|
||||
]; |
]; |
||||
|
|
||||
|
// `CREATE TABLE IF NOT EXISTS Users (
|
||||
|
// Id integer PRIMARY KEY autoincrement,
|
||||
|
// Email text NOT NULL,
|
||||
|
// FirstName text NOT NULL,
|
||||
|
// SurName text NOT NULL,
|
||||
|
// Avatar text NOT NULL,
|
||||
|
// Active integer NOT NULL
|
||||
|
// );`,
|
||||
|
|
||||
|
// `CREATE TABLE IF NOT EXISTS Profiles (
|
||||
|
// Id integer PRIMARY KEY autoincrement,
|
||||
|
// Name text NOT NULL,
|
||||
|
// Active integer NOT NULL
|
||||
|
// );`,
|
||||
|
|
||||
|
// `CREATE TABLE IF NOT EXISTS UsersProfiles (
|
||||
|
// Id integer PRIMARY KEY autoincrement,
|
||||
|
// IdUsers integer NOT NULL,
|
||||
|
// IdProfiles integer NOT NULL,
|
||||
|
// Active integer NOT NULL,
|
||||
|
// FOREIGN KEY (IdUsers) REFERENCES Users (Id),
|
||||
|
// FOREIGN KEY (IdProfiles) REFERENCES Profiles (Id)
|
||||
|
// );`,
|
||||
|
|
||||
|
// `CREATE TABLE IF NOT EXISTS Permissions (
|
||||
|
// Id integer PRIMARY KEY autoincrement,
|
||||
|
// Name text NOT NULL,
|
||||
|
// Active integer NOT NULL
|
||||
|
// );`,
|
||||
|
|
||||
|
// `CREATE TABLE IF NOT EXISTS ProfilesPermissions (
|
||||
|
// Id integer PRIMARY KEY autoincrement,
|
||||
|
// IdProfiles integer NOT NULL,
|
||||
|
// IdPermissions integer NOT NULL,
|
||||
|
// Active integer NOT NULL,
|
||||
|
// FOREIGN KEY (IdProfiles) REFERENCES Profiles (Id),
|
||||
|
// FOREIGN KEY (IdPermissions) REFERENCES Permissions (Id)
|
||||
|
// );`,
|
||||
|
|
||||
|
// `CREATE TABLE IF NOT EXISTS FormsOrigins (
|
||||
|
// Id integer PRIMARY KEY autoincrement,
|
||||
|
// Name text NOT NULL,
|
||||
|
// Active integer NOT NULL
|
||||
|
// );`,
|
||||
|
|
||||
|
// `CREATE TABLE IF NOT EXISTS Forms (
|
||||
|
// Id integer PRIMARY KEY autoincrement,
|
||||
|
// IdFormsOrigins integer NOT NULL,
|
||||
|
// Name text NOT NULL,
|
||||
|
// Description text NOT NULL,
|
||||
|
// DtCreation TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||
|
// Active integer NOT NULL,
|
||||
|
// FOREIGN KEY (IdFormsOrigins) REFERENCES FormsOrigins (Id)
|
||||
|
// );`,
|
||||
|
|
||||
|
// `CREATE TABLE IF NOT EXISTS FieldsDataTypes (
|
||||
|
// Id integer PRIMARY KEY autoincrement,
|
||||
|
// Name text NOT NULL,
|
||||
|
// Description text NOT NULL,
|
||||
|
// Active integer NOT NULL
|
||||
|
// );`,
|
||||
|
|
||||
|
// `CREATE TABLE IF NOT EXISTS Fields (
|
||||
|
// Id integer PRIMARY KEY autoincrement,
|
||||
|
// IdFieldsDataTypes integer NOT NULL,
|
||||
|
// Name text NOT NULL,
|
||||
|
// Description text NOT NULL,
|
||||
|
// FillingClue text NOT NULL,
|
||||
|
// Active integer NOT NULL,
|
||||
|
// FOREIGN KEY (IdFieldsDataTypes) REFERENCES FieldsDataTypes (Id)
|
||||
|
// );`,
|
||||
|
|
||||
|
// `CREATE TABLE IF NOT EXISTS FormsFields (
|
||||
|
// Id integer PRIMARY KEY autoincrement,
|
||||
|
// IdForms integer NOT NULL,
|
||||
|
// IdFields integer NOT NULL,
|
||||
|
// Active integer NOT NULL,
|
||||
|
// FOREIGN KEY (IdForms) REFERENCES Forms (Id),
|
||||
|
// FOREIGN KEY (IdFields) REFERENCES Fields (Id)
|
||||
|
// );`,
|
||||
|
|
||||
|
// `CREATE TABLE IF NOT EXISTS Alternatives (
|
||||
|
// Id integer PRIMARY KEY autoincrement,
|
||||
|
// Response text NOT NULL,
|
||||
|
// ShortResponse text NOT NULL,
|
||||
|
// Description text NOT NULL,
|
||||
|
// Active integer NOT NULL
|
||||
|
// );`,
|
||||
|
|
||||
|
// `CREATE TABLE IF NOT EXISTS FieldsAlternatives (
|
||||
|
// Id integer PRIMARY KEY autoincrement,
|
||||
|
// IdFields integer NOT NULL,
|
||||
|
// IdAlternatives integer NOT NULL,
|
||||
|
// Active integer NOT NULL,
|
||||
|
// FOREIGN KEY (IdFields) REFERENCES Fields (Id),
|
||||
|
// FOREIGN KEY (IdAlternatives) REFERENCES Alternatives (Id)
|
||||
|
// );`,
|
||||
|
|
||||
|
// `CREATE TABLE IF NOT EXISTS FieldsAnswers (
|
||||
|
// Id integer PRIMARY KEY autoincrement,
|
||||
|
// IdFields integer NOT NULL,
|
||||
|
// Value text NOT NULL,
|
||||
|
// DtFilling TIMESTAMP NOT NULL,
|
||||
|
// Active integer NOT NULL,
|
||||
|
// FOREIGN KEY (IdFields) REFERENCES Fields (Id)
|
||||
|
// );`,
|
||||
|
|
||||
|
// `CREATE TABLE IF NOT EXISTS UsersInformerFieldsAnswers (
|
||||
|
// Id integer PRIMARY KEY autoincrement,
|
||||
|
// IdUsersInformer integer NOT NULL,
|
||||
|
// IdFieldsAnswers integer NOT NULL,
|
||||
|
// Latitude real NULL,
|
||||
|
// Longitude real NULL,
|
||||
|
// Active integer NOT NULL,
|
||||
|
// FOREIGN KEY (IdUsersInformer) REFERENCES Users (Id),
|
||||
|
// FOREIGN KEY (IdFieldsAnswers) REFERENCES FieldsAnswers (Id)
|
||||
|
// );`,
|
||||
|
|
||||
|
// `CREATE TABLE IF NOT EXISTS UsersEndorsementFieldsAnswers (
|
||||
|
// Id integer PRIMARY KEY autoincrement,
|
||||
|
// IdUsersEndorsement integer NOT NULL,
|
||||
|
// IdFieldsAnswers integer NOT NULL,
|
||||
|
// Latitude real NULL,
|
||||
|
// Longitude real NULL,
|
||||
|
// IsTrustable integer NOT NULL,
|
||||
|
// Active integer NOT NULL,
|
||||
|
// FOREIGN KEY (IdUsersEndorsement) REFERENCES Users (Id),
|
||||
|
// FOREIGN KEY (IdFieldsAnswers) REFERENCES FieldsAnswers (Id)
|
||||
|
// );`,
|
||||
|
|
||||
|
// `CREATE TABLE IF NOT EXISTS PreliminaryData (
|
||||
|
// Id integer PRIMARY KEY autoincrement,
|
||||
|
// IdFieldsAnswers integer NOT NULL,
|
||||
|
// DtInsert TIMESTAMP NOT NULL,
|
||||
|
// Active integer NOT NULL,
|
||||
|
// FOREIGN KEY (IdFieldsAnswers) REFERENCES FieldsAnswers (Id)
|
||||
|
// );`,
|
||||
|
|
||||
|
// `CREATE TABLE IF NOT EXISTS TrustedData (
|
||||
|
// Id integer PRIMARY KEY autoincrement,
|
||||
|
// IdFieldsAnswers integer NOT NULL,
|
||||
|
// DtInsert TIMESTAMP NOT NULL,
|
||||
|
// Active integer NOT NULL,
|
||||
|
// FOREIGN KEY (IdFieldsAnswers) REFERENCES FieldsAnswers (Id)
|
||||
|
// );`,
|
||||
|
// ];
|
||||
|
|
||||
export default init_queries; |
export default init_queries; |
@ -1,63 +1,70 @@ |
|||||
import React from "react"; |
|
||||
|
import React, { useState, useEffect } from "react"; |
||||
import { StyleSheet, View } from "react-native"; |
import { StyleSheet, View } from "react-native"; |
||||
import MapView, { Marker } from "react-native-maps"; |
import MapView, { Marker } from "react-native-maps"; |
||||
|
|
||||
import colors from "../config/colors"; |
import colors from "../config/colors"; |
||||
|
import "../config/globals"; |
||||
|
|
||||
function MapFeedScreen(props) { |
|
||||
return ( |
|
||||
<View style={styles.container}> |
|
||||
<MapView |
|
||||
style={styles.mapStyle} |
|
||||
initialRegion={{ |
|
||||
latitude: -23.657090, |
|
||||
longitude: -46.699260, |
|
||||
latitudeDelta: 0.0922, |
|
||||
longitudeDelta: 0.0421, |
|
||||
}}> |
|
||||
<Marker |
|
||||
coordinate={{ latitude: -23.657090, longitude: -46.699260 }} |
|
||||
image={require("../assets/chuva_peq.png")} |
|
||||
/> |
|
||||
<Marker |
|
||||
coordinate={{ latitude: -23.656282, longitude: -46.682768 }} |
|
||||
image={require("../assets/chuva_peq.png")} |
|
||||
/> |
|
||||
<Marker |
|
||||
coordinate={{ latitude: -23.666712, longitude: -46.687650 }} |
|
||||
image={require("../assets/chuva_peq.png")} |
|
||||
/> |
|
||||
<Marker |
|
||||
coordinate={{ latitude: -23.660848, longitude: -46.704396 }} |
|
||||
image={require("../assets/chuva_peq.png")} |
|
||||
/> |
|
||||
|
|
||||
<Marker |
|
||||
coordinate={{ latitude: -23.634700, longitude: -46.721960 }} |
|
||||
image={require("../assets/pontos_alagamento_peq.png")} |
|
||||
/> |
|
||||
<Marker |
|
||||
coordinate={{ latitude: -23.650861, longitude: -46.721775 }} |
|
||||
image={require("../assets/pontos_alagamento_peq.png")} |
|
||||
/> |
|
||||
</MapView> |
|
||||
</View> |
|
||||
); |
|
||||
|
function parseResult(db_result) { |
||||
|
var warnings = []; |
||||
|
|
||||
|
for (let i = 0; i < db_result.rows.length; ++i) { |
||||
|
var row = db_result.rows.item(i); |
||||
|
warnings.push({ |
||||
|
key: row["Id"], |
||||
|
title: row["Passable"] == 0 ? "Transponível" : "Intransponível", |
||||
|
coordinate: { latitude: row["Latitude"], longitude: row["Longitude"] }, |
||||
|
image: require("../assets/pontos_alagamento_peq.png"), |
||||
|
description: row["Description"], |
||||
|
}); |
||||
} |
} |
||||
|
|
||||
const styles = StyleSheet.create({ |
|
||||
container: { |
|
||||
backgroundColor: colors.black, |
|
||||
flex: 1, |
|
||||
}, |
|
||||
mapStyle: { |
|
||||
position: 'absolute', |
|
||||
top: 0, |
|
||||
left: 0, |
|
||||
right: 0, |
|
||||
bottom: 0 |
|
||||
}, |
|
||||
}); |
|
||||
|
|
||||
export default MapFeedScreen; |
|
||||
|
return warnings; |
||||
|
} |
||||
|
|
||||
|
function MapFeedScreen(props) { |
||||
|
const [warnings, setWarnings] = useState([]); |
||||
|
|
||||
|
useEffect(() => { |
||||
|
global.userDataBase.transaction((tx) => { |
||||
|
tx.executeSql("SELECT * FROM FloodZones;", [], (tx, results) => { |
||||
|
setWarnings(parseResult(results)); |
||||
|
}); |
||||
|
}); |
||||
|
}, []); |
||||
|
|
||||
|
return ( |
||||
|
<View style={styles.container}> |
||||
|
<MapView |
||||
|
style={styles.mapStyle} |
||||
|
initialRegion={{ |
||||
|
// TODO: make this flexible
|
||||
|
latitude: -22.1070263, |
||||
|
longitude: -51.3948396, |
||||
|
latitudeDelta: 0.0922, |
||||
|
longitudeDelta: 0.0421, |
||||
|
}} |
||||
|
> |
||||
|
{warnings.map((val) => { |
||||
|
return <MapView.Marker {...val} />; |
||||
|
})} |
||||
|
</MapView> |
||||
|
</View> |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
const styles = StyleSheet.create({ |
||||
|
container: { |
||||
|
backgroundColor: colors.black, |
||||
|
flex: 1, |
||||
|
}, |
||||
|
mapStyle: { |
||||
|
position: "absolute", |
||||
|
top: 0, |
||||
|
left: 0, |
||||
|
right: 0, |
||||
|
bottom: 0, |
||||
|
}, |
||||
|
}); |
||||
|
|
||||
|
export default MapFeedScreen; |
Write
Preview
Loading…
Cancel
Save
Reference in new issue