schema_info_macros.html 3.22 KB
Newer Older
1
{% macro html(schema_info, branches, tags, schema_current_version, doc_url) %}
Christophe Benz's avatar
Christophe Benz committed
2 3 4 5 6 7 8 9 10
<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>

11
{% if branches or tags %}
Christophe Benz's avatar
Christophe Benz committed
12 13
<form class="form-inline my-2">
    <div class="form-group">
14
        <label for="git_ref" class="mr-2">Versions</label>
Christophe Benz's avatar
Christophe Benz committed
15
        <select class="form-control" id="version_select" name="git_ref">
16 17 18
            {% if tags %}
            <optgroup label="publiées">
            {% for tag in tags %}
19
            <option{% if tag.name == schema_current_version %} selected{% endif %}>{{ tag.name }}</option>
Christophe Benz's avatar
Christophe Benz committed
20
            {% endfor %}
21 22 23 24
            </optgroup>
            {% endif %}

            {% if branches %}
Johan Richer's avatar
Johan Richer committed
25
            <optgroup label="prochaines">
26
            {% for branch in branches %}
27 28
            <option{% if branch.name == schema_current_version %} selected{% endif %}>{{ branch.name }}</option>
            {% endfor %}
29 30
            </optgroup>
            {% endif %}
Christophe Benz's avatar
Christophe Benz committed
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
        </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 %}

62
{% if doc_url and doc_url != schema_info.homepage %}
Christophe Benz's avatar
Christophe Benz committed
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 92 93 94 95 96 97 98 99 100 101 102 103
<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 %}