Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial working version of nautobot-ssot plugin #1

Merged
merged 42 commits into from
Jul 2, 2021
Merged
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
e29a643
Initial content creation
glennmatthews May 17, 2021
04c867c
More progress towards a basic functioning UI
glennmatthews May 24, 2021
8899de3
Create nautobot_data_sync_servicenow
glennmatthews May 28, 2021
3f367f5
Renames
glennmatthews May 28, 2021
e144eea
Add dashboard view, add source/target/start_time fields to Sync model…
glennmatthews Jun 4, 2021
7a47c4a
Extract ServiceNow plugin to its own repository
glennmatthews Jun 7, 2021
c304c6a
Some refactoring and point fixes
glennmatthews Jun 7, 2021
198a7fe
Log traceback if exception occurs during sync
glennmatthews Jun 8, 2021
6c50e2f
Rename changed_object field to synced_object to be more accurate
glennmatthews Jun 10, 2021
697717e
Breadcrumb fixup
glennmatthews Jun 10, 2021
a39a034
Improve datetime rendering in str(Sync)
glennmatthews Jun 10, 2021
9e6f50b
Improve sync detail view
glennmatthews Jun 10, 2021
64f073f
Various content
glennmatthews Jun 14, 2021
8b108c3
Refactor to more closely align with Jobs core functionality
glennmatthews Jun 15, 2021
1bcf8f2
Temporarily add dependency on my PR branch
glennmatthews Jun 15, 2021
3b9a5de
Initial very rough version of data_source_target view
glennmatthews Jun 15, 2021
81b61c9
Refine per-data-source/target detail view
glennmatthews Jun 16, 2021
ec0e365
Fix bug with null object_repr, refine UI
glennmatthews Jun 17, 2021
c1d0ea5
Improved logging; a few UI tweaks in progress
glennmatthews Jun 17, 2021
7e2e03c
Update temporary Nautobot dependency now that nautobot/nautobot#576 i…
glennmatthews Jun 18, 2021
db5bcf3
Combine synced_object and object_repr columns into one
glennmatthews Jun 18, 2021
1ec71ab
Diff rendering, first version
glennmatthews Jun 18, 2021
174d30f
Avoid an error if the related_object doesn't have a class_path
glennmatthews Jun 18, 2021
0a077e7
Blacken
glennmatthews Jun 18, 2021
22dfb43
Linting
glennmatthews Jun 18, 2021
2f2521f
Regenerate migrations and remove ChangeLoggedModel from Sync
glennmatthews Jun 18, 2021
8aba02b
Fix CI?
glennmatthews Jun 18, 2021
3e2f836
Fix sync_logentries view
glennmatthews Jun 18, 2021
c70c89b
Another CI fix?
glennmatthews Jun 18, 2021
d21477d
Another attempt at fixing CI
glennmatthews Jun 18, 2021
0a5b269
Various UI refinements
glennmatthews Jun 23, 2021
97eb871
Update nautobot dependency, add some docs
glennmatthews Jun 24, 2021
658bd72
Review comments
glennmatthews Jun 25, 2021
076b8d5
Rework 'Statistics' table for readability
glennmatthews Jun 25, 2021
1a782f0
Add config toggle to hide example jobs
glennmatthews Jun 28, 2021
6bbc7ec
Update example jobs to be more realistic, using DiffSync
glennmatthews Jun 28, 2021
39a5600
Fix incorrect filtering of data in dashboard view
glennmatthews Jun 28, 2021
f7d04df
Linting
glennmatthews Jun 28, 2021
d105111
Remove ObjectChange linkage from SyncLogEntry and lookup_object() as …
glennmatthews Jun 28, 2021
ec17c25
Add some unit test coverage
glennmatthews Jun 28, 2021
c0f3ee8
Address review comment
glennmatthews Jun 30, 2021
220b6e3
Update docs and add screenshots
glennmatthews Jul 2, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Diff rendering, first version
  • Loading branch information
glennmatthews committed Jun 18, 2021
commit 1ec71ab39f7dfe3c96195ad873a3d68a6ca0f3b7
11 changes: 10 additions & 1 deletion nautobot_ssot/templates/nautobot_ssot/sync_detail.html
Original file line number Diff line number Diff line change
@@ -2,8 +2,15 @@
{% load buttons %}
{% load plugins %}
{% load shorter_timedelta %}
{% load render_diff %}

{% block content %}
<style>
li.diff-added { list-style-type: "+ "; color: #3c763d; background-color: #dff0d8;}
li.diff-subtracted { list-style-type: "- "; color: #a94442; background-color: #f2dede;}
li.diff-changed { list-style-type: "! "; color: #8a6d3b; background-color: #fcf8e3;}
li.diff-unchanged { list-style-type: circle; color: #333; background-color: white;}
</style>
<div class="row">
<div class="col-md-6">
<div class="panel panel-default">
@@ -115,7 +122,9 @@
<div class="panel-heading">
<strong>Diff</strong>
</div>
<pre class="panel-body" style="max-height: 400px">{{ diff }}</pre>
<div class="panel-body">
{% render_diff object.diff %}
</div>
</div>
</div>
{% plugin_full_width_page object %}
43 changes: 43 additions & 0 deletions nautobot_ssot/templatetags/render_diff.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from django import template
from django.utils.safestring import mark_safe


register = template.Library()


def render_diff_recursive(diff):
result = ""
for type, children in diff.items():
child_result = ""
for child, child_diffs in children.items():
if "+" in child_diffs and "-" not in child_diffs:
child_class = "diff-added"
elif "-" in child_diffs and "+" not in child_diffs:
child_class = "diff-subtracted"
elif not child_diffs.get("+") and not child_diffs.get("-"):
child_class = "diff-unchanged"
else:
child_class = "diff-changed"
child_result += f'<li class="{child_class}">{child}<ul>'

for attr, value in child_diffs.pop("+", {}).items():
child_result += f'<li class="diff-added">{attr}: {value}</li>'

for attr, value in child_diffs.pop("-", {}).items():
child_result += f'<li class="diff-subtracted">{attr}: {value}</li>'

if child_diffs:
child_result += render_diff_recursive(child_diffs)

child_result += f"</ul></li>"
child_result = f"<ul>{child_result}</ul>"
result += f"<li>{type}{child_result}</li>"
return result


@register.simple_tag
def render_diff(diff):
"""Render a DiffSync diff dict to HTML."""
result = f"<ul>{render_diff_recursive(diff)}</ul>"

return mark_safe(result)