Skip to content

Commit

Permalink
added featurecodes-dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
StiftungAusNachlass committed Nov 20, 2020
1 parent b84b30c commit c72434f
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 5 deletions.
6 changes: 5 additions & 1 deletion CustomDataTypeGeonames.config.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -39,6 +39,10 @@ custom_types:
parameters:
value:
type: bool
- name: config_featurecodes
parameters:
value:
type: bool
- name: default_country_code
parameters:
value:
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions l10n/custom-data-type-geonames.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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,,
Expand All @@ -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
Expand Down
116 changes: 113 additions & 3 deletions src/webfrontend/CustomDataTypeGeonames.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -220,15 +305,21 @@ class CustomDataTypeGeonames extends CustomDataTypeWithCommons
geonames_searchterm = searchstring
geonames_countSuggestions = 50
geonames_featureclass = ''
geonames_featurecode = ''
geonames_country = ''

expandQuery = ''

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()
Expand All @@ -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
Expand Down Expand Up @@ -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 = []
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c72434f

Please sign in to comment.