Skip to content
Snippets Groups Projects
Commit 1947dacb authored by Daniel Høyland's avatar Daniel Høyland
Browse files

fixed some bugs so that adding and edit sensor is possible

parent c34603c7
Branches sensorManagement
No related tags found
2 merge requests!71Dev branch,!69fixed some bugs so that adding and edit sensor is possible
......@@ -58,8 +58,9 @@ func NewHotDrop(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusBadRequest)
return
}
department := 0 //check if it is intended to have a department, if not, skip
if data.DepartmentName != "" {
if data.DepartmentName != "" && data.DepartmentName != " " {
department, err = other.GetDepartmentIdByName(data.DepartmentName, building)
if err != nil {
log.Println(err.Error())
......
......@@ -349,7 +349,8 @@ function ManageSensors() {
<FormItem>
<FormLabel>EUI</FormLabel>
<FormControl>
<Input placeholder="EUI" {...field} />
{ /* REMOVED {...field} from the under*/ }
<Input placeholder="EUI" />
</FormControl>
<FormDescription>
The id code found under "MAC" on sensor
......@@ -364,7 +365,8 @@ function ManageSensors() {
<FormItem>
<FormLabel>Name</FormLabel>
<FormControl>
<Input placeholder="Name" {...field} />
{ /* REMOVED {...field} from the under*/ }
<Input placeholder="Name" />
</FormControl>
</FormItem>
)}
......@@ -376,7 +378,8 @@ function ManageSensors() {
<FormItem>
<FormLabel>Nr</FormLabel>
<FormControl>
<Input placeholder="Nr" {...field} />
{ /* REMOVED {...field} from the under*/ }
<Input placeholder="Nr" />
</FormControl>
<FormDescription>
Custom machine nr
......@@ -390,7 +393,8 @@ function ManageSensors() {
render={({ field }) => (
<FormItem>
<FormLabel>Building</FormLabel>
<Select onValueChange={field.onChange} defaultValue={field.value}>
{ /* REMOVED defaultValue={field.value} from the under*/ }
<Select onValueChange={field.onChange} >
<FormControl>
<SelectTrigger>
<SelectValue placeholder="Building" />
......@@ -409,26 +413,28 @@ function ManageSensors() {
)}
/>
{ /* If a building is selected, render department picker */ }
{ (watchBuilding != "null") ? (
{ (watchBuilding != "") ? (
<FormField
control={form.control}
name='dept'
render={({ field }) => (
<FormItem>
<FormLabel>Department</FormLabel>
<Select onValueChange={field.onChange} defaultValue={field.value}>
{ /* REMOVED defaultValue={field.value} from the under*/ }
<Select onValueChange={field.onChange} >
<FormControl>
<SelectTrigger>
<SelectValue placeholder="Department" />
</SelectTrigger>
</FormControl>
<SelectContent>
<SelectItem key={1} value={" "}> </SelectItem>
{ buildDepData.buildingDepartmentData.map((building, index) => {
if (index == 0) return (<></>)
if (building.building.name === watchBuilding) return (
<div key={index}>
{ building.departments.map((dept, index) => {
if (index == 0) return (<></>)
if (index == -1) return (<></>)
else return (
<SelectItem key={index} value={dept.name}>{dept.name}</SelectItem>
)
......@@ -451,7 +457,8 @@ function ManageSensors() {
<FormItem>
<FormLabel>Expected power usage</FormLabel>
<FormControl>
<Input type="number" placeholder="0" {...field} />
{ /* REMOVED {...field} from the under*/ }
<Input type="number" placeholder="0" />
</FormControl>
</FormItem>
)}
......@@ -517,7 +524,7 @@ function ManageSensors() {
<FormItem>
<FormLabel>EUI</FormLabel>
<FormControl>
<Input placeholder={machine.eui} {...field} />
<Input defaultValue={machine.eui} {...field} />
</FormControl>
</FormItem>
)}
......@@ -529,7 +536,7 @@ function ManageSensors() {
<FormItem>
<FormLabel>Name</FormLabel>
<FormControl>
<Input placeholder={machine.machine_name} {...field} />
<Input defaultValue={machine.machine_name} {...field} />
</FormControl>
</FormItem>
)}
......@@ -541,7 +548,7 @@ function ManageSensors() {
<FormItem>
<FormLabel>Nr</FormLabel>
<FormControl>
<Input placeholder={machine.machineNr} {...field} />
<Input defaultValue={machine.machineNr} {...field} />
</FormControl>
</FormItem>
)}
......@@ -552,10 +559,10 @@ function ManageSensors() {
render={({ field }) => (
<FormItem>
<FormLabel>Building</FormLabel>
<Select onValueChange={field.onChange} defaultValue={field.value}>
<Select onValueChange={field.onChange} defaultValue={machine.building_name}>
<FormControl>
<SelectTrigger>
<SelectValue placeholder={machine.building_name} />
<SelectValue />
</SelectTrigger>
</FormControl>
<SelectContent>
......@@ -576,22 +583,23 @@ function ManageSensors() {
render={({ field }) => (
<FormItem>
<FormLabel>Department</FormLabel>
<Select onValueChange={field.onChange} defaultValue={field.value}>
<Select onValueChange={field.onChange} defaultValue={machine.department_name}>
<FormControl>
<SelectTrigger>
<SelectValue placeholder={machine.department_name} />
<SelectValue />
</SelectTrigger>
</FormControl>
<FormDescription>
{"Please select building first to change department : )"}
</FormDescription>
<SelectContent>
<SelectItem key={1} value={" "}></SelectItem>
{ buildDepData.buildingDepartmentData.map((building, index) => {
if (index == 0) return (<></>)
if (building.building.name === watchBuilding) return (
<div key={index}>
{ building.departments.map((dept, index) => {
if (index == 0) return (<></>)
if (index == -1) return (<></>)
else return (
<SelectItem key={index} value={dept.name}>{dept.name}</SelectItem>
)
......@@ -612,7 +620,7 @@ function ManageSensors() {
<FormItem>
<FormLabel>Expected power usage</FormLabel>
<FormControl>
<Input type="number" placeholder="0" {...field} />
<Input type="number" defaultValue={machine.expected_use} {...field} />
</FormControl>
</FormItem>
)}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment