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
672e2ca4
Commit
672e2ca4
authored
2 years ago
by
Timothee P
Browse files
Options
Downloads
Patches
Plain Diff
send basemaps synchronously to keep creation order in backend
parent
e2b352f6
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/store/modules/map.store.js
+27
-26
27 additions, 26 deletions
src/store/modules/map.store.js
with
27 additions
and
26 deletions
src/store/modules/map.store.js
+
27
−
26
View file @
672e2ca4
...
...
@@ -121,25 +121,29 @@ const map = {
},
async
SAVE_BASEMAPS
({
state
,
rootState
,
dispatch
},
newBasemapIds
)
{
const
DJANGO_API_BASE
=
this
.
state
.
configuration
.
VUE_APP_DJANGO_API_BASE
;
function
postOrPut
(
basemap
)
{
basemap
[
'
project
'
]
=
rootState
.
projects
.
project
.
slug
;
if
(
newBasemapIds
.
includes
(
basemap
.
id
))
{
return
axios
.
post
(
`
${
DJANGO_API_BASE
}
base-maps/`
,
basemap
)
.
then
((
response
)
=>
response
)
.
catch
((
error
)
=>
{
console
.
error
(
error
);
return
error
;
});
}
else
{
return
axios
.
put
(
`
${
DJANGO_API_BASE
}
base-maps/
${
basemap
.
id
}
/`
,
basemap
)
.
then
((
response
)
=>
response
)
.
catch
((
error
)
=>
{
console
.
error
(
error
);
return
error
;
});
//* send new basemaps synchronously to create their ids in the order they were created in the form
let
promisesResult
=
[];
function
postOrPut
(
basemapsToSend
)
{
if
(
basemapsToSend
.
length
>
0
)
{
let
basemap
=
basemapsToSend
.
shift
();
//* remove and return first item in array
basemap
[
'
project
'
]
=
rootState
.
projects
.
project
.
slug
;
let
url
=
`
${
rootState
.
configuration
.
VUE_APP_DJANGO_API_BASE
}
base-maps/`
;
if
(
!
newBasemapIds
.
includes
(
basemap
.
id
))
url
+=
`
${
basemap
.
id
}
/`
;
promisesResult
.
push
(
axios
({
url
,
method
:
newBasemapIds
.
includes
(
basemap
.
id
)
?
'
POST
'
:
'
PUT
'
,
data
:
basemap
,
})
.
then
((
response
)
=>
{
postOrPut
(
basemapsToSend
);
return
response
;
})
.
catch
((
error
)
=>
{
postOrPut
(
basemapsToSend
);
return
error
;
})
);
}
}
...
...
@@ -149,14 +153,11 @@ const map = {
.
then
((
response
)
=>
response
);
}
const
promisesResult
=
await
Promise
.
all
(
[
...
state
.
basemaps
.
map
((
basemap
)
=>
postOrPut
(
basemap
)),
...
state
.
basemapsToDelete
.
map
((
basemapId
)
=>
deleteBMap
(
basemapId
))
]
);
postOrPut
([...
state
.
basemaps
]);
//* delete basemaps
const
deletedResult
=
await
Promise
.
all
(
state
.
basemapsToDelete
.
map
((
basemapId
)
=>
deleteBMap
(
basemapId
)));
state
.
basemapsToDelete
=
[];
return
promisesResult
;
return
[...
promisesResult
,
...
deletedResult
]
;
},
DELETE_BASEMAP
({
commit
},
basemapId
)
{
...
...
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