Skip to content

Commit

Permalink
feat: add file path information to xAPI (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
felipemontoya authored Apr 25, 2024
1 parent c2fa71d commit f9761ae
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 11 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ Change Log
Unreleased
**********

0.9.0 - 2024-04-25
**********************************************

Added
=====

* The tracking transformation to xAPI now contains the file path
* Support for tracking event with when multiple files are downloaded in a zip


0.8.1 - 2024-03-11
**********************************************

Expand Down
2 changes: 1 addition & 1 deletion filesmanager/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Init for the FilesManagerXBlock package.
"""

__version__ = '0.8.1'
__version__ = '0.9.0'
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,23 @@ def get_object(self):
type=constants.XAPI_ACTIVITY_FILE,
),
)

def get_context_activities(self):
"""
Add context with activities for each file downloaded from the xblock.
Returns:
`context_activities`
"""
context_activities = super().get_context_activities()
context_activities.grouping = [
Activity(
id=file.get("asset_key"),
definition=ActivityDefinition(
type=constants.XAPI_ACTIVITY_FILE,
name=LanguageMap({constants.EN: file.get("path")}),
),
)
for file in self.event.get('data', {}).get("files_downloaded_metadata", [])
]
return context_activities
2 changes: 1 addition & 1 deletion filesmanager/static/html/bundle.js

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions filesmanager/static/html/bundle.js.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
object-assign
(c) Sindre Sorhus
@license MIT
*/

/*!
Copyright (c) 2018 Jed Watson.
Licensed under the MIT License (MIT), see
Expand Down Expand Up @@ -97,6 +103,15 @@
* @license MIT
*/

/** @license React v0.20.2
* scheduler.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/** @license React v16.13.1
* react-is.production.min.js
*
Expand All @@ -106,6 +121,15 @@
* LICENSE file in the root directory of this source tree.
*/

/** @license React v17.0.2
* react-dom.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/** @license React v17.0.2
* react-is.production.min.js
*
Expand Down
16 changes: 10 additions & 6 deletions react-app/components/FileManager/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,14 @@ const FileManager = (props) => {
const downloadFilesData = useRef(null);
const dateInputRef = useRef(null);

const onFileDownloaded = () => {
const onFileDownloaded = (listOfFiles) => {
setDownloadFileErrorMessage(null);
const fileContents = downloadFilesData.current;
const filesMetadata = getMetadataFiles(fileContents);
if (listOfFiles !== null && fileContents === null) {
var filesMetadata = getMetadataFiles(listOfFiles);
}else{
var filesMetadata = getMetadataFiles(fileContents);
}
const { isStudioView, xblockId, courseId, userId, userName } = xBlockContext;
if (!isStudioView) {
sendTrackingLogEvent('edunext.xblock.filesmanager.files.downloaded', {
Expand Down Expand Up @@ -83,7 +87,7 @@ const FileManager = (props) => {
downloadFiles([fileData])
return
}
downloadFileHook(fullUrl, name, false);
downloadFileHook(fullUrl, name, false, null);
};

const downloadFiles = (filesToDownload) => {
Expand All @@ -97,22 +101,22 @@ const FileManager = (props) => {
throw new Error('Download content has failed: Unexpected status code');
}
let data = createContentData.data;
getStatusFromZipTask(data.task_id)
getStatusFromZipTask(data.task_id, filesToDownload)

return Promise.resolve('Download was successful');
} catch (error) {
return Promise.reject('An error has ocurred while downloading assets');
}
};

const getStatusFromZipTask = async (taskID) => {
const getStatusFromZipTask = async (taskID, filesToDownload) => {
const createContentData = await downloadStatus(taskID);
if (createContentData.status !== StatusCodes.OK) {
throw new Error('Fetching task status has failed: Unexpected status code');
}
let data = createContentData.data;
if (data.status === 'SUCCESS') {
downloadFileHook(data.result, "download.zip", true)
downloadFileHook(data.result, "download.zip", true, filesToDownload)
} else if (data.status === 'ERROR') {
onError()
} else {
Expand Down
8 changes: 7 additions & 1 deletion react-app/components/FileManager/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,17 @@ export const getMetadataFiles = (node) => {
});
}

if (node.children && node.children.length) {
if (node.children && Array.isArray(node.children)) {
node.children.forEach((child) => {
assetKeys.push(...getMetadataFiles(child));
});
}

if (Array.isArray(node)) {
node.forEach((child) => {
assetKeys.push(...getMetadataFiles(child));
});
}

return assetKeys;
};
8 changes: 6 additions & 2 deletions react-app/hooks/useFileDownloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@ const useFileDownloader = ({ onError, onFileDownloaded}) => {
const [, setBlobUrl] = useState(null);
const [isLoading, setIsLoading] = useState(false);

const downloadFileHook = async (fileUrl, fileName, isZip) => {
const downloadFileHook = async (fileUrl, fileName, isZip, listOfFiles) => {

setIsLoading(true);

try {
saveAs(fileUrl, fileName);
onFileDownloaded();
try {
onFileDownloaded(listOfFiles);
}catch (error) {
console.debug("FileManager Xblock: We could not log the download");
}
} catch (error) {
onError();
}finally {
Expand Down

0 comments on commit f9761ae

Please sign in to comment.