Skip to content

Commit 3fc469d

Browse files
committed
clc: add clc sync message
1 parent 6f1a5d0 commit 3fc469d

File tree

10 files changed

+92
-71
lines changed

10 files changed

+92
-71
lines changed

assets/js/components/record_details/clc_sync.js

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ export class CLCSync extends Component {
2121
clcSyncRecord: null,
2222
loading: false,
2323
error: null,
24-
synced: null,
2524
autoSync: null,
2625
showSuccess: false,
2726
};
@@ -30,6 +29,7 @@ export class CLCSync extends Component {
3029
get shouldRenderComponent() {
3130
const { record, permissions } = this.props;
3231
const recordManagementAppDiv = document.getElementById("recordManagement");
32+
3333
const allowedResourceTypes = JSON.parse(
3434
recordManagementAppDiv.dataset.allowedResourceTypes
3535
);
@@ -41,36 +41,21 @@ export class CLCSync extends Component {
4141
return isTypeAllowed && permissions.can_moderate;
4242
}
4343

44-
fetchSyncRecord = async () => {
45-
const { record } = this.props;
46-
try {
47-
this.cancellableRequest = withCancel(
48-
http.get(`/api/clc/${record.parent.id}`)
49-
);
50-
const response = await this.cancellableRequest.promise;
51-
const data = response.data;
52-
if (data) {
53-
this.setState({
54-
synced: true,
55-
clcSyncRecord: data,
56-
autoSync: data.auto_sync,
57-
});
58-
}
59-
} catch (error) {
60-
this.setState({ synced: false });
61-
}
62-
};
63-
6444
componentWillUnmount() {
6545
if (this.cancellableRequest) {
6646
this.cancellableRequest.cancel();
6747
}
6848
}
6949

7050
componentDidMount() {
71-
if (this.shouldRenderComponent) {
72-
this.fetchSyncRecord();
73-
}
51+
const recordManagementAppDiv = document.getElementById("recordManagement");
52+
const clcSyncRecord = JSON.parse(
53+
recordManagementAppDiv.dataset.clcSyncEntry
54+
);
55+
this.setState({
56+
clcSyncRecord: clcSyncRecord,
57+
autoSync: clcSyncRecord.auto_sync,
58+
});
7459
}
7560

7661
syncWithCLC = async (payload, existingId = null) => {
@@ -121,7 +106,6 @@ export class CLCSync extends Component {
121106
this.setState({
122107
autoSync: clcRecordData.auto_sync,
123108
clcSyncRecord: clcRecordData,
124-
synced: true,
125109
});
126110
this.setSuccessMessage();
127111
} catch (error) {
@@ -149,7 +133,6 @@ export class CLCSync extends Component {
149133
this.setState({
150134
autoSync: clcRecordData.auto_sync,
151135
clcSyncRecord: clcRecordData,
152-
synced: newAutoSync,
153136
});
154137
if (newAutoSync) {
155138
this.setSuccessMessage();
@@ -183,8 +166,7 @@ export class CLCSync extends Component {
183166
};
184167

185168
render() {
186-
const { error, loading, synced, autoSync, clcSyncRecord } = this.state;
187-
const { record, permissions } = this.props;
169+
const { error, loading, autoSync, clcSyncRecord } = this.state;
188170

189171
if (!this.shouldRenderComponent) {
190172
return null;
@@ -221,7 +203,7 @@ export class CLCSync extends Component {
221203
icon
222204
size="tiny"
223205
loading={loading}
224-
disabled={loading || !synced}
206+
disabled={loading || !autoSync}
225207
onClick={this.handleClick}
226208
labelPosition="left"
227209
>

invenio.cfg

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ from cds_rdm.components import SubjectsValidationComponent
5959
from cds_rdm.pids import validate_optional_doi_transitions
6060
from cds_rdm.views import frontpage_view_function
6161

62+
from invenio_app_rdm.config import APP_RDM_DETAIL_SIDE_BAR_TEMPLATES as DEFAULT_SIDE_BAR_TEMPLATES
63+
6264

6365
def _(x): # needed to avoid start time failure with lazy strings
6466
return x
@@ -509,3 +511,12 @@ _APP_RDM_STATS_EVENTS["record-view"]["params"]["suffix"] = "%Y"
509511
# Override the index_interval to be year
510512
_APP_RDM_STATS_AGGREGATIONS["file-download-agg"]["params"]["index_interval"] = "year"
511513
_APP_RDM_STATS_AGGREGATIONS["record-view-agg"]["params"]["index_interval"] = "year"
514+
515+
516+
APP_RDM_RECORD_LANDING_PAGE_TEMPLATE = "cds_rdm/records/detail.html"
517+
518+
# Replace the manage menu template
519+
APP_RDM_DETAIL_SIDE_BAR_TEMPLATES = [
520+
"cds_rdm/records/manage_menu.html" if template == "invenio_app_rdm/records/details/side_bar/manage_menu.html" else template
521+
for template in DEFAULT_SIDE_BAR_TEMPLATES
522+
]

site/cds_rdm/clc_sync/services/service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def _clc_import(self, data):
4646

4747
if not record_data or not auto_sync:
4848
return # Skip
49-
resource = record_data.get("metadata", {}).get("resource_type", {}).get("id")
49+
resource = record_data["metadata"]["resource_type"]["id"]
5050
if not any(
5151
resource.startswith(allowed)
5252
for allowed in current_app.config["CLC_SYNC_ALLOWED_RESOURCE_TYPES"]

site/cds_rdm/clc_sync/services/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
def clc_import(record_data):
1414
"""Import a record to CLC."""
15-
clc_url = current_app.config.get("CLC_URL_SYNC")
16-
clc_token = current_app.config.get("CDS_ILS_IMPORTER_API_KEY")
15+
clc_url = current_app.config["CLC_URL_SYNC"]
16+
clc_token = current_app.config["CDS_ILS_IMPORTER_API_KEY"]
1717
clc_payload = {
1818
"data": record_data,
1919
"mode": "IMPORT",

site/cds_rdm/config.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
},
2323
},
2424
}
25-
2625
"""Facets/aggregations for CLC user sync results."""
2726

2827
CLC_SYNC_DEFAULT_QUEUE = None

site/cds_rdm/ext.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from cds_rdm.clc_sync.resources.resource import CLCSyncResource
1111
from cds_rdm.clc_sync.services.config import CLCSyncServiceConfig
1212
from cds_rdm.clc_sync.services.service import CLCSyncService
13+
from cds_rdm.utils import get_clc_sync_entry
1314

1415
from . import config
1516

@@ -32,6 +33,7 @@ def init_app(self, app):
3233
"""Flask application initialization."""
3334
self.init_services(app)
3435
self.init_resources(app)
36+
app.jinja_env.globals["get_clc_sync_entry"] = get_clc_sync_entry
3537
return app
3638

3739
def init_services(self, app):
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{#
2+
Copyright (C) 2025 CERN.
3+
4+
CDS-RDM is free software; you can redistribute it and/or modify it
5+
under the terms of the MIT License; see LICENSE file for more details.
6+
#}
7+
8+
{%- extends "invenio_app_rdm/records/detail.html" %}
9+
10+
{%- set clc_sync_entry = get_clc_sync_entry(record) %}
11+
12+
{%- block after_record_content -%}
13+
{# After record content hook #}
14+
{% if clc_sync_entry %}
15+
<div class="ui info message">
16+
<div class="description">
17+
{{ _("To loan this literature, see Library holdings in the") }}
18+
<a href="{{ clc_sync_entry.clc_url }}" target="_blank">
19+
{{ _("CERN Library Catalogue") }}
20+
</a>
21+
{{ _("website.") }}
22+
</div>
23+
</div>
24+
{% endif %}
25+
{%- endblock after_record_content -%}
26+
27+
{%- block record_manage_data_attributes -%}
28+
{{ super() }}
29+
data-allowed-resource-types='{{ config.CLC_SYNC_ALLOWED_RESOURCE_TYPES | tojson }}'
30+
data-clc-sync-entry='{{ clc_sync_entry | tojson | safe }}'
31+
{%- endblock record_manage_data_attributes -%}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{#
2+
Copyright (C) 2022-2024 CERN.
3+
4+
Invenio RDM Records is free software; you can redistribute it and/or modify
5+
it under the terms of the MIT License; see LICENSE file for more details.
6+
#}
7+
8+
{% extends "invenio_app_rdm/records/details/side_bar/manage_menu.html" %}
9+
10+
{%- block record_manage_data_attributes -%}
11+
{{ super() }}
12+
data-allowed-resource-types='{{ config.CLC_SYNC_ALLOWED_RESOURCE_TYPES | tojson }}'
13+
data-clc-sync-entry='{{ clc_sync_entry | tojson | safe }}'
14+
{%- endblock record_manage_data_attributes -%}

site/cds_rdm/utils.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
from invenio_access.permissions import system_identity
1414
from invenio_records_resources.services.errors import ValidationError
1515

16+
from cds_rdm.clc_sync.proxies import current_clc_sync_service
17+
1618

1719
class NamesUtils:
1820
"""Names utilities."""
@@ -284,3 +286,21 @@ def merge(self, name_source, name_dest):
284286
)
285287
# Update the name_dest value
286288
self.service.update(system_identity, name_dest.get("id"), name_dest)
289+
290+
291+
def get_clc_sync_entry(record):
292+
"""Get the CLC sync entry for the record.
293+
294+
:param record: The record to get the CLC sync entry for.
295+
:return: The CLC sync entry.
296+
"""
297+
try:
298+
clc_sync_entry = current_clc_sync_service.read(
299+
system_identity,
300+
record.get("parent", {}).get(
301+
"id",
302+
),
303+
).to_dict()
304+
return clc_sync_entry
305+
except Exception as e:
306+
return None

templates/semantic-ui/invenio_app_rdm/records/details/side_bar/manage_menu.html

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)