Skip to content

Commit

Permalink
Merged branch feature/projects-in-timeplans into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
horia141 committed Jun 5, 2024
1 parent 0af0f40 commit 6abaf0d
Show file tree
Hide file tree
Showing 8 changed files with 385 additions and 223 deletions.
1 change: 1 addition & 0 deletions src/core/jupiter/core/domain/inbox_tasks/inbox_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -1111,6 +1111,7 @@ async def find_completed_in_range(
allow_archived: bool,
filter_start_completed_date: ADate,
filter_end_completed_date: ADate,
filter_include_sources: Iterable[InboxTaskSource],
filter_exclude_ref_ids: Iterable[EntityId] | None = None,
) -> list[InboxTask]:
"""Find all completed inbox tasks in a time range."""
2 changes: 2 additions & 0 deletions src/core/jupiter/core/repository/sqlite/domain/inbox_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ async def find_completed_in_range(
allow_archived: bool,
filter_start_completed_date: ADate,
filter_end_completed_date: ADate,
filter_include_sources: Iterable[InboxTaskSource],
filter_exclude_ref_ids: Iterable[EntityId] | None = None,
) -> list[InboxTask]:
"""find all completed inbox tasks in a time range."""
Expand All @@ -156,6 +157,7 @@ async def find_completed_in_range(
s.value for s in InboxTaskStatus.all_completed_statuses()
)
)
.where(self._table.c.source.in_(s.value for s in filter_include_sources))
.where(self._table.c.completed_time.is_not(None))
.where(self._table.c.completed_time >= start_completed_time.the_ts)
.where(self._table.c.completed_time <= end_completed_time.the_ts)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ async def _perform_transactional_read(
TimePlanActivity.target_inbox_task,
TimePlanActivity.target_big_plan,
allow_archived=args.allow_archived,
allow_subentity_archived=args.allow_archived,
)

if not workspace.is_feature_available(WorkspaceFeature.BIG_PLANS):
Expand Down
17 changes: 13 additions & 4 deletions src/core/jupiter/core/use_cases/time_plans/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,23 @@ async def _perform_transactional_read(

completed_nontarget_inbox_tasks = None
if args.include_completed_nontarget and target_inbox_tasks is not None:

# The rule here should be:
# If this is a inbox task or big plan include it always
# If this is a generated one, then:
# If the recurring_task_period is strictly higher than the time plan is we include it
# If the recurring_task_period is equal or lower than the time plan one we skip it
# expressed as: (it.source in (user, big-plan)) or (it.period in (*all_higher_periods)
# But this is hard to express cause inbox_tasks don't yet remember the period
# of their source entity. Inference from the timeline is hard in SQL, etc.
completed_nontarget_inbox_tasks = await uow.get(
InboxTaskRepository
).find_completed_in_range(
parent_ref_id=inbox_task_collection.ref_id,
allow_archived=True,
filter_start_completed_date=schedule.first_day,
filter_end_completed_date=schedule.end_day,
filter_include_sources=[InboxTaskSource.USER, InboxTaskSource.BIG_PLAN],
filter_exclude_ref_ids=[it.ref_id for it in target_inbox_tasks],
)

Expand Down Expand Up @@ -153,9 +163,9 @@ async def _perform_transactional_read(
target_inbox_tasks_by_ref_id = {
it.ref_id: it for it in cast(list[InboxTask], target_inbox_tasks)
}
target_big_plans_by_ref_id = {
bp.ref_id: bp for bp in cast(list[BigPlan], target_big_plans)
}
target_big_plans_by_ref_id = (
{bp.ref_id: bp for bp in target_big_plans} if target_big_plans else {}
)
activities_by_big_plan_ref_id: defaultdict[
EntityId, list[EntityId]
] = defaultdict(list)
Expand All @@ -169,7 +179,6 @@ async def _perform_transactional_read(
if activity.kind == TimePlanActivityKind.FINISH:
activity_doneness[activity.ref_id] = inbox_task.is_completed
elif activity.kind == TimePlanActivityKind.MAKE_PROGRESS:
print(time_plan.start_date, time_plan.end_date, inbox_task)
modified_in_time_plan = (
inbox_task.is_working_or_more
and time_plan.start_date.to_timestamp_at_start_of_day()
Expand Down
17 changes: 7 additions & 10 deletions src/webui/app/components/infra/layout/nesting-aware-block.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Stack } from "@mui/system";
import { Form } from "@remix-run/react";
import type { PropsWithChildren } from "react";
import { useBigScreen } from "~/rendering/use-big-screen";

Expand All @@ -22,14 +21,12 @@ export function NestingAwareBlock(
}

return (
<Form method="post">
<Stack
spacing={2}
useFlexGap
sx={{ paddingLeft: "1rem", paddingRight: "1rem" }}
>
{props.children}
</Stack>
</Form>
<Stack
spacing={2}
useFlexGap
sx={{ paddingLeft: "1rem", paddingRight: "1rem" }}
>
{props.children}
</Stack>
);
}
30 changes: 15 additions & 15 deletions src/webui/app/logic/domain/time-plan-activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import {
type InboxTask,
type TimePlanActivity,
} from "@jupiter/webapi-client";
import { isCompleted as isBigPlanCompleted } from "./big-plan-status";
import { isCompleted as isInboxTaskCompleted } from "./inbox-task-status";
import { compareTimePlanActivityFeasability } from "./time-plan-activity-feasability";
import { compareTimePlanActivityKind } from "./time-plan-activity-kind";

Expand All @@ -17,22 +15,24 @@ const TIME_PLAN_ACTIVITY_TARGET_MAP = {
export function filterActivitiesByTargetStatus(
timePlanActivities: TimePlanActivity[],
targetInboxTasks: Map<string, InboxTask>,
targetBigPlans: Map<string, BigPlan>
targetBigPlans: Map<string, BigPlan>,
activityDoneness: Record<string, boolean>
): TimePlanActivity[] {
return timePlanActivities.filter((activity) => {
if (activity.target === TimePlanActivityTarget.INBOX_TASK) {
const inboxTask = targetInboxTasks.get(activity.target_ref_id);
if (!inboxTask) {
return false;
}
return !isInboxTaskCompleted(inboxTask.status);
} else {
const bigPlan = targetBigPlans.get(activity.target_ref_id);
if (!bigPlan) {
return false;
}
return !isBigPlanCompleted(bigPlan.status);
if (activityDoneness[activity.ref_id]) {
return false;
}

switch (activity.target) {
case TimePlanActivityTarget.INBOX_TASK:
const inboxTask = targetInboxTasks.get(activity.target_ref_id)!;
return !inboxTask.archived;
case TimePlanActivityTarget.BIG_PLAN:
const bigPlan = targetBigPlans.get(activity.target_ref_id)!;
return !bigPlan.archived;
}

throw new Error("This should not happen");
});
}

Expand Down
Loading

0 comments on commit 6abaf0d

Please sign in to comment.