diff --git a/src/css/dvwebloader.css b/src/css/dvwebloader.css index 944e8b4..0d9b710 100644 --- a/src/css/dvwebloader.css +++ b/src/css/dvwebloader.css @@ -84,7 +84,7 @@ h1 { width: 58%; display:inline-block; } -.button:disabled { +.button.disabled { background: gray; border-color: gray!important; } @@ -104,3 +104,52 @@ h1 { border-width: 2px; border-style: solid; } + +#refreshDataset { + float:right; +} +.button { + font-size:16px; +} + +.pending { + display: flex; + align-items: center; + padding: 10px; + background-color: #f8f9fa; + border-left: 4px solid #007bff; + margin: 10px 0; +} + +.spinner { + border: 3px solid rgba(0, 0, 0, 0.1); + border-radius: 50%; + border-top: 3px solid #007bff; + width: 20px; + height: 20px; + margin-right: 10px; + animation: spin 1s linear infinite; +} + +@keyframes spin { + 0% { transform: rotate(0deg); } + 100% { transform: rotate(360deg); } +} + +.button-flex-container { + display: flex; + justify-content: space-between; + margin: 10px 0; + min-height: 40px; +} + +.button-left { + display: flex; + align-items: center; +} + +.button-right { + display: flex; + align-items: center; + gap: 10px; /* Space between buttons */ +} \ No newline at end of file diff --git a/src/dvwebloader.html b/src/dvwebloader.html index fc39f9f..536bff3 100644 --- a/src/dvwebloader.html +++ b/src/dvwebloader.html @@ -21,7 +21,13 @@

Folder Upload


- +
+
+ +
+
+
+
diff --git a/src/js/fileupload2.js b/src/js/fileupload2.js index 7687d16..2220d98 100644 --- a/src/js/fileupload2.js +++ b/src/js/fileupload2.js @@ -113,22 +113,13 @@ $(document).ready(function() { var files = e.target.files; // FileList for (let i = 0; i < files.length; ++i) { let f = files[i]; - console.log('before ' + f.webkitRelativePath); + //console.log('before ' + f.webkitRelativePath); queueFileForDirectUpload(f); console.debug(files[i].webkitRelativePath); // output.innerText = output.innerText + files[i].webkitRelativePath+"\n"; } - let numExists = $('#filelist>.ui-fileupload-files .file-exists').length; let totalFiles = Object.keys(rawFileMap).length; - console.log('exists: ' + numExists); - console.log('rawFileMap len: ' + totalFiles); - if (totalFiles === numExists) { - addMessage('info', 'msgFilesAlreadyExist'); - } else if (numExists !== 0 && totalFiles > numExists) { - addMessage('info', 'msgUploadOnlyCheckedFiles'); - } else ( - addMessage('info', 'msgStartUpload') - ) + updateFileSelectionMessage(); $('label.button').hide(); // Add buttons for selecting/deselecting files $('
') @@ -157,6 +148,24 @@ $(document).ready(function() { }; }); +/** + * Updates the message displayed to the user based on file selection status + */ +function updateFileSelectionMessage() { + let numExists = $('#filelist>.ui-fileupload-files .file-exists').length; + let totalFiles = Object.keys(rawFileMap).length; + console.log('exists: ' + numExists); + console.log('rawFileMap len: ' + totalFiles); + + if (totalFiles === numExists) { + addMessage('info', 'msgFilesAlreadyExist'); + } else if (numExists !== 0 && totalFiles > numExists) { + addMessage('info', 'msgUploadOnlyCheckedFiles'); + } else { + addMessage('info', 'msgStartUpload'); + } +} + function updateMaxFiles() { let maxInput = $('#maxFilesInput'); let maxFiles = parseInt(maxInput.val()); @@ -254,7 +263,6 @@ function addContentWarning(key, ...keyArgs) { async function populatePageMetadata(data) { var mdFields = data.metadataBlocks.citation.fields; var title = ""; - var authors = ""; var datasetUrl = siteUrl + '/dataset.xhtml?persistentId=' + datasetPid; draftExists = data.latestVersionPublishingState && data.latestVersionPublishingState === "DRAFT"; @@ -262,22 +270,17 @@ async function populatePageMetadata(data) { if (mdFields[field].typeName === "title") { title = mdFields[field].value; } - if (mdFields[field].typeName === "author") { - var authorFields = mdFields[field].value; - for (var author in authorFields) { - if (authors.length > 0) { - authors = authors + "; "; - } - authors = authors - + authorFields[author].authorName.value; - } - } } let mdDiv = $('
').append($('

').text(getLocalizedString(dvLocale, 'uploadingTo')).append($('').prop("href", datasetUrl).prop('target', '_blank').text(title))); $('#top').prepend(mdDiv); } -async function retrieveDatasetInfo() { +/** + * Refreshes dataset information from Dataverse + * @param {boolean} isInitialLoad - Whether this is the initial load or a refresh + */ +async function retrieveDatasetInfo(isInitialLoad = true) { + addMessage('info', 'msgGettingDatasetInfo'); try { // First, check for dataset locks const locksResponse = await $.ajax({ @@ -297,6 +300,7 @@ async function retrieveDatasetInfo() { if (locksResponse.data && locksResponse.data.length > 0 && !isLockedInReview) { addMessage('error', 'msgDatasetLocked'); disableUploadFunctionality(); + addRefreshButton(); return; } @@ -313,6 +317,7 @@ async function retrieveDatasetInfo() { if (!permissionsResponse.data || !permissionsResponse.data.canPublishDataset) { addMessage('error', 'msgDatasetLockedInReview'); disableUploadFunctionality(); + addRefreshButton(); return; } } @@ -329,8 +334,9 @@ async function retrieveDatasetInfo() { console.log(datasetResponse); let data = datasetResponse.data; console.log(data); - - populatePageMetadata(data); + if(isInitialLoad) { + populatePageMetadata(data); + } if (data.files !== null) { existingFiles = {}; convertedFileNameMap = {}; @@ -348,7 +354,7 @@ async function retrieveDatasetInfo() { if ('directoryLabel' in entry) { filepath = entry.directoryLabel + '/' + filepath; } - console.log("Storing: " + filepath); + //console.log("Storing: " + filepath); existingFiles[filepath] = df.checksum; if (convertedFile) { convertedFileNameMap[removeExtension(filepath)] = filepath; @@ -356,12 +362,113 @@ async function retrieveDatasetInfo() { } } $('#files').prop('disabled', false); - addMessage('info', 'msgReadyToStart'); + if(isInitialLoad || $('#filelist>.ui-fileupload-files').length === 0) { + addMessage('info', 'msgReadyToStart'); + // Add the refresh button after initial load + addRefreshButton(); + } } catch (error) { console.log('Error:', error); addMessage('error', 'msgErrorRetrievingDataset'); + } +} + +/** + * Adds a refresh button to the UI + */ +function addRefreshButton() { + if ($('#refreshDataset').length === 0) { + $('#button-container .button-right').append( + $('