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/internal/application/ProgressTargets.dart'; import '../../about/internal/application/RoutineRunRecord.dart'; import '../../utils/ObjectConvertors.dart'; import '../../utils/ProgressEngine.dart'; import '../parent/ParentViewModel.dart'; import 'ConnectProgress.dart'; class ViewProgress extends ParentViewModel { ConnectProgress connection; ViewProgress(super.context, this.connection); /// The runs and targets are on the device, so there is no network guard /// or spinner. Until a target is saved, the schedule stands in for it. void initialise() async { final List records = await getDataManager().getRunLog(); final ProgressTargets targets = await getDataManager().getProgressTargets(); if (!targets.set) { try { final response = await getDataManager().getMyRoutines(HistoryRequest( query: PageAndSort( sort: Sort('asc', 'startMinute'), page: Pageable(0, 0, 50, 0), ), )); final int scheduled = ProgressEngine.scheduledPerWeek( getRoutineChainList(response.data)); if (scheduled > 0) { targets.routinesPerWeek = scheduled; } } catch (e) { // Offline: the default target stands. } } connection.onProgressLoaded(records, targets); } }