Files
GroundedHelper/frontend/lib/Grounded/see/goal/ViewGoalDetail.dart
alvocool 1a5867a98f Add routines module and full goal management
Routines: workout, meditation and must-do routines with timed, rep and
tick steps, sets and rest. A library screen, a builder with templates
and drag-to-reorder steps, and a full-screen player that auto-advances
timed phases, counts backgrounding and logs broken chains as partial.

Goals: a goal editor (deadline, colour, category, default class, archive),
routines linked to goals, and a goal field on tasks and routines. Tasks
added from inside a goal are now actually attached to it via parentId.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KhQh614DMeYoQEH9SoMRUw
2026-11-02 08:45:41 +03:00

84 lines
2.7 KiB
Dart

import '../../about/external/data/Commitment.dart';
import '../../about/external/data/Goal.dart';
import '../../about/external/data/RoutineChain.dart';
import '../../about/external/data/pages/request/HistoryRequest.dart';
import '../../about/external/data/pages/request/PageAndSort.dart';
import '../../about/external/data/pages/request/Pageable.dart';
import '../../about/external/data/pages/request/Sort.dart';
import '../../about/external/initial/CompletionRequest.dart';
import '../../about/external/initial/IdRequest.dart';
import '../../utils/ObjectConvertors.dart';
import '../parent/ParentViewModel.dart';
import 'ConnectGoalDetail.dart';
class ViewGoalDetail extends ParentViewModel {
ConnectGoalDetail connection;
ViewGoalDetail(super.context, this.connection);
void loadTasks(Goal goal) async {
if (!await hasNetwork(() => loadTasks(goal))) return;
showLoading("Loading ${goal.title}");
try {
final response =
await getDataManager().getGoalTasks(IdRequest(id: goal.id ?? ""));
closeLoading();
connection.onGoalLoaded(goal, getCommitmentList(response.data));
loadRoutines(goal);
} catch (e) {
handleError(e, () => loadTasks(goal), () => dismissError(), "Retry");
}
}
/// Routines are fetched with the library and filtered to this goal, so a
/// routine moved between goals shows up in the right place immediately.
void loadRoutines(Goal goal) async {
try {
final response = await getDataManager().getMyRoutines(HistoryRequest(
query: PageAndSort(
sort: Sort('asc', 'startMinute'),
page: Pageable(0, 0, 50, 0),
),
));
final List<RoutineChain> routines = getRoutineChainList(response.data)
.where((routine) => routine.goalId == goal.id)
.toList();
connection.onRoutinesLoaded(routines);
} catch (e) {
handleError(e, () => loadRoutines(goal), () => dismissError(), "Retry");
}
}
/// Completes a task straight from the goal list.
void tick(Commitment task) async {
if (!await hasNetwork(() => tick(task))) return;
try {
await getDataManager().completeCommitmentEntry(CompletionRequest(
commitmentId: task.id ?? "",
proofType: task.proofType.name,
));
connection.onTaskTicked(task, task.wouldBeLate);
} catch (e) {
connection.onTickFailed(task);
handleError(e, () => tick(task), () => dismissError(), "Retry");
}
}
/// Stashes the task as the active one before the runner opens, so the
/// ongoing notification and any relaunch land back on the right thing.
void startTask(Commitment task) async {
await getDataManager().setActiveCommitment(task);
connection.onTaskReady(task);
}
}