Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
* Fixing .odvd drop off zone
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Berger <christian.berger@gu.se>
  • Loading branch information
chrberger committed Dec 4, 2018
1 parent 8add36a commit ea554f7
Showing 1 changed file with 115 additions and 115 deletions.
230 changes: 115 additions & 115 deletions webapp/views/recordings.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -115,121 +115,6 @@ function toggleMessageViewFromTop() {
</script>
{{/if}}

<script>
function handleDragOver(evt) {
evt.stopPropagation();
evt.preventDefault();
evt.dataTransfer.dropEffect = 'copy';
}
function handleFileSelect(evt) {
evt.stopPropagation();
evt.preventDefault();
var files = evt.dataTransfer.files; // FileList object.
// files is a FileList of File objects. List some properties.
var output = [];
if (1 != files.length) {
alert("Cannot handle more than one message specification file (.odvd).");
}
else if (1024*1024 < files[0].size) {
alert("Cannot handle message specification files (.odvd) that are larger than 1MB.");
}
else {
var reader = new FileReader();
reader.onload = function(e) {
var content = reader.result;
var __libcluon = libcluon();
var res = "0";
try {
// Always add the messages to control the remote player and to actuation request.
var playerMessages = `
message cluon.data.PlayerCommand [id = 9] {
uint8 command [id = 1]; // 0 = nothing, 1 = play, 2 = pause, 3 = seekTo, 4 = step
float seekTo [id = 2];
}
message cluon.data.PlayerStatus [id = 10] {
uint8 state [id = 1]; // 0 = unknown, 1 = loading file, 2 = playback
uint32 numberOfEntries [id = 2];
uint32 currentEntryForPlayback [id = 3];
}
// This message is a legacy one to support controlling Snowfox and Rhino.
message opendlv.proxy.ActuationRequest [id = 160] {
float acceleration [id = 1];
float steering [id = 2];
bool isValid [id = 3];
}
`;
content += playerMessages;
res = __libcluon.setMessageSpecification(content);
}
catch (e) {
res = "0";
}
if ("0" != res) {
if (confirm("Do you want to upload the provided message specification file?")) {
fetch('/provideodvdfile', { method: 'post',
headers: {
'Accept': 'application/json, text/plain, */*',
'Content-Type': 'application/json'
},
body: JSON.stringify({odvd: content})
}
)
.then(function(response) {
if (response.ok) {
location.reload();
return;
}
throw new Error('Request failed.');
})
.catch(function(error) {
console.log(error);
});
}
}
else {
alert("Provided message specification file contained " + res + " messages.");
}
}
reader.readAsText(files[0]);
}
}
// Connect drag-and-drop listeners.
var dropZone = document.getElementById('drop_zone');
dropZone.addEventListener('dragover', handleDragOver, false);
dropZone.addEventListener('drop', handleFileSelect, false);
function deleteExternallySuppliedODVDFile() {
if (confirm("Do you really want to remove previously provided message specification file?")) {
fetch('/deleteodvdfile', { method: 'post',
headers: {
'Accept': 'application/json, text/plain, */*',
'Content-Type': 'application/json'
} }
)
.then(function(response) {
if(response.ok) {
location.reload();
return;
}
throw new Error('Request failed.');
})
.catch(function(error) {
console.log(error);
});
}
}
</script>

<script>
// Sorting table code: https://www.w3schools.com/howto/howto_js_sort_table.asp
function sortTable(n) {
Expand Down Expand Up @@ -500,6 +385,121 @@ function deleteFile(filename, name) {
<br>
</div>

<script>
function handleDragOver(evt) {
evt.stopPropagation();
evt.preventDefault();
evt.dataTransfer.dropEffect = 'copy';
}
function handleFileSelect(evt) {
evt.stopPropagation();
evt.preventDefault();
var files = evt.dataTransfer.files; // FileList object.
// files is a FileList of File objects. List some properties.
var output = [];
if (1 != files.length) {
alert("Cannot handle more than one message specification file (.odvd).");
}
else if (1024*1024 < files[0].size) {
alert("Cannot handle message specification files (.odvd) that are larger than 1MB.");
}
else {
var reader = new FileReader();
reader.onload = function(e) {
var content = reader.result;
var __libcluon = libcluon();
var res = "0";
try {
// Always add the messages to control the remote player and to actuation request.
var playerMessages = `
message cluon.data.PlayerCommand [id = 9] {
uint8 command [id = 1]; // 0 = nothing, 1 = play, 2 = pause, 3 = seekTo, 4 = step
float seekTo [id = 2];
}
message cluon.data.PlayerStatus [id = 10] {
uint8 state [id = 1]; // 0 = unknown, 1 = loading file, 2 = playback
uint32 numberOfEntries [id = 2];
uint32 currentEntryForPlayback [id = 3];
}
// This message is a legacy one to support controlling Snowfox and Rhino.
message opendlv.proxy.ActuationRequest [id = 160] {
float acceleration [id = 1];
float steering [id = 2];
bool isValid [id = 3];
}
`;
content += playerMessages;
res = __libcluon.setMessageSpecification(content);
}
catch (e) {
res = "0";
}
if ("0" != res) {
if (confirm("Do you want to upload the provided message specification file?")) {
fetch('/provideodvdfile', { method: 'post',
headers: {
'Accept': 'application/json, text/plain, */*',
'Content-Type': 'application/json'
},
body: JSON.stringify({odvd: content})
}
)
.then(function(response) {
if (response.ok) {
location.reload();
return;
}
throw new Error('Request failed.');
})
.catch(function(error) {
console.log(error);
});
}
}
else {
alert("Provided message specification file contained " + res + " messages.");
}
}
reader.readAsText(files[0]);
}
}
// Connect drag-and-drop listeners.
var dropZone = document.getElementById('drop_zone');
dropZone.addEventListener('dragover', handleDragOver, false);
dropZone.addEventListener('drop', handleFileSelect, false);
function deleteExternallySuppliedODVDFile() {
if (confirm("Do you really want to remove previously provided message specification file?")) {
fetch('/deleteodvdfile', { method: 'post',
headers: {
'Accept': 'application/json, text/plain, */*',
'Content-Type': 'application/json'
} }
)
.then(function(response) {
if(response.ok) {
location.reload();
return;
}
throw new Error('Request failed.');
})
.catch(function(error) {
console.log(error);
});
}
}
</script>


<div class="container-fluid">
<center>
Expand Down

0 comments on commit ea554f7

Please sign in to comment.