From c72434f958056f54346cbd934f1be0b1201b77ea Mon Sep 17 00:00:00 2001 From: StiftungAusNachlass Date: Fri, 20 Nov 2020 10:06:34 +0100 Subject: [PATCH] added featurecodes-dropdown --- CustomDataTypeGeonames.config.yml | 6 +- README.md | 7 +- l10n/custom-data-type-geonames.csv | 4 + src/webfrontend/CustomDataTypeGeonames.coffee | 116 +++++++++++++++++- 4 files changed, 128 insertions(+), 5 deletions(-) diff --git a/CustomDataTypeGeonames.config.yml b/CustomDataTypeGeonames.config.yml index f0da6bb..6f2d8ca 100755 --- a/CustomDataTypeGeonames.config.yml +++ b/CustomDataTypeGeonames.config.yml @@ -1,6 +1,6 @@ plugin: name: custom-data-type-geonames - version: 1.7 + version: 1.8 url: https://github.com/programmfabrik/easydb-custom-data-type-geonames displayname: de-DE: geonames-Verknüpfung @@ -39,6 +39,10 @@ custom_types: parameters: value: type: bool + - name: config_featurecodes + parameters: + value: + type: bool - name: default_country_code parameters: value: diff --git a/README.md b/README.md index d214572..6995999 100755 --- a/README.md +++ b/README.md @@ -21,7 +21,8 @@ In `CustomDataTypeGeonames.config.yml` you can configure: * if a valid geonames-username is given, fulltext will be available * `mask-options`: - * wether to show a dropdown with available featureclasses or not + * wether to show a dropdown with available featureclasses (place-categorie) or not + * wether to show a dropdown with available featurecodes (place-type) or not * default country for the country-dropdown (2 digits-code) * default value for search expansion (Records of the lowest administrative level ("admin4") are also found via the higher-level administrative unit ("admin3")) * wether the ancestors are shown in hitlist @@ -34,6 +35,10 @@ In `CustomDataTypeGeonames.config.yml` you can configure: * URI to linked record * conceptFulltext * fulltext-string which contains: geonameId, adminName1, adminName2, adminName3, adminName4, adminName5, countryName, toponymName, alternateNames +* conceptAncestors + * the parent hierarchy of the selected record +* frontendLanguage + * the frontendlanguage of the entering user * _fulltext * easydb-fulltext * _standard diff --git a/l10n/custom-data-type-geonames.csv b/l10n/custom-data-type-geonames.csv index 6b57f3c..9f526ea 100755 --- a/l10n/custom-data-type-geonames.csv +++ b/l10n/custom-data-type-geonames.csv @@ -24,10 +24,13 @@ custom.data.type.geonames.setting.schema.add_coorporates,Körperschaften,Corpora custom.data.type.geonames.setting.schema.add_geographicplaces,Geografika,Places,, custom.data.type.geonames.setting.schema.add_subjects,Sachbegriffe,Subjects,, custom.data.type.geonames.config.parameter.mask.config_featureclasses.value.checkbox,Kategorien (Featureklassen) als Dropdown zur Verfeinerung der Suche anbieten?,Offer featureclasses as a drop-down to refine the search?,, +custom.data.type.geonames.config.parameter.mask.config_featurecodes.value.checkbox,Ortstyp (Featurecodes) als Dropdown zur Verfeinerung der Suche anbieten?,Offer featurecodes as a drop-down to refine the search?,, custom.data.type.geonames.config.parameter.schema.mapbox_api_key.value.label,Mapbox-Api-Key (für Kartenanzeige benötigt),Mapbox Api-Key (required for map display),, custom.data.type.geonames.config.parameter.mask.show_infopopup.value.label,Infopopup,Infopopup,, custom.data.type.geonames.config.parameter.mask.config_featureclasses.value.label,Dropdown Featureklassen,Dropdown Featureclasses,, +custom.data.type.geonames.config.parameter.mask.config_featurecodes.value.label,Dropdown Featurecodes,Dropdown Featurecodes,, custom.data.type.geonames.config.parameter.mask.config_featureclasses.all.label,Alle Kategorien,All categories,, +custom.data.type.geonames.config.parameter.mask.config_featurecodes.all.label,Alle Ortstypen,All featurecodes,, custom.data.type.geonames.config.parameter.mask.config_featureclasses.a.label,Administration,Administrative Boundary Features,, custom.data.type.geonames.config.parameter.mask.config_featureclasses.h.label,Gewässer,Hydrographic Features,, custom.data.type.geonames.config.parameter.mask.config_featureclasses.l.label,Gebiete,Area Features,, @@ -51,6 +54,7 @@ custom.data.type.geonames.config.parameter.mask.infopop.zeitzone.label,Zeitzone, custom.data.type.geonames.config.parameter.schema.geonames_username.value.label,geonames-Username,geonames-Username,, custom.data.type.geonames.config.parameter.mask.default_country_code.value.label,Standard-Ländercode (2-stellig),Default countrycode (2 digits),, custom.data.type.geonames.modal.form.text.countrys,Land,Country,, +custom.data.type.geonames.modal.form.text.featurecodes,Ortstyp custom.data.type.geonames.country.name.all,Alle Länder, All countries custom.data.type.geonames.modal.form.text.expand,Ergebnisse ausdehnen,Expand search custom.data.type.geonames.config.parameter.mask.default_expand.value.label,Standardwert für Trefferexpansion,Default value for search expansion diff --git a/src/webfrontend/CustomDataTypeGeonames.coffee b/src/webfrontend/CustomDataTypeGeonames.coffee index be2d67d..021791c 100755 --- a/src/webfrontend/CustomDataTypeGeonames.coffee +++ b/src/webfrontend/CustomDataTypeGeonames.coffee @@ -207,6 +207,91 @@ class CustomDataTypeGeonames extends CustomDataTypeWithCommons return + __getFeaturecodesFromDANTE: (thisSelect, featureclassCode) -> + dfr = new CUI.Deferred() + values = [] + + # start new request + searchsuggest_xhr = new (CUI.XHR)(url: 'https://api.dante.gbv.de/suggest?search=&voc=place_type_geonames&language=' + @getFrontendLanguage() + '&limit=1000&cache=1') + searchsuggest_xhr.start().done((data, status, statusText) -> + # read options for select + select_items = [] + item = ( + text: $$('custom.data.type.geonames.config.parameter.mask.config_featurecodes.all.label') + value: null + ) + select_items.push item + for suggestion, key in data[1] + uriParts = data[3][key] + uriParts = uriParts.split('.') + codeNotation = uriParts.pop() + featureClassCodeExtraction = uriParts[2].split('#') + featureClassCodeExtraction = featureClassCodeExtraction[1] + if (featureClassCodeExtraction == featureclassCode) || featureclassCode == '' || ! featureclassCode || featureclassCode == null + item = ( + text: suggestion + value: codeNotation + ) + select_items.push item + thisSelect.enable() + dfr.resolve(select_items) + ) + dfr.promise() + + + ####################################################################### + # show popover and fill it with the form-elements + showEditPopover: (btn, data, cdata, layout, opts) -> + that = @ + + suggest_Menu + + # init xhr-object to abort running xhrs + searchsuggest_xhr = { "xhr" : undefined } + + # set default value for count of suggestions + cdata.countOfSuggestions = 50 + cdata_form = new CUI.Form + class: 'cdtFormWithPadding' + data: cdata + fields: that.__getEditorFields(cdata) + onDataChanged: (data, elem) => + # if featureclass- & featurecodes-dropdown are visible + if @getCustomMaskSettings().config_featureclasses?.value && @getCustomMaskSettings().config_featurecodes?.value + # if featureclass changed, update featurecodes-dropdown + if elem.opts.name == 'geonamesSelectFeatureClasses' + # if featureclass is '', show all featurecodes + featureclassParameter = '' + if data?.geonamesSelectFeatureClasses != '' && data?.geonamesSelectFeatureClasses != null + featureclassParameter = data.geonamesSelectFeatureClasses + # reset the featurecode-element-value (in data + cdata) + data.geonamesSelectFeatureCodes = null + cdata.geonamesSelectFeatureCodes = null + cdata_form.getFieldsByName("geonamesSelectFeatureCodes")[0]?.setValue(null) + defaultText = cdata_form.getFieldsByName("geonamesSelectFeatureCodes")[0].default_opt.text + + cdata_form.getFieldsByName("geonamesSelectFeatureCodes")[0].reload() + cdata_form.getFieldsByName("geonamesSelectFeatureCodes")[0]?.setText('test') + @__updateResult(cdata, layout, opts) + @__setEditorFieldStatus(cdata, layout) + @__updateSuggestionsMenu(cdata, cdata_form, data.searchbarInput, elem, suggest_Menu, searchsuggest_xhr, layout, opts) + .start() + + # init suggestmenu + suggest_Menu = new CUI.Menu + element: cdata_form.getFieldsByName("searchbarInput")[0] + use_element_width_as_min_width: true + class: "customDataTypeCommonsMenu" + + @popover = new CUI.Popover + element: btn + placement: "wn" + class: "commonPlugin_Popover" + pane: + # titel of popovers + header_left: new CUI.Label(text: $$('custom.data.type.commons.popover.choose.label')) + content: cdata_form + .show() ####################################################################### # handle suggestions-menu @@ -220,6 +305,7 @@ class CustomDataTypeGeonames extends CustomDataTypeWithCommons geonames_searchterm = searchstring geonames_countSuggestions = 50 geonames_featureclass = '' + geonames_featurecode = '' geonames_country = '' expandQuery = '' @@ -227,8 +313,13 @@ class CustomDataTypeGeonames extends CustomDataTypeWithCommons if (cdata_form) geonames_searchterm = cdata_form.getFieldsByName("searchbarInput")[0].getValue() geonames_featureclass = cdata_form.getFieldsByName("geonamesSelectFeatureClasses")[0]?.getValue() - if geonames_featureclass == undefined + if geonames_featureclass == undefined || geonames_featureclass == null geonames_featureclass = '' + + geonames_featurecode = cdata_form.getFieldsByName("geonamesSelectFeatureCodes")[0]?.getValue() + if geonames_featurecode == undefined || geonames_featurecode == null + geonames_featurecode = '' + geonames_countSuggestions = cdata_form.getFieldsByName("countOfSuggestions")[0].getValue() expandStatus = cdata_form.getFieldsByName("expandSearchCheckbox")[0].getValue() @@ -252,7 +343,7 @@ class CustomDataTypeGeonames extends CustomDataTypeWithCommons # abort eventually running request searchsuggest_xhr.xhr.abort() # start new request - searchsuggest_xhr.xhr = new (CUI.XHR)(url: location.protocol + '//ws.gbv.de/suggest/geonames2/?searchterm=' + geonames_searchterm + '&language=' + that.getFrontendLanguage() + '&featureclass=' + geonames_featureclass + '&count=' + geonames_countSuggestions + countryQuery + expandQuery + ancestorsQuery) + searchsuggest_xhr.xhr = new (CUI.XHR)(url: location.protocol + '//ws.gbv.de/suggest/geonames2/?searchterm=' + geonames_searchterm + '&language=' + that.getFrontendLanguage() + '&featureclass=' + geonames_featureclass + '&featurecode=' + geonames_featurecode + '&count=' + geonames_countSuggestions + countryQuery + expandQuery + ancestorsQuery) searchsuggest_xhr.xhr.start().done((data, status, statusText) -> # create new menu with suggestions @@ -328,7 +419,7 @@ class CustomDataTypeGeonames extends CustomDataTypeWithCommons fulltext += ' ' + data.toponymName if data?.alternateNames for altName, altNameKey in data.alternateNames - fulltext += ' ' + altName.name + fulltext += ' ' + altName.name cdata._fulltext.text = fulltext # get ancestors from data conceptAncestors = [] @@ -470,6 +561,25 @@ class CustomDataTypeGeonames extends CustomDataTypeWithCommons fields.unshift(field) + # offer Featurecodes? (see config) + if @getCustomMaskSettings().config_featurecodes?.value + + field = { + type: CUI.Select + undo_and_changed_support: false + form: + label: $$('custom.data.type.geonames.modal.form.text.featurecodes') + name: 'geonamesSelectFeatureCodes' + class: 'commonPlugin_Select' + options: (thisSelect) => + featureclassParameter = '' + if cdata?.geonamesSelectFeatureClasses != '' && cdata?.geonamesSelectFeatureClasses != null + featureclassParameter = cdata.geonamesSelectFeatureClasses + that.__getFeaturecodesFromDANTE(thisSelect, featureclassParameter) + } + + fields.unshift(field) + # offer Featureclasses? (see config) if @getCustomMaskSettings().config_featureclasses?.value # featureclasses