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
4c0ebe73
Commit
4c0ebe73
authored
2 years ago
by
Ingrid Martinsheimen Egge
Browse files
Options
Downloads
Patches
Plain Diff
bedre feilmeldinger. forenklet metoder
parent
c4ba80e2
No related branches found
Branches containing commit
No related tags found
1 merge request
!21
Merge profilinnstillinger into main
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/components/EditAccount.vue
+33
-30
33 additions, 30 deletions
src/components/EditAccount.vue
src/components/EditProfile.vue
+43
-24
43 additions, 24 deletions
src/components/EditProfile.vue
src/util/API.js
+2
-1
2 additions, 1 deletion
src/util/API.js
with
78 additions
and
55 deletions
src/components/EditAccount.vue
+
33
−
30
View file @
4c0ebe73
<
template
>
<h2>
Konto-innstillinger
</h2>
<form
@
submit.prevent=
"submit"
>
<p
class=
"infoText"
>
OBS: Kontakt admin dersom du ønsker å oppdatere epost
</p><br>
...
...
@@ -15,6 +16,8 @@
<p
:style=
{color:alertMsgColor} id="alert">
{{
alertMsg
}}
</p>
</form>
<button
@
click=
"logOut"
>
Logg ut
</button>
<br>
<br>
<hr>
...
...
@@ -61,37 +64,30 @@ export default {
},
methods
:
{
saveAccountSettings
(){
//passord
if
(
this
.
updatedAccount
.
upPassword
.
length
===
0
){
//Oppdater ikke passordet dersom man ikke har gjort endringer
const
id
=
this
.
account
.
id
;
const
id
=
this
.
account
.
id
;
API
.
updateAccount
(
id
,{
firstname
:
this
.
updatedAccount
.
upFirstname
,
password
:
null
,
}
).
then
((
savedAccount
)
=>
{
useAuthStore
().
setAccount
(
savedAccount
);
this
.
setAlertText
(
"
Melding: Bruker oppdatert.
"
,
'
light-green
'
);
}).
catch
((
error
)
=>
{
this
.
setAlertText
(
"
Melding: Det oppsto en feil.
"
,
'
red
'
);
console
.
log
(
error
)
})
}
else
{
const
id
=
this
.
account
.
id
;
let
newPassword
=
null
let
newFirstName
=
null
;
API
.
updateAccount
(
id
,{
firstname
:
this
.
updatedAccount
.
upFirstname
,
password
:
this
.
updatedAccount
.
upPassword
,
}
).
then
((
savedAccount
)
=>
{
useAuthStore
().
setAccount
(
savedAccount
);
this
.
setAlertText
(
"
Melding: Konto oppdatert.
"
,
'
light-green
'
)
}).
catch
((
error
)
=>
{
this
.
setAlertText
(
"
Melding: Det oppsto en feil.
"
,
'
red
'
);
console
.
log
(
error
)
})
//checks if username and password have been changed
if
(
this
.
updatedAccount
.
upPassword
.
length
!==
0
)
{
newPassword
=
this
.
updatedAccount
.
upPassword
;
}
if
(
this
.
updatedAccount
.
upFirstname
!==
''
){
newFirstName
=
this
.
updatedAccount
.
upFirstname
;
}
API
.
updateAccount
(
id
,{
firstname
:
newFirstName
,
password
:
newPassword
,
}
).
then
((
savedAccount
)
=>
{
useAuthStore
().
setAccount
(
savedAccount
);
this
.
setAlertText
(
"
Konto oppdatert.
"
,
'
light-green
'
)
}).
catch
((
error
)
=>
{
this
.
setAlertText
(
"
Det oppsto en feil.
"
,
'
red
'
);
})
},
deleteAccount
(){
if
(
this
.
deletionConfirmation
===
false
){
...
...
@@ -108,6 +104,14 @@ export default {
})
}
},
logOut
(){
useAuthStore
().
logout
();
router
.
push
(
'
/login
'
)
},
setAlertText
(
text
,
color
){
switch
(
color
)
{
case
'
red
'
:
...
...
@@ -140,9 +144,8 @@ export default {
break
;
}
}
}
}
}
</
script
>
<
style
scoped
lang=
"scss"
>
...
...
This diff is collapsed.
Click to expand it.
src/components/EditProfile.vue
+
43
−
24
View file @
4c0ebe73
...
...
@@ -62,6 +62,8 @@ export default {
return
{
alertMsg
:
''
,
alertMsgColor
:
'
black
'
,
initialName
:
''
,
//used to compare with updated values
initialRestriction
:
''
,
}
},
computed
:
{
...
...
@@ -81,6 +83,10 @@ export default {
return
this
.
updatedProfile
.
upImage
.
length
>
0
;
}
},
beforeMount
()
{
this
.
initialName
=
this
.
profile
.
name
;
this
.
initialRestriction
=
this
.
profile
.
restricted
;
},
methods
:
{
changeProfile
(){
router
.
push
(
"
/selectProfile
"
);
...
...
@@ -89,11 +95,46 @@ export default {
const
id
=
this
.
profile
.
id
;
API
.
deleteProfile
(
id
).
then
(()
=>
{
router
.
push
(
'
/selectProfile
'
)
}).
catch
((
error
)
=>
{
this
.
setAlertText
(
"
Det oppsto en feil ved sletting profil:
"
+
error
,
'
red
'
)
}).
catch
((
_
)
=>
{
this
.
setAlertText
(
"
Alle kontoer må ha minst en profil (profil ble ikke slettet)
"
,
'
red
'
)
})
},
saveUserSettings
(){
const
id
=
this
.
profile
.
id
;
let
newName
=
null
;
let
newRestricted
=
null
;
if
(
this
.
updatedProfile
.
upName
!==
this
.
initialName
){
newName
=
this
.
updatedProfile
.
upName
}
if
(
this
.
updatedProfile
.
upRestricted
!==
this
.
initialRestriction
){
newRestricted
=
this
.
updatedProfile
.
upRestricted
}
API
.
updateProfile
(
id
,{
name
:
newName
,
profileImageUrl
:
this
.
updatedProfile
.
upImage
,
restricted
:
newRestricted
,
}
).
then
((
savedProfile
)
=>
{
useAuthStore
().
setProfile
(
savedProfile
);
this
.
setAlertText
(
"
Profil oppdatert.
"
,
'
light-green
'
)
}).
catch
(
error
=>
{
if
(
error
.
message
===
'
400
'
)
{
if
(
this
.
updatedProfile
.
name
!==
this
.
initialName
){
this
.
setAlertText
(
'
Det oppsto en feil: Det finnes allerede en bruker med samme navn
'
,
'
red
'
)
}
else
{
this
.
setAlertText
(
'
Det oppsto en feil: Sørg for at det finnes mist en standard profil på kontoen
'
,
'
red
'
)
}
}
else
{
this
.
setAlertText
(
"
Det oppsto en feil.
"
,
'
red
'
)
}
})
},
...
...
@@ -101,29 +142,7 @@ export default {
updateImage
(){
//todo update image preview
},
saveUserSettings
(){
const
id
=
this
.
profile
.
id
;
const
numOfProfiles
=
API
.
getProfiles
().
length
if
(
numOfProfiles
===
1
&&
this
.
updatedProfile
.
upRestricted
===
true
){
this
.
setAlertText
(
"
Du må ha minst en standardprofil per konto. (ingen endringer er gjort)
"
,
'
red
'
)
}
else
{
API
.
updateProfile
(
id
,{
name
:
this
.
updatedProfile
.
upName
,
profileImageUrl
:
this
.
updatedProfile
.
upImage
,
restricted
:
this
.
updatedProfile
.
upRestricted
,
}
).
then
((
savedProfile
)
=>
{
useAuthStore
().
setProfile
(
savedProfile
);
this
.
setAlertText
(
"
profil oppdatert.
"
,
'
light-green
'
)
}).
catch
((
error
)
=>
{
this
.
setAlertText
(
"
Det oppsto en feil
"
,
'
red
'
)
console
.
log
(
error
)
})
}
},
chooseProfilePicture
(){
this
.
setAlertText
(
"
skriv inn bildelenke i feltet, og oppdater innstillinger
"
,
'
black
'
)
},
...
...
This diff is collapsed.
Click to expand it.
src/util/API.js
+
2
−
1
View file @
4c0ebe73
...
...
@@ -287,6 +287,7 @@ export const API = {
/**
* Updates the profile name, restriction and profile image
* If error: "error.message" returns the status code
* @param id profile id
* @param request
* @returns {Promise<*>}
...
...
@@ -306,7 +307,7 @@ export const API = {
return
response
.
data
;
})
.
catch
((
error
)
=>
{
throw
new
Error
(
"
E
rror
when updating profile:
"
+
error
);
throw
new
Error
(
e
rror
.
response
.
status
);
});
},
...
...
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