1 import { Component, OnInit, ViewEncapsulation } from '@angular/core';
2 import * as $ from 'jquery';
3 import * as _ from 'lodash';
4 import * as joint from '../../../../../../node_modules/jointjs/dist/joint.js';
7 selector: 'app-designer',
8 templateUrl: './designer.component.html',
9 styleUrls: ['./designer.component.css'],
10 encapsulation: ViewEncapsulation.None
12 export class DesignerComponent implements OnInit {
14 private controllerSideBar: boolean;
15 private attributesSideBar: boolean;
20 this.controllerSideBar = true;
21 this.attributesSideBar = false;
23 private _toggleSidebar1() {
24 this.controllerSideBar = !this.controllerSideBar;
26 private _toggleSidebar2() {
27 this.attributesSideBar = !this.attributesSideBar;
32 this.attachEditorBarToCanvas();
35 attachEditorBarToCanvas() {
36 this.graph = new joint.dia.Graph,
37 this.paper = new joint.dia.Paper({
44 cellViewNamespace: joint.shapes
50 { color: 'black', thickness: 2, scaleFactor: 8 }
55 joint.shapes["html"] = {};
56 joint.shapes["html"].Element = joint.shapes.basic.Rect.extend({
57 defaults: joint.util.deepSupplement({
59 }, joint.shapes.basic.Rect.prototype.defaults)
62 joint.shapes["html"].ElementView = joint.dia.ElementView.extend({
66 '<div id="editbar" class="editBar text-center">',
67 '<div class="btn-group mr-2" role="group" aria-label="First group">',
68 '<button type="button" class="btn btn-secondary tooltip-bottom" data-tooltip="Undo">',
69 '<img src="/assets/img/icon-undoActive.svg">',
71 '<button type="button" class="btn btn-secondary tooltip-bottom" data-tooltip="Redo">',
72 '<img src="/assets/img/icon-redo.svg">',
75 '<div class="btn-group mr-2" role="group" aria-label="Second group">',
76 '<button type="button" class="btn btn-secondary tooltip-bottom" data-tooltip="Zoom Out">',
77 '<img src="/assets/img/icon-zoomOut.svg">',
79 '<button type="button" class="btn btn-secondary pl-0 pr-0">100%</button>',
80 '<button type="button" class="btn btn-secondary tooltip-bottom" data-tooltip="Zoom In">',
81 '<img src="/assets/img/icon-zoomIn.svg">',
84 '<div class="btn-group viewBtns" role="group" aria-label="Third group">',
85 '<button type="button" class="btn btn-secondary topologySource active">View</button>',
86 '<button type="button" class="btn btn-secondary topologyView">Source</button>',
92 initialize: function() {
93 _.bindAll(this, 'updateBox');
94 joint.dia.ElementView.prototype.initialize.apply(this, arguments);
96 this.$box = $(_.template(this.template)());
97 // Prevent paper from handling pointerdown.
98 this.$box.find('input,select').on('mousedown click', function(evt) {
99 evt.stopPropagation();
101 this.model.on('change', this.updateBox, this);
106 joint.dia.ElementView.prototype.render.apply(this, arguments);
107 this.paper.$el.prepend(this.$box);
111 updateBox: function() {
112 // Set the position and dimension of the box so that it covers the JointJS element.
113 var bbox = this.model.getBBox();
119 transform: 'rotate(' + (this.model.get('angle') || 0) + 'deg)'
124 var el1 = new joint.shapes["html"].Element({});
125 this.graph.addCells([el1]);