Skip to content

Commit 746e214

Browse files
authored
Merge pull request #658 from itk-dev/feature/dawa-adressevaelger-shift
Switch away from dawa
2 parents 35d39a5 + fd3bab1 commit 746e214

20 files changed

Lines changed: 238 additions & 281 deletions

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
88

9+
* [PR-658](https://github.com/itk-dev/deltag.aarhus.dk/pull/658)
10+
* Replaced DAWA address autocomplete with Adressevaelger in hoeringsportal_forms and hoeringsportal_deskpro
11+
* Added Adressevaelger token configuration in admin settings
12+
* Removed nicoeg/dawa dependency from hoeringsportal_deskpro
13+
* Updated itk_pretix to use branch without DAWA dependency
14+
915
* [PR-654](https://github.com/itk-dev/deltag.aarhus.dk/pull/654)
1016
Updated OIDC development setup
1117

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
"itk-dev/composer-virtualenv": "^1.0",
8181
"itk-dev/itk_azure_video": "^2.0",
8282
"itk-dev/itk_dropzonejs_image_widget": "^1.0",
83-
"itk-dev/itk_pretix": "^1.5",
83+
"itk-dev/itk_pretix": "^1.6",
8484
"itk-dev/itk_siteimprove": "^1.2",
8585
"itk-dev/itk_video": "^1.0",
8686
"itk-dev/serviceplatformen": "^1.5",

composer.lock

Lines changed: 7 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/modules/custom/hoeringsportal_activity/src/Hook/ActivityHooks.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ public function activityFormAlter(&$form, $form_state): void {
7979
$form['#attached']['library'][] = 'hoeringsportal_activity/course_form_alter';
8080
}
8181

82-
// Dawa functionality to address field.
83-
$form['field_address']['widget'][0]['value']['#attributes']['class'][] = 'js-dawa-element';
82+
// Address autocomplete functionality to address field.
83+
$form['field_address']['widget'][0]['value']['#attributes']['class'][] = 'js-adressevaelger-element';
8484
}
8585

8686
}

web/modules/custom/hoeringsportal_config_settings/src/Form/ItkGeneralSettingsForm.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,21 @@ public function buildForm(array $form, FormStateInterface $form_state) {
281281
'#description' => $this->t('The height of the iframe i.e 450px'),
282282
];
283283

284+
$form['integrations'] = [
285+
'#title' => $this->t('Integrations'),
286+
'#type' => 'details',
287+
'#open' => TRUE,
288+
'#weight' => '2',
289+
'#group' => 'general_settings',
290+
];
291+
292+
$form['integrations']['adressevaelger_token'] = [
293+
'#type' => 'textfield',
294+
'#title' => $this->t('Adressevaelger token'),
295+
'#default_value' => $config->get('adressevaelger_token'),
296+
'#description' => $this->t('API token for the Adressevaelger address lookup service. Leave empty to use the default public token.'),
297+
];
298+
284299
$form['messages'] = [
285300
'#title' => $this->t('Messages'),
286301
'#type' => 'details',
@@ -329,6 +344,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
329344
'frontpage_id' => $form_state->getValue('frontpage_id'),
330345
'users_manual_url' => $form_state->getValue('users_manual_url'),
331346
'login_message' => $form_state->getValue('login_message'),
347+
'adressevaelger_token' => $form_state->getValue('adressevaelger_token'),
332348
'newsletter_node' => $form_state->getValue('newsletter_node'),
333349
'newsletter_iframe_source' => $form_state->getValue('newsletter_iframe_source'),
334350
'newsletter_iframe_height' => $form_state->getValue('newsletter_iframe_height'),

web/modules/custom/hoeringsportal_deskpro/assets/js/form-ticket-add.js

Lines changed: 44 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -2,135 +2,56 @@ require('../scss/form-ticket-add.scss')
22

33
const $ = require('jquery')
44
require('jquery-validation')
5-
require('jquery-ui/ui/widgets/autocomplete')
5+
const proj4 = require('proj4').default || require('proj4')
66

7-
// @see https://stackoverflow.com/a/11845718
8-
$.ui.autocomplete.prototype._resizeMenu = function () {
9-
const ul = this.menu.element
10-
ul.outerWidth(this.element.outerWidth())
11-
}
7+
// Define the UTM zone 32N projection used by the adressevaelger API.
8+
proj4.defs('EPSG:25832', '+proj=utm +zone=32 +ellps=GRS80 +units=m +no_defs')
129

1310
$(() => {
14-
const config = {
15-
fields: {
16-
postalCodeAndCity: 'edit-postal-code-and-city',
17-
streetAndNumber: 'edit-street-and-number'
18-
}
19-
}
20-
21-
const postalCodeAndCity = $('[data-drupal-selector="' + config.fields.postalCodeAndCity + '"]')
22-
const streetAndNumber = $('[data-drupal-selector="' + config.fields.streetAndNumber + '"]')
23-
24-
if (postalCodeAndCity && streetAndNumber) {
25-
// @see https://codepen.io/mi2oon/pen/zpNMoL
26-
const API = 'https://dawa.aws.dk'
27-
28-
const getData = (path, query = {}) => {
29-
const url = `${API}/${path}?` + Object.entries(query)
30-
.filter(e => e[1] !== null)
31-
.map(e => encodeURIComponent(e[0]) + '=' + encodeURIComponent(e[1])).join('&')
32-
33-
return $.ajax({
34-
url
35-
})
36-
}
37-
38-
const address = {
39-
postnr: null,
40-
vejnavn: null,
41-
husnr: null
42-
}
43-
44-
// Autocomplete postal code
45-
getData('postnumre')
46-
.then(data => {
47-
const autocompleteData = data.map(postnr => ({
48-
label: `${postnr.nr} ${postnr.navn}`,
49-
dataValue: postnr.nr
50-
}))
51-
52-
postalCodeAndCity.autocomplete({
53-
source: autocompleteData,
54-
autoFocus: true,
55-
minLength: 1,
56-
select: (e, ui) => {
57-
address.postnr = ui.item.dataValue
58-
address.vejnavn = null
59-
address.husnr = null
60-
}
61-
})
62-
})
63-
64-
const autocompleteStreetNumber = function () {
65-
getData('adresser', address)
66-
.then((data) => {
67-
const autocompleteData = data
68-
.map(adresse => adresse.adgangsadresse)
69-
.map(adgangsadresse => ({
70-
label: `${adgangsadresse.vejstykke.navn} ${adgangsadresse.husnr}`,
71-
dataValue: adgangsadresse.husnr
72-
}))
73-
74-
$(this).autocomplete({
75-
source: autocompleteData,
76-
autoFocus: true,
77-
minLength: 1,
78-
select: (e, ui) => { address.husnr = ui.item.dataValue }
79-
})
80-
})
81-
}
82-
83-
const autocompleteStreet = function () {
84-
if (address.postalCode === null) {
85-
return
86-
}
87-
88-
getData('vejnavne', address)
89-
.then((data) => {
90-
const autocompleteData = data.map(vej => ({
91-
label: vej.navn,
92-
dataValue: vej.navn
93-
}))
94-
95-
$(this).autocomplete({
96-
source: autocompleteData,
97-
autoFocus: true,
98-
minLength: 1,
99-
select: (e, ui) => {
100-
address.vejnavn = ui.item.dataValue
101-
address.husnr = null
102-
103-
autocompleteStreetNumber.apply(this)
104-
}
105-
})
106-
})
107-
}
11+
const addressLookup = document.getElementById('address-lookup')
12+
const postalCodeAndCity = document.querySelector('[data-drupal-selector="edit-postal-code-and-city"]')
13+
const streetAndNumber = document.querySelector('[data-drupal-selector="edit-street-and-number"]')
14+
const geolocation = document.querySelector('[data-drupal-selector="edit-geolocation"]')
15+
const postalCode = document.querySelector('[data-drupal-selector="edit-postal-code"]')
16+
17+
if (addressLookup && postalCodeAndCity && streetAndNumber && geolocation) {
18+
const wrapper = document.createElement('div')
19+
wrapper.setAttribute('class', 'autocomplete-container')
20+
addressLookup.parentNode.replaceChild(wrapper, addressLookup)
21+
wrapper.appendChild(addressLookup)
22+
23+
// Initialize adressevaelger on the address lookup field.
24+
// When an address is selected, populate hidden form fields with the
25+
// address components and geolocation for server-side processing.
26+
// `adressevaelger` is a global provided at runtime:
27+
// - adressevaelger: set by adressevaelger.iife.js, loaded via the
28+
// hoeringsportal_forms/adressevaelger-support-text-field library dependency.
29+
// eslint-disable-next-line no-undef
30+
adressevaelger.adressevaelger(addressLookup, {
31+
// eslint-disable-next-line no-undef
32+
token: drupalSettings.adressevaelger.token,
33+
select: function (selected) {
34+
// The selected object nests address data under adresse.husnummer.
35+
const husnummer = (selected.adresse && selected.adresse.husnummer) || {}
36+
const postnr = husnummer.postnummer || {}
37+
postalCodeAndCity.value = (postnr.postnr || '') + ' ' + (postnr.navn || '')
38+
if (postalCode) {
39+
postalCode.value = postnr.postnr || ''
40+
}
10841

109-
streetAndNumber
110-
.on('focus', autocompleteStreet)
111-
.on('keyup', function (event) {
112-
switch (event.key) {
113-
// Ignore keys used to navigate autocomplete suggestions.
114-
case 'ArrowUp':
115-
case 'ArrowDown':
116-
case 'Tab':
117-
case 'Enter':
118-
break
42+
streetAndNumber.value = ((husnummer.vejnavn || '') + ' ' + (husnummer.husnummertekst || '')).trim()
11943

120-
default:
121-
// Decide if we're completing street or street number.
122-
if (address.vejnavn !== null) {
123-
const value = $(this).val()
124-
// If a street has been selected and the current value if a prefix of the selected value, we autocomplete (a new) street.
125-
if (value === '' || address.vejnavn.indexOf(value) > -1) {
126-
autocompleteStreet.apply(this)
127-
} else {
128-
autocompleteStreetNumber.apply(this)
129-
}
130-
}
131-
break
44+
// The adressevaelger API returns coordinates in EPSG:25832 (UTM zone 32N).
45+
// Convert to EPSG:4326 (WGS84 longitude, latitude) for Deskpro.
46+
// proj4 returns [longitude, latitude].
47+
const coords = husnummer.adgangspunkt && husnummer.adgangspunkt.koordinater
48+
if (coords && coords.x && coords.y) {
49+
const wgs84 = proj4('EPSG:25832', 'EPSG:4326', [coords.x, coords.y])
50+
// Format to 8 decimal places to match the precision of the old DAWA API output.
51+
geolocation.value = wgs84[0].toFixed(8) + ', ' + wgs84[1].toFixed(8)
13252
}
133-
})
53+
}
54+
})
13455
}
13556

13657
document.querySelector('form#hearing-ticket-add-form').addEventListener('submit', function () {

web/modules/custom/hoeringsportal_deskpro/build/form-ticket-add.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/modules/custom/hoeringsportal_deskpro/build/form-ticket-add.js.LICENSE.txt

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -23,62 +23,6 @@
2323
* Date: 2022-08-26T17:52Z
2424
*/
2525

26-
/*!
27-
* jQuery UI Autocomplete 1.13.2
28-
* http://jqueryui.com
29-
*
30-
* Copyright jQuery Foundation and other contributors
31-
* Released under the MIT license.
32-
* http://jquery.org/license
33-
*/
34-
35-
/*!
36-
* jQuery UI Keycode 1.13.2
37-
* http://jqueryui.com
38-
*
39-
* Copyright jQuery Foundation and other contributors
40-
* Released under the MIT license.
41-
* http://jquery.org/license
42-
*/
43-
44-
/*!
45-
* jQuery UI Menu 1.13.2
46-
* http://jqueryui.com
47-
*
48-
* Copyright jQuery Foundation and other contributors
49-
* Released under the MIT license.
50-
* http://jquery.org/license
51-
*/
52-
53-
/*!
54-
* jQuery UI Position 1.13.2
55-
* http://jqueryui.com
56-
*
57-
* Copyright jQuery Foundation and other contributors
58-
* Released under the MIT license.
59-
* http://jquery.org/license
60-
*
61-
* http://api.jqueryui.com/position/
62-
*/
63-
64-
/*!
65-
* jQuery UI Unique ID 1.13.2
66-
* http://jqueryui.com
67-
*
68-
* Copyright jQuery Foundation and other contributors
69-
* Released under the MIT license.
70-
* http://jquery.org/license
71-
*/
72-
73-
/*!
74-
* jQuery UI Widget 1.13.2
75-
* http://jqueryui.com
76-
*
77-
* Copyright jQuery Foundation and other contributors
78-
* Released under the MIT license.
79-
* http://jquery.org/license
80-
*/
81-
8226
/*!
8327
* jQuery Validation Plugin v1.19.5
8428
*

web/modules/custom/hoeringsportal_deskpro/composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
},
1313
"require": {
1414
"deskpro/deskpro-api-client-php": "^4.0",
15-
"drupal/advancedqueue": "^1.0",
16-
"nicoeg/dawa": "^1.0"
15+
"drupal/advancedqueue": "^1.0"
1716
}
1817
}

web/modules/custom/hoeringsportal_deskpro/hoeringsportal_deskpro.info.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ core_version_requirement: ^8.8 || ^9 || ^10 || ^11
66

77
dependencies:
88
- itk_admin
9+
- hoeringsportal_forms

0 commit comments

Comments
 (0)