Commit f2540d85 authored by PDuarte's avatar PDuarte

update geolocations

parent 0aba0ae4
...@@ -25,7 +25,7 @@ const Tables = () => { ...@@ -25,7 +25,7 @@ const Tables = () => {
const onSubmitHandler = (values) => { const onSubmitHandler = (values) => {
dispatch( dispatch(
addlocation({ addlocation({
projectid: values.projectid, idproject: values.idproject,
name: values.name, name: values.name,
order: values.order, order: values.order,
country: values.country, country: values.country,
...@@ -57,16 +57,14 @@ const Tables = () => { ...@@ -57,16 +57,14 @@ const Tables = () => {
Select Project Select Project
</div> : <ElementCard selectedElement={{ </div> : <ElementCard selectedElement={{
id: '<generate>', id: '<generate>',
projectid: storeNavbar.projectCurrent.value, idproject: storeNavbar.projectCurrent.value,
title: '', name: '',
parentid: null, order: 1,
parenttype: null, country: '',
external_id: '', state: '',
textual: [], city: '',
genres: [], ip: '',
subgenres: [], polyline: ''
availability: [],
imagery: []
}} }}
onSubmitHandler={onSubmitHandler} onSubmitHandler={onSubmitHandler}
/> />
......
import { useState } from 'react' import { useState, useEffect } from 'react'
import { Card, CardHeader, CardTitle, CardBody } from 'reactstrap' import { Card, CardHeader, CardTitle, CardBody } from 'reactstrap'
import { import {
Circle, Circle,
...@@ -122,6 +122,30 @@ const MapTooltip = ({gis, handleGis}) => { ...@@ -122,6 +122,30 @@ const MapTooltip = ({gis, handleGis}) => {
} }
const showAdd = gis.length < 1 const showAdd = gis.length < 1
useEffect(() => {
// const test = gis + ''
}, [gis])
// const regExp = /(-?\d+(\.\d+)?)\s*(-?\d+(\.\d+)?)(,?)/
// const matches = gis.match(regExp)
// console.log(matches)
const polygon = [
[
[51.51, -0.12],
[51.51, -0.13],
[51.53, -0.13]
],
[
[51.51, -0.05],
[51.51, -0.07],
[51.53, -0.07]
]
]
const purpleOptions = { color: 'purple' }
return ( return (
<Card> <Card>
<CardHeader> <CardHeader>
...@@ -154,7 +178,7 @@ const MapTooltip = ({gis, handleGis}) => { ...@@ -154,7 +178,7 @@ const MapTooltip = ({gis, handleGis}) => {
attribution='&ampcopy <a href="http://osm.org/copyright">OpenStreetMap</a> contributors' attribution='&ampcopy <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
url='https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png' url='https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'
/> />
<Polygon pathOptions={purpleOptions} positions={gis} />
</LeafletMap> </LeafletMap>
</CardBody> </CardBody>
</Card> </Card>
......
...@@ -33,6 +33,7 @@ import MapTooltip from './MapTooltip' ...@@ -33,6 +33,7 @@ import MapTooltip from './MapTooltip'
import '@styles/react/apps/app-users.scss' import '@styles/react/apps/app-users.scss'
import '@styles/react/libs/flatpickr/flatpickr.scss' import '@styles/react/libs/flatpickr/flatpickr.scss'
import '@styles/react/libs/maps/map-leaflet.scss' import '@styles/react/libs/maps/map-leaflet.scss'
import { point } from 'leaflet'
const SuccessProgressToast = () => ( const SuccessProgressToast = () => (
...@@ -126,6 +127,22 @@ const handleError = (text) => { ...@@ -126,6 +127,22 @@ const handleError = (text) => {
useEffect(() => { useEffect(() => {
if (selectedElement !== null || (selectedElement !== null && dataElement !== null && selectedElement.id !== dataElement.id)) { if (selectedElement !== null || (selectedElement !== null && dataElement !== null && selectedElement.id !== dataElement.id)) {
if (selectedElement.polyline !== null && selectedElement.polyline !== undefined && selectedElement.polyline !== '') {
console.log(selectedElement.polylineis)
const regExp = /(-?\d+(\.\d+)?)\s*(-?\d+(\.\d+)?)(\,?)/gm
const matches = selectedElement.polyline.match(regExp)
const polygon = []
matches.map(point => {
const cords = point.replace(',', '').split(' ')
polygon.push(cords)
console.log(cords)
})
console.log(matches)
handleGis(polygon)
}
return setElementData(selectedElement) return setElementData(selectedElement)
} }
}, [selectedElement]) }, [selectedElement])
...@@ -212,16 +229,16 @@ return ( ...@@ -212,16 +229,16 @@ return (
</Col> </Col>
<Col md='4' sm='12'> <Col md='4' sm='12'>
<FormGroup> <FormGroup>
<Label for='name'>Project ID</Label> <Label for='idproject'>Project ID</Label>
<Input <Input
readOnly={true} readOnly={true}
type='text' type='text'
name='projectid' name='idproject'
id='projectid' id='idproject'
innerRef={register({ required: true })} innerRef={register({ required: true })}
placeholder='projectid' placeholder='idproject'
defaultValue={dataElement && dataElement.projectid} defaultValue={dataElement && dataElement.idproject}
className={classnames({ 'is-invalid': errors['projectid'] })} className={classnames({ 'is-invalid': errors['idproject'] })}
/> />
</FormGroup> </FormGroup>
</Col> </Col>
......
...@@ -9,7 +9,7 @@ import Breadcrumbs from '@components/breadcrumbs' ...@@ -9,7 +9,7 @@ import Breadcrumbs from '@components/breadcrumbs'
import { Row, Col } from 'reactstrap' import { Row, Col } from 'reactstrap'
// ** Tables // ** Tables
import ElementEdit from '../card' import ElementEdit from './main'
// ** Styles // ** Styles
import '@styles/react/libs/tables/react-dataTable-component.scss' import '@styles/react/libs/tables/react-dataTable-component.scss'
// module settings // module settings
......
...@@ -2,7 +2,7 @@ import { useState, useEffect, Fragment } from 'react' ...@@ -2,7 +2,7 @@ import { useState, useEffect, Fragment } from 'react'
import { useParams, Link } from 'react-router-dom' import { useParams, Link } from 'react-router-dom'
// ** Store & Actions // ** Store & Actions
import { getasset, updateasset } from '../../store/actions' import { getLocation, updateLocation } from '../../store/actions'
import { useSelector, useDispatch } from 'react-redux' import { useSelector, useDispatch } from 'react-redux'
...@@ -16,26 +16,26 @@ import _ from 'lodash' ...@@ -16,26 +16,26 @@ import _ from 'lodash'
const ElementEdit = () => { const ElementEdit = () => {
// ** States & Vars // ** States & Vars
const store = useSelector(state => state.assets), const store = useSelector(state => state.projectsettings),
[dataElement, setElementData] = useState(null), [dataElement, setElementData] = useState(null),
dispatch = useDispatch(), dispatch = useDispatch(),
{ id } = useParams() { id } = useParams()
const onSubmitHandler = (values, uploadFile) => { const onSubmitHandler = (values) => {
// console.log(values) // console.log(values)
// console.log(uploadFile) // console.log(uploadFile)
dispatch( dispatch(
updateasset({ updateLocation({
...dataElement, ...dataElement,
idproject: values.idproject, idproject: values.idproject,
title: values.title, name: values.name,
parentid: values.parentid, order: values.order,
parenttype: values.parenttype, country: values.country,
external_id: values.external_id, state: values.state,
genres: values.genres, city: values.city,
subgenres: values.subgenres, ip: values.ip,
data: uploadFile polyline: values.polyline
}) })
) )
...@@ -43,21 +43,21 @@ const ElementEdit = () => { ...@@ -43,21 +43,21 @@ const ElementEdit = () => {
// ** Function to get user on mount // ** Function to get user on mount
useEffect(() => { useEffect(() => {
dispatch(getasset(id)) dispatch(getLocation(id))
}, [dispatch]) }, [dispatch])
// ** Update user image on mount or change // ** Update user image on mount or change
useEffect(() => { useEffect(() => {
if (store.selectedAsset !== null || (store.selectedAsset !== null && dataElement !== null && store.selectedAsset.id !== dataElement.id)) { if (store.selectedLocation !== null || (store.selectedLocation !== null && dataElement !== null && store.selectedLocation.id !== dataElement.id)) {
return setElementData(store.selectedAsset) return setElementData(store.selectedLocation)
} }
}, [store.selectedAsset]) }, [store.selectedLocation])
return store.selectedAsset !== null && store.selectedAsset !== undefined ? ( return store.selectedLocation !== null && store.selectedLocation !== undefined ? (
<ElementCard <ElementCard
selectedElement={store.selectedAsset} selectedElement={store.selectedLocation}
onSubmitHandler={onSubmitHandler} onSubmitHandler={onSubmitHandler}
/> />
) : ( ) : (
......
...@@ -211,3 +211,37 @@ export const addlocation = location => { ...@@ -211,3 +211,37 @@ export const addlocation = location => {
}) })
} }
} }
export const getLocation = id => {
return async dispatch => {
await axios
.get(`${process.env.REACT_APP_API}/api/locations/${id}`)
.then(response => {
dispatch({
type: 'GET_LOCATION',
data: response.data.data
})
})
.catch(err => console.log(err))
}
}
export const updateLocation = location => {
return (dispatch, getState) => {
axios
.put(`${process.env.REACT_APP_API}/api/locations/${location.id}`, location)
.then(response => {
dispatch({
type: 'UPDATE_LOCATION',
location
})
})
.then(() => {
dispatch(setSaveSatus(true))
})
.catch(err => {
dispatch(setErrorMsg(err.response.data.message))
console.log(err.response.data)
})
}
}
...@@ -76,6 +76,7 @@ const settings = (state = initialState, action) => { ...@@ -76,6 +76,7 @@ const settings = (state = initialState, action) => {
selectedProject : action.data selectedProject : action.data
} }
case 'UPDATE_PROJECT': case 'UPDATE_PROJECT':
return { ...state } return { ...state }
...@@ -118,6 +119,12 @@ const settings = (state = initialState, action) => { ...@@ -118,6 +119,12 @@ const settings = (state = initialState, action) => {
case 'ADD_LOCATION': case 'ADD_LOCATION':
return { ...state } return { ...state }
case 'GET_LOCATION':
return { ...state,
selectedLocation : action.data
}
case 'UPDATE_LOCATION':
return { ...state }
default: default:
return state return state
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment