application: javascript for component filtering (#86612)
gitea/hobo/pipeline/head This commit looks good Details

This commit is contained in:
Lauréline Guérin 2024-03-15 15:52:11 +01:00
parent 159f93a783
commit 83da3daab6
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
2 changed files with 56 additions and 1 deletions

View File

@ -31,9 +31,63 @@
{% block content %}
<div>
<label>
{% trans "Filter label:" %}
<input type="search" id="name-filter">
</label>
<label>
{% trans "Filter type:" %}
<select id="type-filter">
<option value="">----------</option>
{% for component_type in component_types %}
{% ifchanged component_type.service.title %}
<optgroup label="{{ component_type.service.title }}">
{% endifchanged %}
<option value="{{ component_type.id }}">{{ component_type.text }}</option>
{% endfor %}
</select>
</label>
</div>
<script>
$('#name-filter, #type-filter').on('change blur keyup', function() {
const name_val = $('#name-filter').val().toLowerCase();
const type_val = $('#type-filter').val();
if (!name_val && !type_val) {
$('.application-content li').show();
} else {
$('.application-content li').each(function(idx, elem) {
var slugged_text = $(elem).attr('data-slugged-text');
var type = $(elem).attr('data-type');
if (name_val && type_val) {
if (slugged_text.indexOf(name_val) > -1 && type == type_val) {
$(elem).show();
} else {
$(elem).hide();
}
} else if (name_val) {
if (slugged_text.indexOf(name_val) > -1) {
$(elem).show();
} else {
$(elem).hide();
}
} else if (type_val) {
if (type == type_val) {
$(elem).show();
} else {
$(elem).hide();
}
} else {
$(elem).hide();
}
});
}
});
</script>
<ul class="objects-list single-links application-content">
{% for relation in relations %}
<li {% if relation.auto_dependency %}class="auto-dependency"{% endif %}>
<li data-slugged-text="{{ relation.element.name|slugify }}" data-type="{{ relation.element.type }}" {% if relation.auto_dependency %}class="auto-dependency"{% endif %}>
<a {% if relation.element.get_redirect_url %}href="{{ relation.element.get_redirect_url }}"{% endif %}>
{% if relation.error %}<span class="tag tag-error">{{ relation.get_error_status_display }}</span>{% endif %}
{{ relation.element.name }} <span class="extra-info">- {{ relation.element.type_label }}</span>

View File

@ -91,6 +91,7 @@ class ManifestView(TemplateView):
type_labels = {}
object_types = get_object_types()
context['component_types'] = object_types
types = [o['id'] for o in object_types]
for object_type in object_types:
type_labels[object_type['id']] = object_type['singular']