Skip to content

Commit

Permalink
Improve general UI, Home
Browse files Browse the repository at this point in the history
- Add new home to include detailed stats about portal and categories (themes) with datasets.
- Improve header/footer. Move language selector and fix responsive of general web.
  • Loading branch information
mjanez committed Sep 16, 2024
1 parent 8cb65ff commit 4810b07
Show file tree
Hide file tree
Showing 14 changed files with 619 additions and 117 deletions.
403 changes: 327 additions & 76 deletions ckanext/schemingdcat/helpers.py

Large diffs are not rendered by default.

46 changes: 46 additions & 0 deletions ckanext/schemingdcat/subscriptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from __future__ import annotations
import logging
from typing import Any

import ckan.plugins as p
from ckan import types

import ckanext.schemingdcat.config as sdct_config
from ckanext.schemingdcat.helpers import schemingdcat_update_open_data_statistics

log = logging.getLogger(__name__)

def get_subscriptions():
return {
p.toolkit.signals.action_succeeded: [
{"sender": "bulk_update_public", "receiver": stats_changed},
{"sender": "bulk_update_private", "receiver": stats_changed},
{"sender": "bulk_update_delete", "receiver": stats_changed},
{"sender": "package_create", "receiver": stats_changed},
{"sender": "package_update", "receiver": stats_changed},
{"sender": "package_delete", "receiver": stats_changed},
{"sender": "group_create", "receiver": stats_changed},
{"sender": "group_update", "receiver": stats_changed},
{"sender": "group_delete", "receiver": stats_changed},
{"sender": "organization_create", "receiver": stats_changed},
{"sender": "organization_update", "receiver": stats_changed},
{"sender": "organization_delete", "receiver": stats_changed},
]
}

def stats_changed(sender: str, **kwargs: Any):
"""
Handles the event when certain actions are performed and updates site statistics.
Args:
sender (str): The name of the sender that triggered the event.
**kwargs (Any): Additional keyword arguments passed to the function.
Raises:
Exception: If updating site statistics fails, an error is logged.
"""
try:
schemingdcat_update_open_data_statistics()
log.debug(f"schemingdcat subscription -> [{sender}]. Update Open Data site statistics")
except Exception as e:
log.error(f"Failed to Update Open Data site statistics: {e}")
44 changes: 44 additions & 0 deletions ckanext/schemingdcat/templates/footer.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<footer class="site-footer">
<div class="container">
{% block footer_content %}
<div class="row d-flex align-items-start">
<div class="col-md-8 footer-links d-flex flex-column">
{% block footer_nav %}
<div class="footer-sitelinks">
<ul class="list-unstyled">
{% block footer_links_ckan %}
{% set api_url = 'http://docs.ckan.org/en/{0}/api/'.format(g.ckan_doc_version) %}
<li><a href="{{ h.url_for('home.about') }}">{{ _('About {0}').format(g.site_title) }}</a></li>
<li><a href="{{ api_url }}">{{ _('CKAN API') }}</a></li>
<li><a href="http://www.ckan.org/">{{ _('CKAN Association') }}</a></li>
<li><a href="http://www.opendefinition.org/okd/"><img src="{{ h.url_for_static('/base/images/od_80x15_blue.png') }}" alt="Open Data"></a></li>
{% endblock %}
</ul>
</div>
{% endblock %}
</div>
<div class="col-md-4 attribution d-flex flex-column align-items-start">
{% block footer_attribution %}
<div class="footer-powered-ckan">
<p>{% trans %}<strong>Powered by</strong> <a class="hide-text ckan-footer-logo" href="http://ckan.org">CKAN</a>{% endtrans %}</p>
</div>
{% endblock %}
{% block footer_social %}
{% set social = h.schemingdcat_get_social_links() %}
<div class="footer-socicons">
<a href="{{ h.url_for_static_or_external(social.github) }}" class="icon-button">
<span class="fab fa-github"></span>
</a>
<a href="{{ h.url_for_static_or_external(social.x) }}" class="icon-button">
<span class="fab fa-twitter"></span>
</a>
<a href="{{ h.url_for_static_or_external(social.linkedin) }}" class="icon-button">
<span class="fab fa-linkedin"></span>
</a>
</div>
{% endblock %}
</div>
</div>
{% endblock %}
</div>
</footer>
42 changes: 30 additions & 12 deletions ckanext/schemingdcat/templates/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,40 @@
</a>
</li>
{{ super() }}
{% block header_lang_logged %}
<li class="nav-item dropdown">
{% snippet "schemingdcat/snippets/header_language_selector.html" %}
</li>
{% endblock %}
{% endblock %}

{%- block header_debug %} {%- if g.debug and not g.debug_supress_header %}
<div class="custom-debug"><strong>Debug info:</strong><br>Controller : {{ c.controller }}<br/>Action : {{ c.action }}</div>
{%- endif %} {%- endblock %}
{% block header_account_notlogged %}
{{ super() }}

{% block header_lang_notlogged %}
<li class="nav-item dropdown">
{% snippet "schemingdcat/snippets/header_language_selector.html" %}
</li>
{% endblock %}
{% endblock %}

{% block header_debug %} {% if g.debug and not g.debug_supress_header %}
<div class="custom-debug">
<strong>Debug info:</strong>
<br/>
Blueprint : {{ g.blueprint }}
<br/>
View : {{ g.view }}
</div>
{% endif %} {% endblock %}

{% block header_logo %}
<a class="logo" href="{{ h.url_for('home.index') }}">
{% if g.site_logo %}
<a class="logo" href="{{ h.url_for('home.index') }}">
<img src="{{ h.url_for_static_or_external(g.site_logo) }}" alt="{{ g.site_title }}"
title="{{ g.site_title }}" />
</a>
{% else %}
<a class="logo" href="{{ h.url_for('home.index') }}">
<img src="{{ h.url_for_static_or_external('/images/default/ckan-logo.png') }}" alt="{{ g.site_title }}"
title="{{ g.site_title }}" />
</a>
{% set logo_url = g.site_logo if h.get_root_path() in g.site_logo else h.url_for_static_or_external(g.site_logo) %}
{% else %}
{% set logo_url = h.url_for_static_or_external('/images/default/ckan-logo.png') %}
{% endif %}
<img src="{{ logo_url }}" alt="{{ g.site_title }}" title="{{ g.site_title }}" />
</a>
{% endblock %}
2 changes: 1 addition & 1 deletion ckanext/schemingdcat/templates/home/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{{ self.flash() }}
</div>
{% block primary_content %}
{% snippet "home/layout{0}.html".format(homepage_style) %}
{% snippet "home/layout{0}.html".format(homepage_style), search_facets=search_facets %}
{% endblock %}
</div>
{% endblock %}
24 changes: 9 additions & 15 deletions ckanext/schemingdcat/templates/home/layout1.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
<div class="row row1">
<div class="col-md-12">
{% block search %}
{% snippet 'home/snippets/search.html' %}
{% endblock %}
{% block endpoints %}
{% snippet 'home/snippets/endpoints_layout1.html' %}
{% snippet 'home/snippets/search.html', search_facets=search_facets %}
{% endblock %}
</div>
</div>
Expand All @@ -16,19 +13,16 @@
<div class="main">
<div class="container">
<div class="row row2">
<div class="col-md-6 col1">
{# Note: this featured_group block is used as an example in the theming
tutorial in the docs! If you change this code, be sure to check
whether you need to update the docs. #}
{# Start template block example. #}
{% block featured_group %}
{% snippet 'home/snippets/featured_group.html' %}
<div class="col-md-12">
{% block about_portal %}
{% snippet 'home/snippets/about_portal.html' %}
{% endblock %}
{# End template block example. #}
</div>
<div class="col-md-6 col2">
{% block featured_organization %}
{% snippet 'home/snippets/featured_organization.html' %}
</div>
<div class="row row2"></div>
<div class="col-md-12">
{% block about_themes %}
{% snippet 'home/snippets/about_themes.html' %}
{% endblock %}
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion ckanext/schemingdcat/templates/home/layout2.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class="row row1">
<div class="col-md-6 col1">
{% block search %}
{% snippet 'home/snippets/search.html' %}
{% snippet 'home/snippets/search.html', search_facets=search_facets %}
{% endblock %}
{% block stats %}
{% snippet 'home/snippets/stats.html' %}
Expand Down
2 changes: 1 addition & 1 deletion ckanext/schemingdcat/templates/home/layout3.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div role="main" class="hero">
<div class="container">
{% block search %}
{% snippet 'home/snippets/search.html' %}
{% snippet 'home/snippets/search.html', search_facets=search_facets %}
{% endblock %}
</div>
</div>
Expand Down
41 changes: 41 additions & 0 deletions ckanext/schemingdcat/templates/home/layout4.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<div role="main">
<div class="main hero">
<div class="container">
<div class="row row1">
<div class="col-md-12">
{% block search %}
{% snippet 'home/snippets/search.html', search_facets=search_facets %}
{% endblock %}
</div>
</div>
</div>
</div>
<div class="main">
<div class="container">
<div class="row row2">
<div class="col-md-12">
{% block about_portal %}
{% snippet 'home/snippets/about-portal.html' %}
{% endblock %}
</div>
</div>
<div class="row row2">
<div class="col-md-6 col1">
{# Note: this featured_group block is used as an example in the theming
tutorial in the docs! If you change this code, be sure to check
whether you need to update the docs. #}
{# Start template block example. #}
{% block featured_group %}
{% snippet 'home/snippets/featured_group.html' %}
{% endblock %}
{# End template block example. #}
</div>
<div class="col-md-6 col2">
{% block featured_organization %}
{% snippet 'home/snippets/featured_organization.html' %}
{% endblock %}
</div>
</div>
</div>
</div>
</div>
51 changes: 51 additions & 0 deletions ckanext/schemingdcat/templates/home/snippets/about_portal.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{#
Macro to render a card with an icon, count, label, URL, and aria-label.

icon_class - The Font Awesome icon class.
count - The count to display on the card.
label - The label to display on the card.
url - The URL the card should link to.
target_blank - Optional boolean to open the link in a new tab with security attributes.

Example:

{{ render_card("fas fa-database", 123, "Datasets", "https://example.com", "Example aria label", target_blank=True) }}
#}

{% set stats = h.schemingdcat_get_open_data_statistics() %}
{% macro render_card(icon_class, count, label, url, target_blank=False) %}
<div class="sct-about-figures-alt-card mt-2">
<div class="sct-about-figures-alt-card-icon avoindata-explore-showcase">
<i class="{{ icon_class }}"></i>
</div>
<div class="sct-about-figures-alt-card-content">
<div class="sct-about-figures-alt-card-title">
<h3>{{ h.SI_number_span(count) }}</h3>
</div>
<div class="sct-about-figures-alt-card-text">
<a href="{{ url }}" {% if target_blank %}target="_blank" rel="noopener noreferrer"{% endif %}>{{ label }}</a>
</div>
</div>
</div>
{% endmacro %}

<section>
<div class="sct-about-figures sct-about-figures--col-3 ecl-u-mv-xl ecl-u-border-color-grey-10 ecl-u-border-width-1 ecl-u-border-all">
<div class="sct-about-h3-container">
<h3 class="sct-about-h3">{{ _('Explore and use Open Data') }}</h3>
</div>
<div class="sct-about-figures__items">
{{ render_card("fas fa-table-list", stats.dataset_count, _('Dataset') if stats.dataset_count == 1 else _('Datasets'), h.url_for(controller='dataset', action='search')) }}

{{ render_card("fas fa-globe", stats.spatial_dataset_count, _('Spatial dataset') if stats.spatial_dataset_count == 1 else _('Spatial datasets'), h.url_for('dataset.search', dataset_scope='spatial_dataset')) }}

{{ render_card("fas fa-tags", stats.tag_count, _('Tag') if stats.tag_count == 1 else _('Tags'), h.url_for('api.action', ver=3, logic_function='tag_list'), target_blank=True) }}

{{ render_card("fa-solid fa-sitemap", stats.organization_count, _('Organization') if stats.organization_count == 1 else _('Organizations'), h.url_for(controller='organization', action='index')) }}

{{ render_card("fa-solid fa-square-share-nodes", stats.endpoints_count, _('Catalog endpoints'), h.url_for('schemingdcat.endpoint_index')) }}

{{ render_card("fas fa-folder-open", stats.group_count, _('Group') if stats.group_count == 1 else _('Groups'), h.url_for(controller='group', action='index')) }}
</div>
</div>
</section>
42 changes: 42 additions & 0 deletions ckanext/schemingdcat/templates/home/snippets/about_themes.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{#
Macro to render a card with an SVG icon, label, and URL.

icon_path - The path to the SVG icon.
label - The label to display on the card.
count - The count to display on the card.
url - The base URL the card should link to.
param_name - The name of the URL parameter.
param_value - The value of the URL parameter.
target_blank - Optional boolean to open the link in a new tab with security attributes.

Example:

{{ render_svg_card("/images/icons/theme/example.svg", "Example Label", 123, "https://example.com", "theme", "example_value", target_blank=True) }}
#}
{% macro render_svg_card(icon_path, label, count, url, param_name, param_value, target_blank=False) %}
<a href="{{ url }}?{{ param_name }}={{ param_value | urlencode }}" class="sct-about-themes-card mt-2" {% if target_blank %}target="_blank" rel="noopener noreferrer"{% endif %}>
<div class="sct-about-themes-card-icon-container">
<div class="sct-about-themes-card-icon">
<img src="{{ h.url_for_static(icon_path) }}" alt="{{ label }} icon" />
</div>
<div class="sct-about-themes-card-count">{{ h.SI_number_span(count) }}</div>
</div>
{% if label|length <= 2 %}
<div class="sct-about-themes-card-acronym">{{ label.upper() }}</div>
{% endif %}
<div class="sct-about-themes-card-label">{{ _(label) }}</div>
</a>
{% endmacro %}

{% set themes_stats = h.schemingdcat_get_open_data_statistics().themes_stats %}

<div class="sct-about-themes">
<div class="sct-about-h4-container">
<h3 class="sct-about-h4">{{ _('Theme categories') }}</h3>
</div>
<div class="sct-about-themes-card-container">
{% for theme in themes_stats %}
{{ render_svg_card(theme.icon, theme.label, theme.count, h.url_for('dataset.search'), theme.field_name, theme.value) }}
{% endfor %}
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ <h3><a href="{{ h.url_for('schemingdcat.endpoint_index') }}" title="{{ _('Catalo
{% set csw_uri = h.get_site_protocol_and_host()[0] +'://' + h.get_site_protocol_and_host()[1] + '/' + endpoint.endpoint %}
{% endif %}

<a class="tag endpoints_layout1" href="{{ csw_uri }}"><i class="fa fa-globe"> </i> {{ endpoint.display_name }} <img src="{{ h.url_for_static(endpoint.image_display_url) }}" alt="{{ endpoint.display_name }}"></a>
<a class="tag endpoints_index_cards" href="{{ csw_uri }}"><i class="fa fa-globe"> </i> {{ endpoint.display_name }} <img src="{{ h.url_for_static(endpoint.image_display_url) }}" alt="{{ endpoint.display_name }}"></a>

{% elif endpoint.type == 'lod' %}
{% set endpoint_url = h.url_for(endpoint.endpoint, **endpoint.endpoint_data) %}
<a class="tag endpoints_layout1" href="{{ h.schemingdcat_url_unquote(endpoint_url) }}"><i class="fa fa-share-alt"> </i> {{ endpoint.display_name }} <img src="{{ h.url_for_static(endpoint.image_display_url) }}" alt="{{ endpoint.display_name }}"></a>
<a class="tag endpoints_index_cards" href="{{ h.schemingdcat_url_unquote(endpoint_url) }}"><i class="fa fa-share-alt"> </i> {{ endpoint.display_name }} <img src="{{ h.url_for_static(endpoint.image_display_url) }}" alt="{{ endpoint.display_name }}"></a>
{% endif %}
{% endfor %}
</div>
Expand Down
Loading

0 comments on commit 4810b07

Please sign in to comment.