Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
V
validata-ui
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
21
Issues
21
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Validata
validata-ui
Commits
01abe441
Commit
01abe441
authored
Jun 13, 2019
by
Pierre Dittgen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Display schema version in UI
parent
96767de3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
73 additions
and
11 deletions
+73
-11
validata_ui/templates/base_template.html
validata_ui/templates/base_template.html
+2
-1
validata_ui/templates/schema_info_part.html
validata_ui/templates/schema_info_part.html
+53
-2
validata_ui/views.py
validata_ui/views.py
+18
-8
No files found.
validata_ui/templates/base_template.html
View file @
01abe441
...
...
@@ -10,7 +10,8 @@
<!-- Bootstrap CSS -->
<link
rel=
"stylesheet"
href=
"{{url_for('static', filename='css/bootstrap.min.css')}}"
crossorigin=
"anonymous"
>
<link
rel=
"stylesheet"
href=
"https://use.fontawesome.com/releases/v5.5.0/css/all.css"
integrity=
"sha384-B4dIYHKNBt8Bc12p+WXckhzcICo0wtJAoU8YZTY5qE0Id1GSseTk6S+L3BlXeVIU"
crossorigin=
"anonymous"
>
<!-- JQuery -->
<script
type=
"text/javascript"
src=
"{{ url_for('static', filename='js/jquery-3.3.1.min.js')}}"
></script>
<title>
Validata - {% block title %}{% endblock %}
</title>
<style>
...
...
validata_ui/templates/schema_info_part.html
View file @
01abe441
...
...
@@ -3,6 +3,9 @@
{% if schema_info.title %}
« {{ schema_info.title }} »
{% endif %}
{% if schema_current_version %}
<span
class=
"badge badge-primary"
>
{{ schema_current_version }}
</span>
{% endif %}
</h5>
{% if schema_info.description %}
<h6
class=
"card-subtitle mb-2 text-muted"
>
{{ schema_info.description }}
</h6>
...
...
@@ -17,10 +20,58 @@
{% endif %}
</p>
{% endif %}
{% if schema_info.doc_url or schema_info.url %}
<p>
{% if schema_info.doc_url %}
<a
href=
"{{ schema_info.doc_url }}"
target=
"_blank"
class=
"card-link"
>
Documentation
</a>
{% else %}
<a
href=
"{{ schema_info.url }}"
target=
"_blank"
class=
"card-link"
>
{{ schema_info.url }}
</a>
{% endif %}
{% if schema_info.url %}
Source :
<a
href=
"{{ schema_info.url }}"
target=
"_blank"
title=
"{{ schema_info.url }}"
class=
"card-link"
>
{{ schema_info.url | truncate(40) }}
</a>
{% endif %}
</p>
{% endif %}
{% if schema_versions %}
<p>
Changer de version :
<select
id=
"version_select"
>
{% for sv in schema_versions %}
<option
{%
if
sv =
=
schema_current_version
%}
selected=
"selected"
{%
endif
%}
>
{{ sv }}
</option>
{% endfor %}
</select>
</p>
<script>
var
vbox
=
$
(
'
#version_select
'
);
vbox
.
on
(
'
change
'
,
function
()
{
// Extract base url and query string
var
current_url
=
document
.
location
.
href
;
var
base_url
=
current_url
;
var
query_string
=
""
;
var
qidx
=
current_url
.
indexOf
(
'
?
'
);
if
(
qidx
!=
-
1
)
{
query_string
=
current_url
.
substring
(
qidx
+
1
);
base_url
=
current_url
.
substring
(
0
,
qidx
);
}
// Transforms query string into parameter dictionary
// ignoring schema_ref parameter if exists
var
params
=
query_string
.
split
(
"
&
"
);
var
param_dict
=
{};
for
(
var
i
=
0
;
i
<
params
.
length
;
i
++
)
{
var
pair
=
params
[
i
].
split
(
'
=
'
);
if
(
pair
[
0
]
!=
'
schema_ref
'
)
{
param_dict
[
pair
[
0
]]
=
pair
[
1
];
}
}
param_dict
[
'
schema_ref
'
]
=
encodeURIComponent
(
vbox
.
val
());
// Build new URL to redirect to
var
param_list
=
[];
for
(
p
in
param_dict
)
{
param_list
.
push
(
p
+
'
=
'
+
param_dict
[
p
]);
}
var
new_url
=
base_url
+
'
?
'
+
param_list
.
join
(
'
&
'
);
document
.
location
.
href
=
new_url
;
})
</script>
{% endif %}
validata_ui/views.py
View file @
01abe441
...
...
@@ -35,19 +35,20 @@ log = logging.getLogger(__name__)
class
SchemaInstance
():
"""Handly class to handle schema information"""
def
__init__
(
self
,
url
=
None
,
name
=
None
,
ref
=
None
,
spec
=
None
):
def
__init__
(
self
,
url
=
None
,
name
=
None
,
ref
=
None
,
spec
=
None
,
versions
=
None
):
"""This function is not intended to be called directly
but via from_parameters() static method!"""
self
.
url
=
url
self
.
name
=
name
self
.
ref
=
ref
self
.
spec
=
spec
self
.
versions
=
versions
@
staticmethod
def
from_parameters
(
parameter_dict
,
table_schema_catalog
):
"""Initializes schema instance from requests dict and tableschema catalog (for name ref)
"""
schema_url
,
schema_name
,
schema_ref
=
None
,
None
,
None
schema_url
,
schema_name
,
schema_ref
,
versions
=
None
,
None
,
None
,
None
# From schema_url
if
'schema_url'
in
parameter_dict
:
...
...
@@ -63,13 +64,17 @@ class SchemaInstance():
if
table_schema_reference
is
None
:
return
None
schema_url
=
table_schema_reference
.
get_schema_url
()
# Git refs
if
table_schema_reference
:
versions
=
table_schema_reference
.
get_refs
()
options
=
{
'ref'
:
schema_ref
}
if
schema_ref
else
{}
schema_url
=
table_schema_reference
.
get_schema_url
(
**
options
)
# else???
else
:
return
None
return
SchemaInstance
(
schema_url
,
schema_name
,
schema_ref
,
schema_from_url
(
schema_url
))
return
SchemaInstance
(
schema_url
,
schema_name
,
schema_ref
,
schema_from_url
(
schema_url
)
,
versions
)
def
request_parameters
(
self
):
if
self
.
name
:
...
...
@@ -352,13 +357,14 @@ def validate(schema_instance: SchemaInstance, source: ValidataSource):
# Display report to the user
validator_form_url
=
compute_validation_form_url
(
schema_instance
)
schema_info
,
validator_title
=
compute_schema_info
(
schema_instance
.
spec
)
schema_info
,
validator_title
=
compute_schema_info
(
schema_instance
.
spec
,
schema_instance
.
url
)
pdf_report_url
=
url_for
(
'pdf_report'
)
+
'?'
+
urlencode
(
schema_instance
.
request_parameters
())
return
render_template
(
'validation_report.html'
,
title
=
'Rapport de validation'
,
schema_info
=
schema_info
,
report
=
validata_report
,
pdf_report_url
=
pdf_report_url
,
validation_date
=
report_datetime
.
strftime
(
'le %d/%m/%Y à %Hh%M'
),
source
=
source
,
source_type
=
source
.
type
,
source_data
=
source_data
,
schema_current_version
=
schema_instance
.
ref
,
print_mode
=
request
.
args
.
get
(
'print'
,
'false'
)
==
'true'
,
badge_url
=
badge_url
,
badge_msg
=
badge_msg
,
report_str
=
json
.
dumps
(
validata_report
,
sort_keys
=
True
,
indent
=
2
),
...
...
@@ -455,10 +461,11 @@ def pdf_report():
return
response
def
compute_schema_info
(
table_schema
:
tableschema
.
Schema
):
def
compute_schema_info
(
table_schema
:
tableschema
.
Schema
,
schema_url
):
"""Factor code for validator form page"""
schema_info
=
{
k
:
v
for
k
,
v
in
table_schema
.
descriptor
.
items
()
if
k
!=
'fields'
}
schema_info
[
'url'
]
=
schema_url
title
=
"Schéma « {} »"
.
format
(
schema_info
.
get
(
'title'
))
return
schema_info
,
title
...
...
@@ -496,9 +503,12 @@ def custom_validator():
# First form display
if
input_param
is
None
:
schema_info
,
title
=
compute_schema_info
(
schema_instance
.
spec
)
schema_versions
=
schema_instance
.
versions
schema_info
,
title
=
compute_schema_info
(
schema_instance
.
spec
,
schema_instance
.
url
)
return
render_template
(
'validation_form.html'
,
title
=
title
,
schema_info
=
schema_info
,
schema_info
=
schema_info
,
schema_versions
=
schema_versions
,
schema_current_version
=
schema_instance
.
ref
,
schema_params
=
schema_instance
.
request_parameters
(),
breadcrumbs
=
[{
'url'
:
url_for
(
'home'
),
'title'
:
'Accueil'
},
])
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment