{% comment %} History Panel Component ======================= A reusable history panel component for displaying object change history and FSM transitions. Purpose: Displays both regular history records and FSM (Finite State Machine) transition history for parks, rides, and other entities with historical tracking. Usage Examples: Basic history: {% include 'components/history_panel.html' with history=history %} With FSM toggle (for moderators): {% include 'components/history_panel.html' with history=history show_fsm_toggle=True fsm_history_url=fsm_url model_type='park' object_id=park.id can_view_fsm=perms.parks.change_park %} Ride history: {% include 'components/history_panel.html' with history=history show_fsm_toggle=True fsm_history_url=fsm_url model_type='ride' object_id=ride.id can_view_fsm=perms.rides.change_ride %} Parameters: Required: - history: QuerySet or list of history records Optional (FSM): - show_fsm_toggle: Show toggle button for FSM history (default: False) - fsm_history_url: URL for loading FSM transition history via HTMX - model_type: Model type for FSM history (e.g., 'park', 'ride') - object_id: Object ID for FSM history - can_view_fsm: Whether user can view FSM history (default: False) Optional (styling): - title: Panel title (default: 'History') - panel_class: Additional CSS classes for panel - max_height: Maximum height for scrollable area (default: 'max-h-96') - collapsed: Start collapsed (default: False) Dependencies: - Tailwind CSS for styling - Alpine.js for interactivity - HTMX (optional, for FSM history lazy loading) - Font Awesome icons Accessibility: - Uses heading structure for panel title - Toggle button has accessible label - History items use semantic structure {% endcomment %} {% with title=title|default:'History' show_fsm_toggle=show_fsm_toggle|default:False can_view_fsm=can_view_fsm|default:False max_height=max_height|default:'max-h-96' collapsed=collapsed|default:False %}
{# Header with optional FSM toggle #}

{% if collapsed %} {% else %} {{ title }} {% endif %}

{% if show_fsm_toggle and can_view_fsm %} {% endif %}
{# Collapsible wrapper #}
{# FSM Transition History (Moderators Only) #} {% if show_fsm_toggle and can_view_fsm and fsm_history_url %}
{# Loading State #}
Loading transitions...
{% endif %} {# Regular History #}
{% for record in history %}
{# Timestamp and user #}
{# Support both simple_history and pghistory formats #} {% if record.history_date %} {{ record.history_date|date:"M d, Y H:i" }} {% if record.history_user %} by {{ record.history_user.username }} {% endif %} {% elif record.pgh_created_at %} {{ record.pgh_created_at|date:"M d, Y H:i" }} {% if record.pgh_context.user %} by {{ record.pgh_context.user }} {% endif %} {% if record.pgh_label %} - {{ record.pgh_label }} {% endif %} {% endif %}
{# Changes #} {% if record.diff_against_previous %}
{# Support both dictionary and method formats #} {% if record.get_display_changes %} {% for field, change in record.get_display_changes.items %} {% if field != "updated_at" %}
{{ field }}: {{ change.old|default:"—" }} {{ change.new|default:"—" }}
{% endif %} {% endfor %} {% else %} {% for field, changes in record.diff_against_previous.items %} {% if field != "updated_at" %}
{{ field|title }}: {{ changes.old|default:"—" }} {{ changes.new|default:"—" }}
{% endif %} {% endfor %} {% endif %}
{% endif %}
{% empty %}

No history available.

{% endfor %}
{% endwith %}