diff --git a/assets/less/zenodo-rdm/modules/popup.overrides b/assets/less/zenodo-rdm/modules/popup.overrides new file mode 100644 index 00000000..9aaa8614 --- /dev/null +++ b/assets/less/zenodo-rdm/modules/popup.overrides @@ -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; + } + } +} diff --git a/assets/less/zenodo-rdm/modules/popup.variables b/assets/less/zenodo-rdm/modules/popup.variables new file mode 100644 index 00000000..e69de29b diff --git a/assets/less/zenodo-rdm/views/item.overrides b/assets/less/zenodo-rdm/views/item.overrides index 37ef8b39..c62a3640 100644 --- a/assets/less/zenodo-rdm/views/item.overrides +++ b/assets/less/zenodo-rdm/views/item.overrides @@ -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 + } + } + } \ No newline at end of file diff --git a/invenio.cfg b/invenio.cfg index d5074461..78bf1f13 100644 --- a/invenio.cfg +++ b/invenio.cfg @@ -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 @@ -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 @@ -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 # ================ diff --git a/site/zenodo_rdm/views.py b/site/zenodo_rdm/views.py index 00235124..74a0fdea 100644 --- a/site/zenodo_rdm/views.py +++ b/site/zenodo_rdm/views.py @@ -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 # diff --git a/templates/semantic-ui/zenodo_rdm/frontpage.html b/templates/semantic-ui/zenodo_rdm/frontpage.html index 81944afd..cb8536cd 100644 --- a/templates/semantic-ui/zenodo_rdm/frontpage.html +++ b/templates/semantic-ui/zenodo_rdm/frontpage.html @@ -22,7 +22,7 @@ # 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 %} @@ -30,7 +30,9 @@ {%- 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 %} @@ -82,4 +84,4 @@

{{ _("Why use Zenodo?") }}

-{% endblock side_column_content %} +{% endblock side_column_content %} \ No newline at end of file diff --git a/templates/semantic-ui/zenodo_rdm/macros/creators.html b/templates/semantic-ui/zenodo_rdm/macros/creators.html new file mode 100644 index 00000000..095b0f4d --- /dev/null +++ b/templates/semantic-ui/zenodo_rdm/macros/creators.html @@ -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 %} + + + + {{ creator_name }} + + + {{ creator_icons(creator_name=creator_name, ids=ids) }} + + {% 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 %} + + + + {% endfor %} +{% endmacro %} \ No newline at end of file diff --git a/templates/semantic-ui/zenodo_rdm/macros/recent_uploads_list.html b/templates/semantic-ui/zenodo_rdm/macros/recent_uploads_list.html new file mode 100644 index 00000000..9aff1cfc --- /dev/null +++ b/templates/semantic-ui/zenodo_rdm/macros/recent_uploads_list.html @@ -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) %} +
+ +

{{ title }}

+ +
+ +
+ +
+ + More + +
+
+{% endmacro %} \ No newline at end of file diff --git a/templates/semantic-ui/zenodo_rdm/macros/record_item.html b/templates/semantic-ui/zenodo_rdm/macros/record_item.html new file mode 100644 index 00000000..2f100189 --- /dev/null +++ b/templates/semantic-ui/zenodo_rdm/macros/record_item.html @@ -0,0 +1,135 @@ +{# +# 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/creators.html" import creators %} + +{% macro record_item(record=None) %} +
  • +
    + + {# Top labels #} +
    +
    + {{ record.ui.publication_date_l10n_long }} ({{ record.ui.version }}) +
    +
    + {{ record.ui.resource_type.title_l10n }} +
    + + {% set access_status_id = record.ui.access_status.get("id", "open") %} + {% set access_status = record.ui.access_status.get("title_l10n", "Open") %} + {% set access_status_icon = record.ui.access_status.get("icon", "unlock") %} + +
    + + {{ access_status }} +
    +
    + + {# Title #} + + + {# Creators #} +
    + {% set creators_list = record.ui.creators.creators %} + {% set creators_sliced = creators_list[:3] %} + + {{ creators(creators=creators_sliced) }} +
    + + {# Description #} +

    + {% set description = record.ui.get("description_stripped", "No description") %} + + {{ description | truncate(length=350, end='...') }} +

    + +
    +
    + {# Publishing details #} + {% set created_date = record.ui.created_date_l10n_long %} + {% set publishing_journal = record.ui.publishing_information.get("journal") if record.ui.publishing_information %} + + + {% if created_date %} + {{ _("Uploaded on:")}} {{ created_date }} + {% endif %} + + {% if publishing_journal %} + {{ _("Published in:") }} {{ publishing_journal }} + {% endif %} + + + {# Versions info desktop/tablet #} + {% if record.versions.index > 1 %} + {% set num_versions = record.versions.index %} + {% set text_content = _("more versions exist for this record") %} + {% if num_versions == 2 %} + {% set text_content = _("more version exist for this record") %} + {% endif %} + + +

    {{ record.versions.index - 1 }} {{ text_content }}

    +
    + {% endif %} + + {# Statistics #} + {% set unique_downloads = record.stats.all_versions.unique_downloads %} + {% set unique_views = record.stats.all_versions.unique_views %} + + + {% if unique_views is defined %} +
    + + {{ unique_views }} + +
    + {% endif %} + + {% if unique_downloads is defined %} +
    + + {{ unique_downloads}} + +
    + {% endif %} +
    +
    + + {# Versions info mobile #} + {% if record.versions.index > 1 %} + +

    {{ record.versions.index - 1 }} {{ text_content }}

    +
    + {% endif %} +
    +
    +
  • +{% endmacro %} \ No newline at end of file