|
1 | 1 | <html> |
2 | 2 | <head> |
| 3 | + <meta http-equiv="content-type" content="text/html;charset=UTF-8"> |
3 | 4 | <title>BIM Web Client</title> |
4 | 5 | <style type="text/css"> |
5 | 6 | body { |
|
14 | 15 | background-color: white; |
15 | 16 | border: 1px solid black; |
16 | 17 | padding: 5px; |
| 18 | + margin-right:5px; |
17 | 19 | } |
18 | 20 | p, div { |
19 | 21 | margin: 10px; |
|
40 | 42 | <script src="Base64.js"></script> |
41 | 43 | <script> |
42 | 44 | var viewer; |
43 | | - var host = 'http://localhost'; |
| 45 | + var token = null; |
| 46 | + $.ajaxSetup({ |
| 47 | + url: 'http://localhost:8082/jsonapi', |
| 48 | + type: 'POST', |
| 49 | + contentType: 'text/plain' // suppress preflight |
| 50 | + }); |
44 | 51 | function revisionUpdate(poid) { |
45 | | - $('#roids').empty(); |
46 | | - $.ajax({url: host+'/rest/getAllRevisionsOfProject', data: 'poid='+poid, dataType: 'json', |
47 | | - xhrFields: { withCredentials: true}, success: function(data){ |
48 | | - var select = $('#roids'); |
49 | | - $(data.sRevision).sort(function(r1,r2){ |
50 | | - return r1.id > r2.id; |
51 | | - }).each(function(i, revision){ |
52 | | - $('<option />').val(revision.oid).text(revision.id).appendTo(select); |
53 | | - }); |
54 | | - }}); |
| 52 | + $('#roids option.added').remove(); |
| 53 | + if(poid!='null') $.ajax({ |
| 54 | + data: JSON.stringify({token:token,request:{interface:'ServiceInterface',method:'getAllRevisionsOfProject',parameters:{poid:poid}}}), |
| 55 | + success: function(response,status,request){ |
| 56 | + var select = $('#roids'); |
| 57 | + if('exception' in response.response) $('#errors').text('Error: '+response.response.exception.message); |
| 58 | + else { |
| 59 | + $(response.response.result).sort(function(r1,r2){ |
| 60 | + return r1.id > r2.id; |
| 61 | + }).each(function(i, revision){ |
| 62 | + $('<option class="added" />').val(revision.oid).text(revision.id).appendTo(select); |
| 63 | + }); |
| 64 | + } |
| 65 | + } |
| 66 | + }); |
55 | 67 | } |
56 | 68 | function projectUpdate() { |
57 | | - $('#revision').show(); |
58 | | - $('#poids').empty(); |
59 | | - $.ajax({url: host+'/rest/getAllReadableProjects', dataType: 'json', |
60 | | - xhrFields: { withCredentials: true}, success: function(data) { |
61 | | - var select = $('#poids'); |
62 | | - $(data.sProject).filter(function(i,project){ |
| 69 | + $('#poids option.added').remove(); |
| 70 | + $.ajax({ |
| 71 | + data: JSON.stringify({token:token,request:{interface:'ServiceInterface',method:'getAllProjects',parameters:{onlyTopLevel:false}}}), |
| 72 | + success: function(response,status,request) { |
| 73 | + var select = $('#poids'); |
| 74 | + if('exception' in response.response) $('#errors').text('Error: '+response.response.exception.message); |
| 75 | + else { |
| 76 | + $(response.response.result).filter(function(i,project){ |
63 | 77 | return project.state == "ACTIVE" && project.name != "INT-Store"; |
64 | 78 | }).sort(function(p1,p2){ |
65 | 79 | return p1.name > p2.name; |
66 | 80 | }).each(function(i, project) { |
67 | | - $('<option />').val(project.oid).text(project.name).appendTo(select); |
| 81 | + $('<option class="added" />').val(project.oid).text(project.name).appendTo(select); |
68 | 82 | }); |
69 | 83 | revisionUpdate(select.val()); |
70 | 84 | } |
71 | | - }); |
| 85 | + } |
| 86 | + }); |
72 | 87 | } |
73 | 88 | $(document).ready(function() { |
74 | 89 | $('#errors').ajaxError(function(event, xhr, settings, thrown) { |
75 | 90 | $(this).text( 'Ajax error: ' + thrown.message); |
76 | 91 | }); |
77 | 92 | viewer = new ThreeJsViewer(); |
78 | 93 | viewer.init($('#viewerContainer')); |
79 | | - projectUpdate(); |
80 | 94 | viewer.onClick = function(id) { |
81 | 95 | if (id==null) { |
82 | 96 | $('#selection').html('nothing'); |
83 | 97 | return; |
84 | 98 | } |
85 | 99 | $.ajax({ |
86 | | - url: host+'/rest/getDataObjectByGuid', dataType: 'json', |
87 | | - data: 'roid='+$('#roids').val()+'&guid='+id, |
88 | | - xhrFields: { withCredentials: true}, |
89 | | - success: function(data){ |
90 | | - $('#selection').html(id + ' - ' + data.sDataObject.name + ' - ' + data.sDataObject.type); |
| 100 | + data: JSON.stringify({token:token,request:{interface:'ServiceInterface',method:'getDataObjectByGuid',parameters:{roid:$('#roids').val(),guid:id}}}), |
| 101 | + success: function(res,s,req){ |
| 102 | + $('#selection').html(id + ' - ' + res.response.result.name + ' - ' + res.response.result.type); |
91 | 103 | } |
92 | 104 | }); |
93 | 105 | }; |
|
96 | 108 | revisionUpdate($(this).val()); |
97 | 109 | }); |
98 | 110 | $('#revision').submit(function(){ |
99 | | - $.ajax({ |
100 | | - url: host+'/rest/download', |
101 | | - data: 'roid='+$(this.roids).val()+'&serializerName=ThreeJs&sync=true&showOwn=true', |
102 | | - xhrFields: { withCredentials: true}, |
103 | | - success: function(data) { |
104 | | - viewer.clearModel(); |
105 | | - $.ajax({ |
106 | | - url: host+'/rest/getDownloadData', |
107 | | - dataType: 'json', |
108 | | - data: 'actionId=' + data, |
109 | | - xhrFields: { withCredentials: true}, |
110 | | - success: function(model) { |
111 | | - viewer.loadSerializedModel(Base64.decode(model.sCheckoutResult.file)); |
| 111 | + var roid = $(this.roids).val(); |
| 112 | + if(roid!='null') $.ajax({ |
| 113 | + data: JSON.stringify({token:token,request:{interface:'ServiceInterface',method:'getSerializerByName',parameters:{serializerName:'ThreeJs'}}}), |
| 114 | + success: function(res1,s1,req1){ |
| 115 | + if('result' in res1.response) $.ajax({ |
| 116 | + data: JSON.stringify({token:token,request:{interface:'ServiceInterface',method:'download',parameters:{serializerOid:res1.response.result.oid,sync:true, showOwn:true,roid:roid}}}), |
| 117 | + success: function(res2,s2,req2){ |
| 118 | + if('result' in res2.response) $.ajax({ |
| 119 | + data: JSON.stringify({token:token,request:{interface:'ServiceInterface',method:'getDownloadData',parameters:{actionId:res2.response.result}}}), |
| 120 | + success: function(res3,s3,req3){ |
| 121 | + viewer.loadSerializedModel(Base64.decode(res3.response.result.file)); |
| 122 | + } |
| 123 | + }); |
112 | 124 | } |
113 | 125 | }); |
114 | | - // viewer.loadModel('/rest/downloadBinary?actionId=' + data); |
| 126 | + } |
| 127 | + }); |
| 128 | + return false; |
| 129 | + }); |
| 130 | + $('#authentication').submit(function(){ |
| 131 | + var username = $(this.username).val(); |
| 132 | + var password = $(this.password).val(); |
| 133 | + $.ajax({ |
| 134 | + data: JSON.stringify({request:{interface:'ServiceInterface',method:'login',parameters:{username:username,password:password}}}), |
| 135 | + success: function(response,status,request){ |
| 136 | + if('exception' in response.response) $('#errors').text('Error: '+response.response.exception.message); |
| 137 | + else { |
| 138 | + token = response.response.result; |
| 139 | + $('#authenticatedUsername').val(username); |
| 140 | + $('#authentication').hide(); |
| 141 | + $('#authenticated').show(); |
| 142 | + projectUpdate(); |
| 143 | + } |
| 144 | + } |
| 145 | + }); |
| 146 | + return false; |
| 147 | + }); |
| 148 | + $('#authenticated').submit(function(){ |
| 149 | + $.ajax({ |
| 150 | + data: JSON.stringify({token:token,request:{interface:'ServiceInterface',method:'logout'}}), |
| 151 | + success: function(response,status,request){ |
| 152 | + if('exception' in response.response) $('#errors').text('Error: '+response.response.exception.message); |
| 153 | + else{ |
| 154 | + token = null; |
| 155 | + $('#authenticatedUsername').val(''); |
| 156 | + $('#poids option.added').remove(); |
| 157 | + $('#roids option.added').remove(); |
| 158 | + $('#authenticated').hide(); |
| 159 | + $('#authentication').show(); |
| 160 | + } |
115 | 161 | } |
116 | 162 | }); |
117 | 163 | return false; |
|
121 | 167 | </head> |
122 | 168 | <body> |
123 | 169 | <div> |
124 | | -<form id="revision" class="boxed" style="display: none;"> |
125 | | - <select id="poids"></select> |
126 | | - <select id="roids"></select> |
| 170 | +<form id="authentication" class="boxed" action="javascript:" method="post"> |
| 171 | + User: <input type="text" id="username"/> |
| 172 | + Password: <input type="password" id="password"/> |
| 173 | + <input type="submit" value="Login"/> |
| 174 | +</form> |
| 175 | +<form id="authenticated" class="boxed" style="display: none" action="javascript:" method="post"> |
| 176 | + User: <input type="text" id="authenticatedUsername" disabled /> |
| 177 | + <input type="submit" value="Logout" /> |
| 178 | +</form> |
| 179 | +<form id="revision" class="boxed" action="javascript:" method="post"> |
| 180 | + <select id="poids"><option value="null">-- none --</option></select> |
| 181 | + <select id="roids"><option value="null">-- none --</option></select> |
127 | 182 | <input type="submit" value="Show" /> |
128 | 183 | </form> |
129 | 184 | </div> |
|
0 commit comments