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

Profilbilde

parent 808577b9
No related branches found
No related tags found
1 merge request!25Profilbilde
<template> <template>
<h2>Profilinnstillinger</h2> <h2>Profilinnstillinger</h2>
<div id = "profilepicture-container">
<img width="100" :src="image" alt="profile picture">
<div v-if="hasProfileImage" id = "profilepicture-container">
<img width="100" :src="this.updatedProfile.upImage" alt="profile picture">
</div>
<div v-else id="#placeholder">
<Icon icon="material-symbols:person" :color=iconColor :style="{ fontSize: '500px'}" />
</div> </div>
<h3>{{this.profile.name}}</h3> <h3>{{this.profile.name}}</h3>
<button @click="changeProfile" id="changeUserBtn" class="redBtn">Bytt bruker</button> <button @click="changeProfile" id="changeUserBtn" class="redBtn">Bytt bruker</button>
...@@ -26,16 +22,14 @@ ...@@ -26,16 +22,14 @@
<h3>Profilbilde</h3><br> <h3>Profilbilde</h3><br>
<div id="changeUserImage"> <div id="changeUserImage">
<div v-if="hasProfileImage" id = "profilepicture-container">
<img width="50" :src="this.updatedProfile.upImage" alt="profile picture"> <div id = "profilepicture-container">
<img width="50" :src="image" id = "profile_img_preview" alt="profile picture">
</div> </div>
<div v-else id = "profilepicture-container"> <div>
<Icon icon="material-symbols:person" :color=iconColor :style="{ fontSize: '30px'}" /> <input @change="updateImg" type="file" accept=".jpeg, .jpg" id="profile_img" name="profile_img"><br><br>
</div> </div>
<label for="chooseImageUrl">Bilde-URL:</label><br>
<!--<input type="file" id="chooseImage" v-on:change="updateImage">-->
<input type="text" id="chooseImageUrl" v-model="this.updatedProfile.upImage">
</div> </div>
<br><br> <br><br>
...@@ -64,6 +58,7 @@ export default { ...@@ -64,6 +58,7 @@ export default {
alertMsg:'', alertMsg:'',
initialName: '', //used to compare with updated values initialName: '', //used to compare with updated values
initialRestriction: '', initialRestriction: '',
image: "profile/default_avatar.png",
} }
}, },
computed: { computed: {
...@@ -73,24 +68,32 @@ export default { ...@@ -73,24 +68,32 @@ export default {
return { return {
upName: this.profile.name, upName: this.profile.name,
upRestricted: this.profile.restricted, upRestricted: this.profile.restricted,
upImage: this.profile.profileImageUrl, upImage: "profile/default_avatar.png",
} }
}, },
iconColor() { iconColor() {
return "#D9D9D9" return "#D9D9D9"
}, },
hasProfileImage() {
return false;
}
}, },
beforeMount() {//used to compare with changed values beforeMount() {//used to compare with changed values
this.initialName = this.profile.name; this.initialName = this.profile.name;
this.initialRestriction = this.profile.restricted; this.initialRestriction = this.profile.restricted;
if(this.profile.profileImageUrl !== ''){
this.image = this.profile.profileImageUrl;
}
}, },
methods: { methods: {
changeProfile(){ changeProfile(){
router.push("/selectProfile"); router.push("/selectProfile");
}, },
updateImg() {
let file = document.getElementById("profile_img").files[0];
let reader = new FileReader();
reader.onload = function (ev) {
document.getElementById("profile_img_preview").src = ev.target.result;
};
reader.readAsDataURL(file);
},
async deleteProfile() { async deleteProfile() {
const id = this.profile.id; const id = this.profile.id;
API.deleteProfile(id).then(() => { API.deleteProfile(id).then(() => {
...@@ -115,11 +118,27 @@ export default { ...@@ -115,11 +118,27 @@ export default {
API.updateProfile( API.updateProfile(
id,{ id,{
name:newName, name:newName,
profileImageUrl:this.updatedProfile.upImage, profileImageUrl:null,
isRestricted: newRestricted, isRestricted: newRestricted,
} }
).then((savedProfile)=>{ ).then((savedProfile)=>{
useAuthStore().setProfile(savedProfile); useAuthStore().setProfile(savedProfile);
const id = this.profile.id;
let image = document.getElementById("profile_img").files[0];
if (typeof image !== 'undefined') {
API.uploadProfileImage(image, id)
.then((updatedProfile) => {
useAuthStore().setProfile(updatedProfile);
}).catch(()=> {
this.alertMsg = "Bilde kunne ikke bli oppdatert (bildekrav: JPEG mindre enn 512kB)"
});
}
else {
useAuthStore().setProfile(savedProfile);
this.alertMsg = "Profil oppdatert."
return;
}
this.alertMsg = "Profil oppdatert." this.alertMsg = "Profil oppdatert."
}).catch(error=> { }).catch(error=> {
console.log(error) console.log(error)
......
...@@ -96,8 +96,8 @@ export default { ...@@ -96,8 +96,8 @@ 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();
let month= (fullExpirationDate.getMonth()+1).toString(); let month= (fullExpirationDate.getMonth()+1).toString().padStart(2,'0');
let year= fullExpirationDate.getFullYear().toString(); let year= fullExpirationDate.getFullYear().toString().padStart(2,'0');
return day + "." + month + "." + year; return day + "." + month + "." + year;
} }
......
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