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

Beskjed til bruker på ingredienser som har gått ut på dato. Datoen kan forlenges med 5 dager

parent 0193bab7
No related branches found
No related tags found
1 merge request!13Fridge view
...@@ -12,6 +12,11 @@ ...@@ -12,6 +12,11 @@
<button @click="logFoodAsDiscarded">Ble kastet 🗑️ </button> <button @click="logFoodAsDiscarded">Ble kastet 🗑️ </button>
<button id="eatenBtn" @click="logFoodAsEaten" >Ble spist 😋</button> <button id="eatenBtn" @click="logFoodAsEaten" >Ble spist 😋</button>
</div> </div>
<div v-if="isExpired" id = "itemHasExpiredMessage">
<h2>Varen har gått ut på dato</h2>
<p>Se, lukt, smak : Hvis varen fortsatt ser fin ut, kan du forlenge utløpsdatoen med 5 dager</p>
<button id= "eatenBtn" @click="extendExpiration">Utsett utløpsdato med 5 dager</button>
</div>
</div> </div>
</template> </template>
...@@ -40,13 +45,8 @@ export default { ...@@ -40,13 +45,8 @@ export default {
this.$emit('closeModal',this); this.$emit('closeModal',this);
}, },
logFoodAsEaten(){ logFoodAsEaten(){
const fridgeAction = "CONSUMED"; const fridgeAction = "CONSUMED";
const ingredientId = this.fridgeItem.ingredient_id; const ingredientId = this.fridgeItem.ingredient_id;
const amountEaten = {
"quantity": this.sliderValue,
"unit": this.fridgeItem.amount.unit
};
const request = { const request = {
action: fridgeAction, action: fridgeAction,
...@@ -64,6 +64,17 @@ export default { ...@@ -64,6 +64,17 @@ export default {
logFoodAsDiscarded(){ logFoodAsDiscarded(){
this.close(); this.close();
}, },
extendExpiration(){
const id = this.fridgeItem.ingredient_id;
const today = new Date();
const fiveDays = new Date();
fiveDays.setDate(today.getDate()+5);
API.changeExpirationOfIngredient({"ingredientId": id, "newExpDate":fiveDays}).catch((error)=> {
console.log("could not change date")
})
this.close();
}
}, },
computed:{ computed:{
redIconColor() { redIconColor() {
...@@ -74,11 +85,22 @@ export default { ...@@ -74,11 +85,22 @@ export default {
}, },
maxValue(){ maxValue(){
return this.fridgeItem.amount.quantity; return this.fridgeItem.amount.quantity;
} },
isExpired(){
let date = this.fridgeItem.exp_date;
const epDate = new Date(date);
const parsedDate = Date.parse(epDate)
const today = new Date();
const ms = parsedDate-today;
const numOfDays = Math.ceil(ms/(86400000))
return numOfDays < 1 ;
},
} }
} }
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
#popup { #popup {
background-color: base.$white; background-color: base.$white;
...@@ -119,13 +141,13 @@ export default { ...@@ -119,13 +141,13 @@ export default {
} }
button { button {
qpadding: .2em 2.4em;
margin:.1em; margin:.1em;
font-weight: bolder; font-weight: bolder;
width: 40%; width: 40%;
padding:1em; padding:1em;
background-color: base.$red; background-color: base.$red;
color:white; color:white;
border:none;
} }
button:hover, #eatenBtn:hover { button:hover, #eatenBtn:hover {
...@@ -134,4 +156,16 @@ button:hover, #eatenBtn:hover { ...@@ -134,4 +156,16 @@ button:hover, #eatenBtn:hover {
#eatenBtn { #eatenBtn {
background-color: base.$green; background-color: base.$green;
} }
#itemHasExpiredMessage {
border: 3px dashed base.$red;
padding: 1em;
}
#itemHasExpiredMessage button {
padding: 1em;
width:100%;
border:none;
border-radius:5px;
}
</style> </style>
\ No newline at end of file
...@@ -205,7 +205,7 @@ export const API = { ...@@ -205,7 +205,7 @@ export const API = {
/** /**
* Changes the expiration date of an ingredient. * Changes the expiration date of an ingredient.
* @param request ingredientId, newExpDate (Tip: ) * @param request ingredientId: id of the ingredient, newExpDate: the new expiration date of the ingredient
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
changeExpirationOfIngredient: async(request) => { changeExpirationOfIngredient: async(request) => {
......
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