Skip to content

Commit

Permalink
swancontents: remove dependency on requirejs, jquery and nb in downlo…
Browse files Browse the repository at this point in the history
…ad page
  • Loading branch information
diocas authored and PMax5 committed Jun 7, 2024
1 parent 4bde0d0 commit ef17c81
Showing 1 changed file with 37 additions and 23 deletions.
60 changes: 37 additions & 23 deletions SwanContents/swancontents/serverextension/templates/download.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,34 +40,48 @@

<script type = "text/javascript" >

require(['jquery', 'base/js/utils'], function ($, utils) {
document.addEventListener("DOMContentLoaded", function() {
var base_url = document.body.getAttribute("data-baseUrl") || "";
var urlParams = new URLSearchParams(window.location.search);
var proj_url = urlParams.get('projurl');

var base_url = utils.get_body_data("baseUrl");
var proj_url = utils.get_url_param('projurl');

var settings = {
processData : false,
type : "GET",
contentType: 'application/json',
dataType : "json",
};
var settings = {
method: "GET",
headers: {
'Content-Type': 'application/json'
}
};

utils.promising_ajax(base_url + 'api/contents/fetch?url=' + proj_url, settings)
.then(function (result) {
if (result && result.path) {
window.location.replace(base_url + (result.type == 'directory' ? result.path.replace('SWAN_projects', 'projects') : 'notebooks/' + result.path))
} else {
error('Error downloading project.');
}
}).catch(function (e) {
error(e.message || e.xhr_error || e.reason || e);
fetch(base_url + 'api/contents/fetch?url=' + encodeURIComponent(proj_url), settings)
.then(function(response) {
if (!response.ok) {
throw new Error('Network response was not ok ' + response.statusText);
}
return response.json();
})
.then(function(result) {
if (result && result.path) {
var redirectUrl = base_url + (result.type === 'directory' ? result.path.replace('SWAN_projects', 'projects') : 'notebooks/' + result.path);
window.location.replace(redirectUrl);
} else {
showError('Error downloading project.');
}
})
.catch(function(error) {
showError(error.message || error);
});

function error(reason) {
$('#swan-loader .loader-line-mask').hide();
$('#swan-loader .text').html('<p class="extra">Error downloading Project: ' + reason + '</p>');
function showError(reason) {
var loaderMask = document.querySelector('#swan-loader .loader-line-mask');
if (loaderMask) {
loaderMask.style.display = 'none';
}
var loaderText = document.querySelector('#swan-loader .text');
if (loaderText) {
loaderText.innerHTML = '<p class="extra">Error downloading Project: ' + reason + '</p>';
}
});
}
});

</script>
{% endblock %}

0 comments on commit ef17c81

Please sign in to comment.