parent
bd8cfb573c
commit
af09d88360
@ -1,14 +1,11 @@
|
|||||||
<div class="target" [style.background-color]="backgroundColor ? backgroundColor.rgbaString : 'rgba(0, 0, 0, 0.1)'" #targetRef>
|
<ng-container *ngIf="rect">
|
||||||
|
<div class="target" [style.background-color]="backgroundColor ? backgroundColor.rgbaString : 'rgba(0, 0, 0, 0.1)'"
|
||||||
|
[style.transform]="transform()" [style.width]="rect.width + 'px'" [style.height]="rect.height + 'px'" #targetRef>
|
||||||
<ng-container *ngIf="plan">
|
<ng-container *ngIf="plan">
|
||||||
Has Plan!
|
Has Plan!
|
||||||
</ng-container>
|
</ng-container>
|
||||||
</div>
|
</div>
|
||||||
<ngx-moveable
|
|
||||||
[target]="targetRef"
|
<ngx-moveable [target]="targetRef" [draggable]="draggable" [resizable]="true" (drag)="onDrag($event)"
|
||||||
[draggable]="draggable"
|
(resize)="onResize($event)" (dragEnd)="onDragEnd($event)" (resizeEnd)="onResizeEnd($event)"></ngx-moveable>
|
||||||
[resizable]="true"
|
</ng-container>
|
||||||
(drag)="onDrag($event)"
|
|
||||||
(resize)="onResize($event)"
|
|
||||||
(dragEnd)="onDragEnd($event)"
|
|
||||||
(resizeEnd)="onResizeEnd($event)"
|
|
||||||
#moveableRef></ngx-moveable>
|
|
@ -1,87 +1,61 @@
|
|||||||
import { AfterViewInit, Component, Input, OnInit, ViewChild } from '@angular/core';
|
import { AfterViewInit, ChangeDetectorRef, Component, Input, OnInit, ViewChild } from '@angular/core';
|
||||||
import { NgxMoveableComponent, OnDragEnd, OnResize, OnResizeEnd } from 'ngx-moveable';
|
import { NgxMoveableComponent, OnDragEnd, OnResize, OnResizeEnd } from 'ngx-moveable';
|
||||||
import { OnDrag } from 'ngx-moveable';
|
import { OnDrag } from 'ngx-moveable';
|
||||||
import { ConfigService } from '../services/config.service';
|
import { ConfigService } from '../services/config.service';
|
||||||
import { Rect } from '../models/generated/Rect';
|
import { Rect } from '../models/generated/Rect';
|
||||||
import { Plan } from '../models/plan';
|
import { Plan } from '../models/plan';
|
||||||
import { Color } from '../color-picker/color-picker.component';
|
import { Color } from '../color-picker/color-picker.component';
|
||||||
|
import { Subject } from 'rxjs';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'plan-display',
|
selector: 'plan-display',
|
||||||
templateUrl: './plan-display.component.html',
|
templateUrl: './plan-display.component.html',
|
||||||
styleUrls: ['./plan-display.component.scss']
|
styleUrls: ['./plan-display.component.scss']
|
||||||
})
|
})
|
||||||
export class PlanDisplayComponent implements OnInit, AfterViewInit {
|
export class PlanDisplayComponent implements AfterViewInit {
|
||||||
|
@ViewChild('targetRef') targetRef: any;
|
||||||
|
@Input() plan: boolean = false;
|
||||||
|
@Input() backgroundColor?: Color;
|
||||||
draggable: boolean = true;
|
draggable: boolean = true;
|
||||||
initialized: boolean = false;
|
rect?: Rect;
|
||||||
|
|
||||||
@Input()
|
constructor(private configService: ConfigService, private cdr: ChangeDetectorRef) { }
|
||||||
plan: boolean = false;
|
|
||||||
|
|
||||||
@Input()
|
|
||||||
backgroundColor?: Color;
|
|
||||||
|
|
||||||
@ViewChild("moveableRef")
|
|
||||||
moveableRef!: NgxMoveableComponent;
|
|
||||||
|
|
||||||
constructor(private configService: ConfigService) {}
|
|
||||||
|
|
||||||
ngOnInit(): void {
|
|
||||||
|
|
||||||
|
transform() {
|
||||||
|
return `translate(${this.rect!.x}px, ${this.rect!.y}px)`;
|
||||||
}
|
}
|
||||||
|
|
||||||
ngAfterViewInit(): void {
|
width() {
|
||||||
let init = this.configService.config.initialPlanWindowPosition;
|
return `${this.rect!.width}px`;
|
||||||
this.setPosition(init.x, init.y);
|
|
||||||
this.setArea(init.width, init.height);
|
|
||||||
this.initialized = true;
|
|
||||||
console.log("init: ", init);
|
|
||||||
console.log("cfg at init: ", this.configService.config);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setPosition(x: number, y: number) {
|
height() {
|
||||||
this.moveableRef.request("draggable", {
|
return `${this.rect!.height}px`;
|
||||||
x,
|
|
||||||
y,
|
|
||||||
}, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setArea(width: number, height: number) {
|
ngAfterViewInit(): void {
|
||||||
this.moveableRef.request("resizable", {
|
this.rect = this.configService.config.initialPlanWindowPosition;
|
||||||
offsetWidth: width,
|
this.cdr.detectChanges();
|
||||||
offsetHeight: height,
|
|
||||||
}, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
toRect(): Rect {
|
|
||||||
let rectInfo = this.moveableRef.getRect();
|
|
||||||
return {
|
|
||||||
x: rectInfo.left,
|
|
||||||
y: rectInfo.top,
|
|
||||||
width: rectInfo.width,
|
|
||||||
height: rectInfo.height
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onDrag(e: OnDrag) {
|
onDrag(e: OnDrag) {
|
||||||
e.target.style.transform = e.transform;
|
this.rect!.x = e.translate[0];
|
||||||
|
this.rect!.y = e.translate[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
onDragEnd(e: OnDragEnd) {
|
onDragEnd(e: OnDragEnd) {
|
||||||
if (this.initialized) {
|
this.configService.config.initialPlanWindowPosition = this.rect!;
|
||||||
this.configService.config.initialPlanWindowPosition = this.toRect();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onResize(e: OnResize) {
|
onResize(e: OnResize) {
|
||||||
e.target.style.width = `${e.width}px`;
|
this.rect!.width = e.width;
|
||||||
e.target.style.height = `${e.height}px`;
|
this.rect!.height = e.height;
|
||||||
e.target.style.transform = e.drag.transform;
|
this.onDrag(e.drag);
|
||||||
|
|
||||||
|
console.log(e.style);
|
||||||
}
|
}
|
||||||
|
|
||||||
onResizeEnd(e: OnResizeEnd) {
|
onResizeEnd(e: OnResizeEnd) {
|
||||||
if (this.initialized) {
|
this.configService.config.initialPlanWindowPosition = this.rect!;
|
||||||
this.configService.config.initialPlanWindowPosition = this.toRect();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in new issue