Skip to content

Commit ab6843f

Browse files
SW-724 drop upload either in working area or in design lib directly 2 (mrbeam#1421)
* Make inlineStyle method accessible globally * Add mutation observer to show spinner in WA
1 parent f811dc9 commit ab6843f

File tree

4 files changed

+31
-5
lines changed

4 files changed

+31
-5
lines changed

octoprint_mrbeam/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,7 @@ def get_assets(self):
611611
assets = dict(
612612
js=[
613613
"js/helpers/quick_shape_helper.js",
614+
"js/helpers/element_helper.js",
614615
"js/helpers/debug_rendering_helper.js",
615616
"js/helpers/working_area_helper.js",
616617
"js/lib/jquery.tinycolorpicker.js",
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
(function ($) {
2+
$.fn.inlineStyle = function (prop) {
3+
return this.prop("style")[$.camelCase(prop)];
4+
};
5+
})(jQuery);

octoprint_mrbeam/static/js/mother_viewmodel.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,31 @@ $(function () {
328328
self.state._processProgressData = function () {};
329329
};
330330

331+
// Mutation Observer to show a spinner in working area when file upload is in progress
332+
// since there are no events detecting the start of a the file upload process
333+
const uploadProgressMutationNode = document.getElementById("gcode_upload_progress");
334+
const uploadProgressMutationConfig = {
335+
childList: true,
336+
attributes: true,
337+
subtree: true,
338+
};
339+
const uploadProgressMutationCallback = function (mutationsList, uploadProgressObserver) {
340+
for (let mutation of mutationsList) {
341+
if (OctoPrint.coreui.selectedTab === "#workingarea") {
342+
let width = $(mutation.target).inlineStyle("width");
343+
if (width === "0%") {
344+
$("body").removeClass("activitySpinnerActive");
345+
} else {
346+
$("body").addClass("activitySpinnerActive");
347+
}
348+
}
349+
}
350+
};
351+
const uploadProgressObserver = new MutationObserver(uploadProgressMutationCallback);
352+
uploadProgressObserver.observe(uploadProgressMutationNode, uploadProgressMutationConfig);
353+
// End of Mutation Observer
354+
355+
331356
// event fired (once for each file) after onEventFileAdded, but only on upload (not on filecopy)
332357
self.onEventUpload = async function (payload) {
333358
// if tab workingarea, place it there (assuming tabs did not change during upload)

octoprint_mrbeam/static/js/mrbeam.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -673,11 +673,6 @@ $(function () {
673673
const mutationCallback = function (mutationsList, observer) {
674674
for (let mutation of mutationsList) {
675675
if (mutation.type === "childList") {
676-
(function ($) {
677-
$.fn.inlineStyle = function (prop) {
678-
return this.prop("style")[$.camelCase(prop)];
679-
};
680-
})(jQuery);
681676
let modalElement = $(".modal-scrollable");
682677
let backDrop = $(".modal-backdrop");
683678
if (modalElement.length !== 0) {

0 commit comments

Comments
 (0)