-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest copy.html
224 lines (210 loc) · 7.13 KB
/
test copy.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ROR Lookup</title>
<!-- Include Alpine.js -->
<script src="https://unpkg.com/[email protected]/dist/cdn.min.js" defer></script>
<!-- Include HTMX -->
<script src="https://unpkg.com/[email protected]"
integrity="sha384-0895/pl2MU10Hqc6jd4RvrthNlDiE9U1tWmX7WRESftEDRosgxNsQG/Ze9YMRzHq"
crossorigin="anonymous"></script>
<script src="https://unpkg.com/[email protected]/debug.js"></script>
</head>
<body>
<div x-data="rorLookup">
<!-- Input for organization name -->
<label for="organization">Enter Organization Name:</label>
<input id="organization" x-model="orgName" @input.debounce.500ms="fetchRorData"
placeholder="Type organization name">
<!-- Error message if request fails -->
<p x-show="error" class="error" x-text="error"></p>
<!-- List of matching organizations with checkboxes -->
<div x-show="matches.length > 0">
<h3>Matching Organizations:</h3>
<table>
<thead>
<tr>
<th>Name</th>
<th>Country</th>
<th></th>
</tr>
</thead>
<tbody>
<template x-for="org in matches" :key="org.id">
<tr>
<td x-text="org.name"></td>
<td x-text="org.country?.country_name || 'N/A'"></td>
<td> <button hx-post="/" hx-vals="{'org_id': 1}" hx-swap="none">
Add
</button></td>
</tr>
</template>
</tbody>
</table>
</div>
</div>
<!-- <td><input type="radio" name="organization" :value="org.id" x-model="selectedOrgId"
@change="setSelectedOrg(org)"></td> -->
<script>
function rorLookup() {
return {
orgName: '',
matches: [],
selectedOrgId: '',
selectedOrg: {},
error: null,
// Watch for changes in selectedOrgId and update selectedOrg details
init() {
this.$watch('selectedOrgId', (newValue) => {
if (newValue) {
this.selectedOrg = this.matches.find(org => org.id === newValue) || {}
} else {
this.selectedOrg = {}
}
})
},
// Fetch ROR data based on orgName input
async fetchRorData() {
if (this.orgName.length < 3) {
this.matches = []
return
}
this.error = null
const url = `https://api.ror.org/organizations?query=${encodeURIComponent(this.orgName)}`
try {
// const response = await fetch(url)
// if (!response.ok) {
// throw new Error('Error fetching ROR data')
// }
const data = [
{
"id": "https://ror.org/04z8jg394",
"name": "Helmholtz Centre Potsdam - GFZ German Research Centre for Geosciences",
"email_address": "",
"ip_addresses": [],
"established": 1992,
"types": [
"Facility"
],
"relationships": [
{
"label": "Helmholtz Association of German Research Centres",
"type": "Parent",
"id": "https://ror.org/0281dp749"
},
{
"label": "Research Institute For Sustainability – Helmholtz Centre Potsdam",
"type": "Child",
"id": "https://ror.org/01vvnmw35"
}
],
"addresses": [
{
"lat": 52.39886,
"lng": 13.06566,
"state": null,
"state_code": null,
"city": "Potsdam",
"geonames_city": {
"id": 2852458,
"city": "Potsdam",
"geonames_admin1": {
"name": "Brandenburg",
"id": 2945356,
"ascii_name": "Brandenburg",
"code": "DE.11"
},
"geonames_admin2": {
"name": null,
"id": null,
"ascii_name": null,
"code": "DE.11.00"
},
"license": {
"attribution": "Data from geonames.org under a CC-BY 3.0 license",
"license": "http://creativecommons.org/licenses/by/3.0/"
},
"nuts_level1": {
"name": null,
"code": null
},
"nuts_level2": {
"name": null,
"code": null
},
"nuts_level3": {
"name": null,
"code": null
}
},
"postcode": null,
"primary": false,
"line": null,
"country_geonames_id": 2921044
}
],
"links": [
"https://www.gfz-potsdam.de"
],
"aliases": [],
"acronyms": [
"GFZ"
],
"status": "active",
"wikipedia_url": "https://en.wikipedia.org/wiki/GFZ_German_Research_Centre_for_Geosciences",
"labels": [
{
"label": "Helmholtz-Zentrum Potsdam - Deutsches GeoForschungsZentrum GFZ",
"iso639": "de"
}
],
"country": {
"country_name": "Germany",
"country_code": "DE"
},
"external_ids": {
"ISNI": {
"preferred": null,
"all": [
"0000 0000 9195 2461"
]
},
"FundRef": {
"preferred": "501100010956",
"all": [
"501100010956"
]
},
"Wikidata": {
"preferred": null,
"all": [
"Q1205654"
]
},
"GRID": {
"preferred": "grid.23731.34",
"all": "grid.23731.34"
}
}
}
]
// const data = await response.json()
// this.matches = data.items
this.matches = data
} catch (error) {
this.error = error.message
this.matches = []
}
},
// Set the selected organization details
setSelectedOrg(org) {
this.selectedOrgId = org.id
this.selectedOrg = org
}
}
}
</script>
</body>
</html>