Add basic versioning history support for master view

as with actual data versioning, we only support Person thus far
This commit is contained in:
Lance Edgar 2017-07-05 03:07:35 -05:00
parent 7340ef1f9b
commit 0b68d56ddb
7 changed files with 354 additions and 6 deletions

View file

@ -0,0 +1,21 @@
## -*- coding: utf-8; -*-
## ##############################################################################
##
## Default master 'versions' template, for showing an object's version history.
##
## ##############################################################################
<%inherit file="/base.mako" />
<%def name="title()">${model_title_plural}: ${instance_title} (History)</%def>
<%def name="extra_javascript()">
${parent.extra_javascript()}
${h.javascript_link(request.static_url('tailbone:static/js/jquery.ui.tailbone.js'))}
<script type="text/javascript">
$(function() {
$('.newgrid-wrapper').gridwrapper();
});
</script>
</%def>
${grid.render_complete()|n}

View file

@ -0,0 +1,139 @@
## -*- coding: utf-8; -*-
<%inherit file="/base.mako" />
<%def name="title()">${instance_title} @ ver ${transaction.id}</%def>
## TODO: this was basically copied from Revel diff template..need to abstract
<%def name="extra_styles()">
${parent.extra_styles()}
<style type="text/css">
table {
border-collapse: collapse;
border-left: 1px solid black;
border-top: 1px solid black;
font-size: 11pt;
margin-top: 2em;
margin-left: 50px;
min-width: 80%;
}
table th,
table td {
border-bottom: 1px solid black;
border-right: 1px solid black;
}
table td {
padding: 5px 10px;
}
table td.value {
font-family: monospace;
white-space: pre;
}
table.new td.host-value,
table.diff tr.diff td.host-value {
background-color: #cfc;
}
table.deleted td.local-value,
table.diff tr.diff td.local-value {
background-color: #fcc;
}
</style>
</%def>
<%def name="content_title()">
<div style="float: right;">
% if previous_transaction:
${h.link_to(u"« Older", url('{}.version'.format(route_prefix), uuid=instance.uuid, txnid=previous_transaction.id), class_='button')}
% else:
${h.link_to(u"« Older", '#', class_='button', disabled='disabled')}
% endif
% if next_transaction:
${h.link_to(u"Newer »", url('{}.version'.format(route_prefix), uuid=instance.uuid, txnid=next_transaction.id), class_='button')}
% else:
${h.link_to(u"Newer »", '#', class_='button', disabled='disabled')}
% endif
</div>
<h1>${self.title()}</h1>
</%def>
<div class="form-wrapper">
<div class="form">
<div class="field-wrapper">
<label>Changed</label>
<div class="field">${h.pretty_datetime(request.rattail_config, changed)}</div>
</div>
<div class="field-wrapper">
<label>Changed by</label>
<div class="field">${transaction.user}</div>
</div>
<div class="field-wrapper">
<label>IP Address</label>
<div class="field">${transaction.remote_addr}</div>
</div>
<div class="field-wrapper">
<label>Comment</label>
<div class="field">${transaction.meta.get('comment') or ''}</div>
</div>
</div>
</div><!-- form-wrapper -->
% for version in versions:
<h2>${version.version_parent.get_model_title()}</h2>
% if version.previous:
<table class="diff">
<thead>
<tr>
<th>field name</th>
<th>old value</th>
<th>new value</th>
</tr>
</thead>
<tbody>
% for field in fields_for_version(version):
<tr${' class="diff"' if getattr(version, field) != getattr(version.previous, field) else ''|n}>
<td class="field">${field}</td>
<td class="value local-value">${repr(getattr(version.previous, field))}</td>
<td class="value host-value">${repr(getattr(version, field))}</td>
</tr>
% endfor
</tbody>
</table>
% else:
<table class="new">
<thead>
<tr>
<th>field name</th>
<th>old value</th>
<th>new value</th>
</tr>
</thead>
<tbody>
% for field in fields_for_version(version):
<tr>
<td class="field">${field}</td>
<td class="value local-value">&nbsp;</td>
<td class="value host-value">${repr(getattr(version, field))}</td>
</tr>
% endfor
</tbody>
</table>
% endif
% endfor