nothing with red lines in the entities

This commit is contained in:
broodjeaap89 2021-07-17 14:37:18 +02:00
parent 810e77894e
commit f585861016
10 changed files with 120 additions and 54 deletions

View file

@ -1,4 +1,3 @@
import 'package:floor/floor.dart';
import 'package:pizzaplanner/entities/PizzaEvent.dart';
import 'package:pizzaplanner/entities/PizzaRecipe/Ingredient.dart';
import 'package:pizzaplanner/entities/PizzaRecipe/PizzaRecipe.dart';
@ -10,6 +9,9 @@ import 'package:pizzaplanner/entities/dao/PizzaRecipeDao.dart';
import 'package:pizzaplanner/entities/dao/RecipeStepDao.dart';
import 'package:pizzaplanner/entities/dao/RecipeSubStepDao.dart';
import 'dart:async';
import 'package:floor/floor.dart';
import 'package:sqflite/sqflite.dart' as sqflite;
part 'PizzaDatabase.g.dart';
@TypeConverters([DateTimeConverter])

View file

@ -3,21 +3,25 @@ import 'package:pizzaplanner/entities/PizzaRecipe/PizzaRecipe.dart';
import 'package:floor/floor.dart';
@entity
@Entity(
tableName: "PizzaEvent",
foreignKeys: [
ForeignKey(childColumns: ["recipeId"], parentColumns: ["id"], entity: PizzaRecipe)
]
)
class PizzaEvent {
@PrimaryKey(autoGenerate: true)
final int? id;
final String name;
@ignore
final PizzaRecipe recipe;
final int recipeId; // foreign key to recipe for this event
final int pizzaCount;
final int doughBallSize;
final DateTime dateTime;
PizzaEvent(
this.recipeId,
this.name,
this.recipe,
this.pizzaCount,
this.doughBallSize,
this.dateTime,

View file

@ -1,19 +1,32 @@
import 'package:flutter/material.dart';
import 'package:floor/floor.dart';
import 'package:pizzaplanner/entities/PizzaRecipe/PizzaRecipe.dart';
import 'package:pizzaplanner/util.dart';
@entity
@Entity(
tableName: "Ingredient",
foreignKeys: [
ForeignKey(childColumns: ["pizzaRecipeId"], parentColumns: ["id"], entity: PizzaRecipe)
]
)
class Ingredient {
@PrimaryKey(autoGenerate: true)
final int? id;
final int pizzaRecipeId;
final String name;
final String unit;
final double value;
Ingredient(this.name, this.unit, this.value, {this.id});
Ingredient(this.pizzaRecipeId, this.name, this.unit, this.value, {this.id});
Future<void> insert() async {
final database = await getDatabase();
final ingredientDao = database.ingredientDao;
await ingredientDao.insertIngredient(this);
}
TableRow getIngredientTableRow(int pizzaCount, int doughBallSize){
return TableRow(

View file

@ -16,15 +16,28 @@ class PizzaRecipe {
final String name;
final String description;
@ignore
final List<Ingredient> ingredients;
//final List<Ingredient> ingredients;
@ignore
final List<RecipeStep> recipeSteps;
//final List<RecipeStep> recipeSteps;
PizzaRecipe(this.name, this.description, this.ingredients, this.recipeSteps, {this.id});
PizzaRecipe(this.name, this.description, {this.id});
Future<void> insert() async {
final database = await getDatabase();
final pizzaRecipeDao = database.pizzaRecipeDao;
await pizzaRecipeDao.insertPizzaRecipe(this);
}
Table getIngredientsTable(int pizzaCount, int doughBallSize) {
Future<List<RecipeStep>> getRecipeSteps() async {
final database = await getDatabase();
final recipeStepDao = database.recipeStepDao;
return await recipeStepDao.getPizzaRecipeSteps(this.id!);
}
Future<Table> getIngredientsTable(int pizzaCount, int doughBallSize) async {
final database = await getDatabase();
final ingredientDao = database.ingredientDao;
final ingredients = await ingredientDao.getPizzaRecipeSteps(this.id!);
return Table(
border: TableBorder.all(),
columnWidths: const <int, TableColumnWidth>{
@ -56,13 +69,18 @@ class PizzaRecipe {
String name = recipe["name"];
String description = recipe["description"];
YamlList ingredients = recipe["ingredients"];;
PizzaRecipe pizzaRecipe = PizzaRecipe(name, description);
pizzaRecipe.insert();
List<Ingredient> newIngredients = ingredients.map((ingredient) => Ingredient(ingredient["name"], ingredient["unit"], ingredient["value"])).toList();
YamlList ingredients = recipe["ingredients"];
for (var ingredientYaml in ingredients){
Ingredient ingredient = Ingredient(pizzaRecipe.id!, ingredientYaml["name"], ingredientYaml["unit"], ingredientYaml["value"]);
ingredient.insert();
}
YamlList steps = recipe["steps"];
var newRecipeSteps = List.generate(steps.length, (i) {
YamlMap step = steps[i];
for (var step in steps){
String stepName = step["name"];
String stepDescription = step["description"];
@ -80,57 +98,45 @@ class PizzaRecipe {
waitMax = waitMap["max"];
}
YamlList subSteps = step.containsKey("substeps") ? step["substeps"] : YamlList();
var newSubSteps = List.generate(subSteps.length, (j) {
var subStep = subSteps[j];
return RecipeSubStep(subStep["name"], subStep["description"]);
});
return RecipeStep(
RecipeStep recipeStep = RecipeStep(
pizzaRecipe.id!,
stepName,
stepDescription,
waitDescription,
waitUnit,
waitMin,
waitMax,
newSubSteps
waitMax
);
});
recipeStep.insert();
final database = await $FloorPizzaDatabase.databaseBuilder("app.db").build();
final recipeDao = database.pizzaRecipeDao;
await recipeDao.insertPizzaRecipe(PizzaRecipe(
name,
description,
newIngredients,
newRecipeSteps
));
return PizzaRecipe(
name,
description,
newIngredients,
newRecipeSteps
);
YamlList subSteps = step.containsKey("substeps") ? step["substeps"] : YamlList();
for (var subStep in subSteps ) {
RecipeSubStep recipeSubStep = RecipeSubStep(recipeStep.id!, subStep["name"], subStep["description"]);
recipeSubStep.insert();
}
}
return pizzaRecipe;
}
Duration getMinDuration(){
Future<Duration> getMinDuration() async {
List<RecipeStep> recipeSteps = await this.getRecipeSteps();
return Duration(seconds: recipeSteps.map((recipeStep) => recipeStep.getWaitMinInSeconds()).reduce((a, b) => a+b));
}
Duration getCurrentDuration(){
Future<Duration> getCurrentDuration() async {
List<RecipeStep> recipeSteps = await this.getRecipeSteps();
return Duration(seconds: recipeSteps.map((recipeStep) => recipeStep.getCurrentWaitInSeconds()).reduce((a, b) => a+b));
}
String toString() {
return "PizzaRecipe(${this.name}, ${this.ingredients.length}, ${this.recipeSteps.length})";
return "PizzaRecipe(${this.name})";
}
Table getStepTimeTable(DateTime startTime) {
Future<Table> getStepTimeTable(DateTime startTime) async {
List<TableRow> stepRows = [];
DateTime dateTime = DateTime.fromMillisecondsSinceEpoch(startTime.millisecondsSinceEpoch);
for (var recipeStep in this.recipeSteps.reversed) {
List<RecipeStep> recipeSteps = await this.getRecipeSteps();
for (var recipeStep in recipeSteps.reversed) {
Duration stepWaitDuration = Duration(seconds: recipeStep.getCurrentWaitInSeconds());
stepRows.add(
TableRow(

View file

@ -1,10 +1,18 @@
import 'package:floor/floor.dart';
import 'package:pizzaplanner/entities/PizzaRecipe/PizzaRecipe.dart';
import 'package:pizzaplanner/entities/PizzaRecipe/RecipeSubStep.dart';
import 'package:pizzaplanner/util.dart';
@entity
@Entity(
tableName: "RecipeStep",
foreignKeys: [
ForeignKey(childColumns: ["pizzaRecipeId"], parentColumns: ["id"], entity: PizzaRecipe)
]
)
class RecipeStep {
@PrimaryKey(autoGenerate: true)
final int? id;
final int pizzaRecipeId;
final String name;
final String waitDescription;
final String waitUnit;
@ -13,13 +21,18 @@ class RecipeStep {
late int waitValue;
final String description;
@ignore
final List<RecipeSubStep> subSteps;
// final List<RecipeSubStep> subSteps;
RecipeStep(this.name, this.description, this.waitDescription, this.waitUnit, this.waitMin, this.waitMax, this.subSteps, {this.id}) {
RecipeStep(this.pizzaRecipeId, this.name, this.description, this.waitDescription, this.waitUnit, this.waitMin, this.waitMax, {this.id}) {
waitValue = waitMin;
}
Future<void> insert() async {
final database = await getDatabase();
final recipeStepDao = database.recipeStepDao;
await recipeStepDao.insertRecipeStep(this);
}
int convertToSeconds(int value){
switch (waitUnit){
case "minutes": {

View file

@ -1,12 +1,26 @@
import 'package:floor/floor.dart';
import 'package:pizzaplanner/entities/PizzaRecipe/RecipeStep.dart';
import 'package:pizzaplanner/util.dart';
@entity
@Entity(
tableName: "RecipeSubStep",
foreignKeys: [
ForeignKey(childColumns: ["recipeStepId"], parentColumns: ["id"], entity: RecipeStep)
]
)
class RecipeSubStep {
@PrimaryKey(autoGenerate: true)
final int? id;
final int recipeStepId;
final String name;
final String description;
RecipeSubStep(this.name, this.description, {this.id});
RecipeSubStep(this.recipeStepId, this.name, this.description, {this.id});
Future<void> insert() async {
final database = await getDatabase();
final recipeSubStepDao = database.recipeSubStepDao;
await recipeSubStepDao.insertRecipeSubStep(this);
}
}

View file

@ -10,6 +10,9 @@ abstract class IngredientDao {
@Query("SELECT * FROM Ingredient WHERE id = :id")
Stream<Ingredient?> findIngredientById(int id);
@Query("SELECT * FROM Ingredient WHERE pizzaRecipeId = :pizzaRecipeId")
Future<List<Ingredient>> getPizzaRecipeSteps(int pizzaRecipeId);
@insert
Future<void> insertIngredient(Ingredient ingredient);
}

View file

@ -9,6 +9,9 @@ abstract class RecipeStepDao {
@Query("SELECT * FROM RecipeStep WHERE id = :id")
Stream<RecipeStep?> findRecipeStepById(int id);
@Query("SELECT * FROM RecipeStep WHERE pizzaRecipeId = :pizzaRecipeId")
Future<List<RecipeStep>> getPizzaRecipeSteps(int pizzaRecipeId);
@insert
Future<void> insertRecipeStep(RecipeStep recipeStep);
}

View file

@ -9,6 +9,9 @@ abstract class RecipeSubStepDao {
@Query("SELECT * FROM RecipeSubStep WHERE id = :id")
Stream<RecipeSubStep?> findRecipeSubStepById(int id);
@Query("SELECT * FROM RecipeStep WHERE recipeStepId = :recipeStepId")
Future<List<RecipeSubStep>> getRecipeStepSubSteps(int recipeStepId);
@insert
Future<void> insertRecipeSubStep(RecipeSubStep recipeSubStep);
}

View file

@ -2,6 +2,7 @@ import 'dart:convert';
import 'package:flutter/services.dart' show rootBundle;
import 'package:intl/intl.dart';
import 'package:pizzaplanner/entities/PizzaDatabase.dart';
import 'package:pizzaplanner/entities/PizzaRecipe/PizzaRecipe.dart';
Future<List<PizzaRecipe>> getRecipes() async {
@ -30,4 +31,8 @@ extension StringExtensions on String {
DateFormat getDateFormat(){
return DateFormat("yyyy-MM-dd H:mm");
}
Future<PizzaDatabase> getDatabase() async {
return await $FloorPizzaDatabase.databaseBuilder("pizza.db").build();
}