From 76a42d1bb16aa82dc83929b73a18caf3bf31a449 Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Sun, 26 Oct 2014 18:36:50 -0300 Subject: [PATCH] feat(draw-route): add event for stencil instances to be selectable See #10. --- app/index.html | 2 + app/scripts/app.coffee | 1 + app/scripts/controllers/draw.coffee | 44 ++++++++++++++++-- app/scripts/stencils/base.coffee | 3 ++ app/styles/draw.scss | 16 +++++++ app/views/draw.html | 70 ++++++++--------------------- bower.json | 7 ++- 7 files changed, 86 insertions(+), 57 deletions(-) diff --git a/app/index.html b/app/index.html index a7a8cfc..4d1d10e 100644 --- a/app/index.html +++ b/app/index.html @@ -11,6 +11,7 @@ + @@ -79,6 +80,7 @@ + diff --git a/app/scripts/app.coffee b/app/scripts/app.coffee index 4108b02..87e1738 100644 --- a/app/scripts/app.coffee +++ b/app/scripts/app.coffee @@ -17,6 +17,7 @@ angular 'ngSanitize', 'ngTouch', 'ui.bootstrap' + 'ui.select' ]) .config ($routeProvider) -> $routeProvider diff --git a/app/scripts/controllers/draw.coffee b/app/scripts/controllers/draw.coffee index 8b25b93..c6f58c8 100644 --- a/app/scripts/controllers/draw.coffee +++ b/app/scripts/controllers/draw.coffee @@ -12,6 +12,24 @@ angular.module('seaspongeApp') $scope.stencils = window.stencils + $scope.menu = { + stencilsOpen: false + propertiesOpen: false + } + + $scope.selectedStencil = false + + # Get container + $scope.container = $('#flowchart-demo') + + $scope.stencilTypes = (() -> + arr = [] + arr.push(stencil.type) for name, stencil of $scope.stencils \ + when arr.indexOf(stencil.type) is -1 and stencil.type isnt "Base" + console.log('types', arr, $scope.stencils) + return arr + )() + jsPlumb.ready -> $scope.instance = instance = jsPlumb.getInstance( # default drag options @@ -87,19 +105,37 @@ angular.module('seaspongeApp') console.log "contextmenu: ", component, originalEvent return + $scope.container.on "stencil-instance-click", (e1, inst, e2) -> + console.log "stencil-instance-click", arguments + $scope.$apply -> + # Remove selected class from all selected + $('.selected-stencil').removeClass('selected-stencil') + # Check if same or different stencil instance + if $scope.selectedStencil is inst + # Same instance + # Change selected in $scope + $scope.selectedStencil = null + $scope.menu.propertiesOpen = false + else + # Add selected class + inst.$element.addClass('selected-stencil') + # Change selected in $scope + $scope.selectedStencil = inst + $scope.menu.stencilsOpen = false + $scope.menu.propertiesOpen = true + + return jsPlumb.fire "jsPlumbDemoLoaded", instance return $scope.addStencil = (stencilClass) -> instance = $scope.instance - # Get container - $container = $('#flowchart-demo') - console.log($container) + console.log('container', $scope.container) # Generate UUID uuid = jsPlumbUtil.uuid() console.log('uuid: ', uuid) # # stencil = new stencils.BaseStencil(uuid, $container, instance) - stencil = new stencilClass(uuid, $container, instance) + stencil = new stencilClass(uuid, $scope.container, instance) console.log(stencil) diff --git a/app/scripts/stencils/base.coffee b/app/scripts/stencils/base.coffee index 4a6e87d..3044080 100644 --- a/app/scripts/stencils/base.coffee +++ b/app/scripts/stencils/base.coffee @@ -19,6 +19,9 @@ class @stencils.BaseStencil $element.addClass(cls) # Add to container @$container.append($element); + # Add events + @$element.click (event) => + @$container.trigger "stencil-instance-click", [@, event] # suspend drawing and initialise. @plumbInstance.doWhileSuspended => console.log(@plumbInstance) diff --git a/app/styles/draw.scss b/app/styles/draw.scss index 0a4c6e3..c571b2f 100644 --- a/app/styles/draw.scss +++ b/app/styles/draw.scss @@ -77,3 +77,19 @@ color: white; border: 1px solid white; } + +.stencil.selected-stencil { + background-color: blue; +} + +/* Prevent the text contents of draggable elements from being selectable. */ +[draggable] { + -moz-user-select: none; + -khtml-user-select: none; + -webkit-user-select: none; + user-select: none; + /* Required to make elements draggable in old WebKit */ + -khtml-user-drag: element; + -webkit-user-drag: element; +} + diff --git a/app/views/draw.html b/app/views/draw.html index f6bd09f..f87fb44 100644 --- a/app/views/draw.html +++ b/app/views/draw.html @@ -30,72 +30,38 @@
+ - + Stencils - - -
-
- - + - - + + - Properties - OS Process + Properties + - {{selectedStencil.constructor.title}} + {{selectedStencil.constructor.type}} + + +
diff --git a/bower.json b/bower.json index 6712366..18ff6cf 100644 --- a/bower.json +++ b/bower.json @@ -15,7 +15,8 @@ "angular-route": "1.2.16", "jsplumb": "~1.6.2", "jquery-ui": "~1.11.1", - "angular-bootstrap": "~0.11.2" + "angular-bootstrap": "~0.11.2", + "angular-ui-select": "~0.8.3" }, "devDependencies": { "angular-mocks": "1.2.16", @@ -29,5 +30,9 @@ "dist/js/jquery.jsPlumb-1.6.4.js" ] } + }, + "resolutions": { + "angular": ">=1.2.18", + "angular-ui-select": "~0.8.3" } }