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 = [] mapping_files = []
for mapping_path_item in mapping_path: for mapping_path_item in mapping_path:
if not Path(mapping_path_item).exists(): 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) mapping_file = _get_kimai_mapping_file(mapping_path_item)
next(mapping_file) next(mapping_file)

View File

@ -156,10 +156,26 @@ class ActivityMappingScreen(ModalScreen):
customer_id = None customer_id = None
project_id = None project_id = None
activity_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__() super().__init__()
@staticmethod @staticmethod
@ -197,36 +213,48 @@ class ActivityMappingScreen(ModalScreen):
def compose(self) -> ComposeResult: def compose(self) -> ComposeResult:
yield Vertical( yield Vertical(
Horizontal( Horizontal(
Label(f"Mapping for {self.activity}@{self.category}"), Label(f"Mapping for {self.hamster_activity}@{self.hamster_category}"),
), ),
Horizontal( Horizontal(
Label("Customer"), Label("Customer"),
AutoComplete( AutoComplete(
Input(placeholder="Type to search...", id="customer"), Input(
placeholder="Type to search...",
id="customer",
value=self.customer,
),
Dropdown(items=self._get_customers), Dropdown(items=self._get_customers),
), ),
), ),
Horizontal( Horizontal(
Label("Project"), Label("Project"),
AutoComplete( AutoComplete(
Input(placeholder="Type to search...", id="project"), Input(
placeholder="Type to search...",
id="project",
value=self.project,
),
Dropdown(items=self._get_projects), Dropdown(items=self._get_projects),
), ),
), ),
Horizontal( Horizontal(
Label("Activity"), Label("Activity"),
AutoComplete( AutoComplete(
Input(placeholder="Type to search...", id="activity"), Input(
placeholder="Type to search...",
id="activity",
value=self.activity,
),
Dropdown(items=self._get_activities), Dropdown(items=self._get_activities),
), ),
), ),
Horizontal( Horizontal(
Label("Description"), Label("Description"),
Input(id="description"), Input(id="description", value=self.description),
), ),
Horizontal( Horizontal(
Label("Tags"), Label("Tags"),
Input(id="tags"), Input(id="tags", value=self.tags),
), ),
Horizontal(Checkbox("Global", id="global")), Horizontal(Checkbox("Global", id="global")),
) )
@ -468,20 +496,33 @@ class ActivityListScreen(ListScreen):
.get() .get()
) )
def handle_mapping(mapping): mapping = None
if mapping is None: try:
return mapping = HamsterActivityKimaiMapping.get(
m = HamsterActivityKimaiMapping.create( hamster_activity=selected_activity
hamster_activity=selected_activity, **mapping
) )
m.save() except HamsterActivityKimaiMapping.DoesNotExist:
filter_search = self.query_one("#search") 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._refresh()
self.app.push_screen( self.app.push_screen(
ActivityMappingScreen( ActivityMappingScreen(
category=selected_activity.category_name, category=selected_activity.category_name,
activity=selected_activity.name, activity=selected_activity.name,
mapping=mapping,
), ),
handle_mapping, handle_mapping,
) )

View File

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