Introduction of Room assignments

This commit is contained in:
Ziver Koc 2023-01-06 23:54:53 +01:00
parent b5ac492414
commit 7a90189927
21 changed files with 707 additions and 130 deletions

View file

@ -1,6 +1,39 @@
{
"components": {
"schemas": {
"eventClass": {
"type": "object",
"properties": {
"data": {
"type": "object",
"$ref": "#/components/schemas/dataClass"
},
"name": {"type": "string"},
"id": {"type": "integer"},
"map": {
"type": "object",
"$ref": "#/components/schemas/mapClass"
},
"user": {"type": "string"},
"config": {
"type": "object",
"$ref": "#/components/schemas/configClass"
}
}
},
"roomClass": {
"type": "object",
"properties": {
"id": {"type": "integer"},
"name": {"type": "string"},
"map": {
"type": "object",
"$ref": "#/components/schemas/mapClass"
}
}
},
"sensorClass": {
"type": "object",
"properties": {
@ -10,8 +43,10 @@
},
"name": {"type": "string"},
"id": {"type": "integer"},
"map_x": {"type": "number"},
"map_y": {"type": "number"},
"map": {
"type": "object",
"$ref": "#/components/schemas/mapClass"
},
"user": {"type": "string"},
"config": {
"type": "object",
@ -36,24 +71,6 @@
}
}
},
"eventClass": {
"type": "object",
"properties": {
"data": {
"type": "object",
"$ref": "#/components/schemas/dataClass"
},
"name": {"type": "string"},
"id": {"type": "integer"},
"map_x": {"type": "number"},
"map_y": {"type": "number"},
"user": {"type": "string"},
"config": {
"type": "object",
"$ref": "#/components/schemas/configClass"
}
}
},
"configClass": {
"type": "object",
@ -62,6 +79,7 @@
"typeData": {"type": "string"}
}
},
"dataClass": {
"type": "object",
"properties": {
@ -69,16 +87,29 @@
"value": {"type": "number"},
"timestamp": {"type": "integer"}
}
}
},
"mapClass": {
"type": "object",
"properties": {
"x": {"type": "number"},
"y": {"type": "number"},
"width": {"type": "number"},
"height": {"type": "number"}
}
},
}
},
"servers": [
{
"description": "Hal Server",
"url": "/api"
}
],
"openapi": "3.0.1",
"paths": {
"/event": {
"get": {
@ -123,6 +154,35 @@
]
}
},
"/room": {
"get": {
"responses": {
"200": {
"description": "A successful response.",
"content": {
"application/json": {
"schema": {
"type": "object",
"$ref": "#/components/schemas/roomClass"
}
}
}
}
},
"parameters": [
{
"schema": {
"type": "integer"
},
"in": "query",
"name": "id",
"required": false
}
]
}
},
"/sensor": {
"get": {
"responses": {

View file

@ -35,6 +35,7 @@
data-target="#eventModal"
data-action="modify_local_event"
data-id="{{.getId()}}"
data-room-id="{{.getRoom().getId()}}"
data-name="{{.getName()}}"
data-type="{{.getType()}}"
{{#.getDeviceConfigurator().getConfiguration()}}
@ -125,6 +126,16 @@
<div class="modal-body">
<input type="hidden" id="action" name="action">
<input type="hidden" id="id" name="id">
<div class="form-group">
<label class="control-label">Located in room:</label>
<select class="form-control" name="room-id">
<option value=""></option>
{{#rooms}}
<option value="{{.getId()}}">{{.getName()}} (id: {{.getId()}})</option>
{{/rooms}}
</select>
</div>
<div class="form-group">
<label class="control-label">Name:</label>
<input type="text" class="form-control" name="name">

View file

@ -167,26 +167,24 @@ function initDynamicModalForm(modalId, formTemplateId = null, templateID = null)
var button = $(event.relatedTarget);
var modal = $(this);
// Reset all inputs
if (formTemplateId != null)
modal.find("#" + formTemplateId).empty(); // clear form div
modal.find(" input, select").val('').change(); // Reset all inputs
// set dynamic form data
// Set dynamic form data
$.each(button.attr(), function(fieldName, value) {
if(fieldName.startsWith("data-")) {
fieldName = fieldName.substring(5); // remove prefix data-
// case insensitive search
// Case-insensitive search
var input = modal.find("input, select").filter(function() {
if (this.name.toLowerCase() == fieldName) {
if (this.type == "hidden" && modal.find("input[type=checkbox][name=" + fieldName + "]") != null)
if (this.type == "hidden" && modal.find("input[type=checkbox][name=" + fieldName + "]").length > 0)
return false; // Workaround for the default(false) boolean input
return true;
}
return false;
});
if (input != null) {
if (input.length > 0) {
if (input.prop("type") == "checkbox") { // special handling for checkboxes
input.prop("value", "true");
input.prop("checked", value == "true");
@ -196,10 +194,7 @@ function initDynamicModalForm(modalId, formTemplateId = null, templateID = null)
input.parent().prepend("<input type='hidden' name='" + input.prop("name") + "' value='false' />");
}
} else {
input.val(value);
if (input.prop("tagName") == "SELECT")
input.change(); // required for select elements to update properly
input.val(value).change();
}
}
}

View file

@ -0,0 +1,86 @@
<h1 class="page-header">Room Configuration</h1>
<div class="col-md-12">
<div class="panel panel-default drop-shadow">
<div class="panel-heading">Rooms</div>
<div class="panel-body">
<p>This is a list of all configured rooms.</p>
<table class="table table-hover table-condensed">
<thead>
<th style="width: 50px;">#</th>
<th>Name</th>
<th>
<button class="btn btn-default btn-xs pull-right" data-toggle="modal"
data-target="#roomModal"
data-action="create_room">
<span class="glyphicon glyphicon-plus"></span>
</button>
</th>
</thead>
{{#rooms}}
<tr>
<td>{{.getId()}}</td>
<td>{{.getName()}}</td>
<td>
<form method="POST">
<input type="hidden" name="id" value="{{.getId()}}">
<div class="btn-toolbar pull-right">
<button type="button" class="btn btn-default btn-xs" data-toggle="modal"
data-target="#roomModal"
data-action="modify_room"
data-id="{{.getId()}}"
data-name="{{.getName()}}"
>
<span class="glyphicon glyphicon-pencil"></span>
</button>
<button type="submit" class="btn btn-danger btn-xs" name="action" value="remove_room">
<span class="glyphicon glyphicon-trash"></span>
</button>
</div>
</form>
</td>
</tr>
{{/rooms}}
</table>
</div>
</div>
</div>
<!------------- MODALS --------------->
<script>
$(function(){
initDynamicModalForm("roomModal");
});
</script>
<div class="modal fade" id="roomModal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span>&times;</span></button>
<h4 class="modal-title">Room</h4>
</div>
<form method="POST">
<div class="modal-body">
<input type="hidden" id="action" name="action">
<input type="hidden" id="id" name="id">
<div class="form-group">
<label class="control-label">Name:</label>
<input type="text" class="form-control" name="name">
</div>
</div>
<div class="modal-footer">
<button type="reset" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-primary">Save</button>
</div>
</form>
</div>
</div>
</div>

View file

@ -34,7 +34,8 @@
<div class="btn-toolbar pull-right">
<button type="button" class="btn btn-default btn-xs" data-toggle="modal" data-target="#sensorModal"
data-action="modify_local_sensor"
data-id="{{.getId()}}"
data-sensor-id="{{.getId()}}"
data-room-id="{{.getRoom().getId()}}"
data-name="{{.getName()}}"
data-type="{{.getType()}}"
data-sync="{{.isSynced()}}"
@ -140,7 +141,7 @@
<div class="btn-toolbar pull-right">
<button type="button" class="btn btn-default btn-xs" data-toggle="modal" data-target="#userModal"
data-action="modify_external_user"
data-id="{{.getId()}}"
data-user-id="{{.getId()}}"
data-hostname="{{.getHostname()}}"
data-port="{{.getPort()}}">
<span class="glyphicon glyphicon-pencil"></span>
@ -225,11 +226,27 @@
<form method="POST">
<div class="modal-body">
<input type="hidden" id="action" name="action" value="">
<input type="hidden" id="id" name="id">
<input type="hidden" id="sensor-id" name="sensor-id">
<div class="form-group">
<label class="control-label">Located in room:</label>
<select class="form-control" name="room-id">
<option value=""></option>
{{#rooms}}
<option value="{{.getId()}}">{{.getName()}} (id: {{.getId()}})</option>
{{/rooms}}
</select>
</div>
<div class="form-group">
<label class="control-label">Name:</label>
<input type="text" class="form-control" name="name">
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="sync" value="true">
Public
</label>
</div>
<div class="form-group">
<label class="control-label">Type:</label>
<select class="form-control" name="type">
@ -238,13 +255,6 @@
{{/availableSensorConfigClasses}}
</select>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="sync" value="true">
Public
</label>
</div>
<hr>
<div id="sensor-data-conf">
@ -290,7 +300,7 @@
<form method="POST">
<div class="modal-body">
<input type="hidden" name="action" value="">
<input type="hidden" name="id">
<input type="hidden" name="user-id">
<div class="form-group">
<label class="control-label">Hostname/IP:</label>
<input type="text" class="form-control" name="hostname">