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
GéoContrib
Géocontrib Frontend
Commits
6b7b3102
Commit
6b7b3102
authored
3 years ago
by
Timothee P
Browse files
Options
Downloads
Patches
Plain Diff
allow delete on attachment and linkedfeature if only one
parent
6ec8fd72
No related branches found
No related tags found
2 merge requests
!213
2.3.2-rc1
,
!208
REDMINE_ISSUE-11814
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/store/modules/feature.js
+45
-94
45 additions, 94 deletions
src/store/modules/feature.js
with
45 additions
and
94 deletions
src/store/modules/feature.js
+
45
−
94
View file @
6b7b3102
...
@@ -180,7 +180,6 @@ const feature = {
...
@@ -180,7 +180,6 @@ const feature = {
SEND_FEATURE
({
state
,
rootState
,
commit
,
dispatch
},
routeName
)
{
SEND_FEATURE
({
state
,
rootState
,
commit
,
dispatch
},
routeName
)
{
commit
(
"
DISPLAY_LOADER
"
,
"
Le signalement est en cours de création
"
,
{
root
:
true
})
commit
(
"
DISPLAY_LOADER
"
,
"
Le signalement est en cours de création
"
,
{
root
:
true
})
const
message
=
routeName
===
"
editer-signalement
"
?
"
Le signalement a été mis à jour
"
:
"
Le signalement a été crée
"
;
const
message
=
routeName
===
"
editer-signalement
"
?
"
Le signalement a été mis à jour
"
:
"
Le signalement a été crée
"
;
function
redirect
(
featureId
)
{
function
redirect
(
featureId
)
{
dispatch
(
dispatch
(
'
GET_PROJECT_FEATURE
'
,
'
GET_PROJECT_FEATURE
'
,
...
@@ -228,110 +227,65 @@ const feature = {
...
@@ -228,110 +227,65 @@ const feature = {
}
}
}
}
let
url
=
`
${
rootState
.
configuration
.
VUE_APP_DJANGO_API_BASE
}
features/`
if
(
routeName
===
"
editer-signalement
"
)
{
if
(
routeName
===
"
editer-signalement
"
)
{
return
axios
url
+=
`
${
state
.
form
.
feature_id
}
/?`
+
.
put
(
`
${
rootState
.
configuration
.
VUE_APP_DJANGO_API_BASE
}
features/
${
state
.
form
.
feature_id
}
/?`
+
`feature_type__slug=
${
rootState
.
feature_type
.
current_feature_type_slug
}
`
+
`feature_type__slug=
${
rootState
.
feature_type
.
current_feature_type_slug
}
`
+
`&project__slug=
${
rootState
.
project_slug
}
`
`&project__slug=
${
rootState
.
project_slug
}
`
}
,
geojson
)
.
then
((
response
)
=>
{
if
(
response
.
status
===
200
&&
response
.
data
)
{
if
(
state
.
attachmentFormset
.
length
>
0
||
state
.
linkedFormset
.
length
>
0
)
{
handleOtherForms
(
response
.
data
.
id
)
}
else
{
redirect
(
response
.
data
.
id
)
}
}
})
.
catch
((
error
)
=>
{
commit
(
"
DISCARD_LOADER
"
,
null
,
{
root
:
true
})
if
(
error
.
message
===
"
Network Error
"
||
window
.
navigator
.
onLine
===
false
)
{
let
arraysOffline
=
[];
let
localStorageArray
=
localStorage
.
getItem
(
"
geocontrib_offline
"
);
if
(
localStorageArray
)
{
arraysOffline
=
JSON
.
parse
(
localStorageArray
);
}
let
updateMsg
=
{
project
:
rootState
.
project_slug
,
type
:
'
put
'
,
featureId
:
state
.
form
.
feature_id
,
geojson
:
geojson
};
arraysOffline
.
push
(
updateMsg
);
localStorage
.
setItem
(
"
geocontrib_offline
"
,
JSON
.
stringify
(
arraysOffline
));
router
.
push
({
name
:
"
offline-signalement
"
,
params
:
{
slug_type_signal
:
rootState
.
feature_type
.
current_feature_type_slug
},
});
return
axios
({
url
,
method
:
routeName
===
"
editer-signalement
"
?
"
PUT
"
:
"
POST
"
,
data
:
geojson
}).
then
((
response
)
=>
{
if
((
response
.
status
===
200
||
response
.
status
===
201
)
&&
response
.
data
)
{
if
(
state
.
attachmentFormset
.
length
>
0
||
state
.
linkedFormset
.
length
>
0
||
state
.
attachmentFormset
.
length
>
0
||
state
.
attachmentsToDelete
.
length
>
0
)
{
handleOtherForms
(
response
.
data
.
id
)
}
else
{
redirect
(
response
.
data
.
id
)
}
}
else
{
}
console
.
log
(
error
)
})
throw
error
;
.
catch
((
error
)
=>
{
commit
(
"
DISCARD_LOADER
"
,
null
,
{
root
:
true
})
if
(
error
.
message
===
"
Network Error
"
||
window
.
navigator
.
onLine
===
false
)
{
let
arraysOffline
=
[];
let
localStorageArray
=
localStorage
.
getItem
(
"
geocontrib_offline
"
);
if
(
localStorageArray
)
{
arraysOffline
=
JSON
.
parse
(
localStorageArray
);
}
}
let
updateMsg
=
{
project
:
rootState
.
project_slug
,
type
:
'
put
'
,
featureId
:
state
.
form
.
feature_id
,
geojson
:
geojson
};
arraysOffline
.
push
(
updateMsg
);
localStorage
.
setItem
(
"
geocontrib_offline
"
,
JSON
.
stringify
(
arraysOffline
));
router
.
push
({
name
:
"
offline-signalement
"
,
params
:
{
slug_type_signal
:
rootState
.
feature_type
.
current_feature_type_slug
},
});
}
else
{
console
.
error
(
error
)
throw
error
;
throw
error
;
});
}
}
else
{
throw
error
;
return
axios
});
.
post
(
`
${
rootState
.
configuration
.
VUE_APP_DJANGO_API_BASE
}
features/`
,
geojson
)
.
then
((
response
)
=>
{
if
(
response
.
status
===
201
&&
response
.
data
)
{
if
(
state
.
attachmentFormset
.
length
>
0
||
state
.
linkedFormset
.
length
>
0
)
{
handleOtherForms
(
response
.
data
.
id
)
}
else
{
redirect
(
response
.
data
.
id
)
}
}
})
.
catch
((
error
)
=>
{
commit
(
"
DISCARD_LOADER
"
,
null
,
{
root
:
true
})
if
(
error
.
message
===
"
Network Error
"
||
window
.
navigator
.
onLine
===
false
)
{
let
arraysOffline
=
[];
let
localStorageArray
=
localStorage
.
getItem
(
"
geocontrib_offline
"
);
if
(
localStorageArray
)
{
arraysOffline
=
JSON
.
parse
(
localStorageArray
);
}
let
updateMsg
=
{
project
:
rootState
.
project_slug
,
type
:
'
post
'
,
geojson
:
geojson
};
arraysOffline
.
push
(
updateMsg
);
localStorage
.
setItem
(
"
geocontrib_offline
"
,
JSON
.
stringify
(
arraysOffline
));
router
.
push
({
name
:
"
offline-signalement
"
,
params
:
{
slug_type_signal
:
rootState
.
feature_type
.
current_feature_type_slug
},
});
}
else
{
console
.
log
(
error
)
throw
error
;
}
});
}
// this.$store.dispatch("GET_ALL_PROJECTS"), //* & refresh project list
},
},
async
SEND_ATTACHMENTS
({
state
,
rootState
,
dispatch
},
featureId
)
{
async
SEND_ATTACHMENTS
({
state
,
rootState
,
dispatch
},
featureId
)
{
const
DJANGO_API_BASE
=
rootState
.
configuration
.
VUE_APP_DJANGO_API_BASE
;
const
DJANGO_API_BASE
=
rootState
.
configuration
.
VUE_APP_DJANGO_API_BASE
;
function
addFile
(
attachment
,
attchmtId
)
{
function
addFile
(
attachment
,
attchmtId
)
{
let
formdata
=
new
FormData
();
let
formdata
=
new
FormData
();
formdata
.
append
(
"
file
"
,
attachment
.
fileToImport
,
attachment
.
fileToImport
.
name
);
formdata
.
append
(
"
file
"
,
attachment
.
fileToImport
,
attachment
.
fileToImport
.
name
);
return
axios
return
axios
.
put
(
`
${
DJANGO_API_BASE
}
features/
${
featureId
}
/attachments/
${
attchmtId
}
/upload-file/`
,
formdata
)
.
put
(
`
${
DJANGO_API_BASE
}
features/
${
featureId
}
/attachments/
${
attchmtId
}
/upload-file/`
,
formdata
)
.
then
((
response
)
=>
{
.
then
((
response
)
=>
{
console
.
log
(
response
)
if
(
response
&&
response
.
status
===
200
)
{
console
.
log
(
response
.
status
)
}
return
response
;
return
response
;
})
})
.
catch
((
error
)
=>
{
.
catch
((
error
)
=>
{
...
@@ -349,9 +303,7 @@ const feature = {
...
@@ -349,9 +303,7 @@ const feature = {
return
axios
return
axios
.
post
(
`
${
DJANGO_API_BASE
}
features/
${
featureId
}
/attachments/`
,
formdata
)
.
post
(
`
${
DJANGO_API_BASE
}
features/
${
featureId
}
/attachments/`
,
formdata
)
.
then
((
response
)
=>
{
.
then
((
response
)
=>
{
console
.
log
(
response
)
if
(
response
&&
response
.
status
===
201
&&
attachment
.
fileToImport
)
{
if
(
response
&&
response
.
status
===
201
&&
attachment
.
fileToImport
)
{
console
.
log
(
response
.
status
)
return
addFile
(
attachment
,
response
.
data
.
id
);
return
addFile
(
attachment
,
response
.
data
.
id
);
}
}
return
response
return
response
...
@@ -364,9 +316,7 @@ const feature = {
...
@@ -364,9 +316,7 @@ const feature = {
return
axios
return
axios
.
put
(
`
${
DJANGO_API_BASE
}
features/
${
featureId
}
/attachments/
${
attachment
.
id
}
/`
,
formdata
)
.
put
(
`
${
DJANGO_API_BASE
}
features/
${
featureId
}
/attachments/
${
attachment
.
id
}
/`
,
formdata
)
.
then
((
response
)
=>
{
.
then
((
response
)
=>
{
console
.
log
(
response
)
if
(
response
&&
response
.
status
===
200
&&
attachment
.
fileToImport
)
{
if
(
response
&&
response
.
status
===
200
&&
attachment
.
fileToImport
)
{
console
.
log
(
response
.
status
)
return
addFile
(
attachment
,
response
.
data
.
id
);
return
addFile
(
attachment
,
response
.
data
.
id
);
}
}
})
})
...
@@ -386,6 +336,7 @@ const feature = {
...
@@ -386,6 +336,7 @@ const feature = {
return
dispatch
(
"
DELETE_ATTACHMENTS
"
,
payload
)
return
dispatch
(
"
DELETE_ATTACHMENTS
"
,
payload
)
.
then
((
response
)
=>
response
);
.
then
((
response
)
=>
response
);
}
}
const
promisesResult
=
await
Promise
.
all
([
const
promisesResult
=
await
Promise
.
all
([
...
state
.
attachmentFormset
.
map
((
attachment
)
=>
putOrPostAttachement
(
attachment
)),
...
state
.
attachmentFormset
.
map
((
attachment
)
=>
putOrPostAttachement
(
attachment
)),
...
state
.
attachmentsToDelete
.
map
((
attachmentsId
)
=>
deleteAttachement
(
attachmentsId
,
featureId
))
...
state
.
attachmentsToDelete
.
map
((
attachmentsId
)
=>
deleteAttachement
(
attachmentsId
,
featureId
))
...
...
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