3bafcc9fad3d6d2c870b2bd41278919f8dc9063c
[sdc/sdc-workflow-designer.git] / sdc-workflow-designer-ui / src / app / directive / resizable / resizable.directive.ts
1 /**
2  * Copyright (c) 2017 ZTE Corporation.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * and the Apache License 2.0 which both accompany this distribution,
6  * and are available at http://www.eclipse.org/legal/epl-v10.html
7  * and http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Contributors:
10  *     ZTE - initial API and implementation and/or initial documentation
11  */
12
13 import { AfterViewInit, Directive, ElementRef } from '@angular/core';
14 import * as $ from 'jquery';
15
16 import { JsPlumbService } from '../../services/jsplumb.service';
17 import { ModelService } from '../../services/model.service';
18
19 @Directive({ selector: '[b4tResizable]' })
20 export class ResizableDirective implements AfterViewInit {
21
22     constructor(private el: ElementRef,
23                 private jsPlumbService: JsPlumbService,
24                 private planModelService: ModelService) {
25     }
26
27     public ngAfterViewInit() {
28         console.log('init resizble.');
29         
30         $(this.el.nativeElement).resizable({
31             handles: 'all',
32             resize: (event, ui) => {
33                 const element = ui.helper[0];
34                 this.planModelService.updatePosition(element.id,
35                     element.offsetLeft, element.offsetTop, element.offsetWidth, element.offsetHeight - 12);
36                 this.jsPlumbService.resizeParent(element, element.parentNode);
37                 const node = this.planModelService.getNodeMap().get(element.id);
38                 this.jsPlumbService.jsplumbInstanceMap.get(node.parentId).revalidate(element.id);
39             },
40         });
41     }
42 }