diff --git a/src/canvas-view/canvas-editor/canvas-editor.component.js b/src/canvas-view/canvas-editor/canvas-editor.component.js index 2b0b0de56..1c00a2c8f 100644 --- a/src/canvas-view/canvas-editor/canvas-editor.component.js +++ b/src/canvas-view/canvas-editor/canvas-editor.component.js @@ -4,13 +4,13 @@ angular.module('patternfly.canvas').component('pfCanvasEditor', { bindings: { - chartDataModel: "=", - chartViewModel: "=?", - toolboxTabs: "=", + chartDataModel: '=', + chartViewModel: '=?', + toolboxTabs: '=', readOnly: 'ul").addClass('nav-tabs-pf'); - angular.element("#filterFld").focus(); + angular.element('.subtabs>u').addClass('nav-tabs-pf'); + angular.element('#filterFld').focus(); }); }; @@ -79,7 +79,7 @@ }; ctrl.tabClicked = function () { - angular.element("#filterFld").focus(); + angular.element('#filterFld').focus(); }; /*** Toolbox ***/ @@ -109,7 +109,7 @@ }; ctrl.tabClicked = function () { - angular.element("#filterFld").focus(); + angular.element('#filterFld').focus(); }; ctrl.activeTab = function () { diff --git a/src/canvas-view/canvas-editor/toolbox-items.component.js b/src/canvas-view/canvas-editor/toolbox-items.component.js new file mode 100644 index 000000000..f03ffb21e --- /dev/null +++ b/src/canvas-view/canvas-editor/toolbox-items.component.js @@ -0,0 +1,29 @@ +(function () { + 'use strict'; + + angular.module('patternfly.canvas') + .component('toolboxItems', { + templateUrl: 'canvas-view/canvas-editor/toolbox-items.html', + bindings: { + items: '=', + startDragCallback: '<', + clickCallback: '<', + searchText: '=' + }, + controller: function toolboxItemsController () { + var ctrl = this; + + ctrl.itemClicked = function (item) { + if (angular.isFunction(ctrl.clickCallback) && !item.disableInToolbox) { + ctrl.clickCallback(item); + } + }; + + ctrl.startItemDrag = function (event, ui, item) { + if (angular.isFunction(ctrl.startDragCallback)) { + ctrl.startDragCallback(event, ui, item); + } + }; + } + }); +})(); diff --git a/src/canvas-view/canvas-editor/toolbox-items.directive.js b/src/canvas-view/canvas-editor/toolbox-items.directive.js deleted file mode 100644 index 4421790f6..000000000 --- a/src/canvas-view/canvas-editor/toolbox-items.directive.js +++ /dev/null @@ -1,39 +0,0 @@ -/* eslint-disable */ -(function() { - 'use strict'; - - angular.module('patternfly.canvas') - .directive('toolboxItems', toolboxItemsDirective); - - function toolboxItemsDirective() { - var directive = { - restrict: 'E', - scope: { - items: '=', - startDragCallback: '=', - clickCallback: '=', - searchText: '=' - }, - controller: toolboxItemsController, - templateUrl: 'canvas-view/canvas-editor/toolbox-items.html', - controllerAs: 'vm', - bindToController: true - }; - - return directive; - - function toolboxItemsController() { - var vm = this; - - vm.clickCallbackfmDir = function(item) { - if (!item.disableInToolbox) { - vm.clickCallback(item); - } - }; - - vm.startDragCallbackfmDir = function(event, ui, item) { - vm.startDragCallback(event, ui, item); - }; - } - } -})(); diff --git a/src/canvas-view/canvas-editor/toolbox-items.html b/src/canvas-view/canvas-editor/toolbox-items.html index c5e9be1af..fef10f3d6 100644 --- a/src/canvas-view/canvas-editor/toolbox-items.html +++ b/src/canvas-view/canvas-editor/toolbox-items.html @@ -1,12 +1,12 @@ diff --git a/src/canvas-view/canvas/canvas-component.js b/src/canvas-view/canvas/canvas-component.js new file mode 100644 index 000000000..1a2818bae --- /dev/null +++ b/src/canvas-view/canvas/canvas-component.js @@ -0,0 +1,393 @@ +(function () { + 'use strict'; + + angular.module('patternfly.canvas') + .filter('trustAsResourceUrl', ['$sce', function ($sce) { + return function (val) { + return $sce.trustAsResourceUrl(val); + }; + }]) + + // + // Component that generates the rendered chart from the data model. + // + .component('pfCanvas', { + templateUrl: 'canvas-view/canvas/canvas.html', + bindings: { + chartDataModel:'=', + chartViewModel: '=?', + readOnly: ' startPoint.x ? startPoint.x : curPoint.x, + y: curPoint.y > startPoint.y ? startPoint.y : curPoint.y, + width: curPoint.x > startPoint.x ? curPoint.x - startPoint.x : startPoint.x - curPoint.x, + height: curPoint.y > startPoint.y ? curPoint.y - startPoint.y : startPoint.y - curPoint.y, + }; + }, + + // + // Dragging has ended... select all that are within the drag selection rect. + // + dragEnded: function () { + ctrl.dragSelecting = false; + ctrl.chart.applySelectionRect(ctrl.dragSelectionRect); + delete ctrl.dragSelectionStartPoint; + delete ctrl.dragSelectionRect; + } + }); + }; + + // + // Handle nodeMouseOver on an node. + // + ctrl.nodeMouseOver = function (evt, node) { + if (!ctrl.readOnly) { + ctrl.mouseOverNode = node; + } + }; + + // + // Handle nodeMouseLeave on an node. + // + ctrl.nodeMouseLeave = function () { + ctrl.mouseOverNode = null; + }; + + // + // Handle mousedown on a node. + // + ctrl.nodeMouseDown = function (evt, node) { + var chart = ctrl.chart; + var lastMouseCoords; + + if (ctrl.readOnly) { + return; + } + + dragging.startDrag(evt, { + + // + // Node dragging has commenced. + // + dragStarted: function (x, y) { + lastMouseCoords = ctrl.translateCoordinates(x, y, evt); + + // + // If nothing is selected when dragging starts, + // at least select the node we are dragging. + // + if (!node.selected()) { + chart.deselectAll(); + node.select(); + } + }, + + // + // Dragging selected nodes... update their x,y coordinates. + // + dragging: function (x, y) { + var curCoords = ctrl.translateCoordinates(x, y, evt); + var deltaX = curCoords.x - lastMouseCoords.x; + var deltaY = curCoords.y - lastMouseCoords.y; + + chart.updateSelectedNodesLocation(deltaX, deltaY); + + lastMouseCoords = curCoords; + }, + + // + // The node wasn't dragged... it was clicked. + // + clicked: function () { + chart.handleNodeClicked(node, evt.ctrlKey); + } + + }); + }; + + // + // Listen for node action + // + ctrl.nodeClickHandler = function (action, node) { + if (action === 'nodeActionConnect') { + ctrl.startConnectingMode(node); + } + }; + + ctrl.nodeCloseHandler = function () { + ctrl.mouseOverNode = null; + }; + + ctrl.connectingModeOutputConnector = null; + ctrl.connectingModeSourceNode = null; + + ctrl.startConnectingMode = function (node) { + ctrl.chart.inConnectingMode = true; + ctrl.hideConnectors = false; + ctrl.connectingModeSourceNode = node; + ctrl.connectingModeSourceNode.select(); + ctrl.connectingModeOutputConnector = node.getOutputConnector(); + ctrl.chart.updateValidNodesAndConnectors(ctrl.connectingModeSourceNode); + }; + + ctrl.cancelConnectingMode = function () { + // if output connector not connected to something, remove it + if (!ctrl.connectingModeOutputConnector.connected()) { + ctrl.chart.removeOutputConnector(ctrl.connectingModeOutputConnector); + } + ctrl.stopConnectingMode(); + }; + + ctrl.stopConnectingMode = function () { + ctrl.chart.inConnectingMode = false; + ctrl.chart.resetValidNodesAndConnectors(); + }; + + // + // Handle connectionMouseOver on an connection. + // + ctrl.connectionMouseOver = function (evt, connection) { + if (!ctrl.draggingConnection && !ctrl.readOnly) { // Only allow 'connection mouse over' when not dragging out a connection. + ctrl.mouseOverConnection = connection; + } + }; + + // + // Handle connectionMouseLeave on an connection. + // + ctrl.connectionMouseLeave = function () { + ctrl.mouseOverConnection = null; + }; + + // + // Handle mousedown on a connection. + // + ctrl.connectionMouseDown = function (evt, connection) { + var chart = ctrl.chart; + if (!ctrl.readOnly) { + chart.handleConnectionMouseDown(connection, evt.ctrlKey); + } + // Don't let the chart handle the mouse down. + evt.stopPropagation(); + evt.preventDefault(); + }; + + // + // Handle connectorMouseOver on an connector. + // + ctrl.connectorMouseOver = function (evt, node, connector) { + if (!ctrl.readOnly) { + ctrl.mouseOverConnector = connector; + } + }; + + // + // Handle connectorMouseLeave on an connector. + // + ctrl.connectorMouseLeave = function () { + ctrl.mouseOverConnector = null; + }; + + // + // Handle mousedown on an input connector. + // + ctrl.connectorMouseDown = function (evt, node) { + if (ctrl.chart.inConnectingMode && node !== ctrl.connectingModeSourceNode) { + ctrl.chart.createNewConnection(ctrl.connectingModeOutputConnector, ctrl.mouseOverConnector); + ctrl.stopConnectingMode(); + } + }; + + // + // zoom. + // + $scope.$on('zoomIn', function () { + ctrl.chart.zoom.in(); + }); + + $scope.$on('zoomOut', function () { + ctrl.chart.zoom.out(); + }); + + $scope.maxZoom = function () { + return (ctrl.chart.chartViewModel && ctrl.chart.chartViewModel.zoom) ? ctrl.chart.chartViewModel.zoom.isMax() : false; + }; + $scope.minZoom = function () { + return (ctrl.chart.chartViewModel && ctrl.chart.chartViewModel.zoom) ? ctrl.chart.chartViewModel.zoom.isMin() : false; + }; + + ctrl.zoomLevel = function () { + return ctrl.chart.zoom.getLevel(); + }; + + ctrl.$onInit = function () { + var backspaceKeyCode = 8; + var deleteKeyCode = 46; + var aKeyCode = 65; + var escKeyCode = 27; + + $document.find('body').keydown(function (evt) { + + if (evt.keyCode === aKeyCode && evt.ctrlKey === true) { + // + // Ctrl + A + // + ctrl.selectAll(); + $scope.$digest(); + evt.stopPropagation(); + evt.preventDefault(); + } + + if (evt.keyCode === deleteKeyCode || evt.keyCode === backspaceKeyCode) { + ctrl.deleteSelected(); + $scope.$digest(); + } + + if (evt.keyCode === escKeyCode) { + ctrl.deselectAll(); + $scope.$digest(); + } + }); + }; + } + }); +})(); diff --git a/src/canvas-view/canvas/canvas-directive.js b/src/canvas-view/canvas/canvas-directive.js deleted file mode 100644 index 2763c4f6c..000000000 --- a/src/canvas-view/canvas/canvas-directive.js +++ /dev/null @@ -1,440 +0,0 @@ -(function () { - 'use strict'; - - angular.module('patternfly.canvas') - .filter('trustAsResourceUrl', ['$sce', function ($sce) { - return function (val) { - return $sce.trustAsResourceUrl(val); - }; - }]) - - // - // Directive that generates the rendered chart from the data model. - // - .directive('pfCanvas', function ($document) { - return { - restrict: 'E', - templateUrl: "canvas-view/canvas/canvas.html", - replace: true, - scope: { - chartDataModel: "=", - chartViewModel: "=?", - readOnly: "=?", - hideConnectors: "=?" - }, - controller: 'CanvasController', - link: link - }; - function link (scope) { - var deleteKeyCode = 46; - var ctrlKeyCode = 17; - var ctrlDown = false; - var aKeyCode = 65; - var dKeyCode = 68; - var escKeyCode = 27; - - $document.find('body').keydown(function (evt) { - if (evt.keyCode === ctrlKeyCode) { - ctrlDown = true; - evt.stopPropagation(); - evt.preventDefault(); - } - - if (evt.keyCode === aKeyCode && ctrlDown) { - // - // Ctrl + A - // - scope.selectAll(); - scope.$digest(); - evt.stopPropagation(); - evt.preventDefault(); - } - }); - - $document.find('body').keyup(function (evt) { - if (evt.keyCode === deleteKeyCode) { - scope.deleteSelected(); - scope.$digest(); - } - - if (evt.keyCode === escKeyCode) { - scope.deselectAll(); - scope.$digest(); - } - - if (evt.keyCode === ctrlKeyCode) { - ctrlDown = false; - evt.stopPropagation(); - evt.preventDefault(); - } - }); - } - }) - // - // Controller for the canvas directive. - // Having a separate controller is better for unit testing, otherwise - // it is painful to unit test a directive without instantiating the DOM - // (which is possible, just not ideal). - // - .controller('CanvasController', ['$scope', 'dragging', '$element', '$document', function CanvasController ($scope, dragging, $element, $document) { - var controller = this; - - $scope.chart = new pfCanvas.ChartViewModel($scope.chartDataModel); - $scope.chartViewModel = $scope.chart; - // - // Reference to the document and jQuery, can be overridden for testting. - // - this.document = document; - - // - // Wrap jQuery so it can easily be mocked for testing. - // - this.jQuery = function (element) { - return angular.element(element); - }; - - // - // Init data-model variables. - // - $scope.draggingConnection = false; - $scope.connectorSize = 6; - $scope.dragSelecting = false; - - // - // Reference to the connection, connector or node that the mouse is currently over. - // - $scope.mouseOverConnector = null; - $scope.mouseOverConnection = null; - $scope.mouseOverNode = null; - - // - // The class for connections and connectors. - // - this.connectionClass = 'connection'; - this.connectorClass = 'connector'; - this.nodeClass = 'node'; - - // - // Translate the coordinates so they are relative to the svg element. - // - this.translateCoordinates = function (x, y, evt) { - var svgElem = $element.get(0); - var matrix = svgElem.getScreenCTM(); - var point = svgElem.createSVGPoint(); - point.x = (x - evt.view.pageXOffset) / $scope.zoomLevel(); - point.y = (y - evt.view.pageYOffset) / $scope.zoomLevel(); - - return point.matrixTransform(matrix.inverse()); - }; - - $scope.hideConnectors = $scope.hideConnectors ? $scope.hideConnectors : false; - - $scope.isConnectorConnected = function (connector) { - return (connector && connector.connected()); - }; - - $scope.isConnectorUnconnectedAndValid = function (connector) { - return (connector && !connector.connected() && !connector.invalid() && - connector.parentNode() !== $scope.connectingModeSourceNode); - }; - - // determins if a dest. connector is connected to the source node - $scope.isConnectedTo = function (connector, node) { - var i,connection; - var connections = $scope.chart.connections; - for (i = 0; i < connections.length; i++) { - connection = connections[i]; - if (connection.dest === connector && connection.source.parentNode() === node) { - return true; - } - } - - return false; - }; - - $scope.availableConnections = function () { - return $scope.chart.validConnections; - }; - - $scope.foreignObjectSupported = function () { - return $document[0].implementation.hasFeature('http://www.w3.org/TR/SVG11/feature#Extensibility', '1.1'); - }; - - $scope.addNodeToCanvas = function (newNode) { - $scope.chart.addNode(newNode); - }; - - $scope.$on('selectAll', function (evt, args) { - $scope.selectAll(); - }); - - $scope.selectAll = function () { - $scope.chart.selectAll(); - }; - - $scope.$on('deselectAll', function (evt, args) { - $scope.deselectAll(); - }); - - $scope.deselectAll = function () { - $scope.chart.deselectAll(); - }; - - $scope.$on('deleteSelected', function (evt, args) { - $scope.deleteSelected(); - }); - - $scope.deleteSelected = function () { - $scope.chart.deleteSelected(); - }; - - // - // Called on mouse down in the chart. - // - $scope.mouseDown = function (evt) { - if ($scope.readOnly) { - return; - } - - if ($scope.chart.inConnectingMode ) { - // camceling out of connection mode, remove unused output connector - $scope.cancelConnectingMode(); - } - - $scope.chart.deselectAll(); - - $scope.chart.clickedOnChart = true; - - dragging.startDrag(evt, { - - // - // Commence dragging... setup variables to display the drag selection rect. - // - dragStarted: function (x, y) { - var startPoint; - $scope.dragSelecting = true; - startPoint = controller.translateCoordinates(x, y, evt); - $scope.dragSelectionStartPoint = startPoint; - $scope.dragSelectionRect = { - x: startPoint.x, - y: startPoint.y, - width: 0, - height: 0, - }; - }, - - // - // Update the drag selection rect while dragging continues. - // - dragging: function (x, y) { - var startPoint = $scope.dragSelectionStartPoint; - var curPoint = controller.translateCoordinates(x, y, evt); - - $scope.dragSelectionRect = { - x: curPoint.x > startPoint.x ? startPoint.x : curPoint.x, - y: curPoint.y > startPoint.y ? startPoint.y : curPoint.y, - width: curPoint.x > startPoint.x ? curPoint.x - startPoint.x : startPoint.x - curPoint.x, - height: curPoint.y > startPoint.y ? curPoint.y - startPoint.y : startPoint.y - curPoint.y, - }; - }, - - // - // Dragging has ended... select all that are within the drag selection rect. - // - dragEnded: function () { - $scope.dragSelecting = false; - $scope.chart.applySelectionRect($scope.dragSelectionRect); - delete $scope.dragSelectionStartPoint; - delete $scope.dragSelectionRect; - }, - }); - }; - - // - // Handle nodeMouseOver on an node. - // - $scope.nodeMouseOver = function (evt, node) { - if (!$scope.readOnly) { - $scope.mouseOverNode = node; - } - }; - - // - // Handle nodeMouseLeave on an node. - // - $scope.nodeMouseLeave = function (evt, node) { - $scope.mouseOverNode = null; - }; - - // - // Handle mousedown on a node. - // - $scope.nodeMouseDown = function (evt, node) { - var chart = $scope.chart; - var lastMouseCoords; - - if ($scope.readOnly) { - return; - } - - dragging.startDrag(evt, { - - // - // Node dragging has commenced. - // - dragStarted: function (x, y) { - lastMouseCoords = controller.translateCoordinates(x, y, evt); - - // - // If nothing is selected when dragging starts, - // at least select the node we are dragging. - // - if (!node.selected()) { - chart.deselectAll(); - node.select(); - } - }, - - // - // Dragging selected nodes... update their x,y coordinates. - // - dragging: function (x, y) { - var curCoords = controller.translateCoordinates(x, y, evt); - var deltaX = curCoords.x - lastMouseCoords.x; - var deltaY = curCoords.y - lastMouseCoords.y; - - chart.updateSelectedNodesLocation(deltaX, deltaY); - - lastMouseCoords = curCoords; - }, - - // - // The node wasn't dragged... it was clicked. - // - clicked: function () { - chart.handleNodeClicked(node, evt.ctrlKey); - }, - - }); - }; - - // - // Listen for node action - // - $scope.$on('nodeActionClicked', function (evt, args) { - var action = args.action; - var node = args.node; - - if (action === 'nodeActionConnect') { - $scope.startConnectingMode(node); - } - }); - - $scope.$on('nodeActionClosed', function () { - $scope.mouseOverNode = null; - }); - - $scope.connectingModeOutputConnector = null; - $scope.connectingModeSourceNode = null; - - $scope.startConnectingMode = function (node) { - $scope.chart.inConnectingMode = true; - $scope.hideConnectors = false; - $scope.connectingModeSourceNode = node; - $scope.connectingModeSourceNode.select(); - $scope.connectingModeOutputConnector = node.getOutputConnector(); - $scope.chart.updateValidNodesAndConnectors($scope.connectingModeSourceNode); - }; - - $scope.cancelConnectingMode = function () { - // if output connector not connected to something, remove it - if (!$scope.connectingModeOutputConnector.connected()) { - $scope.chart.removeOutputConnector($scope.connectingModeOutputConnector); - } - $scope.stopConnectingMode(); - }; - - $scope.stopConnectingMode = function () { - $scope.chart.inConnectingMode = false; - $scope.chart.resetValidNodesAndConnectors(); - }; - - // - // Handle connectionMouseOver on an connection. - // - $scope.connectionMouseOver = function (evt, connection) { - if (!$scope.draggingConnection && !$scope.readOnly) { // Only allow 'connection mouse over' when not dragging out a connection. - $scope.mouseOverConnection = connection; - } - }; - - // - // Handle connectionMouseLeave on an connection. - // - $scope.connectionMouseLeave = function (evt, connection) { - $scope.mouseOverConnection = null; - }; - - // - // Handle mousedown on a connection. - // - $scope.connectionMouseDown = function (evt, connection) { - var chart = $scope.chart; - if (!$scope.readOnly) { - chart.handleConnectionMouseDown(connection, evt.ctrlKey); - } - // Don't let the chart handle the mouse down. - evt.stopPropagation(); - evt.preventDefault(); - }; - - // - // Handle connectorMouseOver on an connector. - // - $scope.connectorMouseOver = function (evt, node, connector, connectorIndex, isInputConnector) { - if (!$scope.readOnly) { - $scope.mouseOverConnector = connector; - } - }; - - // - // Handle connectorMouseLeave on an connector. - // - $scope.connectorMouseLeave = function (evt, node, connector, connectorIndex, isInputConnector) { - $scope.mouseOverConnector = null; - }; - - // - // Handle mousedown on an input connector. - // - $scope.connectorMouseDown = function (evt, node, connector, connectorIndex, isInputConnector) { - if ($scope.chart.inConnectingMode && node !== $scope.connectingModeSourceNode) { - $scope.chart.createNewConnection($scope.connectingModeOutputConnector, $scope.mouseOverConnector); - $scope.stopConnectingMode(); - } - }; - - // - // zoom. - // - $scope.$on('zoomIn', function (evt, args) { - $scope.chart.zoom.in(); - }); - - $scope.$on('zoomOut', function (evt, args) { - $scope.chart.zoom.out(); - }); - - $scope.maxZoom = function () { - return ($scope.chart.chartViewModel && $scope.chart.chartViewModel.zoom) ? $scope.chart.chartViewModel.zoom.isMax() : false; - }; - $scope.minZoom = function () { - return ($scope.chart.chartViewModel && $scope.chart.chartViewModel.zoom) ? $scope.chart.chartViewModel.zoom.isMin() : false; - }; - - $scope.zoomLevel = function () { - return $scope.chart.zoom.getLevel(); - }; - } - ]); -})(); diff --git a/src/canvas-view/canvas/canvas.html b/src/canvas-view/canvas/canvas.html index a40b8c210..9a0bd61b4 100644 --- a/src/canvas-view/canvas/canvas.html +++ b/src/canvas-view/canvas/canvas.html @@ -1,282 +1,282 @@ - + - - - - - Select a second item to complete the connection or click on the canvas to cancel - - - No available connections! Click on the canvas to cancel - - + + + + + Select a second item to complete the connection or click on the canvas to cancel + + + No available connections! Click on the canvas to cancel + + - - + - - + - - + - {{node.name()}} - + {{node.name()}} + - - - + + +

{{node.name()}}

- -
+ +
- - + + - - + + - + - + - - - {{node.fontContent()}} - + + + {{node.fontContent()}} + - - - {{'\ue918'}} - + + + {{'\ue918'}} + - - - - + + + + + + + + + + - - - - - - - + - - - + + - + - + - - {{connector.fontContent()}} - + + {{connector.fontContent()}} + - + - - - {{connector.name()}} + + + {{connector.name()}} + - - + - - - - +
+
- + - - + + > - {{connection.name()}} + {{connection.name()}} + ng-class="{'selected-connection-endpoint': connection.selected(), + 'mouseover-connection-endpoint': connection == $ctrl.mouseOverConnection && !connection.selected(), + 'connection-endpoint': connection != $ctrl.mouseOverConnection && !connection.selected()}" + r="5" + ng-attr-cx="{{connection.sourceCoordX()}}" + ng-attr-cy="{{connection.sourceCoordY()}}" + > + ng-class="{'selected-connection-endpoint': connection.selected(), + 'mouseover-connection-endpoint': connection == $ctrl.mouseOverConnection && !connection.selected(), + 'connection-endpoint': connection != $ctrl.mouseOverConnection && !connection.selected()}" + r="5" + ng-attr-cx="{{connection.destCoordX()}}" + ng-attr-cy="{{connection.destCoordY()}}" + > - + - - -
+ +
diff --git a/src/canvas-view/canvas/dragging-service.js b/src/canvas-view/canvas/dragging-service.js index 05a9db39a..13ee6f031 100644 --- a/src/canvas-view/canvas/dragging-service.js +++ b/src/canvas-view/canvas/dragging-service.js @@ -84,13 +84,12 @@ mouseCapture.acquire(evt, { mouseMove: mouseMove, mouseUp: mouseUp, - released: released, + released: released }); evt.stopPropagation(); evt.preventDefault(); - }, - + } }; } })(); diff --git a/src/canvas-view/canvas/mouse-capture-service.js b/src/canvas-view/canvas/mouse-capture-service.js index 57a27d474..ff59db5f2 100644 --- a/src/canvas-view/canvas/mouse-capture-service.js +++ b/src/canvas-view/canvas/mouse-capture-service.js @@ -89,7 +89,7 @@ $element.unbind("mousemove", mouseMove); $element.unbind("mouseup", mouseUp); - }, + } }; } @@ -102,7 +102,7 @@ // Register the directives element as the mouse capture element. // mouseCapture.registerElement($element); - }], + }] }; } diff --git a/src/canvas-view/canvas/node-toolbar.component.js b/src/canvas-view/canvas/node-toolbar.component.js new file mode 100644 index 000000000..df8877de2 --- /dev/null +++ b/src/canvas-view/canvas/node-toolbar.component.js @@ -0,0 +1,34 @@ +(function () { + 'use strict'; + + angular.module('patternfly.canvas') + .component('nodeToolbar', { + templateUrl: 'canvas-view/canvas/node-toolbar.html', + bindings: { + node: '=', + nodeActions: '=', + nodeClickHandler: '<', + nodeCloseHandler: '<' + }, + controller: function NodeToolbarController ($scope) { + var ctrl = this; + ctrl.selectedAction = 'none'; + + ctrl.actionIconClicked = function (action) { + ctrl.selectedAction = action; + $scope.$emit('nodeActionClicked', {'action': action, 'node': ctrl.node}); + if (angular.isFunction(ctrl.nodeClickHandler)) { + ctrl.nodeClickHandler(action, ctrl.node); + } + }; + + ctrl.close = function () { + ctrl.selectedAction = 'none'; + $scope.$emit('nodeActionClosed'); + if (angular.isFunction(ctrl.nodeCloseHandler)) { + ctrl.nodeCloseHandler(); + } + }; + } + }); +})(); diff --git a/src/canvas-view/canvas/node-toolbar.directive.js b/src/canvas-view/canvas/node-toolbar.directive.js deleted file mode 100644 index a36f4beb3..000000000 --- a/src/canvas-view/canvas/node-toolbar.directive.js +++ /dev/null @@ -1,37 +0,0 @@ -(function () { - 'use strict'; - - angular.module('patternfly.canvas') - .directive('nodeToolbar', nodeToolbarDirective); - - function nodeToolbarDirective ($document) { - var directive = { - restrict: 'E', - scope: { - node: '=', - nodeActions: '=', - }, - controller: NodeToolbarController, - templateUrl: 'canvas-view/canvas/node-toolbar.html', - controllerAs: 'vm', - bindToController: true, - }; - - return directive; - - function NodeToolbarController ($scope) { - var vm = this; - vm.selectedAction = "none"; - - $scope.actionIconClicked = function (action) { - vm.selectedAction = action; - $scope.$emit('nodeActionClicked', {'action': action, 'node': vm.node}); - }; - - $scope.close = function () { - vm.selectedAction = 'none'; - $scope.$emit('nodeActionClosed'); - }; - } - } -})(); diff --git a/src/canvas-view/canvas/node-toolbar.html b/src/canvas-view/canvas/node-toolbar.html index 2bf085d7c..2f2fc5094 100644 --- a/src/canvas-view/canvas/node-toolbar.html +++ b/src/canvas-view/canvas/node-toolbar.html @@ -1,6 +1,6 @@ -
- + + ng-click="$ctrl.actionIconClicked(nodeAction.action())">
diff --git a/src/canvas-view/examples/canvas.js b/src/canvas-view/examples/canvas.js index a934da47b..2b9ffe99c 100644 --- a/src/canvas-view/examples/canvas.js +++ b/src/canvas-view/examples/canvas.js @@ -1,10 +1,10 @@ /** * @ngdoc directive - * @name patternfly.canvas.directive:pfCanvas + * @name patternfly.canvas.component:pfCanvas * @restrict E * * @description - * Directive for core operations and rendering of a canvas. Does not work in IE 11 or lower because they do not support + * Component for core operations and rendering of a canvas. Does not work in IE 11 or lower because they do not support * latest svg specification's 'foreignObject' api. Tested in FireFox, Chrome, and MS-Edge. * @param {object} chartDataModel Chart data object which defines the nodes and connections on the canvas * + *
  • .actionIconClicked - function that listens for node actions/events when clicking the items within the node toolbar. + * *
  • .connections - An array of connections between nodes *