@@ -11,13 +11,15 @@ import {
1111 deselectElement ,
1212 refreshElement ,
1313 selectElement ,
14+ urManager ,
1415} from "./../viewportManager" ;
1516import { RightBar } from "../../graphics/right_bar" ;
1617import { Colors , ZIndexLevels } from "../../utils" ;
1718import { Position } from "../common" ;
1819import { DeviceInfo } from "../../graphics/renderables/device_info" ;
1920import { IpAddress } from "../../packets/ip" ;
2021import { DeviceId } from "../graphs/datagraph" ;
22+ import { DragDeviceMove , EdgeData , AddEdgeMove } from "../undo-redo" ;
2123
2224export const DEVICE_SIZE = 20 ;
2325
@@ -42,6 +44,7 @@ export abstract class Device extends Sprite {
4244
4345 static dragTarget : Device | null = null ;
4446 static connectionTarget : Device | null = null ;
47+ static startPosition : Position | null = null ;
4548
4649 ip : IpAddress ;
4750 ipMask : IpAddress ;
@@ -117,6 +120,8 @@ export abstract class Device extends Sprite {
117120 // Clear connections
118121 this . connections . clear ( ) ;
119122 deselectElement ( ) ;
123+ console . log ( `Device ${ this . id } deleted` ) ;
124+ this . destroy ( ) ;
120125 }
121126
122127 onPointerDown ( event : FederatedPointerEvent ) : void {
@@ -125,6 +130,9 @@ export abstract class Device extends Sprite {
125130 selectElement ( this ) ;
126131 }
127132 Device . dragTarget = this ;
133+
134+ // Guardar posición inicial
135+ Device . startPosition = { x : this . x , y : this . y } ;
128136 event . stopPropagation ( ) ;
129137
130138 // Listen to global pointermove and pointerup events
@@ -141,6 +149,15 @@ export abstract class Device extends Sprite {
141149 const adyacentDevice = this . viewgraph . getDevice ( adyacentId ) ;
142150 this . addConnection ( edgeId , adyacentId ) ;
143151 adyacentDevice . addConnection ( edgeId , this . id ) ;
152+
153+ // Register move
154+ const moveData : EdgeData = {
155+ edgeId,
156+ connectedNodes : { n1 : this . id , n2 : adyacentId } ,
157+ } ;
158+ const move = new AddEdgeMove ( moveData ) ;
159+ urManager . push ( move ) ;
160+
144161 return true ;
145162 }
146163 return false ;
@@ -225,7 +242,6 @@ export abstract class Device extends Sprite {
225242}
226243
227244function onPointerMove ( event : FederatedPointerEvent ) : void {
228- console . log ( "Entered onPointerMove" ) ;
229245 if ( Device . dragTarget ) {
230246 Device . dragTarget . parent . toLocal (
231247 event . global ,
@@ -239,8 +255,36 @@ function onPointerMove(event: FederatedPointerEvent): void {
239255}
240256
241257function onPointerUp ( ) : void {
242- console . log ( "Entered onPointerUp" ) ;
243- if ( Device . dragTarget ) {
258+ if ( Device . dragTarget && Device . startPosition ) {
259+ const endPosition : Position = {
260+ x : Device . dragTarget . x ,
261+ y : Device . dragTarget . y ,
262+ } ;
263+ console . log ( "Finalizing move for device:" , {
264+ id : Device . dragTarget . id ,
265+ startPosition : Device . startPosition ,
266+ endPosition,
267+ } ) ;
268+
269+ if (
270+ Device . startPosition . x === endPosition . x &&
271+ Device . startPosition . y === endPosition . y
272+ ) {
273+ console . log (
274+ `No movement detected for device ID ${ Device . dragTarget . id } . Move not registered.` ,
275+ ) ;
276+ } else {
277+ const move = new DragDeviceMove (
278+ Device . dragTarget . id ,
279+ Device . startPosition ,
280+ endPosition ,
281+ ) ;
282+ urManager . push ( move ) ;
283+ }
284+
285+ // Resetear variables estáticas
286+ Device . startPosition = null ;
287+
244288 // Remove global pointermove and pointerup events
245289 Device . dragTarget . parent . off ( "pointermove" , onPointerMove ) ;
246290 Device . dragTarget . parent . off ( "pointerup" , onPointerUp ) ;
0 commit comments