-
Notifications
You must be signed in to change notification settings - Fork 87
/
addnewservice2.html
264 lines (249 loc) · 8.71 KB
/
addnewservice2.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
<div class="addnewservice2">
<table class="table serviceDetails">
<tbody></tbody>
</table>
<div class="panel panel-default">
<div class="panel-heading">Inputs</div>
<div class="panel-body">
<div class="alert alert-info">
You have to select one type of input. For this input type, you have to select which serializer to use. Usually there will only be one input type.
</div>
<table class="table inputsTable">
<thead>
<tr>
<th></th>
<th>Format</th>
<th>Serializer</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">Outputs</div>
<div class="panel-body">
<div class="alert alert-info">
You have to select one type of output as well.
</div>
<table class="table outputsTable">
<thead>
<tr>
<th></th>
<th>Format</th>
<th>Action</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
</div>
<div class="panel panel-default ih checkinDiv">
<div class="panel-heading">Checkin new revision</div>
<div class="panel-body">
<form>
<div class="form-group">
<label>Project</label>
<select class="form-control projectSelect"></select>
</div>
</form>
</div>
</div>
<div class="button-bar-bottom">
<button class="btn btn-primary pull-right btnNext">Next</button>
</div>
</div>
<script>
function AddNewService2(cd, project, projectPage, serviceDescriptor) {
var o = this;
o.project = project;
cd.find("table.serviceDetails tbody").append("<tr><td>Provider</td><td>" + serviceDescriptor.provider + "</td></tr>");
cd.find("table.serviceDetails tbody").append("<tr><td>Name</td><td>" + serviceDescriptor.name + "</td></tr>");
cd.find("table.serviceDetails tbody").append("<tr><td>Description</td><td>" + serviceDescriptor.description + "</td></tr>");
o.selectInput = function(){
o.updateButton();
};
o.selectOutput = function(){
var output = cd.find(".outputsTable input:checked").parents("tr").attr("output");
var action = cd.find(".outputsTable input:checked").parents("tr").find("select").val();
if (action == "NEW_REVISION") {
var canBeCheckedIn = output == "IFC_STEP_2X3TC1" || output == "IFC_STEP_4" || output == "IFC_XML_2X3TC1" || output == "IFC_XML_4" || output == "IFC_JSON_2X3TC1" || output == "IFC_JSON_4";
cd.find(".checkinDiv").toggle(canBeCheckedIn);
if (canBeCheckedIn) {
o.loadProjects(cd.find(".projectSelect"));
}
}
o.updateButton();
};
o.canProceed = function(){
if (cd.find(".inputsTable input[checked='checked']").length > 0) {
var serializerId = cd.find(".inputsTable input[checked='checked']").parents("tr").find("select").val();
if (serializerId != null) {
if (cd.find(".outputsTable input[checked='checked']").length > 0) {
var action = cd.find(".outputsTable input[checked='checked']").parents("tr").find("select").val();
console.log(action);
if (action == "NEW_REVISION") {
var output = cd.find(".outputsTable input:checked").parents("tr").attr("output");
var canBeCheckedIn = output == "IFC_STEP_2X3TC1" || output == "IFC_STEP_4" || output == "IFC_XML_2X3TC1" || output == "IFC_XML_4" || output == "IFC_JSON_2X3TC1" || output == "IFC_JSON_4";
if (canBeCheckedIn) {
return cd.find(".projectSelect").val() != "[SELECT_A_PROJECT]";
} else {
return true;
}
} else {
if (action != null) {
return true;
}
}
}
}
}
return false;
};
this.loadProjects = function(targetElement) {
Global.bimServerApi.call("ServiceInterface", "getAllWritableProjects", {onlyTopLevel: false, onlyActive: true}, function(data){
targetElement.empty();
targetElement.append("<option value=\"[SELECT_A_PROJECT]\" selected=\"selected\">[Select a project]</option>");
data.forEach(function(project){
var option = $("<option value=\"" + project.oid + "\">" + project.name + "</option>");
if (project.oid == o.project.oid) {
option.attr("selected", "selected");
}
targetElement.append(option);
});
o.updateButton();
});
};
o.updateButton = function(){
if (o.canProceed()) {
cd.find(".btnNext").removeAttr("disabled");
} else {
cd.find(".btnNext").attr("disabled", "disabled");
}
};
var availableLocalOutputs = {};
Global.bimServerApi.call("NewServicesInterface", "listAvailableOutputFormats", {poid: project.oid}, function(outputFormats){
outputFormats.forEach(function(mapping){
var map = availableLocalOutputs[mapping.format];
if (map == null) {
map = [];
availableLocalOutputs[mapping.format] = map;
}
map.push(mapping);
});
serviceDescriptor.inputs.forEach(function(input, index){
var tr = $("<tr>");
tr.attr("input", input);
var td = $("<td>");
var radio = $("<input type=\"radio\">");
radio.attr("id", "input" + index);
radio.attr("name", "inputformat");
td.append(radio);
tr.append(td);
tr.append("<td><label for=\"input" + index + "\">" + input + "</label></td>");
var mappings = availableLocalOutputs[input.toUpperCase()];
var td = $("<td>");
tr.append(td);
if (mappings != null) {
var select = $("<select class=\"form-control\">");
mappings.forEach(function(mapping){
mapping.serializers.forEach(function(serializer){
var option = $("<option>" + serializer.name + "</option>");
option.attr("value", serializer.oid);
select.append(option);
});
});
td.append(select);
} else {
td.append("No serializers installed");
}
cd.find(".inputsTable tbody").append(tr);
if (index == 0) {
o.selectInput.apply(radio);
radio.attr("checked", "checked");
}
});
serviceDescriptor.outputs.forEach(function(output, index){
var tr = $("<tr>");
tr.attr("output", output);
var td = $("<td>");
var radio = $("<input type=\"radio\">");
radio.attr("id", "output" + index);
radio.attr("name", "outputformat");
td.append(radio);
tr.append(td);
tr.append("<td><label for=\"output" + index + "\">" + output + "</label></td>");
var td = $("<td>");
tr.append(td);
var select = $("<select class=\"form-control\">");
select.change(o.changeOutput);
select.append("<option value=\"EXTENDED_DATA_TO_REVISION\">Add as extended data to revision</option>");
if (output == "IFC_STEP_2X3TC1" || output == "IFC_STEP_4" || output == "IFC_XML_2X3TC1" || output == "IFC_XML_4" || output == "IFC_JSON_2X3TC1" || output == "IFC_JSON_4") {
var option = $("<option value=\"NEW_REVISION\">Checkin as new revision</option>");
select.append(option);
option.attr("selected", "selected");
}
td.append(select);
cd.find(".outputsTable tbody").append(tr);
if (index == 0) {
radio.attr("checked", "checked");
o.selectOutput.apply(radio);
}
});
o.updateButton();
});
this.changeOutput = function(){
var action = $(this).val();
if (action == "NEW_REVISION") {
var output = cd.find(".outputsTable input:checked").parents("tr").attr("output");
var canBeCheckedIn = output == "IFC_STEP_2X3TC1" || output == "IFC_STEP_4" || output == "IFC_XML_2X3TC1" || output == "IFC_XML_4" || output == "IFC_JSON_2X3TC1" || output == "IFC_JSON_4";
cd.find(".checkinDiv").toggle(canBeCheckedIn);
if (canBeCheckedIn) {
o.loadProjects(cd.find(".projectSelect"));
}
} else {
cd.find(".checkinDiv").hide();
o.updateButton();
}
};
cd.find(".btnNext").click(function(){
var output = cd.find(".outputsTable input:checked").parents("tr").attr("output");
var action = {};
var actionName = cd.find(".outputsTable input:checked").parents("tr").find("select").val();
if (actionName == "NEW_REVISION") {
action.__type = "SCheckinRevision";
action.projectId = cd.find(".projectSelect").val();
} else if (actionName == "EXTENDED_DATA_TO_REVISION") {
action.__type = "SStoreExtendedData";
}
var state = {};
var request = {
poid: project.oid,
sAction: action,
sService: {
__type: "SNewService",
name: serviceDescriptor.name,
provider: serviceDescriptor.provider,
description: serviceDescriptor.description,
tokenUrl: serviceDescriptor.tokenUrl,
authorizationUrl: serviceDescriptor.authorizationUrl,
resourceUrl: serviceDescriptor.resourceUrl,
registerUrl: serviceDescriptor.registerUrl,
input: cd.find(".inputsTable input:checked").parents("tr").attr("input"),
status: "NEW",
oauthCode: "",
action: action,
serializerId: parseInt(cd.find(".inputsTable input:checked").parents("tr").find("select").val()),
output: output,
state: JSON.stringify(state)
}
};
Global.bimServerApi.call("ServiceInterface", "addNewServiceToProject", request, function(){
projectPage.rightPanel.loadServices(function(){}, true);
});
});
cd.find(".projectSelect").change(function(){
o.updateButton();
});
}
</script>