wt1.1.2 new treeview, bar chart for muscle development
This commit is contained in:
@@ -8,31 +8,34 @@ import 'package:aitrainer_app/service/exercise_plan_service.dart';
|
||||
|
||||
class ExercisePlanRepository {
|
||||
bool newPlan = true;
|
||||
ExercisePlan _exercisePlan;
|
||||
ExercisePlan exercisePlan;
|
||||
LinkedHashMap<int, ExercisePlanDetail> exercisePlanDetails =
|
||||
LinkedHashMap<int, ExercisePlanDetail>();
|
||||
LinkedHashMap<int, ExercisePlanDetail> _origExercisePlanDetails =
|
||||
LinkedHashMap<int, ExercisePlanDetail>();
|
||||
int _customerId = 0;
|
||||
int customerId = 0;
|
||||
ExercisePlanDetail actualPlanDetail;
|
||||
|
||||
void setCustomerId( int customerId ) {
|
||||
this._customerId = customerId;
|
||||
this.customerId = customerId;
|
||||
}
|
||||
|
||||
int getCustomerId() {
|
||||
return this._customerId;
|
||||
int getCustomerId() => customerId;
|
||||
|
||||
void setExercisePlan(ExercisePlan plan) {
|
||||
this.exercisePlan = plan;
|
||||
}
|
||||
|
||||
void addExerciseTypeToPlan(ExerciseType exerciseType) {
|
||||
setActualPlanDetail(exerciseType);
|
||||
}
|
||||
|
||||
void addToPlan() {
|
||||
ExercisePlan getExercisePlan() => exercisePlan;
|
||||
|
||||
void addDetailToPlan() {
|
||||
actualPlanDetail.exercisePlanId = exercisePlan.exercisePlanId;
|
||||
exercisePlanDetails[actualPlanDetail.exerciseTypeId] = actualPlanDetail;
|
||||
Cache().addToMyExercisePlanDetails(actualPlanDetail);
|
||||
}
|
||||
|
||||
void setActualPlanDetail(ExerciseType exerciseType) {
|
||||
ExercisePlanDetail getExercisePlanDetailByExerciseId(int exerciseTypeId) => exercisePlanDetails[exerciseTypeId];
|
||||
|
||||
void setActualPlanDetailByExerciseType(ExerciseType exerciseType) {
|
||||
ExercisePlanDetail detail = exercisePlanDetails[exerciseType.exerciseTypeId];
|
||||
if ( detail != null ) {
|
||||
actualPlanDetail = detail;
|
||||
@@ -42,11 +45,14 @@ class ExercisePlanRepository {
|
||||
actualPlanDetail.exerciseType = exerciseType;
|
||||
}
|
||||
|
||||
int getPlanDetailId(int exerciseTypeId) {
|
||||
ExercisePlanDetail detail = exercisePlanDetails[exerciseTypeId];
|
||||
return detail.exercisePlanDetailId;
|
||||
ExercisePlanDetail getActualPlanDetail() => actualPlanDetail;
|
||||
|
||||
void setActualPlanDetail( ExercisePlanDetail detail ) {
|
||||
this.actualPlanDetail = detail;
|
||||
}
|
||||
|
||||
int getPlanDetailId(int exerciseTypeId) => exercisePlanDetails[exerciseTypeId].exercisePlanDetailId;
|
||||
|
||||
String getPlanDetail(int exerciseTypeId) {
|
||||
ExercisePlanDetail detail = exercisePlanDetails[exerciseTypeId];
|
||||
String detailString = "";
|
||||
@@ -70,96 +76,121 @@ class ExercisePlanRepository {
|
||||
exercisePlanDetail.serie = serie;
|
||||
exercisePlanDetail.repeats = repeat;
|
||||
exercisePlanDetail.weightEquation = weight;
|
||||
exercisePlanDetail.change = ExercisePlanDetailChange.update;
|
||||
|
||||
exercisePlanDetails[exerciseType.exerciseTypeId] = exercisePlanDetail;
|
||||
}
|
||||
|
||||
void removeExerciseTypeFromPlan(ExerciseType exerciseType) {
|
||||
exercisePlanDetails.remove(exerciseType.exerciseTypeId);
|
||||
removeExerciseTypeFromPlanByExerciseTypeId(exerciseType.exerciseTypeId);
|
||||
}
|
||||
|
||||
void removeExerciseTypeFromPlanByExerciseTypeId(int exerciseTypeId) {
|
||||
exercisePlanDetails[exerciseTypeId].change = ExercisePlanDetailChange.delete;
|
||||
Cache().deleteMyExercisePlanDetailByExerciseTypeId(exerciseTypeId);
|
||||
}
|
||||
|
||||
Future<void> saveExercisePlan() async {
|
||||
|
||||
if ( _exercisePlan == null ) {
|
||||
if ( exercisePlan == null ) {
|
||||
if ( Cache().userLoggedIn == null ) {
|
||||
throw Exception("please log in");
|
||||
}
|
||||
|
||||
String exercisePlanName;
|
||||
if ( this._customerId == Cache().userLoggedIn.customerId) {
|
||||
if ( this.customerId == Cache().userLoggedIn.customerId) {
|
||||
exercisePlanName = Cache().userLoggedIn.name + " private";
|
||||
} else {
|
||||
exercisePlanName = Cache().getTrainee().name + " " + Cache().getTrainee().firstname + " private";
|
||||
}
|
||||
|
||||
_exercisePlan = ExercisePlan(exercisePlanName, this._customerId);
|
||||
exercisePlan = ExercisePlan(exercisePlanName, this.customerId);
|
||||
}
|
||||
if ( newPlan ) {
|
||||
_exercisePlan.dateAdd = DateTime.now();
|
||||
_exercisePlan.private = true;
|
||||
exercisePlan.dateAdd = DateTime.now();
|
||||
exercisePlan.private = true;
|
||||
ExercisePlan savedExercisePlan =
|
||||
await ExercisePlanApi().saveExercisePlan(_exercisePlan);
|
||||
await ExercisePlanApi().saveExercisePlan(exercisePlan);
|
||||
|
||||
exercisePlanDetails.forEach((exerciseTypeId, exercisePlanDetail) async {
|
||||
LinkedHashMap<int, ExercisePlanDetail> savedExercisePlanDetails = LinkedHashMap();
|
||||
exercisePlanDetails.forEach((exerciseTypeId, exercisePlanDetail) async {
|
||||
exercisePlanDetail.exercisePlanId = savedExercisePlan.exercisePlanId;
|
||||
await ExercisePlanApi().saveExercisePlanDetail(exercisePlanDetail);
|
||||
});
|
||||
ExercisePlanDetail savedDetail = await ExercisePlanApi().saveExercisePlanDetail(exercisePlanDetail);
|
||||
savedExercisePlanDetails[savedDetail.exerciseTypeId] = savedDetail;
|
||||
});
|
||||
|
||||
exercisePlan = savedExercisePlan;
|
||||
exercisePlanDetails = savedExercisePlanDetails;
|
||||
|
||||
} else {
|
||||
|
||||
await ExercisePlanApi().updateExercisePlan(_exercisePlan, _exercisePlan.exercisePlanId);
|
||||
//await ExercisePlanApi().updateExercisePlan(exercisePlan, exercisePlan.exercisePlanId);
|
||||
|
||||
_origExercisePlanDetails.forEach((exerciseTypeId, exercisePlanDetail) async {
|
||||
if (exercisePlanDetails[exercisePlanDetail.exercisePlanDetailId] == null) {
|
||||
exercisePlanDetails.forEach((exerciseTypeId, exercisePlanDetail) async {
|
||||
if ( exercisePlanDetail.change == ExercisePlanDetailChange.delete ) {
|
||||
await ExercisePlanApi()
|
||||
.deleteExercisePlanDetail(exercisePlanDetail.exercisePlanDetailId);
|
||||
} else {
|
||||
exercisePlanDetail.change = ExercisePlanDetailChange.deleted;
|
||||
Cache().deletedMyExercisePlanDetail(exercisePlanDetail);
|
||||
|
||||
} else if ( exercisePlanDetail.change == ExercisePlanDetailChange.update ) {
|
||||
await ExercisePlanApi()
|
||||
.updateExercisePlanDetail(exercisePlanDetail, exercisePlanDetail.exercisePlanDetailId);
|
||||
Cache().updateMyExercisePlanDetail(exercisePlanDetail);
|
||||
} else if ( exercisePlanDetail.change == ExercisePlanDetailChange.add ) {
|
||||
await ExercisePlanApi()
|
||||
.saveExercisePlanDetail(exercisePlanDetail);
|
||||
Cache().addToMyExercisePlanDetails(exercisePlanDetail);
|
||||
}
|
||||
});
|
||||
|
||||
exercisePlanDetails.forEach((exerciseTypeId, exercisePlanDetail) async{
|
||||
exercisePlanDetail.exercisePlanId = _exercisePlan.exercisePlanId;
|
||||
if ( _origExercisePlanDetails[exercisePlanDetail.exercisePlanDetailId] == null) {
|
||||
await ExercisePlanApi()
|
||||
.saveExercisePlanDetail(exercisePlanDetail);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Future<ExercisePlan> getLastExercisePlan() async {
|
||||
if ( _customerId == 0) {
|
||||
if ( customerId == 0) {
|
||||
return null;
|
||||
}
|
||||
_exercisePlan = await ExercisePlanApi().getLastExercisePlan(_customerId);
|
||||
newPlan = (_exercisePlan == null);
|
||||
print("New plan: " + newPlan.toString());
|
||||
ExercisePlan myExercisePlan = Cache().getMyExercisePlan();
|
||||
if ( myExercisePlan != null ) {
|
||||
exercisePlan = myExercisePlan;
|
||||
return myExercisePlan;
|
||||
}
|
||||
|
||||
return _exercisePlan;
|
||||
exercisePlan = await ExercisePlanApi().getLastExercisePlan(customerId);
|
||||
newPlan = (exercisePlan == null);
|
||||
print("New plan: " + newPlan.toString());
|
||||
Cache().setMyExercisePlan(exercisePlan);
|
||||
return exercisePlan;
|
||||
}
|
||||
|
||||
Future<void> getExercisePlanDetails() async {
|
||||
if (_exercisePlan == null) {
|
||||
if (exercisePlan == null) {
|
||||
ExercisePlan exercisePlan = await this.getLastExercisePlan();
|
||||
if ( exercisePlan == null ) {
|
||||
exercisePlanDetails = LinkedHashMap<int, ExercisePlanDetail>();
|
||||
_origExercisePlanDetails = LinkedHashMap<int, ExercisePlanDetail>();
|
||||
return;
|
||||
}
|
||||
}
|
||||
exercisePlanDetails = LinkedHashMap<int, ExercisePlanDetail>();
|
||||
_origExercisePlanDetails = LinkedHashMap<int, ExercisePlanDetail>();
|
||||
|
||||
List<ExercisePlanDetail> list =
|
||||
await ExercisePlanApi().getExercisePlanDetail(_exercisePlan.exercisePlanId);
|
||||
List<ExercisePlanDetail> list = List();
|
||||
LinkedHashMap<int, ExercisePlanDetail> listCache = Cache().getMyExercisePlanDetails();
|
||||
if ( listCache.length > 0) {
|
||||
exercisePlanDetails = listCache;
|
||||
return;
|
||||
} else {
|
||||
list = await ExercisePlanApi().getExercisePlanDetail(exercisePlan.exercisePlanId);
|
||||
}
|
||||
|
||||
exercisePlanDetails = LinkedHashMap<int, ExercisePlanDetail>();
|
||||
|
||||
list.forEach((element) {
|
||||
newPlan = false;
|
||||
ExercisePlanDetail detail = element;
|
||||
_origExercisePlanDetails[detail.exerciseTypeId] = detail;
|
||||
exercisePlanDetails[detail.exerciseTypeId] = detail;
|
||||
});
|
||||
Cache().setMyExercisePlanDetails(exercisePlanDetails);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import 'package:aitrainer_app/model/cache.dart';
|
||||
import 'package:aitrainer_app/model/customer.dart';
|
||||
import 'package:aitrainer_app/model/exercise.dart';
|
||||
import 'package:aitrainer_app/model/exercise_type.dart';
|
||||
import 'package:aitrainer_app/model/workout_tree.dart';
|
||||
import 'package:aitrainer_app/model/workout_menu_tree.dart';
|
||||
import 'package:aitrainer_app/service/exercise_service.dart';
|
||||
|
||||
class ExerciseRepository {
|
||||
@@ -120,14 +120,14 @@ class ExerciseRepository {
|
||||
List<int> baseTreeItem = List();
|
||||
List<int> checkedBaseTreeItem = List();
|
||||
int count1RMExercises = 0;
|
||||
LinkedHashMap<String, WorkoutTree> tree = Cache().getWorkoutTree();
|
||||
LinkedHashMap<String, WorkoutMenuTree> tree = Cache().getWorkoutMenuTree();
|
||||
|
||||
if ( tree == null ) {
|
||||
return;
|
||||
}
|
||||
|
||||
tree.forEach((key, value) {
|
||||
WorkoutTree treeItem = value;
|
||||
WorkoutMenuTree treeItem = value;
|
||||
if (treeItem.exerciseType != null &&
|
||||
treeItem.exerciseType.base == true &&
|
||||
!baseTreeItem.contains(treeItem.parent)) {
|
||||
@@ -148,7 +148,7 @@ class ExerciseRepository {
|
||||
if ( !checkedExerciseTypeId.contains(exercise.exerciseTypeId )) {
|
||||
checkedExerciseTypeId.add(exercise.exerciseTypeId);
|
||||
tree.forEach((key, value) {
|
||||
WorkoutTree treeItem = value;
|
||||
WorkoutMenuTree treeItem = value;
|
||||
if (treeItem.exerciseType != null
|
||||
&& treeItem.exerciseType.base == true
|
||||
&& exercise.exerciseTypeId == treeItem.exerciseType.exerciseTypeId
|
||||
|
||||
@@ -3,7 +3,7 @@ import 'package:aitrainer_app/localization/app_language.dart';
|
||||
import 'package:aitrainer_app/model/cache.dart';
|
||||
import 'package:aitrainer_app/model/exercise_tree.dart';
|
||||
import 'package:aitrainer_app/model/exercise_type.dart';
|
||||
import 'package:aitrainer_app/model/workout_tree.dart';
|
||||
import 'package:aitrainer_app/model/workout_menu_tree.dart';
|
||||
import 'package:aitrainer_app/repository/exercise_repository.dart';
|
||||
import 'package:aitrainer_app/service/exercise_tree_service.dart';
|
||||
import 'package:aitrainer_app/service/exercisetype_service.dart';
|
||||
@@ -29,8 +29,8 @@ class Antagonist {
|
||||
}
|
||||
|
||||
class WorkoutTreeRepository {
|
||||
final LinkedHashMap tree = LinkedHashMap<String, WorkoutTree>();
|
||||
SplayTreeMap sortedTree = SplayTreeMap<String, List<WorkoutTree>>();
|
||||
final LinkedHashMap tree = LinkedHashMap<String, WorkoutMenuTree>();
|
||||
SplayTreeMap sortedTree = SplayTreeMap<String, List<WorkoutMenuTree>>();
|
||||
bool isEnglish;
|
||||
|
||||
final Map<String, int> _antagonist = {
|
||||
@@ -61,7 +61,7 @@ class WorkoutTreeRepository {
|
||||
if ( is1RM == false && treeItem.parentId != 0) {
|
||||
is1RM = isParent1RM(treeItem.parentId);
|
||||
}
|
||||
this.tree[treeItem.name] = WorkoutTree(
|
||||
this.tree[treeItem.name] = WorkoutMenuTree(
|
||||
treeItem.treeId,
|
||||
treeItem.parentId,
|
||||
treeName,
|
||||
@@ -87,7 +87,7 @@ class WorkoutTreeRepository {
|
||||
String assetImage = 'asset/menu/' + exerciseType.imageUrl.substring(7);
|
||||
bool is1RM = this.isParent1RM(exerciseType.treeId);
|
||||
exerciseType.is1RM = is1RM;
|
||||
this.tree[exerciseType.name] = WorkoutTree(
|
||||
this.tree[exerciseType.name] = WorkoutMenuTree(
|
||||
exerciseType.exerciseTypeId,
|
||||
exerciseType.treeId,
|
||||
exerciseTypeName,
|
||||
@@ -103,7 +103,7 @@ class WorkoutTreeRepository {
|
||||
);
|
||||
});
|
||||
|
||||
Cache().setWorkoutTree(tree);
|
||||
Cache().setWorkoutMenuTree(tree);
|
||||
ExerciseRepository exerciseRepository = ExerciseRepository();
|
||||
exerciseRepository.getBaseExerciseFinishedPercent();
|
||||
}
|
||||
@@ -112,7 +112,7 @@ class WorkoutTreeRepository {
|
||||
bool isTreeItem1RM = false;
|
||||
|
||||
this.tree.forEach((key, value) {
|
||||
WorkoutTree treeItem = value as WorkoutTree;
|
||||
WorkoutMenuTree treeItem = value as WorkoutMenuTree;
|
||||
if ( treeItem.id == treeId ) {
|
||||
isTreeItem1RM = treeItem.is1RM;
|
||||
//print (treeItem.name + " 1RM " + treeItem.is1RM.toString() );
|
||||
@@ -124,9 +124,9 @@ class WorkoutTreeRepository {
|
||||
}
|
||||
|
||||
LinkedHashMap getBranch(int parent) {
|
||||
LinkedHashMap branch = LinkedHashMap<String, WorkoutTree>();
|
||||
LinkedHashMap branch = LinkedHashMap<String, WorkoutMenuTree>();
|
||||
tree.forEach((key, value) {
|
||||
WorkoutTree workoutTree = value as WorkoutTree;
|
||||
WorkoutMenuTree workoutTree = value as WorkoutMenuTree;
|
||||
if ( parent == workoutTree.parent) {
|
||||
branch[key] = value;
|
||||
}
|
||||
@@ -134,10 +134,10 @@ class WorkoutTreeRepository {
|
||||
return branch;
|
||||
}
|
||||
|
||||
List<WorkoutTree> getBranchList(int parent) {
|
||||
List branch = List<WorkoutTree>();
|
||||
List<WorkoutMenuTree> getBranchList(int parent) {
|
||||
List branch = List<WorkoutMenuTree>();
|
||||
tree.forEach((key, value) {
|
||||
WorkoutTree workoutTree = value as WorkoutTree;
|
||||
WorkoutMenuTree workoutTree = value as WorkoutMenuTree;
|
||||
if ( parent == workoutTree.parent) {
|
||||
branch.add(workoutTree);
|
||||
}
|
||||
@@ -146,9 +146,9 @@ class WorkoutTreeRepository {
|
||||
}
|
||||
|
||||
void sortByMuscleType() {
|
||||
sortedTree = SplayTreeMap<String, List<WorkoutTree>>();
|
||||
sortedTree = SplayTreeMap<String, List<WorkoutMenuTree>>();
|
||||
tree.forEach((key, value) {
|
||||
WorkoutTree workoutTree = value as WorkoutTree;
|
||||
WorkoutMenuTree workoutTree = value as WorkoutMenuTree;
|
||||
//print("treeitem: " + workoutTree.toJson().toString());
|
||||
/*if ( workoutTree.exerciseType != null) {
|
||||
print("treeItem exerciseTye " + workoutTree.exerciseType.toJson().toString());
|
||||
|
||||
Reference in New Issue
Block a user