Refactored zone history retrieval, parsing and displaying code.

This commit is contained in:
Rauno Tuul
2023-04-04 15:32:52 +03:00
parent 53cfa4fdaa
commit fe10665e19
5 changed files with 224 additions and 303 deletions

View File

@ -10,26 +10,41 @@
<table id="tbl_history" class="table table-bordered table-striped">
<thead>
<tr>
<th>Changed by</th>
<th>Content</th>
<th>Time</th>
<th>Content</th>
<th>Changed by</th>
<th>Detail</th>
</tr>
</thead>
<tbody>
{% for history in histories %}
<tr class="odd gradeX">
<td>{{ history.history.created_by }}</td>
<td>{{ history.history.msg }}</td>
<td>{{ history.history.created_on }}</td>
<td>{{ history.history.msg }}</td>
<td>{{ history.history.created_by }}</td>
<td width="6%">
<div id="history-info-div-{{ loop.index0 }}" style="display: none;">
{{ history.detailed_msg | safe }}
{% if history.change_set %}
<div class="content">
<div id="change_index_definition"></div>
{% call applied_change_macro.applied_change_template(history.change_set) %}
{% endcall %}
<table class="table table-bordered table-striped">
<thead><tr>
<th>Name</th>
<th>Type</th>
<th>TTL</th>
<th>Data</th>
<th>Status</th>
<th>Comment</th>
</tr></thead>
<tbody>
{% for applied_change in history.change_set %}
<tr>
{% call applied_change_macro.applied_change_template(applied_change) %}
{% endcall %}
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endif %}
</div>
@ -52,7 +67,7 @@
$(document).ready(function () {
table = $('#tbl_history').DataTable({
"order": [
[2, "desc"]
[0, "desc"]
],
"searching": true,
"columnDefs": [{
@ -60,7 +75,7 @@
"render": function (data, type, row) {
return moment.utc(data).local().format('YYYY-MM-DD HH:mm:ss');
},
"targets": 2
"targets": 0
}],
"info": true,
"autoWidth": false,

View File

@ -1,114 +1,121 @@
{% macro applied_change_template(change_set) -%}
{% macro applied_change_template(hist_rec_entry) -%}
{{ caller() }}
{% for hist_rec_entry in change_set %}
<table id="tbl_records" class="table table-bordered">
<thead>
<tr>
<th scope="col" colspan="3">
{% if hist_rec_entry.change_type == '-' %}
<span class="diff diff-deletion">{{
hist_rec_entry.del_rrset['name'] }} {{ hist_rec_entry.del_rrset['type']
}}</span>
{% elif hist_rec_entry.change_type == '+' %}
<span class="diff diff-addition">{{
hist_rec_entry.add_rrset['name'] }} {{ hist_rec_entry.add_rrset['type']
}}</span>
{% else %}
<span class="diff diff-unchanged">{{
hist_rec_entry.add_rrset['name'] }} {{ hist_rec_entry.add_rrset['type']
}}</span>
{% endif %}
, TTL
{% if not 'ttl' in hist_rec_entry.changed_fields %}
<span class="diff diff-unchanged">{{
hist_rec_entry.add_rrset['ttl']
}}</span>
{% else %}
{% if hist_rec_entry.change_type in ['-', '*'] %}
<span class="diff diff-deletion">{{
hist_rec_entry.del_rrset['ttl']
}}</span>
{% endif %}
{% if hist_rec_entry.change_type in ['+', '*'] %}
<span class="diff diff-addition">{{
hist_rec_entry.add_rrset['ttl']
}}</span>
{% endif %}
{% endif %}
<td>
{% if hist_rec_entry.change_type == '-' %}
<div class="diff diff-deletion">{{
hist_rec_entry.del_rrset['name']
}}
{% elif hist_rec_entry.change_type == '+' %}
<div class="diff diff-addition">{{
hist_rec_entry.add_rrset['name']
}}
{% else %}
<div class="diff diff-unchanged">{{
hist_rec_entry.add_rrset['name']
}}
{% endif %}
</div>
</td>
</th>
</tr>
<td>
{% if hist_rec_entry.change_type == '-' %}
<div class="diff diff-deletion">{{
hist_rec_entry.del_rrset['type']
}}
{% elif hist_rec_entry.change_type == '+' %}
<div class="diff diff-addition">{{
hist_rec_entry.add_rrset['type']
}}
{% else %}
<div class="diff diff-unchanged">{{
hist_rec_entry.add_rrset['type']
}}
{% endif %}
</div>
</td>
<tr>
<th scope="col" style="width: 150px;">Status</th>
<th scope="col" style="width: 400px;">Data</th>
<th scope="col" style="width: 400px;">Comment</th>
</tr>
</thead>
<tbody>
{% for changes in hist_rec_entry.changeSet %}
<tr>
<td style="word-break: break-all">
{% if changes[2] == "unchanged" or
(changes[2] == "edit" and changes[0]['disabled'] == changes[1]['disabled']) %}
<div class="diff diff-unchanged">{{
"Disabled" if changes[1]['disabled'] else "Activated"
}}</div>
{% else %}
{% if changes[2] in ["deletion", "edit"] %}
<div class="diff diff-deletion">{{
"Disabled" if changes[0]['disabled'] else "Activated"
}}</div>
{% endif %}
{% if changes[2] in ["addition", "edit"] %}
<div class="diff diff-addition">{{
"Disabled" if changes[1]['disabled'] else "Activated"
}}</div>
{% endif %}
{% endif %}
</td>
<td style="word-break: break-all">
{% if changes[2] == "unchanged" or
(changes[2] == "edit" and changes[0]['content'] == changes[1]['content']) %}
<div class="diff diff-unchanged">{{
changes[1]['content']
}}</div>
{% else %}
{% if changes[2] in ["deletion", "edit"] %}
<div class="diff diff-deletion">{{
changes[0]['content']
}}</div>
{% endif %}
{% if changes[2] in ["addition", "edit"] %}
<div class="diff diff-addition">{{
changes[1]['content']
}}</div>
{% endif %}
{% endif %}
</td>
<td style="word-break: break-all">
{% if changes[2] == "unchanged" or
(changes[2] == "edit" and changes[0]['comment'] == changes[1]['comment']) %}
<div class="diff diff-unchanged">{{
changes[1]['comment']
}}</div>
{% else %}
{% if changes[2] in ["deletion", "edit"] and changes[0]['comment'] %}
<div class="diff diff-deletion">{{
changes[0]['comment']
}}</div>
{% endif %}
{% if changes[2] in ["addition", "edit"] and changes[1]['comment'] %}
<div class="diff diff-addition">{{
changes[1]['comment']
}}</div>
{% endif %}
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
<td>
{% if not 'ttl' in hist_rec_entry.changed_fields %}
<div class="diff diff-unchanged">{{
hist_rec_entry.add_rrset['ttl']
}}</div>
{% else %}
{% if hist_rec_entry.change_type in ['+', '*'] %}
<div class="diff diff-addition">{{
hist_rec_entry.add_rrset['ttl']
}}</div>
{% endif %}
{% if hist_rec_entry.change_type in ['-', '*'] %}
<div class="diff diff-deletion">{{
hist_rec_entry.del_rrset['ttl']
}}</div>
{% endif %}
{% endif %}
</td>
<td style="word-break: break-all">
{% for changes in hist_rec_entry.changeSet %}
{% if changes[2] == "unchanged" or (changes[2] == "edit" and changes[0]['content'] == changes[1]['content']) %}
<div class="diff diff-unchanged">{{
changes[1]['content']
}}</div>
{% else %}
{% if changes[2] in ["deletion", "edit"] %}
<div class="diff diff-deletion">{{
changes[0]['content']
}}</div>
{% endif %}
{% if changes[2] in ["addition", "edit"] %}
<div class="diff diff-addition">{{
changes[1]['content']
}}</div>
{% endif %}
{% endif %}
{% endfor %}
</td>
<td>
{% for changes in hist_rec_entry.changeSet %}
{% if changes[2] == "unchanged" or
(changes[2] == "edit" and changes[0]['disabled'] == changes[1]['disabled']) %}
<div class="diff diff-unchanged">{{
"Disabled" if changes[1]['disabled'] else "Activated"
}}</div>
{% else %}
{% if changes[2] in ["deletion", "edit"] %}
<div class="diff diff-deletion">{{
"Disabled" if changes[0]['disabled'] else "Activated"
}}</div>
{% endif %}
{% if changes[2] in ["addition", "edit"] %}
<div class="diff diff-addition">{{
"Disabled" if changes[1]['disabled'] else "Activated"
}}</div>
{% endif %}
{% endif %}
{% endfor %}
</td>
<td style="word-break: break-all">
{% for changes in hist_rec_entry.changeSet %}
{% if changes[2] == "unchanged" or
(changes[2] == "edit" and changes[0]['comment'] == changes[1]['comment']) %}
<div class="diff diff-unchanged">{{
changes[1]['comment']
}}</div>
{% else %}
{% if changes[2] in ["deletion", "edit"] and changes[0]['comment'] %}
<div class="diff diff-deletion">{{
changes[0]['comment']
}}</div>
{% endif %}
{% if changes[2] in ["addition", "edit"] and changes[1]['comment'] %}
<div class="diff diff-addition">{{
changes[1]['comment']
}}</div>
{% endif %}
{% endif %}
{% endfor %}
</td>
{%- endmacro %}

View File

@ -49,6 +49,12 @@
<thead>
<tr>
<th>Changed on</th>
<th>Name</th>
<th>Type</th>
<th>TTL</th>
<th>Data</th>
<th>Status</th>
<th>Comment</th>
<th>Changed by</th>
</tr>
</thead>
@ -56,22 +62,14 @@
{% for applied_change in allHistoryChanges %}
<tr class="odd row_record" id="{{ domain.name }}">
<td id="changed_on" class="changed_on">
{{ allHistoryChanges[applied_change][0].history_entry.created_on }}
{{ applied_change.history_entry.created_on }}
</td>
{% call applied_change_macro.applied_change_template(applied_change) %}
{% endcall %}
<td>
{{allHistoryChanges[applied_change][0].history_entry.created_by }}
{{ applied_change.history_entry.created_by }}
</td>
</tr>
<!-- Nested Table -->
<tr style='visibility:collapse'>
<td colspan="2">
<div class="content">
{% call applied_change_macro.applied_change_template(allHistoryChanges[applied_change]) %}
{% endcall %}
</div>
</td>
</tr>
<!-- end nested table -->
{% endfor %}
</tbody>
</table>
@ -106,18 +104,6 @@
});
}
// handle click on history record
$(document.body).on("click", ".row_record", function (e) {
e.stopPropagation();
var nextRow = $(this).next('tr')
if (nextRow.css("visibility") == "visible")
nextRow.css("visibility", "collapse")
else
nextRow.css("visibility", "visible")
});
var els = document.getElementsByClassName("changed_on");
for (var i = 0; i < els.length; i++) {
// els[i].innerHTML = moment.utc(els[i].innerHTML).local().format('YYYY-MM-DD HH:mm:ss');