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
e3049f6c
Commit
e3049f6c
authored
2 years ago
by
Katarzyna Szlejter
Browse files
Options
Downloads
Plain Diff
Merge main into pincode-view
parents
3e382922
ae325e33
No related branches found
No related tags found
2 merge requests
!17
Pincode view
,
!16
Pincode view
Pipeline
#224230
failed
2 years ago
Stage: build
Stage: test
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/util/API.js
+131
-106
131 additions, 106 deletions
src/util/API.js
src/views/ProfileCreationView.vue
+29
-13
29 additions, 13 deletions
src/views/ProfileCreationView.vue
with
160 additions
and
119 deletions
src/util/API.js
+
131
−
106
View file @
e3049f6c
...
...
@@ -77,20 +77,46 @@ export const API = {
}
else
{
router
.
push
(
"
/
"
)
}
})
.
catch
(()
=>
{
throw
new
Error
(
"
Profile not found or not accessible
"
)
})
},
/**
* Upload profile image
*
* @param {Blob} image - the image file contents to upload. Must be a JPEG no bigger than 512kB
* @param {Number} profileId - the ID of the profile to upload this image to
* @returns {Promise<String>} A Promise that resolves to the URL of the uploaded image
*/
uploadProfileImage
:
async
(
image
,
profileId
)
=>
{
const
authStore
=
useAuthStore
();
let
fd
=
new
FormData
();
fd
.
append
(
"
file
"
,
image
);
fd
.
append
(
"
profileId
"
,
profileId
);
return
axios
.
post
(
`
${
import
.
meta
.
env
.
VITE_BACKEND_URL
}
/img`
,
fd
,
{
headers
:
{
Authorization
:
`Bearer
${
authStore
.
token
}
`
,
}
})
.
then
((
response
)
=>
{
return
response
.
data
;
})
.
catch
(()
=>
{
throw
new
Error
();
})
},
/**
* Sends a request to create a new profile on the currently logged in account
*
* @typedef {{name: string, profileImageUrl: string, isRestricted: boolean}} ProfileType
* @param {ProfileType} profile
* @returns
* @typedef {{name: string,
id?: number, accountId?: number,
profileImageUrl: string, isRestricted: boolean}} ProfileType
* @param {ProfileType} profile
- the partial data of profile to create
* @returns
{Promise<ProfileType>} the full profile after saving, with id and account ID set
*/
addProfile
:
async
(
profile
)
=>
{
const
authStore
=
useAuthStore
();
...
...
@@ -98,9 +124,8 @@ export const API = {
throw
new
Error
();
}
return
axios
.
post
(
import
.
meta
.
env
.
VITE_BACKEND_URL
+
'
/profile
'
,
{
return
axios
.
post
(
import
.
meta
.
env
.
VITE_BACKEND_URL
+
'
/profile
'
,
profile
,
{
headers
:
{
Authorization
:
"
Bearer
"
+
authStore
.
token
},
body
:
profile
})
.
then
((
response
)
=>
{
return
response
.
data
;
...
...
This diff is collapsed.
Click to expand it.
src/views/ProfileCreationView.vue
+
29
−
13
View file @
e3049f6c
<
script
>
import
Toggle
from
'
../components/Toggle.vue
'
;
import
{
mapStores
}
from
'
pinia
'
;
import
router
from
'
../router
'
import
{
API
}
from
'
../util/API
'
;
import
{
useAuthStore
}
from
'
../stores/authStore
'
export
default
{
data
:
()
=>
{
...
...
@@ -14,20 +16,33 @@ export default {
};
},
methods
:
{
submit
()
{
this
.
profile
.
isRestricted
=
this
.
$refs
.
toggle
.
state
;
API
.
addProfile
(
this
.
profile
);
async
submit
()
{
await
API
.
addProfile
(
this
.
profile
)
.
then
((
profile
)
=>
{
let
id
=
profile
.
id
;
let
image
=
document
.
getElementById
(
"
profile_img
"
).
files
[
0
];
API
.
uploadProfileImage
(
image
,
id
)
.
then
((
updatedProfile
)
=>
{
this
.
authStore
.
profile
=
updatedProfile
;
router
.
push
(
"
/
"
);
});
})
},
updateImg
()
{
let
file
=
document
.
getElementById
(
"
avatar
"
).
files
[
0
];
let
file
=
document
.
getElementById
(
"
profile_img
"
).
files
[
0
];
let
reader
=
new
FileReader
();
reader
.
onload
=
function
(
ev
)
{
document
.
getElementById
(
"
avatar
_preview
"
).
src
=
ev
.
target
.
result
;
document
.
getElementById
(
"
profile_img
_preview
"
).
src
=
ev
.
target
.
result
;
};
reader
.
readAsDataURL
(
file
);
}
},
components
:
{
Toggle
}
computed
:
{
...
mapStores
(
useAuthStore
)
}
}
</
script
>
...
...
@@ -36,20 +51,21 @@ export default {
<h1>
Ny profil
</h1>
<form
action=
"todo"
method=
"post"
>
<label
for=
"
avatar"
id=
"avatar
_label"
>
<label
for=
"
profile_img"
id=
"profile_img
_label"
>
<div
class=
"img_hover"
>
<img
:src=
"image"
alt=
"fjes"
id=
"
avatar
_preview"
>
<img
:src=
"image"
alt=
"fjes"
id=
"
profile_img
_preview"
>
<p
class=
"hover_text"
>
Klikk for å endre
</p>
</div>
</label>
<input
type=
"file"
name=
"avatar"
id=
"avatar"
@
change=
"updateImg"
>
<input
@
change=
"updateImg"
type=
"file"
accept=
".jpeg, .jpg"
id=
"profile_img"
name=
"profile_img"
>
<label
for=
"name"
>
Navn
</label>
<input
name=
"name"
type=
"text"
v-model=
"profile.name"
>
<div
class=
"check_container"
>
<label
for=
"
chil
d"
>
Begrenset:
</label>
<
Toggle
ref=
"toggle"
/
>
<label
for=
"
limite
d"
>
Begrenset:
</label>
<
input
type=
"checkbox"
name=
"limited"
id=
"limited"
>
</div>
</form>
<button
@
click=
"submit"
>
Opprett
</button>
...
...
@@ -84,7 +100,7 @@ main {
}
}
#
avatar
_label
{
#
profile_img
_label
{
display
:
flex
;
justify-content
:
center
;
width
:
100%
;
...
...
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