Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
idatt1002_2023_9
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Andreas Kluge Svendsrud
idatt1002_2023_9
Commits
cb5bf851
Commit
cb5bf851
authored
1 year ago
by
HSoreide
Browse files
Options
Downloads
Patches
Plain Diff
Refactor our read and write actions of SuggestRecipesController
parent
5cb47da5
No related branches found
No related tags found
2 merge requests
!42
Hs frontend recipes
,
!41
Hs frontend recipes
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/no/ntnu/idatt1002/demo/controller/SuggestRecipesController.java
+18
-16
18 additions, 16 deletions
...u/idatt1002/demo/controller/SuggestRecipesController.java
src/main/resources/recipes/Fridge.register
+1
-3
1 addition, 3 deletions
src/main/resources/recipes/Fridge.register
with
19 additions
and
19 deletions
src/main/java/no/ntnu/idatt1002/demo/controller/SuggestRecipesController.java
+
18
−
16
View file @
cb5bf851
...
...
@@ -75,11 +75,7 @@ public class SuggestRecipesController implements Initializable {
if
(
clickedButton
.
isPresent
()
&&
clickedButton
.
get
()
==
ButtonType
.
APPLY
)
{
// Refresh ingredientsAtHand.
ingredientsAtHand
=
FileHandler
.
readIngredientsAtHand
(
"Fridge"
);
//TODO: Duplicate code and assertion.
assert
ingredientsAtHand
!=
null
;
fridge
=
FXCollections
.
observableArrayList
(
ingredientsAtHand
.
getIngredientsAtHand
().
stream
().
map
(
foodItem
->
foodItem
.
label
).
toList
());
fridgeList
.
setItems
(
fridge
.
sorted
());
readIngredientsAtHand
();
setRecipeTiles
();
}
}
...
...
@@ -89,11 +85,7 @@ public class SuggestRecipesController implements Initializable {
String
toRemove
=
fridgeList
.
getSelectionModel
().
getSelectedItem
();
//TODO: If anything selected!
ingredientsAtHand
.
removeIngredient
(
FoodItem
.
valueOf
(
toRemove
.
replace
(
" "
,
"_"
).
toUpperCase
()));
FileHandler
.
writeIngredientsAtHand
(
ingredientsAtHand
,
"Fridge"
);
//TODO: Remove toUppercase solution above.
//TODO: Consider factoring out to a update method.
fridge
=
FXCollections
.
observableArrayList
(
ingredientsAtHand
.
getIngredientsAtHand
().
stream
().
map
(
foodItem
->
foodItem
.
label
).
toList
());
fridgeList
.
setItems
(
fridge
.
sorted
());
storeIngredientsAtHand
();
setRecipeTiles
();
}
...
...
@@ -169,16 +161,26 @@ public class SuggestRecipesController implements Initializable {
stage
.
show
();
}
@Override
public
void
initialize
(
URL
url
,
ResourceBundle
resourceBundle
)
{
public
void
readIngredientsAtHand
()
{
// If no ingredients at hand file exsists, add one and let it be empty. //TODO
ingredientsAtHand
=
FileHandler
.
readIngredientsAtHand
(
"Fridge"
);
ingredientsAtHand
=
FileHandler
.
readIngredientsAtHand
(
"Fridge"
);
fridge
=
FXCollections
.
observableArrayList
(
ingredientsAtHand
.
getIngredientsAtHand
().
stream
().
map
(
foodItem
->
foodItem
.
label
).
toList
());
//List<String> fridgeLabels = fridge;
fridgeList
.
setItems
(
fridge
.
sorted
());
fridgeList
.
setItems
(
fridge
.
sorted
());
}
public
void
storeIngredientsAtHand
()
throws
IOException
{
FileHandler
.
writeIngredientsAtHand
(
ingredientsAtHand
,
"Fridge"
);
fridge
=
FXCollections
.
observableArrayList
(
ingredientsAtHand
.
getIngredientsAtHand
().
stream
().
map
(
foodItem
->
foodItem
.
label
).
toList
());
fridgeList
.
setItems
(
fridge
.
sorted
());
}
@Override
public
void
initialize
(
URL
url
,
ResourceBundle
resourceBundle
)
{
readIngredientsAtHand
();
recipeRegister
=
FileHandler
.
readRecipeRegister
(
"Recipes"
);
recipes
=
FXCollections
.
observableArrayList
(
recipeRegister
.
getRecipes
());
...
...
This diff is collapsed.
Click to expand it.
src/main/resources/recipes/Fridge.register
+
1
−
3
View file @
cb5bf851
WHEAT_FLOUR
ONION
EGG
VINEGAR
SPAGHETTI
...
...
@@ -9,14 +8,13 @@ TOMATO_PASTE
CHICKPEAS
SPRING_ROLL
YELLOW_CHEESE
MILK
POTATO
BELL_PEPPER
DRY_THYME
DRY_BASIL
PARMESAN
OLIVE_OIL
OIL
BUTTER
GARLIC_CLOVE
HAM
BROCCOLI
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment