Tidy up kimai screen a bit
This commit is contained in:
parent
fd28955da0
commit
a01652f301
@ -5,6 +5,7 @@ from textual.widgets import DataTable, TabbedContent, TabPane, Header, Footer
|
|||||||
|
|
||||||
from peewee import fn, JOIN
|
from peewee import fn, JOIN
|
||||||
|
|
||||||
|
from ..utils import truncate
|
||||||
from ..sync import sync
|
from ..sync import sync
|
||||||
from ..db import (
|
from ..db import (
|
||||||
KimaiProject,
|
KimaiProject,
|
||||||
@ -36,7 +37,8 @@ class KimaiProjectList(ListPane):
|
|||||||
projects = (
|
projects = (
|
||||||
KimaiProject.select(
|
KimaiProject.select(
|
||||||
KimaiProject,
|
KimaiProject,
|
||||||
KimaiCustomer,
|
KimaiCustomer.id,
|
||||||
|
fn.COALESCE(KimaiCustomer.name, "").alias("customer_name"),
|
||||||
fn.Count(KimaiActivity.id).alias("activities_count"),
|
fn.Count(KimaiActivity.id).alias("activities_count"),
|
||||||
)
|
)
|
||||||
.join(KimaiCustomer, JOIN.LEFT_OUTER)
|
.join(KimaiCustomer, JOIN.LEFT_OUTER)
|
||||||
@ -55,8 +57,8 @@ class KimaiProjectList(ListPane):
|
|||||||
self.table.add_rows(
|
self.table.add_rows(
|
||||||
[
|
[
|
||||||
[
|
[
|
||||||
project.customer.id,
|
str(project.customer_id) if project.customer_id is not None else "",
|
||||||
project.customer.name,
|
project.customer_name,
|
||||||
project.id,
|
project.id,
|
||||||
project.name,
|
project.name,
|
||||||
project.activities_count,
|
project.activities_count,
|
||||||
@ -66,7 +68,7 @@ class KimaiProjectList(ListPane):
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
self.table.sort(self.sort)
|
self.table.sort(*self.sort)
|
||||||
|
|
||||||
def action_get(self) -> None:
|
def action_get(self) -> None:
|
||||||
sync()
|
sync()
|
||||||
@ -78,8 +80,7 @@ class KimaiProjectList(ListPane):
|
|||||||
self.columns = self.table.add_columns(
|
self.columns = self.table.add_columns(
|
||||||
"customer id", "customer", "project id", "project", "activities", "visible"
|
"customer id", "customer", "project id", "project", "activities", "visible"
|
||||||
)
|
)
|
||||||
# self.sort = (self.columns[1], self.columns[3])
|
self.sort = (self.columns[1], self.columns[3])
|
||||||
self.sort = self.columns[1]
|
|
||||||
self._refresh()
|
self._refresh()
|
||||||
|
|
||||||
|
|
||||||
@ -100,8 +101,8 @@ class KimaiActivityList(ListPane):
|
|||||||
activities = (
|
activities = (
|
||||||
KimaiActivity.select(
|
KimaiActivity.select(
|
||||||
KimaiActivity,
|
KimaiActivity,
|
||||||
fn.COALESCE(KimaiProject.name, "None").alias("project_name"),
|
fn.COALESCE(KimaiProject.name, "").alias("project_name"),
|
||||||
fn.COALESCE(KimaiCustomer.name, "None").alias("customer_name"),
|
fn.COALESCE(KimaiCustomer.name, "").alias("customer_name"),
|
||||||
)
|
)
|
||||||
.join(KimaiProject, JOIN.LEFT_OUTER)
|
.join(KimaiProject, JOIN.LEFT_OUTER)
|
||||||
.join(KimaiCustomer, JOIN.LEFT_OUTER)
|
.join(KimaiCustomer, JOIN.LEFT_OUTER)
|
||||||
@ -117,16 +118,16 @@ class KimaiActivityList(ListPane):
|
|||||||
# activity.project.customer_id if activity.project is not None else '',
|
# activity.project.customer_id if activity.project is not None else '',
|
||||||
# activity.customer_name,
|
# activity.customer_name,
|
||||||
str(activity.project_id) if activity.project_id is not None else "",
|
str(activity.project_id) if activity.project_id is not None else "",
|
||||||
activity.project_name,
|
truncate(activity.project_name, 40),
|
||||||
activity.id,
|
activity.id,
|
||||||
activity.name,
|
truncate(activity.name, 40),
|
||||||
activity.visible,
|
activity.visible,
|
||||||
]
|
]
|
||||||
for activity in activities
|
for activity in activities
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
self.table.sort(self.sort)
|
self.table.sort(*self.sort)
|
||||||
|
|
||||||
def action_get(self) -> None:
|
def action_get(self) -> None:
|
||||||
sync()
|
sync()
|
||||||
@ -144,8 +145,7 @@ class KimaiActivityList(ListPane):
|
|||||||
"name",
|
"name",
|
||||||
"visible",
|
"visible",
|
||||||
)
|
)
|
||||||
# self.sort = (self.columns[1], self.columns[3])
|
self.sort = (self.columns[1], self.columns[3])
|
||||||
self.sort = self.columns[3]
|
|
||||||
self._refresh()
|
self._refresh()
|
||||||
|
|
||||||
|
|
||||||
|
2
hamstertools/utils.py
Normal file
2
hamstertools/utils.py
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
def truncate(string: str, length: int) -> str:
|
||||||
|
return string[: length - 2] + ".." if len(string) > 52 else string
|
Loading…
Reference in New Issue
Block a user