Commit 01abe441 authored by Pierre Dittgen's avatar Pierre Dittgen

Display schema version in UI

parent 96767de3
......@@ -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>
......
......@@ -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 %}
......@@ -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'}, ])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment