From 89f140dd0505b967c116b3a91576c15beea7b036 Mon Sep 17 00:00:00 2001 From: Alzpetka Date: Wed, 1 Nov 2023 12:50:51 +0100 Subject: [PATCH 1/3] components refactor --- oarepo_ui/resources/templating.py | 21 +++++++++++++++---- .../templates/{ => components}/Array.jinja | 0 .../{ => components}/DefinitionLink.jinja | 0 .../templates/{ => components}/EditForm.jinja | 0 .../templates/{ => components}/Field.jinja | 0 .../templates/components/Multilingual.jinja | 16 ++++++++++++++ .../{ => components}/SearchLink.jinja | 0 .../{ => components}/SidebarApiLinks.jinja | 0 .../templates/{ => components}/URL.jinja | 2 +- .../templates/{ => components}/Value.jinja | 0 10 files changed, 34 insertions(+), 5 deletions(-) rename oarepo_ui/templates/{ => components}/Array.jinja (100%) rename oarepo_ui/templates/{ => components}/DefinitionLink.jinja (100%) rename oarepo_ui/templates/{ => components}/EditForm.jinja (100%) rename oarepo_ui/templates/{ => components}/Field.jinja (100%) create mode 100644 oarepo_ui/templates/components/Multilingual.jinja rename oarepo_ui/templates/{ => components}/SearchLink.jinja (100%) rename oarepo_ui/templates/{ => components}/SidebarApiLinks.jinja (100%) rename oarepo_ui/templates/{ => components}/URL.jinja (91%) rename oarepo_ui/templates/{ => components}/Value.jinja (100%) diff --git a/oarepo_ui/resources/templating.py b/oarepo_ui/resources/templating.py index f8b416a2..21713124 100644 --- a/oarepo_ui/resources/templating.py +++ b/oarepo_ui/resources/templating.py @@ -1,6 +1,6 @@ from jinja2 import Environment from jinja2.loaders import BaseLoader - +import os class RegistryLoader(BaseLoader): def __init__(self, parent_loader) -> None: @@ -57,6 +57,19 @@ def id_filter(x): return id(x) -def to_dict(value=None): - if value: - return value +def get_components(): + + component_data = [] + directory = os.path.dirname(os.path.abspath(__file__ or '')) + parent_directory = os.path.dirname(directory) + components_directory = os.path.join(parent_directory, 'templates', 'components') + + + file_names = os.listdir(components_directory) + + for file_name in file_names: + component_data.append({"key": file_name.replace(".jinja", "").lower(), "component": file_name.replace(".jinja", "")}) + + + return component_data + diff --git a/oarepo_ui/templates/Array.jinja b/oarepo_ui/templates/components/Array.jinja similarity index 100% rename from oarepo_ui/templates/Array.jinja rename to oarepo_ui/templates/components/Array.jinja diff --git a/oarepo_ui/templates/DefinitionLink.jinja b/oarepo_ui/templates/components/DefinitionLink.jinja similarity index 100% rename from oarepo_ui/templates/DefinitionLink.jinja rename to oarepo_ui/templates/components/DefinitionLink.jinja diff --git a/oarepo_ui/templates/EditForm.jinja b/oarepo_ui/templates/components/EditForm.jinja similarity index 100% rename from oarepo_ui/templates/EditForm.jinja rename to oarepo_ui/templates/components/EditForm.jinja diff --git a/oarepo_ui/templates/Field.jinja b/oarepo_ui/templates/components/Field.jinja similarity index 100% rename from oarepo_ui/templates/Field.jinja rename to oarepo_ui/templates/components/Field.jinja diff --git a/oarepo_ui/templates/components/Multilingual.jinja b/oarepo_ui/templates/components/Multilingual.jinja new file mode 100644 index 00000000..49195415 --- /dev/null +++ b/oarepo_ui/templates/components/Multilingual.jinja @@ -0,0 +1,16 @@ +{# def data #} +
+ + {% for item in data %} +
+ {{ item.value|e }} +
+ {% endfor %} +
diff --git a/oarepo_ui/templates/SearchLink.jinja b/oarepo_ui/templates/components/SearchLink.jinja similarity index 100% rename from oarepo_ui/templates/SearchLink.jinja rename to oarepo_ui/templates/components/SearchLink.jinja diff --git a/oarepo_ui/templates/SidebarApiLinks.jinja b/oarepo_ui/templates/components/SidebarApiLinks.jinja similarity index 100% rename from oarepo_ui/templates/SidebarApiLinks.jinja rename to oarepo_ui/templates/components/SidebarApiLinks.jinja diff --git a/oarepo_ui/templates/URL.jinja b/oarepo_ui/templates/components/URL.jinja similarity index 91% rename from oarepo_ui/templates/URL.jinja rename to oarepo_ui/templates/components/URL.jinja index f45642e8..12dffb76 100644 --- a/oarepo_ui/templates/URL.jinja +++ b/oarepo_ui/templates/components/URL.jinja @@ -1,4 +1,4 @@ -{# def className, data #} +{# def data, className="" #} {% set data_dict = data | to_dict %} diff --git a/oarepo_ui/templates/Value.jinja b/oarepo_ui/templates/components/Value.jinja similarity index 100% rename from oarepo_ui/templates/Value.jinja rename to oarepo_ui/templates/components/Value.jinja From 6f25d04b36fe3a5263203eedbb4736373982deaf Mon Sep 17 00:00:00 2001 From: Alzpetka Date: Wed, 1 Nov 2023 13:11:40 +0100 Subject: [PATCH 2/3] components name cli command --- oarepo_ui/cli.py | 15 ++++++++++++++- oarepo_ui/resources/templating.py | 17 ----------------- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/oarepo_ui/cli.py b/oarepo_ui/cli.py index aeab9473..59f33dbc 100644 --- a/oarepo_ui/cli.py +++ b/oarepo_ui/cli.py @@ -1,7 +1,7 @@ import json as json_lib import sys from pathlib import Path - +import os import click from flask.cli import with_appcontext from oarepo_runtime.cli import oarepo @@ -13,6 +13,19 @@ def ui(): """UI commands""" +@ui.command("components") +def components(): + + component_data = [] + script_directory = os.path.dirname(os.path.abspath(__file__ or '')) + components_directory = os.path.join(script_directory, 'templates', 'components') + + file_names = os.listdir(components_directory) + + for file_name in file_names: + component_data.append({"key": file_name.lower(), "component": file_name.replace(".jinja", "")}) + + print(component_data) @ui.command("renderers") @click.option("-v", "--verbose", is_flag=True, help="Verbose output") diff --git a/oarepo_ui/resources/templating.py b/oarepo_ui/resources/templating.py index 21713124..9d52e6ee 100644 --- a/oarepo_ui/resources/templating.py +++ b/oarepo_ui/resources/templating.py @@ -56,20 +56,3 @@ def jinja_env(self): def id_filter(x): return id(x) - -def get_components(): - - component_data = [] - directory = os.path.dirname(os.path.abspath(__file__ or '')) - parent_directory = os.path.dirname(directory) - components_directory = os.path.join(parent_directory, 'templates', 'components') - - - file_names = os.listdir(components_directory) - - for file_name in file_names: - component_data.append({"key": file_name.replace(".jinja", "").lower(), "component": file_name.replace(".jinja", "")}) - - - return component_data - From 5d329745073332c920b7c74d73b5f88b6d24fd80 Mon Sep 17 00:00:00 2001 From: Alzpetka Date: Wed, 1 Nov 2023 13:19:46 +0100 Subject: [PATCH 3/3] format --- oarepo_ui/cli.py | 14 +++++++++----- oarepo_ui/resources/templating.py | 3 +-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/oarepo_ui/cli.py b/oarepo_ui/cli.py index 59f33dbc..eb219764 100644 --- a/oarepo_ui/cli.py +++ b/oarepo_ui/cli.py @@ -1,7 +1,8 @@ import json as json_lib +import os import sys from pathlib import Path -import os + import click from flask.cli import with_appcontext from oarepo_runtime.cli import oarepo @@ -13,20 +14,23 @@ def ui(): """UI commands""" + @ui.command("components") def components(): - component_data = [] - script_directory = os.path.dirname(os.path.abspath(__file__ or '')) - components_directory = os.path.join(script_directory, 'templates', 'components') + script_directory = os.path.dirname(os.path.abspath(__file__ or "")) + components_directory = os.path.join(script_directory, "templates", "components") file_names = os.listdir(components_directory) for file_name in file_names: - component_data.append({"key": file_name.lower(), "component": file_name.replace(".jinja", "")}) + component_data.append( + {"key": file_name.lower(), "component": file_name.replace(".jinja", "")} + ) print(component_data) + @ui.command("renderers") @click.option("-v", "--verbose", is_flag=True, help="Verbose output") @click.option("--json", is_flag=True, help="Format output as json") diff --git a/oarepo_ui/resources/templating.py b/oarepo_ui/resources/templating.py index 9d52e6ee..66346fe8 100644 --- a/oarepo_ui/resources/templating.py +++ b/oarepo_ui/resources/templating.py @@ -1,6 +1,6 @@ from jinja2 import Environment from jinja2.loaders import BaseLoader -import os + class RegistryLoader(BaseLoader): def __init__(self, parent_loader) -> None: @@ -55,4 +55,3 @@ def jinja_env(self): def id_filter(x): return id(x) -