Skip to content

Commit

Permalink
fix(JS/search-gui): avoid String.prototype.startsWith
Browse files Browse the repository at this point in the history
  • Loading branch information
drfho committed Jun 21, 2024
1 parent 3e06d55 commit 8c0e20b
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class elasticsearch_page:
package = "com.zms.catalog.elasticsearch"

# Revision
revision = "1.5.0"
revision = "1.5.1"

# Type
type = "ZMSDocument"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class opensearch_page:
package = "com.zms.catalog.opensearch"

# Revision
revision = "1.8.6"
revision = "1.8.7"

# Type
type = "ZMSDocument"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,23 @@ $(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'],
'href':source['index_html'],
'title':title,
'snippet':snippet,
'index_name':index_name,
'score':score
'score':score,
'lang':lang
};
if (typeof highlight !== 'undefined') {
if (typeof highlight['title'] !== 'undefined') {
Expand Down Expand Up @@ -180,7 +185,8 @@ $(function() {
'title':title,
'snippet':Adresse,
'index_name':index_name,
'score':score
'score':score,
'lang':'*'
};
}
res_processed.hits.push(hit)
Expand All @@ -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 },
Expand All @@ -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 += `<dt class="${k}">${k}</dt>`;
let lang_key = `opensearch_page.UNITEL_KEY_${k}`;
let lang_str = $ZMI.getLangStr( lang_key, lang )==undefined ? k : $ZMI.getLangStr( lang_key, lang );
s += `<dt class="${lang} ${k}">${lang_str}</dt>`;
if (k=='Institution' && URL) {
s += `<dd class="${k}"><a href="${URL}">${d[k]}</a></dd>`;
} else if (k=='WWWInstitution') {
Expand Down
4 changes: 3 additions & 1 deletion Products/zms/zpt/versionmanager/zmi_version_object_state.zpt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
</tal:block
><tal:block tal:condition="python:not here.getAutocommit() and not request.get('ZMS_VERSION')"
><tal:block tal:define="wfStates python:here.getWfStates(request); work_uid python:here.attr('work_uid'); work_dt python:here.attr('work_dt'); objStates python:here.filteredObjStates(request)"
><tal:block tal:define="wfStates python:here.getWfStates(request);
work_uid python:here.attr('work_uid'); work_dt python:here.attr('work_dt');
objStates python:here.filteredObjStates(request)"
><tal:block tal:condition="python:work_uid and work_dt"
tal:repeat="wfState wfStates"
><span class="zmi-state"
Expand Down

0 comments on commit 8c0e20b

Please sign in to comment.