Skip to content

Home Information - Your home, your data, organized.

Python

Basic add and remove items from location views added.

Anthony Cassandra3ea7063c99c3
diff --git a/src/hi/apps/edit/helpers.py b/src/hi/apps/edit/helpers.py
new file mode 100644
index 00000000..5bf75cdc
--- /dev/null
+++ b/src/hi/apps/edit/helpers.py
@@ -0,0 +1,242 @@
+from decimal import Decimal
+from typing import List
+
+from django.db import transaction
+
+from hi.apps.collection.models import (
+ Collection,
+ CollectionView,
+ CollectionPosition,
+)
+from hi.apps.entity.models import (
+ Entity,
+ EntityView,
+ EntityPosition,
+ EntityPath,
+)
+from hi.apps.location.models import LocationView
+
+from .transient_models import (
+ CollectionViewItem,
+ CollectionViewGroup,
+ EntityViewItem,
+ EntityViewGroup,
+)
+
+
+class EditHelpers:
+
+ @classmethod
+ def create_entity_view_group_list( cls, location_view : LocationView ) -> List[EntityViewItem]:
+
+ entity_queryset = Entity.objects.all()
+
+ entity_view_group_dict = dict()
+ for entity in entity_queryset:
+
+ exists_in_view = False
+ for entity_view in entity.entity_views.all():
+ if entity_view.location_view == location_view:
+ exists_in_view = True
+ break
+ continue
+
+ entity_view_item = EntityViewItem(
+ entity = entity,
+ exists_in_view = exists_in_view,
+ )
+
+ if entity.entity_type not in entity_view_group_dict:
+ entity_view_group = EntityViewGroup(
+ location_view = location_view,
+ entity_type = entity.entity_type,
+ )
+ entity_view_group_dict[entity.entity_type] = entity_view_group
+ entity_view_group_dict[entity.entity_type].item_list.append( entity_view_item )
+ continue
+
+ entity_view_group_list = list( entity_view_group_dict.values() )
+ entity_view_group_list.sort( key = lambda item : item.entity_type.label )
+ return entity_view_group_list
+
+ @classmethod
+ def create_collection_view_group( cls, location_view : LocationView ) -> CollectionViewGroup:
+
+ collection_queryset = Collection.objects.all()
+
+ collection_view_group = CollectionViewGroup(
+ location_view = location_view,
+ )
+ for collection in collection_queryset:
+
+ exists_in_view = False
+ for collection_view in collection.collection_views.all():
+ if collection_view.location_view == location_view:
+ exists_in_view = True
+ break
+ continue
+
+ collection_view_item = CollectionViewItem(
+ collection = collection,
+ exists_in_view = exists_in_view,
+ )
+ collection_view_group.item_list.append( collection_view_item )
+ continue
+
+ collection_view_group.item_list.sort( key = lambda item : item.collection.name )
+ return collection_view_group
+
+ @classmethod
+ def toggle_entity_in_view( cls, entity : Entity, location_view : LocationView ) -> bool:
+
+ try:
+ entity_view = EntityView.objects.get(
+ entity = entity,
+ location_view = location_view,
+ )
+ entity_view.delete()
+ return False
+
+ except EntityView.DoesNotExist:
+ cls.add_entity_to_view( entity = entity, location_view = location_view )
+ return True
+
+ @classmethod
+ def add_entity_to_view( cls, entity : Entity, location_view : LocationView ):
+
+ with transaction.atomic():
+ # Need to make sure it has some visible representation in the view if none exists.
+ if entity.entity_type.is_path:
+ cls.add_entity_path_if_needed(
+ entity = entity,
+ location_view = location_view,
+ )
+ else:
+ cls.add_entity_position_if_needed(
+ entity = entity,
+ location_view = location_view,
+ )
+
+ _ = EntityView.objects.create(
+ entity = entity,
+ location_view = location_view,
+ )
+ return
+
+ @classmethod
+ def add_entity_position_if_needed( cls, entity : Entity, location_view : LocationView ) -> EntityPosition:
+ assert not entity.entity_type.is_path
+
+ try:
+ _ = EntityPosition.objects.get(
+ location = location_view.location,
+ entity = entity,
+ )
+ return
+ except EntityPosition.DoesNotExist:
+ pass
+
+ # Default display in middle of current view
+ svg_x = location_view.svg_view_box.x + ( location_view.svg_view_box.width / 2.0 )
+ svg_y = location_view.svg_view_box.y + ( location_view.svg_view_box.height / 2.0 )
+
+ entity_position = EntityPosition.objects.create(
+ entity = entity,
+ location = location_view.location,
+ svg_x = Decimal( svg_x ),
+ svg_y = Decimal( svg_y ),
+ svg_scale = Decimal( 1.0 ),
+ svg_rotate = Decimal( 0.0 ),
+ )
+ return entity_position
+
+ @classmethod
+ def add_entity_path_if_needed( cls, entity : Entity, location_view : LocationView ) -> EntityPath:
+ assert entity.entity_type.is_path
+
+ try:
+ _ = EntityPath.objects.get(
+ location = location_view.location,
+ entity = entity,
+ )
+ return
+ except EntityPath.DoesNotExist:
+ pass
+
+ # Default display a line in middle of current view with length 10% of viewbox width
+ length = location_view.svg_view_box.width / 10.0
+ center_x = location_view.svg_view_box.x + ( location_view.svg_view_box.width / 2.0 )
+ center_y = location_view.svg_view_box.y + ( location_view.svg_view_box.height / 2.0 )
+ start_x = center_x - ( length / 2.0 )
+ start_y = center_y
+ end_x = start_x + length
+ end_y = start_y
+
+ svg_path = f'M {start_x},{start_y} L {end_x},{end_y}'
+
+ entity_path = EntityPath.objects.create(
+ entity = entity,
+ location = location_view.location,
+ svg_path = svg_path,
+ )
+ return entity_path
+
+ @classmethod
+ def toggle_collection_in_view( cls, collection : Collection, location_view : LocationView ) -> bool:
+
+ try:
+ collection_view = CollectionView.objects.get(
+ collection = collection,
+ location_view = location_view,
+ )
+ collection_view.delete()
+ return False
+
+ except CollectionView.DoesNotExist:
+ cls.add_collection_to_view( collection = collection, location_view = location_view )
+ return True
+
+ @classmethod
+ def add_collection_to_view( cls,
+ collection : Collection,
+ location_view : LocationView ):
+
+ with transaction.atomic():
+ # Need to make sure it has some visible representation in the view if none exists.
+ cls.add_collection_position_if_needed(
+ collection = collection,
+ location_view = location_view,
+ )
+ _ = CollectionView.objects.create(
+ collection = collection,
+ location_view = location_view,
+ )
+ return
+
+ @classmethod
+ def add_collection_position_if_needed( cls,
+ collection : Collection,
+ location_view : LocationView ) -> CollectionPosition:
+ try:
+ _ = CollectionPosition.objects.get(
+ location = location_view.location,
+ collection = collection,
+ )
+ return
+ except CollectionPosition.DoesNotExist:
+ pass
+
+ # Default display in middle of current view
+ svg_x = location_view.svg_view_box.x + ( location_view.svg_view_box.width / 2.0 )
+ svg_y = location_view.svg_view_box.y + ( location_view.svg_view_box.height / 2.0 )
+
+ collection_position = CollectionPosition.objects.create(
+ collection = collection,
+ location = location_view.location,
+ svg_x = Decimal( svg_x ),
+ svg_y = Decimal( svg_y ),
+ svg_scale = Decimal( 1.0 ),
+ svg_rotate = Decimal( 0.0 ),
+ )
+ return collection_position
+
diff --git a/src/hi/apps/edit/templates/edit/panes/add_remove.html b/src/hi/apps/edit/templates/edit/panes/add_remove.html
new file mode 100644
index 00000000..0d9f3596
--- /dev/null
+++ b/src/hi/apps/edit/templates/edit/panes/add_remove.html
@@ -0,0 +1,19 @@
+<div class="">ADD/REMOVE</div>
+
+{% for entity_view_group in entity_view_group_list %}
+<div class="">
+ <div class="">{{ entity_view_group.entity_type.label }}</div>
+ {% for entity_view_item in entity_view_group.item_list %}
+ {% include "edit/panes/edit_view_entity_toggle.html" with location_view=entity_view_group.location_view entity=entity_view_item.entity exists_in_view=entity_view_item.exists_in_view %}
+ {% endfor %}
+</div>
+{% empty %}
+<div><em>No entities defined.</em></div>
+{% endfor %}
+
+<div class="">
+ <div class="">Collections</div>
+ {% for collection_view_item in collection_view_group.item_list %}
+ {% include "edit/panes/edit_view_collection_toggle.html" with location_view=collection_view_group.location_view collection=collection_view_item.collection exists_in_view=collection_view_item.exists_in_view %}
+ {% endfor %}
+</div>
diff --git a/src/hi/apps/edit/templates/edit/panes/edit_view_collection_toggle.html b/src/hi/apps/edit/templates/edit/panes/edit_view_collection_toggle.html
new file mode 100644
index 00000000..1c757f04
--- /dev/null
+++ b/src/hi/apps/edit/templates/edit/panes/edit_view_collection_toggle.html
@@ -0,0 +1,14 @@
+<div id="hi-edit-view-collection-toggle-{{ collection.id }}"
+ class="d-flex justify-content-start">
+ <div class="">
+ <form method="POST" role="form"
+ action="{% url 'edit_view_collection_toggle' location_view_id=location_view.id collection_id=collection.id %}"
+ data-async="#hi-edit-view-collection-toggle-{{ collection.id }}" data-mode="replace" >
+ {% csrf_token %}
+ <input type="checkbox" id="edit-view-collection-checkbox-{{ collection.id }}" name="checkbox_state"
+ {% if exists_in_view %}checked{% endif %}
+ onchange-async="true" >
+ <label for="edit-view-collection-checkbox-{{ collection.id }}">{{ collection.name }}</label>
+ </form>
+ </div>
+</div>
diff --git a/src/hi/apps/edit/templates/edit/panes/edit_view_entity_toggle.html b/src/hi/apps/edit/templates/edit/panes/edit_view_entity_toggle.html
new file mode 100644
index 00000000..556726d4
--- /dev/null
+++ b/src/hi/apps/edit/templates/edit/panes/edit_view_entity_toggle.html
@@ -0,0 +1,14 @@
+<div id="hi-edit-view-entity-toggle-{{ entity.id }}"
+ class="d-flex justify-content-start">
+ <div class="">
+ <form method="POST" role="form"
+ action="{% url 'edit_view_entity_toggle' location_view_id=location_view.id entity_id=entity.id %}"
+ data-async="#hi-edit-view-entity-toggle-{{ entity.id }}" data-mode="replace" >
+ {% csrf_token %}
+ <input type="checkbox" id="edit-view-entity-checkbox-{{ entity.id }}" name="checkbox_state"
+ {% if exists_in_view %}checked{% endif %}
+ onchange-async="true" >
+ <label for="edit-view-entity-checkbox-{{ entity.id }}">{{ entity.name }}</label>
+ </form>
+ </div>
+</div>
diff --git a/src/hi/apps/edit/templates/edit/panes/side.html b/src/hi/apps/edit/templates/edit/panes/side.html
index 05d79998..e43102b1 100644
--- a/src/hi/apps/edit/templates/edit/panes/side.html
+++ b/src/hi/apps/edit/templates/edit/panes/side.html
@@ -1,19 +1,27 @@
-<div id="hi-edit-side-content" class="d-flex justify-content-between">
- <div class="h5">Editing</div>
+<div id="hi-edit-side-content" class="">
+ <div class="">EDIT PANEL</div>
+
+ <div class="">
+ <a href="{% url 'edit_add_remove' %}"
+ class="btn btn-tertiary btn-control" role="button" data-async="true">
+ ADD/REMOVE
+ </a>
+ </div>
<div class="">
<a href="{% url 'edit_end' %}"
- class="btn btn-tertiary" role="button" >
+ class="btn btn-tertiary btn-control" role="button" >
EXIT
</a>
</div>
-</div>
-<div id="hi-edit-item">
- {% if entity %}
- {% include "edit/panes/entity.html" %}
- {% elif collection %}
- {% include "edit/panes/collection.html" %}
- {% else %}
- {% include "edit/panes/default.html" %}
- {% endif %}
-</div>
+ <div id="hi-edit-item">
+ {% if entity %}
+ {% include "edit/panes/entity.html" %}
+ {% elif collection %}
+ {% include "edit/panes/collection.html" %}
+ {% else %}
+ {% include "edit/panes/default.html" %}
+ {% endif %}
+ </div>
+
+</div>
diff --git a/src/hi/apps/edit/transient_models.py b/src/hi/apps/edit/transient_models.py
new file mode 100644
index 00000000..ace2c3fe
--- /dev/null
+++ b/src/hi/apps/edit/transient_models.py
@@ -0,0 +1,38 @@
+from dataclasses import dataclass, field
+from typing import List
+
+from hi.apps.collection.models import Collection
+from hi.apps.entity.enums import EntityType
+from hi.apps.entity.models import Entity
+from hi.apps.location.models import LocationView
+
+
+@dataclass
+class EntityViewItem:
+
+ entity : Entity
+ exists_in_view : bool
+
+
+@dataclass
+class EntityViewGroup:
+
+ location_view : LocationView
+ entity_type : EntityType
+ item_list : List[EntityViewItem] = field( default_factory = list )
+
+
+@dataclass
+class CollectionViewItem:
+
+ collection : Collection
+ exists_in_view : bool
+
+
+@dataclass
+class CollectionViewGroup:
+
+ location_view : LocationView
+ item_list : List[CollectionViewItem] = field( default_factory = list )
+
+
diff --git a/src/hi/apps/edit/urls.py b/src/hi/apps/edit/urls.py
index e097a403..0f8c4d74 100644
--- a/src/hi/apps/edit/urls.py
+++ b/src/hi/apps/edit/urls.py
@@ -20,4 +20,17 @@ urlpatterns = [
re_path( r'^svg/position/(?P<html_id>[\w\-]+)$',
views.EditSvgPositionView.as_view(),
name='edit_svg_position' ),
+
+ re_path( r'^add-remove$',
+ views.EditAddRemoveView.as_view(),
+ name='edit_add_remove' ),
+
+ re_path( r'^view/entity/toggle/(?P<location_view_id>[\w\-]+)/(?P<entity_id>[\w\-]+)$',
+ views.EditViewEntityToggleView.as_view(),
+ name='edit_view_entity_toggle' ),
+
+ re_path( r'^view/collection/toggle/(?P<location_view_id>[\w\-]+)/(?P<collection_id>[\w\-]+)$',
+ views.EditViewCollectionToggleView.as_view(),
+ name='edit_view_collection_toggle' ),
+
]
diff --git a/src/hi/apps/edit/views.py b/src/hi/apps/edit/views.py
index 4f7918f9..133b3552 100644
--- a/src/hi/apps/edit/views.py
+++ b/src/hi/apps/edit/views.py
@@ -1,5 +1,7 @@
import re
+from typing import Dict
+from django.http import HttpRequest
from django.shortcuts import redirect
from django.template.loader import get_template
from django.urls import reverse
@@ -9,11 +11,14 @@ import hi.apps.common.antinode as antinode
from hi.apps.collection.models import Collection, CollectionPosition
from hi.apps.entity.models import Entity, EntityPosition
from hi.apps.location.forms import SvgPositionForm
-from hi.apps.location.models import Location
+from hi.apps.location.location_view_manager import LocationViewManager
+from hi.apps.location.models import Location, LocationView
from hi.constants import DIVID
from hi.enums import EditMode
+from .helpers import EditHelpers
+
class EditViewMixin:
@@ -23,6 +28,33 @@ class EditViewMixin:
raise NotImplementedError( 'Not yet handling bad edit details html id' )
return ( m.group(1), int(m.group(2)) )
+ def get_edit_side_panel_response( self,
+ request : HttpRequest,
+ template_name : str,
+ context : Dict = None):
+ if context is None:
+ context = dict()
+ template = get_template( template_name )
+ content = template.render( context, request = request )
+ insert_map = {
+ DIVID['EDIT_ITEM']: content,
+ }
+ return antinode.response(
+ insert_map = insert_map,
+ )
+
+ def render_location_view_content( self,
+ request : HttpRequest,
+ location_view : LocationView ) -> str:
+ location_view_data = LocationViewManager().get_location_view_data(
+ location_view = location_view,
+ )
+ context = {
+ 'location_view_data': location_view_data,
+ }
+ template = get_template( 'location/location_view.html' )
+ return template.render( context, request = request )
+
class EditStartView( View ):
@@ -77,17 +109,9 @@ class EditDetailsView( View, EditViewMixin ):
raise NotImplementedError( 'Not yet handling unknown edit detail type.' )
def get_default_details( self, request ):
-
- context = {
- }
- template = get_template('edit/panes/default.html')
- content = template.render( context, request = request )
-
- insert_map = {
- DIVID['EDIT_ITEM']: content,
- }
- return antinode.response(
- insert_map = insert_map,
+ return self.get_edit_side_panel_response(
+ request = request,
+ template_name = 'edit/panes/default.html',
)
def get_entity_details( self, request, entity_id : int ):
@@ -108,14 +132,10 @@ class EditDetailsView( View, EditViewMixin ):
'entity': entity,
'svg_position_form': svg_position_form,
}
- template = get_template('edit/panes/entity.html')
- content = template.render( context, request = request )
-
- insert_map = {
- DIVID['EDIT_ITEM']: content,
- }
- return antinode.response(
- insert_map = insert_map,
+ return self.get_edit_side_panel_response(
+ request = request,
+ template_name = 'edit/panes/entity.html',
+ context = context,
)
def get_collection_details( self, request, collection_id : int ):
@@ -136,14 +156,10 @@ class EditDetailsView( View, EditViewMixin ):
'collection': collection,
'svg_position_form': svg_position_form,
}
- template = get_template('edit/panes/collection.html')
- content = template.render( context, request = request )
-
- insert_map = {
- DIVID['EDIT_ITEM']: content,
- }
- return antinode.response(
- insert_map = insert_map,
+ return self.get_edit_side_panel_response(
+ request = request,
+ template_name = 'edit/panes/collection.html',
+ context = context,
)
@@ -235,3 +251,91 @@ class EditSvgPositionView( View, EditViewMixin ):
collection = collection,
location = location,
)
+
+
+class EditAddRemoveView( View, EditViewMixin ):
+
+ def get(self, request, *args, **kwargs):
+
+ location_view = request.view_parameters.location_view
+
+ entity_view_group_list = EditHelpers.create_entity_view_group_list( location_view = location_view )
+ collection_view_group = EditHelpers.create_collection_view_group( location_view = location_view )
+
+ context = {
+ 'entity_view_group_list': entity_view_group_list,
+ 'collection_view_group': collection_view_group,
+ }
+ return self.get_edit_side_panel_response(
+ request = request,
+ template_name = 'edit/panes/add_remove.html',
+ context = context,
+ )
+
+
+class EditViewEntityToggleView( View, EditViewMixin ):
+
+ def post(self, request, *args, **kwargs):
+
+ location_view_id = kwargs.get('location_view_id')
+ entity_id = kwargs.get('entity_id')
+
+ entity = Entity.objects.get( id = entity_id )
+ location_view = LocationView.objects.get( id = location_view_id )
+ exists_in_view = EditHelpers.toggle_entity_in_view(
+ entity = entity,
+ location_view = location_view,
+ )
+
+ context = {
+ 'location_view': location_view,
+ 'entity': entity,
+ 'exists_in_view': exists_in_view,
+ }
+ template = get_template( 'edit/panes/edit_view_entity_toggle.html' )
+ main_content = template.render( context, request = request )
+
+ location_view_content = self.render_location_view_content(
+ request = request,
+ location_view = location_view,
+ )
+ return antinode.response(
+ main_content = main_content,
+ insert_map = {
+ DIVID['MAIN'] : location_view_content,
+ },
+ )
+
+
+class EditViewCollectionToggleView( View, EditViewMixin ):
+
+ def post(self, request, *args, **kwargs):
+
+ location_view_id = kwargs.get('location_view_id')
+ collection_id = kwargs.get('collection_id')
+
+ collection = Collection.objects.get( id = collection_id )
+ location_view = LocationView.objects.get( id = location_view_id )
+ exists_in_view = EditHelpers.toggle_collection_in_view(
+ collection = collection,
+ location_view = location_view,
+ )
+
+ context = {
+ 'location_view': location_view,
+ 'collection': collection,
+ 'exists_in_view': exists_in_view,
+ }
+ template = get_template( 'edit/panes/edit_view_collection_toggle.html' )
+ main_content = template.render( context, request = request )
+
+ location_view_content = self.render_location_view_content(
+ request = request,
+ location_view = location_view,
+ )
+ return antinode.response(
+ main_content = main_content,
+ insert_map = {
+ DIVID['MAIN'] : location_view_content,
+ },
+ )
diff --git a/src/hi/apps/entity/enums.py b/src/hi/apps/entity/enums.py
index dcca6710..df1c14e5 100644
--- a/src/hi/apps/entity/enums.py
+++ b/src/hi/apps/entity/enums.py
@@ -9,6 +9,13 @@ class EntityType(LabeledEnum):
- SVG file is needed for each of these, else will use a default.
- SVG filename is by convention:
"""
+ def __init__( self,
+ label : str,
+ description : str,
+ is_path : bool = False ):
+ super().__init__( label, description )
+ self.is_path = is_path
+ return
AIR_CONDITIONER = ( 'Air Conditioner', '' ) # Controls area
APPLIANCE = ( 'Appliance', '' )
@@ -18,14 +25,14 @@ class EntityType(LabeledEnum):
BAROMETER = ( 'Barometer', '' )
CAMERA = ( 'Camera', '' )
COMPUTER = ( 'Computer', '' )
- CONTROL_WIRE = ( 'Control Wire', '' )
+ CONTROL_WIRE = ( 'Control Wire', '', True )
DISPLAY = ( 'Display', '' )
DOOR = ( 'Door', '' )
DOOR_LOCK = ( 'Door Lock', '' ) # Controls doors
ELECTRICAL_OUTLET = ( 'Electrical Outlet', '' )
ELECTRICY_METER = ( 'Electric Meter', '' )
ELECTRIC_PANEL = ( 'Electric Panel', '' )
- ELECTRIC_WIRE = ( 'Electric Wire', '' )
+ ELECTRIC_WIRE = ( 'Electric Wire', '', True )
HEALTHCHECK = ( 'Healthcheck', '' )
HEATER = ( 'Heater', '' ) # Controls area
HVAC_AIR_HANDLER = ( 'HVAC Air Handler', '' ) # Controls area
@@ -39,15 +46,16 @@ class EntityType(LabeledEnum):
OPEN_CLOSE_DETECTOR = ( 'Open/Close Sensor', '' )
OTHER = ( 'Other', '' ) # Will use generic visual element
PRESENCE_SENSOR = ( 'Presence Sensor', '' )
- SEWER_LINE = ( 'Sewer Wire', '' )
+ SEWER_LINE = ( 'Sewer Wire', '', True )
SHOWER = ( 'Shower', '' )
SINK = ( 'Sink', '' )
SPEAKER = ( 'Speaker', '' )
SPINKLER_CONTROLLER = ( 'Spinkler Controller', '' )
SPINKLER_VALVE = ( 'Spinkler Valve', '' ) # Controls sprinkler heads
SPRINKLER_HEAD = ( 'Sprinkler Head', '' )
+ SPRINKLER_WIRE = ( 'Sprinkler Wire', '', True )
TELECOM_BOX = ( 'Telecom Box', '' )
- TELECOM_WIRE = ( 'Telecom Wire', '' )
+ TELECOM_WIRE = ( 'Telecom Wire', '', True )
THERMOMETER = ( 'Thermometer', '' )
THERMOSTAT = ( 'Thermostat', '' )
TIME_SOURCE = ( 'Time Source', '' )
@@ -55,9 +63,9 @@ class EntityType(LabeledEnum):
TOOL = ( 'Tool', '' )
VIDEO_PLAYER = ( 'Video Player', '' )
WALL_SWITCH = ( 'Wall Switch', '' )
- WASTE_PIPE = ( 'Waste Pipe', '' )
+ WASTE_PIPE = ( 'Waste Pipe', '', True )
WATER_HEATER = ( 'Water Heater', '' )
- WATER_LINE = ( 'Water Line', '' )
+ WATER_LINE = ( 'Water Line', '', True )
WATER_METER = ( 'Water Meter', '' )
WATER_SHUTOFF_VALVE = ( 'Water Shutoff Valve', '' )
WEATHER_STATION = ( 'Weather Station', '' )
diff --git a/src/hi/apps/entity/models.py b/src/hi/apps/entity/models.py
index 2726ba08..4593592d 100644
--- a/src/hi/apps/entity/models.py
+++ b/src/hi/apps/entity/models.py
@@ -385,4 +385,9 @@ class EntityView(models.Model):
verbose_name = 'Entity View'
verbose_name_plural = 'Entity Views'
-
+ constraints = [
+ models.UniqueConstraint(
+ fields = [ 'entity', 'location_view' ],
+ name = 'entity_view_entity_location_view', ),
+ ]
+
diff --git a/src/hi/static/js/antinode.js b/src/hi/static/js/antinode.js
index 8265c815..901a8c1b 100644
--- a/src/hi/static/js/antinode.js
+++ b/src/hi/static/js/antinode.js
@@ -14,7 +14,7 @@
//========================================
// jQuery asynchronous form submission
-// For any anchor tag (<a>) or form submission, you can turn them into an
+// For any anchor tag (<a>) or form tag (<form>), you can turn them into an
// asynchonous (aka, AJAX) request by adding the attribute:
//
// data-async="mnemonic-or-jquery-selector"
@@ -55,9 +55,9 @@
// submissions by adding the form property "debounce". Set this on the form
// HTML element, not the buttons.
//
-// To support "onchange" submission for SELECT elements, add the following
-// attribute to the SELECT (and also add the data-async/data-mode
-// attributes to the form)
+// To support "onchange" submission for Select or checkbox elements, add
+// the following attribute to the SELECT (and also add the
+// data-async/data-mode attributes to the form)
//
// onchange-async="true"
//
@@ -804,6 +804,10 @@ jQuery(function($) {
let $form = $(this.form);
return asyncSubmitHandlerHelper( $form );
});
+ $('body').on('change', 'input[onchange-async]', function() {
+ let $form = $(this.form);
+ return asyncSubmitHandlerHelper( $form );
+ });
// Weirdness of Bootstrap modals means we have to force the autofocus
// element manually. Yuck.
diff --git a/src/hi/templates/modals/action_1.html b/src/hi/templates/modals/action_1.html
new file mode 100644
index 00000000..24479a2c
--- /dev/null
+++ b/src/hi/templates/modals/action_1.html
@@ -0,0 +1,8 @@
+{% extends "modals/base.html" %}
+
+{% block footer %}
+<div class="align-self-center">
+ {% block action_center %}
+ {% endblock %}
+</div>
+{% endblock %}
diff --git a/src/hi/templates/modals/action_done.html b/src/hi/templates/modals/action_done.html
new file mode 100644
index 00000000..d5614db6
--- /dev/null
+++ b/src/hi/templates/modals/action_done.html
@@ -0,0 +1,6 @@
+{% extends "modals/action_1.html" %}
+
+{% block action_center %}
+<a id="hi-modal-cancel" role="button" {% if autofocus %}autofocus="autofocus"{% endif %}
+ class="btn btn-lg btn-secondary" href="#" data-dismiss="modal">DONE</a>
+{% endblock %}
diff --git a/src/hi/templates/modals/base.html b/src/hi/templates/modals/base.html
new file mode 100644
index 00000000..f76b49ff
--- /dev/null
+++ b/src/hi/templates/modals/base.html
@@ -0,0 +1,43 @@
+{% load static %}
+<div class="modal-dialog hi-modal">
+ <div class="modal-content">
+ <div class="modal-title">
+ <div class="row {% block header_class %}bg-secondary{% endblock %} m-0 py-2">
+ <div class="col-md-2 col-3 align-self-center text-center">
+ {% block title_image %}
+ <img class="img-fluid"
+ src="{% static 'img/hi-logo-196x196.png' %}"
+ alt="HI Logo" \>
+ {% endblock %}
+ </div>
+ <div class="col-md-9 col-8 align-self-center h4 m-0 px-1">
+ {% block title_text %}
+ {% endblock %}
+ </div>
+ <div class="col-md-1 col-1 align-self-center m-0 pl-1 text-right">
+ {% block dismiss_button %}
+ <button id="modal_dismiss_x"
+ type="button" class=" w-100 text-center text-white close"
+ data-dismiss="modal" aria-hidden="true">X</button>
+ {% endblock %}
+ </div>
+ </div>
+ </div>
+ {% block preamble %}
+ {% endblock %}
+ <div class="modal-body {% block body_class %}{% endblock %}">
+ {% block subheader %}
+ {% endblock %}
+ {% block body %}
+ {% endblock %}
+ </div>
+ <div class="modal-footer d-flex justify-content-around {% block footer_class %}{% endblock %}">
+ {% block footer %}
+ {% endblock %}
+ </div>
+ {% block after_footer %}
+ {% endblock %}
+ {% block postamble %}
+ {% endblock %}
+ </div>
+</div>