Mapping editing

This commit is contained in:
3wc 2023-11-02 22:43:11 +00:00
parent be1a8a7f7a
commit ce68a03ea9
3 changed files with 58 additions and 21 deletions

View File

@ -370,7 +370,7 @@ def check(username, api_key, just_errors, ignore_activities, mapping_path=None):
mapping_files = []
for mapping_path_item in mapping_path:
if not Path(mapping_path_item).exists():
raise click.UsageError(f'{mapping_path_item} does not exist')
raise click.UsageError(f"{mapping_path_item} does not exist")
mapping_file = _get_kimai_mapping_file(mapping_path_item)
next(mapping_file)

View File

@ -156,10 +156,26 @@ class ActivityMappingScreen(ModalScreen):
customer_id = None
project_id = None
activity_id = None
customer = ""
project = ""
activity = ""
description = ""
tags = ""
def __init__(self, category, activity, mapping=None):
self.hamster_category = category
self.hamster_activity = activity
if mapping is not None:
self.customer_id = mapping.kimai_customer_id
self.customer = mapping.kimai_customer.name
self.project_id = mapping.kimai_project_id
self.project = mapping.kimai_project.name
self.activity_id = mapping.kimai_activity_id
self.activity = mapping.kimai_activity.name
self.description = mapping.kimai_description
self.tags = mapping.kimai_tags
def __init__(self, category, activity):
self.category = category
self.activity = activity
super().__init__()
@staticmethod
@ -197,36 +213,48 @@ class ActivityMappingScreen(ModalScreen):
def compose(self) -> ComposeResult:
yield Vertical(
Horizontal(
Label(f"Mapping for {self.activity}@{self.category}"),
Label(f"Mapping for {self.hamster_activity}@{self.hamster_category}"),
),
Horizontal(
Label("Customer"),
AutoComplete(
Input(placeholder="Type to search...", id="customer"),
Input(
placeholder="Type to search...",
id="customer",
value=self.customer,
),
Dropdown(items=self._get_customers),
),
),
Horizontal(
Label("Project"),
AutoComplete(
Input(placeholder="Type to search...", id="project"),
Input(
placeholder="Type to search...",
id="project",
value=self.project,
),
Dropdown(items=self._get_projects),
),
),
Horizontal(
Label("Activity"),
AutoComplete(
Input(placeholder="Type to search...", id="activity"),
Input(
placeholder="Type to search...",
id="activity",
value=self.activity,
),
Dropdown(items=self._get_activities),
),
),
Horizontal(
Label("Description"),
Input(id="description"),
Input(id="description", value=self.description),
),
Horizontal(
Label("Tags"),
Input(id="tags"),
Input(id="tags", value=self.tags),
),
Horizontal(Checkbox("Global", id="global")),
)
@ -468,20 +496,33 @@ class ActivityListScreen(ListScreen):
.get()
)
def handle_mapping(mapping):
if mapping is None:
return
m = HamsterActivityKimaiMapping.create(
hamster_activity=selected_activity, **mapping
mapping = None
try:
mapping = HamsterActivityKimaiMapping.get(
hamster_activity=selected_activity
)
m.save()
filter_search = self.query_one("#search")
except HamsterActivityKimaiMapping.DoesNotExist:
pass
def handle_mapping(mapping_data):
if mapping_data is None:
return
if mapping is not None:
mapping_ = mapping
for key, value in mapping_data.items():
setattr(mapping_, key, value)
else:
mapping_ = HamsterActivityKimaiMapping.create(
hamster_activity=selected_activity, **mapping_data
)
mapping_.save()
self._refresh()
self.app.push_screen(
ActivityMappingScreen(
category=selected_activity.category_name,
activity=selected_activity.name,
mapping=mapping,
),
handle_mapping,
)

View File

@ -6,13 +6,9 @@ from .kimai import (
)
from .db import (
db,
HamsterCategory,
HamsterActivity,
HamsterFact,
KimaiProject,
KimaiCustomer,
KimaiActivity,
HamsterActivityKimaiMapping,
)