From 8c0e20b2bf4f41e62daa1a28d4707bef623c818d Mon Sep 17 00:00:00 2001 From: drfho Date: Fri, 21 Jun 2024 13:32:01 +0200 Subject: [PATCH] fix(JS/search-gui): avoid String.prototype.startsWith Ref: https://github.com/idasm-unibe-ch/unibe-cms-opensearch/issues/77 --- .../elasticsearch_page/__init__.py | 2 +- .../elasticsearch_page/script.js | 14 +++++++---- .../opensearch_page/__init__.py | 2 +- .../opensearch_page/script.js | 23 +++++++++++++------ .../zmi_version_object_state.zpt | 4 +++- 5 files changed, 31 insertions(+), 14 deletions(-) diff --git a/Products/zms/conf/metaobj_manager/com.zms.catalog.elasticsearch/elasticsearch_page/__init__.py b/Products/zms/conf/metaobj_manager/com.zms.catalog.elasticsearch/elasticsearch_page/__init__.py index 5f059a2b9..8a9068ec2 100644 --- a/Products/zms/conf/metaobj_manager/com.zms.catalog.elasticsearch/elasticsearch_page/__init__.py +++ b/Products/zms/conf/metaobj_manager/com.zms.catalog.elasticsearch/elasticsearch_page/__init__.py @@ -32,7 +32,7 @@ class elasticsearch_page: package = "com.zms.catalog.elasticsearch" # Revision - revision = "1.5.0" + revision = "1.5.1" # Type type = "ZMSDocument" diff --git a/Products/zms/conf/metaobj_manager/com.zms.catalog.elasticsearch/elasticsearch_page/script.js b/Products/zms/conf/metaobj_manager/com.zms.catalog.elasticsearch/elasticsearch_page/script.js index d08b1bd53..5ef56a25d 100644 --- a/Products/zms/conf/metaobj_manager/com.zms.catalog.elasticsearch/elasticsearch_page/script.js +++ b/Products/zms/conf/metaobj_manager/com.zms.catalog.elasticsearch/elasticsearch_page/script.js @@ -97,16 +97,22 @@ $(function() { let index_name = x['_index']; let source = x['_source']; let highlight = x['highlight']; - let body = source['standard_html']; + let lang = source['lang']; let title = source['title']; - // Remove repeating title string from beginning of snippet - let snippet = body.startsWith(title) ? body.substr(title.length).trim() : body; + let snippet = source['attr_dc_description']; + if (!snippet) { + snippet = source['standard_html']; + // Remove repeating title string from beginning of snippet + snippet = snippet ? ( snippet.indexOf(title) === 0 ? snippet.substr(title.length).trim() : snippet ) : snippet; + }; var hit = { 'path':source['uid'], 'href':source['index_html'], 'title':title, 'snippet':snippet, - 'index_name':index_name + 'index_name':index_name, + 'score':score, + 'lang':lang }; if (typeof highlight !== 'undefined') { if (typeof highlight['title'] !== 'undefined') { diff --git a/Products/zms/conf/metaobj_manager/com.zms.catalog.opensearch/opensearch_page/__init__.py b/Products/zms/conf/metaobj_manager/com.zms.catalog.opensearch/opensearch_page/__init__.py index 9b2948d55..997aed7cb 100644 --- a/Products/zms/conf/metaobj_manager/com.zms.catalog.opensearch/opensearch_page/__init__.py +++ b/Products/zms/conf/metaobj_manager/com.zms.catalog.opensearch/opensearch_page/__init__.py @@ -69,7 +69,7 @@ class opensearch_page: package = "com.zms.catalog.opensearch" # Revision - revision = "1.8.6" + revision = "1.8.7" # Type type = "ZMSDocument" diff --git a/Products/zms/conf/metaobj_manager/com.zms.catalog.opensearch/opensearch_page/script.js b/Products/zms/conf/metaobj_manager/com.zms.catalog.opensearch/opensearch_page/script.js index 8c5c8d497..8cf22a3af 100644 --- a/Products/zms/conf/metaobj_manager/com.zms.catalog.opensearch/opensearch_page/script.js +++ b/Products/zms/conf/metaobj_manager/com.zms.catalog.opensearch/opensearch_page/script.js @@ -106,10 +106,14 @@ $(function() { let score = x['_score']; // UNIBE if ( index_name != 'unitel' ) { - let body = source['standard_html']; + let lang = source['lang']; let title = source['seotitle_tag'] ? source['seotitle_tag'] : source['title']; - // Remove repeating title string from beginning of snippet - let snippet = source['seometa_tag'] ? source['seometa_tag'] : ( body.startsWith(title) ? body.substr(title.length).trim() : body ); + let snippet = source['seometa_tag'] ? source['seometa_tag'] : source['attr_dc_description']; + if (!snippet) { + snippet = source['standard_html']; + // Remove repeating title string from beginning of snippet + snippet = snippet ? ( snippet.indexOf(title) === 0 ? snippet.substr(title.length).trim() : snippet ) : snippet; + }; let highlight = x['highlight']; var hit = { 'path':source['uid'], @@ -117,7 +121,8 @@ $(function() { 'title':title, 'snippet':snippet, 'index_name':index_name, - 'score':score + 'score':score, + 'lang':lang }; if (typeof highlight !== 'undefined') { if (typeof highlight['title'] !== 'undefined') { @@ -180,7 +185,8 @@ $(function() { 'title':title, 'snippet':Adresse, 'index_name':index_name, - 'score':score + 'score':score, + 'lang':'*' }; } res_processed.hits.push(hit) @@ -204,7 +210,7 @@ $(function() { } const show_breadcrumbs = (el) => { - const lang = $('#lang').attr('value'); + const lang = el.dataset.lang!='undefined'? el.dataset.lang : $('#lang').attr('value'); if ( el.dataset.id.startsWith('uid') ) { $.get(url=`${root_url}/opensearch_breadcrumbs_obj_path`, data={ 'id' : el.dataset.id, 'lang' : lang }, @@ -216,10 +222,13 @@ $(function() { } const stringify_address = (d,URL) => { + const lang = $('#lang').attr('value'); let s = ''; Object.keys(d).forEach(k => { if (d[k]) { - s += `
${k}
`; + let lang_key = `opensearch_page.UNITEL_KEY_${k}`; + let lang_str = $ZMI.getLangStr( lang_key, lang )==undefined ? k : $ZMI.getLangStr( lang_key, lang ); + s += `
${lang_str}
`; if (k=='Institution' && URL) { s += `
${d[k]}
`; } else if (k=='WWWInstitution') { diff --git a/Products/zms/zpt/versionmanager/zmi_version_object_state.zpt b/Products/zms/zpt/versionmanager/zmi_version_object_state.zpt index 200913e52..7f58c904e 100644 --- a/Products/zms/zpt/versionmanager/zmi_version_object_state.zpt +++ b/Products/zms/zpt/versionmanager/zmi_version_object_state.zpt @@ -44,7 +44,9 @@ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-