Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion public/activities/activitypainter.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,29 @@ var ActivityPainter = {
Simva.setActivityCompletion(activityId, username, status, function(){
console.log('saved');
});
}
},

getMinioData: function(activity, as_array=false){
Simva.getMinioDataUrl(activity, as_array, function(error, result){
if(error){
$.toast({
heading: 'Error loading the result',
text: error.message,
position: 'top-right',
icon: 'error',
stack: false
});
}else{
let filename=activity;
if(as_array) {
filename=`${activity}_traces_data_as_array.json`;
} else {
filename=`${activity}_traces_data_one_per_line.txt`;
}
Utils.download(`${filename}`,`${result.data}`);
}
})
},
}

PainterFactory.addPainter(ActivityPainter);
7 changes: 5 additions & 2 deletions public/activities/gameplaypainter.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,12 @@ var GameplayActivityPainter = {
}
activitybox += '<br>'
*/
activitybox += '<p>Trace Storage: '
activitybox += '<br>Trace Storage:'
if(activity.extra_data.config.trace_storage) {
activitybox += `<a onclick="GameplayActivityPainter.getMinioData('${activity._id}')" target="_blank">Download Data</a>
activitybox += `<p>Download as <a onclick="PainterFactory.Painters['activity'].getMinioData('${activity._id}', true)" target="_blank">Array</a></p>
<p>Download as <a onclick="PainterFactory.Painters['activity'].getMinioData('${activity._id}', false)" target="_blank">OneTracePerLine</a></p>
</br>
<br>
<br>
XASU Config:
<a onclick="GameplayActivityPainter.downloadXasuConfig('${activity._id}','${activity.study}')">
Expand Down
7 changes: 4 additions & 3 deletions public/activities/limesurveypainter.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,10 @@ var LimeSurveyPainter = {
<p><a onclick="LimeSurveyPainter.generateTinyURL('${activity._id}', ${activity.extra_data.surveyId})">Generate Tiny URL</a></p>
<p><a onclick="LimeSurveyPainter.downloadBackup('${activity._id}', 'full')"> Full : ⬇️</a>
<a onclick="LimeSurveyPainter.downloadBackup('${activity._id}', 'code')"> Code : ⬇️</a></p>
<div id="completion_progress_${activity._id}" class="progress"><div class="partial"></div><div class="done"></div><span>Completed: <done>0</done>% [ <doneres>0</doneres> /<total>0</total> ]</span></div>
<div id="result_progress_${activity._id}" class="progress"><div class="partial"></div><div class="done"></div><div></div><span>Results: <done>0</done> (<partial>0</partial>) % [ <doneres>0</doneres> (<partialres>0</partialres>) /<total>0</total> ]</span></div>
${this.paintActivityParticipantsTable(activity, participants)}</div>`);
Trace Storage :
<p>Download as <a onclick="PainterFactory.Painters['activity'].getMinioData('${activity._id}', true)" target="_blank">Array</a></p>
<p>Download as <a onclick="PainterFactory.Painters['activity'].getMinioData('${activity._id}', false)" target="_blank">OneTracePerLine</a></p>
${PainterFactory.Painters["activity"].paintActivityParticipantsTable(activity, participants, false)}</div>`);
},

paintActivityParticipantsTable: function(activity, participants){
Expand Down
3 changes: 3 additions & 0 deletions public/activities/manualpainter.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ var ManualActivityPainter = {
<input class="red" type="button" value="X" onclick="deleteActivity('${activity._id}', '${activity.name}', '${activity.test}')"></div>
<p class="subtitle">${this.simpleName}</p>
<p>Students ${complete} complete</p>
<p>Download as <a onclick="PainterFactory.Painters['activity'].getMinioData('${activity._id}', true)" target="_blank">Array</a></p>
<p>Download as <a onclick="PainterFactory.Painters['activity'].getMinioData('${activity._id}', false)" target="_blank">OneTracePerLine</a></p>
<br>
<div id="completion_progress_${activity._id}" class="progress"><div class="partial"></div><div class="done"></div><span>Completed: <done>0</done>% [ <doneres>0</doneres> /<total>0</total> ]</span></div>
<div id="result_progress_${activity._id}" class="progress"><div class="partial"></div><div class="done"></div><div></div><span>Results: <done>0</done> (<partial>0</partial>) % [ <doneres>0</doneres> (<partialres>0</partialres>) /<total>0</total> ]</span></div>
${this.paintActivityParticipantsTable(activity, participants)}</div>`);
Expand Down
8 changes: 6 additions & 2 deletions public/simva.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,12 @@ var Simva = {
Utils.get(`/bff/activities/${activity_id}/openable`, callback);
},

getMinioDataUrl: function(activity_id, callback){
Utils.get(`/bff/activities/${activity_id}/presignedurl`, callback);
getMinioDataUrl: function(activity_id, as_array, callback){
let as_array_query="";
if(as_array) {
as_array_query= "?as_array=true";
}
Utils.get(`/bff/activities/${activity_id}/presignedurl${as_array_query}`, callback);
},

deleteActivity: function(activity_id, callback){
Expand Down
28 changes: 26 additions & 2 deletions routes/routes/bff.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ module.exports = function(auth, config){
const studycontroler = require('../lib/studycontroler');
const groupcontroler = require('../lib/groupcontroler');
const testscontroler = require('../lib/testscontroler');

const axios = require('axios');

/**
* USERS
*
Expand Down Expand Up @@ -516,7 +517,30 @@ module.exports = function(auth, config){
if(error) {
next(error.response.data);
} else {
res.status(200).send(result);
let url = result.url;
logger.info(url);
// Fetch the file from the pre-signed URL
axios.get(url, { responseType: 'arraybuffer' }) // Use 'arraybuffer' for binary data
.then(response => {
// Modify the file content. This example assumes it's a text file.
// For binary files, you might need to handle it differently.
let fileContent = Buffer.from(response.data, 'binary').toString(); // Assuming text file
let result={};
if(req.query.as_array) {
let array=fileContent.split('\n');
if (array[array.length - 1].trim() === '') {
array.pop();
}
array = array.map(line => JSON.parse(line));
result.data=JSON.stringify(array, null, 2);
} else {
result.data=fileContent;
}
res.status(200).send(result);
})
.catch(fetchError => {
next(fetchError.response.data);
});
}
});
});
Expand Down