-
Notifications
You must be signed in to change notification settings - Fork 130
/
index.html
399 lines (369 loc) · 17.3 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
<!DOCTYPE html>
<html>
<head>
<!-- META -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1">
<meta name="robots" content="index,follow">
<meta name="description" content="decent looking diagrams for engineers">
<link rel="icon"
type="image/png"
href="./build/images/radial.png" />
<base href="/">
<title>Decent looking diagrams for engineers</title>
<link rel="stylesheet" href="build/css/bootstrap.min.css">
<link rel="stylesheet" href="build/css/font-awesome.min.css">
<link rel="stylesheet" href="build/css/app.css">
<link rel="stylesheet" href="build/css/notes.css">
<script type="text/javascript" src="build/js/angular.min.js"></script>
<script type="text/javascript" src="build/js/angular-animate.min.js"></script>
<script type="text/javascript" src="build/js/ui-ace.min.js"></script>
<script type="text/javascript" src="build/js/ui-bootstrap.min.js"></script>
<script type="text/javascript" src="build/js/ui-bootstrap-tpls.min.js"></script>
<script type="text/javascript" src="build/js/js-yaml.min.js"></script>
<script type="text/javascript" src="./build/js/d3.min.js"></script>
<script type="text/javascript" src="./build/js/showdown.js"></script>
<script type="text/javascript" src="./build/js/showdown-prettify.min.js"></script>
<script type="text/javascript" src="./build/js/prettify/run_prettify.js"></script>
<!-- previous version of ace caused import conflict -->
<script src="http://cdnjs.cloudflare.com/ajax/libs/ace/1.1.3/ace.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" src="build/js/dld4e-connections.js"></script>
<script type="text/javascript" src="build/js/dld4e-draw.js"></script>
<script type="text/javascript" src="build/js/dld4e-gridlines.js"></script>
<script type="text/javascript" src="build/js/dld4e-groups.js"></script>
<script type="text/javascript" src="build/js/dld4e-icons.js"></script>
<script type="text/javascript" src="build/js/dld4e-title.js"></script>
<script type="text/javascript" src="build/js/dld4e-notes.js"></script>
<script type="text/javascript" src="build/js/dld4e-process.js"></script>
<script type="text/javascript" src="build/js/app.js"></script>
<script type="text/javascript" src="build/js/saveSvgAsPng.js"></script>
</head>
<body ng-app="dld4e" ng-controller="mainController">
<uib-alert class="col-sm-6 col-sm-offset-3" ng-repeat="alert in alerts" type="{{alert.type}}" close="closeAlert($index)">
<span ng-bind-html="alert.msg"></span>
</uib-alert>
<div class="row">
<div class="col-sm-6" id="leftSide">
<div class="row no-gutters">
<div class="col-sm-11 container-fluid">
<button id="save" class="btn btn-black btn-sm" ng-click="save()">
<span ng-class="saveIcon" aria-hidden="true" ></span> <span ng-bind="state"></span>
</button>
<button id="fork" class="btn btn-black btn-sm" ng-click="fork()">
<span class="fa fa-code-fork" aria-hidden="true" ></span> Fork
</button>
<button id="download" class="btn btn-black btn-sm" ng-click="saveFile()">
<span class="glyphicon glyphicon-floppy-save" aria-hidden="true" ></span> Download
</button>
<button id="link" class="btn btn-black btn-sm" ng-click="link()">
<span class="fa fa-clipboard" aria-hidden="true" ></span><span ng-bind="linkText">Link</span>
</button>
<form class="form-inline">
<div class="input-group">
<input type="text" size="35" class="form-control input-sm" ng-model="gistURL" placeholder="Load from Github Gist">
<span class="input-group-btn">
<button class="btn btn-black btn-sm" type="submit" ng-click="gist()">
<span class="fa fa-cloud-download"></span>
</button>
</span>
</div>
</form>
</div>
<div class="col-sm-1">
<button id="draw" class="btn btn-black btn-sm pull-right" ng-click="drawClick(value)" uib-tooltip="hint: press ctrl-enter to refresh the drawing" tooltip-placement="bottom" tooltip-append-to-body="true">
<span class="glyphicon glyphicon glyphicon-pencil" aria-hidden="true" ></span> Draw
</button>
</div>
</div>
<div class="row">
<div ui-ace="aceyamlOptions" ng-model="acedata"></div>
</div>
</div>
<div class="col-sm-6" id="rightSide">
<div class="row pull-right">
<button id="saveimage" type="button" class="btn btn-black btn-sm" ng-click="saveImage()" uib-tooltip="Save SVG as Image" tooltip-placement="bottom" tooltip-append-to-body="true">
<span class="glyphicon glyphicon glyphicon-floppy-save" aria-hidden="true" ></span> PNG
</button>
<div class="btn-group" uib-dropdown is-open="status.isopen1" ng-show="shown">
<button id="examples" type="button" class="btn btn-black btn-sm" uib-dropdown-toggle ng-disabled="disabled">
Examples<span class="caret"></span>
</button>
<ul class="dropdown-menu" uib-dropdown-menu role="menu" aria-labelledby="examples">
<li role="menuitem" ng-click="example('coffee.yaml')"><a href="javascript:void(0);">Coffee Colors</a></li>
<li role="menuitem" ng-click="example('curves.yaml')"><a href="javascript:void(0);">Curves</a></li>
<li role="menuitem" ng-click="example('groups.yaml')"><a href="javascript:void(0);">Groups</a></li>
<li role="menuitem" ng-click="example('group connections.yaml')"><a href="javascript:void(0);">Group connections</a></li>
<li role="menuitem" ng-click="example('labels.yaml')"><a href="javascript:void(0);">Labels</a></li>
<li role="menuitem" ng-click="example('mouseover.yaml')"><a href="javascript:void(0);">Mouseover Metadata</a></li>
<li role="menuitem" ng-click="example('notes.yaml')"><a href="javascript:void(0);">Notes</a></li>
<li role="menuitem" ng-click="example('NTP.yaml')"><a href="javascript:void(0);">NTP</a></li>
<li role="menuitem" ng-click="example('relative positions.yaml')"><a href="javascript:void(0);">Relative positions</a></li>
<li role="menuitem" ng-click="example('sample.yaml')"><a href="javascript:void(0);">Sample</a></li>
<li role="menuitem" ng-click="example('text locations.yaml')"><a href="javascript:void(0);">Text locations</a></li>
<li role="menuitem" ng-click="example('urls.yaml')"><a href="javascript:void(0);">URLs for icons</a></li>
</ul>
</div>
<div class="btn-group" uib-dropdown is-open="status.isopen2" ng-show="shown">
<button id="foo" type="button" class="btn btn-black btn-sm" uib-dropdown-toggle ng-disabled="disabled">
Icons<span class="caret"></span>
</button>
<ul class="dropdown-menu" uib-dropdown-menu role="menu" aria-labelledby="icons">
<li role="menuitem" ng-click="drawIconFamily('aws-native')"><a href="javascript:void(0);">aws</a></li>
<li role="menuitem" ng-click="drawIconFamily('aws-filled')"><a href="javascript:void(0);">aws (iconFill)</a></li>
<li role="menuitem" ng-click="drawIconFamily('aws-stroke')"><a href="javascript:void(0);">aws (iconStroke)</a></li>
<li role="menuitem" ng-click="drawIconFamily('cisco-native')"><a href="javascript:void(0);">cisco</a></li>
<li role="menuitem" ng-click="drawIconFamily('cisco-filled')"><a href="javascript:void(0);">cisco (iconFill)</a></li>
<li role="menuitem" ng-click="drawIconFamily('cisco-stroke')"><a href="javascript:void(0);">cisco (iconStroke)</a></li>
<li role="menuitem" ng-click="drawIconFamily('azureEnterprise-native')"><a href="javascript:void(0);">azureEnterprise</a></li>
<li role="menuitem" ng-click="drawIconFamily('azureEnterprise-filled')"><a href="javascript:void(0);">azureEnterprise (iconFill)</a></li>
<li role="menuitem" ng-click="drawIconFamily('azureEnterprise-stroke')"><a href="javascript:void(0);">azureEnterprise (iconStroke)</a></li>
<li role="menuitem" ng-click="drawIconFamily('azureCloud-native')"><a href="javascript:void(0);">azureCloud</a></li>
<li role="menuitem" ng-click="drawIconFamily('azureCloud-filled')"><a href="javascript:void(0);">azureCloud (iconFill)</a></li>
<li role="menuitem" ng-click="drawIconFamily('azureCloud-stroke')"><a href="javascript:void(0);">azureCloud (iconStroke)</a></li>
</ul>
</div>
<a href="http://github.com/cidrblock/network_diagram" target="_blank" class="btn btn-black btn-sm">
<span class="fa fa-github"></span> Github
</a>
<button id="fullScreen" class="btn btn-black btn-sm" ng-click="fullScreen()">
<span class="fa fa-pencil-square-o" aria-hidden="true"></span><span ng-bind="mode"></span>
</button>
</div>
<div class="row">
<div class="drawing" id="svg"></div>
</div>
</div>
</div>
</div>
</body>
<script>
angular
.module("dld4e", ['ui.bootstrap', 'ui.ace'])
.controller("mainController", mainController)
mainController.$inject = ["$scope", "$http", "$sce", "$log", "$window", "$location", "$timeout", "$animate"];
function mainController($scope, $http, $sce, $log, $window, $location, $timeout, $animate) {
var w = angular.element($window);
w.bind('resize', function () {
$scope.drawClick()
});
$scope.mode = " Hide editor"
$scope.shown = true
$scope.design = "";
$scope.gistURL = "";
$scope.dbURL = "https://syg5y0qnyf.execute-api.us-west-2.amazonaws.com/prod/"
$scope.saveIcon = "glyphicon glyphicon-floppy-disk"
$scope.linkText = " Link"
$scope.docId = $window.location.hash.substring(2)
if ($scope.docId) {
$scope.url = $scope.dbURL + $scope.docId
$scope.state = "Update";
var leftSide = angular.element( document.querySelector( '#leftSide' ) );
var rightSide = angular.element( document.querySelector( '#rightSide' ) );
$scope.shown = false
$scope.mode = " Show editor"
$animate.setClass(leftSide, 'ng-hide', 'ng-show').then(function() {
$animate.setClass(rightSide, 'col-sm-12', 'col-sm-6').then(function() {
$http.get($scope.url)
.then(function(res){
$scope.acedata = res.data;
$scope.drawClick()
});
})
})
} else {
$scope.url = 'examples/NTP.yaml'
$scope.state = "Save";
$http.get($scope.url)
.then(function(res){
$scope.acedata = res.data;
$scope.drawClick()
});
}
$scope.aceyamlOptions = {
onLoad: function (_ace) {
_ace.getSession().setMode("ace/mode/yaml");
_ace.$blockScrolling = Infinity;
_ace.commands.addCommand({
name: 'saveFile',
bindKey: {
win: 'Ctrl-S',
mac: 'Command-S',
sender: 'editor|cli'
},
exec: function(env, args, request) {
$scope.saveFile();
}
});
_ace.setOption("tabSize", 2);
}
};
$scope.opend3js = function(greeting) {
$window.design = jsyaml.load($scope.acedata) || {};
var w = $window.open("fullscreen.html");
};
$scope.drawIconFamily = function(iconFamily) {
var wi = window.open('about:blank', '_blank');
$http.get('./build/js/iconFamilies.json')
.then(function(res){
var iconFamilies = res.data
var bestFit = Math.ceil(Math.sqrt(size))
var familyName = iconFamily.split('-')[0]
var size = iconFamilies[familyName].length
var url = "./templates/" + iconFamily + ".yaml"
$http.get(url)
.then(function(res){
var doc = jsyaml.load(res.data);
var ratios = doc.diagram.aspectRatio.split(':')
var h = ratios[0]
var w = ratios[1]
doc.diagram.rows = Math.ceil(Math.sqrt(size*w/h))
doc.diagram.columns = Math.ceil(size/doc.diagram.rows)
var x = 0
var y = doc.diagram.rows - 1
doc.icons = {}
for (var icon in iconFamilies[familyName]){
doc.icons[iconFamilies[familyName][icon]] = Object.assign( { x: x, y: y, icon: iconFamilies[familyName][icon]}, doc.icon)
x += 1
if (x == doc.diagram.columns) {
x = 0
y -= 1
}
}
$window.design = doc;
wi.location.href = 'fullscreen.html';
});
});
}
$scope.example = function(file) {
$http.get("examples/" + file)
.then(function(res){
$scope.acedata = res.data;
$window.location.hash = ""
$scope.state = "Save"
$scope.drawClick();
});
}
$scope.drawClick = function() {
$window.design = jsyaml.load($scope.acedata) || {};
draw($window.design);
$window.document.title = 'drawthe.net: ' + window.design.title.text
}
$scope.gist = function() {
var parts = $scope.gistURL.split('/')
var githubUser = parts[3]
var githubGist = parts[4]
$http.get('//gist.githubusercontent.com/' + githubUser + '/' + githubGist + '/raw')
.then(function(res) {
$scope.acedata = res.data;
$scope.drawClick()
})
$scope.gistURL = ""
$window.location.hash = ""
$scope.state = "Save"
}
$scope.link = function() {
copyToClipboard($location.absUrl())
$scope.linkText = " Copied to clipboard"
$timeout(function () {
$scope.linkText = "Link"
}, 200);
}
$scope.fork = function() {
$scope.state = "Save"
$scope.save()
}
$scope.fullScreen = function () {
var leftSide = angular.element( document.querySelector( '#leftSide' ) );
var rightSide = angular.element( document.querySelector( '#rightSide' ) );
if ($scope.shown) {
$scope.shown = false
$scope.mode = " Show editor"
$animate.setClass(leftSide, 'ng-hide', 'ng-show').then(function() {
$animate.setClass(rightSide, 'col-sm-12', 'col-sm-6').then(function() {
$scope.drawClick();
})
})
} else {
$scope.shown = true
$scope.mode = " Hide editor"
$animate.setClass(leftSide, 'ng-show', 'ng-hide').then(function() {
$animate.setClass(rightSide, 'col-sm-6', 'col-sm-12').then(function() {
$scope.drawClick();
})
})
}
}
$scope.save = function() {
if ($scope.state == "Save") {
$scope.saveIcon = "glyphicon glyphicon-hourglass"
var data = $scope.acedata;
var config = {
headers : {
'Content-Type': 'text/x-yaml'
}
}
$http.post($scope.dbURL, data, config)
.then(
function(response){
$scope.docId = response.data.docId
$window.location.hash=response.data.docId
$scope.saveIcon = "glyphicon glyphicon-ok-circle"
$timeout(function () {
$scope.saveIcon = "glyphicon glyphicon-floppy-disk";
$scope.state = "Update";
}, 200);
},
function(response){
$scope.saveIcon = "glyphicon glyphicon-alert";
console.log(response)
}
);
} else if ($scope.state == "Update") {
$scope.saveIcon = "glyphicon glyphicon-hourglass"
var url = $scope.dbURL + $scope.docId;
var data = $scope.acedata;
var config = {
headers : {
'Content-Type': 'text/x-yaml'
}
}
$http.put(url, data, config)
.then(
function(response){
$window.location.hash=response.data.docId
$scope.saveIcon = "glyphicon glyphicon-ok-circle"
$timeout(function () {
$scope.saveIcon = "glyphicon glyphicon-floppy-disk"
}, 200);
},
function(response){
$scope.saveIcon = "glyphicon glyphicon-alert";
console.log(response)
}
);
}
}
$scope.saveFile = function() {
var data = $scope.acedata,
blob = new Blob([data], { type: 'text/plain' }),
url = $window.URL || $window.webkitURL;
design = jsyaml.load(data) || {};
fileName = `${design.title.text || 'dld4e'}-v${design.title.version || '1.01'}.yaml`
url = url.createObjectURL(blob); //do
var downloadLink = document.createElement("a");
downloadLink.href = url;
downloadLink.download = fileName;
document.body.appendChild(downloadLink);
downloadLink.click();
document.body.removeChild(downloadLink);
}
$scope.saveImage = function() {
saveSvgAsPng(
document.querySelector('svg'),
design.title.text + '.png',
{scale: 4, backgroundColor: 'white'}
);
}
};
</script>
</html>