nothing with red lines in the entities
This commit is contained in:
parent
810e77894e
commit
f585861016
10 changed files with 120 additions and 54 deletions
|
@ -1,4 +1,3 @@
|
||||||
import 'package:floor/floor.dart';
|
|
||||||
import 'package:pizzaplanner/entities/PizzaEvent.dart';
|
import 'package:pizzaplanner/entities/PizzaEvent.dart';
|
||||||
import 'package:pizzaplanner/entities/PizzaRecipe/Ingredient.dart';
|
import 'package:pizzaplanner/entities/PizzaRecipe/Ingredient.dart';
|
||||||
import 'package:pizzaplanner/entities/PizzaRecipe/PizzaRecipe.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/RecipeStepDao.dart';
|
||||||
import 'package:pizzaplanner/entities/dao/RecipeSubStepDao.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';
|
part 'PizzaDatabase.g.dart';
|
||||||
|
|
||||||
@TypeConverters([DateTimeConverter])
|
@TypeConverters([DateTimeConverter])
|
||||||
|
|
|
@ -3,21 +3,25 @@ import 'package:pizzaplanner/entities/PizzaRecipe/PizzaRecipe.dart';
|
||||||
|
|
||||||
import 'package:floor/floor.dart';
|
import 'package:floor/floor.dart';
|
||||||
|
|
||||||
@entity
|
@Entity(
|
||||||
|
tableName: "PizzaEvent",
|
||||||
|
foreignKeys: [
|
||||||
|
ForeignKey(childColumns: ["recipeId"], parentColumns: ["id"], entity: PizzaRecipe)
|
||||||
|
]
|
||||||
|
)
|
||||||
class PizzaEvent {
|
class PizzaEvent {
|
||||||
@PrimaryKey(autoGenerate: true)
|
@PrimaryKey(autoGenerate: true)
|
||||||
final int? id;
|
final int? id;
|
||||||
|
|
||||||
final String name;
|
final String name;
|
||||||
@ignore
|
final int recipeId; // foreign key to recipe for this event
|
||||||
final PizzaRecipe recipe;
|
|
||||||
final int pizzaCount;
|
final int pizzaCount;
|
||||||
final int doughBallSize;
|
final int doughBallSize;
|
||||||
final DateTime dateTime;
|
final DateTime dateTime;
|
||||||
|
|
||||||
PizzaEvent(
|
PizzaEvent(
|
||||||
|
this.recipeId,
|
||||||
this.name,
|
this.name,
|
||||||
this.recipe,
|
|
||||||
this.pizzaCount,
|
this.pizzaCount,
|
||||||
this.doughBallSize,
|
this.doughBallSize,
|
||||||
this.dateTime,
|
this.dateTime,
|
||||||
|
|
|
@ -1,19 +1,32 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:floor/floor.dart';
|
import 'package:floor/floor.dart';
|
||||||
|
import 'package:pizzaplanner/entities/PizzaRecipe/PizzaRecipe.dart';
|
||||||
|
|
||||||
import 'package:pizzaplanner/util.dart';
|
import 'package:pizzaplanner/util.dart';
|
||||||
|
|
||||||
@entity
|
@Entity(
|
||||||
|
tableName: "Ingredient",
|
||||||
|
foreignKeys: [
|
||||||
|
ForeignKey(childColumns: ["pizzaRecipeId"], parentColumns: ["id"], entity: PizzaRecipe)
|
||||||
|
]
|
||||||
|
)
|
||||||
class Ingredient {
|
class Ingredient {
|
||||||
@PrimaryKey(autoGenerate: true)
|
@PrimaryKey(autoGenerate: true)
|
||||||
final int? id;
|
final int? id;
|
||||||
|
final int pizzaRecipeId;
|
||||||
|
|
||||||
final String name;
|
final String name;
|
||||||
final String unit;
|
final String unit;
|
||||||
final double value;
|
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){
|
TableRow getIngredientTableRow(int pizzaCount, int doughBallSize){
|
||||||
return TableRow(
|
return TableRow(
|
||||||
|
|
|
@ -16,15 +16,28 @@ class PizzaRecipe {
|
||||||
final String name;
|
final String name;
|
||||||
final String description;
|
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});
|
||||||
|
|
||||||
Table getIngredientsTable(int pizzaCount, int doughBallSize) {
|
Future<void> insert() async {
|
||||||
|
final database = await getDatabase();
|
||||||
|
final pizzaRecipeDao = database.pizzaRecipeDao;
|
||||||
|
await pizzaRecipeDao.insertPizzaRecipe(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
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(
|
return Table(
|
||||||
border: TableBorder.all(),
|
border: TableBorder.all(),
|
||||||
columnWidths: const <int, TableColumnWidth>{
|
columnWidths: const <int, TableColumnWidth>{
|
||||||
|
@ -56,13 +69,18 @@ class PizzaRecipe {
|
||||||
String name = recipe["name"];
|
String name = recipe["name"];
|
||||||
String description = recipe["description"];
|
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"];
|
YamlList steps = recipe["steps"];
|
||||||
var newRecipeSteps = List.generate(steps.length, (i) {
|
for (var step in steps){
|
||||||
YamlMap step = steps[i];
|
|
||||||
String stepName = step["name"];
|
String stepName = step["name"];
|
||||||
String stepDescription = step["description"];
|
String stepDescription = step["description"];
|
||||||
|
|
||||||
|
@ -80,57 +98,45 @@ class PizzaRecipe {
|
||||||
waitMax = waitMap["max"];
|
waitMax = waitMap["max"];
|
||||||
}
|
}
|
||||||
|
|
||||||
YamlList subSteps = step.containsKey("substeps") ? step["substeps"] : YamlList();
|
RecipeStep recipeStep = RecipeStep(
|
||||||
var newSubSteps = List.generate(subSteps.length, (j) {
|
pizzaRecipe.id!,
|
||||||
var subStep = subSteps[j];
|
|
||||||
return RecipeSubStep(subStep["name"], subStep["description"]);
|
|
||||||
});
|
|
||||||
return RecipeStep(
|
|
||||||
stepName,
|
stepName,
|
||||||
stepDescription,
|
stepDescription,
|
||||||
waitDescription,
|
waitDescription,
|
||||||
waitUnit,
|
waitUnit,
|
||||||
waitMin,
|
waitMin,
|
||||||
waitMax,
|
waitMax
|
||||||
newSubSteps
|
|
||||||
);
|
);
|
||||||
});
|
recipeStep.insert();
|
||||||
|
|
||||||
final database = await $FloorPizzaDatabase.databaseBuilder("app.db").build();
|
YamlList subSteps = step.containsKey("substeps") ? step["substeps"] : YamlList();
|
||||||
|
for (var subStep in subSteps ) {
|
||||||
final recipeDao = database.pizzaRecipeDao;
|
RecipeSubStep recipeSubStep = RecipeSubStep(recipeStep.id!, subStep["name"], subStep["description"]);
|
||||||
await recipeDao.insertPizzaRecipe(PizzaRecipe(
|
recipeSubStep.insert();
|
||||||
name,
|
}
|
||||||
description,
|
}
|
||||||
newIngredients,
|
return pizzaRecipe;
|
||||||
newRecipeSteps
|
|
||||||
));
|
|
||||||
|
|
||||||
|
|
||||||
return PizzaRecipe(
|
|
||||||
name,
|
|
||||||
description,
|
|
||||||
newIngredients,
|
|
||||||
newRecipeSteps
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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));
|
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));
|
return Duration(seconds: recipeSteps.map((recipeStep) => recipeStep.getCurrentWaitInSeconds()).reduce((a, b) => a+b));
|
||||||
}
|
}
|
||||||
|
|
||||||
String toString() {
|
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 = [];
|
List<TableRow> stepRows = [];
|
||||||
DateTime dateTime = DateTime.fromMillisecondsSinceEpoch(startTime.millisecondsSinceEpoch);
|
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());
|
Duration stepWaitDuration = Duration(seconds: recipeStep.getCurrentWaitInSeconds());
|
||||||
stepRows.add(
|
stepRows.add(
|
||||||
TableRow(
|
TableRow(
|
||||||
|
|
|
@ -1,10 +1,18 @@
|
||||||
import 'package:floor/floor.dart';
|
import 'package:floor/floor.dart';
|
||||||
|
import 'package:pizzaplanner/entities/PizzaRecipe/PizzaRecipe.dart';
|
||||||
import 'package:pizzaplanner/entities/PizzaRecipe/RecipeSubStep.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 {
|
class RecipeStep {
|
||||||
@PrimaryKey(autoGenerate: true)
|
@PrimaryKey(autoGenerate: true)
|
||||||
final int? id;
|
final int? id;
|
||||||
|
final int pizzaRecipeId;
|
||||||
final String name;
|
final String name;
|
||||||
final String waitDescription;
|
final String waitDescription;
|
||||||
final String waitUnit;
|
final String waitUnit;
|
||||||
|
@ -13,13 +21,18 @@ class RecipeStep {
|
||||||
late int waitValue;
|
late int waitValue;
|
||||||
final String description;
|
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;
|
waitValue = waitMin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> insert() async {
|
||||||
|
final database = await getDatabase();
|
||||||
|
final recipeStepDao = database.recipeStepDao;
|
||||||
|
await recipeStepDao.insertRecipeStep(this);
|
||||||
|
}
|
||||||
|
|
||||||
int convertToSeconds(int value){
|
int convertToSeconds(int value){
|
||||||
switch (waitUnit){
|
switch (waitUnit){
|
||||||
case "minutes": {
|
case "minutes": {
|
||||||
|
|
|
@ -1,12 +1,26 @@
|
||||||
import 'package:floor/floor.dart';
|
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 {
|
class RecipeSubStep {
|
||||||
@PrimaryKey(autoGenerate: true)
|
@PrimaryKey(autoGenerate: true)
|
||||||
final int? id;
|
final int? id;
|
||||||
|
final int recipeStepId;
|
||||||
|
|
||||||
final String name;
|
final String name;
|
||||||
final String description;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -10,6 +10,9 @@ abstract class IngredientDao {
|
||||||
@Query("SELECT * FROM Ingredient WHERE id = :id")
|
@Query("SELECT * FROM Ingredient WHERE id = :id")
|
||||||
Stream<Ingredient?> findIngredientById(int id);
|
Stream<Ingredient?> findIngredientById(int id);
|
||||||
|
|
||||||
|
@Query("SELECT * FROM Ingredient WHERE pizzaRecipeId = :pizzaRecipeId")
|
||||||
|
Future<List<Ingredient>> getPizzaRecipeSteps(int pizzaRecipeId);
|
||||||
|
|
||||||
@insert
|
@insert
|
||||||
Future<void> insertIngredient(Ingredient ingredient);
|
Future<void> insertIngredient(Ingredient ingredient);
|
||||||
}
|
}
|
|
@ -9,6 +9,9 @@ abstract class RecipeStepDao {
|
||||||
@Query("SELECT * FROM RecipeStep WHERE id = :id")
|
@Query("SELECT * FROM RecipeStep WHERE id = :id")
|
||||||
Stream<RecipeStep?> findRecipeStepById(int id);
|
Stream<RecipeStep?> findRecipeStepById(int id);
|
||||||
|
|
||||||
|
@Query("SELECT * FROM RecipeStep WHERE pizzaRecipeId = :pizzaRecipeId")
|
||||||
|
Future<List<RecipeStep>> getPizzaRecipeSteps(int pizzaRecipeId);
|
||||||
|
|
||||||
@insert
|
@insert
|
||||||
Future<void> insertRecipeStep(RecipeStep recipeStep);
|
Future<void> insertRecipeStep(RecipeStep recipeStep);
|
||||||
}
|
}
|
|
@ -9,6 +9,9 @@ abstract class RecipeSubStepDao {
|
||||||
@Query("SELECT * FROM RecipeSubStep WHERE id = :id")
|
@Query("SELECT * FROM RecipeSubStep WHERE id = :id")
|
||||||
Stream<RecipeSubStep?> findRecipeSubStepById(int id);
|
Stream<RecipeSubStep?> findRecipeSubStepById(int id);
|
||||||
|
|
||||||
|
@Query("SELECT * FROM RecipeStep WHERE recipeStepId = :recipeStepId")
|
||||||
|
Future<List<RecipeSubStep>> getRecipeStepSubSteps(int recipeStepId);
|
||||||
|
|
||||||
@insert
|
@insert
|
||||||
Future<void> insertRecipeSubStep(RecipeSubStep recipeSubStep);
|
Future<void> insertRecipeSubStep(RecipeSubStep recipeSubStep);
|
||||||
}
|
}
|
|
@ -2,6 +2,7 @@ import 'dart:convert';
|
||||||
|
|
||||||
import 'package:flutter/services.dart' show rootBundle;
|
import 'package:flutter/services.dart' show rootBundle;
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
|
import 'package:pizzaplanner/entities/PizzaDatabase.dart';
|
||||||
import 'package:pizzaplanner/entities/PizzaRecipe/PizzaRecipe.dart';
|
import 'package:pizzaplanner/entities/PizzaRecipe/PizzaRecipe.dart';
|
||||||
|
|
||||||
Future<List<PizzaRecipe>> getRecipes() async {
|
Future<List<PizzaRecipe>> getRecipes() async {
|
||||||
|
@ -31,3 +32,7 @@ extension StringExtensions on String {
|
||||||
DateFormat getDateFormat(){
|
DateFormat getDateFormat(){
|
||||||
return DateFormat("yyyy-MM-dd H:mm");
|
return DateFormat("yyyy-MM-dd H:mm");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<PizzaDatabase> getDatabase() async {
|
||||||
|
return await $FloorPizzaDatabase.databaseBuilder("pizza.db").build();
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue