Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HTMX to activity stream #8160

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
2 changes: 2 additions & 0 deletions changes/8129.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Use htmx on the activity type select element filters.
Use htmx to navigate to newer and older versions of activity stream.
1 change: 1 addition & 0 deletions changes/8129.removal
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove `activity-stream.js` module
10 changes: 10 additions & 0 deletions ckan/lib/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,13 @@ def edit_template(self) -> str:
"""
return 'group/edit.html'

def activity_read_base_template(self) -> str:
"""
Returns a string representing the location of the template to be
rendered for the activity stream page
"""
return 'group/read_base.html'

def activity_template(self) -> str:
"""
Returns a string representing the location of the template to be
Expand Down Expand Up @@ -581,6 +588,9 @@ def edit_template(self) -> str:
def activity_template(self) -> str:
return 'organization/activity_stream.html'

def activity_template(self) -> str:
return 'organization/read_base.html'


class DefaultTranslation(object):
name: str
Expand Down
34 changes: 0 additions & 34 deletions ckanext/activity/assets/activity-stream.js

This file was deleted.

1 change: 0 additions & 1 deletion ckanext/activity/assets/webassets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ activity:
- base/main
contents:
- dashboard.js
- activity-stream.js

activity-css:
output: ckanext-activity/%(version)s_activity.css
Expand Down
17 changes: 5 additions & 12 deletions ckanext/activity/templates/group/activity_stream.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
{% extends "group/read_base.html" %}
{% if activity_types is defined %}
{% snippet 'snippets/activity_type_selector.html', id=id, activity_type=activity_type, activity_types=activity_types, blueprint='activity.group_activity' %}
{% endif %}

{% block subtitle %}{{ _('Activity Stream') }} {{ g.template_title_delimiter }} {{ super() }}{% endblock %}
{% snippet 'snippets/stream.html', activity_stream=activity_stream, id=id, object_type='group' %}

{% block primary_content_inner %}
{% snippet 'snippets/pagination.html', newer_activities_url=newer_activities_url, older_activities_url=older_activities_url %}

{% if activity_types is defined %}
{% snippet 'snippets/activity_type_selector.html', id=id, activity_type=activity_type, activity_types=activity_types, blueprint='activity.group_activity' %}
{% endif %}

{% snippet 'snippets/stream.html', activity_stream=activity_stream, id=id, object_type='group' %}

{% snippet 'snippets/pagination.html', newer_activities_url=newer_activities_url, older_activities_url=older_activities_url %}

{% endblock %}
6 changes: 6 additions & 0 deletions ckanext/activity/templates/group/read_base.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
{% ckan_extends %}

{% block subtitle %}{{ _('Activity Stream') }} {{ g.template_title_delimiter }} {{ super() }}{% endblock subtitle %}

{% block content_primary_nav %}
{{ super() }}
{{ h.build_nav_icon('activity.group_activity', _('Activity Stream'), id=group_dict.name, offset=0, icon='clock') }}
{% endblock content_primary_nav %}

{% block primary_content_inner %}
{% snippet 'group/activity_stream.html', activity_stream=activity_stream, id=id, object_type='group', group_type=group_type, activity_types=activity_types, blueprint='activity.group_activity' %}
{% endblock primary_content_inner %}
17 changes: 5 additions & 12 deletions ckanext/activity/templates/organization/activity_stream.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
{% extends "organization/read_base.html" %}
{% if activity_types is defined %}
{% snippet 'snippets/activity_type_selector.html', id=id, activity_type=activity_type, activity_types=activity_types, blueprint='activity.organization_activity' %}
{% endif %}

{% block subtitle %}{{ _('Activity Stream') }} {{ g.template_title_delimiter }} {{ super() }}{% endblock %}
{% snippet 'snippets/stream.html', activity_stream=activity_stream, id=id, object_type='organization' %}

{% block primary_content_inner %}

{% if activity_types is defined %}
{% snippet 'snippets/activity_type_selector.html', id=id, activity_type=activity_type, activity_types=activity_types, blueprint='activity.organization_activity' %}
{% endif %}

{% snippet 'snippets/stream.html', activity_stream=activity_stream, id=id, object_type='organization', group_type=group_type %}

{% snippet 'snippets/pagination.html', newer_activities_url=newer_activities_url, older_activities_url=older_activities_url %}
{% endblock %}
{% snippet 'snippets/pagination.html', newer_activities_url=newer_activities_url, older_activities_url=older_activities_url %}
6 changes: 6 additions & 0 deletions ckanext/activity/templates/organization/read_base.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
{% ckan_extends %}

{% block subtitle %}{{ _('Activity Stream') }} {{ g.template_title_delimiter }}{% endblock subtitle%}

{% block content_primary_nav %}
{{ super() }}
{{ h.build_nav_icon('activity.organization_activity', _('Activity Stream'), id=group_dict.name, offset=0, icon='clock') }}
{% endblock content_primary_nav %}

{% block primary_content_inner %}
{% snippet 'organization/activity_stream.html', activity_stream=activity_stream, id=id, object_type='organization', group_type=group_type, activity_types=activity_types, blueprint='activity.organization_activity' %}
{% endblock primary_content_inner %}
7 changes: 7 additions & 0 deletions ckanext/activity/templates/snippets/activity_stream.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% if activity_types is defined %}
{% snippet 'snippets/activity_type_selector.html', id=id, activity_type=activity_type, activity_types=activity_types, blueprint=blueprint %}
{% endif %}

{% snippet 'snippets/stream.html', activity_stream=activity_stream, id=id, object_type=group_type %}

{% snippet 'snippets/pagination.html', newer_activities_url=newer_activities_url, older_activities_url=older_activities_url %}
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
blueprint - blueprint to call when selecting an activity type to filter by (eg: dataset.activity)
#}

<div id="activity_types_filter" style="margin-bottom: 15px;" data-module="activity-stream">
<div id="activity_types_filter" style="margin-bottom: 15px;">
<label for="activity_types_filter_select" class="form-label">
{{ _('Activity type') }}
</label>
<select id="activity_types_filter_select" class="form-select">
<option {% if not activity_types %}selected{% endif %} data-url="{{ h.url_for(blueprint, id=id) }}">
<option {% if not activity_types %}selected{% endif %} hx-get="{{ h.url_for(blueprint, id=id) }}" hx-target="closest .module-content" hx-push-url="true">
{{ _('All activity types') }}
</option>
{% for type_ in activity_types %}
<option {% if activity_type == type_ %}selected{% endif %} data-url="{{ h.url_for(blueprint, id=id, activity_type=type_) }}">
<option {% if activity_type == type_ %}selected{% endif %} hx-get="{{ h.url_for(blueprint, id=id, activity_type=type_) }}" hx-target="closest .module-content" hx-push-url="true">
{# TODO: Calling humanize gets complex when displaying orgs/groups since the activities also contains dataset activities #}
{{ type_ | title }}
</option>
Expand Down
2 changes: 1 addition & 1 deletion ckanext/activity/templates/snippets/pagination.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{% set class_next = "btn btn-default" if older_activities_url else "btn disabled" %}

{% if newer_activities_url or older_activities_url %}
<div id="activity_page_buttons" class="activity_buttons" style="margin-top: 25px;">
<div hx-boost="true" id="activity_page_buttons" class="activity_buttons" style="margin-top: 25px;">
<a href="{{ newer_activities_url }}" class="{{ class_prev }}">
{{ _('Newer activities') }}
</a>
Expand Down
12 changes: 9 additions & 3 deletions ckanext/activity/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,9 +572,15 @@ def group_activity(id: str, group_type: str) -> str:
"older_activities_url": older_activities_url
}

return tk.render(
_get_group_template("activity_template", group_type), extra_vars
)
if tk.request.htmx:
return tk.render(
_get_group_template("activity_template", group_type), extra_vars
)
else:
return tk.render(
_get_group_template("activity_read_base_template", group_type),
extra_vars
)


@bp.route(
Expand Down