Skip to content

Commit

Permalink
keeps refactoring for nicegui
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfgangFahl committed Apr 17, 2024
1 parent 87eda59 commit 1a30369
Showing 1 changed file with 50 additions and 31 deletions.
81 changes: 50 additions & 31 deletions frontend/webserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
from ngwidgets.input_webserver import InputWebserver
from ngwidgets.login import Login
from ngwidgets.users import Users
from ngwidgets.webserver import WebserverConfig
from ngwidgets.webserver import WebserverConfig, WebSolution
from nicegui import Client, app, ui

from frontend.server import Server
from frontend.version import Version
from frontend.wikigrid import WikiGrid


class CmsWebServer(InputWebserver):
"""
WebServer class that manages the server
Expand All @@ -26,9 +25,15 @@ class CmsWebServer(InputWebserver):
def get_config(cls) -> WebserverConfig:
copy_right = "(c)2023-2024 Wolfgang Fahl"
config = WebserverConfig(
copy_right=copy_right, version=Version(), default_port=8252
copy_right=copy_right,
version=Version(),
default_port=8252,
short_name="wikicms"
)
return config
server_config = WebserverConfig.get(config)
server_config.solution_class = CmsSolution
return server_config


def __init__(self):
"""
Expand All @@ -41,25 +46,18 @@ def __init__(self):
self.server = Server()
self.server.load()
self.enabledSites = ["admin"]
self.wiki_grid = WikiGrid(self)

@ui.page("/")
async def home(client: Client):
return await self.home(client)

@ui.page("/settings")
async def settings():
return await self.settings()

@ui.page("/login")
async def login(client: Client):
return await self.login(client)
#@ui.page("/login")
#async def login(client: Client):
# return await self.page(
# client,CmsSolution.login
# )

@ui.page("/wikis")
async def wikis(client: Client):
if not self.login.authenticated():
return RedirectResponse("/login")
return await self.wikis()
#@ui.page("/wikis")
#async def wikis(client: Client):
# if not self.login.authenticated():
# return RedirectResponse("/login")
# return await self.wikis()

@app.get("/{frontend_name}/{page_path:path}")
def render_path(frontend_name: str, page_path: str) -> HTMLResponse:
Expand Down Expand Up @@ -111,23 +109,44 @@ def enableSites(self, siteNames):
self.server.enableFrontend(siteName, self)
self.enabledSites.append(siteName)

async def home(self, _client: Client):
def configure_run(self):
"""
Generates the home page with an overview of available wikis
configure command line specific details
"""
self.setup_menu()
with ui.element("div").classes("w-full h-full"):
self.server_html = ui.html(self.server.asHtml())
self.wiki_grid.setup()
await self.setup_footer()
InputWebserver.configure_run(self)
self.enableSites(self.args.sites)

class CmsSolution(WebSolution):
"""
Content management solution
"""

def __init__(self, webserver: CmsWebServer, client: Client):
"""
Initialize the solution
Calls the constructor of the base solution
Args:
webserver (Cms WebServer): The webserver instance associated with this context.
client (Client): The client instance this context is associated with.
"""
super().__init__(webserver, client) # Call to the superclass constructor
self.wiki_grid = WikiGrid(self)

def configure_menu(self):
"""
configure specific menu entries
"""
username = app.storage.user.get("username", "?")
ui.label(username)

async def home(self):
"""
provide the main content page
def configure_run(self):
self.enableSites(self.args.sites)
self.args.storage_secret = self.server.storage_secret
"""
def show():
with self.content_div:
self.server_html = ui.html(self.server.asHtml())
self.wiki_grid.setup()
await self.setup_content_div(show)

0 comments on commit 1a30369

Please sign in to comment.