-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from N5GEH/15-work-on-devices-app
work on devices app
- Loading branch information
Showing
15 changed files
with
763 additions
and
3 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class DevicesConfig(AppConfig): | ||
default_auto_field = "django.db.models.BigAutoField" | ||
name = "devices" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
from crispy_forms.helper import FormHelper | ||
from crispy_forms.layout import Layout, Div, HTML | ||
from django import forms | ||
from django.forms import formset_factory | ||
from filip.models.ngsi_v2.iot import DataType | ||
|
||
|
||
ATTRIBUTES_TYPE = [ | ||
DataType.NUMBER.value, | ||
DataType.FLOAT.value, | ||
DataType.INTEGER.value, | ||
DataType.BOOLEAN.value, | ||
DataType.TEXT.value, | ||
DataType.DATETIME.value, | ||
DataType.ARRAY.value | ||
] | ||
|
||
COMMANDS_TYPE = [ | ||
DataType.COMMAND.value | ||
] | ||
|
||
|
||
class DeviceBasic(forms.Form): | ||
device_id = forms.CharField(label="Device ID", required=True, | ||
widget=forms.TextInput( | ||
attrs={ | ||
"data-bs-toggle": "tooltip", | ||
# "data-bs-placement": "top ", | ||
"title": "Deice ID", | ||
} | ||
), | ||
) | ||
entity_name = forms.CharField(label="Entity Name", max_length=256, required=True, | ||
widget=forms.TextInput( | ||
attrs={ | ||
"data-bs-toggle": "tooltip", | ||
# "data-bs-placement": "top ", | ||
"title": "Entity ID", | ||
} | ||
), | ||
) | ||
entity_type = forms.CharField(label="Entity Type", max_length=256, | ||
widget=forms.TextInput( | ||
attrs={ | ||
"data-bs-toggle": "tooltip", | ||
# "data-bs-placement": "top ", | ||
"title": "Entity Type", | ||
} | ||
), | ||
) | ||
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
self.helper = FormHelper(self) | ||
self.helper.form_tag = False | ||
|
||
|
||
class DeviceAttributes(forms.Form): | ||
name = forms.CharField(label="Name", required=True) | ||
type_choices = tuple([(f"{t}", t) for i, t in enumerate(ATTRIBUTES_TYPE)]) | ||
type = forms.ChoiceField(label="Type", required=True, choices=type_choices) | ||
object_id = forms.CharField(label="Object ID", required=False) | ||
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
self.helper = FormHelper(self) | ||
self.helper.form_tag = False | ||
self.helper.layout = Layout( | ||
Div( | ||
"name", | ||
"type", | ||
"object_id", | ||
HTML( | ||
"<button class='remove-form btn btn-danger rounded-pill btn-sm'><i class='bi bi-trash'></i></button>" | ||
), | ||
css_class="d_attr_form col-6", | ||
) | ||
) | ||
|
||
|
||
class DeviceCommands(forms.Form): | ||
name = forms.CharField(label="Name", required=True) | ||
type_choices = tuple([(f"{t}", t) for i, t in enumerate(COMMANDS_TYPE)]) | ||
type = forms.ChoiceField(label="Type", required=True, choices=type_choices) | ||
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
self.helper = FormHelper(self) | ||
self.helper.form_tag = False | ||
self.helper.layout = Layout( | ||
Div( | ||
"name", | ||
"type", | ||
HTML( | ||
"<button class='remove-form btn btn-danger rounded-pill btn-sm'><i class='bi bi-trash'></i></button>" | ||
), | ||
css_class="d_attr_form col-6", | ||
) | ||
) | ||
|
||
|
||
Attributes = formset_factory(DeviceAttributes, extra=0) | ||
Commands = formset_factory(DeviceCommands, extra=0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from django.db import models | ||
|
||
|
||
# Create your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from django_tables2 import tables | ||
|
||
|
||
class CheckBoxColumnWithName(tables.columns.CheckBoxColumn): | ||
""""Allow custom header for the first column""" | ||
@property | ||
def header(self): | ||
return self.verbose_name | ||
|
||
|
||
class DevicesTable(tables.Table): | ||
selection = CheckBoxColumnWithName( | ||
verbose_name="Select", | ||
accessor="device_id", | ||
attrs={ | ||
"td__input": { | ||
"value": lambda record: record.device_id, | ||
"type": "radio", | ||
}, | ||
}, | ||
orderable=False, | ||
) | ||
device_id = tables.columns.Column() | ||
entity_name = tables.columns.Column() | ||
entity_type = tables.columns.Column() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{% extends '_base.html' %} | ||
|
||
{#{% block title %}Edit Device{% endblock %}#} | ||
|
||
{% block content %} | ||
<h3 class="mt-5">{{ action }} Device</h3> | ||
|
||
{% if action == "Create" %} | ||
<form action="{% url 'projects:devices:create_submit' project.uuid %}" method="post" novalidate> | ||
{% elif action == "Edit" %} | ||
<form action="{% url 'projects:devices:edit-submit' project.uuid %}" method="post" novalidate> | ||
{% endif %} | ||
{% csrf_token %} | ||
{% include 'accordion.html' %} | ||
<button class="btn btn-primary rounded-pill" type="submit">Save</button> | ||
</form> | ||
|
||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
{% extends '_base.html' %} | ||
{% load django_tables2 %} | ||
|
||
{% block title %}Devices{% endblock %} | ||
|
||
|
||
{% block content %} | ||
|
||
<div class="d-flex"> | ||
<span class="h3">Devices </span> | ||
</div> | ||
|
||
<form action="" method="GET" > | ||
{% csrf_token %} | ||
<div class="row justify-content-center"> | ||
<div class="col-8"> | ||
<div class="p-3 border border-light rounded-pill bg-light"> | ||
<div class="input-group border-0 shadow-none"> | ||
<input name="search-patern" type="text" class="form-control border-light rounded-pill" | ||
placeholder="Filter devices ..."/> | ||
<span class="input-group-btn"> | ||
<button class="btn btn-info btn-lg bg-light border-light" type="submit" | ||
value="search"> | ||
<i class="bi-search"></i> | ||
</button> | ||
</span> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</form> | ||
|
||
<form action="{% url 'projects:devices:list_submit' project.uuid %}" method="POST" > | ||
{% csrf_token %} | ||
<div> | ||
<button type="submit" class="btn btn-primary mb-1 ms-auto" data-toggle="tooltip" data-placement="bottom" | ||
title="Create Device" value="True" name="Create"> | ||
<i class="bi bi-plus"></i> | ||
</button> | ||
<button type="button" class="btn btn-danger mb-1" data-toggle="tooltip" data-placement="bottom" | ||
title="Delete Device" data-bs-toggle="modal" data-bs-target="#deleteModal"> | ||
<i class="bi bi-trash"></i> | ||
</button> | ||
<button type="submit" class="btn btn-secondary mb-1" data-toggle="tooltip" data-placement="bottom" | ||
title="Edit Device" value="True" name="Edit"> | ||
<i class="bi bi-pen"></i> | ||
</button> | ||
</div> | ||
|
||
{% render_table table %} | ||
|
||
<div class="modal fade" id="deleteModal" tabindex="-1" aria-labelledby="deleteModalLabel" aria-hidden="true"> | ||
<div class="modal-dialog"> | ||
<div class="modal-content"> | ||
<div class="modal-header"> | ||
<h5 class="modal-title" id="deleteModalLabel">Delete Device</h5> | ||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> | ||
</div> | ||
<div class="modal-body"> | ||
Are you sure you want to delete this device? | ||
<div class="container"> | ||
<div class="form-check"> | ||
<input class="form-check-input" type="checkbox" id="ifDeleteEntity" name="delete_entity"> | ||
<label class="form-check-label" for="ifDeleteEntity">Delete the related entity</label> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="modal-footer"> | ||
<button type="button" class="btn btn-warning mb-1 text-end" data-toggle="tooltip" data-placement="bottom" | ||
data-bs-toggle="modal" data-bs-target="#deleteModalAdv">Advanced | ||
</button> | ||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button> | ||
<button type="submit" class="btn btn-danger" name="Delete" value="True"> | ||
Delete | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="modal fade" id="deleteModalAdv" tabindex="-1" aria-labelledby="deleteModalAdvLabel" aria-hidden="true"> | ||
<div class="modal-dialog"> | ||
<div class="modal-content"> | ||
<div class="modal-header"> | ||
<h5 class="modal-title" id="deleteModalAdvLabel">Delete Device</h5> | ||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> | ||
</div> | ||
<div class="modal-body"> | ||
If you want to delete the corresponding entity and the associated relationships or subscriptions, | ||
please select them in the checkbox. Note that loading might take some while. | ||
<div class="container"> | ||
<div class="form-check"> | ||
<input class="form-check-input" type="checkbox" id="ifDeleteEntitySubscription" name="subscriptions"> | ||
<label class="form-check-label" for="ifDeleteEntitySubscription">Subscriptions</label> | ||
</div> | ||
<div class="form-check"> | ||
<input class="form-check-input" type="checkbox" id="ifDeleteEntityRelationship" name="relationships"> | ||
<label class="form-check-label" for="ifDeleteEntityRelationship">Relationships</label> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="modal-footer"> | ||
<button type="submit" class="btn btn-danger" name="AdvancedDelete" value="True"> | ||
Delete | ||
</button> | ||
<button type="button" class="btn btn-secondary mb-1" data-toggle="tooltip" data-placement="bottom" | ||
data-bs-toggle="modal" data-bs-target="#deleteModal">Back | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</form> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from django.urls import path | ||
from devices.views import ( | ||
DeviceListView, | ||
DeviceListSubmitView, | ||
DeviceCreateView, | ||
DeviceCreateSubmitView, | ||
DeviceEditSubmitView, | ||
DeviceEditView, | ||
DeviceDeleteView | ||
) | ||
|
||
app_name = "devices" | ||
urlpatterns = [ | ||
path("create", DeviceCreateView.as_view(), name="create"), | ||
path("edit", DeviceEditView.as_view(), name="edit"), | ||
path("edit-submit", DeviceEditSubmitView.as_view(), name="edit-submit"), | ||
path("create-submit", DeviceCreateSubmitView.as_view(), name="create_submit"), | ||
path("list", DeviceListView.as_view(), name="list"), | ||
path("list-submit", DeviceListSubmitView.as_view(), name="list_submit"), | ||
path("delete", DeviceDeleteView.as_view(), name="delete") | ||
] |
Oops, something went wrong.