Add kimai "visible" field, moar kimai screens

This commit is contained in:
3wc
2023-11-03 23:42:11 +00:00
parent d3c2da74e6
commit fd28955da0
6 changed files with 152 additions and 33 deletions

View File

@ -44,24 +44,26 @@ class BaseAPI(object):
setattr(self, key, value)
@dataclass
class Customer(BaseAPI):
def __init__(self, api, id, name):
super().__init__(api, id=id, name=name)
api: KimaiAPI = field(repr=False)
id: int
name: str
visible: bool = field(default=True)
@staticmethod
def list(api):
return [Customer(api, c["id"], c["name"]) for c in api.customers_json]
return [
Customer(api, c["id"], c["name"], c["visible"]) for c in api.customers_json
]
@staticmethod
def get_by_id(api, id):
for value in api.customers_json:
if value["id"] == id:
return Customer(api, value["id"], value["name"])
for c in api.customers_json:
if c["id"] == id:
return Customer(api, c["id"], c["name"], c["visible"])
raise NotFound()
def __repr__(self):
return f"Customer (id={self.id}, name={self.name})"
@dataclass
class Project(BaseAPI):
@ -70,6 +72,7 @@ class Project(BaseAPI):
name: str
customer: Customer
allow_global_activities: bool = field(default=True)
visible: bool = field(default=True)
@staticmethod
def list(api):
@ -80,20 +83,22 @@ class Project(BaseAPI):
p["name"],
Customer.get_by_id(api, p["customer"]),
p["globalActivities"],
p["visible"],
)
for p in api.projects_json
]
@staticmethod
def get_by_id(api, id, none=False):
for value in api.projects_json:
if value["id"] == id:
for p in api.projects_json:
if p["id"] == id:
return Project(
api,
value["id"],
value["name"],
Customer.get_by_id(api, value["customer"]),
value["globalActivities"],
p["id"],
p["name"],
Customer.get_by_id(api, p["customer"]),
p["globalActivities"],
p["visible"],
)
if not none:
raise NotFound()
@ -105,25 +110,31 @@ class Activity(BaseAPI):
id: int
name: str
project: Project
visible: bool = field(default=True)
@staticmethod
def list(api):
return [
Activity(
api, a["id"], a["name"], Project.get_by_id(api, a["project"], none=True)
api,
a["id"],
a["name"],
Project.get_by_id(api, a["project"], none=True),
a["visible"],
)
for a in api.activities_json
]
@staticmethod
def get_by_id(api, id, none=False):
for value in api.activities_json:
if value["id"] == id:
for a in api.activities_json:
if a["id"] == id:
return Activity(
api,
value["id"],
value["name"],
Project.get_by_id(api, value["project"]),
a["id"],
a["name"],
Project.get_by_id(api, a["project"]),
a["visible"],
)
if not none:
raise NotFound()