-
Notifications
You must be signed in to change notification settings - Fork 87
/
query.html
93 lines (87 loc) · 3.1 KB
/
query.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
<div class="query">
<div class="noEngines well ih">
No query engines have been installed (for this account)
</div>
<div class="engines">
<form class="form-inline">
<label>Query engine <select class="form-control queryEngineSelect"></select></label>
<div class="btn-group">
<a class="btn btn-default dropdown-toggle" data-toggle="dropdown" href="#"> Load example <span class="caret"></span>
</a>
<ul class="dropdown-menu examplesDropdown">
</ul>
</div>
</form>
<textarea id="editor" rows="16" class="queryText form-control" style="width: 100%"></textarea>
<button class="btn queryButton pull-right btn-primary">Query</button>
</div>
</div>
<script>
function Query(containerDiv, main, poid, roid) {
var othis = this;
this.loadEngines = function(){
Global.bimServerApi.call("PluginInterface", "getDefaultQueryEngine", {}, function(defaultQueryEngine){
Global.bimServerApi.call("PluginInterface", "getAllQueryEngines", {onlyEnabled: true}, function(data){
if (data.length == 0) {
containerDiv.find(".noEngines").show();
containerDiv.find(".engines").hide();
} else {
containerDiv.find(".queryEngineSelect option").remove();
data.forEach(function(queryEngine){
var option = $("<option value=\"" + queryEngine.oid + "\">" + queryEngine.name + "</option>");
if (defaultQueryEngine != null && queryEngine.oid == defaultQueryEngine.oid) {
option.attr("selected", "selected");
}
containerDiv.find(".queryEngineSelect").append(option);
});
othis.queryEngineChange();
}
});
});
};
this.exampleClick = function(){
var qeid = containerDiv.find(".queryEngineSelect option:selected").val();
Global.bimServerApi.call("ServiceInterface", "getQueryEngineExample", {qeid: qeid, key: $(this).html()}, function(data){
containerDiv.find(".queryText").val(data);
});
};
this.loadExampleKeys = function(qeid){
Global.bimServerApi.call("ServiceInterface", "getQueryEngineExampleKeys", {qeid: qeid}, function(data){
containerDiv.find(".examplesDropdown li").remove();
data.forEach(function(key){
var li = $("<li></li>");
var a = $("<a>" + key + "</a>");
a.click(othis.exampleClick);
li.append(a);
containerDiv.find(".examplesDropdown").append(li);
});
});
};
this.queryEngineChange = function(){
var selected = $(".query .queryEngineSelect").find(":selected").val();
if (selected != null) {
othis.loadExampleKeys(selected);
}
};
this.queryButtonClick = function(){
var div = $("<div class=\"modal fade\">");
$(document.body).append(div);
var qeid = containerDiv.find(".queryEngineSelect option:selected").val();
var query = containerDiv.find(".queryText").val();
var params = {
downloadType: "downloadQuery",
allowCheckouts: false,
poid: poid,
roid: roid,
qeid: qeid,
code: query
};
div.load(Global.baseDir + "download.html", function(){
new Download($(this), params);
}).modal({keyboard:true});
};
othis.loadEngines();
containerDiv.find(".queryEngineSelect").change(othis.queryEngineChange);
containerDiv.find(".queryButton").click(othis.queryButtonClick);
}
</script>