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
d31425e0
Commit
d31425e0
authored
3 years ago
by
Sébastien DA ROCHA
Browse files
Options
Downloads
Plain Diff
Merge branch 'redmine-issues/11814' into 'develop'
REDMINE_ISSUE-11814
See merge request
!208
parents
fe052f2a
65ba7174
No related branches found
Branches containing commit
No related tags found
Tags containing commit
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
+64
-128
64 additions, 128 deletions
src/store/modules/feature.js
with
64 additions
and
128 deletions
src/store/modules/feature.js
+
64
−
128
View file @
d31425e0
import
axios
from
'
@/axios-client.js
'
;
import
router
from
'
../../router
'
// axios.defaults.headers.common['X-CSRFToken'] = (name => {
// var re = new RegExp(name + "=([^;]+)");
// var value = re.exec(document.cookie);
// return (value !== null) ? unescape(value[1]) : null;
// })('csrftoken');
const
feature
=
{
namespaced
:
true
,
...
...
@@ -98,7 +92,6 @@ const feature = {
},
ADD_ATTACHMENT_TO_DELETE
(
state
,
attachementId
)
{
// state.attachmentFormset = state.attachmentFormset.filter(el => el.id !== attachementId);
state
.
attachmentsToDelete
.
push
(
attachementId
);
},
...
...
@@ -144,7 +137,6 @@ const feature = {
commit
(
"
SET_FEATURES
"
,
features
);
const
features_count
=
response
.
data
.
count
;
commit
(
"
SET_FEATURES_COUNT
"
,
features_count
);
//dispatch("map/ADD_FEATURES", null, { root: true }); //todo: should check if map was initiated
}
return
response
;
})
...
...
@@ -180,7 +172,6 @@ const feature = {
SEND_FEATURE
({
state
,
rootState
,
commit
,
dispatch
},
routeName
)
{
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
"
;
function
redirect
(
featureId
)
{
dispatch
(
'
GET_PROJECT_FEATURE
'
,
...
...
@@ -228,110 +219,66 @@ const feature = {
}
}
let
url
=
`
${
rootState
.
configuration
.
VUE_APP_DJANGO_API_BASE
}
features/`
if
(
routeName
===
"
editer-signalement
"
)
{
return
axios
.
put
(
`
${
rootState
.
configuration
.
VUE_APP_DJANGO_API_BASE
}
features/
${
state
.
form
.
feature_id
}
/?`
+
`feature_type__slug=
${
rootState
.
feature_type
.
current_feature_type_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
},
});
url
+=
`
${
state
.
form
.
feature_id
}
/?`
+
`feature_type__slug=
${
rootState
.
feature_type
.
current_feature_type_slug
}
`
+
`&project__slug=
${
rootState
.
project_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
;
});
}
else
{
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
}
throw
error
;
});
},
async
SEND_ATTACHMENTS
({
state
,
rootState
,
dispatch
},
featureId
)
{
const
DJANGO_API_BASE
=
rootState
.
configuration
.
VUE_APP_DJANGO_API_BASE
;
function
addFile
(
attachment
,
attchmtId
)
{
let
formdata
=
new
FormData
();
formdata
.
append
(
"
file
"
,
attachment
.
fileToImport
,
attachment
.
fileToImport
.
name
);
return
axios
.
put
(
`
${
DJANGO_API_BASE
}
features/
${
featureId
}
/attachments/
${
attchmtId
}
/upload-file/`
,
formdata
)
.
then
((
response
)
=>
{
console
.
log
(
response
)
if
(
response
&&
response
.
status
===
200
)
{
console
.
log
(
response
.
status
)
}
return
response
;
})
.
catch
((
error
)
=>
{
...
...
@@ -345,37 +292,25 @@ const feature = {
formdata
.
append
(
"
title
"
,
attachment
.
title
);
formdata
.
append
(
"
info
"
,
attachment
.
info
);
if
(
!
attachment
.
id
)
{
//* used to check if doesn't exist in DB and should be send through post (useless now)
return
axios
.
post
(
`
${
DJANGO_API_BASE
}
features/
${
featureId
}
/attachments/`
,
formdata
)
.
then
((
response
)
=>
{
console
.
log
(
response
)
if
(
response
&&
response
.
status
===
201
&&
attachment
.
fileToImport
)
{
console
.
log
(
response
.
status
)
return
addFile
(
attachment
,
response
.
data
.
id
);
}
return
response
})
.
catch
((
error
)
=>
{
console
.
error
(
error
);
return
error
});
}
else
{
return
axios
.
put
(
`
${
DJANGO_API_BASE
}
features/
${
featureId
}
/attachments/
${
attachment
.
id
}
/`
,
formdata
)
.
then
((
response
)
=>
{
console
.
log
(
response
)
if
(
response
&&
response
.
status
===
200
&&
attachment
.
fileToImport
)
{
console
.
log
(
response
.
status
)
return
addFile
(
attachment
,
response
.
data
.
id
);
}
})
.
catch
((
error
)
=>
{
console
.
error
(
error
);
return
error
});
let
url
=
`
${
DJANGO_API_BASE
}
features/
${
featureId
}
/attachments/`
if
(
attachment
.
id
)
{
url
+=
`
${
attachment
.
id
}
/`
}
return
axios
({
url
,
method
:
attachment
.
id
?
"
PUT
"
:
"
POST
"
,
data
:
formdata
}).
then
((
response
)
=>
{
if
(
response
&&
(
response
.
status
===
200
||
response
.
status
===
201
)
&&
attachment
.
fileToImport
)
{
return
addFile
(
attachment
,
response
.
data
.
id
);
}
return
response
})
.
catch
((
error
)
=>
{
console
.
error
(
error
);
return
error
});
}
function
deleteAttachement
(
attachmentsId
,
featureId
)
{
...
...
@@ -386,6 +321,7 @@ const feature = {
return
dispatch
(
"
DELETE_ATTACHMENTS
"
,
payload
)
.
then
((
response
)
=>
response
);
}
const
promisesResult
=
await
Promise
.
all
([
...
state
.
attachmentFormset
.
map
((
attachment
)
=>
putOrPostAttachement
(
attachment
)),
...
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