Skip to content

Home Information - Your home, your data, organized.

Python

Allowing collections to be icons or paths. Much refactoring too.

Anthony Cassandra3490fde679d4
diff --git a/src/hi/apps/collection/admin.py b/src/hi/apps/collection/admin.py
index 7037444c..8c1123e8 100644
--- a/src/hi/apps/collection/admin.py
+++ b/src/hi/apps/collection/admin.py
@@ -21,6 +21,12 @@ class CollectionPositionInLine(admin.TabularInline):
show_change_link = True
+class PathInLine(admin.TabularInline):
+ model = models.CollectionPath
+ extra = 0
+ show_change_link = True
+
+
@admin.register(models.Collection)
class CollectionAdmin(admin.ModelAdmin):
@@ -36,4 +42,5 @@ class CollectionAdmin(admin.ModelAdmin):
CollectionEntityInLine,
CollectionViewInLine,
CollectionPositionInLine,
+ PathInLine,
]
diff --git a/src/hi/apps/collection/collection_manager.py b/src/hi/apps/collection/collection_manager.py
index 0ba423f5..2a7fdd81 100644
--- a/src/hi/apps/collection/collection_manager.py
+++ b/src/hi/apps/collection/collection_manager.py
@@ -1,12 +1,27 @@
+from decimal import Decimal
+
+from django.db import transaction
+from django.http import HttpRequest
+
from hi.apps.common.singleton import Singleton
from hi.apps.entity.models import Entity
+from hi.apps.location.models import Location, LocationView
from .collection_data import CollectionData
-from .models import Collection, CollectionEntity
+from .enums import CollectionType
+from .models import (
+ Collection,
+ CollectionEntity,
+ CollectionPath,
+ CollectionPosition,
+ CollectionView,
+)
class CollectionManager(Singleton):
+ PATH_EDIT_NEW_PATH_RADIUS_PERCENT = 5.0 # Preferrable if this matches Javascript new path sizing.
+
def __init_singleton__(self):
return
@@ -22,6 +37,18 @@ class CollectionManager(Singleton):
entity_list = entity_list,
)
+ def create_collection( self,
+ request : HttpRequest,
+ collection_type : CollectionType,
+ name : str ) -> Collection:
+ last_collection = Collection.objects.all().order_by( '-order_id' ).first()
+
+ return Collection.objects.create(
+ name = name,
+ collection_type_str = str(collection_type),
+ order_id = last_collection.order_id + 1,
+ )
+
def create_collection_entity( self,
entity : Entity,
collection : Collection ) -> CollectionEntity:
@@ -42,3 +69,167 @@ class CollectionManager(Singleton):
return True
except CollectionEntity.DoesNotExist:
return False
+
+ def remove_collection_view( self, collection : Collection, location_view : LocationView ):
+
+ with transaction.atomic():
+ collection_view = CollectionView.objects.get(
+ collection = collection,
+ location_view = location_view,
+ )
+ collection_view.delete()
+
+ return
+
+ def create_collection_view( self, collection : Collection, location_view : LocationView ):
+
+ with transaction.atomic():
+
+ # Need to make sure it has some visible representation in the view if none exists.
+ if collection.collection_type.is_path:
+ self.add_collection_path_if_needed(
+ collection = collection,
+ location_view = location_view,
+ )
+ else:
+ self.add_collection_position_if_needed(
+ collection = collection,
+ location_view = location_view,
+ )
+
+ try:
+ collection_view = CollectionView.objects.get(
+ collection = collection,
+ location_view = location_view,
+ )
+ except CollectionView.DoesNotExist:
+ collection_view = CollectionView.objects.create(
+ collection = collection,
+ location_view = location_view,
+ )
+
+ return collection_view
+
+ def set_collection_path( self,
+ collection_id : int,
+ location : Location,
+ svg_path_str : str ) -> CollectionPath:
+
+ try:
+ collection_path = CollectionPath.objects.get(
+ location = location,
+ collection_id = collection_id,
+ )
+ collection_path.svg_path = svg_path_str
+ collection_path.save()
+ return collection_path
+
+ except CollectionPath.DoesNotExist:
+ pass
+
+ collection = Collection.objects.get( id = collection_id )
+ return CollectionPath.objects.create(
+ collection = collection,
+ location = location,
+ svg_path = svg_path_str,
+ )
+
+ def get_collection_position( self,
+ collection_id : int,
+ location : Location ) -> CollectionPosition:
+ try:
+ collection = Collection.objects.get( id = collection_id )
+ except Collection.DoesNotExist:
+ return None
+
+ collection_position = CollectionPosition.objects.filter(
+ collection = collection,
+ location = location,
+ ).first()
+ if collection_position:
+ return collection_position
+
+ return CollectionPosition(
+ collection = collection,
+ location = location,
+ )
+ @classmethod
+ def add_collection_position_if_needed( cls,
+ collection : Collection,
+ location_view : LocationView ) -> CollectionPosition:
+ assert not collection.collection_type.is_path
+
+ 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
+
+ def add_collection_path_if_needed( self,
+ collection : Collection,
+ location_view : LocationView ) -> CollectionPath:
+ assert collection.collection_type.is_path
+
+ try:
+ _ = CollectionPath.objects.get(
+ location = location_view.location,
+ collection = collection,
+ )
+ return
+ except CollectionPath.DoesNotExist:
+ pass
+
+ # Note that this server-side creation of a new path is just one
+ # place new paths can be created. During client-side path editing,
+ # the Javascript code also uses logic to add new path segments.
+ # These do not have to behave identical, but it is preferrable for
+ # there to be some consistency.
+
+ # Default display a line or rectangle in middle of current view with radius X% of viewbox
+ 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 )
+ radius_x = location_view.svg_view_box.width * ( self.PATH_EDIT_NEW_PATH_RADIUS_PERCENT / 100.0 )
+ radius_y = location_view.svg_view_box.height * ( self.PATH_EDIT_NEW_PATH_RADIUS_PERCENT / 100.0 )
+
+ if collection.collection_type.is_path_closed:
+ top_left_x = center_x - radius_x
+ top_left_y = center_y - radius_y
+ top_right_x = center_x + radius_x
+ top_right_y = center_y - radius_y
+ bottom_right_x = center_x + radius_x
+ bottom_right_y = center_y + radius_y
+ bottom_left_x = center_x - radius_x
+ bottom_left_y = center_y + radius_y
+ svg_path = f'M {top_left_x},{top_left_y} L {top_right_x},{top_right_y} L {bottom_right_x},{bottom_right_y} L {bottom_left_x},{bottom_left_y} Z'
+ else:
+ start_x = center_x - radius_x
+ start_y = center_y
+ end_x = start_x + radius_x
+ end_y = start_y
+ svg_path = f'M {start_x},{start_y} L {end_x},{end_y}'
+
+ collection_path = CollectionPath.objects.create(
+ collection = collection,
+ location = location_view.location,
+ svg_path = svg_path,
+ )
+ return collection_path
+
+
diff --git a/src/hi/apps/collection/edit/helpers.py b/src/hi/apps/collection/edit/helpers.py
index 9b8a1ce9..694169a4 100644
--- a/src/hi/apps/collection/edit/helpers.py
+++ b/src/hi/apps/collection/edit/helpers.py
@@ -1,10 +1,8 @@
from typing import List
from django.db import transaction
-from django.http import HttpRequest
from hi.apps.collection.collection_manager import CollectionManager
-from hi.apps.collection.enums import CollectionType
from hi.apps.collection.models import (
Collection,
CollectionEntity,
@@ -21,19 +19,6 @@ from .transient_models import (
class CollectionEditHelpers:
- @classmethod
- def create_collection( cls,
- request : HttpRequest,
- collection_type : CollectionType,
- name : str ) -> Collection:
- last_collection = Collection.objects.all().order_by( '-order_id' ).first()
-
- return Collection.objects.create(
- name = name,
- collection_type_str = str(collection_type),
- order_id = last_collection.order_id + 1,
- )
-
@classmethod
def create_entity_collection_group_list( cls, collection : Collection ) -> List[EntityCollectionGroup]:
diff --git a/src/hi/apps/collection/edit/views.py b/src/hi/apps/collection/edit/views.py
index 95fa084c..66676bb1 100644
--- a/src/hi/apps/collection/edit/views.py
+++ b/src/hi/apps/collection/edit/views.py
@@ -1,6 +1,7 @@
import json
import logging
+from django.db import transaction
from django.shortcuts import redirect
from django.template.loader import get_template
from django.urls import reverse
@@ -13,6 +14,7 @@ from hi.apps.collection.enums import CollectionType
from hi.apps.collection.models import Collection, CollectionPosition
from hi.apps.entity.models import Entity
from hi.apps.location.forms import SvgPositionForm
+from hi.apps.location.edit.helpers import LocationEditHelpers
from hi.decorators import edit_required
from hi.enums import ViewType
from hi.views import bad_request_response, page_not_found_response
@@ -91,11 +93,19 @@ class CollectionAddView( View ):
name = cleaned_data.get('name')
try:
- collection = CollectionEditHelpers.create_collection(
- request = request,
- collection_type = collection_type,
- name = name,
- )
+ with transaction.atomic():
+ collection = CollectionManager().create_collection(
+ request = request,
+ collection_type = collection_type,
+ name = name,
+ )
+ if ( request.view_parameters.view_type.is_location_view
+ and request.view_parameters.location_view_id ):
+ LocationEditHelpers.add_collection_to_view_by_id(
+ collection = collection,
+ location_view_id = request.view_parameters.location_view_id,
+ )
+
except ValueError as e:
return bad_request_response( request, message = str(e) )
diff --git a/src/hi/apps/collection/enums.py b/src/hi/apps/collection/enums.py
index ce2fff7d..f355506e 100644
--- a/src/hi/apps/collection/enums.py
+++ b/src/hi/apps/collection/enums.py
@@ -1,9 +1,25 @@
from hi.apps.common.enums import LabeledEnum
-from hi.apps.common.svg_models import SvgViewBox
+from hi.apps.common.svg_models import SvgPathStyle, SvgViewBox
class CollectionType(LabeledEnum):
+ """
+ - This helps define the default visual appearance.
+ - No assumptions are made about what sensors or controllers are associated with a given EntityType.
+ - 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 = True,
+ is_path_closed : bool = True ):
+ super().__init__( label, description )
+ self.is_path = is_path
+ self.is_path_closed = is_path_closed
+ return
+
APPLIANCES = ( 'Appliances', '' )
DEVICES = ( 'Devices', '' )
ELECTRONICS = ( 'Electronics', '' )
@@ -11,12 +27,15 @@ class CollectionType(LabeledEnum):
LANDSCAPING = ( 'Landscaping', '' )
TOOLS = ( 'Tools', '' )
OTHER = ( 'Other', '' )
- ZONE = ( 'Zone', '' )
@classmethod
def default(cls):
return cls.OTHER
+ @property
+ def is_icon(self):
+ return bool( not self.is_path )
+
@property
def svg_icon_bounding_box(self):
"""
@@ -45,3 +64,13 @@ class CollectionType(LabeledEnum):
#
# return f'templates/entity/svg/type.{self.name.lower()}.svg'
return 'entity/svg/type.other.svg'
+
+ @property
+ def svg_path_style(self):
+ # TODO: Change this to be based on type
+ return SvgPathStyle(
+ stroke_color = '#40f040',
+ stroke_width = 5.0,
+ fill_color = 'none',
+ )
+
diff --git a/src/hi/apps/collection/helpers.py b/src/hi/apps/collection/helpers.py
deleted file mode 100644
index f28ea9ca..00000000
--- a/src/hi/apps/collection/helpers.py
+++ /dev/null
@@ -1,28 +0,0 @@
-from hi.apps.location.models import Location
-
-from .models import Collection, CollectionPosition
-
-
-class CollectionHelpers:
-
- @classmethod
- def get_collection_position( cls,
- collection_id : int,
- location : Location ) -> CollectionPosition:
- try:
- collection = Collection.objects.get( id = collection_id )
- except Collection.DoesNotExist:
- return None
-
- collection_position = CollectionPosition.objects.filter(
- collection = collection,
- location = location,
- ).first()
- if collection_position:
- return collection_position
-
- return CollectionPosition(
- collection = collection,
- location = location,
- )
-
diff --git a/src/hi/apps/collection/migrations/0007_collectionpath_and_more.py b/src/hi/apps/collection/migrations/0007_collectionpath_and_more.py
new file mode 100644
index 00000000..9bd94b4e
--- /dev/null
+++ b/src/hi/apps/collection/migrations/0007_collectionpath_and_more.py
@@ -0,0 +1,67 @@
+# Generated by Django 4.2.15 on 2024-10-09 21:35
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("location", "0007_rename_view_type_str_locationview_location_view_type_str"),
+ ("collection", "0006_remove_collectionview_order_id_collection_order_id"),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name="CollectionPath",
+ fields=[
+ (
+ "id",
+ models.BigAutoField(
+ auto_created=True,
+ primary_key=True,
+ serialize=False,
+ verbose_name="ID",
+ ),
+ ),
+ ("svg_path", models.TextField(verbose_name="Path")),
+ (
+ "created_datetime",
+ models.DateTimeField(auto_now_add=True, verbose_name="Created"),
+ ),
+ (
+ "updated_datetime",
+ models.DateTimeField(auto_now=True, verbose_name="Updated"),
+ ),
+ (
+ "collection",
+ models.ForeignKey(
+ on_delete=django.db.models.deletion.CASCADE,
+ related_name="paths",
+ to="collection.collection",
+ verbose_name="Collection",
+ ),
+ ),
+ (
+ "location",
+ models.ForeignKey(
+ on_delete=django.db.models.deletion.CASCADE,
+ related_name="collection_paths",
+ to="location.location",
+ verbose_name="Location",
+ ),
+ ),
+ ],
+ options={
+ "verbose_name": "Collection Path",
+ "verbose_name_plural": "Collection Paths",
+ },
+ ),
+ migrations.AddConstraint(
+ model_name="collectionpath",
+ constraint=models.UniqueConstraint(
+ fields=("location", "collection"),
+ name="collection_path_location_collection",
+ ),
+ ),
+ ]
diff --git a/src/hi/apps/collection/models.py b/src/hi/apps/collection/models.py
index a24595c7..01467189 100644
--- a/src/hi/apps/collection/models.py
+++ b/src/hi/apps/collection/models.py
@@ -1,10 +1,11 @@
from django.db import models
-from hi.apps.common.svg_models import SvgIconItem
+from hi.apps.common.svg_models import SvgIconItem, SvgPathItem
from hi.apps.entity.models import Entity
from hi.apps.location.models import (
Location,
LocationView,
+ SvgPathModel,
SvgPositionModel,
)
@@ -128,6 +129,53 @@ class CollectionPosition( SvgPositionModel ):
)
+class CollectionPath( SvgPathModel ):
+ """
+ - For collection represented by an arbitary (usually closed) SVG path.
+ - The styling of the path is determined by the CollectionType.
+ - An Collection is not required to have an CollectionPath.
+ """
+
+ location = models.ForeignKey(
+ Location,
+ related_name = 'collection_paths',
+ verbose_name = 'Location',
+ on_delete = models.CASCADE,
+ )
+ collection = models.ForeignKey(
+ Collection,
+ related_name = 'paths',
+ verbose_name = 'Collection',
+ on_delete = models.CASCADE,
+ )
+ created_datetime = models.DateTimeField(
+ 'Created',
+ auto_now_add = True,
+ )
+ updated_datetime = models.DateTimeField(
+ 'Updated',
+ auto_now=True,
+ blank = True,
+ )
+
+ class Meta:
+ verbose_name = 'Collection Path'
+ verbose_name_plural = 'Collection Paths'
+ constraints = [
+ models.UniqueConstraint(
+ fields = [ 'location', 'collection' ],
+ name = 'collection_path_location_collection', ),
+ ]
+
+ @property
+ def svg_path_item(self) -> SvgPathItem:
+ return SvgPathItem(
+ html_id = f'hi-collection-{self.collection.id}',
+ svg_path = self.svg_path,
+ path_style = self.collection.collection_type.svg_path_style,
+ )
+
+
class CollectionView(models.Model):
collection = models.ForeignKey(
diff --git a/src/hi/apps/edit/views.py b/src/hi/apps/edit/views.py
index 752b2bb4..d286e069 100644
--- a/src/hi/apps/edit/views.py
+++ b/src/hi/apps/edit/views.py
@@ -12,7 +12,7 @@ from django.views.generic import View
import hi.apps.common.antinode as antinode
import hi.apps.collection.edit.views as collection_edit_views
-from hi.apps.collection.helpers import CollectionHelpers
+from hi.apps.collection.collection_manager import CollectionManager
import hi.apps.entity.edit.views as entity_edit_views
from hi.apps.entity.entity_manager import EntityManager
import hi.apps.location.edit.views as location_edit_views
@@ -159,7 +159,7 @@ class EditSvgPositionView( View, EditViewMixin ):
location = location_view.location,
)
elif item_type == 'collection':
- svg_position_model = CollectionHelpers.get_collection_position(
+ svg_position_model = CollectionManager().get_collection_position(
collection_id = item_id,
location = location_view.location,
)
@@ -212,6 +212,12 @@ class EditSvgPathView( View, EditViewMixin ):
location = location_view.location,
svg_path_str = svg_path_str,
)
+ elif item_type == 'collection':
+ CollectionManager().set_collection_path(
+ collection_id = item_id,
+ location = location_view.location,
+ svg_path_str = svg_path_str,
+ )
else:
return bad_request_response( request, message = f'Cannot set SVG path for "{item_type}"' )
diff --git a/src/hi/apps/entity/enums.py b/src/hi/apps/entity/enums.py
index 9aed5bf2..6eb9dcca 100644
--- a/src/hi/apps/entity/enums.py
+++ b/src/hi/apps/entity/enums.py
@@ -19,10 +19,6 @@ class EntityType(LabeledEnum):
self.is_path_closed = is_path_closed
return
- @property
- def is_icon(self):
- return bool( not self.is_path )
-
AIR_CONDITIONER = ( 'Air Conditioner', '' ) # Controls area
APPLIANCE = ( 'Appliance', '' )
AREA = ( 'Area', '', True, True )
@@ -82,6 +78,10 @@ class EntityType(LabeledEnum):
def default(cls):
return cls.OTHER
+ @property
+ def is_icon(self):
+ return bool( not self.is_path )
+
@property
def svg_icon_bounding_box(self):
"""
diff --git a/src/hi/apps/entity/migrations/0011_alter_entitystatedelegation_options_and_more.py b/src/hi/apps/entity/migrations/0011_alter_entitystatedelegation_options_and_more.py
new file mode 100644
index 00000000..ba413255
--- /dev/null
+++ b/src/hi/apps/entity/migrations/0011_alter_entitystatedelegation_options_and_more.py
@@ -0,0 +1,39 @@
+# Generated by Django 4.2.15 on 2024-10-09 21:35
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("location", "0007_rename_view_type_str_locationview_location_view_type_str"),
+ ("entity", "0010_entitystatedelegation_delete_entitystateproxy"),
+ ]
+
+ operations = [
+ migrations.AlterModelOptions(
+ name="entitystatedelegation",
+ options={
+ "verbose_name": "Entity State Delegation",
+ "verbose_name_plural": "Entity State Delegations",
+ },
+ ),
+ migrations.AlterField(
+ model_name="entitypath",
+ name="location",
+ field=models.ForeignKey(
+ on_delete=django.db.models.deletion.CASCADE,
+ related_name="entity_paths",
+ to="location.location",
+ verbose_name="Location",
+ ),
+ ),
+ migrations.AddConstraint(
+ model_name="entitystatedelegation",
+ constraint=models.UniqueConstraint(
+ fields=("delegate_entity", "entity_state"),
+ name="entity_state_delegation_uniqueness",
+ ),
+ ),
+ ]
diff --git a/src/hi/apps/entity/models.py b/src/hi/apps/entity/models.py
index 9639122a..e5fdef9d 100644
--- a/src/hi/apps/entity/models.py
+++ b/src/hi/apps/entity/models.py
@@ -354,7 +354,7 @@ class EntityPath( SvgPathModel ):
location = models.ForeignKey(
Location,
- related_name = 'paths',
+ related_name = 'entity_paths',
verbose_name = 'Location',
on_delete = models.CASCADE,
)
diff --git a/src/hi/apps/location/edit/helpers.py b/src/hi/apps/location/edit/helpers.py
index 36ad51d8..0776295a 100644
--- a/src/hi/apps/location/edit/helpers.py
+++ b/src/hi/apps/location/edit/helpers.py
@@ -4,10 +4,12 @@ from typing import List
from django.db import transaction
from django.http import HttpRequest
+from hi.apps.collection.collection_manager import CollectionManager
from hi.apps.collection.models import (
Collection,
- CollectionView,
+ CollectionPath,
CollectionPosition,
+ CollectionView,
)
from hi.apps.entity.delegation_manager import DelegationManager
from hi.apps.entity.entity_manager import EntityManager
@@ -19,10 +21,10 @@ from hi.apps.location.enums import LocationViewType
from hi.apps.location.models import Location, LocationView
from .transient_models import (
+ EntityViewGroup,
+ EntityViewItem,
CollectionViewItem,
CollectionViewGroup,
- EntityViewItem,
- EntityViewGroup,
)
@@ -178,70 +180,45 @@ class LocationEditHelpers:
@classmethod
def toggle_collection_in_view( cls,
collection : Collection,
- location_view : LocationView,
- add_position_if_needed : bool ) -> bool:
+ location_view : LocationView ) -> bool:
try:
- collection_view = CollectionView.objects.get(
- collection = collection,
- location_view = location_view,
- )
- collection_view.delete()
+ cls.remove_collection_from_view( collection = collection, location_view = location_view )
return False
except CollectionView.DoesNotExist:
- cls.add_collection_to_view(
+ cls.add_collection_to_view( collection = collection, location_view = location_view )
+ return True
+
+ @classmethod
+ def remove_collection_from_view( cls,
+ collection : Collection,
+ location_view : LocationView ):
+ with transaction.atomic():
+ CollectionManager().remove_collection_view(
collection = collection,
location_view = location_view,
- add_position_if_needed = add_position_if_needed,
)
- return True
+ return
+ @classmethod
+ def add_collection_to_view_by_id( cls, collection : Collection, location_view_id : int ):
+ location_view = LocationView.objects.get( id = location_view_id )
+ cls.add_collection_to_view( collection = collection, location_view = location_view )
+ return
+
@classmethod
def add_collection_to_view( cls,
collection : Collection,
- location_view : LocationView,
- add_position_if_needed : bool ):
+ location_view : LocationView ):
with transaction.atomic():
- if add_position_if_needed:
- cls.add_collection_position_if_needed(
- collection = collection,
- location_view = location_view,
- )
- _ = CollectionView.objects.create(
+ _ = CollectionManager().create_collection_view(
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
-
@classmethod
def set_location_view_order( cls, location_view_id_list : List[int] ):
diff --git a/src/hi/apps/location/edit/urls.py b/src/hi/apps/location/edit/urls.py
index 1a9bdefd..65c31daa 100644
--- a/src/hi/apps/location/edit/urls.py
+++ b/src/hi/apps/location/edit/urls.py
@@ -26,7 +26,7 @@ urlpatterns = [
name='location_edit_location_view_entity_toggle' ),
re_path( r'^location-view/collection/toggle/(?P<location_view_id>\d+)/(?P<collection_id>\d+)$',
- views.LocationViewEntityToggleCollectionView.as_view(),
+ views.LocationViewCollectionToggleView.as_view(),
name='location_edit_location_view_collection_toggle' ),
re_path( r'^location-view/geometry/(?P<location_view_id>\d+)$',
diff --git a/src/hi/apps/location/edit/views.py b/src/hi/apps/location/edit/views.py
index 88c11643..8d5ade5d 100644
--- a/src/hi/apps/location/edit/views.py
+++ b/src/hi/apps/location/edit/views.py
@@ -234,7 +234,7 @@ class LocationViewEntityRemoveView( View ):
@method_decorator( edit_required, name='dispatch' )
-class LocationViewEntityToggleCollectionView( View ):
+class LocationViewCollectionToggleView( View ):
def post(self, request, *args, **kwargs):
@@ -246,7 +246,6 @@ class LocationViewEntityToggleCollectionView( View ):
exists_in_view = LocationEditHelpers.toggle_collection_in_view(
collection = collection,
location_view = location_view,
- add_position_if_needed = True,
)
context = {
diff --git a/src/hi/apps/location/location_view_data.py b/src/hi/apps/location/location_view_data.py
index 2fb39480..9a12f6bc 100644
--- a/src/hi/apps/location/location_view_data.py
+++ b/src/hi/apps/location/location_view_data.py
@@ -1,7 +1,7 @@
from dataclasses import dataclass
from typing import List, Set
-from hi.apps.collection.models import Collection, CollectionPosition
+from hi.apps.collection.models import Collection, CollectionPath, CollectionPosition
from hi.apps.entity.models import Entity, EntityPosition, EntityPath
from .models import LocationView
@@ -17,5 +17,6 @@ class LocationViewData:
entity_positions : List[ EntityPosition ]
entity_paths : List[ EntityPath ]
collection_positions : List[ CollectionPosition ]
+ collection_paths : List[ CollectionPath ]
unpositioned_collections : List[ Collection ]
orphan_entities : Set[ Entity ]
diff --git a/src/hi/apps/location/location_view_manager.py b/src/hi/apps/location/location_view_manager.py
index a723bff0..858c9a5a 100644
--- a/src/hi/apps/location/location_view_manager.py
+++ b/src/hi/apps/location/location_view_manager.py
@@ -31,6 +31,7 @@ class LocationViewManager(Singleton):
continue
collection_positions = list()
+ collection_paths = list()
unpositioned_collections = list()
for collection_view in location_view.collection_views.all():
collection = collection_view.collection
@@ -39,6 +40,9 @@ class LocationViewManager(Singleton):
collection_positions.append( collection_position )
else:
unpositioned_collections.append( collection )
+ collection_path = collection.paths.filter( location = location ).first()
+ if collection_path:
+ collection_paths.append( collection_path )
continue
# These are used for reporting entities that might otherwise be
@@ -59,6 +63,7 @@ class LocationViewManager(Singleton):
entity_positions = entity_positions,
entity_paths = entity_paths,
collection_positions = collection_positions,
+ collection_paths = collection_paths,
unpositioned_collections = unpositioned_collections,
orphan_entities = orphan_entities,
)
diff --git a/src/hi/apps/location/templates/location/location_view.html b/src/hi/apps/location/templates/location/location_view.html
index 41fb306b..71565d45 100644
--- a/src/hi/apps/location/templates/location/location_view.html
+++ b/src/hi/apps/location/templates/location/location_view.html
@@ -18,6 +18,10 @@
{% include "location/svg_icon_item.html" with svg_icon_item=entity_position.svg_icon_item %}
{% endfor %}
+ {% for collection_path in location_view_data.collection_paths %}
+ {% include "location/svg_path_item.html" with svg_path_item=collection_path.svg_path_item %}
+ {% endfor %}
+
{% for collection_position in location_view_data.collection_positions %}
{% include "location/svg_icon_item.html" with svg_icon_item=collection_position.svg_icon_item %}
{% endfor %}
diff --git a/src/hi/apps/location/views.py b/src/hi/apps/location/views.py
index d96efe8c..d5868c7d 100644
--- a/src/hi/apps/location/views.py
+++ b/src/hi/apps/location/views.py
@@ -78,7 +78,7 @@ class LocationViewView( HiGridView ):
'is_async_request': is_ajax( request ),
'location_view_data': location_view_data,
}
-
+
side_template_name = None
if request.is_editing:
side_template_name = 'edit/panes/side.html'
diff --git a/src/hi/static/js/edit-svg-path.js b/src/hi/static/js/edit-svg-path.js
index 708cddb8..e5fbcef1 100644
--- a/src/hi/static/js/edit-svg-path.js
+++ b/src/hi/static/js/edit-svg-path.js
@@ -778,8 +778,13 @@
x: event.clientX,
y: event.clientY
};
- const offsetX = event.clientX - parseFloat($(proxyPoint).attr('cx'));
- const offsetY = event.clientY - parseFloat($(proxyPoint).attr('cy'));
+
+ const baseSvgElement = $(Hi.BASE_SVG_SELECTOR);
+ const eventSvgPoint = Hi.toSvgPoint( baseSvgElement, event.clientX, event.clientY );
+
+
+ const offsetX = eventSvgPoint.x - parseFloat($(proxyPoint).attr('cx'));
+ const offsetY = eventSvgPoint.y - parseFloat($(proxyPoint).attr('cy'));
let isDragging = false;
@@ -799,9 +804,12 @@
isDragging = true;
event.preventDefault();
event.stopImmediatePropagation();
+
+ const eventSvgPoint = Hi.toSvgPoint( baseSvgElement, event.clientX, event.clientY );
+
gSvgPathEditData.dragProxyPoint = event.target;
- const newCx = event.clientX - offsetX;
- const newCy = event.clientY - offsetY;
+ const newCx = eventSvgPoint.x - offsetX;
+ const newCy = eventSvgPoint.y - offsetY;
$(proxyPoint).attr('cx', newCx).attr('cy', newCy);
// Update the line endpoints to follow proxy point movement