Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
Géocontrib Frontend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Redmine
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Contributor 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
externe Matthieu
Géocontrib Frontend
Commits
01b63128
Commit
01b63128
authored
3 years ago
by
Timothee P
Browse files
Options
Downloads
Patches
Plain Diff
Import attachment file
parent
eb5447a5
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/components/feature/FeatureAttachmentForm.vue
+24
-14
24 additions, 14 deletions
src/components/feature/FeatureAttachmentForm.vue
src/store/modules/feature.js
+25
-9
25 additions, 9 deletions
src/store/modules/feature.js
with
49 additions
and
23 deletions
src/components/feature/FeatureAttachmentForm.vue
+
24
−
14
View file @
01b63128
...
...
@@ -34,27 +34,24 @@
<div
class=
"required field"
>
<label>
Fichier (PDF, PNG, JPEG)
</label>
<!-- // todo : mettre en place la sélection de fichier -->
<label
@
click=
"selectFile"
class=
"ui icon button"
:for=
"form.attachment_file.id_for_label"
>
<!-- @click="selectFile" -->
<label
class=
"ui icon button"
for=
"attachment_file"
>
<i
class=
"file icon"
></i>
<span
v-if=
"form.attachment_file.value"
class=
"label"
>
{{
form
.
attachment_file
.
value
}}
</span>
<span
v-else
class=
"label"
>
Sélectionner un fichier ...
</span>
<span
v-else
class=
"label"
>
Sélectionner un fichier ...
</span>
</label>
<!-- // todo: récupérer la valeur :accept="IMAGE_FORMAT" -->
<!-- @change="processImgData" -->
<input
@
change=
"onFileChange"
type=
"file"
style=
"display: none"
:name=
"form.attachment_file.html_name"
class=
"image_file"
:id=
"form.attachment_file.id_for_label"
@
change=
"updateStore"
id=
"attachment_file"
/>
<!-- // todo: récupérer la valeur :accept="IMAGE_FORMAT" -->
<!-- @change="processImgData" -->
{{
form
.
attachment_file
.
errors
}}
</div>
</div>
...
...
@@ -81,6 +78,7 @@ export default {
data
()
{
return
{
fileToImport
:
null
,
form
:
{
title
:
{
errors
:
null
,
...
...
@@ -94,7 +92,6 @@ export default {
},
attachment_file
:
{
errors
:
null
,
id_for_label
:
"
titre
"
,
html_name
:
"
titre
"
,
label
:
"
Titre
"
,
value
:
""
,
...
...
@@ -116,9 +113,13 @@ export default {
methods
:
{
initForm
(
attachmentForm
)
{
console
.
log
(
"
initForm
"
);
for
(
let
el
in
attachmentForm
)
{
if
(
el
&&
this
.
form
[
el
])
{
this
.
form
[
el
].
value
=
attachmentForm
[
el
];
this
.
form
[
el
].
value
=
el
===
"
attachment_file
"
?
attachmentForm
[
el
].
split
(
"
/
"
).
pop
()
//* keep only the file name
:
attachmentForm
[
el
];
}
}
},
...
...
@@ -128,15 +129,24 @@ export default {
this
.
attachmentForm
.
dataKey
);
},
selectFile
()
{},
updateStore
()
{
this
.
$store
.
commit
(
"
feature/UPDATE_ATTACHMENT_FORM
"
,
{
dataKey
:
this
.
attachmentForm
.
dataKey
,
title
:
this
.
form
.
title
.
value
,
attachment_file
:
this
.
form
.
attachment_file
.
value
,
info
:
this
.
form
.
info
.
value
,
fileToImport
:
this
.
fileToImport
,
});
},
onFileChange
(
e
)
{
const
files
=
e
.
target
.
files
||
e
.
dataTransfer
.
files
;
console
.
log
(
e
,
files
);
if
(
!
files
.
length
)
return
;
this
.
fileToImport
=
files
[
0
];
this
.
form
.
attachment_file
.
value
=
files
[
0
].
name
;
this
.
updateStore
();
//this.$store.commit("feature_type/SET_FILE_TO_IMPORT", this.fileToImport);
},
},
mounted
()
{
...
...
This diff is collapsed.
Click to expand it.
src/store/modules/feature.js
+
25
−
9
View file @
01b63128
...
...
@@ -58,9 +58,11 @@ const feature = {
axios
.
get
(
`
${
this
.
state
.
configuration
.
VUE_APP_DJANGO_API_BASE
}
projects/
${
project_slug
}
/feature/`
)
.
then
((
response
)
=>
{
const
features
=
response
.
data
.
features
;
commit
(
"
SET_FEATURES
"
,
features
);
//dispatch("map/ADD_FEATURES", null, { root: true }); //todo: should check if map was initiated
if
(
response
.
status
===
200
&&
response
.
data
)
{
const
features
=
response
.
data
.
features
;
commit
(
"
SET_FEATURES
"
,
features
);
//dispatch("map/ADD_FEATURES", null, { root: true }); //todo: should check if map was initiated
}
})
.
catch
((
error
)
=>
{
throw
error
;
...
...
@@ -90,7 +92,9 @@ const feature = {
axios
.
put
(
`
${
this
.
state
.
configuration
.
VUE_APP_DJANGO_API_BASE
}
features/
${
state
.
form
.
feature_id
}
/`
,
geojson
)
.
then
((
response
)
=>
{
console
.
log
(
response
,
response
.
data
)
if
(
response
.
status
===
200
&&
response
.
data
)
{
console
.
log
(
response
,
response
.
data
)
}
})
.
catch
((
error
)
=>
{
throw
error
;
...
...
@@ -99,8 +103,10 @@ const feature = {
axios
.
post
(
`
${
this
.
state
.
configuration
.
VUE_APP_DJANGO_API_BASE
}
features/`
,
geojson
)
.
then
((
response
)
=>
{
console
.
log
(
response
,
response
.
data
)
dispatch
(
"
SEND_ATTACHMENTS
"
,
response
.
data
.
id
)
if
(
response
.
status
===
201
&&
response
.
data
)
{
console
.
log
(
response
,
response
.
data
)
dispatch
(
"
SEND_ATTACHMENTS
"
,
response
.
data
.
id
)
}
})
.
catch
((
error
)
=>
{
throw
error
;
...
...
@@ -109,11 +115,21 @@ const feature = {
},
SEND_ATTACHMENTS
({
state
},
featureId
)
{
for
(
let
attachment
of
state
.
attachmentFormset
)
{
for
(
let
attacht
of
state
.
attachmentFormset
)
{
let
formdata
=
new
FormData
();
formdata
.
append
(
"
file
"
,
attacht
.
fileToImport
,
attacht
.
fileToImport
.
name
);
const
data
=
{
title
:
attacht
.
title
,
info
:
attacht
.
info
,
}
formdata
.
append
(
"
data
"
,
JSON
.
stringify
(
data
));
axios
.
post
(
`
${
this
.
state
.
configuration
.
VUE_APP_DJANGO_API_BASE
}
features/
${
featureId
}
/attachments/`
,
attachment
)
.
post
(
`
${
this
.
state
.
configuration
.
VUE_APP_DJANGO_API_BASE
}
features/
${
featureId
}
/attachments/`
,
formdata
)
.
then
((
response
)
=>
{
console
.
log
(
response
,
response
.
data
)
if
(
response
.
status
===
200
&&
response
.
data
)
{
console
.
log
(
response
,
response
.
data
)
return
"
La pièce jointe a bien été ajouté
"
}
})
.
catch
((
error
)
=>
{
throw
error
;
...
...
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