Browse Source

Update Frontend Decouple (#799)

* Update Frontend Decoupld

* per Fabien

* Update frontend/taipy-gui/base/src/app.ts

Co-authored-by: Fabien Lelaquais <86590727+FabienLelaquais@users.noreply.github.com>

* Update frontend/taipy-gui/base/src/app.ts

Co-authored-by: Fabien Lelaquais <86590727+FabienLelaquais@users.noreply.github.com>

---------

Co-authored-by: Fabien Lelaquais <86590727+FabienLelaquais@users.noreply.github.com>
dinhlongnguyen 1 năm trước cách đây
mục cha
commit
637f48bd5f
3 tập tin đã thay đổi với 16 bổ sung9 xóa
  1. 14 4
      frontend/taipy-gui/base/src/app.ts
  2. 1 1
      taipy/gui/custom/_page.py
  3. 1 4
      taipy/gui/server.py

+ 14 - 4
frontend/taipy-gui/base/src/app.ts

@@ -1,4 +1,5 @@
 import { sendWsMessage } from "../../src/context/wsUtils";
+import { uploadFile } from "../../src/workers/fileupload";
 
 import { Socket, io } from "socket.io-client";
 import { VariableManager } from "./variableManager";
@@ -39,9 +40,9 @@ export class TaipyApp {
     }
     set onInit(handler: OnInitHandler | undefined) {
         if (handler !== undefined && handler?.length !== 1) {
-            throw new Error("onInit function requires 1 parameter")
+            throw new Error("onInit() requires one parameter");
         }
-        this._onInit = handler
+        this._onInit = handler;
     }
 
     get onChange() {
@@ -49,9 +50,9 @@ export class TaipyApp {
     }
     set onChange(handler: OnChangeHandler | undefined) {
         if (handler !== undefined && handler?.length !== 3) {
-            throw new Error("onChange function requires 3 parameters")
+            throw new Error("onChange() requires three parameters");
         }
-        this._onChange = handler
+        this._onChange = handler;
     }
 
     // Public methods
@@ -95,6 +96,15 @@ export class TaipyApp {
         }
         sendWsMessage(this.socket, "GMC", "get_module_context", { path: path }, this.clientId);
     }
+
+    trigger(actionName: string, triggerId: string, payload: Record<string, unknown> = {}) {
+        payload["action"] = actionName;
+        sendWsMessage(this.socket, "A", triggerId, payload, this.clientId, this.context);
+    }
+
+    upload(encodedName: string, files: FileList, progressCallback: (val: number) => void) {
+        return uploadFile(encodedName, files, progressCallback, this.clientId);
+    }
 }
 
 export const createApp = (onInit?: OnInitHandler, onChange?: OnChangeHandler, path?: string, socket?: Socket) => {

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

@@ -48,7 +48,7 @@ class ResourceHandler(ABC):
         return self.id if id != "" else str(id(self))
 
     @abstractmethod
-    def get_resources(self, path: str, base_bundle_path: str) -> t.Any:
+    def get_resources(self, path: str, taipy_resource_path: str) -> t.Any:
         raise NotImplementedError
 
 

+ 1 - 4
taipy/gui/server.py

@@ -49,7 +49,6 @@ class _Server:
     __OPENING_CURLY = r"\1&#x7B;"
     __CLOSING_CURLY = r"&#x7D;\2"
     _RESOURCE_HANDLER_ARG = "tprh"
-    __BASE_FILE_NAME = "taipy-gui-base.js"
 
     def __init__(
         self,
@@ -158,9 +157,7 @@ class _Server:
                 if resource_handler is None:
                     return (f"Invalid value for query {_Server._RESOURCE_HANDLER_ARG}", 404)
                 try:
-                    return resource_handler.get_resources(
-                        path, f"{static_folder}{os.path.sep}{_Server.__BASE_FILE_NAME}"
-                    )
+                    return resource_handler.get_resources(path, static_folder)
                 except Exception as e:
                     raise RuntimeError("Can't get resources from custom resource handler") from e
             if path == "" or path == "index.html" or "." not in path: