public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH widget-toolkit v2] utils: API2Request: defer masking after layout
@ 2024-03-19  8:51 Dominik Csapak
  2024-03-19 17:07 ` [pve-devel] applied: " Thomas Lamprecht
  0 siblings, 1 reply; 2+ messages in thread
From: Dominik Csapak @ 2024-03-19  8:51 UTC (permalink / raw)
  To: pve-devel

since recently (not sure when exactly), the 'load()' method of the edit
window did not correctly mask the window anymore

the reason seems to be that the API2Request tries to mask the component
before it's rendered, and that did never work correctly.

Instead of simply calling `setLoading`, test if the component is
rendered, and if not, mask it after it has finished it's layout.

Since we cannot guarantee that there is only one API2Request with the
waitMsgTarget set to it, nor that the 'afterlayout' and api call
responses come in a specific order, we count the loads, and only
ever unmask the component when the counter reaches zero again.

Since we're strictly in non-async code here and javascript is
single-threaded, this should not result in a data race.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
changes from v1:
* use a counter for all loads instead of a unique id to keep the loading
  mask until all loads are finished that were started in the meantime
* improve commit message to make the data race sentence correct

 src/Utils.js | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/src/Utils.js b/src/Utils.js
index ff7c1a7..2d4e1dd 100644
--- a/src/Utils.js
+++ b/src/Utils.js
@@ -458,6 +458,12 @@ utilities: {
 	    newopts.url = '/api2/extjs' + newopts.url;
 	}
 	delete newopts.callback;
+	let unmask = (target) => {
+	    if (target.waitMsgTargetCount === undefined || --target.waitMsgTargetCount <= 0) {
+		target.setLoading(false);
+		delete target.waitMsgTargetCount;
+	    }
+	};
 
 	let createWrapper = function(successFn, callbackFn, failureFn) {
 	    Ext.apply(newopts, {
@@ -466,7 +472,7 @@ utilities: {
 			if (Proxmox.Utils.toolkit === 'touch') {
 			    options.waitMsgTarget.setMasked(false);
 			} else {
-			    options.waitMsgTarget.setLoading(false);
+			    unmask(options.waitMsgTarget);
 			}
 		    }
 		    let result = Ext.decode(response.responseText);
@@ -488,7 +494,7 @@ utilities: {
 			if (Proxmox.Utils.toolkit === 'touch') {
 			    options.waitMsgTarget.setMasked(false);
 			} else {
-			    options.waitMsgTarget.setLoading(false);
+			    unmask(options.waitMsgTarget);
 			}
 		    }
 		    response.result = {};
@@ -518,9 +524,16 @@ utilities: {
 	if (target) {
 	    if (Proxmox.Utils.toolkit === 'touch') {
 		target.setMasked({ xtype: 'loadmask', message: newopts.waitMsg });
-	    } else {
-		// Note: ExtJS bug - this does not work when component is not rendered
+	    } else if (target.rendered) {
+		target.waitMsgTargetCount = (target.waitMsgTargetCount ?? 0) + 1;
 		target.setLoading(newopts.waitMsg);
+	    } else {
+		target.waitMsgTargetCount = (target.waitMsgTargetCount ?? 0) + 1;
+		target.on('afterlayout', function() {
+		    if ((target.waitMsgTargetCount ?? 0) > 0) {
+			target.setLoading(newopts.waitMsg);
+		    }
+		}, target, { single: true });
 	    }
 	}
 	Ext.Ajax.request(newopts);
-- 
2.39.2





^ permalink raw reply	[flat|nested] 2+ messages in thread

* [pve-devel] applied: [PATCH widget-toolkit v2] utils: API2Request: defer masking after layout
  2024-03-19  8:51 [pve-devel] [PATCH widget-toolkit v2] utils: API2Request: defer masking after layout Dominik Csapak
@ 2024-03-19 17:07 ` Thomas Lamprecht
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Lamprecht @ 2024-03-19 17:07 UTC (permalink / raw)
  To: Proxmox VE development discussion, Dominik Csapak

On 19/03/2024 09:51, Dominik Csapak wrote:
> since recently (not sure when exactly), the 'load()' method of the edit
> window did not correctly mask the window anymore
> 
> the reason seems to be that the API2Request tries to mask the component
> before it's rendered, and that did never work correctly.
> 
> Instead of simply calling `setLoading`, test if the component is
> rendered, and if not, mask it after it has finished it's layout.
> 
> Since we cannot guarantee that there is only one API2Request with the
> waitMsgTarget set to it, nor that the 'afterlayout' and api call
> responses come in a specific order, we count the loads, and only
> ever unmask the component when the counter reaches zero again.
> 
> Since we're strictly in non-async code here and javascript is
> single-threaded, this should not result in a data race.
> 
> Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
> ---
> changes from v1:
> * use a counter for all loads instead of a unique id to keep the loading
>   mask until all loads are finished that were started in the meantime
> * improve commit message to make the data race sentence correct
> 
>  src/Utils.js | 21 +++++++++++++++++----
>  1 file changed, 17 insertions(+), 4 deletions(-)
> 
>

applied, thanks!




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-03-19 17:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-19  8:51 [pve-devel] [PATCH widget-toolkit v2] utils: API2Request: defer masking after layout Dominik Csapak
2024-03-19 17:07 ` [pve-devel] applied: " Thomas Lamprecht

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal