Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rFixed upload button in modal #11

Merged
merged 1 commit into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions buildchain/src/js/canto-embed.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ function setToken(tokenInfo) {
_formatDistrict = tokenInfo.formatDistrict;
}


cantoAPI.loadTree = function (callback) {
var url = "https://" + _tenants + "/api/v1/tree?sortBy=name&sortDirection=ascending&layer=1";
$.ajax({
Expand Down Expand Up @@ -371,6 +372,8 @@ $(document).ready(function () {
$("#cantoViewBody").find("#globalSearch input").val("");
getImageInit(initSchme);
});


});

function getTokenInfo() {
Expand All @@ -397,7 +400,13 @@ function addEventListener() {
_tokenType = tokenInfo.tokenType;
});

$(document).off('click').on("click", "#treeviewSwitch", function (e) {
$(document).off('click').on("change", "#uploadBtnInvisible", (e) => {
uploadFileToCanto(e);
})
.on("click", "#uploadBtn", (e) => {
document.querySelector("#uploadBtnInvisible").click();
})
.on("click", "#treeviewSwitch", function (e) {
if ($('#treeviewSection').hasClass("expanded")) {
$('#treeviewSection').stop().animate({
left: '-20%'
Expand Down Expand Up @@ -930,10 +939,6 @@ function loadMoreAction() {
}
}

function uploadClick(e) {
document.querySelector("#uploadBtnInvisible").click();
}

function uploadFileToCanto(e) {
let url = `https://${_tenants}/api/v1/upload/setting`;
fetch(url, {
Expand All @@ -951,12 +956,12 @@ function uploadFileToCanto(e) {
formData.append("AWSAccessKeyId", data.AWSAccessKeyId);
formData.append("Policy", data.Policy);
formData.append("Signature", data.Signature);
formData.append("x-amz-meta-file_name", e.files[0].name);
formData.append("x-amz-meta-file_name", e.currentTarget.files[0].name);
formData.append("x-amz-meta-tag", "");
formData.append("x-amz-meta-scheme", "");
formData.append("x-amz-meta-id", "");
formData.append("x-amz-meta-album_id", "");
formData.append("file", e.files[0]);
formData.append("file", e.currentTarget.files[0]);
let statusBar = parent.document.querySelector(".modal-status-bar");

fetch(data.url, {
Expand All @@ -965,14 +970,13 @@ function uploadFileToCanto(e) {
mode: "no-cors",
redirect: 'follow'
}).then(response => {
statusBar.style.display = "block";
statusBar.innerHTML = "Uploading image...";

document.getElementById("uploadBtn").style.background = "linear-gradient(16deg, rgb(205 101 1) 0%, rgb(169 218 0 / 100%) 100%)";
document.getElementById("uploadBtn").value = "Uploading image...";
}).catch(error => {
console.log(error);
}).finally(() => {
statusBar.innerHTML = "Uploading - This can take several minutes...";
checkStatusInterval(e.files[0].name);
document.getElementById("uploadBtn").value = "Upload complete - processing";
checkStatusInterval(e.currentTarget.files[0].name);
});
}).catch(error => {
console.log("An error occurred while attempting to grab upload settings!");
Expand All @@ -982,7 +986,7 @@ function uploadFileToCanto(e) {
function checkStatusInterval(filename) {
let url = `https://${_tenants}/api/v1/upload/status?hours=1`;
let statusBar = parent.document.querySelector(".modal-status-bar");
statusChecker = setInterval(() => {
setInterval(() => {

fetch(url, {
method: "get",
Expand All @@ -992,14 +996,12 @@ function uploadFileToCanto(e) {
}).then(body => {
if (body.results && body.results.length > 0) {
let results = body.results.filter(e => {
console.log("evaluating: ", e);
if (e.name == filename && e.status != "Done") {
console.log("match!!!");
return e;
}
});
if (results.filter(e => e != undefined).length == 0) {
statusBar.innerHTML = "Canto processing complete! Reloading"
document.getElementById("uploadBtn").value = "Canto processing complete! Reloading";
window.location.reload();
}
}
Expand All @@ -1020,3 +1022,4 @@ if (import.meta.hot) {
console.log("HMR")
});
}

4 changes: 2 additions & 2 deletions src/templates/canto-embed.twig
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
<div id="selectedCountSection" class="selected-count-section hidden"><span id="selected-count">2</span><span> File(s) Selected</span>
</div>
<div style="display: inline-block;">
<input type="button" onClick="uploadClick(this)" id="uploadBtn" value="Upload File"/>
<input onChange="uploadFileToCanto(this);" data-buttonText="Upload File" type="file" id="uploadBtnInvisible"
<input type="button" id="uploadBtn" value="Upload File"/>
<input data-buttonText="Upload File" type="file" id="uploadBtnInvisible"
help-id="upload-button" set-aria="{i:70,d:'upload files',pup:1}"
class="btn-parent btn-default thirdColorText" tabindex="70" aria-label="upload files"
aria-haspopup="true">
Expand Down
1 change: 1 addition & 0 deletions src/web/assets/dist/assets/app-7c0be19c.css

Large diffs are not rendered by default.

Binary file added src/web/assets/dist/assets/app-7c0be19c.css.gz
Binary file not shown.
2 changes: 2 additions & 0 deletions src/web/assets/dist/assets/app-fe94df30.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/web/assets/dist/assets/app-fe94df30.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions src/web/assets/dist/assets/canto-embed-f0b95696.js

Large diffs are not rendered by default.

Binary file not shown.
1 change: 1 addition & 0 deletions src/web/assets/dist/assets/canto-embed-f0b95696.js.map

Large diffs are not rendered by default.

Binary file not shown.
17 changes: 17 additions & 0 deletions src/web/assets/dist/assets/canto-field-ce0b6f6c.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
1 change: 1 addition & 0 deletions src/web/assets/dist/assets/canto-field-ce0b6f6c.js.map

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading