Skip to content

Commit

Permalink
🚧 Add initial Board ListView
Browse files Browse the repository at this point in the history
  • Loading branch information
Zaloog committed Nov 10, 2024
1 parent 8224107 commit 6ac536a
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 17 deletions.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ ktui = "kanban_tui.__main__:cli"

[tool.pytest.ini_options]
asyncio_mode = "auto"
asyncio_default_fixture_loop_scope = "function"
addopts = "--cov src/kanban_tui --cov-report term-missing --verbose --color=yes"# -n 4 --dist=loadgroup"
asyncio_default_fixture_loop_scope = "file"
addopts = "--cov src/kanban_tui --cov-report term-missing --verbose --color=yes -n 4 --dist=loadgroup"
testpaths = ["tests"]

[build-system]
Expand Down
19 changes: 15 additions & 4 deletions src/kanban_tui/assets/style.tcss
Original file line number Diff line number Diff line change
Expand Up @@ -284,15 +284,26 @@ ModalBoardOverviewScreen {
align:center middle;
content-align:center middle;

Label{
#label_header{
width:1fr;
height: auto;
text-align:center;
padding:0 0 1 0;

VerticalScroll{
width:1fr;
height: auto;
}
BoardList{
# border:outer $success;
}
BoardListItem{
height:auto;
padding:1 0;
content-align:center middle;

Label{
text-align:left;
}


}
Button {
width: 1fr;
Expand Down
4 changes: 4 additions & 0 deletions src/kanban_tui/classes/board.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ class Board(BaseModel):
name: str
icon: str | None = None
creation_date: datetime = datetime.now().replace(microsecond=0)

@property
def full_name(self):
return f"{self.icon} {self.name}"
9 changes: 8 additions & 1 deletion src/kanban_tui/modal/modal_board_screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def compose(self) -> Iterable[Widget]:
validators=[ValidBoard()],
id="input_board_name",
)
# yield CreationDateInfo()
yield Label(
f"Board created at: {datetime.now().replace(microsecond=0)}",
id="label_create_date",
Expand Down Expand Up @@ -105,6 +104,7 @@ class ModalBoardOverviewScreen(ModalScreen):
BINDINGS = [
Binding("escape", "app.pop_screen", "Close"),
Binding("n", "new_board", "New Board", show=True, priority=True),
Binding("e", "edit_board", "Edit Board", show=True, priority=True),
]

def _on_mount(self, event: Mount) -> None:
Expand All @@ -123,5 +123,12 @@ def compose(self) -> Iterable[Widget]:
yield Footer(show_command_palette=False)
return super().compose()

@on(Button.Pressed, "#btn_create_board")
def action_new_board(self) -> None:
self.app.push_screen(ModalNewBoardScreen(), callback=None)

def action_edit_board(self) -> None:
highlighted_board = self.query_one(BoardList).highlighted_child.board
self.app.push_screen(
ModalNewBoardScreen(board=highlighted_board), callback=None
)
4 changes: 4 additions & 0 deletions src/kanban_tui/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,10 @@ def create_demo_tasks(database_path: Path, config_path: Path):
create_new_board_db(
name="Demo Board No2", icon=":sparkles:", database=database_path
)
for i in range(3, 6):
create_new_board_db(
name=f"Demo Board No{i}", icon=":sparkles:", database=database_path
)

# Ready
create_new_task_db(
Expand Down
26 changes: 16 additions & 10 deletions src/kanban_tui/widgets/modal_board_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
if TYPE_CHECKING:
from kanban_tui.app import KanbanTui

from textual.containers import VerticalScroll
from textual.binding import Binding
from textual.widget import Widget
from textual.widgets import ListView, ListItem, Label

Expand All @@ -12,28 +12,34 @@
# Or use Datatable?


class BoardList(VerticalScroll):
class BoardList(ListView):
app: "KanbanTui"

def compose(self) -> Iterable[Widget]:
self.id = "board_list"
BINDINGS = [
Binding(key="j", action="cursor_down", show=False),
Binding(key="k", action="cursor_up", show=False),
]

yield ListView(
*[BoardListItem(board=board) for board in self.app.board_list],
)
def __init__(self) -> None:
children = [BoardListItem(board=board) for board in self.app.board_list]
initial_index = self.app.cfg.active_board - 1

return super().compose()
super().__init__(*children, initial_index=initial_index, id="board_list")

def on_mount(self):
self.query_one(ListView).index = None
self.focus()


class BoardListItem(ListItem):
app: "KanbanTui"

def __init__(self, board: Board) -> None:
self.board = board
super().__init__(id=f"listitem_board_{self.board.board_id}")

def compose(self) -> Iterable[Widget]:
yield Label(self.board.name)
if self.board.board_id == self.app.cfg.active_board:
self.styles.background = "green"
yield Label(self.board.full_name)

return super().compose()

0 comments on commit 6ac536a

Please sign in to comment.