refactor
This commit is contained in:
parent
90b4ed7300
commit
6d3b82ece2
@ -4,7 +4,8 @@ import lxml.html
|
|||||||
from typing_extensions import Annotated
|
from typing_extensions import Annotated
|
||||||
from .controller import add_task
|
from .controller import add_task
|
||||||
from .import_csv import import_tasks_from_csv
|
from .import_csv import import_tasks_from_csv
|
||||||
from . import tui
|
from .db import initialize_db
|
||||||
|
from .tui import tasks
|
||||||
|
|
||||||
app = typer.Typer()
|
app = typer.Typer()
|
||||||
|
|
||||||
@ -16,6 +17,7 @@ def new(
|
|||||||
due: Annotated[str, typer.Option("-d", "--due", help="due")] = "",
|
due: Annotated[str, typer.Option("-d", "--due", help="due")] = "",
|
||||||
url: Annotated[str, typer.Option("-u", "--url", help="URL")] = "",
|
url: Annotated[str, typer.Option("-u", "--url", help="URL")] = "",
|
||||||
):
|
):
|
||||||
|
initialize_db()
|
||||||
required = ["name", "category"]
|
required = ["name", "category"]
|
||||||
|
|
||||||
if url and not name:
|
if url and not name:
|
||||||
@ -42,7 +44,8 @@ def new(
|
|||||||
def browse(
|
def browse(
|
||||||
view: Annotated[str, typer.Option("-v", "--view", help="saved view")] = "default",
|
view: Annotated[str, typer.Option("-v", "--view", help="saved view")] = "default",
|
||||||
):
|
):
|
||||||
tui.run(view)
|
initialize_db()
|
||||||
|
tasks.run(view)
|
||||||
|
|
||||||
|
|
||||||
@app.command()
|
@app.command()
|
||||||
|
@ -7,13 +7,13 @@ from textual.widgets import (
|
|||||||
)
|
)
|
||||||
from textual.containers import Container
|
from textual.containers import Container
|
||||||
|
|
||||||
from .utils import (
|
from ..utils import (
|
||||||
remove_rich_tag,
|
remove_rich_tag,
|
||||||
filter_to_string,
|
filter_to_string,
|
||||||
advance_enum_val,
|
advance_enum_val,
|
||||||
get_text_from_editor,
|
get_text_from_editor,
|
||||||
)
|
)
|
||||||
from .tui_keybindings import KeyBindingsScreen
|
from .keymodal import KeyModal
|
||||||
|
|
||||||
|
|
||||||
class NotifyValidationError(Exception):
|
class NotifyValidationError(Exception):
|
||||||
@ -285,7 +285,7 @@ class TableEditor(App):
|
|||||||
cconf = self._active_column_config()
|
cconf = self._active_column_config()
|
||||||
if cconf.filterable:
|
if cconf.filterable:
|
||||||
return
|
return
|
||||||
cur_filter_val = self.filters.get(cconf.name) or ""
|
cur_filter_val = self.filters.get(cconf.field) or ""
|
||||||
self._show_input("filter", cur_filter_val)
|
self._show_input("filter", cur_filter_val)
|
||||||
self.table.cursor_type = "column"
|
self.table.cursor_type = "column"
|
||||||
|
|
||||||
@ -299,7 +299,7 @@ class TableEditor(App):
|
|||||||
if self.table.cursor_row is None or self.table.cursor_column == 0:
|
if self.table.cursor_row is None or self.table.cursor_column == 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
self._save_crefresh_data()
|
self._save_cursor()
|
||||||
current_value = self.table.get_cell_at(
|
current_value = self.table.get_cell_at(
|
||||||
(self.table.cursor_row, self.table.cursor_column)
|
(self.table.cursor_row, self.table.cursor_column)
|
||||||
)
|
)
|
||||||
@ -334,7 +334,7 @@ class TableEditor(App):
|
|||||||
self.refresh_data(restore_cursor=False)
|
self.refresh_data(restore_cursor=False)
|
||||||
elif self.mode == "filter":
|
elif self.mode == "filter":
|
||||||
cconf = self._active_column_config()
|
cconf = self._active_column_config()
|
||||||
self.filters[cconf.name] = event.value
|
self.filters[cconf.field] = event.value
|
||||||
self.refresh_data(restore_cursor=False)
|
self.refresh_data(restore_cursor=False)
|
||||||
self.table.cursor_type = "cel"
|
self.table.cursor_type = "cel"
|
||||||
elif self.mode == "sort":
|
elif self.mode == "sort":
|
||||||
@ -350,12 +350,12 @@ class TableEditor(App):
|
|||||||
row, col = self.saved_cursor_pos
|
row, col = self.saved_cursor_pos
|
||||||
item_id = int(self.table.get_cell_at((row, 0)))
|
item_id = int(self.table.get_cell_at((row, 0)))
|
||||||
cconf = self.TABLE_CONFIG[col]
|
cconf = self.TABLE_CONFIG[col]
|
||||||
field = cconf.name
|
field = cconf.field
|
||||||
update_data = {}
|
update_data = {}
|
||||||
|
|
||||||
# preprocess/validate the field being saved
|
# preprocess/validate the field being saved
|
||||||
try:
|
try:
|
||||||
update_data[field] = cconf.preprocess(new_value)
|
update_data[field] = cconf.preprocessor(new_value)
|
||||||
self.update_item_callback(item_id, **update_data)
|
self.update_item_callback(item_id, **update_data)
|
||||||
self.refresh_data()
|
self.refresh_data()
|
||||||
except NotifyValidationError as e:
|
except NotifyValidationError as e:
|
||||||
@ -367,4 +367,4 @@ class TableEditor(App):
|
|||||||
self.action_cancel_edit()
|
self.action_cancel_edit()
|
||||||
|
|
||||||
def action_show_keys(self):
|
def action_show_keys(self):
|
||||||
self.push_screen(KeyBindingsScreen())
|
self.push_screen(KeyModal())
|
@ -3,7 +3,7 @@ from rich.table import Table
|
|||||||
from textual.widgets import Static
|
from textual.widgets import Static
|
||||||
|
|
||||||
|
|
||||||
class KeyBindingsScreen(ModalScreen):
|
class KeyModal(ModalScreen):
|
||||||
CSS = """
|
CSS = """
|
||||||
KeyBindingsScreen {
|
KeyBindingsScreen {
|
||||||
align: center middle;
|
align: center middle;
|
@ -2,7 +2,7 @@ import json
|
|||||||
from textual.widgets import Input
|
from textual.widgets import Input
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from .controller import (
|
from ..controller import (
|
||||||
get_task,
|
get_task,
|
||||||
get_tasks,
|
get_tasks,
|
||||||
add_task,
|
add_task,
|
||||||
@ -11,13 +11,12 @@ from .controller import (
|
|||||||
save_view,
|
save_view,
|
||||||
get_saved_view,
|
get_saved_view,
|
||||||
)
|
)
|
||||||
from .db import initialize_db
|
from ..utils import (
|
||||||
from .utils import (
|
|
||||||
get_colored_category,
|
get_colored_category,
|
||||||
get_colored_status,
|
get_colored_status,
|
||||||
get_colored_date,
|
get_colored_date,
|
||||||
)
|
)
|
||||||
from .tui_editor import (
|
from .editor import (
|
||||||
TableEditor,
|
TableEditor,
|
||||||
TableColumnConfig,
|
TableColumnConfig,
|
||||||
NotifyValidationError,
|
NotifyValidationError,
|
Loading…
Reference in New Issue
Block a user