Commit f2540d85 authored by PDuarte's avatar PDuarte

update geolocations

parent 0aba0ae4
......@@ -25,7 +25,7 @@ const Tables = () => {
const onSubmitHandler = (values) => {
dispatch(
addlocation({
projectid: values.projectid,
idproject: values.idproject,
name: values.name,
order: values.order,
country: values.country,
......@@ -57,16 +57,14 @@ const Tables = () => {
Select Project
</div> : <ElementCard selectedElement={{
id: '<generate>',
projectid: storeNavbar.projectCurrent.value,
title: '',
parentid: null,
parenttype: null,
external_id: '',
textual: [],
genres: [],
subgenres: [],
availability: [],
imagery: []
idproject: storeNavbar.projectCurrent.value,
name: '',
order: 1,
country: '',
state: '',
city: '',
ip: '',
polyline: ''
}}
onSubmitHandler={onSubmitHandler}
/>
......
import { useState } from 'react'
import { useState, useEffect } from 'react'
import { Card, CardHeader, CardTitle, CardBody } from 'reactstrap'
import {
Circle,
......@@ -122,6 +122,30 @@ const MapTooltip = ({gis, handleGis}) => {
}
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 (
<Card>
<CardHeader>
......@@ -154,7 +178,7 @@ const MapTooltip = ({gis, handleGis}) => {
attribution='&ampcopy <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
url='https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'
/>
<Polygon pathOptions={purpleOptions} positions={gis} />
</LeafletMap>
</CardBody>
</Card>
......
......@@ -33,6 +33,7 @@ import MapTooltip from './MapTooltip'
import '@styles/react/apps/app-users.scss'
import '@styles/react/libs/flatpickr/flatpickr.scss'
import '@styles/react/libs/maps/map-leaflet.scss'
import { point } from 'leaflet'
const SuccessProgressToast = () => (
......@@ -126,6 +127,22 @@ const handleError = (text) => {
useEffect(() => {
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)
}
}, [selectedElement])
......@@ -212,16 +229,16 @@ return (
</Col>
<Col md='4' sm='12'>
<FormGroup>
<Label for='name'>Project ID</Label>
<Label for='idproject'>Project ID</Label>
<Input
readOnly={true}
type='text'
name='projectid'
id='projectid'
name='idproject'
id='idproject'
innerRef={register({ required: true })}
placeholder='projectid'
defaultValue={dataElement && dataElement.projectid}
className={classnames({ 'is-invalid': errors['projectid'] })}
placeholder='idproject'
defaultValue={dataElement && dataElement.idproject}
className={classnames({ 'is-invalid': errors['idproject'] })}
/>
</FormGroup>
</Col>
......
......@@ -9,7 +9,7 @@ import Breadcrumbs from '@components/breadcrumbs'
import { Row, Col } from 'reactstrap'
// ** Tables
import ElementEdit from '../card'
import ElementEdit from './main'
// ** Styles
import '@styles/react/libs/tables/react-dataTable-component.scss'
// module settings
......
......@@ -2,7 +2,7 @@ import { useState, useEffect, Fragment } from 'react'
import { useParams, Link } from 'react-router-dom'
// ** Store & Actions
import { getasset, updateasset } from '../../store/actions'
import { getLocation, updateLocation } from '../../store/actions'
import { useSelector, useDispatch } from 'react-redux'
......@@ -16,26 +16,26 @@ import _ from 'lodash'
const ElementEdit = () => {
// ** States & Vars
const store = useSelector(state => state.assets),
const store = useSelector(state => state.projectsettings),
[dataElement, setElementData] = useState(null),
dispatch = useDispatch(),
{ id } = useParams()
const onSubmitHandler = (values, uploadFile) => {
const onSubmitHandler = (values) => {
// console.log(values)
// console.log(uploadFile)
dispatch(
updateasset({
updateLocation({
...dataElement,
idproject: values.idproject,
title: values.title,
parentid: values.parentid,
parenttype: values.parenttype,
external_id: values.external_id,
genres: values.genres,
subgenres: values.subgenres,
data: uploadFile
name: values.name,
order: values.order,
country: values.country,
state: values.state,
city: values.city,
ip: values.ip,
polyline: values.polyline
})
)
......@@ -43,21 +43,21 @@ const ElementEdit = () => {
// ** Function to get user on mount
useEffect(() => {
dispatch(getasset(id))
dispatch(getLocation(id))
}, [dispatch])
// ** Update user image on mount or change
useEffect(() => {
if (store.selectedAsset !== null || (store.selectedAsset !== null && dataElement !== null && store.selectedAsset.id !== dataElement.id)) {
return setElementData(store.selectedAsset)
if (store.selectedLocation !== null || (store.selectedLocation !== null && dataElement !== null && store.selectedLocation.id !== dataElement.id)) {
return setElementData(store.selectedLocation)
}
}, [store.selectedAsset])
}, [store.selectedLocation])
return store.selectedAsset !== null && store.selectedAsset !== undefined ? (
return store.selectedLocation !== null && store.selectedLocation !== undefined ? (
<ElementCard
selectedElement={store.selectedAsset}
selectedElement={store.selectedLocation}
onSubmitHandler={onSubmitHandler}
/>
) : (
......
......@@ -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) => {
selectedProject : action.data
}
case 'UPDATE_PROJECT':
return { ...state }
......@@ -118,6 +119,12 @@ const settings = (state = initialState, action) => {
case 'ADD_LOCATION':
return { ...state }
case 'GET_LOCATION':
return { ...state,
selectedLocation : action.data
}
case 'UPDATE_LOCATION':
return { ...state }
default:
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