Skip to content

Commit

Permalink
Uploader: Submissions in progress delete button now works
Browse files Browse the repository at this point in the history
  • Loading branch information
jorvis committed Oct 2, 2024
1 parent 950548d commit 5e7d0bb
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 1 deletion.
60 changes: 60 additions & 0 deletions www/cgi/delete_upload_in_progress.cgi
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/opt/bin/python3

"""
This script deletes one of directories representing a user's upload in progress.
"""

import cgi
import json
import os, sys
import shutil

lib_path = os.path.abspath(os.path.join('..', '..', 'lib'))
sys.path.append(lib_path)
import geardb

share_uid = None
dataset_id = None
session_id = None
user_upload_file_base = '../uploads/files'

def main():
print('Content-Type: application/json\n\n', flush=True)
result = {'success':0, 'message':''}
global share_uid
global session_id

form = cgi.FieldStorage()
share_uid = form.getvalue('share_uid')
session_id = form.getvalue('session_id')
dataset_id = form.getvalue('dataset_id')

user = geardb.get_user_from_session_id(session_id)
if user is None:
result['message'] = 'User ID not found. Please log in to continue.'
print(json.dumps(result))
return

user_upload_file_path = os.path.join(user_upload_file_base, session_id, share_uid)

if not os.path.exists(user_upload_file_path):
result['message'] = 'Upload directory not found: ' + user_upload_file_path
print(json.dumps(result))
return

try:
# recursively delete the directory
shutil.rmtree(user_upload_file_path)

except Exception as e:
result['message'] = 'Error deleting file: ' + str(e)
print(json.dumps(result))
return

result['success'] = 1
result['message'] = 'File deleted successfully.'
print(json.dumps(result))


if __name__ == '__main__':
main()
31 changes: 30 additions & 1 deletion www/js/upload_dataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,20 @@ const checkDatasetProcessingStatus = async () => {
}
}

const deleteUploadInProgress = async (share_uid, dataset_id) => {
const {data} = await axios.post('./cgi/delete_upload_in_progress.cgi', convertToFormData({
share_uid: share_uid,
dataset_id: dataset_id,
session_id: CURRENT_USER.session_id
}));

if (data.success) {
loadUploadsInProgress();
} else {
createToast('Error deleting upload in progress', data.message, 'is-warning');
}
}

const finalizeUpload = async () => {
let formData = new FormData();
formData.append('share_uid', share_uid);
Expand Down Expand Up @@ -405,8 +419,11 @@ const loadUploadsInProgress = async () => {
});

// Add click listeners for submissions-in-progress-table-tbody rows we just added
document.querySelectorAll('.submission-history-row').forEach((row) => {
// First, the resume button
document.querySelectorAll('.submission-history-row .submission-resume').forEach((row) => {
row.addEventListener('click', (event) => {
let row = event.target.closest('tr');

share_uid = row.dataset.shareId;
const step = row.dataset.loadStep;

Expand All @@ -423,6 +440,18 @@ const loadUploadsInProgress = async () => {
});
});

// Now the delete button
document.querySelectorAll('.submission-history-row .submission-delete').forEach((row) => {
row.addEventListener('click', (event) => {
// reset row to be the parent tr element
let row = event.target.closest('tr');

share_uid = row.dataset.shareId;
const dataset_id = row.dataset.datasetId;
deleteUploadInProgress(share_uid, dataset_id);
});
});

document.getElementById('submissions-in-progress').classList.remove('is-hidden');
} else {
document.getElementById('submission-c').classList.remove('is-hidden');
Expand Down

0 comments on commit 5e7d0bb

Please sign in to comment.