Skip to content

Commit

Permalink
refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfgangFahl committed Feb 23, 2024
1 parent cf56686 commit b3fe9ec
Show file tree
Hide file tree
Showing 4 changed files with 178 additions and 24 deletions.
89 changes: 88 additions & 1 deletion ceurws/volume_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
@author: wf
"""
from ngwidgets.lod_grid import GridConfig,ListOfDictsGrid
from ngwidgets.widgets import Link
from nicegui import ui

Expand Down Expand Up @@ -148,7 +149,7 @@ def showVolume(self, volume):

# template=self.templateEnv.getTemplate('volume_index_body.html')
# html=template.render(volume=volume)
headerHtml = f"""{links}<h3>{volume.h1}</h3>
headerHtml = f"""{links}<h3 style='font-size: 24px; font-weight: normal; margin-top: 20px; margin-bottom: 10px;'>{volume.h1}</h3>
<a href='{volume.url}'>{volume.acronym}<a>
{volume.title}<br>
{volume.desc}
Expand Down Expand Up @@ -192,3 +193,89 @@ async def onWikidataButtonClick(self, _args):
self.solution.log_view.push(err_msg)
except Exception as ex:
self.solution.handle_exception(ex)

class VolumeListView(View):
"""
show a list of volumes a table
"""

def __init__(self, solution, parent):
"""
constructor
Args:
solution: the solution
parent: the parent UI container
"""
self.solution = solution
self.parent = parent
self.wdSync=self.solution.wdSync
self.get_volume_lod()
self.setup_ui()

def setup_ui(self):
"""
show my volumes as a list
"""
try:
with ui.row() as self.button_row:
self.wikidataButton = (
ui.button(
icon="web",
on_click=self.onWikidataButtonClick,
)
.classes("btn btn-primary btn-sm col-1")
.tooltip("Export to Wikidata")
)
pass
with ui.row() as self.grid_row:
grid_config = GridConfig(
key_col="Vol",
multiselect=True)
self.lod_grid=ListOfDictsGrid(lod=self.lod,config=grid_config)
# Modify the columnDefs for the "Title" column after grid initialization
for col_def in self.lod_grid.ag_grid.options["columnDefs"]:
if col_def["field"] == "Title": # Identify the "Title" column
col_def["maxWidth"] = 400 # width in pixels
self.lod_grid.sizeColumnsToFit()
except Exception as ex:
self.handle_exception(ex)

async def onWikidataButtonClick(self, _args):
"""
handle wikidata sync request
"""
try:
selected_rows = await self.lod_grid.get_selected_rows()
for row in selected_rows:
vol_number=row["#"]
volume = self.wdSync.volumesByNumber[vol_number]
ui.notify(f"exporting {vol_number}")
pass
except Exception as ex:
self.handle_exception(ex)

def get_volume_lod(self):
"""
get the list of dict of all volumes
"""
self.lod = []
volumeList = self.wdSync.vm.getList()
reverseVolumeList = sorted(
volumeList, key=lambda volume: volume.number, reverse=True
)
for volume in reverseVolumeList:
validMark = "✅" if volume.valid else "❌"
self.lod.append(
{
"#": volume.number,
"Vol": self.createLink(volume.url, f"Vol-{volume.number:04}"),
"Acronym": self.getValue(volume, "acronym"),
"Title": self.getValue(volume, "title"),
"Loctime": self.getValue(volume, "loctime"),
"Published": self.getValue(volume, "published"),
"SubmittedBy": self.getValue(volume, "submittedBy"),
"valid": validMark,
}
)
75 changes: 52 additions & 23 deletions ceurws/webserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

from ceurws.models.dblp import DblpPaper, DblpProceeding, DblpScholar
from ceurws.version import Version
from ceurws.volume_view import VolumeView
from ceurws.volume_view import VolumeView, VolumeListView
from ceurws.wikidatasync import VolumeNotFound, WikidataSync

from ceurws.wikidata_view import WikidataView

class CeurWsWebServer(InputWebserver):
"""
Expand All @@ -45,6 +45,25 @@ def __init__(self):
"""
InputWebserver.__init__(self, config=CeurWsWebServer.get_config())

@ui.page("/volumes")
async def show_volumes(client: Client):
return await self.page(
client,CeurWsSolution.volumes
)

@ui.page("/volume/{volnumber}")
async def show_volume_page(client: Client,vol_number):
return await self.page(
client,CeurWsSolution.volumePage,vol_number
)

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


@app.get("/volumes.json")
async def volumes():
"""
Expand Down Expand Up @@ -227,25 +246,15 @@ def __init__(self, webserver: CeurWsWebServer, client: Client):
"""
super().__init__(webserver, client) # Call to the superclass constructor
self.wdSync = self.webserver.wdSync
self.get_volume_options()

def get_volume_options(self):
"""
get the volume options
"""
# Initialize an empty dictionary to store volume number as key and title as value
self.volume_options = {}
self.volumes_by_number = {}

# Populate the dictionary with volume numbers and titles
for volume in self.wdSync.vm.getList():
self.volumes_by_number[volume.number] = volume

reverse_keys = sorted(self.volumes_by_number.keys(), reverse=True)
for volume_number in reverse_keys:
volume = self.volumes_by_number[volume_number]
self.volume_options[volume.number] = f"Vol-{volume.number}:{volume.title}"
pass

def configure_menu(self):
InputWebSolution.configure_menu(self)
self.link_button(
name="volumes", icon_name="table", target="/volumes"
)
self.link_button(
name="wikidata",icon_name="cloud_sync",target="/wikidatasync"
)

def prepare_ui(self):
"""
Expand All @@ -270,6 +279,26 @@ def add_css(self):
ui.add_head_html(
f'<link rel="stylesheet" type="text/css" href="/css/{css_file}">'
)

async def wikidatasync(self):
"""
show the wikidata sync table
"""
def show():
self.wikidata_view =WikidataView(
self, self.container
)
await self.setup_content_div(show)

async def volumes(self):
"""
show the volumes table
"""
def show():
self.volume_list_view = VolumeListView(
self, self.container
)
await self.setup_content_div(show)

async def home(self):
"""
Expand All @@ -282,7 +311,7 @@ def show():
with ui.row() as self.select_container:
self.volume_select = self.add_select(
"Volume",
selection=self.volume_options,
selection=self.wdSync.volumeOptions,
with_input=True,
on_change=self.volume_selected,
)
Expand All @@ -297,6 +326,6 @@ async def volume_selected(self, args: ValueChangeEventArguments):
when a volume is selected show the details in the Volume View
"""
vol_number = args.value
volume = self.volumes_by_number[vol_number]
volume = self.wdSync.volumesByNumber[vol_number]
self.volume_view.showVolume(volume)
pass
32 changes: 32 additions & 0 deletions ceurws/wikidata_view.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'''
Created on 2024-02-23
@author: wf
'''
from ceurws.view import View

class WikidataView(View):
"""
Wikidata View
"""

def __init__(self, solution, parent):
"""
constructor
Args:
solution: the solution
parent: the parent UI container
"""
self.solution = solution
self.parent = parent
self.setup_ui()

def setup_ui(self):
"""
setup my User Interface elements
"""
with self.parent:
pass

6 changes: 6 additions & 0 deletions ceurws/wikidatasync.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ def prepareVolumeManager(self):
self.volumesByNumber, _duplicates = LOD.getLookup(self.vm.getList(), "number")
self.volumeList = self.vm.getList()
self.volumeCount = len(self.volumeList)
self.volumeOptions = {}
reverse_keys = sorted(self.volumesByNumber.keys(), reverse=True)
for volume_number in reverse_keys:
volume = self.volumesByNumber[volume_number]
self.volumeOptions[volume.number] = f"Vol-{volume.number}:{volume.title}"


def addVolume(self, volume: Volume):
"""
Expand Down

0 comments on commit b3fe9ec

Please sign in to comment.