generated from OpenRail-Playground/template-dreilaenderhack
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAddressList.vue
359 lines (315 loc) · 9.1 KB
/
AddressList.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
<template>
<div>
<div class="wrapper">
<h2>Ergebnis</h2>
<p>
Du kannst die Ergebnisse über die Suche bzw. den Filter für die Immissionsrichtwerte nach
AVV Baulärm eingrenzen. Das Ergebnis zeigt die Adressen, die Tags oder Nachts vom Lärm
betroffen sind. Nutze den Tag-Nacht-Schalter auf der Karte zur Anzeige des betroffenen
Bereichs.
</p>
<div v-if="addressStore.loading">Lade Daten...</div>
<div v-if="addressStore.error">Fehler: {{ addressStore.error }}</div>
<div v-if="!addressStore.loading && addressStore.addresses.length">
<div class="filter">
<!-- Search input -->
<div class="search-input">
<input
v-model="searchQuery"
type="text"
class="elm-input"
placeholder="Suche"
name="search"
id="search"
aria-labelledby="search-label"
data-variant="outline"
/>
<label class="elm-label" for="search" aria-hidden="true" id="search-label">Suche</label>
</div>
<!-- Filter -->
<div class="select-classification">
<select
class="elm-select"
name="isophone-classification"
id="isophone-classification"
data-variant="outline"
v-model="selectedIsophoneFilterIndex"
>
<option value="all">Alle</option>
<option
v-for="(label, index) of isophoneLabels.keys()"
:value="isophoneLabels.get(label)"
:key="index"
>
{{ label }}
</option>
</select>
<label class="elm-label" for="isophone-classification">Einstufung</label>
</div>
</div>
</div>
</div>
<!-- Address table -->
<table>
<caption class="sr-only">
Betroffene Adressen im gewählten Bereich. Sortierung:
{{
sortDirection === 'desc' ? 'absteigend' : 'aufsteigend'
}}
nach
{{
sortKey
}}.
</caption>
<thead>
<tr>
<th
@click="sortBy('isophoneLevelDay')"
:class="getSortClass('isophoneLevelDay')"
class="center"
data-icon-before="day"
data-icon-variant-before="24-outline"
></th>
<th
@click="sortBy('isophoneLevelNight')"
:class="getSortClass('isophoneLevelNight')"
class="center"
data-icon-before="night"
data-icon-variant-before="24-outline"
></th>
<th @click="sortBy('postcode')" :class="getSortClass('postcode')">PLZ</th>
<th @click="sortBy('city')" :class="getSortClass('city')">Ort</th>
<th @click="sortBy('street')" :class="getSortClass('street')">Straße</th>
</tr>
</thead>
<tbody>
<tr
v-for="address in filteredAndSortedAddresses"
:key="address.id + address.lat + address.lon"
>
<td
:style="{
background:
address.isophoneLevelDay === undefined
? 'transparent'
: getIsophoneColor(address.isophoneLevelDay, 'day')
}"
class="isophone"
>
<span v-if="address.isophoneLevelDay !== undefined"
>> {{ address.isophoneLevelDay }}</span
>
</td>
<td
:style="{
background:
address.isophoneLevelNight === undefined
? 'transparent'
: getIsophoneColor(address.isophoneLevelNight, 'night')
}"
class="isophone"
>
<span v-if="address.isophoneLevelNight !== undefined"
>> {{ address.isophoneLevelNight }}</span
>
</td>
<td>{{ address.postcode }}</td>
<td>{{ address.city }}</td>
<td>
{{ address.street }} {{ address.housenumber }}
<div v-if="address.levels">
<small
><i>Ebenen: {{ address.levels }}</i></small
>
</div>
</td>
</tr>
</tbody>
</table>
<div class="wrapper">
<p v-if="!addressStore.loading && filteredAndSortedAddresses.length === 0">
Keine Adressen gefunden.
</p>
<button
v-if="!addressStore.loading"
class="elm-button inform"
data-variant="brand-primary"
data-width="full"
title="Betroffene Anwohnende informieren"
type="button"
@click="informPeople"
>
Betroffene Anwohnende informieren
</button>
</div>
</div>
</template>
<script setup lang="ts">
import { useAddressStore } from '../stores/addressStore'
import { computed, onMounted, ref, watch } from 'vue'
import { useConstructionSiteStore } from '../stores/constructionSiteStore'
import { storeToRefs } from 'pinia'
import { getIsophoneColor, isophoneLabels } from '../services/Isophones'
type SortKey = 'postcode' | 'street' | 'city' | 'isophoneLevelDay' | 'isophoneLevelNight'
type SortDirection = 'asc' | 'desc'
const addressStore = useAddressStore()
const constructionSiteStore = useConstructionSiteStore()
const { center, isophonesCalculated, isophonesDay, isophonesNight } =
storeToRefs(constructionSiteStore)
const lon = computed(() => center.value && center.value[0])
const lat = computed(() => center.value && center.value[1])
const selectedIsophoneFilterIndex = ref<{ day: number; night: number } | 'all'>('all')
// Fetch addresses when the component is mounted
onMounted(() => {
// addressStore.fetchAddresses(lat.value, lon.value, props.radius)
})
// Watch for changes in the input props and refetch data if they change
watch(
isophonesCalculated,
(newValue) => {
if (newValue && lon.value && lat.value) {
addressStore.fetchAddresses(lat.value, lon.value, {
isophonesDay: isophonesDay.value,
isophonesNight: isophonesNight.value
})
}
},
{ immediate: true }
)
// Search query for filtering addresses
const searchQuery = ref('')
// State for sorting
const sortKey = ref<SortKey>('postcode')
const sortDirection = ref<SortDirection>('asc')
function getSortClass(key: SortKey) {
return sortKey.value === key ? sortDirection.value : undefined
}
// Method to sort the table by a given column
// Method to sort the table by a given column
function sortBy(key: SortKey) {
if (sortKey.value === key) {
sortDirection.value = sortDirection.value === 'asc' ? 'desc' : 'asc'
} else {
sortKey.value = key
sortDirection.value = 'asc'
}
}
// Filter and sort addresses based on the search query and selected sort column
const filteredAndSortedAddresses = computed(() => {
const filteredAndSortedResult = [...addressStore.addresses]
// filter by category
.filter((address) => {
if (selectedIsophoneFilterIndex.value === 'all') {
return true
}
return (
address.isophoneLevelDay === selectedIsophoneFilterIndex.value.day ||
address.isophoneLevelNight === selectedIsophoneFilterIndex.value.night
)
})
// filter by test input
.filter((address) => {
const searchLower = searchQuery.value.toLowerCase()
return (
[address.street, address.housenumber, address.postcode, address.city]
.join(' ')
.toLowerCase()
.includes(searchLower) ||
address.postcode?.toString().includes(searchLower) ||
address.street?.toLowerCase().includes(searchLower) ||
address.city?.toLowerCase().includes(searchLower)
)
})
.sort((a, b) => {
const aValue = a[sortKey.value] || ''
const bValue = b[sortKey.value] || ''
if (aValue < bValue) return sortDirection.value === 'asc' ? -1 : 1
if (aValue > bValue) return sortDirection.value === 'asc' ? 1 : -1
return 0
})
return filteredAndSortedResult
})
function informPeople() {
console.log(filteredAndSortedAddresses.value)
}
</script>
<style scoped>
.search-input {
flex-grow: 1;
.elm-input {
width: 100%;
}
}
table {
width: 100%;
border-collapse: collapse;
}
thead tr {
vertical-align: bottom;
}
th {
padding: 0.5rem;
text-align: left;
background-color: #f4f4f4;
border-bottom: 2px solid #ddd;
position: relative;
}
th:not(.unsortable) {
cursor: pointer;
}
td {
padding: 0.5rem;
border-bottom: 1px solid #ddd;
}
th:hover {
background-color: #eaeaea;
}
th:after {
right: 0;
position: absolute;
margin-right: 0.5rem;
}
th.asc:after {
content: '↑';
}
th.desc:after {
content: '↓';
}
td.isophone {
text-wrap: nowrap;
font-size: 0.75rem;
color: white;
}
td.small {
max-width: 70px;
}
.numeric {
text-align: right;
}
.center {
text-align: center;
}
.filter {
display: flex;
gap: 0.5rem;
margin: 1rem 0.2rem;
}
.inform {
margin-top: 1rem;
}
.wrapper {
padding: 0 1rem;
}
.select-classification {
position: relative;
}
select {
max-width: 200px;
}
/* Layout für Desktop */
@media (min-width: 460px) {
select {
max-width: unset;
}
}
</style>