Skip to content

Commit

Permalink
frontpage: replace react recent uploads component with jinja
Browse files Browse the repository at this point in the history
  • Loading branch information
jennur authored and zzacharo committed Jul 5, 2023
1 parent a1b54f8 commit 4215924
Show file tree
Hide file tree
Showing 9 changed files with 370 additions and 5 deletions.
44 changes: 44 additions & 0 deletions assets/less/zenodo-rdm/modules/popup.overrides
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

.ui.label.stats-popup {
position: relative;

.ui.popup {
display: none;
position: absolute;
top: -200%;
width: max-content;

&:before {
top: 95%;
}

}

&#uniqueViews {
.ui.popup {
left: 0;

&:before {
top: 87%;
left: 24%;
}
}
}

&#uniqueDownloads {
.ui.popup {
right: 0;

&:before {
top: 87%;
right: 16%;
}
}
}

&:hover {
.ui.popup {
display: block !important;
}
}
}
Empty file.
37 changes: 37 additions & 0 deletions assets/less/zenodo-rdm/views/item.overrides
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,40 @@
font-weight: @bold;
}
}


.ui.items {

&.link > .item:hover .content .header {
color: @darkTextColor;
}

&.carousel.page {
width: 100%;

&:first-child {
margin: 1.5em 0 !important;
}
}

& > .carousel.item {
min-width: 100%;
}

.content {
width: 100% !important;

&.flex.right-column {
flex-direction: column;
align-items: end;
};
}
}

#records-list {
.ui.items {
li.item {
padding-left: 0 !important; // Needed because of override for li ~ .item
}
}
}
4 changes: 3 additions & 1 deletion invenio.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Only configuration created via cookiecutter or very likely to be edited
by installer are included here.
"""

from invenio_app_rdm.config import CELERY_BEAT_SCHEDULE
from invenio_app_rdm.config import CELERY_BEAT_SCHEDULE, APP_RDM_ROUTES
from invenio_i18n import lazy_gettext as _
from invenio_oauthclient.contrib.openaire_aai import REMOTE_SANDBOX_APP
from invenio_oauthclient.contrib.orcid import ORCIDOAuthSettingsHelper
Expand All @@ -27,6 +27,7 @@ from invenio_records_resources.services.records.queryparser import (
from invenio_oauthclient.views.client import auto_redirect_login

from zenodo_rdm.custom_fields import CUSTOM_FIELDS_UI, CUSTOM_FIELDS, CUSTOM_FIELDS_FACETS, NAMESPACES
from zenodo_rdm.views import frontpage_view_function
from zenodo_rdm.permissions import ZenodoRDMRecordPermissionPolicy

# Flask
Expand All @@ -40,6 +41,7 @@ SECRET_KEY="CHANGE_ME"
# route correct hosts to the application.
APP_ALLOWED_HOSTS = ['0.0.0.0', 'localhost', '127.0.0.1']

APP_RDM_ROUTES["index"] = ("/", frontpage_view_function)

# Flask-SQLAlchemy
# ================
Expand Down
30 changes: 29 additions & 1 deletion site/zenodo_rdm/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,40 @@
# under the terms of the MIT License; see LICENSE file for more details.
"""Additional views."""

from flask import Blueprint
from flask import Blueprint, current_app, g, render_template
from invenio_rdm_records.proxies import current_rdm_records
from invenio_rdm_records.resources.serializers import UIJSONSerializer
from invenio_records_resources.resources.records.utils import search_preference
from marshmallow import ValidationError

from .support.support import ZenodoSupport


#
# Views
#
def frontpage_view_function():
"""Zenodo frontpage view."""
recent_uploads = current_rdm_records.records_service.search(
identity=g.identity,
params={"sort": "newest", "size": 10},
search_preference=search_preference(),
expand=False,
)

records_ui = []

for record in recent_uploads:
record_ui = UIJSONSerializer().dump_obj(record)
records_ui.append(record_ui)

return render_template(
current_app.config["THEME_FRONTPAGE_TEMPLATE"],
show_intro_section=current_app.config["THEME_SHOW_FRONTPAGE_INTRO_SECTION"],
recent_uploads=records_ui,
)


#
# Registration
#
Expand Down
8 changes: 5 additions & 3 deletions templates/semantic-ui/zenodo_rdm/frontpage.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@
# as an Intergovernmental Organization or submit itself to any jurisdiction.
-#}

{% from "invenio_app_rdm/macros/records_list.html" import records_list %}
{% from "zenodo_rdm/macros/recent_uploads_list.html" import recent_uploads_list %}
{%- extends "invenio_app_rdm/frontpage.html" %}

{%- block page_header %}
{%- include "zenodo_rdm/header_frontpage.html" %}
{%- endblock page_header %}

{% block main_column_content %}
{{ records_list(fetch_url=config.ZENODO_FRONTPAGE_RECENT_UPLOADS_QUERY) }}
{% if recent_uploads %}
{{ recent_uploads_list(records=recent_uploads) }}
{% endif %}
{% endblock main_column_content %}

{% block side_column_content %}
Expand Down Expand Up @@ -82,4 +84,4 @@ <h2 class="ui small header">{{ _("Why use Zenodo?") }} </h2>
</ul>
</p>
</section>
{% endblock side_column_content %}
{% endblock side_column_content %}
71 changes: 71 additions & 0 deletions templates/semantic-ui/zenodo_rdm/macros/creators.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{#
# This file is part of Zenodo.
# Copyright (C) 2022 CERN.
#
# Zenodo is free software; you can redistribute it
# and/or modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# Zenodo is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Zenodo; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307, USA.
#
# In applying this license, CERN does not
# waive the privileges and immunities granted to it by virtue of its status
# as an Intergovernmental Organization or submit itself to any jurisdiction.
-#}

{% macro creators(creators=None) %}
{% for creator in creators %}
{% set creator_name = creator.person_or_org.get("name", "No name") if creator.person_or_org %}
{% set ids = creator.person_or_org.get("identifiers", []) if creator.person_or_org %}

<span class="creatibutor-wrap separated">
<a
class="creatibutor-link"
href="/search?q=metadata.creators.person_or_org.name:{{ creator_name }}"
title="{{ creator_name }}: {{_('Search')}}"
>
<span class="creatibutor-name">{{ creator_name }}</span>
</a>

{{ creator_icons(creator_name=creator_name, ids=ids) }}
</span>
{% endfor%}
{% endmacro %}


{% macro creator_icons(creator_name=None, ids=None) %}
{% for id in ids %}
{% if id.scheme == "orcid" %}
{% set link = "https://orcid.org/{identifier}".format(identifier=id.identifier) %}
{% set link_title = _("ORCID profile") %}
{% set icon = "/static/images/orcid.svg" %}

{% elif id.scheme == "ror" %}
{% set link = "https://ror.org/{identifier}".format(identifier=id.identifier) %}
{% set link_title = _("ROR profile") %}
{% set icon = "/static/images/ror-icon.svg" %}

{% elif id.scheme == "gnd" %}
{% set link = "https://d-nb.info/gnd/{identifier}".format(identifier=id.identifier) %}
{% set link_title = _("GND profile") %}
{% set icon = "/static/images/gnd-icon.svg" %}
{% endif %}
<a
class="no-text-decoration mr-0"
href="{{ link }}"
aria-label="{{ creator_name }}: {{ link_title }}"
title="{{ creator_name }}: {{ link_title }}"
>
<img class="inline-id-icon ml-5" src="{{ icon }}" alt="" />
</a>
{% endfor %}
{% endmacro %}
46 changes: 46 additions & 0 deletions templates/semantic-ui/zenodo_rdm/macros/recent_uploads_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{#
# This file is part of Zenodo.
# Copyright (C) 2022 CERN.
#
# Zenodo is free software; you can redistribute it
# and/or modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# Zenodo is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Zenodo; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307, USA.
#
# In applying this license, CERN does not
# waive the privileges and immunities granted to it by virtue of its status
# as an Intergovernmental Organization or submit itself to any jurisdiction.
-#}

{% from "zenodo_rdm/macros/record_item.html" import record_item %}

{% macro recent_uploads_list(title="Recent uploads", records=None) %}
<div id="records-list" data-title="{{ title }}">

<h2 class="ui header">{{ title }}</h2>

<div class="ui container rel-mb-2 ml-0-mobile mr-0-mobile">
<ul class="ui divided link relaxed items pl-0">
{% for record in records %}
{{ record_item(record=record) }}
{% endfor %}
</ul>
</div>

<div class="ui center aligned container">
<a class="ui button" href="/search" aria-label="See more records">
More
</a>
</div>
</div>
{% endmacro %}
Loading

0 comments on commit 4215924

Please sign in to comment.