ADD: the api call to create a new Entity
This commit is contained in:
@@ -10,11 +10,11 @@ function EntityControl(props)
|
||||
|
||||
|
||||
|
||||
const [Entity, setEntity] = useState('');
|
||||
const [Entity, setEntity] = useState({});
|
||||
|
||||
const [Course, setCourse] = useState('');
|
||||
// const [Course, setCourse] = useState('');
|
||||
const [CourseInControl, setCourseInControl] = useState(false);
|
||||
const [Speed, setSpeed] = useState();
|
||||
// const [Speed, setSpeed] = useState();
|
||||
|
||||
const [formData, setFormData] = useState({name: "",course: 0,speed: 0,position: [0,0]});
|
||||
|
||||
@@ -30,8 +30,14 @@ function EntityControl(props)
|
||||
|
||||
if(props.Entity !== undefined)
|
||||
{
|
||||
|
||||
setFormData({name:props.Entity.Name,course:props.Entity.Course,speed:props.Entity.Speed,position:props.Entity.Position})
|
||||
if(props.Entity.NewPos !== undefined)
|
||||
{
|
||||
setFormData({name:props.Entity.Name,course:props.Entity.Course,speed:props.Entity.Speed,position:props.Entity.NewPos})
|
||||
}
|
||||
else
|
||||
{
|
||||
setFormData({name:props.Entity.Name,course:props.Entity.Course,speed:props.Entity.Speed,position:props.Entity.Position})
|
||||
}
|
||||
}else{
|
||||
setFormData({name:"",course:"",speed:"",position:['','']})
|
||||
|
||||
@@ -45,6 +51,19 @@ function EntityControl(props)
|
||||
|
||||
},[props.Entity,props]);
|
||||
|
||||
useEffect(() => {
|
||||
if(props.PositionCliecked !== undefined)
|
||||
{
|
||||
console.log(props.PositionCliecked)
|
||||
var pos = [0,0];
|
||||
pos[0] = props.PositionCliecked.lat;
|
||||
pos[1] = props.PositionCliecked.lng
|
||||
setFormData({...formData,position:pos});
|
||||
}
|
||||
|
||||
},[props.PositionCliecked])
|
||||
|
||||
|
||||
|
||||
|
||||
// Entity.Entity.Course
|
||||
@@ -76,11 +95,16 @@ const handleClick = (e) => {
|
||||
}
|
||||
};
|
||||
|
||||
const handleNameInput = (e) => {
|
||||
setFormData({...formData,name:e.currentTarget.value});
|
||||
|
||||
}
|
||||
|
||||
const emptyForm= (e) =>
|
||||
{
|
||||
|
||||
setFormData({name:'',course:'',speed:'',position:['','']})
|
||||
setEntity('')
|
||||
setEntity(undefined)
|
||||
|
||||
}
|
||||
|
||||
@@ -91,8 +115,37 @@ const handleClick = (e) => {
|
||||
|
||||
const handleSubmit = (e) => {
|
||||
e.preventDefault();
|
||||
console.log(e.target.data);
|
||||
console.log(formData)
|
||||
// console.log(e.target.data);
|
||||
// console.log(formData)
|
||||
console.log(Entity)
|
||||
if(Entity === undefined)
|
||||
{
|
||||
var msg =
|
||||
{
|
||||
Data: "Entity",
|
||||
Type: "New",
|
||||
Speed: formData.speed,
|
||||
Course: formData.course,
|
||||
Position: formData.position
|
||||
|
||||
}
|
||||
|
||||
}else {
|
||||
var msg =
|
||||
{
|
||||
Data: "Entity",
|
||||
Type: "Update",
|
||||
ID: Entity.id,
|
||||
Speed: formData.speed,
|
||||
Course: formData.course,
|
||||
Position: formData.position
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
console.log(msg);
|
||||
|
||||
// props.Client.send(JSON.stringify(msg));
|
||||
// alert(`Course: ${formData.course}`);
|
||||
}
|
||||
// console.log(Entity)
|
||||
@@ -107,7 +160,7 @@ const handleClick = (e) => {
|
||||
<div class="parent">
|
||||
<div class="div1">
|
||||
<div class="NameInput">
|
||||
<input className="EntityinputField NameInput" name="Name" readOnly={false} type="text" maxLength={3} onClick={handleClick} onChange={handleCourseInput} value={formData.name} />
|
||||
<input className="EntityinputField NameInput" name="Name" type="text" onChange={handleNameInput} value={formData.name} />
|
||||
</div>
|
||||
</div>
|
||||
<div class="div2">
|
||||
|
||||
Reference in New Issue
Block a user