Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
Frontend
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
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
IDATT2106 Scrum Team 02
Frontend
Commits
0193bab7
Commit
0193bab7
authored
1 year ago
by
Ingrid Martinsheimen Egge
Browse files
Options
Downloads
Patches
Plain Diff
kan nesten oppdatere fridgeItem mengde
parent
1a70eb84
No related branches found
Branches containing commit
No related tags found
1 merge request
!13
Fridge view
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/components/EatFridgeItemModal.vue
+32
-3
32 additions, 3 deletions
src/components/EatFridgeItemModal.vue
src/util/API.js
+56
-38
56 additions, 38 deletions
src/util/API.js
src/views/FridgeView.vue
+22
-13
22 additions, 13 deletions
src/views/FridgeView.vue
with
110 additions
and
54 deletions
src/components/EatFridgeItemModal.vue
+
32
−
3
View file @
0193bab7
...
@@ -9,8 +9,8 @@
...
@@ -9,8 +9,8 @@
<input
type =
"range"
id =
"slider"
name =
"slider"
min=
"0"
:max =
"this.maxValue"
v-model=
"sliderValue"
>
<input
type =
"range"
id =
"slider"
name =
"slider"
min=
"0"
:max =
"this.maxValue"
v-model=
"sliderValue"
>
<div
id=
"buttons"
>
<div
id=
"buttons"
>
<button
@
click=
"
c
lo
se
"
>
Ble kastet 🗑️
</button>
<button
@
click=
"lo
gFoodAsDiscarded
"
>
Ble kastet 🗑️
</button>
<button
id=
"eatenBtn"
@
click=
"
c
lo
se
"
>
Ble spist 😋
</button>
<button
id=
"eatenBtn"
@
click=
"lo
gFoodAsEaten
"
>
Ble spist 😋
</button>
</div>
</div>
</div>
</div>
</
template
>
</
template
>
...
@@ -18,6 +18,7 @@
...
@@ -18,6 +18,7 @@
<
script
>
<
script
>
import
{
Icon
}
from
"
@iconify/vue
"
;
import
{
Icon
}
from
"
@iconify/vue
"
;
import
fridgeItem
from
"
@/components/FridgeItem.vue
"
;
import
fridgeItem
from
"
@/components/FridgeItem.vue
"
;
import
{
API
}
from
"
@/util/API
"
;
export
default
{
export
default
{
name
:
"
EatFridgeItemModal
"
,
name
:
"
EatFridgeItemModal
"
,
...
@@ -38,7 +39,31 @@ export default {
...
@@ -38,7 +39,31 @@ export default {
close
(){
close
(){
this
.
$emit
(
'
closeModal
'
,
this
);
this
.
$emit
(
'
closeModal
'
,
this
);
},
},
logFoodAsEaten
(){
const
fridgeAction
=
"
CONSUMED
"
;
const
ingredientId
=
this
.
fridgeItem
.
ingredient_id
;
const
amountEaten
=
{
"
quantity
"
:
this
.
sliderValue
,
"
unit
"
:
this
.
fridgeItem
.
amount
.
unit
};
const
request
=
{
action
:
fridgeAction
,
ingredients
:
{
[
ingredientId
]:{
"
quantity
"
:
this
.
sliderValue
,
"
unit
"
:
this
.
fridgeItem
.
amount
.
unit
}
}
};
API
.
removeIngredientFromFridge
(
request
).
catch
((
error
)
=>
console
.
log
(
error
));
this
.
close
();
},
logFoodAsDiscarded
(){
this
.
close
();
},
},
},
computed
:{
computed
:{
redIconColor
()
{
redIconColor
()
{
...
@@ -98,10 +123,14 @@ button {
...
@@ -98,10 +123,14 @@ button {
margin
:
.1em
;
margin
:
.1em
;
font-weight
:
bolder
;
font-weight
:
bolder
;
width
:
40%
;
width
:
40%
;
padding
:
1em
;
background-color
:
base
.
$red
;
background-color
:
base
.
$red
;
color
:white
;
color
:white
;
}
}
button
:hover
,
#eatenBtn
:hover
{
background-color
:
base
.
$grey
;
}
#eatenBtn
{
#eatenBtn
{
background-color
:
base
.
$green
;
background-color
:
base
.
$green
;
}
}
...
...
This diff is collapsed.
Click to expand it.
src/util/API.js
+
56
−
38
View file @
0193bab7
...
@@ -136,9 +136,8 @@ export const API = {
...
@@ -136,9 +136,8 @@ export const API = {
.
catch
(()
=>
{
throw
new
Error
()})
.
catch
(()
=>
{
throw
new
Error
()})
},
},
/**
/**
* fetches all fridge items belonging to
user
* fetches all fridge items belonging to
the user that is currently logged in
* @returns {Promise<*>}
* @returns {Promise<*>}
*/
*/
getFridgeItems
:
async
()
=>
{
getFridgeItems
:
async
()
=>
{
...
@@ -154,21 +153,6 @@ export const API = {
...
@@ -154,21 +153,6 @@ export const API = {
});
});
},
},
//returns fridgeItem of specific id
getFridgeItem
:
async
(
id
)
=>
{
const
authStore
=
useAuthStore
();
axios
.
get
(
`
${
import
.
meta
.
env
.
VITE_BACKEND_URL
}
/fridge/
${
id
}
`
,
{
headers
:
{
Authorization
:
`Bearer
${
authStore
.
token
}
`
},
})
.
then
((
response
)
=>
{
return
response
.
data
;
})
.
catch
(()
=>
{
throw
new
Error
(
"
Could not fetch fridge item
"
);
});
},
/**
/**
* Adds item(s) to the fridge
* Adds item(s) to the fridge
* @param request List<Ingredient> listOfIngredients
* @param request List<Ingredient> listOfIngredients
...
@@ -184,29 +168,12 @@ export const API = {
...
@@ -184,29 +168,12 @@ export const API = {
}).
catch
(()
=>
{
}).
catch
(()
=>
{
throw
new
Error
(
"
Could not add item to fridge:
"
);
throw
new
Error
(
"
Could not add item to fridge:
"
);
})
})
},
},
/**
/**
* Array(3) [ {…}, {…}, {…} ]
* Searches for registered items.
* 0: Object { name: "Tomat", ean: "7040512550214", shelfLife: 10, … }
* @param searchPhrase Name of the item that one is looking for (e.g: "purre")
* allergens: Array []
* @returns {Promise<*>} list containing items that match the search phrase
* amount: Object { quantity: 4, unit: "stk" }
* quantity: 4
* unit: "stk"
* <prototype>: Object { … }
* ean: "7040512550214"
* image_url: "https://bilder.ngdata.no/7040512550818/meny/large.jpg"
* name: "Tomat"
* nutrition: Array(11) [ {…}, {…}, {…}, … ]
* shelfLife: 10
* store: null
*/
/**
* Searches for available items
* @param searchPhrase
* @returns {Promise<*>}
*/
*/
searchItems
:
async
(
searchPhrase
)
=>
{
searchItems
:
async
(
searchPhrase
)
=>
{
return
axios
.
get
(
`
${
import
.
meta
.
env
.
VITE_BACKEND_URL
}
/item/search?name=
${
searchPhrase
}
`
,
{
return
axios
.
get
(
`
${
import
.
meta
.
env
.
VITE_BACKEND_URL
}
/item/search?name=
${
searchPhrase
}
`
,
{
...
@@ -216,5 +183,56 @@ export const API = {
...
@@ -216,5 +183,56 @@ export const API = {
}).
catch
(()
=>
{
}).
catch
(()
=>
{
throw
new
Error
(
"
Error when searching for item
"
);
throw
new
Error
(
"
Error when searching for item
"
);
})
})
}
},
/**
* Removes an amount of an ingredient from the frodge, and the action is then logged
* @param request Log.Action action, Map<Integer, Amount>
* Action available: CONSUMED, DISCARDED,ADDED_TO_FRIDGE
* @returns {Promise<void>}
*/
removeIngredientFromFridge
:
async
(
request
)
=>
{
const
authStore
=
useAuthStore
();
axios
.
put
(
`
${
import
.
meta
.
env
.
VITE_BACKEND_URL
}
/fridge/ingredients`
,
request
,{
headers
:
{
Authorization
:
`Bearer
${
authStore
.
token
}
`
},
}).
then
((
response
)
=>
{
return
response
.
data
;
}).
catch
(()
=>
{
throw
new
Error
(
"
Could modify ingredient.
"
);
})
},
/**
* Changes the expiration date of an ingredient.
* @param request ingredientId, newExpDate (Tip: )
* @returns {Promise<void>}
*/
changeExpirationOfIngredient
:
async
(
request
)
=>
{
const
authStore
=
useAuthStore
();
axios
.
put
(
`
${
import
.
meta
.
env
.
VITE_BACKEND_URL
}
/fridge/ingredient`
,
request
,{
headers
:
{
Authorization
:
`Bearer
${
authStore
.
token
}
`
},
}).
then
((
response
)
=>
{
return
response
.
data
;
}).
catch
(()
=>
{
throw
new
Error
(
"
Could modify ingredient.
"
);
})
},
//returns fridgeItem of specific id
getFridgeItem
:
async
(
id
)
=>
{
const
authStore
=
useAuthStore
();
axios
.
get
(
`
${
import
.
meta
.
env
.
VITE_BACKEND_URL
}
/fridge/
${
id
}
`
,
{
headers
:
{
Authorization
:
`Bearer
${
authStore
.
token
}
`
},
})
.
then
((
response
)
=>
{
return
response
.
data
;
})
.
catch
(()
=>
{
throw
new
Error
(
"
Could not fetch fridge item
"
);
});
},
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/views/FridgeView.vue
+
22
−
13
View file @
0193bab7
<
template
>
<
template
>
<main>
<main>
<h1>
Kjøleskap
</h1><br><br>
<h1>
Kjøleskap
</h1><br><br>
<ItemSearch
@
itemsAdded=
"updateFridge"
></ItemSearch>
<ItemSearch
v-if=
"searchVisible"
@
itemsAdded=
"updateFridge"
></ItemSearch>
<div><p>
{{
this
.
fridgeMsg
}}
</p></div>
<eat-fridge-item-modal
@
closeModal=
"hideModal"
v-if=
"visible"
:fridge-item=
"selectedItem"
></eat-fridge-item-modal>
<eat-fridge-item-modal
@
closeModal=
"hideModal"
v-if=
"visible"
:fridge-item=
"selectedItem"
></eat-fridge-item-modal>
<div
id =
"itemContainer"
>
<div
id =
"itemContainer"
>
<FridgeItem
v-for=
"item in fridgeItems"
:actualItem =
"item"
:item=
"testItem"
@
appleBtnPressed=
"showModal"
></FridgeItem>
<FridgeItem
v-for=
"item in fridgeItems"
:actualItem =
"item"
@
appleBtnPressed=
"showModal"
></FridgeItem>
</div>
</div>
<div
id=
"addItemBtn-container"
>
<div
id=
"addItemBtn-container"
>
<button
@
click=
"
addItemToFridge
"
id=
"addItemBtn"
>
<button
@
click=
"
showItemSearch
"
id=
"addItemBtn"
>
<span
class=
"plus"
>
+
</span>
<span
class=
"plus"
>
+
</span>
</button>
</button>
</div>
</div>
...
@@ -32,13 +33,14 @@ export default {
...
@@ -32,13 +33,14 @@ export default {
computed
:{
computed
:{
...
mapState
(
useAuthStore
,
[
'
account
'
]),
...
mapState
(
useAuthStore
,
[
'
account
'
]),
...
mapStores
(
useFridgeStore
),
...
mapStores
(
useFridgeStore
),
},
},
data
()
{
data
()
{
return
{
return
{
visible
:
false
,
//is the useitemModal visible
visible
:
false
,
//is the useitemModal visible
selectedItem
:
null
,
selectedItem
:
null
,
fridgeItems
:
[],
fridgeItems
:
[],
searchVisible
:
false
,
fridgeMsg
:
"
fridge message:
"
}
}
},
},
methods
:
{
methods
:
{
...
@@ -46,19 +48,26 @@ export default {
...
@@ -46,19 +48,26 @@ export default {
this
.
visible
=
true
;
this
.
visible
=
true
;
this
.
selectedItem
=
item
;
this
.
selectedItem
=
item
;
},
},
hideModal
(){
hideModal
(){
this
.
visible
=
false
;
this
.
visible
=
false
;
},
},
addItemToFridge
()
{
showItemSearch
()
{
alert
(
"
Denne knappen legger en ny vare i kjøleskapet
"
)
this
.
searchVisible
=!
this
.
searchVisible
;
},
},
hideItemSearch
()
{
this
.
searchVisible
=
false
;
},
updateFridgeMessage
(
msg
){
this
.
fridgeMsg
=
msg
;
},
async
updateFridge
()
{
async
updateFridge
()
{
this
.
fridgeItems
=
await
API
.
getFridgeItems
();
this
.
fridgeItems
=
await
API
.
getFridgeItems
();
this
.
hideItemSearch
();
this
.
updateFridgeMessage
(
"
Varen ble lagt i kjøleskapet.
"
)
}
}
},
},
async
mounted
()
{
async
mounted
()
{
this
.
fridgeItems
=
await
API
.
getFridgeItems
();
this
.
fridgeItems
=
await
API
.
getFridgeItems
();
console
.
log
(
this
.
fridgeItems
.
length
)
}
}
}
}
</
script
>
</
script
>
...
...
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