mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-24 17:38:37 -06:00
Closes #4421: Retain user's preference for config context format
This commit is contained in:
parent
f019c8d2ce
commit
bdbf21b3e2
@ -5,7 +5,8 @@
|
|||||||
### Enhancements
|
### Enhancements
|
||||||
|
|
||||||
* [#3294](https://github.com/netbox-community/netbox/issues/3294) - Implement mechanism for storing user preferences
|
* [#3294](https://github.com/netbox-community/netbox/issues/3294) - Implement mechanism for storing user preferences
|
||||||
* [#4531](https://github.com/netbox-community/netbox/issues/4531) - Retain user's pagination preference
|
* [#4421](https://github.com/netbox-community/netbox/issues/4421) - Retain user's preference for config context format
|
||||||
|
* [#4531](https://github.com/netbox-community/netbox/issues/4531) - Retain user's preference for page length
|
||||||
|
|
||||||
### Bug Fixes
|
### Bug Fixes
|
||||||
|
|
||||||
|
@ -119,11 +119,18 @@ class ConfigContextView(PermissionRequiredMixin, View):
|
|||||||
permission_required = 'extras.view_configcontext'
|
permission_required = 'extras.view_configcontext'
|
||||||
|
|
||||||
def get(self, request, pk):
|
def get(self, request, pk):
|
||||||
|
|
||||||
configcontext = get_object_or_404(ConfigContext, pk=pk)
|
configcontext = get_object_or_404(ConfigContext, pk=pk)
|
||||||
|
|
||||||
|
# Determine user's preferred output format
|
||||||
|
if request.GET.get('format') in ['json', 'yaml']:
|
||||||
|
format = request.GET.get('format')
|
||||||
|
request.user.config.set('extras.configcontext.format', format, commit=True)
|
||||||
|
else:
|
||||||
|
format = request.user.config.get('extras.configcontext.format', 'json')
|
||||||
|
|
||||||
return render(request, 'extras/configcontext.html', {
|
return render(request, 'extras/configcontext.html', {
|
||||||
'configcontext': configcontext,
|
'configcontext': configcontext,
|
||||||
|
'format': format,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
@ -171,11 +178,19 @@ class ObjectConfigContextView(View):
|
|||||||
source_contexts = ConfigContext.objects.get_for_object(obj)
|
source_contexts = ConfigContext.objects.get_for_object(obj)
|
||||||
model_name = self.object_class._meta.model_name
|
model_name = self.object_class._meta.model_name
|
||||||
|
|
||||||
|
# Determine user's preferred output format
|
||||||
|
if request.GET.get('format') in ['json', 'yaml']:
|
||||||
|
format = request.GET.get('format')
|
||||||
|
request.user.config.set('extras.configcontext.format', format, commit=True)
|
||||||
|
else:
|
||||||
|
format = request.user.config.get('extras.configcontext.format', 'json')
|
||||||
|
|
||||||
return render(request, 'extras/object_configcontext.html', {
|
return render(request, 'extras/object_configcontext.html', {
|
||||||
model_name: obj,
|
model_name: obj,
|
||||||
'obj': obj,
|
'obj': obj,
|
||||||
'rendered_context': obj.get_config_context(),
|
'rendered_context': obj.get_config_context(),
|
||||||
'source_contexts': source_contexts,
|
'source_contexts': source_contexts,
|
||||||
|
'format': format,
|
||||||
'base_template': self.base_template,
|
'base_template': self.base_template,
|
||||||
'active_tab': 'config-context',
|
'active_tab': 'config-context',
|
||||||
})
|
})
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
$('.rendered-context-format').on('click', function() {
|
|
||||||
if (!$(this).hasClass('active')) {
|
|
||||||
// Update selection in the button group
|
|
||||||
$('span.rendered-context-format').removeClass('active');
|
|
||||||
$('span.rendered-context-format[data-format=' + $(this).data('format') + ']').addClass('active');
|
|
||||||
|
|
||||||
// Hide all rendered contexts and only show the selected one
|
|
||||||
$('div.rendered-context-data').hide();
|
|
||||||
$('div.rendered-context-data[data-format=' + $(this).data('format') + ']').show();
|
|
||||||
}
|
|
||||||
});
|
|
@ -215,13 +215,9 @@
|
|||||||
{% include 'extras/inc/configcontext_format.html' %}
|
{% include 'extras/inc/configcontext_format.html' %}
|
||||||
</div>
|
</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
{% include 'extras/inc/configcontext_data.html' with data=configcontext.data %}
|
{% include 'extras/inc/configcontext_data.html' with data=configcontext.data format=format %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block javascript %}
|
|
||||||
<script src="{% static 'js/configcontext.js' %}?v{{ settings.VERSION }}"></script>
|
|
||||||
{% endblock %}
|
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
{% load helpers %}
|
{% load helpers %}
|
||||||
|
|
||||||
<div class="rendered-context-data" data-format="json">
|
<div class="rendered-context-data">
|
||||||
<pre>{{ data|render_json }}</pre>
|
<pre>{% if format == 'json' %}{{ data|render_json }}{% elif format == 'yaml' %}{{ data|render_yaml }}{% else %}{{ data }}{% endif %}</pre>
|
||||||
</div>
|
|
||||||
<div class="rendered-context-data" data-format="yaml" style="display: none;">
|
|
||||||
<pre>{{ data|render_yaml }}</pre>
|
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<div class="pull-right">
|
<div class="pull-right">
|
||||||
<div class="btn-group btn-group-xs" role="group">
|
<div class="btn-group btn-group-xs" role="group">
|
||||||
<span class="btn btn-default rendered-context-format active" data-format="json">JSON</span>
|
<a href="?format=json" class="btn btn-default{% if format == 'json' %} active{% endif %}">JSON</a>
|
||||||
<span class="btn btn-default rendered-context-format" data-format="yaml">YAML</span>
|
<a href="?format=yaml" class="btn btn-default{% if format == 'yaml' %} active{% endif %}">YAML</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
{% include 'extras/inc/configcontext_format.html' %}
|
{% include 'extras/inc/configcontext_format.html' %}
|
||||||
</div>
|
</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
{% include 'extras/inc/configcontext_data.html' with data=rendered_context %}
|
{% include 'extras/inc/configcontext_data.html' with data=rendered_context format=format %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -24,7 +24,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
{% if obj.local_context_data %}
|
{% if obj.local_context_data %}
|
||||||
{% include 'extras/inc/configcontext_data.html' with data=obj.local_context_data %}
|
{% include 'extras/inc/configcontext_data.html' with data=obj.local_context_data format=format %}
|
||||||
{% else %}
|
{% else %}
|
||||||
<span class="text-muted">None</span>
|
<span class="text-muted">None</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@ -49,7 +49,7 @@
|
|||||||
{% if context.description %}
|
{% if context.description %}
|
||||||
<br /><small>{{ context.description }}</small>
|
<br /><small>{{ context.description }}</small>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% include 'extras/inc/configcontext_data.html' with data=context.data %}
|
{% include 'extras/inc/configcontext_data.html' with data=context.data format=format %}
|
||||||
</div>
|
</div>
|
||||||
{% empty %}
|
{% empty %}
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
@ -60,7 +60,3 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block javascript %}
|
|
||||||
<script src="{% static 'js/configcontext.js' %}?v{{ settings.VERSION }}"></script>
|
|
||||||
{% endblock %}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user