Improve filtering, add "move facts"
This commit is contained in:
parent
8e5e28ea67
commit
cbbf952787
@ -12,6 +12,7 @@ class ActivitiesScreen(Screen):
|
|||||||
BINDINGS = [
|
BINDINGS = [
|
||||||
("q", "quit", "Quit"),
|
("q", "quit", "Quit"),
|
||||||
("s", "sort", "Sort"),
|
("s", "sort", "Sort"),
|
||||||
|
("f", "move_facts", "Move facts"),
|
||||||
("r", "refresh", "Refresh"),
|
("r", "refresh", "Refresh"),
|
||||||
("d", "delete", "Delete activity"),
|
("d", "delete", "Delete activity"),
|
||||||
("/", "filter", "Search"),
|
("/", "filter", "Search"),
|
||||||
@ -60,19 +61,30 @@ class ActivitiesScreen(Screen):
|
|||||||
def action_sort(self) -> None:
|
def action_sort(self) -> None:
|
||||||
self.table.cursor_type = "column"
|
self.table.cursor_type = "column"
|
||||||
|
|
||||||
|
def on_data_table_column_selected(self, event):
|
||||||
|
self.sort = (event.column_key,)
|
||||||
|
event.data_table.sort(*self.sort)
|
||||||
|
event.data_table.cursor_type = "row"
|
||||||
|
|
||||||
def action_filter(self) -> None:
|
def action_filter(self) -> None:
|
||||||
filter_input = self.query_one("#filter")
|
filter_input = self.query_one("#filter")
|
||||||
filter_input.display = True
|
filter_input.display = True
|
||||||
|
self._refresh(filter_input.value)
|
||||||
filter_input.focus()
|
filter_input.focus()
|
||||||
print(filter_input)
|
|
||||||
|
def on_input_submitted(self, event):
|
||||||
|
self.table.focus()
|
||||||
|
|
||||||
|
|
||||||
def action_cancelfilter(self) -> None:
|
def action_cancelfilter(self) -> None:
|
||||||
filter_input = self.query_one("#filter")
|
filter_input = self.query_one("#filter")
|
||||||
filter_input.display = False
|
filter_input.display = False
|
||||||
|
filter_input.clear()
|
||||||
|
self.table.focus()
|
||||||
self._refresh()
|
self._refresh()
|
||||||
|
|
||||||
def action_delete(self) -> None:
|
def action_delete(self) -> None:
|
||||||
# get the keys for the row and column under the cursor.
|
# get the keys for the row and column under the cursor.
|
||||||
row_key, _ = self.table.coordinate_to_cell_key(self.table.cursor_coordinate)
|
row_key, _ = self.table.coordinate_to_cell_key(self.table.cursor_coordinate)
|
||||||
|
|
||||||
activity_id = self.table.get_cell_at(
|
activity_id = self.table.get_cell_at(
|
||||||
@ -85,15 +97,30 @@ class ActivitiesScreen(Screen):
|
|||||||
# supply the row key to `remove_row` to delete the row.
|
# supply the row key to `remove_row` to delete the row.
|
||||||
self.table.remove_row(row_key)
|
self.table.remove_row(row_key)
|
||||||
|
|
||||||
def on_data_table_column_selected(self, event):
|
def action_move_facts(self) -> None:
|
||||||
self.sort = (event.column_key,)
|
row_idx: int = self.table.cursor_row
|
||||||
event.data_table.sort(*self.sort)
|
row_cells = self.table.get_row_at(row_idx)
|
||||||
event.data_table.cursor_type = "row"
|
self.move_from_activity = Activity.get_by_id(self.db_manager, row_cells[2])
|
||||||
|
for col_idx, cell_value in enumerate(row_cells):
|
||||||
|
cell_coordinate = Coordinate(row_idx, col_idx)
|
||||||
|
self.table.update_cell_at(
|
||||||
|
cell_coordinate,
|
||||||
|
f"[red]{cell_value}[/red]",
|
||||||
|
)
|
||||||
|
self.table.move_cursor(row=self.table.cursor_coordinate[0]+1)
|
||||||
|
|
||||||
|
def on_data_table_row_selected(self, event):
|
||||||
|
if getattr(self, "move_from_activity", None) is not None:
|
||||||
|
move_to_activity = Activity.get_by_id(self.db_manager, self.table.get_cell_at(
|
||||||
|
Coordinate(event.cursor_row, 2)
|
||||||
|
))
|
||||||
|
self.move_from_activity.move_facts(move_to_activity)
|
||||||
|
self._refresh()
|
||||||
|
del self.move_from_activity
|
||||||
|
|
||||||
def on_input_changed(self, event):
|
def on_input_changed(self, event):
|
||||||
self._refresh(event.value)
|
self._refresh(event.value)
|
||||||
|
|
||||||
|
|
||||||
class CategoriesScreen(Screen):
|
class CategoriesScreen(Screen):
|
||||||
BINDINGS = [
|
BINDINGS = [
|
||||||
("s", "sort", "Sort"),
|
("s", "sort", "Sort"),
|
||||||
@ -149,12 +176,17 @@ class CategoriesScreen(Screen):
|
|||||||
def action_filter(self) -> None:
|
def action_filter(self) -> None:
|
||||||
filter_input = self.query_one("#filter")
|
filter_input = self.query_one("#filter")
|
||||||
filter_input.display = True
|
filter_input.display = True
|
||||||
|
self._refresh(filter_input.value)
|
||||||
filter_input.focus()
|
filter_input.focus()
|
||||||
print(filter_input)
|
|
||||||
|
def on_input_submitted(self, event):
|
||||||
|
self.table.focus()
|
||||||
|
|
||||||
def action_cancelfilter(self) -> None:
|
def action_cancelfilter(self) -> None:
|
||||||
filter_input = self.query_one("#filter")
|
filter_input = self.query_one("#filter")
|
||||||
filter_input.display = False
|
filter_input.display = False
|
||||||
|
filter_input.clear()
|
||||||
|
self.table.focus()
|
||||||
self._refresh()
|
self._refresh()
|
||||||
|
|
||||||
def on_input_changed(self, event):
|
def on_input_changed(self, event):
|
||||||
|
@ -92,6 +92,22 @@ class Activity(BaseORM):
|
|||||||
self.category_name = category_name
|
self.category_name = category_name
|
||||||
self.facts_count = facts_count
|
self.facts_count = facts_count
|
||||||
|
|
||||||
|
def move_facts(self, to_activity):
|
||||||
|
cursor = self.db_manager.get_cursor()
|
||||||
|
|
||||||
|
print(f"moving from {self.id} to {to_activity.id}")
|
||||||
|
|
||||||
|
cursor.execute("""
|
||||||
|
UPDATE
|
||||||
|
facts
|
||||||
|
SET
|
||||||
|
activity_id = ?
|
||||||
|
WHERE
|
||||||
|
activity_id = ?
|
||||||
|
""", (to_activity.id, self.id))
|
||||||
|
|
||||||
|
self.conn.commit()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def list_activities(db_manager, filter_query=None):
|
def list_activities(db_manager, filter_query=None):
|
||||||
cursor = db_manager.get_cursor()
|
cursor = db_manager.get_cursor()
|
||||||
@ -121,7 +137,7 @@ class Activity(BaseORM):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
if filter_query is not None:
|
if filter_query is not None:
|
||||||
cursor.execute(sql, ("%{}%".format(filter_query),) * 2 )
|
cursor.execute(sql, ("%{}%".format(filter_query),) * 2)
|
||||||
else:
|
else:
|
||||||
cursor.execute(sql)
|
cursor.execute(sql)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user