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

feat: babeltheque #3632

Merged
merged 1 commit into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion rero_ils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,8 @@ def _(x):
'https://www.google-analytics.com',
'https://services.test.rero.ch',
'https://services.rero.ch',
'https://cdn.jsdelivr.net'
'https://cdn.jsdelivr.net',
'https://www.babelio.com'
]
},
'content_security_policy_report_uri': None,
Expand Down Expand Up @@ -3943,3 +3944,7 @@ def search_type(field):
}
},
]

# Babeltheque Configuration
# =========================
RERO_ILS_APP_BABELTHEQUE_ENABLED_VIEWS = []
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{# -*- coding: utf-8 -*-

RERO ILS
Copyright (C) 2019-2023 RERO
Copyright (C) 2019-2024 RERO
Copyright (C) 2019-2023 UCLouvain

This program is free software: you can redistribute it and/or modify
Expand All @@ -20,9 +20,14 @@
{%- extends 'rero_ils/page.html' %}
{% from 'rero_ils/macros/macro.html' import div, dict_values, div_list, dl, dl_row, dl_dict, dl_list, div_json %}

{% set isbn = record|get_first_isbn %}

{%- block css %}
{{ super() }}
{{ node_assets('@rero/rero-ils-ui/dist/public-holdings-items', ['styles.*css'], 'css') }}
{% if viewcode | babeltheque_enabled_view %}
{{ webpack['babeltheque.css'] }}
{% endif %}
{%- endblock css %}

{%- block body %}
Expand Down Expand Up @@ -278,6 +283,15 @@ <h3>
{% endif %}
</div>
</div>
{% if viewcode | babeltheque_enabled_view and isbn is not none %}
<!-- BABELTHEQUE -->
<input id="BW_id_isbn" class="d-none" value="{{ isbn }}"></input>
<!-- Hidden on XS and SM screens -->
<div class="babelio-block d-none d-md-flex d-lg-flex d-xl-flex d-xxl-flex">
<div id="BW_suggestions"></div>
<div id="BW_etiquettes"></div>
</div>
{% endif %}

{%- block record_body %}
<section>
Expand All @@ -293,6 +307,15 @@ <h3>
<i class="fa fa-bars"></i> {{ _('Description') }}
</a>
</li>
{% if viewcode | babeltheque_enabled_view and isbn is not none %}
<li class="nav-item">
<a class="nav-link" href="#documents-more-infos" data-toggle="tab"
id="documents-more-infos-tab" title="Babelio" role="tab"
aria-controls="documents-description" aria-selected="false">
<i class="fa fa-bars"></i> Babelio
</a>
</li>
{% endif %}
</ul>
</nav>
</header>
Expand Down Expand Up @@ -322,6 +345,15 @@ <h3>
<i class="fa fa-bars"></i> {{ _('Description') }}
</a>
</li>
{% if viewcode | babeltheque_enabled_view and isbn is not none %}
<li class="nav-item">
<a class="nav-link" href="#documents-more-infos" data-toggle="tab"
id="documents-more-infos-tab" title="Babelio" role="tab"
aria-controls="documents-more-infos" aria-selected="false">
<i class="fa fa-bars"></i> Babelio
</a>
</li>
{% endif %}
</ul>
</nav>
</header>
Expand All @@ -344,6 +376,25 @@ <h3>
<section class="tab-pane container" id="documents-description" role="tabpanel" aria-labelledby="documents-description-tab">
{% include('rero_ils/_documents_description.html') %}
</section>
{% if viewcode | babeltheque_enabled_view %}
<section class="tab-pane container" id="documents-more-infos" role="tabpanel" aria-labelledby="documents-more-infos-tab">
<!-- BABELTHEQUE -->
<div class="babelio-block mt-3">
<div>
<div id="BW_critiques"></div>
<div id="BW_notes">{{ _('No additionnal information yet.') }}</div>
</div>
<div id="BW_citations"></div>
<div id="BW_critiques_pro"></div>
<div id="BW_prix_litt"></div>
</div>
<div id="BW_bio_auteur"></div>
<div class="babelio-block mt-3">
<div id="BW_videos"></div>
<div id="BW_podcasts"></div>
</div>
</section>
{% endif %}
</article>
{% endif %}
</article>
Expand All @@ -370,6 +421,9 @@ <h5 class="d-inline-block">{{ _('Export Formats') }}:</h5>
{%- endblock body %}

{%- block javascript %}
{{ super() }}
{{ node_assets('@rero/rero-ils-ui/dist/public-holdings-items', tags='defer') }}
{{ super() }}
{{ node_assets('@rero/rero-ils-ui/dist/public-holdings-items', tags='defer') }}
{% if viewcode | babeltheque_enabled_view and isbn is not none %}
<script type="text/javascript" src="https://www.babelio.com/bw_330.js"></script>
{% endif %}
{% endblock javascript %}
22 changes: 21 additions & 1 deletion rero_ils/modules/documents/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
#
# RERO ILS
# Copyright (C) 2019-2023 RERO
# Copyright (C) 2019-2024 RERO
# Copyright (C) 2019-2023 UCLouvain
#
# This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -118,6 +118,26 @@ def doc_item_view_method(pid, record, template=None, **kwargs):
)


@blueprint.app_template_filter()
def babeltheque_enabled_view(view):
"""Check if the view is activated for babeltheque."""
enabled_views = current_app.config.get(
'RERO_ILS_APP_BABELTHEQUE_ENABLED_VIEWS', [])
return view in enabled_views


@blueprint.app_template_filter()
def get_first_isbn(record):
"""Get first isbn result."""
# ISBN
isbns = [
identified_by.get('value')
for identified_by in record.get('identifiedBy', [])
if identified_by.get('type') == 'bf:Isbn'
]
return isbns[0] if isbns else None


@blueprint.app_template_filter()
def note_general(notes):
"""Preprocess notes to extract only general type."""
Expand Down
131 changes: 131 additions & 0 deletions rero_ils/theme/assets/scss/rero_ils/babeltheque.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/*

RERO ILS
Copyright (C) 2019-2024 RERO

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, version 3 of the License.

This program 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 Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.

*/

#BW_suggestions,
#BW_notes,
#BW_etiquettes,
#BW_prix_litt,
#BW_critiques,
#BW_critiques_pro,
#BW_citations,
#BW_bio_auteur,
#BW_videos,
#BW_podcasts {
margin-top: 16px;
padding: 0 !important;
}

#BW_notes img {
margin-bottom: 6px;
}

#BW_etiquettes h2,
.BW_critiques_opac_add,
.BW_citations_opac_add {
display: none;
}

#BW_ulEti {
display: flex;
gap: 6px;
align-items: center;
justify-content: center;
flex-wrap: wrap;
padding-inline-start: 0;
max-width: 400px !important;
}

#BW_ulEti ol {
padding-inline-start: 0;
text-transform: lowercase;
}

#BW_ulEti a.tag_s0 {
font-weight: 120;
font-size: 0.8em;
}
#BW_ulEti a.tag_s1 {
font-weight: 150;
font-size: 0.9em;
}
#BW_ulEti a.tag_s2 {
font-weight: 180;
font-size: 1.0em;
}
#BW_ulEti a.tag_s3 {
font-weight: 200;
font-size: 1.2em;
}
#BW_ulEti a.tag_s4 {
font-weight: 220;
font-size: 1.4em;
}
#BW_ulEti a.tag_s5 {
font-weight: 230;
font-size: 1.5em;
}
#BW_ulEti a.tag_s6 {
font-weight: 320;
font-size: 1.6em;
}
#BW_ulEti a.tag_s7 {
font-weight: 350;
font-size: 1.7em;
}
#BW_ulEti a.tag_s8 {
font-weight: 400;
font-size: 1.8em;
}

.babelio-block,
.bw_list_recos {
display: flex;
flex-wrap: wrap;
gap: 20px;
}

.babelio-block div,
.bw_list_recos div {
flex-grow: 1;
}

.babelio-block div:empty,
.BW_critiques_OPAC {
display: none;
}

#BW_prix_litt ul {
list-style: none;
padding-inline-start: 0;
flex-wrap: wrap;
}

#BW_bio_titre,
.bw_h2 {
font-size: 1.3em;
}

.BW_couv_suggestions {
max-height: 140px;
max-width: 100px;
}

.bw_boxclose {
color: white !important;
}
5 changes: 3 additions & 2 deletions rero_ils/theme/webpack.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
#
# RERO ILS
# Copyright (C) 2019-2022 RERO
# Copyright (C) 2019-2024 RERO
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
Expand Down Expand Up @@ -30,7 +30,8 @@
'assets',
entry={
'global': './scss/rero_ils/styles.scss',
'reroils_public': './js/reroils/public.js'
'reroils_public': './js/reroils/public.js',
'babeltheque': './scss/rero_ils/babeltheque.scss'
},
dependencies={
'popper.js': '1.16.1',
Expand Down
34 changes: 30 additions & 4 deletions tests/ui/documents/test_documents_filter.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
#
# RERO ILS
# Copyright (C) 2019 RERO
# Copyright (C) 2019-2024 RERO
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
Expand All @@ -16,9 +16,13 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

"""Document filters tests."""
from rero_ils.modules.documents.views import cartographic_attributes, \
contribution_format, doc_entity_label, identified_by, main_title_text, \
note_general, notes_except_general, part_of_format, provision_activity, \

import mock

from rero_ils.modules.documents.views import babeltheque_enabled_view, \
cartographic_attributes, contribution_format, doc_entity_label, \
get_first_isbn, identified_by, main_title_text, note_general, \
notes_except_general, part_of_format, provision_activity, \
provision_activity_not_publication, provision_activity_original_date, \
provision_activity_publication, title_variants, work_access_point
from rero_ils.modules.entities.models import EntityType
Expand Down Expand Up @@ -629,3 +633,25 @@ def test_doc_entity_label_filter(entity_person, local_entity_person):
assert 'textual' == entity_type
assert 'subject topic' == value
assert 'subject topic - Sub 1 - Sub 2' == label


def test_babeltheque_enabled_view():
"""Check enabled view for babeltheque."""
class CurrentApp:
"""Current app mock."""
config = {'RERO_ILS_APP_BABELTHEQUE_ENABLED_VIEWS': ['global']}
with mock.patch(
'rero_ils.modules.documents.views.current_app', CurrentApp):
assert babeltheque_enabled_view('global')
assert not babeltheque_enabled_view('foo')


def test_get_first_isbn():
"""Get the first isbn on identifiedBy field."""
record = {'identifiedBy': [
{'type': 'bf:Isbn', 'value': '9782501053006'},
{'type': 'bf:Isbn', 'value': '9782501033671'}
]}
assert '9782501053006' == get_first_isbn(record)
record = {'identifiedBy': []}
assert None is get_first_isbn(record)
Loading