Skip to content

Commit

Permalink
Merge pull request #206 from dooit-org/develop
Browse files Browse the repository at this point in the history
v3.0.2
  • Loading branch information
kraanzu authored Nov 15, 2024
2 parents 592b3e3 + 45e21b6 commit c38bd6d
Show file tree
Hide file tree
Showing 14 changed files with 193 additions and 172 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 3.0.3

### Fixed

- Recurrence not working as expected (https://github.com/dooit-org/dooit/issues/204)
- Dooit crash on item delete and then addition (https://github.com/dooit-org/dooit/issues/205)
- Stuck on CONFIRM mode if deletions are fast
- Messed up column widths on sudden width changes
- Values not getting parsed because of whitespace

## 3.0.2

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion dooit/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from platformdirs import user_data_dir, user_config_dir

OLD_CONFIG = Path(user_data_dir("dooit")) / "todo.yaml"
VERSION = "3.0.2"
VERSION = "3.0.3"


def run_dooit():
Expand Down
16 changes: 16 additions & 0 deletions dooit/api/hooks/update_hooks.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from datetime import datetime
from sqlalchemy import event, update
from ..todo import Todo

Expand Down Expand Up @@ -56,3 +57,18 @@ def update_parent_completed(todo: Todo):
)

connection.execute(query)


@event.listens_for(Todo, "before_update")
def update_due_for_recurrence(mapper, connection, todo: Todo):
if todo.recurrence is None:
return

if todo.due is None:
todo.due = datetime.now()

if todo.pending:
return

todo.pending = True
todo.due += todo.recurrence
40 changes: 14 additions & 26 deletions dooit/api/todo.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from functools import cmp_to_key
from typing import TYPE_CHECKING, Optional, Union
from datetime import datetime, timedelta
from typing import List
from sqlalchemy import ForeignKey, select, nulls_last
from sqlalchemy.orm import Mapped, mapped_column, relationship
from sqlalchemy.orm import Mapped, mapped_column, relationship, validates
from .model import DooitModel
from .manager import manager

Expand All @@ -12,29 +11,6 @@
from dooit.api.workspace import Workspace


def _custom_sort_by_status(x: "Todo", y: "Todo") -> int:
if x.status == y.status:
d1 = x.due or datetime.max
d2 = y.due or datetime.max
if d1 < d2:
return 1
elif d1 > d2:
return -1
else:
return 0

values = {"completed": 0, "pending": 1, "overdue": 2}
s1 = values[x.status]
s2 = values[y.status]

if s1 < s2:
return 1
elif s1 > s2:
return -1
else:
return 0


class Todo(DooitModel):
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
order_index: Mapped[int] = mapped_column(default=-1)
Expand Down Expand Up @@ -71,6 +47,13 @@ class Todo(DooitModel):
order_by=order_index,
)

@validates("recurrence")
def validate_pending(self, key, value):
if value is not None:
self.pending = True

return value

@classmethod
def from_id(cls, _id: str) -> "Todo":
_id = _id.lstrip("Todo_")
Expand Down Expand Up @@ -132,7 +115,11 @@ def sort_siblings(self, field: str):
else:
items = sorted(
self.siblings,
key=cmp_to_key(_custom_sort_by_status),
key=lambda x: (
not x.pending,
x.due or datetime.max,
x.order_index,
),
)

for index, todo in enumerate(items):
Expand All @@ -150,6 +137,7 @@ def _add_sibling(self) -> "Todo":
parent_todo=self.parent_todo,
parent_workspace=self.parent_workspace,
)
todo.save()
return todo

# ----------- HELPER FUNCTIONS --------------
Expand Down
1 change: 1 addition & 0 deletions dooit/api/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ def _add_sibling(self) -> "Workspace":
workspace = Workspace(
parent_workspace=self.parent_workspace,
)
workspace.save()
return workspace

def save(self) -> None:
Expand Down
5 changes: 5 additions & 0 deletions dooit/ui/tui.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ def shutdown(self, event: ShutDown):
@on(ModeChanged)
def change_status(self, event: ModeChanged):
self._mode = event.mode
if event.mode == "NORMAL":
self.workspace_tree.refresh_options()
todos_tree = self.api.vars.todos_tree
if todos_tree:
todos_tree.refresh_options()

@on(_QuitApp)
async def quit_app(self):
Expand Down
3 changes: 2 additions & 1 deletion dooit/ui/widgets/bars/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ def switcher(self) -> "BarSwitcher":
assert isinstance(parent, BarSwitcher)
return parent

def on_unmount(self):
async def on_unmount(self):
self.post_message(ModeChanged("NORMAL"))
self.switcher.current = "status_bar"

def perform_action(self, cancel: bool):
Expand Down
1 change: 1 addition & 0 deletions dooit/ui/widgets/inputs/simple_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def reset(self) -> str:
return self.value

def stop_edit(self) -> None:
self._value = self.value.strip()
try:
self.model_value = self._typecast_value(self.value)
self.model.save()
Expand Down
6 changes: 5 additions & 1 deletion dooit/ui/widgets/trees/model_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,11 @@ def add_sibling(self):
@require_confirmation
@refresh_tree
def _remove_node(self):
self.current_model.drop()
model = self.current_model

self._renderers.pop(model.uuid)
self.expanded_nodes.pop(model.uuid)
model.drop()

@require_highlighted_node
def remove_node(self):
Expand Down
Loading

0 comments on commit c38bd6d

Please sign in to comment.