Skip to content

Commit

Permalink
feat(config_management): add configuration groups
Browse files Browse the repository at this point in the history
!17 #42
  • Loading branch information
jon-nfc committed Jun 2, 2024
1 parent 8061b7c commit fdeae21
Show file tree
Hide file tree
Showing 13 changed files with 519 additions and 7 deletions.
4 changes: 2 additions & 2 deletions app/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
'itam.apps.ItamConfig',
'settings.apps.SettingsConfig',
'drf_spectacular',
'drf_spectacular_sidecar'
'drf_spectacular_sidecar',
'config_management.apps.ConfigManagementConfig',
]

MIDDLEWARE = [
Expand Down Expand Up @@ -242,6 +243,5 @@
# Apps Under Development
INSTALLED_APPS += [
'information.apps.InformationConfig',
'config_management.apps.ConfigManagementConfig',
'project_management.apps.ProjectManagementConfig',
]
34 changes: 34 additions & 0 deletions app/config_management/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Generated by Django 5.0.6 on 2024-06-02 14:48

import access.fields
import django.db.models.deletion
import django.utils.timezone
from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
('access', '0002_alter_team_organization'),
]

operations = [
migrations.CreateModel(
name='ConfigGroups',
fields=[
('is_global', models.BooleanField(default=False)),
('id', models.AutoField(primary_key=True, serialize=False, unique=True)),
('created', access.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False)),
('modified', access.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False)),
('name', models.CharField(max_length=50)),
('config', models.JSONField(blank=True, default=None, null=True)),
('organization', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='access.organization')),
('parent', models.ForeignKey(blank=True, default=None, null=True, on_delete=django.db.models.deletion.CASCADE, to='config_management.configgroups')),
],
options={
'verbose_name': 'Config Groups',
},
),
]
1 change: 0 additions & 1 deletion app/config_management/models.py

This file was deleted.

88 changes: 88 additions & 0 deletions app/config_management/models/groups.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
from django.db import models

from access.fields import *
from access.models import TenancyObject

from core.mixin.history_save import SaveHistory



class GroupsCommonFields(TenancyObject, models.Model):

class Meta:
abstract = True

id = models.AutoField(
primary_key=True,
unique=True,
blank=False
)

created = AutoCreatedField()

modified = AutoLastModifiedField()

def __str__(self):

return self.name



class ConfigGroups(GroupsCommonFields, SaveHistory):


parent = models.ForeignKey(
'self',
on_delete=models.CASCADE,
default = None,
null = True,
blank= True
)


name = models.CharField(
blank = False,
max_length = 50,
unique = False,
)


config = models.JSONField(
blank = True,
default = None,
null = True,
)



def count_children(self) -> int:
""" Count all child groups recursively
Returns:
int: Total count of ALL child-groups
"""

count = 0

children = ConfigGroups.objects.filter(parent=self.pk)

for child in children.all():

count += 1

count += child.count_children()

return count



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

self.is_global = False

if self.parent:
self.organization = ConfigGroups.objects.get(id=self.parent.id).organization

super().save(*args, **kwargs)


107 changes: 107 additions & 0 deletions app/config_management/templates/config_management/group.html.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
{% extends 'base.html.j2' %}

{% block body %}

<script>
function openCity(evt, cityName) {
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
document.getElementById(cityName).style.display = "block";
evt.currentTarget.className += " active";
}
</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 %}';"
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" />
</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 class="tablinks" onclick="openCity(event, 'Notes')">Notes</button>

</div>

<form method="post">
<div id="Details" class="tabcontent">
<h3>Details</h3>

{% csrf_token %}
{{ form }}
{% include 'icons/issue_link.html.j2' with issue=13 %}<br>
<input type="submit" value="Submit">

<script>
document.getElementById("defaultOpen").click();
</script>

</div>

<div id="Children" class="tabcontent">
<h3>Child Groups</h3>
<table class="data">
<tr>
<th>Name</th>
<th>Sub-Groups</th>
<th>&nbsp;</th>
</tr>
{% if child_groups %}
{% for group in child_groups %}
<tr>
<td><a href="{% url 'Config Management:_group_view' pk=group.id %}">{{ group.name }}</a></td>
<td>{{ group.count_children }}</td>
<td>&nbsp;</td>
</tr>
{% endfor %}
{% else %}
<tr>
<td colspan="4">Nothing Found</td>
</tr>
{% endif %}
</table>

</div>


<div id="Software" class="tabcontent">
<h3>
Software
</h3>

</div>

<div id="Notes" class="tabcontent">
<h3>
Notes
</h3>
{{ notes_form }}
<input type="submit" name="{{notes_form.prefix}}" value="Submit" />
<div class="comments">
{% if notes %}
{% for note in notes %}
{% include 'note.html.j2' %}
{% endfor %}
{% endif %}
</div>

</div>

</form>

{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{% extends 'base.html.j2' %}

{% block body %}

<input type="button" value="New Group" onclick="window.location='{% url 'Config Management:_group_add' %}';">
<table class="data">
<tr>
<th>Name</th>
<th>Organization</th>
<th>Sub-Groups</th>
<th>&nbsp;</th>
</tr>
{% if groups %}
{% for group in groups %}
<tr>
<td><a href="{% url 'Config Management:_group_view' pk=group.id %}">{{ group.name }}</a></td>
<td>{{ group.organization }}</td>
<td>{{ group.count_children }}</td>
<td>&nbsp;</td>
</tr>
{% endfor %}
{% else %}
<tr>
<td colspan="4">Nothing Found</td>
</tr>
{% endif %}
</table>
<br>
<div class="pagination">
<span class="step-links">
{% if page_obj.has_previous %}
<a href="?page=1">&laquo; first</a>
<a href="?page={{ page_obj.previous_page_number }}">previous</a>
{% endif %}

<span class="current">
Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}.
</span>

{% if page_obj.has_next %}
<a href="?page={{ page_obj.next_page_number }}">next</a>
<a href="?page={{ page_obj.paginator.num_pages }}">last &raquo;</a>
{% endif %}
</span>
</div>

{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% extends 'base.html.j2' %}

{% block body %}
what will go here?

<ul>
<li><a href="{% url 'Config Management:_group_index' %}">Groups</a></li>
</ul>
{% endblock %}
10 changes: 8 additions & 2 deletions app/config_management/urls.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
from django.urls import path

from .views import ConfigIndex
from config_management.views.index import ConfigIndex
from config_management.views.groups import GroupIndexView, GroupAdd, GroupDelete, GroupView

app_name = "Config Management"

urlpatterns = [
path('', ConfigIndex.as_view(), name='Config Management'),

path('group', GroupIndexView.as_view(), name='_group_index'),
path('group/add', GroupAdd.as_view(), name='_group_add'),
path('group/<int:pk>', GroupView.as_view(), name='_group_view'),
path('group/<int:pk>/delete', GroupDelete.as_view(), name='_group_delete'),

]
Loading

0 comments on commit fdeae21

Please sign in to comment.