Skip to content
This repository has been archived by the owner on Apr 17, 2018. It is now read-only.

Commit

Permalink
Merge pull request #24 from mozilla/draw-route-ui
Browse files Browse the repository at this point in the history
feat(draw-route): scaffold the draw route UI
  • Loading branch information
Frozenfire92 committed Sep 24, 2014
2 parents 209e701 + 6c9b644 commit 982b0ba
Show file tree
Hide file tree
Showing 10 changed files with 582 additions and 14 deletions.
8 changes: 6 additions & 2 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<!-- Place favicon.ico and apple-touch-icon.png in the root directory -->
<!-- build:css(.) styles/vendor.css -->
<!-- bower:css -->
<link rel="stylesheet" href="bower_components/jsplumb/dist/css/jsplumb.css" />
<link rel="stylesheet" href="bower_components/jsplumb/css/demo-all.css" />
<!-- endbower -->
<!-- endbuild -->
<!-- build:css(.tmp) styles/main.css -->
Expand All @@ -23,7 +25,7 @@
<div ng-view=""></div>

<!-- Google Analytics: change UA-XXXXX-X to be your site's ID -->
<script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
Expand Down Expand Up @@ -63,14 +65,16 @@
<script src="bower_components/angular-animate/angular-animate.js"></script>
<script src="bower_components/angular-touch/angular-touch.js"></script>
<script src="bower_components/angular-route/angular-route.js"></script>
<script src="bower_components/jsplumb/dist/js/dom.jsPlumb-1.6.2.js"></script>
<script src="bower_components/jsplumb/dist/js/jquery.jsPlumb-1.6.4.js"></script>
<script src="bower_components/jquery-ui/jquery-ui.js"></script>
<!-- endbower -->
<!-- endbuild -->

<!-- build:js({.tmp,app}) scripts/scripts.js -->
<script src="scripts/app.js"></script>
<script src="scripts/controllers/main.js"></script>
<script src="scripts/controllers/about.js"></script>
<script src="scripts/controllers/draw.js"></script>
<!-- endbuild -->
</body>
</html>
3 changes: 3 additions & 0 deletions app/scripts/app.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ angular
.when '/about',
templateUrl: 'views/about.html'
controller: 'AboutCtrl'
.when '/draw',
templateUrl: 'views/draw.html'
controller: 'DrawCtrl'
.otherwise
redirectTo: '/'

255 changes: 255 additions & 0 deletions app/scripts/controllers/draw.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,255 @@
'use strict'

###*
# @ngdoc function
# @name seaspongeApp.controller:DrawCtrl
# @description
# # DrawCtrl
# Controller of the seaspongeApp
###
angular.module('seaspongeApp')
.controller 'DrawCtrl', ($scope) ->

jsPlumb.ready ->
instance = jsPlumb.getInstance(
# default drag options
DragOptions:
cursor: "pointer"
zIndex: 2000
# the overlays to decorate each connection with. note that the label overlay uses a function to generate the label text; in this
# case it returns the 'labelText' member that we set on each connection in the 'init' method below.
ConnectionOverlays: [
[
"Arrow"
{
location: 1
}
]
[
"Label"
{
location: 0.1
id: "label"
cssClass: "aLabel"
}
]
]
Container: "content-right"
)

# this is the paint style for the connecting lines..
connectorPaintStyle =
lineWidth: 4
strokeStyle: "#61B7CF"
joinstyle: "round"
outlineColor: "white"
outlineWidth: 2

connectorHoverStyle =
# .. and this is the hover style.
lineWidth: 4
strokeStyle: "#216477"
outlineWidth: 2
outlineColor: "white"

endpointHoverStyle =
fillStyle: "#216477"
strokeStyle: "#216477"

sourceEndpoint =
# the definition of source endpoints (the small blue ones)
endpoint: "Dot"
paintStyle:
strokeStyle: "#7AB02C"
fillStyle: "transparent"
radius: 7
lineWidth: 3
isSource: true
connector: [
"Flowchart"
{
stub: [
40
60
]
gap: 10
cornerRadius: 5
alwaysRespectStubs: true
}
]
connectorStyle: connectorPaintStyle
hoverPaintStyle: endpointHoverStyle
connectorHoverStyle: connectorHoverStyle
dragOptions: {}
overlays: [[
"Label"
{
location: [
0.5
1.5
]
label: "Drag"
cssClass: "endpointSourceLabel"
}
]]

targetEndpoint =
# the definition of target endpoints (will appear when the user drags a connection)
endpoint: "Dot"
paintStyle:
fillStyle: "#7AB02C"
radius: 11
hoverPaintStyle: endpointHoverStyle
maxConnections: -1
dropOptions:
hoverClass: "hover"
activeClass: "active"
isTarget: true
overlays: [[
"Label"
{
location: [
0.5
-0.5
]
label: "Drop"
cssClass: "endpointTargetLabel"
}
]]

init = (connection) ->
connection.getOverlay("label").setLabel connection.sourceId.substring(15) + "-" + connection.targetId.substring(15)
connection.bind "editCompleted", (o) ->
console.log "connection edited. path is now ", o.path unless typeof console is "undefined"
return
return

_addEndpoints = (toId, sourceAnchors, targetAnchors) ->
i = 0
while i < sourceAnchors.length
sourceUUID = toId + sourceAnchors[i]
instance.addEndpoint "flowchart" + toId, sourceEndpoint,
anchor: sourceAnchors[i]
uuid: sourceUUID
i++
j = 0
while j < targetAnchors.length
targetUUID = toId + targetAnchors[j]
instance.addEndpoint "flowchart" + toId, targetEndpoint,
anchor: targetAnchors[j]
uuid: targetUUID
j++
return

# suspend drawing and initialise.
instance.doWhileSuspended ->
_addEndpoints "Window4", [
"TopCenter"
"BottomCenter"
], [
"LeftMiddle"
"RightMiddle"
]
_addEndpoints "Window2", [
"LeftMiddle"
"BottomCenter"
], [
"TopCenter"
"RightMiddle"
]
_addEndpoints "Window3", [
"RightMiddle"
"BottomCenter"
], [
"LeftMiddle"
"TopCenter"
]
_addEndpoints "Window1", [
"LeftMiddle"
"RightMiddle"
], [
"TopCenter"
"BottomCenter"
]

# listen for new connections; initialise them the same way we initialise the connections at startup.
instance.bind "connection", (connInfo, originalEvent) ->
init connInfo.connection
return

# make all the window divs draggable
instance.draggable jsPlumb.getSelector(".flowchart-demo .window"),
grid: [
20
20
]

# THIS DEMO ONLY USES getSelector FOR CONVENIENCE. Use your library's appropriate selector
# method, or document.querySelectorAll:
#jsPlumb.draggable(document.querySelectorAll(".window"), { grid: [20, 20] });

# connect a few up
instance.connect
uuids: [
"Window2BottomCenter"
"Window3TopCenter"
]
editable: true

instance.connect
uuids: [
"Window2LeftMiddle"
"Window4LeftMiddle"
]
editable: true

instance.connect
uuids: [
"Window4TopCenter"
"Window4RightMiddle"
]
editable: true

instance.connect
uuids: [
"Window3RightMiddle"
"Window2RightMiddle"
]
editable: true

instance.connect
uuids: [
"Window4BottomCenter"
"Window1TopCenter"
]
editable: true

instance.connect
uuids: [
"Window3BottomCenter"
"Window1BottomCenter"
]
editable: true

#
#
# listen for clicks on connections, and offer to delete connections on click.
#
instance.bind "click", (conn, originalEvent) ->
jsPlumb.detach conn if confirm("Delete connection from " + conn.sourceId + " to " + conn.targetId + "?")
return

instance.bind "connectionDrag", (connection) ->
console.log "connection " + connection.id + " is being dragged. suspendedElement is ", connection.suspendedElement, " of type ", connection.suspendedElementType
return

instance.bind "connectionDragStop", (connection) ->
console.log "connection " + connection.id + " was dragged"
return

instance.bind "connectionMoved", (params) ->
console.log "connection " + params.connection.id + " was moved"
return
return
jsPlumb.fire "jsPlumbDemoLoaded", instance
return
57 changes: 57 additions & 0 deletions app/styles/draw.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
.flowchart-demo .window { border:1px solid #346789;
box-shadow: 2px 2px 19px #aaa;
-o-box-shadow: 2px 2px 19px #aaa;
-webkit-box-shadow: 2px 2px 19px #aaa;
-moz-box-shadow: 2px 2px 19px #aaa;
-moz-border-radius:0.5em;
border-radius:0.5em;
opacity:0.8;
filter:alpha(opacity=80);

text-align:center;
z-index:20; position:absolute;
background-color:#eeeeef;
color:black;
font-family:helvetica;padding:0.5em;
font-size:0.9em;
}

.flowchart-demo .window:hover {
box-shadow: 2px 2px 19px #444;
-o-box-shadow: 2px 2px 19px #444;
-webkit-box-shadow: 2px 2px 19px #444;
-moz-box-shadow: 2px 2px 19px #444;
opacity:0.6;
filter:alpha(opacity=60);
}

.flowchart-demo .active {
border:1px dotted green;
}
.flowchart-demo .hover {
border:1px dotted red;
}

#flowchartWindow1 { top:34em;left:5em;}
#flowchartWindow2 { top:7em; left:36em;}
#flowchartWindow3 { top:27em;left:48em; }
#flowchartWindow4 { top:23em; left:22em;}
.flowchart-demo ._jsPlumb_connector { z-index:4; }
.flowchart-demo ._jsPlumb_endpoint, .endpointTargetLabel, .endpointSourceLabel{ z-index:21;cursor:pointer; }

.flowchart-demo .aLabel {
background-color:white;
padding:0.4em;
font:12px sans-serif;
color:#444;
z-index:21;
border:1px dotted gray;
opacity:0.8;
filter:alpha(opacity=80);
cursor: pointer;
}
.flowchart-demo .aLabel._jsPlumb_hover {
background-color:#5C96BC;
color:white;
border:1px solid white;
}
Loading

0 comments on commit 982b0ba

Please sign in to comment.