-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tab for devices with their config compliance
- Loading branch information
Showing
8 changed files
with
156 additions
and
95 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
netbox_config_diff/migrations/0008_alter_configcompliance_device.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("dcim", "0181_rename_device_role_device_role"), | ||
("netbox_config_diff", "0007_configurationrequest"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="configcompliance", | ||
name="device", | ||
field=models.OneToOneField( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="config_compliance", | ||
to="dcim.device", | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 10 additions & 78 deletions
88
netbox_config_diff/templates/netbox_config_diff/configcompliance.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,13 @@ | ||
{% extends "netbox_config_diff/configcompliance/base.html" %} | ||
{% load static %} | ||
{% extends "generic/object.html" %} | ||
{% load buttons %} | ||
{% load perms %} | ||
|
||
{% block content %} | ||
<div class="row mb-3"> | ||
<div class="col col-md-6"> | ||
<div class="card"> | ||
<h5 class="card-header">{{ object|meta:"verbose_name"|bettertitle }}</h5> | ||
<div class="card-body"> | ||
<table class="table table-hover attr-table"> | ||
<tr> | ||
<th scope="row">Device</th> | ||
<td>{{ object.device|linkify }}</td> | ||
</tr> | ||
<tr> | ||
<th scope="row">Status</th> | ||
<td>{% badge object.get_status_display bg_color=object.get_status_color %}</td> | ||
</tr> | ||
</table> | ||
</div> | ||
</div> | ||
{% block controls %} | ||
<div class="controls"> | ||
<div class="control-group"> | ||
{% if request.user|can_delete:object %} | ||
{% delete_button object %} | ||
{% endif %} | ||
</div> | ||
{% if object.error %} | ||
<div class="col col-md-6"> | ||
<div class="card"> | ||
<h5 class="card-header">Error</h5> | ||
<div class="card-body"> | ||
<pre class="block">{{ object.error }}</pre> | ||
</div> | ||
</div> | ||
</div> | ||
{% endif %} | ||
</div> | ||
{% if object.diff %} | ||
<div class="row mb-3"> | ||
<div class="col col-md-12"> | ||
<div class="card"> | ||
<h5 class="card-header">Diff</h5> | ||
<div class="card-body" id="diffElement"></div> | ||
</div> | ||
</div> | ||
</div> | ||
{% endif %} | ||
{% endblock content %} | ||
|
||
{% block javascript %} | ||
<script type="text/javascript" src="{% static 'netbox_config_diff/diff2html-ui.min.js' %}"></script> | ||
<script type="text/javascript"> | ||
var link = document.createElement('link'); | ||
link.type = 'text/css'; | ||
link.rel = 'stylesheet'; | ||
const colorMode = localStorage.getItem("netbox-color-mode"); | ||
if (colorMode === 'dark') { | ||
link.href = `{% static 'netbox_config_diff/diff2html.dark.min.css' %}` | ||
} else { | ||
link.href = `{% static 'netbox_config_diff/diff2html.min.css' %}` | ||
}; | ||
document.head.appendChild(link); | ||
document.addEventListener('DOMContentLoaded', () => { | ||
var configuration = { | ||
drawFileList: false, | ||
fileListToggle: false, | ||
fileListStartVisible: false, | ||
fileContentToggle: false, | ||
matching: 'lines', | ||
outputFormat: 'side-by-side', | ||
synchronisedScroll: true, | ||
highlight: true, | ||
renderNothingWhenEmpty: false, | ||
stickyFileHeaders: false, | ||
drawFileList: false, | ||
}; | ||
const jsonDiff = `{{ object.diff|safe }}`; | ||
var targetElement = document.getElementById('diffElement'); | ||
var diff2htmlUi = new Diff2HtmlUI(targetElement, jsonDiff, configuration); | ||
diff2htmlUi.draw(); | ||
document.querySelector(".d2h-file-header").remove(); | ||
diff2htmlUi.highlightCode(); | ||
}); | ||
</script> | ||
{% endblock javascript %} | ||
{% endblock controls %} |
13 changes: 0 additions & 13 deletions
13
netbox_config_diff/templates/netbox_config_diff/configcompliance/base.html
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
netbox_config_diff/templates/netbox_config_diff/configcompliance/config.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
netbox_config_diff/templates/netbox_config_diff/configcompliance/data.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
{% extends base_template %} | ||
{% load static %} | ||
|
||
{% block content %} | ||
<div class="row mb-3"> | ||
<div class="col col-md-6"> | ||
<div class="card"> | ||
<h5 class="card-header">{{ instance|meta:"verbose_name"|bettertitle }}</h5> | ||
<div class="card-body"> | ||
<table class="table table-hover attr-table"> | ||
<tr> | ||
<th scope="row">Device</th> | ||
<td>{{ instance.device|linkify }}</td> | ||
</tr> | ||
<tr> | ||
<th scope="row">Status</th> | ||
<td>{% badge instance.get_status_display bg_color=instance.get_status_color %}</td> | ||
</tr> | ||
</table> | ||
</div> | ||
</div> | ||
</div> | ||
{% if instance.error %} | ||
<div class="col col-md-6"> | ||
<div class="card"> | ||
<h5 class="card-header">Error</h5> | ||
<div class="card-body"> | ||
<pre class="block">{{ instance.error }}</pre> | ||
</div> | ||
</div> | ||
</div> | ||
{% endif %} | ||
</div> | ||
{% if instance.diff %} | ||
<div class="row mb-3"> | ||
<div class="col col-md-12"> | ||
<div class="card"> | ||
<h5 class="card-header">Diff</h5> | ||
<div class="card-body" id="diffElement"></div> | ||
</div> | ||
</div> | ||
</div> | ||
{% endif %} | ||
{% endblock content %} | ||
|
||
{% block javascript %} | ||
<script type="text/javascript" src="{% static 'netbox_config_diff/diff2html-ui.min.js' %}"></script> | ||
<script type="text/javascript"> | ||
var link = document.createElement('link'); | ||
link.type = 'text/css'; | ||
link.rel = 'stylesheet'; | ||
const colorMode = localStorage.getItem("netbox-color-mode"); | ||
if (colorMode === 'dark') { | ||
link.href = `{% static 'netbox_config_diff/diff2html.dark.min.css' %}` | ||
} else { | ||
link.href = `{% static 'netbox_config_diff/diff2html.min.css' %}` | ||
}; | ||
document.head.appendChild(link); | ||
document.addEventListener('DOMContentLoaded', () => { | ||
var configuration = { | ||
drawFileList: false, | ||
fileListToggle: false, | ||
fileListStartVisible: false, | ||
fileContentToggle: false, | ||
matching: 'lines', | ||
outputFormat: 'side-by-side', | ||
synchronisedScroll: true, | ||
highlight: true, | ||
renderNothingWhenEmpty: false, | ||
stickyFileHeaders: false, | ||
drawFileList: false, | ||
}; | ||
const jsonDiff = `{{ instance.diff|safe }}`; | ||
var targetElement = document.getElementById('diffElement'); | ||
var diff2htmlUi = new Diff2HtmlUI(targetElement, jsonDiff, configuration); | ||
diff2htmlUi.draw(); | ||
document.querySelector(".d2h-file-header").remove(); | ||
diff2htmlUi.highlightCode(); | ||
}); | ||
</script> | ||
{% endblock javascript %} |
2 changes: 1 addition & 1 deletion
2
netbox_config_diff/templates/netbox_config_diff/configcompliance/missing_extra.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters