From d88fc5cdb22d54383771383cb7d889a4ace04b53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Garc=C3=ADa?= Date: Thu, 7 Sep 2023 12:03:18 +0200 Subject: [PATCH] Metadata editor / link to remote dataset improvements: - Improve the title extraction For HTML links, to support title elements with attributes. - Allow to define a custom title for the remote dataset link --- .../edit/onlinesrc/OnlineSrcDirective.js | 26 +++++++++++++++---- .../edit/onlinesrc/partials/addOnlinesrc.html | 3 ++- .../edit/onlinesrc/partials/linkToMd.html | 2 +- .../partials/remote-record-selector.html | 11 +++++--- .../resources/catalog/locales/en-editor.json | 3 ++- 5 files changed, 34 insertions(+), 11 deletions(-) diff --git a/web-ui/src/main/resources/catalog/components/edit/onlinesrc/OnlineSrcDirective.js b/web-ui/src/main/resources/catalog/components/edit/onlinesrc/OnlineSrcDirective.js index 6817d94a0aa..4f16a40a6d2 100644 --- a/web-ui/src/main/resources/catalog/components/edit/onlinesrc/OnlineSrcDirective.js +++ b/web-ui/src/main/resources/catalog/components/edit/onlinesrc/OnlineSrcDirective.js @@ -270,14 +270,12 @@ // No UUID can be easily extracted. try { scope.remoteRecord.title = doc.replace( - /(.|[\r\n])*(.*)<\/title>(.|[\r\n])*/, - "$2" + /(.|[\r\n])*<title(.*)>(.*)<\/title>(.|[\r\n])*/, + "$3" ); + scope.remoteRecord.uuid = scope.remoteRecord.remoteUrl; - if (scope.remoteRecord.title === "") { - return false; - } // Looking for schema.org tags or json+ld format could also be an option. } catch (e) { console.warn(e); @@ -1939,6 +1937,24 @@ scope.searchObj.params.any = scope.searchObj.any; }; + /** + * Checks if there are selected records and the selected records have a title. + * + * @param selectRecords + * @returns {boolean} + */ + scope.canEnableLinkButton = function (selectRecords) { + if (selectRecords.length < 1) return false; + + // Check if the metadata titles are defined + for (var i = 0; i < selectRecords.length; i++) { + if (!selectRecords[i].title && !selectRecords[i].resourceTitle) + return false; + } + + return true; + }; + /** * Register a method on popup open to reset * the search form and trigger a search. diff --git a/web-ui/src/main/resources/catalog/components/edit/onlinesrc/partials/addOnlinesrc.html b/web-ui/src/main/resources/catalog/components/edit/onlinesrc/partials/addOnlinesrc.html index 7b84fd16691..405682e079b 100644 --- a/web-ui/src/main/resources/catalog/components/edit/onlinesrc/partials/addOnlinesrc.html +++ b/web-ui/src/main/resources/catalog/components/edit/onlinesrc/partials/addOnlinesrc.html @@ -395,7 +395,8 @@ /> </div> </div> - <div class="col-sm-9 col-xs-9 " + <div + class="col-sm-9 col-xs-9" data-ng-if="params.linkType.fields.desc.directive === 'gn-multientry-combiner-online-resources-description'" > <div diff --git a/web-ui/src/main/resources/catalog/components/edit/onlinesrc/partials/linkToMd.html b/web-ui/src/main/resources/catalog/components/edit/onlinesrc/partials/linkToMd.html index 62d98906c18..3fbc27150ff 100644 --- a/web-ui/src/main/resources/catalog/components/edit/onlinesrc/partials/linkToMd.html +++ b/web-ui/src/main/resources/catalog/components/edit/onlinesrc/partials/linkToMd.html @@ -35,7 +35,7 @@ type="button" class="btn navbar-btn btn-success" data-gn-click-and-spin="gnOnlinesrc.linkToMd(mode, selectRecords[0], popupid)" - ng-disabled="(selectRecords.length < 1)" + ng-disabled="!canEnableLinkButton(selectRecords)" > <i class="fa gn-icon-{{mode}}" /> <i class="icon-external-link"></i>  {{btn.label}} diff --git a/web-ui/src/main/resources/catalog/components/edit/onlinesrc/partials/remote-record-selector.html b/web-ui/src/main/resources/catalog/components/edit/onlinesrc/partials/remote-record-selector.html index ed54f9ee990..de05ed00e16 100644 --- a/web-ui/src/main/resources/catalog/components/edit/onlinesrc/partials/remote-record-selector.html +++ b/web-ui/src/main/resources/catalog/components/edit/onlinesrc/partials/remote-record-selector.html @@ -1,4 +1,4 @@ -<div data-ng-if="allowRemoteRecordLink"> +<div data-ng-if="allowRemoteRecordLink" xmlns="http://www.w3.org/1999/html"> <form class="form-horizontal"> <div class="form-group"> <label for="gnRemoteRecordUrl" class="control-label col-sm-2" data-translate="" @@ -28,13 +28,18 @@ </div> </form> - <div class="list-group" data-ng-if="remoteRecord.title"> + <div class="list-group" data-ng-if="remoteRecord.uuid"> <li class="list-group-item" data-ng-click="updateSelection();triggerSearch();" data-ng-class="{'active' : selectionList[0].uuid === remoteRecord.uuid}" > - {{remoteRecord.title}} ({{remoteRecord.uuid}}) + <input + type="text" + class="form-control" + data-ng-model="remoteRecord.title" + placeholder="{{'remoteAssociatedMetadataTitlePlaceholder' | translate}}" + /> </li> </div> diff --git a/web-ui/src/main/resources/catalog/locales/en-editor.json b/web-ui/src/main/resources/catalog/locales/en-editor.json index 827c0fb3f6e..9870ce39cf6 100644 --- a/web-ui/src/main/resources/catalog/locales/en-editor.json +++ b/web-ui/src/main/resources/catalog/locales/en-editor.json @@ -428,5 +428,6 @@ "confirmCancelEdit": "Do you want to cancel all changes and close the editor?", "allowEditGroupMembers": "Allow group editors to edit", "wmsSelectedLayers": "Selected layers", - "wmsSelectedLayersNone": "No layers selected" + "wmsSelectedLayersNone": "No layers selected", + "remoteAssociatedMetadataTitlePlaceholder": "Remote associated metadata title" }