misuzu/templates/changelog/macros.twig

86 lines
3.7 KiB
Twig

{% macro changelog_listing(changes, hide_dates, is_manage, change_url, date_url, tag_url, user_url) %}
{% set hide_dates = hide_dates ? true : false %}
{% set is_manage = is_manage ? true : false %}
{% set last_date = '' %}
{% set date_url = date_url|default('/changelog.php?d=%s') %}
{% from _self import changelog_entry %}
{% if changes|length > 0 %}
{% for change in changes %}
{% if not hide_dates and last_date != change.change_date %}
{% set last_date = change.change_date %}
<a class="changelog__date" href="{{ date_url|format(last_date) }}"
{% if date_url|slice(0, 1) == '#' %} id="{{ date_url|format(last_date)|slice(1) }}"{% endif %}>
{{ last_date }}
</a>
{% endif %}
{{ changelog_entry(change, is_manage, change_url, tag_url, user_url) }}
{% endfor %}
{% else %}
<div class="changelog__none">
There are no changes to display here.
</div>
{% endif %}
{% endmacro %}
{% macro changelog_entry(change, is_manage, change_url, tag_url, user_url) %}
{% set is_manage = is_manage ? true : false %}
{% set change_url = change_url|default('/changelog.php?c=%d') %}
{% set tag_url = tag_url|default('/changelog.php?t=%d') %}
{% set user_url = user_url|default('/profile.php?u=%d') %}
{% set has_text = change.change_has_text|default(false)
or (change.change_text is defined and change.change_text|length > 0)
%}
<div class="changelog" id="cl{{ change.change_id }}">
<div class="changelog__info">
{% if is_manage %}
<a href="{{ change_url|format(change.change_id) }}" class="changelog__datetime">
<time class="changelog__datetime__text"
datetime="{{ change.change_created|date('c') }}"
title="{{ change.change_created|date('r') }}">
{{ change.change_created|time_diff }}
</time>
</a>
{% endif %}
<a class="changelog__action{{ change.action_class is defined and change.action_class is not null ? ' changelog__action--' ~ change.action_class : '' }} changelog__action--{{ change.action_colour|colour_get_css_contrast }}"
href="{{ change_url|format(change.change_id) }}"
{% if change.action_colour is defined %}style="{{ change.action_colour|html_colour('--action-colour') }}"{% endif %}>
<div class="changelog__action__text">
{{ change.action_name|default('Unknown') }}
</div>
</a>
{% if change.user_id is defined %}
<a class="changelog__user"
href="{{ user_url|format(change.user_id) }}"
style="{{ change.user_colour|html_colour }}">
<div class="changelog__user__text">
{{ change.username }}
</div>
</a>
{% endif %}
</div>
<div class="changelog__text">
<a class="changelog__log{% if has_text %} changelog__log--link{% endif %}"
{% if has_text %}href="{{ change_url|format(change.change_id) }}"{% endif %}>
{{ change.change_log }}
</a>
{% if is_manage %}
<div class="changelog__tags">
{% for tag in change.tags %}
<a href="{{ tag_url|format(tag.tag_id) }}" class="changelog__tag">
{{ tag.tag_name }}
</a>
{% endfor %}
</div>
{% endif %}
</div>
</div>
{% endmacro %}