Add kimai "visible" field, moar kimai screens
This commit is contained in:
@ -15,6 +15,10 @@ from ..db import (
|
||||
from .list import ListPane
|
||||
|
||||
|
||||
class KimaiCustomerList(ListPane):
|
||||
pass
|
||||
|
||||
|
||||
class KimaiProjectList(ListPane):
|
||||
BINDINGS = [
|
||||
("s", "sort", "Sort"),
|
||||
@ -24,9 +28,11 @@ class KimaiProjectList(ListPane):
|
||||
Binding(key="escape", action="cancelfilter", show=False),
|
||||
]
|
||||
|
||||
def _refresh(self, filter_query=None):
|
||||
def _refresh(self):
|
||||
self.table.clear()
|
||||
|
||||
filter_search = self.query_one("#filter #search").value
|
||||
|
||||
projects = (
|
||||
KimaiProject.select(
|
||||
KimaiProject,
|
||||
@ -40,10 +46,10 @@ class KimaiProjectList(ListPane):
|
||||
.group_by(KimaiProject)
|
||||
)
|
||||
|
||||
if filter_query:
|
||||
if filter_search:
|
||||
projects = projects.where(
|
||||
KimaiProject.name.contains(filter_query)
|
||||
| KimaiCustomer.name.contains(filter_query)
|
||||
KimaiProject.name.contains(filter_search)
|
||||
| KimaiCustomer.name.contains(filter_search)
|
||||
)
|
||||
|
||||
self.table.add_rows(
|
||||
@ -54,6 +60,7 @@ class KimaiProjectList(ListPane):
|
||||
project.id,
|
||||
project.name,
|
||||
project.activities_count,
|
||||
project.visible,
|
||||
]
|
||||
for project in projects
|
||||
]
|
||||
@ -69,29 +76,104 @@ class KimaiProjectList(ListPane):
|
||||
self.table = self.query_one(DataTable)
|
||||
self.table.cursor_type = "row"
|
||||
self.columns = self.table.add_columns(
|
||||
"customer id", "customer", "project id", "project", "activities"
|
||||
"customer id", "customer", "project id", "project", "activities", "visible"
|
||||
)
|
||||
# self.sort = (self.columns[1], self.columns[3])
|
||||
self.sort = self.columns[1]
|
||||
self._refresh()
|
||||
|
||||
|
||||
class KimaiActivityList(ListPane):
|
||||
BINDINGS = [
|
||||
("s", "sort", "Sort"),
|
||||
("r", "refresh", "Refresh"),
|
||||
("g", "get", "Get data"),
|
||||
("/", "filter", "Search"),
|
||||
Binding(key="escape", action="cancelfilter", show=False),
|
||||
]
|
||||
|
||||
def _refresh(self):
|
||||
self.table.clear()
|
||||
|
||||
filter_search = self.query_one("#filter #search").value
|
||||
|
||||
activities = (
|
||||
KimaiActivity.select(
|
||||
KimaiActivity,
|
||||
fn.COALESCE(KimaiProject.name, "None").alias("project_name"),
|
||||
fn.COALESCE(KimaiCustomer.name, "None").alias("customer_name"),
|
||||
)
|
||||
.join(KimaiProject, JOIN.LEFT_OUTER)
|
||||
.join(KimaiCustomer, JOIN.LEFT_OUTER)
|
||||
.group_by(KimaiActivity)
|
||||
)
|
||||
|
||||
if filter_search:
|
||||
activities = activities.where(KimaiActivity.name.contains(filter_search))
|
||||
|
||||
self.table.add_rows(
|
||||
[
|
||||
[
|
||||
# activity.project.customer_id if activity.project is not None else '',
|
||||
# activity.customer_name,
|
||||
str(activity.project_id) if activity.project_id is not None else "",
|
||||
activity.project_name,
|
||||
activity.id,
|
||||
activity.name,
|
||||
activity.visible,
|
||||
]
|
||||
for activity in activities
|
||||
]
|
||||
)
|
||||
|
||||
self.table.sort(self.sort)
|
||||
|
||||
def action_get(self) -> None:
|
||||
sync()
|
||||
self._refresh()
|
||||
|
||||
def on_mount(self) -> None:
|
||||
self.table = self.query_one(DataTable)
|
||||
self.table.cursor_type = "row"
|
||||
self.columns = self.table.add_columns(
|
||||
# "customer id",
|
||||
# "customer",
|
||||
"project id",
|
||||
"project",
|
||||
"id",
|
||||
"name",
|
||||
"visible",
|
||||
)
|
||||
# self.sort = (self.columns[1], self.columns[3])
|
||||
self.sort = self.columns[3]
|
||||
self._refresh()
|
||||
|
||||
|
||||
class KimaiScreen(Screen):
|
||||
BINDINGS = [
|
||||
("c", "show_tab('customers')", "Customers"),
|
||||
("p", "show_tab('projects')", "Projects"),
|
||||
("a", "show_tab('activities')", "Activities"),
|
||||
]
|
||||
|
||||
SUB_TITLE = "Kimai"
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Header()
|
||||
with TabbedContent(initial="activities"):
|
||||
with TabPane("Categories", id="categories"):
|
||||
with TabbedContent(initial="projects"):
|
||||
with TabPane("Customers", id="customers"):
|
||||
yield KimaiCustomerList()
|
||||
with TabPane("Projects", id="projects"):
|
||||
yield KimaiProjectList()
|
||||
with TabPane("Activities", id="activities"):
|
||||
yield KimaiProjectList()
|
||||
yield KimaiActivityList()
|
||||
yield Footer()
|
||||
|
||||
def on_mount(self) -> None:
|
||||
self.query_one("TabbedContent Tabs").can_focus = False
|
||||
self.query_one("#projects DataTable").focus()
|
||||
|
||||
def action_show_tab(self, tab: str) -> None:
|
||||
"""Switch to a new tab."""
|
||||
self.get_child_by_type(TabbedContent).active = tab
|
||||
self.query_one(f"#{tab} DataTable").focus()
|
||||
|
Reference in New Issue
Block a user