Ver código fonte

root page decouple (#1443)

* root page decouple

* fix resource_handler id
Dinh Long Nguyen 11 meses atrás
pai
commit
013faf93ec
3 arquivos alterados com 10 adições e 5 exclusões
  1. 1 1
      frontend/taipy-gui/base/src/app.ts
  2. 2 2
      taipy/gui/custom/_page.py
  3. 7 2
      taipy/gui/gui.py

+ 1 - 1
frontend/taipy-gui/base/src/app.ts

@@ -162,7 +162,7 @@ export class TaipyApp {
         if (!path || path === "") {
         if (!path || path === "") {
             path = window.location.pathname.slice(1);
             path = window.location.pathname.slice(1);
         }
         }
-        sendWsMessage(this.socket, "GMC", "get_module_context", { path: path }, this.clientId);
+        sendWsMessage(this.socket, "GMC", "get_module_context", { path: path || "/" }, this.clientId);
     }
     }
 
 
     trigger(actionName: string, triggerId: string, payload: Record<string, unknown> = {}) {
     trigger(actionName: string, triggerId: string, payload: Record<string, unknown> = {}) {

+ 2 - 2
taipy/gui/custom/_page.py

@@ -46,13 +46,13 @@ class ResourceHandler(ABC):
     User can implement this class to provide custom resources for the custom pages
     User can implement this class to provide custom resources for the custom pages
     """
     """
 
 
-    id: str = ""
+    rh_id: str = ""
 
 
     def __init__(self) -> None:
     def __init__(self) -> None:
         _ExternalResourceHandlerManager().register(self)
         _ExternalResourceHandlerManager().register(self)
 
 
     def get_id(self) -> str:
     def get_id(self) -> str:
-        return self.id if id != "" else str(id(self))
+        return self.rh_id if self.rh_id != "" else str(id(self))
 
 
     @abstractmethod
     @abstractmethod
     def get_resources(self, path: str, taipy_resource_path: str) -> t.Any:
     def get_resources(self, path: str, taipy_resource_path: str) -> t.Any:

+ 7 - 2
taipy/gui/gui.py

@@ -1111,10 +1111,13 @@ class Gui:
 
 
     def __handle_ws_get_module_context(self, payload: t.Any):
     def __handle_ws_get_module_context(self, payload: t.Any):
         if isinstance(payload, dict):
         if isinstance(payload, dict):
+            page_path = str(payload.get("path"))
+            if page_path in {"/", ""}:
+                page_path = Gui.__root_page_name
             # Get Module Context
             # Get Module Context
-            if mc := self._get_page_context(str(payload.get("path"))):
+            if mc := self._get_page_context(page_path):
                 self._bind_custom_page_variables(
                 self._bind_custom_page_variables(
-                    self._get_page(str(payload.get("path")))._renderer, self._get_client_id()
+                    self._get_page(page_path)._renderer, self._get_client_id()
                 )
                 )
                 self.__send_ws(
                 self.__send_ws(
                     {
                     {
@@ -2149,6 +2152,8 @@ class Gui:
 
 
     def _bind_custom_page_variables(self, page: CustomPage, client_id: t.Optional[str]):
     def _bind_custom_page_variables(self, page: CustomPage, client_id: t.Optional[str]):
         """Handle the bindings of custom page variables"""
         """Handle the bindings of custom page variables"""
+        if not isinstance(page, CustomPage):
+            return
         with self.get_flask_app().app_context() if has_app_context() else contextlib.nullcontext():  # type: ignore[attr-defined]
         with self.get_flask_app().app_context() if has_app_context() else contextlib.nullcontext():  # type: ignore[attr-defined]
             self.__set_client_id_in_context(client_id)
             self.__set_client_id_in_context(client_id)
             with self._set_locals_context(page._get_module_name()):
             with self._set_locals_context(page._get_module_name()):