Skip to content
Snippets Groups Projects
Commit bd618f39 authored by Ingrid Martinsheimen Egge's avatar Ingrid Martinsheimen Egge :cow2:
Browse files

Enheter tilpasser seg

parent 8794af1f
No related branches found
No related tags found
1 merge request!13Fridge view
Pipeline #224056 passed
......@@ -6,7 +6,7 @@
<p id="sliderDisplay">{{sliderValue}} {{this.fridgeItem.amount.unit}}</p>
<label for="slider">Mengde tatt av varen:</label>
<input type = "range" id = "slider" name = "slider" min="0" :max = "this.maxValue" step="this.stepIncrentValue" v-model="sliderValue">
<input type = "range" id = "slider" name = "slider" min="0" :max = "this.maxValue" :step = this.getStep v-model="sliderValue">
<div id="buttons">
<button @click="logFoodAsDiscarded">Ble kastet</button>
......@@ -36,9 +36,8 @@ export default {
},
data() {
return {
visible:true,
sliderValue: 0,
stepIncrentValue:'1',
visible:true,
sliderValue: 0,
}
},
methods:{
......@@ -47,22 +46,29 @@ export default {
},
logFoodAsEaten(){
const fridgeAction = "CONSUMED";
this.updateFridgeItem(fridgeAction)
},
logFoodAsDiscarded(){
const fridgeAction = "DISCARDED";
this.updateFridgeItem(fridgeAction)
},
updateFridgeItem(fridgeAction){
const ingredientId = this.fridgeItem.ingredient_id;
const request = {
action: fridgeAction,
ingredients: {
[ingredientId]:{
"quantity": this.sliderValue,
"unit": this.fridgeItem.amount.unit
}
[ingredientId]:{
"quantity": this.sliderValue,
"unit": this.fridgeItem.amount.unit
}
}
};
API.updateFridge(request).catch((error)=> console.log(error));
this.close();
},
logFoodAsDiscarded(){
API.updateFridge(request)
.catch((error)=>
console.log(error)
);
this.close();
},
extendExpiration(){
......@@ -89,9 +95,9 @@ export default {
},
isExpired(){
let date = this.fridgeItem.exp_date;
const epDate = new Date(date);
const expirationDate = new Date(date);
const parsedDate = Date.parse(epDate)
const parsedDate = Date.parse(expirationDate)
const today = new Date();
const ms = parsedDate-today;
......@@ -100,6 +106,15 @@ export default {
return numOfDays < 1 ;
},
getStep(){
const itemQuantity = this.fridgeItem.amount.quantity.toString();
const isDecimal = itemQuantity.split('.').length === 2 || itemQuantity==='1';
switch(isDecimal){
case true:
return '0.1';
case false:
return '1';
}
return 0.1;
},
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment