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

Profilmeldinger

parent e2968efc
No related branches found
No related tags found
1 merge request!26Profilmeldinger
<template> <template>
<div v-if="visible" id="popup"> <div v-if="visible" id="popup">
<div id="exitBtn" @click="close"><Icon icon="mdi:alpha-x-box" :color="redIconColor" :style="{ fontSize: redIconSize }" /></div> <div id="exitBtn" @click="close"><button :aria-label="'close menu'">X</button></div>
<h2>{{ this.fridgeItem.item.name }}</h2> <h2>{{ this.fridgeItem.item.name }}</h2>
<p id="sliderDisplay">{{sliderValue}} {{this.fridgeItem.amount.unit}}</p> <p id="sliderDisplay">{{sliderValue}} {{this.fridgeItem.amount.unit}}</p>
...@@ -66,6 +66,7 @@ export default { ...@@ -66,6 +66,7 @@ export default {
}; };
API.updateFridge(request) API.updateFridge(request)
.catch((error)=> .catch((error)=>
console.log(error) console.log(error)
); );
...@@ -159,6 +160,15 @@ export default { ...@@ -159,6 +160,15 @@ export default {
} }
#exitBtn button {
width:2em;
height:2em;
display: flex;
align-items: center;
justify-content: center;
padding: 1em;
}
button { button {
margin:.1em; margin:.1em;
font-weight: bolder; font-weight: bolder;
......
...@@ -52,12 +52,9 @@ import { useAuthStore } from "@/stores/authStore"; ...@@ -52,12 +52,9 @@ import { useAuthStore } from "@/stores/authStore";
import router from "../router"; import router from "../router";
export default { export default {
name: "EditProfile", name: "EditProfile",
components: {Icon},
data() { data() {
return { return {
alertMsg:'', alertMsg:'',
initialName: '', //used to compare with updated values
initialRestriction: '',
image: "profile/default_avatar.png", image: "profile/default_avatar.png",
} }
}, },
...@@ -71,13 +68,8 @@ export default { ...@@ -71,13 +68,8 @@ export default {
upImage: "profile/default_avatar.png", upImage: "profile/default_avatar.png",
} }
}, },
iconColor() {
return "#D9D9D9"
},
}, },
beforeMount() {//used to compare with changed values beforeMount() {
this.initialName = this.profile.name;
this.initialRestriction = this.profile.restricted;
if(this.profile.profileImageUrl !== ''){ if(this.profile.profileImageUrl !== ''){
this.image = this.profile.profileImageUrl; this.image = this.profile.profileImageUrl;
} }
...@@ -87,12 +79,23 @@ export default { ...@@ -87,12 +79,23 @@ export default {
router.push("/selectProfile"); router.push("/selectProfile");
}, },
updateImg() { updateImg() {
this.alertMsg=""
let file = document.getElementById("profile_img").files[0]; let file = document.getElementById("profile_img").files[0];
let fileSize = file.size
let reader = new FileReader(); let reader = new FileReader();
reader.onload = function (ev) { reader.onload = function (ev) {
document.getElementById("profile_img_preview").src = ev.target.result; document.getElementById("profile_img_preview").src = ev.target.result;
}; };
reader.readAsDataURL(file); reader.readAsDataURL(file);
if(fileSize>524288){ //if image is bigger than 512kB
this.alertMsg = "Bildet er for stort (" + Math.ceil(fileSize/1024) + "kB) Maksimal bildestørrelse er 512kB"
}
if(file.name.split('.jpeg').length===1 && file.name.split('.jpg').length===1 ){
this.alertMsg="filtypen støttes ikke (bildet må være av type .jpg/.jpeg)"
}
}, },
async deleteProfile() { async deleteProfile() {
const id = this.profile.id; const id = this.profile.id;
...@@ -106,14 +109,11 @@ export default { ...@@ -106,14 +109,11 @@ export default {
const id = this.profile.id; const id = this.profile.id;
let newName = null; let newName = null;
let newRestricted = null; let newRestricted = this.updatedProfile.upRestricted
if(this.updatedProfile.upName !== this.initialName){ if(this.updatedProfile.upName !== this.profile.name){
newName = this.updatedProfile.upName newName = this.updatedProfile.upName
} }
if(this.updatedProfile.upRestricted !== this.initialRestriction){
newRestricted = this.updatedProfile.upRestricted
}
API.updateProfile( API.updateProfile(
id,{ id,{
...@@ -123,6 +123,7 @@ export default { ...@@ -123,6 +123,7 @@ export default {
} }
).then((savedProfile)=>{ ).then((savedProfile)=>{
useAuthStore().setProfile(savedProfile); useAuthStore().setProfile(savedProfile);
const id = this.profile.id; const id = this.profile.id;
let image = document.getElementById("profile_img").files[0]; let image = document.getElementById("profile_img").files[0];
...@@ -142,28 +143,23 @@ export default { ...@@ -142,28 +143,23 @@ export default {
this.alertMsg = "Profil oppdatert." this.alertMsg = "Profil oppdatert."
}).catch(error=> { }).catch(error=> {
console.log(error) console.log(error)
if (error.message === '400') {
if(newRestricted){ switch (error.message){
case '400':
{
this.alertMsg = '‼️Det oppsto en feil: Sørg for at det finnes mist en standard profil på kontoen‼️ ' this.alertMsg = '‼️Det oppsto en feil: Sørg for at det finnes mist en standard profil på kontoen‼️ '
} else if(this.updatedProfile.name !== this.initialName || this.updatedProfile.name) { break;
}
case '409':
{
this.alertMsg = '‼️Det oppsto en feil: Det finnes allerede en bruker med samme navn‼️' this.alertMsg = '‼️Det oppsto en feil: Det finnes allerede en bruker med samme navn‼️'
break;
} }
}else{ default:
this.alertMsg = "‼️Det oppsto en feil.‼️" this.alertMsg = "‼️Det oppsto en feil.‼️"
} }
}) })
}, },
updateImage(){
//todo update image preview
},
chooseProfilePicture(){
this.alertMsg = "skriv inn bildelenke i feltet, og oppdater innstillinger"
},
} }
} }
...@@ -174,7 +170,6 @@ export default { ...@@ -174,7 +170,6 @@ export default {
input[type="radio"] { input[type="radio"] {
width: 2em; width: 2em;
height: 2em; height: 2em;
} }
#changeUserBtn { #changeUserBtn {
...@@ -210,7 +205,22 @@ img { ...@@ -210,7 +205,22 @@ img {
justify-content: space-between; justify-content: space-between;
} }
input[type=file]::file-selector-button {
background-color: base.$light-green;
color: base.$white;
border: none;
font-weight: bold;
padding: 8px 14px;
width: 50%;
border-radius: 10px;
cursor: pointer;
margin: 10px;
transition: color .2s;
}
input[type=file]::file-selector-button:hover {
background-color: base.$light-green-hover;
}
...@@ -275,7 +285,6 @@ button { ...@@ -275,7 +285,6 @@ button {
display: flex; display: flex;
width:100%; width:100%;
justify-content: center; justify-content: center;
color: base.$light-green;
font-weight: bold; font-weight: bold;
} }
</style> </style>
\ No newline at end of file
<template> <template>
<div id ="item"> <div id ="item">
<img :src="getImage" alt=""> <div>
<img :src="getImage" :alt="'bilde av ' + this.fridgeItem.item.name">
</div>
<div id="itemInfo"> <div id="itemInfo">
<p id="fridgeItemName">{{ this.fridgeItem.item.name }} {{ <p id="fridgeItemName">{{ this.fridgeItem.item.name }} {{
this.fridgeItem.amount.quantity this.fridgeItem.amount.quantity
...@@ -95,9 +98,9 @@ export default { ...@@ -95,9 +98,9 @@ export default {
}, },
formatDate(){ //formats expiration date as dd.mm.yyyy formatDate(){ //formats expiration date as dd.mm.yyyy
let fullExpirationDate = new Date(this.fridgeItem.exp_date); let fullExpirationDate = new Date(this.fridgeItem.exp_date);
let day = fullExpirationDate.getDate(); let day = fullExpirationDate.getDate().toString().padStart(2,'0');
let month= (fullExpirationDate.getMonth()+1).toString().padStart(2,'0'); let month= (fullExpirationDate.getMonth()+1).toString().padStart(2,'0');
let year= fullExpirationDate.getFullYear().toString().padStart(2,'0'); let year= fullExpirationDate.getFullYear().toString();
return day + "." + month + "." + year; return day + "." + month + "." + year;
} }
...@@ -109,9 +112,7 @@ export default { ...@@ -109,9 +112,7 @@ export default {
#item { #item {
background-color: base.$white; background-color: base.$white;
color: black; color: black;
padding: 1em; padding: 1em 2em;
padding-left: 2em;
padding-right:2em;
display:flex; display:flex;
align-items: center; align-items: center;
justify-content: space-between; justify-content: space-between;
...@@ -127,14 +128,14 @@ export default { ...@@ -127,14 +128,14 @@ export default {
font-size: 1.2em; font-size: 1.2em;
} }
img { img {
width: 3rem; width: 3rem;
height: 3em; height: 3rem;
border-radius: 50%; border-radius: 50%;
background-color: #00663C; background-color: base.$light-grey;
margin-right:.6em; margin-right:.6em;
object-fit: cover; object-fit: cover;
} }
#itemInfo{ #itemInfo{
......
...@@ -234,6 +234,7 @@ export const API = { ...@@ -234,6 +234,7 @@ export const API = {
axios.put(`${import.meta.env.VITE_BACKEND_URL}/fridge/ingredientsAmount`, request,{ axios.put(`${import.meta.env.VITE_BACKEND_URL}/fridge/ingredientsAmount`, request,{
headers: { Authorization: `Bearer ${authStore.token}` }, headers: { Authorization: `Bearer ${authStore.token}` },
}).then((response) => { }).then((response) => {
authStore.setFridge(response.data);
return response.data; return response.data;
}).catch(()=> { }).catch(()=> {
throw new Error("Could modify ingredient. "); throw new Error("Could modify ingredient. ");
......
...@@ -27,9 +27,6 @@ export default { ...@@ -27,9 +27,6 @@ export default {
components: {Icon}, components: {Icon},
computed: { computed: {
...mapStores(useAuthStore), ...mapStores(useAuthStore),
iconColor() {
return "#000000"
},
}, },
beforeMount() { beforeMount() {
if (!useAuthStore().isLoggedIn) { if (!useAuthStore().isLoggedIn) {
......
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