Skip to content

Commit

Permalink
Nice stuff in the calendar show
Browse files Browse the repository at this point in the history
  • Loading branch information
horia141 committed Jul 10, 2024
1 parent a6a3b93 commit fa86f41
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 2 deletions.
132 changes: 131 additions & 1 deletion src/cli/jupiter/cli/command/calendar_show.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
"""Command for loading a calendar."""
from jupiter.cli.command.command import LoggedInReadonlyCommand
from jupiter.cli.command.rendering import (
date_with_label_to_rich_text,
entity_name_to_rich_text,
period_to_rich_text,
person_birthday_to_rich_text,
time_in_day_to_rich_text,
)
from jupiter.core.use_cases.application.calendar.load_for_date_and_period import (
CalendarLoadForDateAndPeriodResult,
CalendarLoadForDateAndPeriodUseCase,
)
from jupiter.core.use_cases.infra.use_cases import AppLoggedInReadonlyUseCaseContext
from rich.console import Console
from rich.text import Text
from rich.tree import Tree


class CalendarShow(
Expand All @@ -21,4 +30,125 @@ def _render_result(
context: AppLoggedInReadonlyUseCaseContext,
result: CalendarLoadForDateAndPeriodResult,
) -> None:
console.print(result)
header_text = Text("📅 ")
header_text.append(period_to_rich_text(result.period))
header_text.append(" calendar for")
header_text.append(date_with_label_to_rich_text(result.right_now, ""))

rich_tree = Tree(header_text)

# Process the full days events

full_day_events_tree = Tree("Full Days Events", guide_style="bold bright_blue")

for person_entry in sorted(
result.person_entries,
key=lambda pe: (
pe.birthday_time_event.start_date,
pe.birthday_time_event.end_date,
),
):
person = person_entry.person

person_text = Text("Birthday for ")
person_text.append(entity_name_to_rich_text(person.name))
person_text.append(" ")
person_text.append(person_birthday_to_rich_text(person.birthday))

full_day_events_tree.add(person_text)

for schedule_event_full_days_entry in sorted(
result.schedule_event_full_days_entries,
key=lambda se: (se.time_event.start_date, se.time_event.end_date),
):
schedule_event_full_days = schedule_event_full_days_entry.event
time_event = schedule_event_full_days_entry.time_event
shcedule_stream = schedule_event_full_days_entry.stream

schedule_event_full_days_text = Text("")
schedule_event_full_days_text.append(
entity_name_to_rich_text(schedule_event_full_days.name)
)
schedule_event_full_days_text.append(" ")
schedule_event_full_days_text.append(
date_with_label_to_rich_text(time_event.start_date, "from")
)
schedule_event_full_days_text.append(" ")
schedule_event_full_days_text.append(
date_with_label_to_rich_text(time_event.end_date, "to")
)
schedule_event_full_days_text.append(" for stream ")
schedule_event_full_days_text.append(
entity_name_to_rich_text(shcedule_stream.name)
)

full_day_events_tree.add(schedule_event_full_days_text)

rich_tree.add(full_day_events_tree)

# Process the in day events

in_day_events_tree = Tree("In Day Events", guide_style="bold bright_blue")

for inbox_task_entry in sorted(
result.inbox_task_entries,
key=lambda it: (
it.time_event[0].start_date,
it.time_event[0].start_time_in_day,
it.time_event[0].duration_mins,
),
):
inbox_task = inbox_task_entry.inbox_task
time_event = inbox_task_entry.time_event

inbox_task_text = Text("")
inbox_task_text.append(entity_name_to_rich_text(inbox_task.name))
inbox_task_text.append(" ")
inbox_task_text.append(
date_with_label_to_rich_text(time_event.start_date, "from")
)
inbox_task_text.append(" ")
inbox_task_text.append(
date_with_label_to_rich_text(time_event.end_date, "to")
)

in_day_events_tree.add(inbox_task_text)

for schedule_event_in_day_entry in sorted(
result.schedule_event_in_day_entries,
key=lambda se: (
se.time_event.start_date,
se.time_event.start_time_in_day,
se.time_event.duration_mins,
),
):
schedule_event_in_day = schedule_event_in_day_entry.event
time_event = schedule_event_in_day_entry.time_event
schedule_stream = schedule_event_in_day_entry.stream

schedule_event_in_day_text = Text("")
schedule_event_in_day_text.append(
entity_name_to_rich_text(schedule_event_in_day.name)
)
schedule_event_in_day_text.append(" ")
schedule_event_in_day_text.append(
date_with_label_to_rich_text(time_event.start_date, "from")
)
schedule_event_in_day_text.append(" at ")
schedule_event_in_day_text.append(
time_in_day_to_rich_text(time_event.start_time_in_day)
)
schedule_event_in_day_text.append(
f" that lasts for {time_event.duration_mins} minutes"
)

schedule_event_in_day_text.append(" for stream ")
schedule_event_in_day_text.append(
entity_name_to_rich_text(schedule_stream.name)
)

in_day_events_tree.add(schedule_event_in_day_text)

rich_tree.add(in_day_events_tree)

console.print(rich_tree)
8 changes: 7 additions & 1 deletion src/cli/jupiter/cli/command/rendering.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
from jupiter.core.domain.core.recurring_task_due_at_month import RecurringTaskDueAtMonth
from jupiter.core.domain.core.recurring_task_period import RecurringTaskPeriod
from jupiter.core.domain.core.recurring_task_skip_rule import RecurringTaskSkipRule
from jupiter.core.domain.core.time_in_day import TimeInDay
from jupiter.core.domain.core.timezone import Timezone
from jupiter.core.domain.named_entity_tag import NamedEntityTag
from jupiter.core.domain.sync_target import SyncTarget
Expand Down Expand Up @@ -385,7 +386,7 @@ def due_date_to_rich_text(due_date: ADate) -> Text:

def date_with_label_to_rich_text(due_date: ADate, label: str) -> Text:
"""Transform a due date into text."""
return Text(f"{label} ").append(str(due_date), style="underline")
return Text(f"{label} ").append(str(due_date), style="blue underline")


def project_to_rich_text(project_name: ProjectName) -> Text:
Expand Down Expand Up @@ -657,3 +658,8 @@ def time_plan_activity_feasability_to_rich_text(
) -> Text:
"""Transform a time plan feasaibility to rich text."""
return Text(str(feasability.value).capitalize(), style="red")


def time_in_day_to_rich_text(time_in_day: TimeInDay) -> Text:
"""Transform a time in day to rich text."""
return Text(str(time_in_day), style="green")
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,21 @@ async def find_all_between(
.where(self._table.c.time_event_domain_ref_id == parent_ref_id.as_int())
.where(
or_(
# Start date is in range
and_(
self._table.c.start_date >= start_date.the_date,
self._table.c.start_date <= end_date.the_date,
),
# End date is in range
and_(
self._table.c.end_date >= start_date.the_date,
self._table.c.end_date <= end_date.the_date,
),
# Start and end date span the range
and_(
self._table.c.start_date <= start_date.the_date,
self._table.c.end_date >= end_date.the_date,
),
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ class PersonEntry(UseCaseResultBase):
class CalendarLoadForDateAndPeriodResult(UseCaseResultBase):
"""Result."""

right_now: ADate
period: RecurringTaskPeriod
schedule_event_in_day_entries: list[ScheduleInDayEventEntry]
schedule_event_full_days_entries: list[ScheduleFullDaysEventEntry]
inbox_task_entries: list[InboxTaskEntry]
Expand Down Expand Up @@ -242,6 +244,8 @@ async def _perform_transactional_read(
]

return CalendarLoadForDateAndPeriodResult(
right_now=args.right_now,
period=args.period,
schedule_event_in_day_entries=schedule_event_in_day_entries,
schedule_event_full_days_entries=schedule_event_full_days_entries,
inbox_task_entries=inbox_task_entries,
Expand Down

0 comments on commit fa86f41

Please sign in to comment.