From a28c9ca3bdc932b5f072574172e9562760f8c7f1 Mon Sep 17 00:00:00 2001 From: Andrei Markin Date: Thu, 1 Feb 2024 01:27:36 +0400 Subject: [PATCH] Support creating notes from CLI * `terka note sprint` will create a note for a given sprint_id --- README.md | 2 +- terka/domain/commands.py | 18 +++++++++++++----- terka/presentations/text_ui/ui.py | 23 +++++++++++++++++------ terka/service_layer/handlers.py | 16 ++++++++++++++++ 4 files changed, 47 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index c647c78..85149a9 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Key features: To install `terka` run the following command: -`pip install terka` +`pip install terka[all]` > install the latest development version with `pip install -e git+https://github.com/AndreyMarkinPPC/terka.git#egg=terka[all]` It will make `terka` command available in your shell. diff --git a/terka/domain/commands.py b/terka/domain/commands.py index 79f2d4b..d920f2b 100644 --- a/terka/domain/commands.py +++ b/terka/domain/commands.py @@ -48,7 +48,9 @@ def format_date(attributes: dict, date_attribute: str): @dataclass class Note(Command): id: int + name: str text: str + created_by: int | None = None @dataclass @@ -104,11 +106,6 @@ class Start(Command): ... -@dataclass -class Create(Command): - ... - - @dataclass class List(Command): ... @@ -322,6 +319,11 @@ class ListProject(List): ... +@dataclass +class NoteProject(Note): + ... + + @dataclass class GetTask(Get): ... @@ -396,6 +398,11 @@ class ListSprint(List): ... +@dataclass +class NoteSprint(Note): + ... + + # EPIC @dataclass class CreateEpic(Command): @@ -503,6 +510,7 @@ class CreateWorkspace(Command): class DeleteWorkspace(Delete): ... + @dataclass class ListWorkspace(List): ... diff --git a/terka/presentations/text_ui/ui.py b/terka/presentations/text_ui/ui.py index c03ab58..a5da277 100644 --- a/terka/presentations/text_ui/ui.py +++ b/terka/presentations/text_ui/ui.py @@ -607,10 +607,15 @@ def compose(self) -> ComposeResult: variant="success", classes="new_entity") table = DataTable(id="project_notes_table") - for column in ("id", "text"): + for column in ("id", "date", "name"): table.add_column(column, key=f"note_{column}") - for note in self.entity.notes: - table.add_row(str(note.id), note.name, key=note.id) + for note in sorted(self.entity.notes, + key=lambda x: x.date, + reverse=True): + table.add_row(str(note.id), + note.date.strftime("%Y-%m-%d"), + note.name, + key=note.id) yield table with TabPane("Time", id="time"): plotext = PlotextPlot(classes="plotext") @@ -795,9 +800,15 @@ def compose(self) -> ComposeResult: yield table with TabPane("Notes", id="notes"): table = DataTable(id="sprint_notes_table") - table.add_columns("id", "text") - for task in self.entity.notes: - table.add_row(str(task.id), task.name) + for column in ("id", "date", "name"): + table.add_column(column, key=f"note_{column}") + for note in sorted(self.entity.notes, + key=lambda x: x.date, + reverse=True): + table.add_row(str(note.id), + note.date.strftime("%Y-%m-%d"), + note.name, + key=note.id) yield table with TabPane("Time", id="time"): plotext = PlotextPlot(classes="plotext") diff --git a/terka/service_layer/handlers.py b/terka/service_layer/handlers.py index 34cea77..8f5a0e2 100644 --- a/terka/service_layer/handlers.py +++ b/terka/service_layer/handlers.py @@ -199,6 +199,22 @@ def list(cmd: commands.ListSprint, bus.printer.console.print_sprint( sprints, printer.PrintOptions.from_kwargs(**context)) + @register(cmd=commands.NoteSprint) + def note(cmd: commands.NoteSprint, + bus: "messagebus.MessageBus", + context: dict = {}) -> int: + if not cmd: + cmd, context = templates.create_command_from_editor( + entities.notes.SprintNote, type(cmd)) + with bus.uow as uow: + cmd = convert_user(cmd, bus, "created_by") + note = entities.note.SprintNote(**asdict(cmd)) + uow.tasks.add(note) + uow.commit() + note_id = note.id + bus.printer.console.print_new_object(note) + return note_id + class SprintEventHandlers: