Skip to content

Commit

Permalink
Merge pull request #104 from e-ucm/kahoot
Browse files Browse the repository at this point in the history
Adds Upload Kahoot Trace File Functionality
  • Loading branch information
gorco committed Dec 14, 2018
2 parents 1c03e8d + bdf558c commit 8a32c98
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 6 deletions.
40 changes: 34 additions & 6 deletions app/public/js/controllers/activity.js
Expand Up @@ -287,13 +287,37 @@ angular.module('activityApp', ['myApp', 'ngStorage', 'services'])
console.error('Error on get /offlinetraces/' + $scope.activity._id + ' ' +
JSON.stringify(response, null, ' '));
});

$http.get(CONSTANTS.PROXY + '/offlinetraces/' + $scope.activity._id + '/kahoot', {
transformRequest: angular.identity,
headers: {
'Content-Type': undefined,
enctype: 'multipart/form-data'
}
}).then(function successCallback(response) {
// This callback will be called asynchronously
// when the response is available

$scope.offlinetraceskahoot = response.data;
}, function errorCallback(response) {
// Called asynchronously if an error occurs
// or server returns response with an error status.
console.error('Error on get /offlinetraces/' + $scope.activity._id + '/kahoot ' +
JSON.stringify(response, null, ' '));
});
}
}

function upload(file) {
function upload(file, kahoot) {
var appended = 'offlinetraces';
var url = CONSTANTS.PROXY + '/offlinetraces/' + $scope.activity._id;
if (kahoot) {
url += '/kahoot';
appended += 'kahoot';
}
var formData = new FormData();
formData.append('offlinetraces', file);
$http.post(CONSTANTS.PROXY + '/offlinetraces/' + $scope.activity._id, formData, {
formData.append(appended, file);
$http.post(url, formData, {
transformRequest: angular.identity,
headers: {
'Content-Type': undefined,
Expand All @@ -306,20 +330,24 @@ angular.module('activityApp', ['myApp', 'ngStorage', 'services'])
}, function errorCallback(response) {
// Called asynchronously if an error occurs
// or server returns response with an error status.
console.error('Error on post /offlinetraces/' + $scope.activity._id + ' ' +
console.error('Error on post ' + url + ' ' +
JSON.stringify(response, null, ' '));
});
}

$rootScope.tracesFile = undefined;
$scope.uploadTracesFile = function () {
console.log('aaaaaaaaaa');
if ($rootScope.tracesFile) {
console.log('bbbbbbbb');
upload($rootScope.tracesFile);
}
};

$scope.uploadKahootTracesFile = function () {
if ($rootScope.kahootTracesFile) {
upload($rootScope.kahootTracesFile, true);
}
};

// Anonymous

$scope.anonymous = 'btn-default';
Expand Down
Binary file added app/public/kahoot.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions app/views/view/data/information.jade
Expand Up @@ -50,6 +50,31 @@
label {{tracefile._id | prettyDateId }}
td
label {{tracefile.author }}
hr
img.img-circle(src='kahoot.jpg', alt='Kahoot')
.col-xs-12
label Select a Kahoot traces file (Downloading a Kahoot session into a results.xlsx file):
input(type="file" file-model="kahootTracesFile")
button.btn.btn-primary.top5(type='submit', ng-click='uploadKahootTracesFile()') Upload Kahoot results file
.row
.col-md-12
table.table.table-hover
thead
tr
th Trace file
th Time uploaded
th Author
tbody
tr(ng-if='!offlinetraceskahoot || offlinetraceskahoot.length === 0')
td(colspan=6)
div.alert.alert-warning(style='margin-bottom: 0px') No kahoot trace files found (you can get one by downloading the results.xlsx file from a Kahoot Activity)
tr(ng-repeat='tracefile in offlinetraceskahoot')
td
label {{tracefile.name}}
td
label {{tracefile._id | prettyDateId }}
td
label {{tracefile.author }}
.row(ng-if='isDeveloper()')
hr
.col-xs-12
Expand Down

0 comments on commit 8a32c98

Please sign in to comment.