This repository has been archived by the owner on Nov 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.html
856 lines (799 loc) · 30.9 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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Console</title>
<base href="/"></base>
</head>
<body>
<nav class="navbar navbar-inverse navbar-static-top" role="navigation">
<ul class="nav navbar-nav">
<li><img class="logo" style="margin: 12px"/></li>
<li class="active"><a class="pageLink apiLink">API</a></li>
<li><a class="pageLink scenariosLink">Common scenarios</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><button class="btn btn-default loginButton menuLoginButton" style="margin-top: 12px">Login</button></li>
<li><label class="addressLabel" style="margin-top: 18px">Address</label></li><li><input type="text" style="margin: 10px; margin-right: 30px; width:500px" class="addressInput form-control"/></li>
</ul>
</nav>
<div class="home page">
</div>
<div class="api page">
<div class="container">
<div class="row">
<div class="methodList">
<div class="innerMethodList list-group"></div>
</div>
<div class="mainDiv">
<div class="jumbotron">
<div class="media">
<a class="pull-left" href="#">
<img class="largeLogo"/>
</a>
<div class="media-body">
<h1 class="title">BIMserver API</h1>
<p>
<div class="subtitle">Execute your own calls and get to learn the way of the BIMserver
</div>
<span class="version"></span>
</p>
</div>
</div>
</div>
<div class="method initialhide">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title name"></h3>
</div>
<div class="panel-body">
<div class="alert">
<span class="label label-info">Description</span>
<div class="doc"></div>
<div style="margin-top: 8px">
<span class="label label-default">Returns</span>
<div class="docreturn"></div>
</div>
</div>
<div class="example">
<div class="noparameters initialhide">This call has no parameters</div>
<div class="parameters initialhide">
<form class="parametersForm form-horizontal">
</form>
</div>
<div class="protocolSelector btn-group" data-toggle="buttons">
<label class="btn btn-default active">
<input type="radio" name="options" class="jsonRadio" id="option1" autocomplete="off" checked> JSON
</label>
<label class="btn btn-default">
<input type="radio" name="options" class="soapRadio" id="option2" autocomplete="off"> SOAP
</label>
</div>
<button class="btn btn-primary sendButton">Send</button>
<div class="textareas">
<div class="requestdiv">
Request<br/>
<div>
<pre class="prettyprint"></pre>
</div>
</div>
<div class="responsediv initialhide">
Response<br/>
<div>
<pre class="prettyprint"></pre>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="scenarios page initialhide container-fluid">
<div class="row-fluid">
<div class="alert alert-danger">Scenarios are in development</div>
</div>
<div class="row-fluid">
<div class="span2">
<ul class="nav nav-tabs nav-stacked scenarioNav">
</ul>
</div>
<div class="span10">
<div class="scenarioDetails initialhide">
<h1 class="title"></h1>
<div class="pagination">
<ul>
<li class="disabled backButton"><a>«</a></li>
<li class="disabled forwardButton"><a>»</a></li>
</ul>
</div>
<div class="scenarioDescription well well-sm"></div>
<div class="scenarioMethod">
</div>
</div>
</div>
</div>
</div>
<script>
Global = {};
LazyLoad=function(k){function p(b,a){var g=k.createElement(b),c;for(c in a)a.hasOwnProperty(c)&&g.setAttribute(c,a[c]);return g}function l(b){var a=m[b],c,f;if(a)c=a.callback,f=a.urls,f.shift(),h=0,f.length||(c&&c.call(a.context,a.obj),m[b]=null,n[b].length&&j(b))}function w(){var b=navigator.userAgent;c={async:k.createElement("script").async===!0};(c.webkit=/AppleWebKit\//.test(b))||(c.ie=/MSIE/.test(b))||(c.opera=/Opera/.test(b))||(c.gecko=/Gecko\//.test(b))||(c.unknown=!0)}function j(b,a,g,f,h){var j=
function(){l(b)},o=b==="css",q=[],d,i,e,r;c||w();if(a)if(a=typeof a==="string"?[a]:a.concat(),o||c.async||c.gecko||c.opera)n[b].push({urls:a,callback:g,obj:f,context:h});else{d=0;for(i=a.length;d<i;++d)n[b].push({urls:[a[d]],callback:d===i-1?g:null,obj:f,context:h})}if(!m[b]&&(r=m[b]=n[b].shift())){s||(s=k.head||k.getElementsByTagName("head")[0]);a=r.urls;d=0;for(i=a.length;d<i;++d)g=a[d],o?e=c.gecko?p("style"):p("link",{href:g,rel:"stylesheet"}):(e=p("script",{src:g}),e.async=!1),e.className="lazyload",
e.setAttribute("charset","utf-8"),c.ie&&!o?e.onreadystatechange=function(){if(/loaded|complete/.test(e.readyState))e.onreadystatechange=null,j()}:o&&(c.gecko||c.webkit)?c.webkit?(r.urls[d]=e.href,t()):(e.innerHTML='@import "'+g+'";',u(e)):e.onload=e.onerror=j,q.push(e);d=0;for(i=q.length;d<i;++d)s.appendChild(q[d])}}function u(b){var a;try{a=!!b.sheet.cssRules}catch(c){h+=1;h<200?setTimeout(function(){u(b)},50):a&&l("css");return}l("css")}function t(){var b=m.css,a;if(b){for(a=v.length;--a>=0;)if(v[a].href===
b.urls[0]){l("css");break}h+=1;b&&(h<200?setTimeout(t,50):l("css"))}}var c,s,m={},h=0,n={css:[],js:[]},v=k.styleSheets;return{css:function(b,a,c,f){j("css",b,a,c,f)},js:function(b,a,c,f){j("js",b,a,c,f)}}}(this.document);
Global.baseDir = new String(document.location.protocol + "//" + document.location.host + document.location.pathname);
if (Global.baseDir.substring(Global.baseDir.length - 5) == ".html") {
Global.baseDir = Global.baseDir.substring(0, Global.baseDir.lastIndexOf("/"));
}
if (Global.baseDir.substring(Global.baseDir.length - 1) != "/") {
Global.baseDir = Global.baseDir + "/";
}
Global.baseJsDir = Global.baseDir + "js/";
Global.baseCssDir = Global.baseDir + "css/";
var base = document.getElementsByTagName("base");
base[0].href = Global.baseDir;
var global = (function () {
return this;
}());
// http://stackoverflow.com/questions/3362471/how-can-i-call-a-javascript-constructor-using-call-or-apply
function conthunktor(Constructor) {
var args = Array.prototype.slice.call(arguments, 1);
return function() {
var Temp = function(){}, // temporary constructor
inst, ret; // other vars
// Give the Temp constructor the Constructor's prototype
Temp.prototype = Constructor.prototype;
// Create a new instance
inst = new Temp;
// Call the original Constructor with the temp
// instance as its context (i.e. its 'this' value)
ret = Constructor.apply(inst, args);
// If an object has been returned then return it otherwise
// return the original instance.
// (consistent with behaviour of the new operator)
return Object(ret) === ret ? ret : inst;
}
};
(function() {
var link = document.createElement('link');
link.type = 'image/x-icon';
link.rel = 'shortcut icon';
link.href = Global.baseDir + 'img/logo_small.png';
document.getElementsByTagName('head')[0].appendChild(link);
}());
LazyLoad.css([
Global.baseCssDir + "prettify.css",
Global.baseCssDir + "bootstrap.min.css",
Global.baseCssDir + "console.css",
Global.baseCssDir + "console-extra.css"
], function(){});
LazyLoad.js([
Global.baseJsDir + "vkbeautify.0.99.00.beta.js",
Global.baseJsDir + "prettify.js",
Global.baseJsDir + "consolesettings.js",
Global.baseJsDir + "jquery-2.1.3.min.js",
Global.baseJsDir + "jquery.cookie.js",
Global.baseJsDir + "jquery.enterpress.js",
Global.baseJsDir + "bootstrap.min.js",
Global.baseJsDir + "String.js",
Global.baseJsDir + "utils.js"
], function () {
function Console() {
var othis = this;
othis.currentScenarioContext = null;
if ($.cookie("address" + window.document.location.port) != null) {
$(".addressInput").val($.cookie("address" + window.document.location.port));
}
$(".addressInput").change(function(){
$.cookie("address" + window.document.location.port, $(".addressInput").val(), { expires: 31, path: '/' });
});
$(".logo").attr("src", Global.baseDir + "img/consolelogo.png");
$(".largeLogo").attr("src", Global.baseDir + "img/consolelogolarge.png");
$(".title").html(ConsoleSettings.title);
$(".subtitle").html(ConsoleSettings.subtitle);
$(".version").html("Version: " + ConsoleSettings.getVersion());
var scenarios = [
{
name: "Checkin IFC",
calls: [
{
id: "login",
name: "Login",
description: "First you will have to login, if you are already logged-in, you can skip this step",
interface: "Bimsie1AuthInterface",
method: "login"
},
{
id: "createproject",
name: "Create project",
description: "Create a project, if the call is successful, the Object-ID of the project will be stored for you, so it can be used in the actual checkin call",
interface: "Bimsie1ServiceInterface",
method: "addProject",
post: function(data, context){
context.poid = data.oid;
}
},
{
id: "finddeserializer",
name: "Find deserializer",
description: "To checkin a file, we have to define a deserializer. If you are uploading an IFC file, use \"ifc\" here",
interface: "Bimsie1ServiceInterface",
method: "getSuggestedDeserializerForExtension",
post: function(data, context) {
context.deserializerOid = data.oid;
}
},
{
id: "checkin",
name: "Checkin",
description: "This call will checkin the actual file, poid and deserializerOid should be prefilled if you successfully executed the previous steps",
interface: "Bimsie1ServiceInterface",
method: "checkin",
fieldChange: function(fieldName, data, form){
if (fieldName == "data") {
form.setFieldValue("fileSize", data.size);
form.setFieldValue("fileName", data.name);
}
},
pre: function(context, form){
form.setFieldValue("poid", context.poid);
form.setFieldValue("deserializerOid", context.deserializerOid);
}
}
]
}
];
var token = $.cookie("autologin" + window.document.location.port);
if (token != null) {
$(".loginButton").html("Logout");
}
var protocol = "json";
othis.namespaceMapping = {
"AuthInterface": "org_bimserver_AuthInterface",
"ServiceInterface": "org_bimserver_ServiceInterface",
"AdminInterface": "org_bimserver_AdminInterface",
"MetaInterface": "org_bimserver_MetaInterface",
"PluginInterface": "org_bimserver_PluginInterface",
"SettingsInterface": "org_bimserver_SettingsInterface",
"Bimsie1NotificationRegistryInterface": "org_buildingsmart_bimsie_Bimsie1NotificationRegistryInterface",
"Bimsie1RemoteServiceInterface": "org_buildingsmart_bimsie_Bimsie1RemoteServiceInterface",
"Bimsie1AuthInterface": "org_buildingsmart_bimsie_Bimsie1AuthInterface",
"Bimsie1ServiceInterface": "org_buildingsmart_bimsie_Bimsie1ServiceInterface",
"Bimsie1LowLevelInterface": "org_buildingsmart_bimsie_Bimsie1LowLevelInterface",
"Bimsie1NotificationInterface": "org_buildingsmart_bimsie_Bimsie1NotificationInterface"
};
othis.lastCall = {};
this.call = function(requestObject, callback) {
$.ajax({
url: $(".addressInput").val() + "/json",
data: JSON.stringify(requestObject),
contentType: "application/json",
type: "POST",
dataType: "json",
success: function(data){
if (data.exception == null) {
if (requestObject.request != null && requestObject.request.method == "login") {
token = data.response.result;
$.cookie("autologin" + window.document.location.port, token);
$(".loginButton").html("Logout");
} else if (requestObject.request != null && requestObject.request.method == "logout") {
token = null;
$.cookie("autologin" + window.document.location.port, null);
$(".loginButton").html("Login");
}
callback(data);
} else {
$(".output").removeClass("success").addClass("error");
$(".output").val(JSON.stringify(data, null, ' '));
$(".console").val(data.exception.message);
}
},
error: function(jqXHR, textStatus, errorThrown){
console.log(textStatus);
$(".output").removeClass("success").addClass("error");
$(".output").val(textStatus);
}
});
};
this.makeExampleFromType = function(fieldName, type, genericType, doc, indent) {
if (doc == "") {
doc = null;
}
var example = "";
if (type.simpleName == "String") {
example += "\"" + $(".__field" + fieldName).val() + "\"";
} else if (type.name.contains("Long")) {
example += $(".__field" + fieldName).val();
} else if (type.name.contains("Boolean")) {
example += "\"" + $(".__field" + fieldName).is(":checked") + "\"";
} else if (type.simpleName == "Set"){
example += JSON.stringify($(".__field" + fieldName).val().split(',').map(function(e){ return e.trim(); }).filter(function(e){ return e.length > 0;}));
} else if (type.name.contains("javax.activation.DataHandler")) {
example += "\"" + $(".__field" + fieldName).data("base64") + "\"";
} else if (type.name.contains("org.bimserver")) {
if (type.simpleType == "ENUM") {
example += "\"" + $(".__field" + fieldName).val() + "\"";
} else {
example += "{\n";
type.fields.forEach(function(field, index){
example += othis.indent(indent) + "\"" + field.name + "\": " + othis.makeExampleFromType("", field.type, field.genericType, field.doc, indent + 1);
if (index != type.fields.length - 1) {
example += ",";
}
example += "\n";
});
example += othis.indent(indent - 1) + "}";
}
} else if (type.simpleName == "List") {
example += "[<<" + genericType.simpleName.toLowerCase() + (doc == null ? "" : (", " + doc)) + ">>]";
} else {
example += "\"" + $(".__field" + fieldName).val() + "\"";
}
return example;
};
this.getJsonText = function(indent) {
if (indent == undefined) {
indent = 1;
}
var request = "{\n";
if (token != null) {
request += othis.indent(indent) + "\"token\": \"" + token + "\",\n";
}
request += othis.indent(indent) + "\"request\": {\n";
request += othis.indent(indent + 1) + "\"interface\": \"" + othis.lastCall.serviceInterface.simpleName + "\", \n";
request += othis.indent(indent + 1) + "\"method\": \"" + othis.lastCall.method.name + "\", \n";
request += othis.indent(indent + 1) + "\"parameters\": {\n";
othis.lastCall.method.parameters.forEach(function(parameter, index){
request += othis.indent(indent + 2) + "\"" + parameter.name + "\": ";
request += othis.makeExampleFromType(parameter.name, parameter.type, parameter.genericType, parameter.doc, indent + 3);
if (index != othis.lastCall.method.parameters.length - 1) {
request += ",\n";
} else {
request += "\n";
}
});
request += othis.indent(indent + 1) + "}\n";
request += othis.indent(indent) + "}\n";
request += "}";
return request;
};
this.indent = function(indentation) {
var str = "";
for (var i=0; i<indentation; i++) {
str += " ";
}
return str;
};
this.getSoapArgs = function() {
var params = [];
othis.lastCall.method.parameters.forEach(function(parameter, index){
params.push($(".__field" + parameter.name).val());
});
return params;
};
this.getSoapText = function() {
var params = othis.getSoapArgs();
var global = (function () {
return this;
}());
var interfaceConstructor = global[othis.namespaceMapping[othis.lastCall.serviceInterface.simpleName]];
if (interfaceConstructor == null) {
console.error("No constructor found for", othis.lastCall.serviceInterface.simpleName);
} else {
var interfaceObject = conthunktor(interfaceConstructor)();
var inputSerializer = interfaceObject[othis.lastCall.method.name + "_serializeInput"];
var code = inputSerializer(new CxfApacheOrgUtil(), params);
return vkbeautify.xml(code);
}
};
this.inputChange = function() {
$(".requestdiv pre").removeClass("prettyprinted");
if (protocol == "json") {
$(".requestdiv pre").text(othis.getJsonText());
} else if (protocol == "soap") {
$(".requestdiv pre").text(othis.getSoapText());
}
prettyPrint();
};
this.makeFieldFromType = function(call, fieldName, type, genericType, doc, callback) {
var div = $("<div class=\"form-group\">");
var fullTypeString = type.simpleName;
if (genericType != null) {
fullTypeString += "<" + genericType.simpleName + ">";
}
var label = $("<label><a></a></label>");
label.find("a").text(fieldName + " (" + fullTypeString + ")");
label.find("a").attr("title", doc);
label.find("a").tooltip();
var controls = $("<div class=\"controls\">");
div.append(label);
div.append(controls);
if (type.simpleName == "String") {
var input = $("<input type=\"text\" class=\"form-control\"/>");
input.addClass("__field" + fieldName);
input.keyup(othis.inputChange);
input.enterpress(othis.send);
controls.append(input);
} else if (type.simpleType == "ENUM") {
var select = $("<select class=\"form-control\"></select>");
select.addClass("__field" + fieldName);
select.change(othis.inputChange);
var request = {
request: {
"interface": "MetaInterface",
method: "getEnumLiterals",
parameters: {
enumName: type.name
}
}
};
othis.call(request, function(data){
data.response.result.forEach(function(enumConstant){
var option = $("<option value=\"" + enumConstant + "\">" + enumConstant + "</option>");
select.append(option);
});
controls.append(select);
callback(div);
});
return;
} else if (type.name.contains("org.bimserver")) {
controls.append("Complex objects have not been implemented in console.html");
} else if (type.name.contains("javax.activation.DataHandler")) {
var input = $("<input class=\"form-control\" type=\"file\"/>");
input.addClass("__field" + fieldName);
var reader = new FileReader();
reader.onload = function (event) {
var data = event.target.result;
var encoded = data.substr(data.indexOf(",") + 1);
input.data("base64", encoded);
othis.inputChange();
};
input.change(function(){
var get = input.get(0);
var files = get.files;
if (files != null && files.length == 1) {
var oFile = files[0];
if (call != null) {
if (call.fieldChange != null) {
call.fieldChange(fieldName, oFile, {
setFieldValue: function(fieldName, newValue){
var methodDiv = $(".scenarioMethod");
methodDiv.find(".__field" + fieldName).val(newValue);
}
});
}
}
reader.readAsDataURL(oFile);
}
});
controls.append(input);
} else if (type.simpleName == "Boolean") {
var input = $("<input type=\"checkbox\" value=\"true\"/>");
input.addClass("__field" + fieldName);
input.change(othis.inputChange);
controls.append(input);
var div = $("<div class=\"checkbox\">");
var label = $("<label><a>" + fieldName + "</a></label>");
label.find("a").attr("title", doc);
label.find("a").tooltip();
div.append(label);
label.append(input);
} else if (type.simpleName == "List") {
controls.append("List objects have not been implemented in console.html");
} else {
var input = $("<input type=\"text\" class=\"form-control\"/>");
input.keyup(othis.inputChange);
input.enterpress(othis.send);
input.addClass("__field" + fieldName);
controls.append(input);
}
callback(div);
};
this.loadParameter = function(container, call, index, method, keys, callback){
var parameter = method.parameters[keys[index]];
othis.makeFieldFromType(call, parameter.name, parameter.type, parameter.genericType, parameter.doc, function(div){
container.find(".parametersForm").append(div);
if (index + 1 < keys.length) {
othis.loadParameter(container, call, index + 1, method, keys, callback);
} else {
callback();
}
});
};
this.loadExampleJson = function(call, serviceInterface, method, container) {
if ($(".jumbotron").is(":visible")) {
$(".jumbotron").hide();
}
othis.lastCall.serviceInterface = serviceInterface;
othis.lastCall.method = method;
container.find(".name").html(serviceInterface.simpleName + "." + method.name);
if (method.doc == null || method.doc == "") {
container.find(".doc").html("No documentation for this method yet");
} else {
container.find(".doc").html(method.doc);
}
if (method.returnDoc == null || method.returnDoc == "") {
container.find(".docreturn").parent().hide();
} else {
container.find(".docreturn").html(method.returnDoc).parent().show();
}
container.find(".parametersForm *").remove();
container.find(".noparameters").hide();
container.find(".parameters").show();
var keys = Object.keys(method.parameters);
if (keys.length > 0) {
othis.loadParameter(container, call, 0, method, keys, function(){
container.show();
container.find(".parameters input:first").focus();
container.find(".responsediv").hide();
othis.inputChange();
});
} else {
container.find(".parametersForm").append("<p>This method has no arguments</p>");
}
};
this.loadMethods = function(event) {
if (event != null) {
event.preventDefault();
}
ConsoleSettings.getServiceInterfaces(othis, function(serviceInterfaces){
$(".innerMethodList").empty();
serviceInterfaces.forEach(function(serviceInterface, index){
var headerLi = $("<li class=\"list-group-item header\"><h4>" + serviceInterface.simpleName + "</h4></li>");
$(".innerMethodList").append(headerLi);
serviceInterface.methods.forEach(function(serviceMethod){
var a = $("<a class=\"list-group-item\">" + serviceMethod.name + "</a>");
a.data("method", serviceMethod);
a.data("serviceInterface", serviceInterface);
a.click(function(){
$(this).parent().find(".list-group-item").removeClass("active");
$(this).addClass("active");
othis.loadExampleJson(null, $(this).data("serviceInterface"), $(this).data("method"), $(".method"));
});
$(".innerMethodList").append(a);
});
});
});
};
this.send = function() {
$(".responsediv pre").val("");
if (protocol == "json") {
var input = othis.getJsonText();
try {
input = JSON.parse(input);
othis.call(input, function(data){
$(".responsediv pre").removeClass("error").addClass("success");
$(".responsediv pre").removeClass("prettyprinted");
$(".responsediv pre").text(JSON.stringify(data, null, ' '));
prettyPrint();
$(".responsediv").show();
if (othis.currentScenarioContext != null) {
if (othis.currentScenarioContext.call != null) {
if (othis.currentScenarioContext.call.post != null) {
othis.currentScenarioContext.call.post(data.response.result, othis.currentScenarioContext);
}
}
}
});
} catch (e) {
$(".responsediv pre").removeClass("success").addClass("error");
$(".responsediv pre").html("Invalid json");
$(".responsediv").show();
}
} else if (protocol == "soap") {
var interfaceConstructor = global[othis.namespaceMapping[othis.lastCall.serviceInterface.simpleName]];
var interfaceObject = conthunktor(interfaceConstructor)();
var callMethod = interfaceObject[othis.lastCall.method.name];
var allArguments = [];
allArguments.push(function(response){
if (othis.lastCall.method.name == "login") {
token = response.getReturn();
$.cookie("autologin" + window.document.location.port, token);
$(".loginButton").html("Logout");
} else if (othis.lastCall.method.name == "logout") {
token = null;
$.cookie("autologin" + window.document.location.port, null);
$(".loginButton").html("Login");
}
});
allArguments.push(function(){
console.log(arguments);
});
var otherArgs = othis.getSoapArgs();
otherArgs.forEach(function(arg){
allArguments.push(arg);
});
var existingSuccessMethod = interfaceObject[othis.lastCall.method.name + "_onsuccess"];
var newSuccessMethod = function(client, responseXml){
$(".responsediv pre").removeClass("error").addClass("success");
$(".responsediv pre").removeClass("prettyprinted");
var oSerializer = new XMLSerializer();
$(".responsediv pre").text(vkbeautify.xml(oSerializer.serializeToString(responseXml)));
prettyPrint();
$(".responsediv").show();
existingSuccessMethod.apply(this, arguments);
if (othis.currentScenarioContext != null) {
if (othis.currentScenarioContext.call != null) {
if (othis.currentScenarioContext.call.post != null) {
othis.currentScenarioContext.call.post(responseXml.response.result, othis.currentScenarioContext);
}
}
}
};
interfaceObject[othis.lastCall.method.name + "_onsuccess"] = newSuccessMethod;
var existingErrorMethod = interfaceObject[othis.lastCall.method.name + "_onerror"];
var newErrorMethod = function(client, responseXml){
$(".responsediv pre").addClass("error").removeClass("success");
$(".responsediv pre").removeClass("prettyprinted");
var oSerializer = new XMLSerializer();
$(".responsediv pre").text(vkbeautify.xml(oSerializer.serializeToString(responseXml)));
prettyPrint();
$(".responsediv").show();
existingErrorMethod.apply(this, arguments);
};
interfaceObject[othis.lastCall.method.name + "_onerror"] = newErrorMethod;
callMethod.apply(interfaceObject, allArguments);
}
};
this.loadServiceInterfaceMethod = function(interfaceName, interfaceSimpleName, methodName) {
var request = {
request: {
interface: "org.bimserver.MetaInterface",
method: "getServiceMethod",
parameters: {
serviceInterfaceName: interfaceName,
methodName: methodName
}
}
};
othis.call(request, function(data){
othis.loadExampleJson(null, interfaceName, interfaceSimpleName, data.response.result.name, data.response.result.doc, data.response.result.returnDoc);
});
};
this.loadScenarioCall = function(call){
othis.currentScenarioContext.call = call;
var methodDiv = $(".scenarioMethod");
methodDiv.parent().find(".scenarioDescription").html(call.description);
$(".callLink" + call.id).parent().find("li").removeClass("selected");
$(".callLink" + call.id).addClass("selected");
othis.findServiceInterfaceAndMethod(call.interface, call.method, function(serviceInterface, method){
othis.loadExampleJson(call, serviceInterface, method, methodDiv);
if (call.pre != null) {
call.pre(othis.currentScenarioContext, {
setFieldValue: function(fieldName, newValue){
methodDiv.find(".__field" + fieldName).val(newValue);
}
});
}
});
};
this.loadScenario = function(){
var scenario = $(this).data("scenario");
othis.currentScenarioContext = {
scenario: scenario
};
var clone = $(".method").clone();
$(".scenarioDetails .scenarioMethod").append(clone.show());
$(".scenarioDetails .title").html(scenario.name + " Scenario");
$(".scenarioDetails .sendButton").click(othis.send);
scenario.calls.forEach(function(call, index){
var li = $("<li>");
li.addClass("callLink" + call.id);
var a = $("<a>");
a.data("call", call);
a.click(function(){
var call = $(this).data("call");
othis.loadScenarioCall(call);
});
a.html(call.name);
li.append(a);
$(".scenarioDetails .pagination .forwardButton").before(li);
if (index == 0) {
othis.loadScenarioCall(call);
}
});
$(".scenarioDetails").show();
};
this.findServiceInterface = function(simpleName, callback){
ConsoleSettings.getServiceInterfaces(othis, function(serviceInterfaces){
serviceInterfaces.forEach(function(serviceInterface){
if (serviceInterface.simpleName == simpleName) {
callback(serviceInterface);
}
});
});
};
this.findServiceInterfaceAndMethod = function(simpleName, methodName, callback){
ConsoleSettings.getServiceInterfaces(othis, function(serviceInterfaces){
serviceInterfaces.forEach(function(serviceInterface){
if (serviceInterface.simpleName == simpleName) {
serviceInterface.methods.forEach(function(method){
if (method.name == methodName) {
callback(serviceInterface, method);
}
});
}
});
});
};
$(".loginButton").click(function(){
othis.findServiceInterface("Bimsie1AuthInterface", function(serviceInterface){
serviceInterface.methods.forEach(function(method){
if (token == null && method.name == "login") {
othis.loadExampleJson(null, serviceInterface, method, $(".method"));
} else if (token != null && method.name == "logout") {
othis.loadExampleJson(null, serviceInterface, method, $(".method"));
}
});
});
});
scenarios.forEach(function(scenario){
var a = $("<a>");
var li = $("<li>");
a.append(scenario.name);
a.data("scenario", scenario);
a.click(othis.loadScenario);
li.append(a);
$(".scenarioNav").append(li);
});
$(".soapRadio, .jsonRadio").change(function(){
if ($(this).hasClass("jsonRadio")) {
protocol = "json";
} else if ($(this).hasClass("soapRadio")) {
protocol = "soap";
}
othis.inputChange();
});
$(".sendButton").click(othis.send);
$(".homeLink").click(function(){
$(".page").hide();
$(".pageLink").parent().removeClass("active");
$(".homeLink").parent().addClass("active");
$(".home").show();
});
$(".apiLink").click(function(){
$(".page").hide();
$(".pageLink").parent().removeClass("active");
$(".apiLink").parent().addClass("active");
$(".api").show();
});
$(".scenariosLink").click(function(){
$(".page").hide();
$(".pageLink").parent().removeClass("active");
$(".scenariosLink").parent().addClass("active");
$(".scenarios").show();
});
$(".backButton").click(function(){
var currentIndex = othis.currentScenarioContext.scenario.calls.indexOf(othis.currentScenarioContext.call);
if (currentIndex > 0) {
var call = othis.currentScenarioContext.scenario.calls[currentIndex - 1];
othis.loadScenarioCall(call);
}
});
$(".forwardButton").click(function(){
var currentIndex = othis.currentScenarioContext.scenario.calls.indexOf(othis.currentScenarioContext.call);
if (currentIndex < othis.currentScenarioContext.scenario.calls.length - 1) {
var call = othis.currentScenarioContext.scenario.calls[currentIndex + 1];
othis.loadScenarioCall(call);
}
});
ConsoleSettings.getStaticServerAddress(function(address){
Global.address = address;
$(".addressInput").val(address);
for (var key in othis.namespaceMapping) {
$.ajax({
url: Global.address + "/soap12/" + key + "?js",
dataType: "script",
cache: true,
success: function(){}
});
}
othis.loadMethods();
});
}
new Console();
});
</script>
</body>
</html>