Skip to content

Commit

Permalink
feat(config_management): Config groups rendered config
Browse files Browse the repository at this point in the history
new tab to display the rendered configuration

!17 #42
  • Loading branch information
jon-nfc committed Jun 2, 2024
1 parent fdeae21 commit a7d195d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
18 changes: 18 additions & 0 deletions app/config_management/models/groups.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import json

from django.db import models

from access.fields import *
Expand Down Expand Up @@ -76,6 +78,22 @@ def count_children(self) -> int:



def render_config(self) -> str:

config: dict = dict()

if self.parent:

config.update(json.loads(ConfigGroups.objects.get(id=self.parent.id).render_config()))

if self.config:

config.update(self.config)

return json.dumps(config)



def save(self, *args, **kwargs):

self.is_global = False
Expand Down
18 changes: 15 additions & 3 deletions app/config_management/templates/config_management/group.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,19 @@
</script>

<div class="tab">
<button onclick="window.location='{% if group.parent %}{% url 'Config Management:_group_view' pk=group.parent.id %}{% else %}{% url 'Config Management:_group_index' %}{% endif %}';"
<button
onclick="window.location='{% if group.parent %}{% url 'Config Management:_group_view' pk=group.parent.id %}{% else %}{% url 'Config Management:_group_index' %}{% endif %}';"
style="vertical-align: middle; padding: auto; margin: 0px">
<svg xmlns="http://www.w3.org/2000/svg" height="25px" viewBox="0 -960 960 960" width="25px"
style="vertical-align: middle; margin: 0px; padding: 0px border: none; " fill="#6a6e73">
<path d="m313-480 155 156q11 11 11.5 27.5T468-268q-11 11-28 11t-28-11L228-452q-6-6-8.5-13t-2.5-15q0-8 2.5-15t8.5-13l184-184q11-11 27.5-11.5T468-692q11 11 11 28t-11 28L313-480Zm264 0 155 156q11 11 11.5 27.5T732-268q-11 11-28 11t-28-11L492-452q-6-6-8.5-13t-2.5-15q0-8 2.5-15t8.5-13l184-184q11-11 27.5-11.5T732-692q11 11 11 28t-11 28L577-480Z" />
<path
d="m313-480 155 156q11 11 11.5 27.5T468-268q-11 11-28 11t-28-11L228-452q-6-6-8.5-13t-2.5-15q0-8 2.5-15t8.5-13l184-184q11-11 27.5-11.5T468-692q11 11 11 28t-11 28L313-480Zm264 0 155 156q11 11 11.5 27.5T732-268q-11 11-28 11t-28-11L492-452q-6-6-8.5-13t-2.5-15q0-8 2.5-15t8.5-13l184-184q11-11 27.5-11.5T732-692q11 11 11 28t-11 28L577-480Z" />
</svg>Back to {% if group.parent %}Parent{% else %}Groups{% endif %}</button>

<button id="defaultOpen" class="tablinks" onclick="openCity(event, 'Details')">Details</button>
<button id="defaultOpen" class="tablinks" onclick="openCity(event, 'Children')">Child Groups</button>
<button id="defaultOpen" class="tablinks" onclick="openCity(event, 'Software')">Software</button>
<button id="defaultOpen" class="tablinks" onclick="openCity(event, 'Configuration')">Configuration</button>
<button class="tablinks" onclick="openCity(event, 'Notes')">Notes</button>

</div>
Expand Down Expand Up @@ -84,6 +87,15 @@
Software
</h3>



</div>

<div id="Configuration" class="tabcontent">
<h3>Configuration</h3>
<div>
<textarea cols="90" rows="30" readonly>{{ config }}</textarea>
</div>
</div>

<div id="Notes" class="tabcontent">
Expand Down
5 changes: 5 additions & 0 deletions app/config_management/views/groups.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import json

from django.contrib.auth import decorators as auth_decorator

from django.db.models import Count, Q
Expand Down Expand Up @@ -114,6 +116,9 @@ def get_context_data(self, **kwargs):

context['child_groups'] = ConfigGroups.objects.filter(parent=self.kwargs['pk'])

context['config'] = json.dumps(json.loads(self.object.render_config()), indent=4, sort_keys=True)


context['notes_form'] = AddNoteForm(prefix='note')
context['notes'] = Notes.objects.filter(config_group=self.kwargs['pk'])

Expand Down

0 comments on commit a7d195d

Please sign in to comment.