Skip to content

Commit

Permalink
New design (bootstrap 4 based)
Browse files Browse the repository at this point in the history
  • Loading branch information
DamienHarper committed Mar 22, 2019
1 parent 61db15c commit 2ed93ff
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 104 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{% macro dump(value, separator) %}
{% spaceless %}
{% if value is iterable %}
{# Ugly hack to guess if value is describing an object #}
{% if value|length == 4 and value.label is defined %}
{{ value.label }}
{% else %}
{% for k, v in value %}
{{ k }}: {{ v }}{{ separator|default('<br/>')|raw }}
{% endfor %}
{% endif %}
{% else %}
{{ value }}
{% endif %}
{% endspaceless %}
{% endmacro dump %}

{% macro humanize(entity, entry) %}
{% import _self as audit_helper %}

{% if entry.getType() == 'insert' %}
{% set action = 'inserted' %}
{% elseif entry.getType() == 'update' %}
{% set action = 'updated' %}
{% elseif entry.getType() == 'remove' %}
{% set action = 'deleted' %}
{% elseif entry.getType() == 'associate' %}
{% set action = 'associated' %}
{% set target = entry.getDiffs() %}
{% elseif entry.getType() == 'dissociate' %}
{% set action = 'dissociated' %}
{% set target = entry.getDiffs() %}
{% else %}
{% set action = '???' %}
{% endif %}

<code>{{ entity }}#{{ entry.getObjectId() }}</code>
has been <b>{{ action }}</b>
{% if target is defined %}
{% set defaultLabel = target['target']['class'] ~ '#' ~ target['target']['id'] %}
{{ entry.getType() == 'associate' ? 'with' : 'from' }} <code>{{ defaultLabel }}</code>
{% if defaultLabel != target['target']['label'] %}
(<em>{{ audit_helper.dump(target['target']) }}</em>)
{% endif %}
{% endif %}
by <b>{{ entry.getUsername() is null ? 'unknown user' : entry.getUsername() }}</b>
on {{ entry.getCreatedAt()|date('Y-m-d') }} at {{ entry.getCreatedAt()|date('H:i:s') }}
{% if entry.getIp() is not empty %}
, IP: {{ entry.getIp() }}
{% endif %}
{% endmacro %}
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
{% extends "@DHDoctrineAudit/layout.html.twig" %}

{% block dh_doctrine_audit_content %}
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item active"><a href="{{ path('dh_doctrine_audit_list_audits') }}">Home</a></li>
</ol>
</nav>

<h2 class="card-title">{{ audited|length }} audited entities</h2>

<table class="table table-hover">
<thead class="thead-dark">
<th>Entity</th>
<th>Table</th>
<th></th>
</thead>
<tbody>
{% for entity, table in audited %}
<tr>
<td><code>{{ entity|escape }}</code></td>
<td>{{ table|escape }}</td>
<td>
<a href="{{ path('dh_doctrine_audit_show_entity_history', { 'entity': entity }) }}">View audits</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<div class="card">
<div class="card-body">
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item active"><a href="{{ path('dh_doctrine_audit_list_audits') }}">Home</a></li>
</ol>
</nav>
<h4 class="card-title">{{ audited|length }} audited entities</h4>
<table class="table table-hover">
<thead class="thead-dark">
<th>Entity</th>
<th>Table</th>
<th></th>
</thead>
<tbody>
{% for entity, table in audited %}
<tr>
<td><code>{{ entity|escape }}</code></td>
<td>{{ table|escape }}</td>
<td>
<a href="{{ path('dh_doctrine_audit_show_entity_history', { 'entity': entity }) }}">View audits</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% endblock dh_doctrine_audit_content %}
Original file line number Diff line number Diff line change
@@ -1,36 +1,23 @@
{% extends "@DHDoctrineAudit/layout.html.twig" %}

{% import '@DHDoctrineAudit/Audit/bootstrap.html.twig' as bootstrap %}

{% macro dump(value, separator) %}
{% if value is iterable %}
{# Vilain hack afin de deviner si value correspond à un objet #}
{% if value|length == 4 and value.label is defined %}
{{ value.label|trans }}
{% else %}
{% for k, v in value %}
{{ k }}: {{ v }}{{ separator|default('<br/>')|raw }}
{% endfor %}
{% endif %}
{% else %}
{{ value }}
{% endif %}
{% endmacro dump %}

{% import _self as audit_viewer %}
{% import '@DHDoctrineAudit/Audit/audit_helper.html.twig' as audit_helper %}

{% block dh_doctrine_audit_content %}
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="{{ path('dh_doctrine_audit_list_audits') }}">Home</a></li>
<li class="breadcrumb-item"><a href="{{ path('dh_doctrine_audit_show_entity_history', {'entity': entity}) }}">{{ entity }}</a></li>
<li class="breadcrumb-item active" aria-current="page"><a href="{{ path('dh_doctrine_audit_show_audit_entry', {'entity': entity, 'id': entry.getObjectId()}) }}">{{ entity }}#{{ entry.getObjectId() }}</a></li>
</ol>
</nav>
<div class="card">
<div class="card-body">
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="{{ path('dh_doctrine_audit_list_audits') }}">Home</a></li>
<li class="breadcrumb-item"><a href="{{ path('dh_doctrine_audit_show_entity_history', {'entity': entity}) }}">{{ entity }}</a></li>
<li class="breadcrumb-item active" aria-current="page"><a href="{{ path('dh_doctrine_audit_show_audit_entry', {'entity': entity, 'id': entry.getObjectId()}) }}">{{ entity }}#{{ entry.getObjectId() }}</a></li>
</ol>
</nav>

{% set diffs = entry.getDiffs() %}
<h2 class="card-title float-left"><code>{{ entity }}#{{ entry.getObjectId() }}</code></h2>
<h3 class="float-right">{{ bootstrap.badge(entry.getType(), bootstrap.label_type(entry.getType())) }}</h3>
{% set diffs = entry.getDiffs() %}
<h4 class="card-title float-left"><code>{{ entity }}#{{ entry.getObjectId() }}</code></h4>
<h5 class="float-right">{{ bootstrap.badge(entry.getType(), bootstrap.label_type(entry.getType())) }}</h5>
<h6 style="clear: both">{{ audit_helper.humanize(entity, entry) }}</h6>

{% if entry.getType() in ['associate', 'dissociate'] %}
<table class="table table-hover">
Expand All @@ -42,7 +29,7 @@
{% for key, value in diffs['target'] %}
<tr>
<td><code>{{ key }}</code></td>
<td>{{ bootstrap.text(audit_viewer.dump(value), 'secondary') }}</td>
<td>{{ bootstrap.text(audit_helper.dump(value), 'secondary') }}</td>
</tr>
{% endfor %}
</tbody>
Expand All @@ -57,7 +44,7 @@
{% for key, value in diffs %}
<tr>
<td><code>{{ key }}</code></td>
<td>{{ bootstrap.text(audit_viewer.dump(value), 'secondary') }}</td>
<td>{{ bootstrap.text(audit_helper.dump(value), 'secondary') }}</td>
</tr>
{% endfor %}
</tbody>
Expand All @@ -78,13 +65,13 @@
{% if values['old'] is empty %}
{{ bootstrap.badge('null', 'secondary') }}
{% else %}
{{ bootstrap.text(audit_viewer.dump(values['old']), 'danger') }}
{{ bootstrap.text(audit_helper.dump(values['old']), 'danger') }}
{% endif %}
{% else %}
{% if values['-'] is empty %}
{{ bootstrap.badge('null', 'secondary') }}
{% else %}
{{ bootstrap.text(audit_viewer.dump(values['-']), 'danger') }}
{{ bootstrap.text(audit_helper.dump(values['-']), 'danger') }}
{% endif %}
{% endif %}
</td>
Expand All @@ -94,19 +81,19 @@
{{ bootstrap.badge('null', 'secondary') }}
{% else %}
{% if values['old'] is empty %}
{{ bootstrap.text(audit_viewer.dump(values['new']), 'primary') }}
{{ bootstrap.text(audit_helper.dump(values['new']), 'primary') }}
{% else %}
{{ bootstrap.text(audit_viewer.dump(values['new']), 'success') }}
{{ bootstrap.text(audit_helper.dump(values['new']), 'success') }}
{% endif %}
{% endif %}
{% else %}
{% if values['+'] is empty %}
{{ bootstrap.badge('null', 'secondary') }}
{% else %}
{% if values['-'] is empty %}
{{ bootstrap.text(audit_viewer.dump(values['+']), 'primary') }}
{{ bootstrap.text(audit_helper.dump(values['+']), 'primary') }}
{% else %}
{{ bootstrap.text(audit_viewer.dump(values['+']), 'success') }}
{{ bootstrap.text(audit_helper.dump(values['+']), 'success') }}
{% endif %}
{% endif %}
{% endif %}
Expand All @@ -116,4 +103,6 @@
</tbody>
</table>
{% endif %}
</div>
</div>
{% endblock dh_doctrine_audit_content %}
Original file line number Diff line number Diff line change
@@ -1,46 +1,37 @@
{% extends "@DHDoctrineAudit/layout.html.twig" %}

{% import '@DHDoctrineAudit/Audit/bootstrap.html.twig' as bootstrap %}

{% import _self as audit_viewer %}
{% import '@DHDoctrineAudit/Audit/audit_helper.html.twig' as audit_helper %}

{% block dh_doctrine_audit_content %}
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="{{ path('dh_doctrine_audit_list_audits') }}">Home</a></li>
<li class="breadcrumb-item active" aria-current="page"><a href="{{ path('dh_doctrine_audit_show_entity_history', {'entity': entity}) }}">{{ entity }}</a></li>
</ol>
</nav>
<div class="card">
<div class="card-body">
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="{{ path('dh_doctrine_audit_list_audits') }}">Home</a></li>
<li class="breadcrumb-item active" aria-current="page"><a href="{{ path('dh_doctrine_audit_show_entity_history', {'entity': entity}) }}">{{ entity }}</a></li>
</ol>
</nav>

<h2 class="card-title float-left"><code>{{ entity }}</code></h2>
<h3 class="float-right">{{ bootstrap.badge(entries|length ~ ' operations', 'primary') }}</h3>
<h4 class="card-title float-left"><code>{{ entity }}</code></h4>
<h5 class="float-right">{{ bootstrap.badge(entries|length ~ ' operations', 'primary') }}</h5>

<table class="table table-hover">
<thead class="thead-dark">
<th>Type</th>
<th>Object Id</th>
<th>User Id</th>
<th>Username</th>
<th>Firewall</th>
<th>Class</th>
<th>IP</th>
<th>Created At</th>
<th></th>
</thead>
<tbody>
{% for entry in entries %}
<tr>
<td>{{ bootstrap.badge(entry.getType(), bootstrap.label_type(entry.getType())) }}</td>
<td><a href="{{ path('dh_doctrine_audit_show_entity_history', { 'entity': entity, 'id': entry.getObjectId() }) }}">{{ entry.getObjectId() }}</a></td>
<td>{{ entry.getUserId() }}</td>
<td>{{ entry.getUsername() }}</td>
<td>{{ entry.getUserFirewall() }}</td>
<td>{{ entry.getUserFqdn() }}</td>
<td>{{ entry.getIp() }}</td>
<td>{{ entry.getCreatedAt() }}</td>
<td><a href="{{ path('dh_doctrine_audit_show_audit_entry', { 'entity': entity, 'id': entry.id }) }}">View details</a></td>
</tr>
{% endfor %}
</tbody>
</table>
<table class="table table-hover">
<thead class="thead-dark">
<th>Type</th>
<th>Description</th>
<th></th>
</thead>
<tbody>
{% for entry in entries %}
<tr>
<td>{{ bootstrap.badge(entry.getType(), bootstrap.label_type(entry.getType())) }}</td>
<td>{{ audit_helper.humanize(entity, entry) }}</td>
<td><a href="{{ path('dh_doctrine_audit_show_audit_entry', { 'entity': entity, 'id': entry.id }) }}">View details</a></td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% endblock dh_doctrine_audit_content %}
6 changes: 1 addition & 5 deletions src/DoctrineAuditBundle/Resources/views/layout.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@
<a class="navbar-brand mb-0 text-light">DoctrineAuditBundle demo</a>
</nav>

<div class="card">
<div class="card-body">
{% block dh_doctrine_audit_content %}{% endblock %}
</div>
</div>
{% block dh_doctrine_audit_content %}{% endblock %}
</div>
{% block javascripts %}
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
Expand Down

0 comments on commit 2ed93ff

Please sign in to comment.