Skip to content

Home Information - Your home, your data, organized.

Python

Fixed location rotate for SVG. Fixed magic code case sensitivity.

Anthony Cassandrab626850a3dfd
diff --git a/src/hi/apps/user/magic_code_generator.py b/src/hi/apps/user/magic_code_generator.py
index 5e197d83..bfd232df 100644
--- a/src/hi/apps/user/magic_code_generator.py
+++ b/src/hi/apps/user/magic_code_generator.py
@@ -61,7 +61,7 @@ class MagicCodeGenerator:
magic_code = re.sub( r'[\-\s]', '', magic_code )
expected_magic_code = request.session.get( self.MAGIC_CODE )
- if magic_code != expected_magic_code:
+ if magic_code.lower() != expected_magic_code.lower():
return MagicCodeStatus.INVALID
magic_code_origin_timestamp = request.session.get( self.MAGIC_CODE_TIMESTAMP )
diff --git a/src/hi/integrations/integration_manager.py b/src/hi/integrations/integration_manager.py
index 3ecde2db..56c7878e 100644
--- a/src/hi/integrations/integration_manager.py
+++ b/src/hi/integrations/integration_manager.py
@@ -1,4 +1,4 @@
-from asgiref.sync import async_to_sync, sync_to_async
+from asgiref.sync import sync_to_async
import asyncio
import json
import logging
diff --git a/src/hi/integrations/views.py b/src/hi/integrations/views.py
index d70f4233..dadf5512 100644
--- a/src/hi/integrations/views.py
+++ b/src/hi/integrations/views.py
@@ -100,36 +100,12 @@ class IntegrationEnableView( HiModalView ):
'integration_attribute_formset': integration_attribute_formset,
}
return self.modal_response( request, context, status_code = 400 )
-
-
-
-
-
- import asyncio
- import tracemalloc
- tracemalloc.start()
-
-
-
-
-
-
integration_manager.enable_integration(
integration_data = integration_data,
integration_attribute_formset = integration_attribute_formset,
)
-
-
- snapshot = tracemalloc.take_snapshot()
- top_stats = snapshot.statistics('lineno') # Or 'filename'
- for stat in top_stats[:10]: # Show top 10 allocations
- print(stat)
- tracemalloc.stop()
-
-
-
redirect_url = reverse( 'integrations_home' )
return self.redirect_response( request, redirect_url )
diff --git a/src/hi/static/css/main.css b/src/hi/static/css/main.css
index 360e1500..6da46211 100644
--- a/src/hi/static/css/main.css
+++ b/src/hi/static/css/main.css
@@ -269,7 +269,9 @@ input[type="number"] {
.hi-location-view {
justify-content: center;
align-items: center;
- height: calc(100vh - var(--top-buttons-height) - var(--bottom-buttons-height) );
+ height: calc(100vh - var(--top-buttons-height) - var(--bottom-buttons-height) );
+ touch-action: none;
+
}
.hi-location-view-svg {
max-height: calc(100vh - var(--top-buttons-height) - var(--bottom-buttons-height) );
diff --git a/src/hi/static/js/main.js b/src/hi/static/js/main.js
index 860ddbb1..c6b5aa3b 100644
--- a/src/hi/static/js/main.js
+++ b/src/hi/static/js/main.js
@@ -51,6 +51,9 @@
normalizeAngle: function(angle) {
return _normalizeAngle(angle);
},
+ getTouchDistance: function( event ) {
+ return _getTouchDistance( event );
+ },
displayEventInfo: function ( label, event ) {
return _displayEventInfo( label, event );
},
@@ -167,19 +170,19 @@
const endVectorX = endX - centerX;
const endVectorY = endY - centerY;
- const startAngle = Math.atan2(startVectorY, startVectorX);
- const endAngle = Math.atan2(endVectorY, endVectorX);
+ const startAngle = Math.atan2( startVectorY, startVectorX );
+ const endAngle = Math.atan2( endVectorY, endVectorX );
let angleDifference = endAngle - startAngle;
// Normalize the angle to be between -π and π
- if (angleDifference > Math.PI) {
+ if ( angleDifference > Math.PI ) {
angleDifference -= 2 * Math.PI;
- } else if (angleDifference < -Math.PI) {
+ } else if ( angleDifference < -Math.PI ) {
angleDifference += 2 * Math.PI;
}
- const angleDifferenceDegrees = angleDifference * (180 / Math.PI);
+ const angleDifferenceDegrees = angleDifference * ( 180 / Math.PI );
return angleDifferenceDegrees;
}
@@ -201,6 +204,14 @@
Pos: ( ${event.clientX}, ${event.clientY} )` );
}
+ function _getTouchDistance( event ) {
+ if ( event.touches.length < 2 ) return 0;
+ let [ touch1, touch2 ] = event.touches;
+ let dx = touch1.clientX - touch2.clientX;
+ let dy = touch1.clientY - touch2.clientY;
+ return Math.sqrt( dx * dx + dy * dy );
+ }
+
function _displayElementInfo( label, element ) {
if ( ! Hi.DEBUG ) { return; }
if ( ! element ) {
diff --git a/src/hi/static/js/svg-location.js b/src/hi/static/js/svg-location.js
index 1888668e..5e3d6ca1 100644
--- a/src/hi/static/js/svg-location.js
+++ b/src/hi/static/js/svg-location.js
@@ -57,7 +57,8 @@
const KEYPRESS_ZOOM_SCALE_FACTOR_PERCENT = 10.0;
const MOUSE_WHEEL_ZOOM_SCALE_FACTOR_PERCENT = 10.0;
const ZOOM_API_CALL_DEBOUNCE_MS = 400;
-
+ const ROTATE_EASING_FACTOR = 0.5;
+
const LOCATION_VIEW_EDIT_PANE_SELECTOR = '#hi-location-view-edit';
const API_EDIT_LOCATION_VIEW_GEOMETRY_URL = '/location/edit/location-view/geometry';
@@ -115,7 +116,7 @@
if ( gSvgTransformType == SvgTransformType.SCALE ) {
updateScaleFromMouseMove( event );
} else if( gSvgTransformType == SvgTransformType.ROTATE ) {
- updateRotation( event );
+ updateRotationFromMouseMove( event );
} else {
updateDrag(event);
}
@@ -426,23 +427,23 @@
$(gSelectedLocationViewSvg).attr( Hi.SVG_ACTION_STATE_ATTR_NAME, gSvgTransformType );
}
- function updateRotation( event ) {
- if ( Hi.DEBUG ) { console.log( `updateRotation [${MODULE_NAME}]` ); }
+ function updateRotationFromMouseMove( event ) {
+ if ( Hi.DEBUG ) { console.log( `updateRotationFromMouseMove [${MODULE_NAME}]` ); }
let screenCenter = Hi.getScreenCenterPoint( gSelectedLocationViewSvg );
let deltaAngle = Hi.getRotationAngle( screenCenter.x, screenCenter.y,
- gLastMousePosition.x, gLastMousePosition.y,
+
+ gSvgTransformData.clickStart.x, gSvgTransformData.clickStart.y,
+
event.clientX, event.clientY );
let transform = $(gSelectedLocationViewSvg).attr('transform');
let { scale, translate, rotate } = Hi.svgUtils.getSvgTransformValues( transform );
- rotate.angle += deltaAngle;
+ rotate.angle = gSvgTransformData.initialSvgRotate.angle + ( deltaAngle * ROTATE_EASING_FACTOR );
rotate.angle = Hi.normalizeAngle( rotate.angle );
-
let newTransform = `rotate(${rotate.angle}, ${rotate.cx}, ${rotate.cy})`;
$(gSelectedLocationViewSvg).attr( 'transform', newTransform );
-
}
function applyRotation( event ) {