Skip to content

Commit

Permalink
feat: added loading of taipy-gui libraries from bundle folder #27
Browse files Browse the repository at this point in the history
  • Loading branch information
GhilesHideur committed May 6, 2024
1 parent 4fb0ae0 commit a35422b
Show file tree
Hide file tree
Showing 13 changed files with 115 additions and 391 deletions.
9 changes: 3 additions & 6 deletions back_end/common/template_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def get_version(cls, root_dir: str) -> str:
return "" # debug mode

@classmethod
def render_template(cls, root_dir: str, xprjson_path: str, file_name: str) -> str:
def render_template(cls, root_dir: str, xprjson_path: str) -> str:
"""
Generates the dashboard HTML content by dynamically injecting configuration data
from a JSON file into the dashboard's template HTML.
Expand All @@ -48,9 +48,6 @@ def render_template(cls, root_dir: str, xprjson_path: str, file_name: str) -> st
- xprjson_path (str): The filesystem path to the configuration JSON file. This file
contains the configuration data to be injected into the dashboard
template.
- file_name (str): The base name of the template HTML file.
The method dynamically appends the version number obtained from
`get_version` method to this base name to locate the final template file.
- root_dir (Path): The root directory path where the index HTML file is located. This
path is also set as the base directory for the application.
Expand All @@ -63,12 +60,12 @@ def render_template(cls, root_dir: str, xprjson_path: str, file_name: str) -> st
with open(xprjson_path, "r") as config_file:
config_data = json.load(config_file)

index_view_path: Path = root_dir / f"{file_name}{VERSION}.html"
index_view_path: Path = Path(root_dir) / f"index-view{VERSION}.html"

with open(index_view_path, "r") as template_file:
template_data: str = template_file.read()

template_data_with_config: str = template_data.replace(
template_data_with_config = template_data.replace(
"jsonContent = {};", f"jsonContent = {json.dumps(config_data)};"
)

Expand Down
2 changes: 1 addition & 1 deletion back_end/render/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def add_cors_headers(response: Response) -> Response:
def static_files(path: str) -> Any:
if path == "" or path.endswith("/"):
return TemplateUtils.render_template(
RenderApp.BASE_DIR, RenderApp.XPRJSON_PATH, "index-view"
RenderApp.BASE_DIR, RenderApp.XPRJSON_PATH
)
return send_from_directory(str(RenderApp.BASE_DIR), path)

Expand Down
20 changes: 15 additions & 5 deletions back_end/taipy/resource_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
# specific language governing permissions and limitations under the License.


from pathlib import Path
import typing as t
from flask import send_from_directory
import os
from pathlib import Path
from flask import send_file, send_from_directory
from taipy.gui.custom import ResourceHandler
from ..common import TemplateUtils

Expand Down Expand Up @@ -43,13 +44,22 @@ def get_resources(self, path: str, base_bundle_path: str) -> t.Any:
return send_from_directory(root_dir, "index.html")
xprjson_path: Path = (Path.cwd() / self.xprjson_file_name).resolve()
if xprjson_path.is_file():
return TemplateUtils.render_template(
root_dir, xprjson_path, "index-taipy-view"
)
return TemplateUtils.render_template(root_dir, xprjson_path)

# Serve the requested file if it exists
file_path: Path = root_dir / path
if file_path.is_file():
return send_from_directory(root_dir, path)

if any(
substring in path
for substring in [
"shared.taipy-gui-base.js",
"taipy-gui-base.js",
"preview.taipy-gui-base.js",
]
):
file_path = Path(base_bundle_path) / os.path.basename(path)
return send_file(file_path, mimetype="application/javascript")

return ("File not found", 404)
8 changes: 2 additions & 6 deletions front-end/gulpFiles/JsFiles.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@
"thirdparty/marked.min.js",
"thirdparty/jquery.bt.js",
"thirdparty/moment.min.js",
"thirdparty/daterangepicker.js",
"source/connectors/taipy/shared.taipy-gui-base.js",
"source/connectors/taipy/preview.taipy-gui-base.js"
"thirdparty/daterangepicker.js"
],
"body": [
"source/kernel/utils/geoConversion.js",
Expand Down Expand Up @@ -294,9 +292,7 @@
"source/kernel/general/backend/FileMngr.js",
"thirdparty/json_parseMore.js",
"thirdparty/marked.min.js",
"thirdparty/daterangepicker.js",
"source/connectors/taipy/shared.taipy-gui-base.js",
"source/connectors/taipy/taipy-gui-base.js"
"thirdparty/daterangepicker.js"
],
"body": [
"source/kernel/datanodes/execution-engine/DatanodeDependency.js",
Expand Down
Loading

0 comments on commit a35422b

Please sign in to comment.