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

improve the previous fix for overwriting uploads #39

Merged
merged 2 commits into from
Aug 8, 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
4 changes: 2 additions & 2 deletions amigor/composer.lock

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

2 changes: 1 addition & 1 deletion amigor/public/vendor/transmorpher/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"/transmorpher.js": "/transmorpher.js?id=5b7ab84ce745288f338db3682557a717",
"/transmorpher.js": "/transmorpher.js?id=87f85bfe73123b6a5abd7f638bd951ed",
"/transmorpher.css": "/transmorpher.css?id=56dbb0cba726c3e63f1c109f6b9a6f1b",
"/icons/delete.svg": "/icons/delete.svg?id=f88179ccc3649c47f2264315be6c0421",
"/icons/enlargen.svg": "/icons/enlargen.svg?id=9f560ce3f022646dbb826a066715a343",
Expand Down
27 changes: 17 additions & 10 deletions amigor/public/vendor/transmorpher/transmorpher.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ if (!window.transmorpherScriptLoaded) {
} else {
getState(transmorpherIdentifier).then(function (uploadingStateResponse) {
if (uploadingStateResponse.state === 'uploading' || uploadingStateResponse.state === 'processing') {
openUploadConfirmModal(transmorpherIdentifier, createCallbackWithArguments(reserveUploadSlot, transmorpherIdentifier, file.done), uploadingStateResponse.state);
openUploadConfirmModal(transmorpherIdentifier, createCallbackWithArguments(reserveUploadSlot, transmorpherIdentifier, file.done));
} else {
reserveUploadSlot(transmorpherIdentifier, file.done);
}
Expand Down Expand Up @@ -291,8 +291,9 @@ if (!window.transmorpherScriptLoaded) {
displayUploadResult(response, transmorpherIdentifier, uploadToken);
}

// Fixes undefined state after first upload.
document.querySelector("#dz-".concat(transmorpherIdentifier)).dropzone.removeAllFiles();
// Remove the uploaded file to reset the state.
var dropzone = document.querySelector("#dz-".concat(transmorpherIdentifier)).dropzone;
dropzone.removeFile(dropzone.files[0]);
};
window.displayUploadResult = function (uploadResult, transmorpherIdentifier, uploadToken) {
resetAgeElement(transmorpherIdentifier);
Expand Down Expand Up @@ -415,7 +416,7 @@ if (!window.transmorpherScriptLoaded) {
window.setVersion = function (transmorpherIdentifier, version) {
getState(transmorpherIdentifier).then(function (uploadingStateResponse) {
if (uploadingStateResponse.state === 'uploading' || uploadingStateResponse.state === 'processing') {
openUploadConfirmModal(transmorpherIdentifier, createCallbackWithArguments(makeSetVersionCall, transmorpherIdentifier, version), uploadingStateResponse.state);
openUploadConfirmModal(transmorpherIdentifier, createCallbackWithArguments(makeSetVersionCall, transmorpherIdentifier, version));
} else {
makeSetVersionCall(transmorpherIdentifier, version);
}
Expand Down Expand Up @@ -610,7 +611,7 @@ if (!window.transmorpherScriptLoaded) {
}
return date.toLocaleString();
};
window.openUploadConfirmModal = function (transmorpherIdentifier, callback, uploadState) {
window.openUploadConfirmModal = function (transmorpherIdentifier, callback) {
var modal = document.querySelector("#modal-uc-".concat(transmorpherIdentifier));
var dropzone = document.querySelector("#dz-".concat(transmorpherIdentifier)).dropzone;
var previewElement = document.querySelector("#dz-".concat(transmorpherIdentifier, " .dz-preview ~ .dz-preview"));
Expand All @@ -620,12 +621,18 @@ if (!window.transmorpherScriptLoaded) {
var _dropzone$files$;
previewElement ? previewElement.style.display = 'block' : null;
document.querySelector("#modal-uc-".concat(transmorpherIdentifier)).classList.remove('d-flex');
if (dropzone.files[1] != null) {

// If there is an upload in progress, remove it.
if (((_dropzone$files$ = dropzone.files[0]) === null || _dropzone$files$ === void 0 ? void 0 : _dropzone$files$.status) === 'uploading') {
// If a version was restored, show the default message.
if (!dropzone.files[1]) {
document.querySelector("#dz-".concat(transmorpherIdentifier, " .dz-default")).style.display = 'block';
}
dropzone.removeFile(dropzone.files[0]);
} else if (uploadState !== 'processing' && (dropzone === null || dropzone === void 0 || (_dropzone$files$ = dropzone.files[0]) === null || _dropzone$files$ === void 0 ? void 0 : _dropzone$files$.status) !== dropzone__WEBPACK_IMPORTED_MODULE_0__["default"].ADDED) {
// This happens when the dropzone state was reset while initializing.
displayState(transmorpherIdentifier, 'error', media[transmorpherIdentifier].translations['upload_aborted']);
return;
} else if (dropzone.files[0]) {
// If the file is not uploading, the overwrite button was clicked after finishing the upload. Display the progressbar.
document.querySelector("#dz-".concat(transmorpherIdentifier, " .dz-default")).style.display = 'none';
previewElement ? previewElement.style.display = 'block' : null;
}
callback();
};
Expand Down
2 changes: 1 addition & 1 deletion dist/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"/transmorpher.js": "/transmorpher.js?id=5b7ab84ce745288f338db3682557a717",
"/transmorpher.js": "/transmorpher.js?id=87f85bfe73123b6a5abd7f638bd951ed",
"/transmorpher.css": "/transmorpher.css?id=56dbb0cba726c3e63f1c109f6b9a6f1b",
"/icons/delete.svg": "/icons/delete.svg?id=f88179ccc3649c47f2264315be6c0421",
"/icons/enlargen.svg": "/icons/enlargen.svg?id=9f560ce3f022646dbb826a066715a343",
Expand Down
27 changes: 17 additions & 10 deletions dist/transmorpher.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ if (!window.transmorpherScriptLoaded) {
} else {
getState(transmorpherIdentifier).then(function (uploadingStateResponse) {
if (uploadingStateResponse.state === 'uploading' || uploadingStateResponse.state === 'processing') {
openUploadConfirmModal(transmorpherIdentifier, createCallbackWithArguments(reserveUploadSlot, transmorpherIdentifier, file.done), uploadingStateResponse.state);
openUploadConfirmModal(transmorpherIdentifier, createCallbackWithArguments(reserveUploadSlot, transmorpherIdentifier, file.done));
} else {
reserveUploadSlot(transmorpherIdentifier, file.done);
}
Expand Down Expand Up @@ -291,8 +291,9 @@ if (!window.transmorpherScriptLoaded) {
displayUploadResult(response, transmorpherIdentifier, uploadToken);
}

// Fixes undefined state after first upload.
document.querySelector("#dz-".concat(transmorpherIdentifier)).dropzone.removeAllFiles();
// Remove the uploaded file to reset the state.
var dropzone = document.querySelector("#dz-".concat(transmorpherIdentifier)).dropzone;
dropzone.removeFile(dropzone.files[0]);
};
window.displayUploadResult = function (uploadResult, transmorpherIdentifier, uploadToken) {
resetAgeElement(transmorpherIdentifier);
Expand Down Expand Up @@ -415,7 +416,7 @@ if (!window.transmorpherScriptLoaded) {
window.setVersion = function (transmorpherIdentifier, version) {
getState(transmorpherIdentifier).then(function (uploadingStateResponse) {
if (uploadingStateResponse.state === 'uploading' || uploadingStateResponse.state === 'processing') {
openUploadConfirmModal(transmorpherIdentifier, createCallbackWithArguments(makeSetVersionCall, transmorpherIdentifier, version), uploadingStateResponse.state);
openUploadConfirmModal(transmorpherIdentifier, createCallbackWithArguments(makeSetVersionCall, transmorpherIdentifier, version));
} else {
makeSetVersionCall(transmorpherIdentifier, version);
}
Expand Down Expand Up @@ -610,7 +611,7 @@ if (!window.transmorpherScriptLoaded) {
}
return date.toLocaleString();
};
window.openUploadConfirmModal = function (transmorpherIdentifier, callback, uploadState) {
window.openUploadConfirmModal = function (transmorpherIdentifier, callback) {
var modal = document.querySelector("#modal-uc-".concat(transmorpherIdentifier));
var dropzone = document.querySelector("#dz-".concat(transmorpherIdentifier)).dropzone;
var previewElement = document.querySelector("#dz-".concat(transmorpherIdentifier, " .dz-preview ~ .dz-preview"));
Expand All @@ -620,12 +621,18 @@ if (!window.transmorpherScriptLoaded) {
var _dropzone$files$;
previewElement ? previewElement.style.display = 'block' : null;
document.querySelector("#modal-uc-".concat(transmorpherIdentifier)).classList.remove('d-flex');
if (dropzone.files[1] != null) {

// If there is an upload in progress, remove it.
if (((_dropzone$files$ = dropzone.files[0]) === null || _dropzone$files$ === void 0 ? void 0 : _dropzone$files$.status) === 'uploading') {
// If a version was restored, show the default message.
if (!dropzone.files[1]) {
document.querySelector("#dz-".concat(transmorpherIdentifier, " .dz-default")).style.display = 'block';
}
dropzone.removeFile(dropzone.files[0]);
} else if (uploadState !== 'processing' && (dropzone === null || dropzone === void 0 || (_dropzone$files$ = dropzone.files[0]) === null || _dropzone$files$ === void 0 ? void 0 : _dropzone$files$.status) !== dropzone__WEBPACK_IMPORTED_MODULE_0__["default"].ADDED) {
// This happens when the dropzone state was reset while initializing.
displayState(transmorpherIdentifier, 'error', media[transmorpherIdentifier].translations['upload_aborted']);
return;
} else if (dropzone.files[0]) {
// If the file is not uploading, the overwrite button was clicked after finishing the upload. Display the progressbar.
document.querySelector("#dz-".concat(transmorpherIdentifier, " .dz-default")).style.display = 'none';
previewElement ? previewElement.style.display = 'block' : null;
}
callback();
};
Expand Down
1 change: 0 additions & 1 deletion src/lang/en/dropzone.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
'success' => 'Success',
'uploading' => 'Uploading',
'upload_canceled' => 'Upload canceled',
'upload_aborted' => 'Error, please try again.',
'validation_error' => 'There was an error when trying to validate media dimensions.',
'video_in_process' => 'A video is currently uploading or processing, do you want to overwrite it?',
'html_video_not_supported' => 'Your browser doesn\'t support HTML video. Here is a link to the video instead.'
Expand Down
27 changes: 16 additions & 11 deletions src/resources/js/transmorpher.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ if (!window.transmorpherScriptLoaded) {
openUploadConfirmModal(
transmorpherIdentifier,
createCallbackWithArguments(reserveUploadSlot, transmorpherIdentifier, file.done),
uploadingStateResponse.state
);
} else {
reserveUploadSlot(transmorpherIdentifier, file.done);
Expand Down Expand Up @@ -284,9 +283,9 @@ if (!window.transmorpherScriptLoaded) {
displayUploadResult(response, transmorpherIdentifier, uploadToken);
}


// Fixes undefined state after first upload.
document.querySelector(`#dz-${transmorpherIdentifier}`).dropzone.removeAllFiles();
// Remove the uploaded file to reset the state.
let dropzone = document.querySelector(`#dz-${transmorpherIdentifier}`).dropzone;
dropzone.removeFile(dropzone.files[0]);
}

window.displayUploadResult = function (uploadResult, transmorpherIdentifier, uploadToken) {
Expand Down Expand Up @@ -421,7 +420,7 @@ if (!window.transmorpherScriptLoaded) {
window.setVersion = function (transmorpherIdentifier, version) {
getState(transmorpherIdentifier).then(uploadingStateResponse => {
if (uploadingStateResponse.state === 'uploading' || uploadingStateResponse.state === 'processing') {
openUploadConfirmModal(transmorpherIdentifier, createCallbackWithArguments(makeSetVersionCall, transmorpherIdentifier, version), uploadingStateResponse.state);
openUploadConfirmModal(transmorpherIdentifier, createCallbackWithArguments(makeSetVersionCall, transmorpherIdentifier, version));
} else {
makeSetVersionCall(transmorpherIdentifier, version);
}
Expand Down Expand Up @@ -641,7 +640,7 @@ if (!window.transmorpherScriptLoaded) {
return date.toLocaleString();
}

window.openUploadConfirmModal = function (transmorpherIdentifier, callback, uploadState) {
window.openUploadConfirmModal = function (transmorpherIdentifier, callback) {
let modal = document.querySelector(`#modal-uc-${transmorpherIdentifier}`);
let dropzone = document.querySelector(`#dz-${transmorpherIdentifier}`).dropzone;
let previewElement = document.querySelector(`#dz-${transmorpherIdentifier} .dz-preview ~ .dz-preview`);
Expand All @@ -653,12 +652,18 @@ if (!window.transmorpherScriptLoaded) {
previewElement ? previewElement.style.display = 'block' : null;
document.querySelector(`#modal-uc-${transmorpherIdentifier}`).classList.remove('d-flex');

if (dropzone.files[1] != null) {
// If there is an upload in progress, remove it.
if (dropzone.files[0]?.status === 'uploading') {
// If a version was restored, show the default message.
if (!dropzone.files[1]) {
document.querySelector(`#dz-${transmorpherIdentifier} .dz-default`).style.display = 'block';
}

dropzone.removeFile(dropzone.files[0]);
} else if (uploadState !== 'processing' && dropzone?.files[0]?.status !== Dropzone.ADDED) {
// This happens when the dropzone state was reset while initializing.
displayState(transmorpherIdentifier, 'error', media[transmorpherIdentifier].translations['upload_aborted']);
return;
} else if (dropzone.files[0]) {
// If the file is not uploading, the overwrite button was clicked after finishing the upload. Display the progressbar.
document.querySelector(`#dz-${transmorpherIdentifier} .dz-default`).style.display = 'none';
previewElement ? previewElement.style.display = 'block' : null;
}

callback();
Expand Down