Browse Source

River form with "Descrição" field.

master
GabrielTrettel 4 years ago
parent
commit
5c060b78a7
  1. 10
      src/app/database/databaseLoader.js
  2. 10
      src/app/database/db.js
  3. 8
      src/app/hooks/selectFromDB.js
  4. 17
      src/app/screens/RiverFloodSharingDataScreen.js

10
src/app/database/databaseLoader.js

@ -55,8 +55,8 @@ function insertPluviometerData({ pluviometer, images, dateTime, location }) {
transaction(global.userDataBase, query, values); transaction(global.userDataBase, query, values);
} }
function insertRainData({ images, rain, location }) {
const query = `INSERT INTO RainLevel(RainIdx, Images, Latitude, Longitude) VALUES(?, ?, ?, ?);`;
function insertRainData({ images, description, rain, location }) {
const query = `INSERT INTO RainLevel(RainIdx, Description, Images, Latitude, Longitude) VALUES(?, ?, ?, ?, ?);`;
if (location === undefined) { if (location === undefined) {
console.debug("undefined location"); console.debug("undefined location");
@ -65,6 +65,7 @@ function insertRainData({ images, rain, location }) {
const values = [ const values = [
parseInt(rain), parseInt(rain),
description,
JSON.stringify(images), JSON.stringify(images),
parseFloat(location["latitude"]), parseFloat(location["latitude"]),
parseFloat(location["longitude"]), parseFloat(location["longitude"]),
@ -75,8 +76,8 @@ function insertRainData({ images, rain, location }) {
transaction(global.userDataBase, query, values); transaction(global.userDataBase, query, values);
} }
function insertRiverData({ images, riverScale, location }) {
const query = `INSERT INTO RiverLevel(RiverIdx, Images, Latitude, Longitude) VALUES(?, ?, ?, ?);`;
function insertRiverData({ images, description, riverScale, location }) {
const query = `INSERT INTO RiverLevel(RiverIdx, Description, Images, Latitude, Longitude) VALUES(?, ?, ?, ?, ?);`;
if (location === undefined) { if (location === undefined) {
console.debug("undefined location"); console.debug("undefined location");
@ -85,6 +86,7 @@ function insertRiverData({ images, riverScale, location }) {
const values = [ const values = [
parseInt(riverScale), parseInt(riverScale),
description,
JSON.stringify(images), JSON.stringify(images),
parseFloat(location["latitude"]), parseFloat(location["latitude"]),
parseFloat(location["longitude"]), parseFloat(location["longitude"]),

10
src/app/database/db.js

@ -1,7 +1,7 @@
// FIXME: Refactor to our database ERM already combined // FIXME: Refactor to our database ERM already combined
const init_queries = [ const init_queries = [
`CREATE TABLE IF NOT EXISTS FloodZones (
`CREATE TABLE IF NOT EXISTS FloodZones (
Id integer PRIMARY KEY autoincrement, Id integer PRIMARY KEY autoincrement,
Description text, Description text,
Images text, Images text,
@ -9,7 +9,7 @@ const init_queries = [
Longitude real NOT NULL, Longitude real NOT NULL,
Passable INTERGER NOT NULL Passable INTERGER NOT NULL
);`, );`,
`CREATE TABLE IF NOT EXISTS Pluviometer (
`CREATE TABLE IF NOT EXISTS Pluviometer (
Id integer PRIMARY KEY autoincrement, Id integer PRIMARY KEY autoincrement,
Date text NOT NULL, Date text NOT NULL,
Images text, Images text,
@ -17,15 +17,17 @@ const init_queries = [
Longitude real NOT NULL, Longitude real NOT NULL,
Precipitation real NOT NULL Precipitation real NOT NULL
);`, );`,
`CREATE TABLE IF NOT EXISTS RainLevel (
`CREATE TABLE IF NOT EXISTS RainLevel (
Id integer PRIMARY KEY autoincrement, Id integer PRIMARY KEY autoincrement,
Description text,
RainIdx INTEGER NOT NULL, RainIdx INTEGER NOT NULL,
Images text, Images text,
Latitude real NOT NULL, Latitude real NOT NULL,
Longitude real NOT NULL Longitude real NOT NULL
);`, );`,
`CREATE TABLE IF NOT EXISTS RiverLevel (
`CREATE TABLE IF NOT EXISTS RiverLevel (
Id integer PRIMARY KEY autoincrement, Id integer PRIMARY KEY autoincrement,
Description text,
RiverIdx INTEGER NOT NULL, RiverIdx INTEGER NOT NULL,
Images text, Images text,
Latitude real NOT NULL, Latitude real NOT NULL,

8
src/app/hooks/selectFromDB.js

@ -89,19 +89,19 @@ function parseRiverLevel(row) {
if (!is_valid(row["Id"], "river")) { if (!is_valid(row["Id"], "river")) {
return null; return null;
} }
console.log(JSON.stringify(row));
displacement += offset; displacement += offset;
const riverLevel = ["Baixo", "Rio normal", "Alto", "Transbordando"];
const riverLevel = ["baixo", "normal", "alto", "transbordando"];
const riverIdx = row["RiverIdx"]; const riverIdx = row["RiverIdx"];
return { return {
ID: ++ID, ID: ++ID,
title: "Nível do rio",
title: "Rio" + riverLevel[riverIdx],
coordinate: { coordinate: {
latitude: row["Latitude"], latitude: row["Latitude"],
longitude: row["Longitude"] + displacement, longitude: row["Longitude"] + displacement,
}, },
image: custom_assets.riverLevel[riverIdx], image: custom_assets.riverLevel[riverIdx],
description: riverLevel[riverIdx],
description: row["Description"],
}; };
} }

17
src/app/screens/RiverFloodSharingDataScreen.js

@ -2,7 +2,12 @@ import React, { useState } from "react";
import { StyleSheet, View } from "react-native"; import { StyleSheet, View } from "react-native";
import * as Yup from "yup"; import * as Yup from "yup";
import { Form, FormPicker as Picker, SubmitButton } from "../components/forms";
import {
Form,
FormPicker as Picker,
SubmitButton,
FormField,
} from "../components/forms";
import Screen from "../components/Screen"; import Screen from "../components/Screen";
import FormImagePicker from "../components/forms/FormImagePicker"; import FormImagePicker from "../components/forms/FormImagePicker";
import useLocation from "../hooks/useLocation"; import useLocation from "../hooks/useLocation";
@ -17,6 +22,7 @@ import { scaleDimsFromWidth, dimensions } from "../config/dimensions";
const validationSchema = Yup.object().shape({ const validationSchema = Yup.object().shape({
images: Yup.array(), images: Yup.array(),
description: Yup.string().label("Description"),
}); });
const borderWidth = 4; const borderWidth = 4;
@ -46,6 +52,7 @@ function RiverFloodSharingDataScreen(props) {
<Form <Form
initialValues={{ initialValues={{
images: [], images: [],
description: "",
}} }}
onSubmit={(values) => { onSubmit={(values) => {
if (riverScale == -1) { if (riverScale == -1) {
@ -126,7 +133,13 @@ function RiverFloodSharingDataScreen(props) {
)} )}
<FormImagePicker backgroundColor={colors.primary} name="images" /> <FormImagePicker backgroundColor={colors.primary} name="images" />
<FormField
maxLength={255}
multiline
name="description"
numberOfLines={3}
placeholder="Descrição"
/>
<SubmitButton title="Enviar" backgroundColor={colors.primary} /> <SubmitButton title="Enviar" backgroundColor={colors.primary} />
</Form> </Form>
</KeyboardAwareScrollView> </KeyboardAwareScrollView>

Loading…
Cancel
Save