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
a119c757
Commit
a119c757
authored
3 years ago
by
Timothee P
Browse files
Options
Downloads
Patches
Plain Diff
read json, check properties correspond to feature_type custom_fields & prevent upload
parent
eb50668f
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/views/feature_type/Feature_type_detail.vue
+75
-3
75 additions, 3 deletions
src/views/feature_type/Feature_type_detail.vue
src/views/feature_type/Feature_type_edit.vue
+9
-8
9 additions, 8 deletions
src/views/feature_type/Feature_type_edit.vue
with
84 additions
and
11 deletions
src/views/feature_type/Feature_type_detail.vue
+
75
−
3
View file @
a119c757
...
...
@@ -157,7 +157,8 @@
[ Créé le
{{
feature
.
created_on
|
formatDate
}}
<span
v-if=
"$store.state.user"
>
par
{{
feature
.
display_creator
}}
</span
>
]
>
]
</div>
</div>
</div>
...
...
@@ -249,11 +250,81 @@ export default {
this
.
$store
.
dispatch
(
"
feature_type/GET_IMPORTS
"
,
this
.
structure
.
slug
);
}
},
transformProperties
(
prop
)
{
const
type
=
typeof
prop
;
const
date
=
new
Date
(
prop
);
if
(
type
===
"
boolean
"
)
{
return
"
boolean
"
;
}
else
if
(
Number
.
isSafeInteger
(
prop
))
{
return
"
integer
"
;
}
else
if
(
type
===
"
string
"
&&
date
instanceof
Date
&&
!
isNaN
(
date
.
valueOf
())
)
{
return
"
date
"
;
}
else
if
(
type
===
"
number
"
&&
!
isNaN
(
parseFloat
(
prop
)))
{
return
"
decimal
"
;
}
return
"
char
"
;
//* string by default, most accepted type in database
},
checkJsonValidity
(
json
)
{
const
fields
=
this
.
structure
.
customfield_set
.
map
((
el
)
=>
{
return
{
name
:
el
.
name
,
field_type
:
el
.
field_type
,
options
:
el
.
options
,
};
});
console
.
log
({
json
,
fields
});
for
(
const
feature
of
json
.
features
)
{
console
.
log
(
feature
.
properties
);
for
(
const
{
name
,
field_type
,
options
}
of
fields
)
{
console
.
log
(
"
name
"
,
name
,
"
field_type
"
,
field_type
);
//* check if custom field is present
if
(
!
(
name
in
feature
.
properties
))
{
console
.
log
(
"
NOT present
"
);
return
false
;
}
const
fieldInFeature
=
feature
.
properties
[
name
];
const
customType
=
this
.
transformProperties
(
fieldInFeature
);
//* if custom field value is not null, then check validity of field
if
(
fieldInFeature
!==
null
)
{
//* if field type is list, it's not possible to guess from value type
if
(
field_type
===
"
list
"
)
{
//*then check if the value is an available option
if
(
!
options
.
includes
(
fieldInFeature
))
{
console
.
log
(
"
NOT an element of list options
"
);
return
false
;
}
}
else
if
(
customType
!==
field_type
)
{
//* check if custom field value match
console
.
log
(
"
NOT matched
"
);
return
false
;
}
}
}
}
return
true
;
},
onFileChange
(
e
)
{
const
files
=
e
.
target
.
files
||
e
.
dataTransfer
.
files
;
if
(
!
files
.
length
)
return
;
this
.
fileToImport
=
files
[
0
];
// todo : remove this value from state as it stored (first attempt didn't work)
this
.
$store
.
commit
(
"
feature_type/SET_FILE_TO_IMPORT
"
,
this
.
fileToImport
);
let
reader
=
new
FileReader
();
reader
.
addEventListener
(
"
load
"
,
(
e
)
=>
{
if
(
this
.
checkJsonValidity
(
JSON
.
parse
(
e
.
target
.
result
)))
{
this
.
fileToImport
=
files
[
0
];
// todo : remove this value from state as it stored (first attempt didn't work)
this
.
$store
.
commit
(
"
feature_type/SET_FILE_TO_IMPORT
"
,
this
.
fileToImport
);
}
});
reader
.
readAsText
(
files
[
0
]);
},
importGeoJson
()
{
...
...
@@ -263,6 +334,7 @@ export default {
fileToImport
:
this
.
fileToImport
,
});
},
exportFeatures
()
{
const
url
=
`
${
this
.
$store
.
state
.
configuration
.
VUE_APP_DJANGO_API_BASE
}
projects/
${
this
.
$route
.
params
.
slug
}
/feature-type/
${
this
.
$route
.
params
.
feature_type_slug
}
/export/`
;
console
.
log
(
url
);
...
...
This diff is collapsed.
Click to expand it.
src/views/feature_type/Feature_type_edit.vue
+
9
−
8
View file @
a119c757
...
...
@@ -459,15 +459,16 @@ export default {
const
date
=
new
Date
(
prop
);
if
(
type
===
"
boolean
"
)
{
return
"
boolean
"
;
}
else
if
(
type
===
"
number
"
)
{
}
else
if
(
Number
.
isSafeInteger
(
prop
)
)
{
return
"
integer
"
;
}
else
if
(
type
===
"
string
"
)
{
//* check if string is convertible to a number, then it should be a decimal
if
(
date
instanceof
Date
&&
!
isNaN
(
date
.
valueOf
()))
{
return
"
date
"
;
}
else
if
(
!
isNaN
(
parseFloat
(
prop
)))
{
return
"
decimal
"
;
}
}
else
if
(
type
===
"
string
"
&&
date
instanceof
Date
&&
!
isNaN
(
date
.
valueOf
())
)
{
return
"
date
"
;
}
else
if
(
type
===
"
number
"
&&
!
isNaN
(
parseFloat
(
prop
)))
{
return
"
decimal
"
;
}
return
"
char
"
;
//* string by default, most accepted type in database
},
...
...
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