From 8ce44bc0fcbf225dd1dffc36abc6639cead2b08c Mon Sep 17 00:00:00 2001 From: Jordan Blasenhauer Date: Mon, 19 Aug 2024 18:03:13 +0200 Subject: [PATCH] cache page done + build all base pages --- src/ui/client/build.py | 5 +- src/ui/client/builder/pages/cache.py | 32 +++ src/ui/client/builder/pages/utils/widgets.py | 41 +++ src/ui/client/builder/test_cache.py | 21 ++ .../dashboard/components/Builder/Cache.vue | 70 +++++ .../dashboard/components/Icons/Folder.vue | 56 ++++ .../components/Widget/FileManager.vue | 126 ++++++++ .../dashboard/components/Widget/Icons.vue | 2 + .../dashboard/components/Widget/Modal.vue | 27 ++ src/ui/client/dashboard/lang/fr.json | 269 ++++++++++++++---- src/ui/client/dashboard/pages/cache/Cache.vue | 37 +++ src/ui/client/dashboard/pages/cache/cache.js | 11 + .../client/dashboard/pages/cache/index.html | 28 ++ src/ui/client/input.css | 109 +++---- src/ui/client/public/css/style.css | 2 +- src/ui/client/vite.config.dashboard.js | 8 +- 16 files changed, 714 insertions(+), 130 deletions(-) create mode 100644 src/ui/client/builder/pages/cache.py create mode 100644 src/ui/client/builder/test_cache.py create mode 100644 src/ui/client/dashboard/components/Builder/Cache.vue create mode 100644 src/ui/client/dashboard/components/Icons/Folder.vue create mode 100644 src/ui/client/dashboard/components/Widget/FileManager.vue create mode 100644 src/ui/client/dashboard/pages/cache/Cache.vue create mode 100644 src/ui/client/dashboard/pages/cache/cache.js create mode 100644 src/ui/client/dashboard/pages/cache/index.html diff --git a/src/ui/client/build.py b/src/ui/client/build.py index 33a0c11ba..862a1a20c 100644 --- a/src/ui/client/build.py +++ b/src/ui/client/build.py @@ -65,6 +65,8 @@ def create_dir(directory: Path): def create_base_dirs(): """Create the base directories we will need to build front end and add them to flask app""" create_dir(opt_dir_dashboard) + create_dir(ui_dir_static) + create_dir(ui_dir_templates) def move_template(folder: Path, target_folder: Path): @@ -168,7 +170,8 @@ def build(): """All steps to build the front end and set it to the flask app""" reset() create_base_dirs() - add_legacy() + # add_legacy() + # Only install packages if not already installed if not current_directory.joinpath("node_modules").exists(): if run_command(["/usr/bin/npm", "install"], current_directory): diff --git a/src/ui/client/builder/pages/cache.py b/src/ui/client/builder/pages/cache.py new file mode 100644 index 000000000..f723f36b0 --- /dev/null +++ b/src/ui/client/builder/pages/cache.py @@ -0,0 +1,32 @@ +from .utils.widgets import file_manager_widget, title_widget, subtitle_widget, unmatch_widget +from typing import Optional + + +def fallback_message(msg: str, display: Optional[list] = None) -> dict: + + return { + "type": "void", + "display": display if display else [], + "widgets": [ + unmatch_widget(text=msg), + ], + } + + +def cache_builder(file_manager: Optional[dict] = None) -> str: + + if file_manager is None or (isinstance(file_manager, dict) and len(file_manager) == 0): + return [fallback_message("cache_not_found")] + + return [ + { + "type": "card", + "widgets": [ + title_widget("cache_title"), # keep it (a18n) + subtitle_widget("cache_subtitle"), # keep it (a18n) + file_manager_widget( + data=file_manager, + ), + ], + }, + ] diff --git a/src/ui/client/builder/pages/utils/widgets.py b/src/ui/client/builder/pages/utils/widgets.py index a2529748a..c2fbdc2ce 100644 --- a/src/ui/client/builder/pages/utils/widgets.py +++ b/src/ui/client/builder/pages/utils/widgets.py @@ -875,6 +875,47 @@ def fields_widget( return { "type" : "Fields", "data" : data } +def file_manager_widget( + data: dict, + baseFolder: str = "base", + columns: dict = {"pc":"12","tablet":"12","mobile":"12"}, + containerClass: str = "" + ): + """ + File manager component. Useful with cache page. + + PARAMETERS + + - `data` **Object** Can be a translation key or by default raw text. + - `baseFolder` **String** The base folder to display by default (optional, default `"base"`) + - `columns` **Object** Work with grid system { pc: 12, tablet: 12, mobile: 12} (optional, default `{"pc":"12","tablet":"12","mobile":"12"}`) + - `containerClass` **String** Additional class (optional, default `""`) + + EXAMPLE + + { + title: "Total Users", + type: "card", + titleClass: "text-lg", + color : "info", + tag: "h2" + } + + """ + + data = { + "data" : data, + } + + + # List of params that will be add only if not default value + list_params = [("baseFolder", baseFolder, "base"),("columns", columns, {"pc":"12","tablet":"12","mobile":"12"}),("containerClass", containerClass, "")] + for param in list_params: + add_key_value(data, param[0], param[1], param[2]) + + return { "type" : "Filemanager", "data" : data } + + def filter_widget( filters: Optional[list] = None, data: Union[dict, list] = {}, diff --git a/src/ui/client/builder/test_cache.py b/src/ui/client/builder/test_cache.py new file mode 100644 index 000000000..ce03105de --- /dev/null +++ b/src/ui/client/builder/test_cache.py @@ -0,0 +1,21 @@ +from utils import save_builder +from pages.cache import cache_builder + +# parents is parent folders +# children can be either files or folders +file_manager = { + # always need a root, this is the first folder display + "base": {"parents": [], "children": ["certificates", "configs", "test"], "type": "folder"}, + "certificates": {"parents": ["base"], "children": ["cert-1"], "type": "folder"}, + "cert-1": {"parents": ["base", "certificates"], "children": [], "type": "file", "downloadEndpoint": "/download/cert-1"}, + "configs": {"parents": ["base"], "children": ["config-1"], "type": "folder"}, + "config-1": {"parents": ["base", "configs"], "children": [], "type": "file", "downloadEndpoint": "/download/cert-1"}, + "test": {"parents": ["base"], "children": ["test-1"], "type": "folder"}, + "test-1": {"parents": ["base", "test"], "children": ["test-2"], "type": "folder", "downloadEndpoint": "/download/cert-1"}, + "test-2": {"parents": ["base", "test", "test-1"], "children": [], "type": "file", "downloadEndpoint": "/download/cert-1"}, +} + + +builder = cache_builder(file_manager=file_manager) + +save_builder(page_name="cache", output=builder, script_name="cache") diff --git a/src/ui/client/dashboard/components/Builder/Cache.vue b/src/ui/client/dashboard/components/Builder/Cache.vue new file mode 100644 index 000000000..1ca56233f --- /dev/null +++ b/src/ui/client/dashboard/components/Builder/Cache.vue @@ -0,0 +1,70 @@ + + +