forked from makurideru/infrastructuregraph_visualisator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
2695 lines (2240 loc) · 78.8 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
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Autor Mark Riedel [email protected] -->
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>IT-Infrastructure Visualisator</title>
<!-- Bootstrap Core CSS -->
<link href="lib/css/bootstrap.min.css" rel="stylesheet">
<link href="lib/css/navbar-fixed-side.css" rel="stylesheet" />
<!-- jQuery Version 3.11.1 -->
<script src="lib/js/jquery.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="lib/js/bootstrap.min.js"></script>
<!-- jQuery für das Popupmodal zur Kantenwahl -->
<script src="lib/js/jquery-ui.js"></script>
<link rel="stylesheet" href="lib/css/jquery-ui.css">
<!-- <link rel="stylesheet" href="lib/css/jquery-ui.theme.css"> -->
<!-- <link rel="stylesheet" href="lib/css/jquery-ui.structure.css"> -->
<!-- D3 JS for the force-directed-graph -->
<script type="text/javascript" src="lib/js/d3.v3.min.js"></script>
<!-- slider -->
<link rel="stylesheet" href="lib/css/slider.css">
<script type="text/javascript" src="lib/js/bootstrap_slider_953.js"></script>
<!-- checkboxes -->
<link rel="stylesheet" href="lib/css/custom_checkbox.css">
<!-- Custom CSS -->
<link rel="stylesheet" href="css/index.css">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body onload="fillAnwendungsbox()">
<!-- Navigation -->
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.html">Graph anzeigen</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li>
<a href="add_ci.html">Technologie-Stack hinzufügen</a>
</li>
<li>
<a href="connect_ci.html"><s>CI verknüpfen</s></a>
</li>
<li>
<a href="delete_ci.html"><s>CI löschen</s></a>
</li>
<li>
<a href="edit_ci.html"><s>CI bearbeiten</s></a>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container -->
</nav>
<!-- Page Content -->
<div class="container-fluid">
<div class="col-sm-3 col-lg-2">
<nav class="navbar navbar-default navbar-fixed-side">
<!-- normal collapsible navbar markup -->
<label>Sicht wählen:</label>
<ul class="list-group">
<li class="list-group-item"><a href="index.html"><s>Gesamtansicht</s></a></li>
<li class="list-group-item"><a href="#" onclick="Anwendungssicht()">Anwendungssicht</a></li>
</ul>
<br/>
<div class="form-group">
<label for="sel1">Anwendung wählen:</label>
<select class="form-control" id="sel1" onchange="doFiltering(1)">
</select>
</div>
<ul class="list-group">
<li class="list-group-item"><a href="#" onclick="Artefaktsicht()">Artefaktsicht</a></li>
<li class="list-group-item"><a href="#" onclick="Instanzsicht()">Instanzsicht</a></li>
<li class="list-group-item"><a href="#" onclick="Hardwaresicht()">Hardwaresicht</a></li>
</ul>
<br/>
<label>Zur internen Sicht der Datenbank wechseln:</label>
<ul class="list-group">
<li class="list-group-item"><a href="http://localhost:7474/browser/">Neo4J-Sicht</a></li>
</ul>
</nav>
</div>
<div class="col-sm-9 col-lg-10">
<!-- page content -->
<div class="col-lg-12 text-center">
<table border="0" id="table1">
<tr>
<td><label>CI suchen:</label></td>
<td>
<div id="custom-search-input">
<div class="input-group col-md-12">
<input type="text" class="search-query form-control" placeholder="Search" />
<span class="input-group-btn">
<button class="btn btn-danger" type="button" id="CIsearchBtn" onclick="SearchCI_or_EventChain(this)">
<span class=" glyphicon glyphicon-search"></span>
</button>
</span>
</div>
</div>
</td>
<td> </td>
<td><label>Wirkkette anzeigen:</label></td>
<td>
<div id="custom-search-input">
<div class="input-group col-md-12">
<input type="text" class="search-query form-control" placeholder="Emphasize" />
<span class="input-group-btn">
<button class="btn btn-danger" type="button" id="eventChainBtn" onclick="SearchCI_or_EventChain(this)">
<span class=" glyphicon glyphicon-search"></span>
</button>
</span>
</div>
</div>
</td>
<td>
<span class="form-group" id="wirkkettenconf">
<label class="radiocontainer" title="Anwendung -...> HW">↓
<input type="radio" checked="checked" name="radio" id="Urs_checkbox">
<span class="radiomark"></span>
</label>
<label class="radiocontainer" title="HW -...> Anwendung">↑
<input type="radio" name="radio" id="Aus_checkbox">
<span class="radiomark"></span>
</label>
</span>
</td>
</tr>
</table>
<table class="table-condensed" id="table2">
<tr>
<td><label>Show:</label></td>
<td> </td>
<td> <span class="custom-checkbox"><input type="checkbox" id="Anw_checkbox" onclick="doFiltering();" checked><label for="Anw_checkbox">Anwendungen</label></span></td>
<td><span class="custom-checkbox"><input type="checkbox" id="Art_checkbox" onclick="doFiltering();" ><label for="Art_checkbox">Artefakte</label></span></td>
<td> <span class="custom-checkbox"><input type="checkbox" id="Dep_checkbox" onclick="doFiltering();"><label for="Dep_checkbox">Deployment-Layer</label></span></td>
<td><span class="custom-checkbox"><input type="checkbox" id="Ser_checkbox" onclick="doFiltering();"><label for="Ser_checkbox">Server</label></span></td>
<td><span class="custom-checkbox"><input type="checkbox" id="HW_checkbox" onclick="doFiltering();"><label for="HW_checkbox">Hardware</label></span> </td>
<td><span class="custom-checkbox"><input type="checkbox" id="Special_checkbox" onclick="doFiltering();"><label for="Special_checkbox">Sonder-CIs</label></span> </td>
<td>
<select class="form-control" id="sel_filter" onchange="doFiltering(2)">
</select>
</td>
</tr>
</table>
<table>
<tr>
<td><span class="custom-checkbox"><input type="checkbox" id="Drag_checkbox" onclick="start_stop_drag();" checked><label for="Drag_checkbox">Drag</label></span> </td>
<td> </td>
<td>Charge:<input id="ForceSlider" class="slider" data-slider-id='Force1Slider' type="text" data-slider-min="-900" data-slider-max="0" data-slider-step="10" data-slider-value="-400"/></td>
<td> </td>
<td>Link Dist.:<input id="linkDistanceSlider" class="slider" data-slider-id='Edge1Slider' type="text" data-slider-min="0" data-slider-max="200" data-slider-step="10" data-slider-value="30"/></td>
<!--162.5 default-->
<td> </td>
<td>Size:<input id="sizeSlider" class="slider" data-slider-id='Size1Slider' type="text" data-slider-min="700" data-slider-max="2000" data-slider-step="10" data-slider-value="1250"/></td>
</tr>
</table>
<br/>
<div id='container_for_graph'>
<div id='graph'></div>
<div id='notes'></div>
</div>
</div>
</div>
</div>
<!-- rightclickmenu -->
<menu id="ctxMenu">
<menu title="Anwendung" onclick="AddNode('Anwendung');"></menu>
<menu title="Artefakt" onclick="AddNode('Artefakt');"></menu>
<menu title="Deployment-Layer" onclick="AddNode('DeploymentLayer');"></menu>
<menu title="Server" onclick="AddNode('Server');"></menu>
<menu title="Hardware" onclick="AddNode('Hardware');"></menu>
<menu title="Loadbalancer" onclick="AddNode('Loadbalancer');"></menu>
<menu title="Firewall" onclick="AddNode('Firewall');"></menu>
<menu title="Proxy" onclick="AddNode('Proxy');"></menu>
</menu>
<!-- modal für Kantenbeschriftung -->
<div id="edge_selector" title="Kantenbeschriftung">
<select name="chosen_edge" id="chosen_edge">
<option value="0">Bitte wählen!</option>
<option value="1">has_child</option>
<option value="2">deployed_On</option>
<option value="3">installed_On</option>
<option value="4">instanced_On</option>
<option value="5">requires</option>
<option value="6">uses</option>
<option value="7">communicates_with</option>
</select>
</div>
<!-- /.container -->
<script type="text/javascript">
$( "#edge_selector" ).dialog({ autoOpen: false }); //der Kantenwahldialog wird zu beginn ausgeblendet
//rightclickmenu Eventhandling
var notepad = document.getElementById("container_for_graph");
notepad.addEventListener("contextmenu",function(event){
event.preventDefault();
var ctxMenu = document.getElementById("ctxMenu");
ctxMenu.style.display = "block";
ctxMenu.style.left = (event.pageX - 10)+"px";
ctxMenu.style.top = (event.pageY - 10)+"px";
},false);
notepad.addEventListener("click",function(event){
var ctxMenu = document.getElementById("ctxMenu");
ctxMenu.style.display = "";
ctxMenu.style.left = "";
ctxMenu.style.top = "";
},false);
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function AddNode(ci_typ)
{
var ci_name = prompt("Name des CIs", "unknown CI");
if(ci_name != null)
{
//var add_node_allowd = false;
ci_name = ci_name.trim(); //leerzeichen am Anfang und Ende entfernen
$.ajax({
type: "POST",
url: "check_if_nodename_exists.php",
data: { ci_name: ci_name},
success : function(text)
{
response = text;
}
}).done(function( ) {
if(response == "exists")
{
//alert("Info: Knoten mit diesem Namen existiert bereits - Knoten wird nur zusätzlich angezeigt, wurde aber nicht neu angelegt");
//add_node_allowd = false;
var my_tempParent = $('#container_for_graph');
my_tempParent.append( "<div id='waiting'><b>Info: Knoten mit diesem Namen existiert bereits - Knoten wird nur zusätzlich angezeigt, wurde aber nicht neu angelegt</b></div>" );
$( "#waiting" ).fadeOut(5000, function() { $(this).remove(); });
}
else{
var newNode;
switch(ci_typ){
case "Loadbalancer":
addnewNodeToDB(ci_name, "Special", "Loadbalancer"); //write it to neo4j
break;
case "Firewall":
addnewNodeToDB(ci_name, "Special", "Firewall");
break;
case "Proxy":
addnewNodeToDB(ci_name, "Special", "Proxy");
break;
default:
addnewNodeToDB(ci_name, ci_typ, null);
}
//add_node_allowd = true;
}
});
await sleep(400); //wait till its written
//if(add_node_allowd == true)
//{
$.ajax({ //so you can delete the last node you just created withoud reloadig //thats why sleep and async
type: "POST",
url: "getLastID.php",
data: {},
success : function(text)
{
response = text;
}
}).done(function( ) {
//alert(response);
var id_helper = jQuery.parseJSON(response);
switch(ci_typ) {
case "Hardware":
newNode = {id:id_helper,label:"Hardware",title:ci_name}; //id, Label=type (Hardware), name (X86 Strang xy)
break;
case "Server":
newNode = {id:id_helper,label:"Server",title:ci_name, os:"unnamed OS", zone:"unnamed Zone"}; //id, Label (Server), name (upxy), OS, Zone
break;
case "DeploymentLayer":
newNode = {id:id_helper,label:"DeploymentLayer", title:ci_name, rte:"unnamed RTE", port:"unnamed Port"}; //id, Label (DeploymentLayer), title (Wildfly8), rte, port
break;
case "Artefakt":
newNode = {id:id_helper,label:"Artefakt",title:ci_name, lizenz:"unnamed", sonstiges:"unnamed"};
break;
case "Anwendung":
newNode = {id:id_helper,label:"Anwendung",title:ci_name}; //id, Label (Anwendung), name (Graylog)
fillAnwendungsbox();
break;
case "Loadbalancer":
newNode = {id:id_helper,label:"Special",title:ci_name, kategorie:"Loadbalancer"}; //id, Label (Special), name (LB1)
break;
case "Firewall":
newNode = {id:id_helper,label:"Special",title:ci_name, kategorie:"Firewall"};
break;
case "Proxy":
newNode = {id:id_helper,label:"Special",title:ci_name, kategorie:"Proxy"};
break;
default:
//can't happen
alert("error in DB-model");
}
graph[ graph.nodes.length ] = newNode; //write it to the graph, so we dont need reload the whole page jsut the svg
force.nodes().push(newNode);
svg.selectAll(".node")
.data(force.nodes(), function(datum, index) { return index })
.enter()
.insert("g", "#graph");
labels.push({node: newNode});
labels.push({node: newNode});
/*
var labelSelection = svg.selectAll('g.labelNode')
.data(labels)
.enter()
.append('g')
.classed('labelNode',true);
labelSelection.append('text')
.text(ci_name)
.attr('x', mouseposX -30)
.attr('y',mouseposY - 30);
*/
/*
edges.push({
source: graph.nodes[1],
target: graph.nodes[1],
links: ["has_Child"]
});
*/
/*
links.push({
source: 2,
target: 12,
link: "has_child"
});
*/
force.stop();
labelForce.stop();
svg.selectAll("*").remove();
d3.select("#graph").remove();
d3.select("#notes").remove();
var my_tempParent = $('#container_for_graph');
my_tempParent.append( "<div id='graph'></div>" );
my_tempParent.append( "<div id='notes'></div>" );
visualize(true); //params: clear_labels = true
});
//}
}
}
//fill Anwendungen
function fillAnwendungsbox()
{
$.ajax({
type: "POST",
url: "get_allApplications.php",
success : function(text)
{
response = text;
}
}).done(function( ) {
var selectBox = document.getElementById('sel_filter');
var selectBox2 = document.getElementById('sel1');
$('#sel_filter').find('option').remove().end();
$('#sel1').find('option').remove().end();
var optdefault = document.createElement('option');
optdefault.value = "alle Anwendungen";
optdefault.innerHTML = "alle Anwendungen";
selectBox.appendChild(optdefault);
var optdefault2 = document.createElement('option');
optdefault2.value = "--";
optdefault2.innerHTML = "--";
selectBox2.appendChild(optdefault2);
var erg = jQuery.parseJSON(response);
for (var i = 0; i<erg.length; i++){
var opt = document.createElement('option');
opt.value = erg[i];
opt.innerHTML = erg[i];
selectBox.appendChild(opt);
var opt2 = document.createElement('option');
opt2.value = erg[i];
opt2.innerHTML = erg[i];
selectBox2.appendChild(opt2);
}
});
}
//filtering anwendungen, artefakte, .... (aufegrufen via checkbox onclick)
function doFiltering(checkboxnr){
if(checkboxnr == 1)
document.getElementById('sel_filter').selectedIndex = document.getElementById('sel1').selectedIndex; //synchronize the selectionmenus
else if(checkboxnr == 2)
document.getElementById('sel1').selectedIndex = document.getElementById('sel_filter').selectedIndex; //synchronize the selectionmenus
force.stop();
svg.selectAll("*").remove();
d3.select("#graph").remove();
d3.select("#notes").remove();
var my_tempParent = $('#container_for_graph');
my_tempParent.append( "<div id='waiting'>getting Data from the database...</div>" );//TODO: see if other request also take long
my_tempParent.append( "<div id='graph'></div>" );
my_tempParent.append( "<div id='notes'></div>" );
var AnwBool;
var ArtBool;
var DepBool;
var SerBool;
var HWBool;
var SpecBool;
var Anw_checkbox = document.getElementById("Anw_checkbox");
var Art_checkbox = document.getElementById('Art_checkbox');
var Dep_checkbox = document.getElementById('Dep_checkbox');
var Ser_checkbox = document.getElementById('Ser_checkbox');
var HW_checkbox = document.getElementById('HW_checkbox');
var Special_checkbox = document.getElementById('Special_checkbox');
if(!Anw_checkbox.checked){
AnwBool = false;
}else{
AnwBool = "n.type='Anwendung'";
}
if(!Art_checkbox.checked){
ArtBool = false;
}else{
ArtBool = "n.type='Artefakt'" ;
}
if(!Dep_checkbox.checked){
DepBool = false;
}else{
DepBool = "n.type='DeploymentLayer'";
}
if(!Ser_checkbox.checked){
SerBool = false;
}else{
SerBool = "n.type='Server'";
}
if(!HW_checkbox.checked){
HWBool = false;
}else{
HWBool = "n.type='Hardware'";
}
if(!Special_checkbox.checked){
SpecBool = false;
}else{
SpecBool = "n.type='Special'";
}
var Anwendungsfilter = document.getElementById('sel_filter').value;
labels = []; //has to be cleared after each request cause its global now
getDataFromNeo4J(AnwBool, ArtBool, DepBool, SerBool, HWBool, SpecBool, Anwendungsfilter, null, null); //anwe, art, dep, ser, hw, spec, ValueOfSelectbox, Wirkkette
}
function Anwendungssicht(){
force.stop();
svg.selectAll("*").remove();
d3.select("#graph").remove();
d3.select("#notes").remove();
var my_tempParent = $('#container_for_graph');
my_tempParent.append( "<div id='waiting'>getting Data from the database...</div>" );//TODO: see if other request also take long
my_tempParent.append( "<div id='graph'></div>" );
my_tempParent.append( "<div id='notes'></div>" );
//setzt Checkboxen und Selectbox auf Default
document.getElementById("Anw_checkbox").checked = true;
document.getElementById('Art_checkbox').checked = false;
document.getElementById('Dep_checkbox').checked = false;
document.getElementById('Ser_checkbox').checked = false;
document.getElementById('HW_checkbox').checked = false;
document.getElementById('Special_checkbox').checked = false;
document.getElementById('sel_filter').selectedIndex = 0;
document.getElementById('sel1').selectedIndex = 0;
labels = [];
getDataFromNeo4J("n.type='Anwendung'", false, false, false, false, false, null, null, null); //anwe, art, dep, ser, hw, spec, ValueOfSelectbox, CI-Search, Wirkkette
}
function Artefaktsicht(){
var anw_sel1_val = document.getElementById('sel1').value;
var anw_sel1_idx = document.getElementById('sel1').selectedIndex;
if(anw_sel1_val == "--")
{
alert("Bitte Anwendung wählen!");
}
else{
force.stop();
svg.selectAll("*").remove();
d3.select("#graph").remove();
d3.select("#notes").remove();
var my_tempParent = $('#container_for_graph');
my_tempParent.append( "<div id='waiting'>getting Data from the database...</div>" );//TODO: see if other request also take long
my_tempParent.append( "<div id='graph'></div>" );
my_tempParent.append( "<div id='notes'></div>" );
//setzt Checkboxen und Selectbox auf Default
document.getElementById("Anw_checkbox").checked = true;
document.getElementById('Art_checkbox').checked = true;
document.getElementById('Dep_checkbox').checked = false;
document.getElementById('Ser_checkbox').checked = false;
document.getElementById('HW_checkbox').checked = false;
document.getElementById('Special_checkbox').checked = true;
document.getElementById('sel_filter').selectedIndex = anw_sel1_idx;
document.getElementById('sel1').selectedIndex = anw_sel1_idx;
labels = [];
getDataFromNeo4J("n.type='Anwendung'", "n.type='Artefakt'", false, false, false, "n.type='Special'", anw_sel1_val, null, null); //anwe, art, dep, ser, hw, spec, ValueOfSelectbox, CI-Search, Wirkkette
}
}
function Instanzsicht(){
var anw_sel1_val = document.getElementById('sel1').value;
var anw_sel1_idx = document.getElementById('sel1').selectedIndex;
if(anw_sel1_val == "--")
{
alert("Bitte Anwendung wählen!");
}
else{
force.stop();
svg.selectAll("*").remove();
d3.select("#graph").remove();
d3.select("#notes").remove();
var my_tempParent = $('#container_for_graph');
my_tempParent.append( "<div id='waiting'>getting Data from the database...</div>" );//TODO: see if other request also take long
my_tempParent.append( "<div id='graph'></div>" );
my_tempParent.append( "<div id='notes'></div>" );
//setzt Checkboxen und Selectbox auf Default
document.getElementById("Anw_checkbox").checked = false;
document.getElementById('Art_checkbox').checked = false;
document.getElementById('Dep_checkbox').checked = false;
document.getElementById('Ser_checkbox').checked = true;
document.getElementById('HW_checkbox').checked = false;
document.getElementById('Special_checkbox').checked = false;
document.getElementById('sel_filter').selectedIndex = anw_sel1_idx;
document.getElementById('sel1').selectedIndex = anw_sel1_idx;
labels = [];
getDataFromNeo4J(false, false, false, "n.type='Server'", false, false, anw_sel1_val, null, null); //anwe, art, dep, ser, hw, spec, ValueOfSelectbox, CI-Search, Wirkkette
}
}
function Hardwaresicht(){
var anw_sel1_val = document.getElementById('sel1').value;
var anw_sel1_idx = document.getElementById('sel1').selectedIndex;
if(anw_sel1_val == "--")
{
alert("Bitte Anwendung wählen!");
}
else{
force.stop();
svg.selectAll("*").remove();
d3.select("#graph").remove();
d3.select("#notes").remove();
var my_tempParent = $('#container_for_graph');
my_tempParent.append( "<div id='waiting'>getting Data from the database...</div>" );//TODO: see if other request also take long
my_tempParent.append( "<div id='graph'></div>" );
my_tempParent.append( "<div id='notes'></div>" );
//setzt Checkboxen und Selectbox auf Default
document.getElementById("Anw_checkbox").checked = false;
document.getElementById('Art_checkbox').checked = false;
document.getElementById('Dep_checkbox').checked = false;
document.getElementById('Ser_checkbox').checked = true;
document.getElementById('HW_checkbox').checked = true;
document.getElementById('Special_checkbox').checked = false;
document.getElementById('sel_filter').selectedIndex = anw_sel1_idx;
document.getElementById('sel1').selectedIndex = anw_sel1_idx;
labels = [];
getDataFromNeo4J(false, false, false, "n.type='Server'", "n.type='Hardware'", false, anw_sel1_val, null, null); //anwe, art, dep, ser, hw, spec, ValueOfSelectbox, CI-Search, Wirkkette
}
}
//für search-for CIs box und Wirkketten-finden Box
function SearchCI_or_EventChain(elem)
{
var current_input = $(elem ).parent().prev().val();
if(current_input == "")
{
alert("Bitte Wert eingeben!")
}
else{
force.stop();
svg.selectAll("*").remove();
d3.select("#graph").remove();
d3.select("#notes").remove();
var my_tempParent = $('#container_for_graph');
my_tempParent.append( "<div id='waiting'>getting Data from the database...</div>" );//TODO: see if other request also take long
my_tempParent.append( "<div id='graph'></div>" );
my_tempParent.append( "<div id='notes'></div>" );
//setzt Checkboxen und Selectbox auf Default
document.getElementById("Anw_checkbox").checked = false;
document.getElementById('Art_checkbox').checked = false;
document.getElementById('Dep_checkbox').checked = false;
document.getElementById('Ser_checkbox').checked = false;
document.getElementById('HW_checkbox').checked = false;
document.getElementById('Special_checkbox').checked = false;
document.getElementById('sel_filter').selectedIndex = 0;
document.getElementById('sel1').selectedIndex = 0;
labels = [];
if(elem.id == "CIsearchBtn") //ci
getDataFromNeo4J(false, false, false, false, false, false, null, current_input, null); //anwe, art, dep, ser, hw, spec, ValueOfSelectbo, CI-Search, Wirkkette
else //event-chain
getDataFromNeo4J(false, false, false, false, false, false, null, null, current_input); //anwe, art, dep, ser, hw, spec, ValueOfSelectbo, CI-Search, wirkkettte
}
}
//START of all the actual basic visualisation begins here
//http://stackoverflow.com/questions/29440613/return-the-graph-structure-of-a-neo4j-cypher-query-using-jquery
var nodes = new Array();
var links = new Array();
var graph; //global variable that holds the current graph
var svg; //has to be global for filtering
var force = d3.layout.force(); //has to be global for the chargeslider
var labels = [];
//var mouseposX, mouseposY; //Helper to get mouseposition for adding nodes
var labelForce = d3.layout.force();
//var svg_edges = []; //global cause passing objects to function bug (node clicked -> delete)
//var selected_svg_edge = []; //global cause passing objects to function bug (edge clicked -> delete)
//handling the slider charge
var slider = $('#ForceSlider').bootstrapSlider({
formatter: function(value) {
force = force.charge(value)
force.start()
window.setTimeout(function() {
force = force.charge(value)
force.start()
},3000);
return 'Current value: ' + value;
}
});
//handling the slider linkdistance
var slider2 = $('#linkDistanceSlider').bootstrapSlider({
formatter: function(value) {
force = force.linkDistance(value)
force.start()
window.setTimeout(function() {
force = force.linkDistance(value)
force.start()
},3000);
return 'Current value: ' + value;
}
});
//handling the slider width
var slider3 = $('#sizeSlider').bootstrapSlider({
formatter: function(value) {
$('#graph').css("width", value);
//$('#graph').css("margin-left", -50);
//$('#graph').css("margin-top", -50);
return 'Current value: ' + value;
}
});
//Handling the DRAG; stolen from http://stackoverflow.com/questions/34970477/disable-force-in-forcelayout-algorithm-in-d3
function start_stop_drag()
{
function dragstart(d, i) {
force.stop() // stops the force auto positioning before you start dragging
}
function dragmove(d, i) {
d.fixed = true;
d.px += d3.event.dx;
d.py += d3.event.dy;
d.x += d3.event.dx;
d.y += d3.event.dy;
force.resume()
}
function dragend(d, i) {
// of course set the node to fixed so the force doesn't include the node in its auto positioning stuff
force.resume();
}
if(document.getElementById('Drag_checkbox').checked == true) //start drag
{
var node_drag = d3.behavior.drag()
.on("dragstart", dragstart)
.on("drag", dragmove)
.on("dragend", dragend);
svg.selectAll(".node").call(node_drag);
}
else //reset drag
{
//reset all fixed node
svg.selectAll(".node")[0].forEach(function(d){
d3.select(d).data()[0].fixed = false;
});
//remove drag listener
svg.selectAll(".node").on('mousedown.drag', null);
force.resume();
//nodeSelection.call(force.drag); //TODO
}
}
//get the Data and start everything
//aus Performancegründen beim Start nur Anw. und Artefakte
getDataFromNeo4J("n.type='Anwendung'", false, false, false, false, false, null, null, null); //Anwendungssicht per Default
function getDataFromNeo4J(AnwBool, ArtBool, DepBool, SerBool, HWBool, SpecBool, Anwendungsfilter, CIsearch, Wirkkette){
//reset arrays for further filtering
nodes = [];
links = [];
graph = {};
var query;
if(CIsearch == null && Wirkkette == null)//Suchbox der CI bzw. wirkkette geht vor
{
//START get relevant Edges For Filtering
var edgeAAr = false;
var edgeArD = false;
var edgeDS = false;
var edgeSH = false;
var edgeReq = false;
var edgeUses = false;
var edgeComm_with = false;
var singleAnw = ""; //so i can also get the nodes that have no edges
var singleAnw2 = "";
var singleArt = "";
var singleArt2 = "";
var singleDepl = "";
var singleDepl2 = "";
var singleSer = "";
var singleSer2 = "";
var singleHW = "";
var singleHW2 = "";
var singleSpec = "";
var singleSpec2 = "";
if(AnwBool != false) //Anwendungssicht (nur Anwendungen)
{
singleAnw = "(v:Anwendung)";
singleAnw2 = "v,";
}
if(ArtBool != false) //nur Artefakte
{
singleArt = ", (w:Artefakt)";
singleArt2 = "w,";
}
if(DepBool != false) //nur Depl
{
singleDepl = ", (x:DeploymentLayer)";
singleDepl2 = "x,";
}
if(SerBool != false) //nur Server
{
singleSer = ", (y:Server)";
singleSer2 = "y,";
}
if(HWBool != false) //nur HW
{
singleHW = ", (z:Hardware)";
singleHW2 = "z,";
}
if(SpecBool != false) //nur Spec
{
singleSpec = ", (s:Special)";
singleSpec2 = "s,";
}
//Kanten die gefiltert werden sollen festlegen
if(AnwBool != false && ArtBool != false && SpecBool == false) //anw-> Artefakt
{
edgeAAr = "type(r)='has_child' AND m.type='Artefakt'";
}else{
edgeAAr = false;
}
if(ArtBool != false && DepBool != false) //Art -> Depl
{
edgeArD = "type(r)='deployed_On'";
}else{
edgeArD = false;
}
if(DepBool != false && SerBool != false) //Depl -> Server
{
edgeDS = "type(r)='installed_On'";
}else{
edgeDS = false;
}
if(SerBool != false && HWBool != false) //Server -> HW
{
edgeSH = "type(r)='instanced_On'";
}else{
edgeSH = false;
}
if(AnwBool != false && SpecBool != false && ArtBool == false) //anw-> Special
{
edgeAAr = "type(r)='has_child' AND m.type='Special'";
}
if(AnwBool != false && SpecBool != false && ArtBool != false) //beides Anw -> Special und Artefakt
{
edgeAAr = "type(r)='has_child'";
}
//hat sich als sinnvoll ergeben immer alle beziehungen anzuzeigen
//Artefaktebez.
if((ArtBool != false || SpecBool != false) ) //&& !(Anwendungsfilter == null || Anwendungsfilter == "alle Anwendungen")
{
edgeReq = "type(r)='requires'";
edgeUses = "type(r)='uses'";
}else{
edgeReq = false;
edgeUses = false;
}
//Serverbez.
if(SerBool != false ) //&&!(Anwendungsfilter == null || Anwendungsfilter == "alle Anwendungen")
{
edgeComm_with = "type(r)='communicates_with'";
}else{
edgeComm_with = false;
}
//ENDE
if(Anwendungsfilter == null || Anwendungsfilter == "alle Anwendungen")
{
//alle Anw.
query = {"statements":[{"statement":"MATCH path=(n)-[r*]-(m) RETURN COLLECT([ filter(n in nodes(path) WHERE "+
"("+AnwBool+" OR "+ArtBool+" OR "+DepBool+" OR "+SerBool+" OR "+HWBool+")), "+
"filter(r in relationships(path) WHERE "+edgeAAr+" OR "+edgeArD+" OR "+edgeDS+" OR "+edgeSH+" OR "+edgeReq+" OR "+edgeUses+" OR "+edgeComm_with+") ]) AS data" +
" UNION MATCH "+singleAnw+" "+singleArt+" "+singleDepl+" "+singleSer+" "+singleHW+" "+singleSpec+" RETURN COLLECT ([ "+singleAnw2+" "+singleArt2+" "+singleDepl2+" "+singleSer2+" "+singleHW2+" "+singleSpec2+" false]) as data",
"resultDataContents":["graph","row"]}]};
}
else{ //nur eine best. Anwendung (oder spezielle Sicht einer Anwendung gewählt); hier werde keine einzelnen Knoten angezeigt
// The query [r*1..4] (maximale entfernung von 4 von der Anw.) makes the query slow -> if-else only for performance
query= {"statements":[{"statement":"MATCH path=(n)-[r*]-(m) WHERE n.name='"+Anwendungsfilter+"' RETURN COLLECT([ filter(n in nodes(path) WHERE "+
"("+AnwBool+" OR "+ArtBool+" OR "+DepBool+" OR "+SerBool+" OR "+HWBool+")), "+
"filter(r in relationships(path) WHERE "+edgeAAr+" OR "+edgeArD+" OR "+edgeDS+" OR "+edgeSH+" OR "+edgeReq+" OR "+edgeUses+" OR "+edgeComm_with+") ]) AS data" +
" UNION MATCH (v:Anwendung) WHERE v.name='"+Anwendungsfilter+"' RETURN COLLECT(v) as data",
"resultDataContents":["graph","row"]}]};
}
}
else if(Wirkkette != null){//Suchbox der Wirkkette geht vor
//get Wirkkette
//exakte Schreibweise beachten
if(document.getElementById("Urs_checkbox").checked == true){
//Ursachenwirkkette
query= {"statements":[{"statement":"MATCH p=allShortestPaths( (a {name:'"+Wirkkette+"'})-[*]->(b) ) RETURN p;",
"resultDataContents":["graph","row"]}]};
}else{
//Auswirkungswirkkette
query= {"statements":[{"statement":"match p=(v)-[r*]->(w) WHERE w.name='"+Wirkkette+"' RETURN p",
"resultDataContents":["graph","row"]}]};
}
}
else{
//get CI
//(?i) --> case-insesitiv
query= {"statements":[{"statement":"MATCH (a) WHERE a.name =~ '.*(?i)"+CIsearch+".*' OR a.Lizenz=~ '.*(?i)"+CIsearch+".*' OR a.Sonstiges=~ '.*(?i)"+CIsearch+".*' OR a.DeploymentLayer=~ '.*(?i)"+CIsearch+".*'"+
" OR a.RTE=~ '.*(?i)"+CIsearch+".*' OR a.Port=~ '.*(?i)"+CIsearch+".*' OR a.Zone=~ '.*(?i)"+CIsearch+".*' OR a.OS=~ '.*(?i)"+CIsearch+".*' RETURN a",
"resultDataContents":["graph","row"]}]};
}
//the helper function provided by neo4j documents
function idIndex(a,id) {
for (var i=0;i<a.length;i++) {
if (a[i].id == id) return i;}
return null;
}
// jQuery ajax call
var request = $.ajax({
type: "POST",
url: "/api/db/data/transaction/commit",
accepts: "application/json" ,
dataType: "json",
headers: {
"Authorization": "Basic " + btoa("neo4j" + ":" + "test"), //without this u get a prompt asking for pw
"Accept" : "application/json"
},
contentType:"application/json",
data: JSON.stringify(query),
//now pass a callback to success to do something with the data
success: function (data) {
// parsing the output of neo4j rest api
data.results[0].data.forEach(function (row) {
row.graph.nodes.forEach(function (n) {
if (idIndex(nodes,n.id) == null){
switch(n.labels[0]) {
case "Hardware":
nodes.push({id:n.id,label:n.labels[0],title:n.properties.name}); //id, Label=type (Hardware), name (X86 Strang xy)
break;
case "Server":
nodes.push({id:n.id,label:n.labels[0],title:n.properties.name, os:n.properties.OS, zone:n.properties.Zone}); //id, Label (Server), name (upxy), OS, Zone
break;
case "DeploymentLayer":
nodes.push({id:n.id,label:n.labels[0], title:n.properties.DeploymentLayer, rte:n.properties.RTE, port:n.properties.Port}); //id, Label (DeploymentLayer), title (Wildfly8), rte, port
break;
case "Artefakt":
nodes.push({id:n.id,label:n.labels[0],title:n.properties.name, lizenz:n.properties.Lizenz, sonstiges:n.properties.Sonstiges}); //id, Label (Art.), name (MongoDB), Liz., Son.
break;