@wmfs/tymly-address-picker 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.circleci/config.yml +42 -0
- package/.releaserc.json +83 -0
- package/CHANGELOG.md +5 -0
- package/LICENSE +21 -0
- package/README.md +81 -2
- package/lib/AddressPicker.vue +985 -0
- package/package.json +50 -4
- package/renovate.json +5 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
version: 2.1
|
|
2
|
+
orbs:
|
|
3
|
+
gh-app: wmfs/github-app-token@1.0.0
|
|
4
|
+
tymly: wmfs/tymly-ci@1
|
|
5
|
+
jobs:
|
|
6
|
+
build:
|
|
7
|
+
docker:
|
|
8
|
+
- image: cimg/node:lts
|
|
9
|
+
auth:
|
|
10
|
+
username: $DOCKERHUB_USERNAME
|
|
11
|
+
password: $DOCKERHUB_PASSWORD
|
|
12
|
+
environment:
|
|
13
|
+
TZ: "Europe/London"
|
|
14
|
+
working_directory: ~/repo
|
|
15
|
+
steps:
|
|
16
|
+
- checkout
|
|
17
|
+
- run:
|
|
18
|
+
name: install
|
|
19
|
+
command: |
|
|
20
|
+
npm config set //registry.npmjs.org/:_authToken=$NPM_TOKEN
|
|
21
|
+
npm install
|
|
22
|
+
- gh-app/mint
|
|
23
|
+
- run:
|
|
24
|
+
name: release
|
|
25
|
+
command: npx semantic-release
|
|
26
|
+
workflows:
|
|
27
|
+
release:
|
|
28
|
+
jobs:
|
|
29
|
+
- tymly/commit-check:
|
|
30
|
+
context:
|
|
31
|
+
- docker-hub-creds
|
|
32
|
+
filters:
|
|
33
|
+
branches:
|
|
34
|
+
ignore: master
|
|
35
|
+
- build:
|
|
36
|
+
context:
|
|
37
|
+
- docker-hub-creds
|
|
38
|
+
- build-env-vars
|
|
39
|
+
- github-app
|
|
40
|
+
filters:
|
|
41
|
+
branches:
|
|
42
|
+
only: master
|
package/.releaserc.json
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
{
|
|
2
|
+
"branch": "master",
|
|
3
|
+
"analyzeCommits": {
|
|
4
|
+
"preset": "angular",
|
|
5
|
+
"releaseRules": [
|
|
6
|
+
{"type": "build", "scope":"deps", "release": "minor"}
|
|
7
|
+
]
|
|
8
|
+
},
|
|
9
|
+
"verifyConditions": [
|
|
10
|
+
"@semantic-release/changelog",
|
|
11
|
+
"@semantic-release/npm",
|
|
12
|
+
"@semantic-release/git"
|
|
13
|
+
],
|
|
14
|
+
"generateNotes": {
|
|
15
|
+
"preset": "conventionalcommits",
|
|
16
|
+
"presetConfig": {
|
|
17
|
+
"types": [
|
|
18
|
+
{
|
|
19
|
+
"breaking": true,
|
|
20
|
+
"type": "feat!",
|
|
21
|
+
"section": "BREAKING"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"type": "feat",
|
|
25
|
+
"section": "New Feature(s) :rocket:"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"type": "fix",
|
|
29
|
+
"section": "Bug Fix(es) :bug:"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"type": "docs",
|
|
33
|
+
"section": "Documentation Changes :memo:"
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"type": "refactor",
|
|
37
|
+
"section": "Code Refactor :recycle:"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"type": "test",
|
|
41
|
+
"section": "Tests :alembic:"
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"type": "perf",
|
|
45
|
+
"section": "Performance Improvement(s) :zap:"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"type": "build",
|
|
49
|
+
"section": "Build system dependencies :hammer:"
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
"type": "chore",
|
|
53
|
+
"section": "Chores :pencil2:"
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
"type": "ci",
|
|
57
|
+
"section": "CICD Configuration Changes :construction_worker:"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"type": "style",
|
|
61
|
+
"section": "Code Styling :art:"
|
|
62
|
+
}
|
|
63
|
+
]
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
"prepare": [
|
|
67
|
+
{
|
|
68
|
+
"path": "@semantic-release/changelog",
|
|
69
|
+
"changelogFile": "CHANGELOG.md"
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
"path": "@semantic-release/git",
|
|
73
|
+
"assets": ["CHANGELOG.md"]
|
|
74
|
+
},
|
|
75
|
+
"@semantic-release/npm"
|
|
76
|
+
],
|
|
77
|
+
"publish": [
|
|
78
|
+
"@semantic-release/npm",
|
|
79
|
+
"@semantic-release/github"
|
|
80
|
+
],
|
|
81
|
+
"success": ["@semantic-release/github"],
|
|
82
|
+
"fail": ["@semantic-release/github"]
|
|
83
|
+
}
|
package/CHANGELOG.md
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 West Midlands Fire Service
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,82 @@
|
|
|
1
|
-
#
|
|
1
|
+
# tymly-address-picker
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://tymly.io/)
|
|
4
|
+
[](https://www.npmjs.com/package/@wmfs/tymly-address-picker)
|
|
5
|
+
[](http://commitizen.github.io/cz-cli/)
|
|
6
|
+
[](https://github.com/wmfs/tymly/blob/master/packages/concrete-paths/LICENSE)
|
|
7
|
+
|
|
8
|
+
> Tymly gazetteer address picker for the cardscript `Input.Address` element, as a Quasar component
|
|
9
|
+
|
|
10
|
+
States: search (as you type, or on Enter), results with Official/Temporary tags and UPRN, too many matches,
|
|
11
|
+
no matches, search unavailable, validation error, address chosen (with map), manual entry (with a draggable pin),
|
|
12
|
+
and a phone layout.
|
|
13
|
+
|
|
14
|
+
## <a name="install"></a>Install
|
|
15
|
+
```bash
|
|
16
|
+
$ npm install @wmfs/tymly-address-picker --save
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## <a name="usage"></a>Usage
|
|
20
|
+
|
|
21
|
+
Register the component with the components your cardscript templates are compiled against:
|
|
22
|
+
|
|
23
|
+
```js
|
|
24
|
+
import TymlyAddressPicker from '@wmfs/tymly-address-picker'
|
|
25
|
+
|
|
26
|
+
export default {
|
|
27
|
+
components: { TymlyAddressPicker, ... }
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Then use `Input.Address` in a card template. `@wmfs/cardscript-to-quasar` renders it as `<tymly-address-picker>`:
|
|
32
|
+
|
|
33
|
+
```json
|
|
34
|
+
{ "type": "Input.Address", "id": "selectedUprn" }
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Props
|
|
38
|
+
|
|
39
|
+
| Prop | | |
|
|
40
|
+
| --- | --- | --- |
|
|
41
|
+
| `config` | required | Resolved settings, made by cardscript-to-quasar from the element |
|
|
42
|
+
| `model` | required | Card data. The picker reads it and emits `update` with the values to merge; it never changes it directly |
|
|
43
|
+
| `validation` | | `v$.data` from vuelidate |
|
|
44
|
+
| `invalidFields` | | Fields that failed on submit, with messages |
|
|
45
|
+
| `execute` | | `async ({ stateMachineName, input, sendResponse }) => ({ status, ctx })`. Defaults to `this.$tymly.executions.execute` (TymlySDK from `@wmfs/tymly-cardscript-sdk`) |
|
|
46
|
+
|
|
47
|
+
### Events
|
|
48
|
+
|
|
49
|
+
`update (patch)`: values to merge into the card data.
|
|
50
|
+
|
|
51
|
+
### Element settings
|
|
52
|
+
|
|
53
|
+
All optional, see the `Input.Address` definition in `@wmfs/cardscript-schema`:
|
|
54
|
+
`idPrefix`, `title`, `subtitle`, `placeholder`, `searchEndpoint` (default `wmfs_addressPickerSearch_1_0`),
|
|
55
|
+
`detailsEndpoint` (default `wmfs_addressPickerDetails_1_0`, `false` to turn off),
|
|
56
|
+
`searchFields`, `resultsPerPage`, `tooManyResults`, `searchAsYouType`, `allowGeoLocation`, `showMap`,
|
|
57
|
+
`allowManualEntry`, `manualEntryTitle`, `manualEntryNotice`, `manualEntryFields`, `onSelectionEndpoint`, `validation`.
|
|
58
|
+
|
|
59
|
+
### Data written (prefixed with `idPrefix_` when set)
|
|
60
|
+
|
|
61
|
+
| Key | |
|
|
62
|
+
| --- | --- |
|
|
63
|
+
| `<id>` | Selected UPRN |
|
|
64
|
+
| `addressLabel` | Label of the chosen address |
|
|
65
|
+
| `selectedAddress` | `{ uprn, label, line, locality, postcode, status, dataSource, dataSourceLabel, temporary, latitude, longitude, details, ... }` |
|
|
66
|
+
| `cannotFindAddress` | `true` when entered by hand |
|
|
67
|
+
| `addressLine1`, `addressLine2`, `townOrCity`, `county`, `postcode` (and any other `manualEntryFields`) | Manual entry |
|
|
68
|
+
| `latitude`, `longitude` | Pin from manual entry |
|
|
69
|
+
|
|
70
|
+
The search endpoint is given `{ filter, page, limit, fields?, useGeoLocation?, $GEOLOCATION? }` and should return
|
|
71
|
+
`{ totalHits, totalPages, page, results: [{ uprn, label, line, locality, postcode, reference, status, dataSource, dataSourceLabel, temporary, latitude, longitude }] }`.
|
|
72
|
+
|
|
73
|
+
Once an address is chosen, the details endpoint is given `{ uprn }` and should return
|
|
74
|
+
`{ found, maskingNumber, classification: { code, title, path }, status, hierarchy: { parentUprn, parentAddressLabel, siblingCount, childrenCount } }`.
|
|
75
|
+
The picker keeps them in `selectedAddress.details` and shows them as on the gazetteer property card.
|
|
76
|
+
|
|
77
|
+
Each result's tag shows `dataSourceLabel` (no tag when it's empty). `temporary` results get the highlighted tag.
|
|
78
|
+
`wmfs_addressPickerSearch_1_0` fills these from the gazetteer `data_source`, with labels from
|
|
79
|
+
`gazetteer-property-blueprint/shared/address-data-sources.json`.
|
|
80
|
+
|
|
81
|
+
## <a name="license"></a>License
|
|
82
|
+
[MIT](https://github.com/wmfs/tymly/blob/master/packages/concrete-paths/LICENSE)
|
|
@@ -0,0 +1,985 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Address picker for the cardscript Input.Address element (@wmfs/tymly-address-picker).
|
|
3
|
+
|
|
4
|
+
Rendered by cardscript-to-quasar (lib/builders/Input.Address.js), which passes:
|
|
5
|
+
config resolved settings (see cardscript-to-quasar lib/utils/address-picker-config.js)
|
|
6
|
+
model the card data the picker reads and writes
|
|
7
|
+
validation v$.data from vuelidate
|
|
8
|
+
invalidFields fields that failed on submit, with messages
|
|
9
|
+
Optional:
|
|
10
|
+
execute async ({ stateMachineName, input, sendResponse }) => ({ status, ctx }).
|
|
11
|
+
Defaults to this.$tymly.executions.execute (TymlySDK from @wmfs/tymly-cardscript-sdk).
|
|
12
|
+
|
|
13
|
+
It never changes `model` directly: it emits `update` with the values to merge.
|
|
14
|
+
|
|
15
|
+
States follow the "Tymly unified UI" design board: search, results, too many matches,
|
|
16
|
+
no matches, search unavailable, error, address chosen, manual entry, and a phone layout.
|
|
17
|
+
-->
|
|
18
|
+
<template>
|
|
19
|
+
<div
|
|
20
|
+
class="tap"
|
|
21
|
+
:class="{ 'tap--phone': isPhone, 'tap--error': hasError }"
|
|
22
|
+
>
|
|
23
|
+
<!-- Manual entry -->
|
|
24
|
+
<template v-if="isManual">
|
|
25
|
+
<a
|
|
26
|
+
href="#"
|
|
27
|
+
class="tap__link tap__back"
|
|
28
|
+
@click.prevent="backToSearch"
|
|
29
|
+
>‹ Back to address search</a>
|
|
30
|
+
<div class="tap__heading q-mt-md">{{ config.manualEntryTitle }}</div>
|
|
31
|
+
|
|
32
|
+
<div
|
|
33
|
+
v-if="config.manualEntryNotice"
|
|
34
|
+
class="tap__banner tap__banner--change q-mt-md"
|
|
35
|
+
>
|
|
36
|
+
{{ config.manualEntryNotice }}
|
|
37
|
+
</div>
|
|
38
|
+
|
|
39
|
+
<div class="tap__panel q-mt-md">
|
|
40
|
+
<div
|
|
41
|
+
v-for="field in config.manualEntryFields"
|
|
42
|
+
:id="`CARDSCRIPT_${field.id}`"
|
|
43
|
+
:key="field.id"
|
|
44
|
+
class="tap__field"
|
|
45
|
+
:class="{ 'tap__field--error': fieldError(field.id), 'tap__field--short': field.width === 'short' }"
|
|
46
|
+
>
|
|
47
|
+
<label
|
|
48
|
+
:for="inputId(field.id)"
|
|
49
|
+
class="tap__label"
|
|
50
|
+
>
|
|
51
|
+
{{ field.title }}
|
|
52
|
+
<span
|
|
53
|
+
v-if="!field.required"
|
|
54
|
+
class="tap__optional"
|
|
55
|
+
>(optional)</span>
|
|
56
|
+
</label>
|
|
57
|
+
<p
|
|
58
|
+
v-if="field.hint"
|
|
59
|
+
:id="inputId(field.id) + '-hint'"
|
|
60
|
+
class="tap__hint"
|
|
61
|
+
>{{ field.hint }}</p>
|
|
62
|
+
<p
|
|
63
|
+
v-if="fieldError(field.id)"
|
|
64
|
+
:id="inputId(field.id) + '-error'"
|
|
65
|
+
class="tap__error-message"
|
|
66
|
+
>
|
|
67
|
+
<span class="sr-only">Error: </span>{{ fieldError(field.id) }}
|
|
68
|
+
</p>
|
|
69
|
+
<input
|
|
70
|
+
:id="inputId(field.id)"
|
|
71
|
+
class="tap__input"
|
|
72
|
+
:value="model[field.id]"
|
|
73
|
+
:autocomplete="field.autocomplete || 'off'"
|
|
74
|
+
:aria-invalid="fieldError(field.id) ? 'true' : 'false'"
|
|
75
|
+
:aria-describedby="describedBy(field)"
|
|
76
|
+
@input="e => update({ [field.id]: e.target.value || null })"
|
|
77
|
+
@blur="touch(field.id)"
|
|
78
|
+
>
|
|
79
|
+
</div>
|
|
80
|
+
|
|
81
|
+
<div
|
|
82
|
+
v-if="config.showMap"
|
|
83
|
+
class="tap__field"
|
|
84
|
+
>
|
|
85
|
+
<div class="tap__label">
|
|
86
|
+
Location <span class="tap__optional">(optional)</span>
|
|
87
|
+
</div>
|
|
88
|
+
<p class="tap__hint">Drag the pin to the property, or use your current location.</p>
|
|
89
|
+
<div class="tap__map">
|
|
90
|
+
<q-map
|
|
91
|
+
:key="`manual-${manualMapKey}`"
|
|
92
|
+
:locked="false"
|
|
93
|
+
:draggable="true"
|
|
94
|
+
:centre-latitude="manualPin.latitude"
|
|
95
|
+
:centre-longitude="manualPin.longitude"
|
|
96
|
+
>
|
|
97
|
+
<q-map-circle
|
|
98
|
+
format="LatLon"
|
|
99
|
+
:latitude="manualPin.latitude"
|
|
100
|
+
:longitude="manualPin.longitude"
|
|
101
|
+
:showMarker="true"
|
|
102
|
+
label="Property"
|
|
103
|
+
@latitude="v => update({ [keys.latitude]: v })"
|
|
104
|
+
@longitude="v => update({ [keys.longitude]: v })"
|
|
105
|
+
/>
|
|
106
|
+
</q-map>
|
|
107
|
+
</div>
|
|
108
|
+
<div
|
|
109
|
+
v-if="config.allowGeoLocation"
|
|
110
|
+
class="tap__row q-mt-sm"
|
|
111
|
+
>
|
|
112
|
+
<q-btn
|
|
113
|
+
class="tap__quiet-btn"
|
|
114
|
+
no-caps
|
|
115
|
+
unelevated
|
|
116
|
+
:loading="locating"
|
|
117
|
+
label="Use my current location"
|
|
118
|
+
@click="pinMyLocation"
|
|
119
|
+
/>
|
|
120
|
+
<span
|
|
121
|
+
v-if="hasManualPin"
|
|
122
|
+
class="tap__muted"
|
|
123
|
+
>Pin at {{ formatCoord(model[keys.latitude]) }}, {{ formatCoord(model[keys.longitude]) }}</span>
|
|
124
|
+
</div>
|
|
125
|
+
<p
|
|
126
|
+
v-if="locationError"
|
|
127
|
+
class="tap__warning q-mt-sm"
|
|
128
|
+
role="status"
|
|
129
|
+
>{{ locationError }}</p>
|
|
130
|
+
</div>
|
|
131
|
+
</div>
|
|
132
|
+
</template>
|
|
133
|
+
|
|
134
|
+
<!-- Address chosen -->
|
|
135
|
+
<div
|
|
136
|
+
v-else-if="isSelected"
|
|
137
|
+
class="tap__panel"
|
|
138
|
+
>
|
|
139
|
+
<div class="tap__selected-head">
|
|
140
|
+
<div class="tap__selected-text">
|
|
141
|
+
<div class="tap__selected-line">{{ selected.line || selected.label }}</div>
|
|
142
|
+
<div
|
|
143
|
+
v-if="selected.locality"
|
|
144
|
+
class="tap__muted"
|
|
145
|
+
>{{ selected.locality }}</div>
|
|
146
|
+
</div>
|
|
147
|
+
<a
|
|
148
|
+
href="#"
|
|
149
|
+
class="tap__link tap__change"
|
|
150
|
+
@click.prevent="changeAddress"
|
|
151
|
+
>Change<span class="sr-only"> address</span></a>
|
|
152
|
+
</div>
|
|
153
|
+
|
|
154
|
+
<div class="tap__selected-body q-mt-md">
|
|
155
|
+
<div
|
|
156
|
+
v-if="config.showMap && selectedHasPoint"
|
|
157
|
+
class="tap__map tap__map--small"
|
|
158
|
+
>
|
|
159
|
+
<q-map
|
|
160
|
+
:key="`selected-${selected.uprn}`"
|
|
161
|
+
:locked="true"
|
|
162
|
+
>
|
|
163
|
+
<q-map-circle
|
|
164
|
+
format="LatLon"
|
|
165
|
+
:latitude="selected.latitude"
|
|
166
|
+
:longitude="selected.longitude"
|
|
167
|
+
:showMarker="true"
|
|
168
|
+
:locked="true"
|
|
169
|
+
:label="selected.line || selected.label"
|
|
170
|
+
/>
|
|
171
|
+
</q-map>
|
|
172
|
+
</div>
|
|
173
|
+
<dl class="tap__summary">
|
|
174
|
+
<div>
|
|
175
|
+
<dt>UPRN</dt>
|
|
176
|
+
<dd class="tap__mono">{{ details && details.maskingNumber ? selected.uprn : (selected.reference || selected.uprn) }}</dd>
|
|
177
|
+
</div>
|
|
178
|
+
<div v-if="details && details.maskingNumber">
|
|
179
|
+
<dt>Masking number</dt>
|
|
180
|
+
<dd class="tap__mono">{{ details.maskingNumber }}</dd>
|
|
181
|
+
</div>
|
|
182
|
+
<div v-if="selected.dataSourceLabel">
|
|
183
|
+
<dt>Data source</dt>
|
|
184
|
+
<dd>
|
|
185
|
+
<span
|
|
186
|
+
class="tap__tag"
|
|
187
|
+
:class="selected.temporary ? 'tap__tag--info' : 'tap__tag--grey'"
|
|
188
|
+
>{{ selected.dataSourceLabel }}</span>
|
|
189
|
+
</dd>
|
|
190
|
+
</div>
|
|
191
|
+
<div v-if="details && details.classification">
|
|
192
|
+
<dt>Classification</dt>
|
|
193
|
+
<dd>
|
|
194
|
+
{{ details.classification.title }} <span class="tap__mono tap__muted">({{ details.classification.code }})</span>
|
|
195
|
+
<span
|
|
196
|
+
v-if="details.classification.path"
|
|
197
|
+
class="tap__dd-sub"
|
|
198
|
+
>{{ details.classification.path }}</span>
|
|
199
|
+
</dd>
|
|
200
|
+
</div>
|
|
201
|
+
<div v-if="status">
|
|
202
|
+
<dt>Status</dt>
|
|
203
|
+
<dd><span class="tap__tag tap__tag--ok">{{ status }}</span></dd>
|
|
204
|
+
</div>
|
|
205
|
+
<div v-if="hierarchy && hierarchy.parentUprn">
|
|
206
|
+
<dt>Hierarchy</dt>
|
|
207
|
+
<dd>
|
|
208
|
+
Part of {{ hierarchy.parentAddressLabel || 'a parent property' }}
|
|
209
|
+
<span class="tap__dd-sub"><span class="tap__mono">UPRN {{ hierarchy.parentUprn }}</span> · {{ hierarchy.siblingCount }} {{ hierarchy.siblingCount === 1 ? 'property' : 'properties' }} under it</span>
|
|
210
|
+
</dd>
|
|
211
|
+
</div>
|
|
212
|
+
<div v-else-if="hierarchy && hierarchy.childrenCount > 0">
|
|
213
|
+
<dt>Hierarchy</dt>
|
|
214
|
+
<dd>Parent of {{ hierarchy.childrenCount }} {{ hierarchy.childrenCount === 1 ? 'property' : 'properties' }}</dd>
|
|
215
|
+
</div>
|
|
216
|
+
<div v-if="loadingDetails">
|
|
217
|
+
<dt class="sr-only">Details</dt>
|
|
218
|
+
<dd
|
|
219
|
+
class="tap__muted tap__small"
|
|
220
|
+
role="status"
|
|
221
|
+
>Loading property details…</dd>
|
|
222
|
+
</div>
|
|
223
|
+
</dl>
|
|
224
|
+
</div>
|
|
225
|
+
</div>
|
|
226
|
+
|
|
227
|
+
<!-- Search -->
|
|
228
|
+
<div
|
|
229
|
+
v-else
|
|
230
|
+
class="tap__panel"
|
|
231
|
+
>
|
|
232
|
+
<q-btn
|
|
233
|
+
v-if="isPhone && config.allowGeoLocation"
|
|
234
|
+
class="tap__quiet-btn full-width q-mb-md"
|
|
235
|
+
no-caps
|
|
236
|
+
unelevated
|
|
237
|
+
:loading="locating"
|
|
238
|
+
label="Use my current location"
|
|
239
|
+
@click="searchNearMe"
|
|
240
|
+
/>
|
|
241
|
+
|
|
242
|
+
<div
|
|
243
|
+
class="tap__field"
|
|
244
|
+
:class="{ 'tap__field--error': hasError }"
|
|
245
|
+
>
|
|
246
|
+
<label
|
|
247
|
+
:for="inputId(config.id)"
|
|
248
|
+
class="tap__label tap__label--large"
|
|
249
|
+
>{{ isPhone && config.allowGeoLocation ? 'Or search for the address' : config.title }}</label>
|
|
250
|
+
<p
|
|
251
|
+
v-if="config.subtitle"
|
|
252
|
+
:id="inputId(config.id) + '-hint'"
|
|
253
|
+
class="tap__hint"
|
|
254
|
+
>{{ config.subtitle }}</p>
|
|
255
|
+
<p
|
|
256
|
+
v-if="hasError"
|
|
257
|
+
:id="inputId(config.id) + '-error'"
|
|
258
|
+
class="tap__error-message"
|
|
259
|
+
>
|
|
260
|
+
<span class="sr-only">Error: </span>{{ errorMessage }}
|
|
261
|
+
</p>
|
|
262
|
+
<div class="tap__search">
|
|
263
|
+
<input
|
|
264
|
+
:id="inputId(config.id)"
|
|
265
|
+
v-model="query"
|
|
266
|
+
type="search"
|
|
267
|
+
class="tap__input tap__search-input"
|
|
268
|
+
autocomplete="off"
|
|
269
|
+
:placeholder="config.placeholder"
|
|
270
|
+
:aria-invalid="hasError ? 'true' : 'false'"
|
|
271
|
+
:aria-describedby="searchDescribedBy"
|
|
272
|
+
@input="onType"
|
|
273
|
+
@keydown.enter.prevent="search(1)"
|
|
274
|
+
>
|
|
275
|
+
<q-btn
|
|
276
|
+
class="tap__search-btn"
|
|
277
|
+
no-caps
|
|
278
|
+
unelevated
|
|
279
|
+
:loading="searching"
|
|
280
|
+
label="Search"
|
|
281
|
+
@click="search(1)"
|
|
282
|
+
/>
|
|
283
|
+
</div>
|
|
284
|
+
</div>
|
|
285
|
+
|
|
286
|
+
<div
|
|
287
|
+
v-if="!isPhone && (config.allowGeoLocation || config.allowManualEntry) && !hasSearched"
|
|
288
|
+
class="tap__row q-mt-md"
|
|
289
|
+
>
|
|
290
|
+
<q-btn
|
|
291
|
+
v-if="config.allowGeoLocation"
|
|
292
|
+
class="tap__quiet-btn"
|
|
293
|
+
no-caps
|
|
294
|
+
unelevated
|
|
295
|
+
:loading="locating"
|
|
296
|
+
label="Use my current location"
|
|
297
|
+
@click="searchNearMe"
|
|
298
|
+
/>
|
|
299
|
+
<a
|
|
300
|
+
v-if="config.allowManualEntry"
|
|
301
|
+
href="#"
|
|
302
|
+
class="tap__link"
|
|
303
|
+
@click.prevent="enterManually"
|
|
304
|
+
>I can't find the address</a>
|
|
305
|
+
</div>
|
|
306
|
+
|
|
307
|
+
<p
|
|
308
|
+
v-if="locationError"
|
|
309
|
+
class="tap__warning q-mt-md"
|
|
310
|
+
role="status"
|
|
311
|
+
>{{ locationError }}</p>
|
|
312
|
+
|
|
313
|
+
<!-- Search unavailable -->
|
|
314
|
+
<div
|
|
315
|
+
v-if="searchFailed"
|
|
316
|
+
class="tap__banner tap__banner--change q-mt-md"
|
|
317
|
+
role="status"
|
|
318
|
+
>
|
|
319
|
+
<b>Search is unavailable</b>
|
|
320
|
+
<div>Try again in a moment<template v-if="config.allowManualEntry">, or enter the address by hand</template>.</div>
|
|
321
|
+
<q-btn
|
|
322
|
+
class="tap__quiet-btn q-mt-sm"
|
|
323
|
+
no-caps
|
|
324
|
+
unelevated
|
|
325
|
+
label="Try again"
|
|
326
|
+
@click="search(page)"
|
|
327
|
+
/>
|
|
328
|
+
</div>
|
|
329
|
+
|
|
330
|
+
<!-- Too many matches -->
|
|
331
|
+
<div
|
|
332
|
+
v-else-if="tooMany"
|
|
333
|
+
class="tap__banner tap__banner--change q-mt-md"
|
|
334
|
+
role="status"
|
|
335
|
+
>
|
|
336
|
+
<b>More than {{ config.tooManyResults }} addresses match "{{ lastQuery }}"</b>
|
|
337
|
+
<div>Add more of the address, for example a full postcode, a street name or a house number.</div>
|
|
338
|
+
</div>
|
|
339
|
+
|
|
340
|
+
<!-- No matches -->
|
|
341
|
+
<div
|
|
342
|
+
v-else-if="hasSearched && totalHits === 0 && !searching"
|
|
343
|
+
class="tap__banner tap__banner--change q-mt-md"
|
|
344
|
+
role="status"
|
|
345
|
+
>
|
|
346
|
+
<b>No addresses match "{{ lastQuery }}"</b>
|
|
347
|
+
<div>Check the spelling, or try a postcode, street name or UPRN.</div>
|
|
348
|
+
</div>
|
|
349
|
+
|
|
350
|
+
<!-- Results -->
|
|
351
|
+
<template v-else-if="results.length > 0">
|
|
352
|
+
<div class="tap__row tap__results-head q-mt-md">
|
|
353
|
+
<p
|
|
354
|
+
class="tap__count"
|
|
355
|
+
role="status"
|
|
356
|
+
>{{ resultsSummary }}</p>
|
|
357
|
+
<a
|
|
358
|
+
v-if="config.showMap && resultsWithPoints.length > 0"
|
|
359
|
+
href="#"
|
|
360
|
+
class="tap__link tap__small"
|
|
361
|
+
:aria-expanded="showResultsMap ? 'true' : 'false'"
|
|
362
|
+
@click.prevent="showResultsMap = !showResultsMap"
|
|
363
|
+
>{{ showResultsMap ? 'Hide map' : 'Show on map' }}</a>
|
|
364
|
+
</div>
|
|
365
|
+
|
|
366
|
+
<div
|
|
367
|
+
v-if="showResultsMap"
|
|
368
|
+
class="tap__map q-mt-sm"
|
|
369
|
+
>
|
|
370
|
+
<q-map
|
|
371
|
+
:key="`results-${page}-${lastQuery}`"
|
|
372
|
+
:locked="true"
|
|
373
|
+
:draggable="true"
|
|
374
|
+
>
|
|
375
|
+
<q-map-circle
|
|
376
|
+
v-for="r in resultsWithPoints"
|
|
377
|
+
:key="r.uprn"
|
|
378
|
+
format="LatLon"
|
|
379
|
+
:latitude="r.latitude"
|
|
380
|
+
:longitude="r.longitude"
|
|
381
|
+
:showMarker="true"
|
|
382
|
+
:locked="true"
|
|
383
|
+
:label="r.line || r.label"
|
|
384
|
+
/>
|
|
385
|
+
</q-map>
|
|
386
|
+
</div>
|
|
387
|
+
|
|
388
|
+
<fieldset class="tap__fieldset q-mt-sm">
|
|
389
|
+
<legend class="sr-only">Choose the address</legend>
|
|
390
|
+
<div class="tap__list">
|
|
391
|
+
<label
|
|
392
|
+
v-for="r in results"
|
|
393
|
+
:key="r.uprn"
|
|
394
|
+
class="tap__option"
|
|
395
|
+
:class="{ 'tap__option--selected': r.uprn === model[keys.uprn] }"
|
|
396
|
+
>
|
|
397
|
+
<input
|
|
398
|
+
type="radio"
|
|
399
|
+
:name="inputId(config.id) + '-choice'"
|
|
400
|
+
:value="r.uprn"
|
|
401
|
+
:checked="r.uprn === model[keys.uprn]"
|
|
402
|
+
@change="choose(r)"
|
|
403
|
+
>
|
|
404
|
+
<span class="tap__option-text">
|
|
405
|
+
<span class="tap__option-line">{{ r.line || r.label }}</span>
|
|
406
|
+
<span class="tap__option-meta">
|
|
407
|
+
<template v-if="r.locality">{{ r.locality }} · </template><span class="tap__mono">UPRN {{ r.uprn }}</span>
|
|
408
|
+
</span>
|
|
409
|
+
</span>
|
|
410
|
+
<span
|
|
411
|
+
v-if="r.dataSourceLabel"
|
|
412
|
+
class="tap__tag"
|
|
413
|
+
:class="r.temporary ? 'tap__tag--info' : 'tap__tag--grey'"
|
|
414
|
+
:title="r.dataSource"
|
|
415
|
+
>{{ r.temporary && isPhone ? 'Temporary' : r.dataSourceLabel }}</span>
|
|
416
|
+
</label>
|
|
417
|
+
</div>
|
|
418
|
+
</fieldset>
|
|
419
|
+
|
|
420
|
+
<div
|
|
421
|
+
v-if="totalPages > 1"
|
|
422
|
+
class="tap__row q-mt-sm"
|
|
423
|
+
>
|
|
424
|
+
<span class="tap__muted tap__small">Showing {{ firstShown }} to {{ lastShown }} of {{ totalHits }}. Or add a house number to narrow it down.</span>
|
|
425
|
+
<q-pagination
|
|
426
|
+
:model-value="page"
|
|
427
|
+
class="tap__pagination"
|
|
428
|
+
:max="totalPages"
|
|
429
|
+
:max-pages="isPhone ? 3 : 5"
|
|
430
|
+
direction-links
|
|
431
|
+
boundary-links
|
|
432
|
+
:disable="searching"
|
|
433
|
+
@update:model-value="p => search(p)"
|
|
434
|
+
/>
|
|
435
|
+
</div>
|
|
436
|
+
</template>
|
|
437
|
+
|
|
438
|
+
<div
|
|
439
|
+
v-if="config.allowManualEntry && (hasSearched || isPhone)"
|
|
440
|
+
class="q-mt-md"
|
|
441
|
+
>
|
|
442
|
+
<a
|
|
443
|
+
href="#"
|
|
444
|
+
class="tap__link"
|
|
445
|
+
@click.prevent="enterManually"
|
|
446
|
+
>I can't find the address</a>
|
|
447
|
+
</div>
|
|
448
|
+
</div>
|
|
449
|
+
</div>
|
|
450
|
+
</template>
|
|
451
|
+
|
|
452
|
+
<script>
|
|
453
|
+
import QMap from '@wmfs/quasar-map-mapbox'
|
|
454
|
+
import template from 'lodash.template'
|
|
455
|
+
|
|
456
|
+
// Centre of the West Midlands, used when there is nothing better for the manual entry map.
|
|
457
|
+
const DEFAULT_CENTRE = { latitude: 52.4862, longitude: -1.8904 }
|
|
458
|
+
const MIN_TYPED_LENGTH = 3
|
|
459
|
+
const TYPING_DELAY_MS = 500
|
|
460
|
+
|
|
461
|
+
export default {
|
|
462
|
+
name: 'TymlyAddressPicker',
|
|
463
|
+
components: {
|
|
464
|
+
QMap,
|
|
465
|
+
QMapCircle: QMap.components.QMapCircle
|
|
466
|
+
},
|
|
467
|
+
props: {
|
|
468
|
+
config: { type: Object, required: true },
|
|
469
|
+
model: { type: Object, required: true },
|
|
470
|
+
validation: { type: Object, default: null },
|
|
471
|
+
invalidFields: { type: Object, default: null },
|
|
472
|
+
execute: { type: Function, default: null }
|
|
473
|
+
},
|
|
474
|
+
emits: ['update'],
|
|
475
|
+
data () {
|
|
476
|
+
return {
|
|
477
|
+
query: '',
|
|
478
|
+
lastQuery: '',
|
|
479
|
+
searching: false,
|
|
480
|
+
searchFailed: false,
|
|
481
|
+
hasSearched: false,
|
|
482
|
+
results: [],
|
|
483
|
+
totalHits: 0,
|
|
484
|
+
totalPages: 0,
|
|
485
|
+
page: 1,
|
|
486
|
+
nearMe: false,
|
|
487
|
+
showResultsMap: false,
|
|
488
|
+
changing: false,
|
|
489
|
+
locating: false,
|
|
490
|
+
locationError: null,
|
|
491
|
+
manualMapKey: 0,
|
|
492
|
+
typingTimer: null,
|
|
493
|
+
searchCount: 0,
|
|
494
|
+
loadingDetails: false
|
|
495
|
+
}
|
|
496
|
+
},
|
|
497
|
+
computed: {
|
|
498
|
+
keys () {
|
|
499
|
+
return this.config.keys
|
|
500
|
+
},
|
|
501
|
+
isPhone () {
|
|
502
|
+
return this.$q.screen.lt.sm
|
|
503
|
+
},
|
|
504
|
+
isManual () {
|
|
505
|
+
return this.model[this.keys.cannotFindAddress] === true
|
|
506
|
+
},
|
|
507
|
+
selected () {
|
|
508
|
+
const uprn = this.model[this.keys.uprn]
|
|
509
|
+
if (uprn === null || uprn === undefined || uprn === '') return null
|
|
510
|
+
const stored = this.model[this.keys.selectedAddress]
|
|
511
|
+
if (stored && String(stored.uprn) === String(uprn)) return stored
|
|
512
|
+
// A draft or prefilled card may only have the UPRN and label
|
|
513
|
+
return { uprn: String(uprn), label: this.model[this.keys.addressLabel] || String(uprn) }
|
|
514
|
+
},
|
|
515
|
+
isSelected () {
|
|
516
|
+
return this.selected !== null && !this.changing
|
|
517
|
+
},
|
|
518
|
+
details () {
|
|
519
|
+
return (this.selected && this.selected.details) || null
|
|
520
|
+
},
|
|
521
|
+
hierarchy () {
|
|
522
|
+
return this.details && this.details.hierarchy
|
|
523
|
+
},
|
|
524
|
+
status () {
|
|
525
|
+
return (this.details && this.details.status) || (this.selected && this.selected.status) || null
|
|
526
|
+
},
|
|
527
|
+
selectedHasPoint () {
|
|
528
|
+
return this.selected && isNumber(this.selected.latitude) && isNumber(this.selected.longitude)
|
|
529
|
+
},
|
|
530
|
+
tooMany () {
|
|
531
|
+
return this.hasSearched && !this.nearMe && this.totalHits > this.config.tooManyResults
|
|
532
|
+
},
|
|
533
|
+
resultsWithPoints () {
|
|
534
|
+
return this.results.filter(r => isNumber(r.latitude) && isNumber(r.longitude))
|
|
535
|
+
},
|
|
536
|
+
firstShown () {
|
|
537
|
+
return (this.page - 1) * this.config.resultsPerPage + 1
|
|
538
|
+
},
|
|
539
|
+
lastShown () {
|
|
540
|
+
return Math.min(this.page * this.config.resultsPerPage, this.totalHits)
|
|
541
|
+
},
|
|
542
|
+
resultsSummary () {
|
|
543
|
+
const n = this.totalHits
|
|
544
|
+
const what = `${n} address${n === 1 ? '' : 'es'}`
|
|
545
|
+
if (this.nearMe) return `${what} near you`
|
|
546
|
+
const postcode = this.results.length && this.results[0].postcode
|
|
547
|
+
if (postcode && normalise(this.lastQuery) === normalise(postcode)) return `${what} in ${postcode}`
|
|
548
|
+
return `${what} found`
|
|
549
|
+
},
|
|
550
|
+
hasError () {
|
|
551
|
+
const v = this.validation && this.validation[this.config.id]
|
|
552
|
+
return !!(v && v.$error)
|
|
553
|
+
},
|
|
554
|
+
errorMessage () {
|
|
555
|
+
const invalid = this.invalidFields && this.invalidFields[this.config.id]
|
|
556
|
+
if (invalid && Array.isArray(invalid.messages) && invalid.messages.length) return invalid.messages.join(' ')
|
|
557
|
+
return this.config.validation.message
|
|
558
|
+
},
|
|
559
|
+
searchDescribedBy () {
|
|
560
|
+
return [
|
|
561
|
+
this.config.subtitle ? this.inputId(this.config.id) + '-hint' : null,
|
|
562
|
+
this.hasError ? this.inputId(this.config.id) + '-error' : null
|
|
563
|
+
].filter(Boolean).join(' ') || null
|
|
564
|
+
},
|
|
565
|
+
hasManualPin () {
|
|
566
|
+
return isNumber(this.model[this.keys.latitude]) && isNumber(this.model[this.keys.longitude])
|
|
567
|
+
},
|
|
568
|
+
manualPin () {
|
|
569
|
+
if (this.hasManualPin) {
|
|
570
|
+
return { latitude: this.model[this.keys.latitude], longitude: this.model[this.keys.longitude] }
|
|
571
|
+
}
|
|
572
|
+
const geo = this.model.$GEOLOCATION
|
|
573
|
+
if (geo && isNumber(geo.lat) && isNumber(geo.lng)) return { latitude: geo.lat, longitude: geo.lng }
|
|
574
|
+
return DEFAULT_CENTRE
|
|
575
|
+
}
|
|
576
|
+
},
|
|
577
|
+
watch: {
|
|
578
|
+
// Drafts and prefilled cards may have an address without details yet
|
|
579
|
+
'selected.uprn': {
|
|
580
|
+
handler () {
|
|
581
|
+
if (this.selected && !this.details) this.loadDetails(this.selected)
|
|
582
|
+
},
|
|
583
|
+
immediate: true
|
|
584
|
+
}
|
|
585
|
+
},
|
|
586
|
+
beforeUnmount () {
|
|
587
|
+
clearTimeout(this.typingTimer)
|
|
588
|
+
},
|
|
589
|
+
methods: {
|
|
590
|
+
inputId (id) {
|
|
591
|
+
return `tap-${id}`
|
|
592
|
+
},
|
|
593
|
+
runExecution (options) {
|
|
594
|
+
if (this.execute) return this.execute(options)
|
|
595
|
+
if (this.$tymly && this.$tymly.executions) return this.$tymly.executions.execute(options)
|
|
596
|
+
throw new Error('Address picker needs an execute prop or this.$tymly (TymlySDK)')
|
|
597
|
+
},
|
|
598
|
+
update (patch) {
|
|
599
|
+
this.$emit('update', patch)
|
|
600
|
+
},
|
|
601
|
+
touch (id) {
|
|
602
|
+
const v = this.validation && this.validation[id]
|
|
603
|
+
if (v && typeof v.$touch === 'function') v.$touch()
|
|
604
|
+
},
|
|
605
|
+
fieldError (id) {
|
|
606
|
+
const v = this.validation && this.validation[id]
|
|
607
|
+
if (!v || !v.$error) return null
|
|
608
|
+
const invalid = this.invalidFields && this.invalidFields[id]
|
|
609
|
+
if (invalid && Array.isArray(invalid.messages) && invalid.messages.length) return invalid.messages.join(' ')
|
|
610
|
+
const field = this.config.manualEntryFields.find(f => f.id === id)
|
|
611
|
+
if (v.postcode && v.postcode.$invalid) return 'Enter a real postcode'
|
|
612
|
+
return field ? (field.message || `Enter ${field.title.toLowerCase()}`) : 'Check this field'
|
|
613
|
+
},
|
|
614
|
+
describedBy (field) {
|
|
615
|
+
return [
|
|
616
|
+
field.hint ? this.inputId(field.id) + '-hint' : null,
|
|
617
|
+
this.fieldError(field.id) ? this.inputId(field.id) + '-error' : null
|
|
618
|
+
].filter(Boolean).join(' ') || null
|
|
619
|
+
},
|
|
620
|
+
formatCoord (v) {
|
|
621
|
+
return Number(v).toFixed(5)
|
|
622
|
+
},
|
|
623
|
+
onType () {
|
|
624
|
+
clearTimeout(this.typingTimer)
|
|
625
|
+
if (!this.config.searchAsYouType) return
|
|
626
|
+
if (this.query.trim().length < MIN_TYPED_LENGTH) return
|
|
627
|
+
this.typingTimer = setTimeout(() => this.search(1), TYPING_DELAY_MS)
|
|
628
|
+
},
|
|
629
|
+
async search (page = 1, { nearMe = false, position = null } = {}) {
|
|
630
|
+
clearTimeout(this.typingTimer)
|
|
631
|
+
|
|
632
|
+
const query = nearMe ? '' : this.query.trim()
|
|
633
|
+
if (!nearMe && query.length === 0) return
|
|
634
|
+
|
|
635
|
+
// Ignore replies to older searches if the user has carried on typing
|
|
636
|
+
const searchId = ++this.searchCount
|
|
637
|
+
|
|
638
|
+
this.searching = true
|
|
639
|
+
this.searchFailed = false
|
|
640
|
+
this.nearMe = nearMe
|
|
641
|
+
|
|
642
|
+
const input = {
|
|
643
|
+
filter: query,
|
|
644
|
+
page,
|
|
645
|
+
limit: this.config.resultsPerPage
|
|
646
|
+
}
|
|
647
|
+
if (this.config.searchFields) input.fields = this.config.searchFields
|
|
648
|
+
if (nearMe && position) {
|
|
649
|
+
input.useGeoLocation = true
|
|
650
|
+
input.$GEOLOCATION = position
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
try {
|
|
654
|
+
const res = await this.runExecution({
|
|
655
|
+
stateMachineName: this.config.searchEndpoint,
|
|
656
|
+
input,
|
|
657
|
+
sendResponse: 'COMPLETE'
|
|
658
|
+
})
|
|
659
|
+
|
|
660
|
+
if (searchId !== this.searchCount) return
|
|
661
|
+
|
|
662
|
+
if (res.status !== 'SUCCEEDED') throw new Error(`Search ended with status ${res.status}`)
|
|
663
|
+
|
|
664
|
+
const ctx = res.ctx || {}
|
|
665
|
+
this.results = Array.isArray(ctx.results) ? ctx.results : []
|
|
666
|
+
this.totalHits = ctx.totalHits || 0
|
|
667
|
+
this.totalPages = ctx.totalPages || 0
|
|
668
|
+
this.page = ctx.page || page
|
|
669
|
+
this.lastQuery = query
|
|
670
|
+
this.hasSearched = true
|
|
671
|
+
} catch (err) {
|
|
672
|
+
if (searchId !== this.searchCount) return
|
|
673
|
+
console.log('Address picker search failed', err)
|
|
674
|
+
this.searchFailed = true
|
|
675
|
+
this.hasSearched = true
|
|
676
|
+
this.results = []
|
|
677
|
+
} finally {
|
|
678
|
+
if (searchId === this.searchCount) this.searching = false
|
|
679
|
+
}
|
|
680
|
+
},
|
|
681
|
+
async getPosition () {
|
|
682
|
+
this.locating = true
|
|
683
|
+
this.locationError = null
|
|
684
|
+
try {
|
|
685
|
+
const position = await getCurrentPosition({ timeout: 10000 })
|
|
686
|
+
return { lat: position.coords.latitude, lng: position.coords.longitude }
|
|
687
|
+
} catch {
|
|
688
|
+
this.locationError = 'Your location is not available. Check location is allowed in your browser settings.'
|
|
689
|
+
return null
|
|
690
|
+
} finally {
|
|
691
|
+
this.locating = false
|
|
692
|
+
}
|
|
693
|
+
},
|
|
694
|
+
async searchNearMe () {
|
|
695
|
+
const position = await this.getPosition()
|
|
696
|
+
if (!position) return
|
|
697
|
+
this.query = ''
|
|
698
|
+
await this.search(1, { nearMe: true, position })
|
|
699
|
+
},
|
|
700
|
+
async pinMyLocation () {
|
|
701
|
+
const position = await this.getPosition()
|
|
702
|
+
if (!position) return
|
|
703
|
+
this.update({ [this.keys.latitude]: position.lat, [this.keys.longitude]: position.lng })
|
|
704
|
+
this.manualMapKey++
|
|
705
|
+
},
|
|
706
|
+
async choose (result) {
|
|
707
|
+
this.changing = false
|
|
708
|
+
this.update({
|
|
709
|
+
[this.keys.uprn]: result.uprn,
|
|
710
|
+
[this.keys.addressLabel]: result.label,
|
|
711
|
+
[this.keys.selectedAddress]: { ...result },
|
|
712
|
+
[this.keys.cannotFindAddress]: false
|
|
713
|
+
})
|
|
714
|
+
this.touch(this.config.id)
|
|
715
|
+
await Promise.all([
|
|
716
|
+
this.loadDetails(result),
|
|
717
|
+
this.runSelectionEndpoint(result)
|
|
718
|
+
])
|
|
719
|
+
},
|
|
720
|
+
async loadDetails (address) {
|
|
721
|
+
const endpoint = this.config.detailsEndpoint
|
|
722
|
+
if (!endpoint || !address || this.loadingDetails === address.uprn) return
|
|
723
|
+
|
|
724
|
+
this.loadingDetails = address.uprn
|
|
725
|
+
try {
|
|
726
|
+
const res = await this.runExecution({
|
|
727
|
+
stateMachineName: endpoint,
|
|
728
|
+
input: { uprn: address.uprn },
|
|
729
|
+
sendResponse: 'COMPLETE'
|
|
730
|
+
})
|
|
731
|
+
const details = res.status === 'SUCCEEDED' && res.ctx && res.ctx.found !== false
|
|
732
|
+
? {
|
|
733
|
+
maskingNumber: res.ctx.maskingNumber || null,
|
|
734
|
+
classification: res.ctx.classification || null,
|
|
735
|
+
status: res.ctx.status || null,
|
|
736
|
+
hierarchy: res.ctx.hierarchy || null
|
|
737
|
+
}
|
|
738
|
+
: null
|
|
739
|
+
// Only keep them if the user hasn't picked something else meanwhile
|
|
740
|
+
if (details && String(this.model[this.keys.uprn]) === String(address.uprn)) {
|
|
741
|
+
const current = this.model[this.keys.selectedAddress] || address
|
|
742
|
+
this.update({ [this.keys.selectedAddress]: { ...current, details } })
|
|
743
|
+
}
|
|
744
|
+
} catch (err) {
|
|
745
|
+
console.log('Address picker could not load property details', endpoint, err)
|
|
746
|
+
} finally {
|
|
747
|
+
if (this.loadingDetails === address.uprn) this.loadingDetails = false
|
|
748
|
+
}
|
|
749
|
+
},
|
|
750
|
+
async runSelectionEndpoint (result) {
|
|
751
|
+
const endpoint = this.config.onSelectionEndpoint
|
|
752
|
+
if (!endpoint || !endpoint.name) return
|
|
753
|
+
|
|
754
|
+
let input = { ...this.model, uprn: result.uprn }
|
|
755
|
+
if (endpoint.params) {
|
|
756
|
+
input = {}
|
|
757
|
+
for (const [key, value] of Object.entries(endpoint.params)) {
|
|
758
|
+
input[key] = typeof value === 'string'
|
|
759
|
+
? template(value, { interpolate: /{{([\s\S]+?)}}/g })({ data: { ...this.model, [this.keys.uprn]: result.uprn } }) || null
|
|
760
|
+
: value
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
try {
|
|
765
|
+
const res = await this.runExecution({
|
|
766
|
+
stateMachineName: endpoint.name,
|
|
767
|
+
input,
|
|
768
|
+
sendResponse: 'COMPLETE'
|
|
769
|
+
})
|
|
770
|
+
if (res.status === 'SUCCEEDED' && res.ctx) this.update(res.ctx)
|
|
771
|
+
} catch (err) {
|
|
772
|
+
console.log('Address picker selection endpoint failed', endpoint.name, err)
|
|
773
|
+
}
|
|
774
|
+
},
|
|
775
|
+
changeAddress () {
|
|
776
|
+
this.changing = true
|
|
777
|
+
if (!this.hasSearched && this.selected && this.selected.postcode) {
|
|
778
|
+
this.query = this.selected.postcode
|
|
779
|
+
this.search(1)
|
|
780
|
+
}
|
|
781
|
+
this.$nextTick(() => {
|
|
782
|
+
const input = document.getElementById(this.inputId(this.config.id))
|
|
783
|
+
if (input) input.focus()
|
|
784
|
+
})
|
|
785
|
+
},
|
|
786
|
+
enterManually () {
|
|
787
|
+
this.changing = false
|
|
788
|
+
this.update({
|
|
789
|
+
[this.keys.cannotFindAddress]: true,
|
|
790
|
+
[this.keys.uprn]: null,
|
|
791
|
+
[this.keys.addressLabel]: null,
|
|
792
|
+
[this.keys.selectedAddress]: null
|
|
793
|
+
})
|
|
794
|
+
},
|
|
795
|
+
backToSearch () {
|
|
796
|
+
this.update({ [this.keys.cannotFindAddress]: false })
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
function getCurrentPosition (options) {
|
|
802
|
+
return new Promise((resolve, reject) => {
|
|
803
|
+
if (typeof navigator === 'undefined' || !navigator.geolocation) return reject(new Error('Geolocation is not supported'))
|
|
804
|
+
navigator.geolocation.getCurrentPosition(resolve, reject, options)
|
|
805
|
+
})
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
function isNumber (v) {
|
|
809
|
+
return typeof v === 'number' && Number.isFinite(v)
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
function normalise (s) {
|
|
813
|
+
return String(s || '').replace(/\s/g, '').toUpperCase()
|
|
814
|
+
}
|
|
815
|
+
</script>
|
|
816
|
+
|
|
817
|
+
<style scoped>
|
|
818
|
+
.tap {
|
|
819
|
+
--tap-ink: #0b0c0c;
|
|
820
|
+
--tap-ink-2: #505a5f;
|
|
821
|
+
--tap-ink-3: #626a6e;
|
|
822
|
+
--tap-line: #dedcd7;
|
|
823
|
+
--tap-panel: #ffffff;
|
|
824
|
+
--tap-link: #1d70b8;
|
|
825
|
+
--tap-link-hover: #003078;
|
|
826
|
+
--tap-accent: var(--q-primary);
|
|
827
|
+
--tap-accent-soft: #e8f1f8;
|
|
828
|
+
--tap-danger: #d4351c;
|
|
829
|
+
--tap-danger-ink: #aa2a16;
|
|
830
|
+
--tap-warn-soft: #fff4dc;
|
|
831
|
+
--tap-warn: #8a5300;
|
|
832
|
+
--tap-ok-soft: #e7f3ec;
|
|
833
|
+
--tap-ok: #005a30;
|
|
834
|
+
--tap-neutral-soft: #efeeea;
|
|
835
|
+
--tap-focus: #ffdd00;
|
|
836
|
+
color: var(--tap-ink);
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
.tap__panel {
|
|
840
|
+
background: var(--tap-panel);
|
|
841
|
+
padding: 24px;
|
|
842
|
+
display: flex;
|
|
843
|
+
flex-direction: column;
|
|
844
|
+
}
|
|
845
|
+
.tap--phone .tap__panel { padding: 16px; }
|
|
846
|
+
|
|
847
|
+
.tap__heading { font-size: 24px; font-weight: 700; line-height: 1.2; }
|
|
848
|
+
|
|
849
|
+
.tap__field + .tap__field { margin-top: 18px; }
|
|
850
|
+
.tap__field--error { border-left: 4px solid var(--tap-danger); padding-left: 16px; }
|
|
851
|
+
.tap__field--short .tap__input { max-width: 180px; }
|
|
852
|
+
|
|
853
|
+
.tap__label { display: block; font-weight: 700; font-size: 16px; }
|
|
854
|
+
.tap__label--large { font-size: 19px; }
|
|
855
|
+
.tap__optional { font-weight: 400; color: var(--tap-ink-2); }
|
|
856
|
+
.tap__hint { margin: 4px 0 8px; color: var(--tap-ink-2); }
|
|
857
|
+
.tap__error-message { margin: 0 0 8px; color: var(--tap-danger-ink); font-weight: 700; }
|
|
858
|
+
.tap__label + .tap__input { margin-top: 6px; }
|
|
859
|
+
|
|
860
|
+
.tap__input {
|
|
861
|
+
width: 100%;
|
|
862
|
+
height: 44px;
|
|
863
|
+
box-sizing: border-box;
|
|
864
|
+
border: 2px solid var(--tap-ink);
|
|
865
|
+
border-radius: 4px;
|
|
866
|
+
padding: 0 12px;
|
|
867
|
+
font: inherit;
|
|
868
|
+
font-size: 17px;
|
|
869
|
+
background: var(--tap-panel);
|
|
870
|
+
color: var(--tap-ink);
|
|
871
|
+
}
|
|
872
|
+
.tap__input:focus {
|
|
873
|
+
outline: 3px solid var(--tap-focus);
|
|
874
|
+
outline-offset: 0;
|
|
875
|
+
box-shadow: inset 0 0 0 2px var(--tap-ink);
|
|
876
|
+
}
|
|
877
|
+
.tap__field--error .tap__input { border-color: var(--tap-danger); }
|
|
878
|
+
|
|
879
|
+
.tap__search { display: flex; }
|
|
880
|
+
.tap__search-input { flex: 1; min-width: 0; border-right: 0; border-radius: 4px 0 0 4px; }
|
|
881
|
+
.tap__search-btn {
|
|
882
|
+
min-height: 44px;
|
|
883
|
+
border: 2px solid var(--tap-ink);
|
|
884
|
+
border-radius: 0 4px 4px 0;
|
|
885
|
+
background: var(--tap-neutral-soft);
|
|
886
|
+
color: var(--tap-ink);
|
|
887
|
+
font-weight: 600;
|
|
888
|
+
}
|
|
889
|
+
.tap__field--error .tap__search-btn { border-color: var(--tap-danger); }
|
|
890
|
+
|
|
891
|
+
.tap__quiet-btn {
|
|
892
|
+
background: var(--tap-neutral-soft);
|
|
893
|
+
color: var(--tap-ink);
|
|
894
|
+
font-weight: 600;
|
|
895
|
+
min-height: 40px;
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
.tap__row { display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: center; }
|
|
899
|
+
.tap__results-head { align-items: baseline; }
|
|
900
|
+
.tap__results-head .tap__link { margin-left: auto; }
|
|
901
|
+
.tap__count { margin: 0; font-weight: 700; }
|
|
902
|
+
.tap__muted { color: var(--tap-ink-2); }
|
|
903
|
+
.tap__small { font-size: 14px; }
|
|
904
|
+
.tap__mono { font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace; }
|
|
905
|
+
|
|
906
|
+
.tap__link { color: var(--tap-link); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
|
|
907
|
+
.tap__link:hover { color: var(--tap-link-hover); }
|
|
908
|
+
.tap__link:focus { outline: none; background: var(--tap-focus); color: var(--tap-ink); box-shadow: 0 4px 0 var(--tap-ink); text-decoration: none; }
|
|
909
|
+
.tap__back { font-size: 15px; }
|
|
910
|
+
.tap__change { margin-left: auto; font-weight: 600; }
|
|
911
|
+
|
|
912
|
+
.tap__banner {
|
|
913
|
+
border-left: 5px solid var(--tap-warn);
|
|
914
|
+
background: var(--tap-warn-soft);
|
|
915
|
+
padding: 12px 16px;
|
|
916
|
+
}
|
|
917
|
+
.tap__banner b { display: block; margin-bottom: 2px; }
|
|
918
|
+
.tap__warning { margin: 0; color: var(--tap-warn); font-weight: 600; }
|
|
919
|
+
|
|
920
|
+
.tap__fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
|
|
921
|
+
.tap__list { border: 1px solid var(--tap-line); border-radius: 10px; overflow: hidden; }
|
|
922
|
+
.tap__option {
|
|
923
|
+
display: flex;
|
|
924
|
+
gap: 12px;
|
|
925
|
+
align-items: flex-start;
|
|
926
|
+
padding: 11px 14px;
|
|
927
|
+
cursor: pointer;
|
|
928
|
+
background: var(--tap-panel);
|
|
929
|
+
}
|
|
930
|
+
.tap__option + .tap__option { border-top: 1px solid var(--tap-line); }
|
|
931
|
+
.tap__option:hover { background: #fafaf8; }
|
|
932
|
+
.tap__option--selected,
|
|
933
|
+
.tap__option--selected:hover { background: var(--tap-accent-soft); box-shadow: inset 4px 0 0 var(--tap-accent); }
|
|
934
|
+
.tap__option input { width: 22px; height: 22px; margin: 1px 0 0; accent-color: var(--tap-ink); flex: none; }
|
|
935
|
+
.tap__option-text { min-width: 0; flex: 1; }
|
|
936
|
+
.tap__option-line { display: block; font-weight: 600; }
|
|
937
|
+
.tap__option-meta { display: block; color: var(--tap-ink-3); font-size: 13px; }
|
|
938
|
+
|
|
939
|
+
.tap__tag {
|
|
940
|
+
display: inline-block;
|
|
941
|
+
padding: 2px 8px;
|
|
942
|
+
border-radius: 4px;
|
|
943
|
+
font-size: 13px;
|
|
944
|
+
font-weight: 600;
|
|
945
|
+
white-space: nowrap;
|
|
946
|
+
}
|
|
947
|
+
.tap__tag--grey { background: var(--tap-neutral-soft); color: var(--tap-ink-2); }
|
|
948
|
+
.tap__tag--info { background: var(--tap-accent-soft); color: var(--tap-accent); }
|
|
949
|
+
.tap__tag--ok { background: var(--tap-ok-soft); color: var(--tap-ok); }
|
|
950
|
+
|
|
951
|
+
.tap__selected-head { display: flex; align-items: flex-start; gap: 12px; }
|
|
952
|
+
.tap__selected-text { min-width: 0; }
|
|
953
|
+
.tap__selected-line { font-weight: 700; font-size: 19px; margin-bottom: 2px; }
|
|
954
|
+
.tap__selected-body { display: flex; flex-wrap: wrap; gap: 16px; }
|
|
955
|
+
.tap__selected-body .tap__map { flex: 1 1 260px; }
|
|
956
|
+
.tap__summary { flex: 1 1 260px; margin: 0; }
|
|
957
|
+
.tap__summary > div {
|
|
958
|
+
display: grid;
|
|
959
|
+
grid-template-columns: 110px 1fr;
|
|
960
|
+
gap: 8px;
|
|
961
|
+
padding: 8px 0;
|
|
962
|
+
border-bottom: 1px solid var(--tap-line);
|
|
963
|
+
}
|
|
964
|
+
.tap__summary dt { font-weight: 700; }
|
|
965
|
+
.tap__summary dd { margin: 0; }
|
|
966
|
+
.tap__dd-sub { display: block; color: var(--tap-ink-3); font-size: 13px; }
|
|
967
|
+
|
|
968
|
+
.tap__map { border-radius: 10px; overflow: hidden; }
|
|
969
|
+
.tap__map :deep(.q-card) { margin-bottom: 0; }
|
|
970
|
+
|
|
971
|
+
.tap__pagination { margin-left: auto; }
|
|
972
|
+
.tap--phone .tap__pagination { margin-left: 0; }
|
|
973
|
+
|
|
974
|
+
.sr-only {
|
|
975
|
+
position: absolute;
|
|
976
|
+
width: 1px;
|
|
977
|
+
height: 1px;
|
|
978
|
+
padding: 0;
|
|
979
|
+
margin: -1px;
|
|
980
|
+
overflow: hidden;
|
|
981
|
+
clip: rect(0 0 0 0);
|
|
982
|
+
white-space: nowrap;
|
|
983
|
+
border: 0;
|
|
984
|
+
}
|
|
985
|
+
</style>
|
package/package.json
CHANGED
|
@@ -1,6 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wmfs/tymly-address-picker",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"description": "Tymly gazetteer address picker for the cardscript Input.Address element, as a Quasar component",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"author": "West Midlands Fire Service",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"tymly",
|
|
8
|
+
"cardscript",
|
|
9
|
+
"vue",
|
|
10
|
+
"quasar",
|
|
11
|
+
"address",
|
|
12
|
+
"gazetteer"
|
|
13
|
+
],
|
|
14
|
+
"main": "lib/AddressPicker.vue",
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@wmfs/quasar-map-mapbox": "1.33.0",
|
|
17
|
+
"lodash.template": "4.18.1"
|
|
18
|
+
},
|
|
19
|
+
"peerDependencies": {
|
|
20
|
+
"quasar": "^2.0.0",
|
|
21
|
+
"vue": "^3.2.33"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@semantic-release/changelog": "7.0.0",
|
|
25
|
+
"@semantic-release/git": "11.0.1",
|
|
26
|
+
"@semantic-release/release-notes-generator": "14.1.0",
|
|
27
|
+
"conventional-changelog-conventionalcommits": "8.0.0",
|
|
28
|
+
"cz-conventional-changelog": "3.3.0",
|
|
29
|
+
"semantic-release": "25.0.9"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"lint": "echo Lint with the app's eslint config, sorry",
|
|
33
|
+
"test": "echo No Tests, sorry",
|
|
34
|
+
"semantic-release": "semantic-release"
|
|
35
|
+
},
|
|
36
|
+
"license": "MIT",
|
|
37
|
+
"repository": {
|
|
38
|
+
"type": "git",
|
|
39
|
+
"url": "https://github.com/wmfs/tymly-address-picker.git"
|
|
40
|
+
},
|
|
41
|
+
"bugs": {
|
|
42
|
+
"url": "https://github.com/wmfs/tymly-address-picker/issues"
|
|
43
|
+
},
|
|
44
|
+
"config": {
|
|
45
|
+
"commitizen": {
|
|
46
|
+
"path": "cz-conventional-changelog"
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"publishConfig": {
|
|
50
|
+
"access": "public"
|
|
51
|
+
}
|
|
52
|
+
}
|