feat: organise router path
This commit is contained in:
parent
f9bfb917bd
commit
d8f2fb52e1
@ -1,6 +1,6 @@
|
||||
import dash
|
||||
from dash import Dash, html, dcc
|
||||
from .pages import home, config
|
||||
from .pages import home, config, stage, schema, table
|
||||
|
||||
external_scripts = [
|
||||
{'src': 'https://cdn.tailwindcss.com'}
|
||||
@ -9,8 +9,31 @@ external_scripts = [
|
||||
|
||||
app = Dash(__name__, use_pages=True, external_scripts=external_scripts)
|
||||
app.scripts.config.serve_locally = True
|
||||
dash.register_page(home.__name__, path='/', layout=home.layout)
|
||||
dash.register_page(config.__name__, path='/config', layout=config.layout)
|
||||
dash.register_page(
|
||||
home.__name__,
|
||||
path='/',
|
||||
layout=home.layout,
|
||||
)
|
||||
dash.register_page(
|
||||
config.__name__,
|
||||
path='/config',
|
||||
layout=config.layout
|
||||
)
|
||||
dash.register_page(
|
||||
stage.__name__,
|
||||
path_template='/stage/<stage_name>',
|
||||
layout=stage.layout
|
||||
)
|
||||
dash.register_page(
|
||||
schema.__name__,
|
||||
path_template='/stg/<stage_name>/schema/<schema_name>',
|
||||
layout=schema.layout
|
||||
)
|
||||
dash.register_page(
|
||||
table.__name__,
|
||||
path_template='/stg/<stage_name>/schm/<schema_name>/table/<table_name>',
|
||||
layout=table.layout
|
||||
)
|
||||
|
||||
app.layout = html.Div([
|
||||
html.Div([
|
||||
|
@ -6,8 +6,8 @@ env = {
|
||||
}
|
||||
|
||||
stages = {
|
||||
"raw": FSStage(f"{env['DATA_PATH']}/{env['RAW_SUBPATH']}"),
|
||||
"staging": FSStage(f"{env['DATA_PATH']}/{env['STAGING_SUBPATH']}"),
|
||||
"gold": FSStage(f"{env['DATA_PATH']}/{env['GOLD_SUBPATH']}"),
|
||||
"mart": FSStage(f"{env['DATA_PATH']}/{env['MART_SUBPATH']}"),
|
||||
"raw": FSStage("raw", f"{env['DATA_PATH']}/{env['RAW_SUBPATH']}"),
|
||||
"staging": FSStage("staging", f"{env['DATA_PATH']}/{env['STAGING_SUBPATH']}"),
|
||||
"gold": FSStage("gold", f"{env['DATA_PATH']}/{env['GOLD_SUBPATH']}"),
|
||||
"mart": FSStage("mart", f"{env['DATA_PATH']}/{env['MART_SUBPATH']}"),
|
||||
}
|
||||
|
@ -2,7 +2,9 @@ from .stage import AbstractStage
|
||||
from pathlib import Path
|
||||
|
||||
class FSStage(AbstractStage):
|
||||
def __init__(self, basepath, metadata_engine=None):
|
||||
def __init__(self, name, basepath, metadata_engine=None):
|
||||
self.name = name
|
||||
|
||||
self.basepath = Path(basepath)
|
||||
self._metadata_engine = metadata_engine
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
from dash import html
|
||||
from dash import html, dcc
|
||||
from ..datalake import stages
|
||||
from ..libs.stage.stage import AbstractStage
|
||||
|
||||
@ -6,13 +6,15 @@ from ..libs.stage.stage import AbstractStage
|
||||
def html_list_schema(stage:AbstractStage, with_tables=True):
|
||||
""" Build html list of schema in stage """
|
||||
ul_classes = "ml-2"
|
||||
schema_baseurl = f"/stg/{stage.name}/schema/"
|
||||
if with_tables:
|
||||
return html.Ul(
|
||||
[
|
||||
html.Li(
|
||||
children = [
|
||||
html.Span(
|
||||
dcc.Link(
|
||||
schema,
|
||||
href=schema_baseurl + schema,
|
||||
className="text-lg text-bold"
|
||||
),
|
||||
html_list_table(stage, schema)
|
||||
@ -25,8 +27,11 @@ def html_list_schema(stage:AbstractStage, with_tables=True):
|
||||
return html.Ul(
|
||||
[
|
||||
html.Li(
|
||||
dcc.Link(
|
||||
schema,
|
||||
href=schema_baseurl + schema,
|
||||
className="text-lg text-bold"
|
||||
),
|
||||
) for schema in stage.schemas()
|
||||
],
|
||||
className=ul_classes
|
||||
@ -36,9 +41,16 @@ def html_list_schema(stage:AbstractStage, with_tables=True):
|
||||
|
||||
def html_list_table(stage:AbstractStage, schema:str):
|
||||
""" Build html list of table in stage """
|
||||
table_baseurl = f"/stg/{stage.name}/schm/{schema}/table/"
|
||||
return html.Ul(
|
||||
[
|
||||
html.Li(table) for table in stage.tables(schema=schema)
|
||||
html.Li(
|
||||
dcc.Link(
|
||||
table,
|
||||
href=table_baseurl + table,
|
||||
className="text-lg text-bold"
|
||||
),
|
||||
) for table in stage.tables(schema=schema)
|
||||
],
|
||||
className="ml-4"
|
||||
)
|
||||
@ -51,8 +63,9 @@ layout = html.Div([
|
||||
children=[
|
||||
html.Li(
|
||||
children=[
|
||||
html.Span(
|
||||
dcc.Link(
|
||||
stagename,
|
||||
href=f"/stage/{stagename}",
|
||||
className="text-2xl text-center p-2 bg-amber-100 rounded shadow"
|
||||
),
|
||||
html_list_schema(stage)
|
||||
|
11
dashboard/pages/schema.py
Normal file
11
dashboard/pages/schema.py
Normal file
@ -0,0 +1,11 @@
|
||||
from dash import html
|
||||
from ..datalake import stages
|
||||
from ..libs.stage.stage import AbstractStage
|
||||
|
||||
|
||||
def layout(stage_name=None, schema_name=None):
|
||||
return html.Div([
|
||||
html.H2(f"Stage - {stage_name}"),
|
||||
html.H3(f"Schema - {schema_name}"),
|
||||
])
|
||||
|
10
dashboard/pages/stage.py
Normal file
10
dashboard/pages/stage.py
Normal file
@ -0,0 +1,10 @@
|
||||
from dash import html
|
||||
from ..datalake import stages
|
||||
from ..libs.stage.stage import AbstractStage
|
||||
|
||||
|
||||
def layout(stage_name=None):
|
||||
stage = stages[stage_name]
|
||||
return html.Div([
|
||||
html.H2(f"Stage - {stage_name}")
|
||||
])
|
13
dashboard/pages/table.py
Normal file
13
dashboard/pages/table.py
Normal file
@ -0,0 +1,13 @@
|
||||
from dash import html
|
||||
from ..datalake import stages
|
||||
from ..libs.stage.stage import AbstractStage
|
||||
|
||||
|
||||
def layout(stage_name=None, schema_name=None, table_name=None):
|
||||
return html.Div([
|
||||
html.H2(f"Stage - {stage_name}"),
|
||||
html.H3(f"Schema - {schema_name}"),
|
||||
html.H4(f"Table - {table_name}"),
|
||||
])
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user