schema_info_macros.html 2.82 KB
Newer Older
Christophe Benz's avatar
Christophe Benz committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
{% macro html(schema_info, schema_versions, schema_current_version, doc_url) %}
<h2 class="card-title">
    {% if schema_info.title %}
    {{ schema_info.title }}
    {% endif %}
    {% if schema_info.version %}
    <span class="badge badge-primary">{{ schema_info.version }}</span>
    {% endif %}
</h2>

{% if schema_versions %}
<form class="form-inline my-2">
    <div class="form-group">
        <label for="git_ref" class="mr-2">Version</label>
        <select class="form-control" id="version_select" name="git_ref">
            {% for sv in schema_versions %}
            <option{% if sv.name == schema_current_version %} selected="selected"{% endif %}>{{ sv.name }}</option>
            {% endfor %}
        </select>
    </div>
</form>
{% endif %}

{% if schema_info.description %}
<p>{{ schema_info.description }}</p>
{% endif %}

{% if schema_info.contributors %}
<p>Contributeurs :</p>
<ul>
    {% for contributor in schema_info.contributors %}
    <li>
        {{ contributor.title }}{% if contributor.title and contributor.organisation %}, {% endif %}
        {% if contributor.organisation %}{{ contributor.organisation }}{% endif %}

        {# role #}
        {% if contributor.role == 'author' %}(auteur){% endif %}
        {% if contributor.role == 'contributor' %}(contributeur){% endif %}
    </li>
    {% endfor %}
</ul>
{% endif %}

{% if schema_info.homepage %}
<a href="{{ schema_info.homepage }}" target="_blank" class="card-link d-block ml-0">
    Page d'accueil
</a>
{% endif %}

{% if schema_current_version == 'master' %}
<a href="{{ doc_url }}" target="_blank" class="card-link d-block ml-0">Documentation</a>
{% endif %}
{% endmacro %}

{% macro script() %}
<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>
{% endmacro %}