Advertisement
Guest User

Untitled

a guest
Aug 17th, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.14 KB | None | 0 0
  1. export class FloorZoneComponent {
  2.  
  3. urlFloorZoneIn: any;
  4. roomsFloorZoneIn: any;
  5. existingDroppedItemZoneIn: any[] = [];
  6. @Input() urlFloorZone;
  7. @Input() roomsFloorZone;
  8. @Input() currentBoxFloorZone;
  9. @Input() existingDroppedItem: any[] = [];
  10. dropzone1 = [];
  11. currentBox?: string = this.currentBoxFloorZone;
  12. mouse = {
  13. x: null,
  14. y: null,
  15. down: false
  16. };
  17. will_draw = false;
  18. left;
  19. top;
  20. topLeft = [];
  21.  
  22. @ViewChild('parentparent') parentparent;
  23.  
  24. @HostListener('mousedown', ['$event'])
  25. onMousedown(event) {
  26. this.mouse.down = true;
  27. }
  28.  
  29. @HostListener('mouseup', ['$event'])
  30. onMouseup(event) {
  31. this.mouse.down = false;
  32. }
  33.  
  34. documentMouseMove(e: MouseEvent) {
  35. // move logic
  36. if(!this.mouse.down) { return; }
  37.  
  38. const container_rect = this.parentparent.nativeElement.getBoundingClientRect();
  39. this.mouse.x = e.clientX - container_rect.left;
  40. this.mouse.y = e.clientY - container_rect.top;
  41. if(!this.will_draw) {
  42. requestAnimationFrame(this.draw.bind(this));
  43. this.will_draw = true;
  44. }
  45.  
  46. }
  47.  
  48. draw() {
  49. this.will_draw = false;
  50. const { width, height} = this.parentparent.nativeElement.getBoundingClientRect();
  51. const perc_x = this.mouse.x / width * 100;
  52. const perc_y = this.mouse.y / height * 100;
  53. // -5 to center (elem has its width set to 10%)
  54. console.log('left', (perc_x - 5) + '%');
  55. this.left = perc_x - 5;
  56. this.topLeft = []
  57. this.topLeft.push(this.left);
  58. // -5 to center (elem has its height set to 10%)
  59. console.log('top', (perc_y - 5) + '%');
  60. this.top = perc_y - 5;
  61. this.topLeft.push(this.top)
  62. }
  63.  
  64. ngOnChanges(changes: SimpleChanges) {
  65. if (changes.urlFloorZone && changes.urlFloorZone.currentValue) {
  66. this.urlFloorZoneIn = changes.urlFloorZone.currentValue;
  67. }
  68. if (changes.roomsFloorZone && changes.roomsFloorZone.currentValue) {
  69. this.roomsFloorZoneIn = changes.roomsFloorZone.currentValue
  70. }
  71. if(changes.existingDroppedItem && changes.existingDroppedItem.currentValue){
  72. this.existingDroppedItemZoneIn = changes.existingDroppedItem.currentValue;
  73. }
  74. }
  75.  
  76.  
  77. move(box: string, toList: string[]): void {
  78. box = this.currentBoxFloorZone;
  79.  
  80. let objTemp:any = {
  81. pos:[]
  82. };
  83.  
  84. objTemp.dis = this.currentBoxFloorZone;
  85.  
  86. for(var i=0; i < this.topLeft.length; i++){
  87. objTemp.pos.push(this.topLeft[i]);
  88. }
  89.  
  90. this.removeBox(box, this.dropzone1);
  91. toList.push(objTemp);
  92.  
  93. }
  94.  
  95. removeBox(item: string, list) {
  96. if (list.indexOf(item) !== -1) {
  97. list.splice(list.indexOf(item), 1);
  98. }
  99.  
  100. }
  101.  
  102. }
  103.  
  104. <div (mousemove)="documentMouseMove($event)" #parentparent>
  105.  
  106. <div class="dropzone"
  107. (drop)="move(currentBox, dropzone1)">
  108.  
  109. <div class="box"
  110. *ngFor="let existingZone of existingDroppedItemZoneIn">
  111. {{ existingZone.dis }}
  112. <span style="display: none">{{existingZone.left}}</span>
  113. <span style="display: none">{{existingZone.top}}</span>
  114. </div>
  115.  
  116. <div class="box"
  117. *ngFor="let box of dropzone1"
  118. (dragStart)="currentBox = box">
  119. {{ box.dis.dis }}
  120. <span style="display: none">{{box.pos[1]}}</span>
  121. <span style="display: none">{{box.pos[0]}}</span>
  122. </div>
  123.  
  124. </div>
  125. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement