-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearchTest.html
More file actions
605 lines (538 loc) · 25 KB
/
searchTest.html
File metadata and controls
605 lines (538 loc) · 25 KB
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
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Stewardship Workforce Training Program Database</title>
<!-- Add Bootstrap CSS link -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://js.arcgis.com/4.27/esri/themes/light/main.css" />
</head>
<style>
body {
background-color: #dee2e6;
}
#viewDiv {
grid-column: 2;
grid-row: 1;
padding: 0;
margin: 0;
height: 25vh;
width: 25vh;
border: 1px solid #dee2e6;
}
.parent {
display: grid;
grid-template-columns: 1fr 2fr;
grid-template-rows: auto 1fr auto;
grid-gap: 10px;
}
.header {
grid-column: 1 / 3;
grid-row: 1;
padding: 5px;
background-color: #ffffff
}
.search {
grid-column: 1;
grid-row: 2;
padding: 5px
}
.resList {
grid-column: 2;
grid-row: 2;
padding: 5px
}
.footer {
grid-column: 1 / 3;
grid-row: 3;
padding: 5px
}
.modal-body {
display: grid;
grid-template-columns: 2fr 1fr;
grid-template-rows: 1fr;
grid-gap: 0px;
min-height: 30vh
}
.info {
grid-column: 1;
grid-row: 1;
}
.modal-dialog {
max-width: 70vw !important
}
</style>
<body>
<div class="parent">
<div class="header">
<h1>Stewardship Workforce Training Program Database</h1>
</div>
<!-- No file input, using test JSON data directly in the script -->
<div class="search">
<div class="input-group">
<input type="text" class="form-control" id="searchInput" placeholder="Enter text to search">
<div class="input-group-append">
<button class="btn btn-primary" onclick="searchJson()">Search</button>
</div>
</div>
<div class="accordion" id="accordionExample">
<div id="trainData" class="accordion-item">
<h6 class="accordion-header" id="headingOne">
<button class="accordion-button" type="button" data-bs-toggle="collapse"
data-bs-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
Training Type
</button>
</h6>
<div id="collapseOne" class="accordion-collapse collapse show" aria-labelledby="headingOne">
<div class="accordion-body">
<div class="form-check"><input name="trainCheck" id="gis" class="form-check-input"
type="checkbox" value="apprenticeship" /> <label class="form-check-label"
for="gis">Apprenticeship</label></div>
<div class="form-check"><input name="trainCheck" id="training" class="form-check-input"
type="checkbox" value="internship" /> <label class="form-check-label"
for="internship">Internship</label>
</div>
<div class="form-check"><input name="trainCheck" id="drone" class="form-check-input"
type="checkbox" value="certificate" />
<label class="form-check-label" for="certificate">Certificate Program</label></div>
<div class="form-check"><input name="trainCheck" id="research" class="form-check-input"
type="checkbox" value="associate" /> <label class="form-check-label"
for="associate">Associate's Degree</label>
</div>
</div>
</div>
</div>
<div id="focusData" class="accordion-item">
<h6 class="accordion-header" id="headingTwo">
<button class="accordion-button" type="button" data-bs-toggle="collapse"
data-bs-target="#collapseTwo" aria-expanded="true" aria-controls="collapseTwo">
Stewardship Focus
</button>
</h6>
<div id="collapseTwo" class="accordion-collapse collapse" aria-labelledby="headingTwo">
<div class="accordion-body">
<div class="form-check"><input name="trainCheck" id="gis" class="form-check-input"
type="checkbox" value="waterways" /> <label class="form-check-label"
for="gis">Waterways</label>
</div>
<div class="form-check"><input name="trainCheck" id="training" class="form-check-input"
type="checkbox" value="fire management" /> <label class="form-check-label"
for="internship">Fire
Management</label>
</div>
<div class="form-check"><input name="trainCheck" id="drone" class="form-check-input"
type="checkbox" value="habitat restoration" />
<label class="form-check-label" for="certificate">Habitat Restoration</label></div>
<div class="form-check"><input name="trainCheck" id="research" class="form-check-input"
type="checkbox" value="forestry" /> <label class="form-check-label"
for="associate">Forestry</label>
</div>
<div class="form-check"><input name="trainCheck" id="gis" class="form-check-input"
type="checkbox" value="invasive plant control" /> <label class="form-check-label"
for="gis">Invasive Plant
Control</label></div>
<div class="form-check"><input name="trainCheck" id="training" class="form-check-input"
type="checkbox" value="climate resilience" /> <label class="form-check-label"
for="internship">Climate
Resilience</label>
</div>
<div class="form-check"><input name="trainCheck" id="drone" class="form-check-input"
type="checkbox" value="environmental education" />
<label class="form-check-label" for="certificate">Environmental Education</label></div>
<div class="form-check"><input name="trainCheck" id="research" class="form-check-input"
type="checkbox" value="sustainable farming practices" /> <label
class="form-check-label" for="associate">Sustainable Farming Practices</label>
</div>
</div>
</div>
</div>
<div id="skillData" class="accordion-item">
<h6 class="accordion-header" id="headingThree">
<button class="accordion-button" type="button" data-bs-toggle="collapse"
data-bs-target="#collapseThree" aria-expanded="true" aria-controls="collapseThree">
Skills
</button>
</h6>
<div id="collapseThree" class="accordion-collapse collapse" aria-labelledby="headingThree">
<div class="accordion-body">
<div class="form-check"><input name="trainCheck" id="gis" class="form-check-input"
type="checkbox" value="horticulture" /> <label class="form-check-label"
for="gis">Horticulture</label></div>
<div class="form-check"><input name="trainCheck" id="training" class="form-check-input"
type="checkbox" value="small equip" /> <label class="form-check-label"
for="internship">Small Equipment
Operation</label>
</div>
<div class="form-check"><input name="trainCheck" id="drone" class="form-check-input"
type="checkbox" value="research methods" />
<label class="form-check-label" for="certificate">Research Methods</label></div>
<div class="form-check"><input name="trainCheck" id="research" class="form-check-input"
type="checkbox" value="traditional indigenous knowledge" /> <label
class="form-check-label" for="associate">Traditional Indigenous Knowledge</label>
</div>
<div class="form-check"><input name="trainCheck" id="gis" class="form-check-input"
type="checkbox" value="project management" /> <label class="form-check-label"
for="gis">Project
Management</label></div>
<div class="form-check"><input name="trainCheck" id="training" class="form-check-input"
type="checkbox" value="restoration trade work" /> <label class="form-check-label"
for="internship">Restoration
Trade Work</label>
</div>
</div>
</div>
</div>
<div id="knowData" class="accordion-item">
<h6 class="accordion-header" id="headingFour">
<button class="accordion-button" type="button" data-bs-toggle="collapse"
data-bs-target="#collapseFour" aria-expanded="true" aria-controls="collapseFour">
Knowledge Level
</button>
</h6>
<div id="collapseFour" class="accordion-collapse collapse" aria-labelledby="headingFour">
<div class="accordion-body">
<div class="form-check"><input name="trainCheck" id="gis" class="form-check-input"
type="checkbox" value="beginner" /> <label class="form-check-label"
for="gis">Beginner</label></div>
<div class="form-check"><input name="trainCheck" id="training" class="form-check-input"
type="checkbox" value="intermediate" /> <label class="form-check-label"
for="internship">Intermediate</label>
</div>
</div>
</div>
</div>
<div id="wageData" class="accordion-item">
<h6 class="accordion-header" id="headingFive">
<button class="accordion-button" type="button" data-bs-toggle="collapse"
data-bs-target="#collapseFive" aria-expanded="true" aria-controls="collapseFive">
Wages/Stipends
</button>
</h6>
<div id="collapseFive" class="accordion-collapse collapse" aria-labelledby="headingFive">
<div class="accordion-body">
<div class="form-check"><input name="trainCheck" id="gis" class="form-check-input"
type="checkbox" value="yeswage" /> <label class="form-check-label"
for="gis">Yes</label></div>
<div class="form-check"><input name="trainCheck" id="training" class="form-check-input"
type="checkbox" value="nowage" /> <label class="form-check-label"
for="internship">No</label>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Display search results as Bootstrap list -->
<div class="resList">
<ul class="list-group" id="searchResults"></ul>
</div>
<div class="modal fade" id="infoModal" tabindex="-1" role="dialog" aria-labelledby="infoModalLabel"
aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="infoModalLabel">
</h5>
</div>
<div class="modal-body">
<div id="modalInfo" class="info">
</div>
<div id="viewDiv"></div>
</div>
</div>
</div>
</div>
</div>
<!-- Add Bootstrap JS script -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/fuse.js@6.6.2"></script>
<script src="https://js.arcgis.com/4.27/"></script>
<script>
//const Fuse = require('fuse.js');
let jsonData = []
let searchTerms = []
let searchResults = []
let searchArr = []
let checkTrain
let checkFocus
let checkSkill
let checkKnow
let checkWage
let fuse
let view
let simpleMarkerSymbol
let searchWidget
let searchStatus
let fuseOptions
require([
"esri/core/reactiveUtils",
"esri/Map",
"esri/views/MapView",
"esri/widgets/Search",
"esri/symbols/SimpleMarkerSymbol",
"esri/geometry/Point",
"esri/Graphic"
], (reactiveUtils, Map, MapView, Search, SimpleMarkerSymbol, Point, Graphic) => {
simpleMarkerSymbol = new SimpleMarkerSymbol({
angle: 0,
color: [255, 255, 255, 1],
outline: {
cap: "round",
color: [0, 122, 194, 1],
join: "round",
miterLimit: 1,
style: "solid",
width: 2
},
path: "undefined",
size: 12,
style: "circle",
xoffset: 0,
yoffset: 0
});
const map = new Map({
basemap: "topo-vector"
});
view = new MapView({
scale: 123456789,
container: "viewDiv",
map: map
});
view.ui.remove(["attribution", "zoom"]);
searchWidget = new Search({
view: view,
popupEnabled: false
});
function stopEvtPropagation(event) {
event.stopPropagation();
}
// disable mouse wheel scroll zooming on the view
view.on("mouse-wheel", stopEvtPropagation);
// disable zooming via double-click on the view
view.on("double-click", stopEvtPropagation);
// disable zooming out via double-click + Control on the view
view.on("double-click", ["Control"], stopEvtPropagation);
// disables pinch-zoom and panning on the view
view.on("drag", stopEvtPropagation);
// disable the view's zoom box to prevent the Shift + drag
// and Shift + Control + drag zoom gestures.
view.on("drag", ["Shift"], stopEvtPropagation);
view.on("drag", ["Shift", "Control"], stopEvtPropagation);
// prevents zooming with the + and - keys
view.on("key-down", (event) => {
const prohibitedKeys = [
"+",
"-",
"Shift",
"_",
"=",
"ArrowUp",
"ArrowDown",
"ArrowRight",
"ArrowLeft"
];
const keyPressed = event.key;
if (prohibitedKeys.indexOf(keyPressed) !== -1) {
event.stopPropagation();
}
});
searchWidget.search("fresno");
reactiveUtils.when(() => !view?.updating, () => {
if (view.graphics.items[0]) {
view.graphics.items[0].symbol = simpleMarkerSymbol
}
//let newExt = view.extent.expand(1.5)
view.zoom = 10
})
});
$.getJSON(
"https://sheets.googleapis.com/v4/spreadsheets/1xf2K2UQZAc_shQT5RIZAkfY93smNv33e0cnyr5WFBww/values/Form Responses 1?alt=json&key=AIzaSyBljC7y8axtIJMi5FXbTK655sdUZQGHSw0",
function (data) {
$.each(data.values, function (key, val) {
if (key > 0) {
t = {
id: key,
date: val[0],
name: val[1],
org: val[2],
website: val[3],
mission: val[4],
address: val[5] + " " + val[6] + " " + val[7],
city: val[6],
zip: val[7],
train: val[8],
focus: val[9],
bioregion: val[10],
hours: val[11],
weeks: val[12],
tags: val[1] + ", " + val[2] + ", " + val[8] + ", " + val[9] + ", " + val[
13] + ", " + val[14] + ", " + val[16] + "wage"
}
jsonData.push(t);
}
});
searchResults = [...jsonData]; // Initialize search results with all data on page load
searchJson()
fuseOptions = {
isCaseSensitive: false,
// includeScore: false,
// shouldSort: true,
// includeMatches: true,
// findAllMatches: true,
// minMatchCharLength: 1,
// location: 0,
threshold: 0.25,
// distance: 100,
useExtendedSearch: true,
ignoreLocation: true,
// ignoreFieldNorm: false,
// fieldNormWeight: 1,
keys: [
"tags"
]
};
fuse = new Fuse(jsonData, fuseOptions);
})
// Test JSON data to search on
/* const jsonData = [{
"id": 1,
"name": "John Doe",
"age": 30,
"email": "john@example.com"
}, {
"id": 2,
"name": "Jane Smith",
"age": 25,
"email": "jane@example.com"
}, {
"id": 3,
"name": "Bob Johnson",
"age": 35,
"email": "bob@example.com"
}
// Add more test data as needed
]; */
// Function to search JSON data and display results
function searchJson() {
let searchQuery = document.getElementById("searchInput").value.trim().toLowerCase();
searchArr = []
checkTrain = ''
checkFocus = ''
checkSkill = ''
checkKnow = ''
checkWage = ''
if (searchQuery != '') {
searchArr.push(searchQuery)
}
$('#trainData').find('.form-check-input').each(function () {
if (this.checked) {
checkTrain += this.value + "|"
}
})
if (checkTrain != "") {
searchArr.push(checkTrain.slice(0, -1))
}
$('#focusData').find('.form-check-input').each(function () {
if (this.checked) {
checkFocus += this.value + "|"
}
})
if (checkFocus != "") {
searchArr.push(checkFocus.slice(0, -1))
}
$('#skillData').find('.form-check-input').each(function () {
if (this.checked) {
checkSkill += this.value + "|"
}
})
if (checkSkill != "") {
searchArr.push(checkSkill.slice(0, -1))
}
$('#knowData').find('.form-check-input').each(function () {
if (this.checked) {
checkKnow += this.value + "|"
}
})
if (checkKnow != "") {
searchArr.push(checkKnow.slice(0, -1))
}
$('#wageData').find('.form-check-input').each(function () {
if (this.checked) {
checkWage += this.value + "|"
}
})
if (checkWage != "") {
searchArr.push(checkWage.slice(0, -1))
}
/* if (checkSearch) {
searchQuery = checkSearch
} */
// If the search query is empty, show all results
/* if (!searchQuery) {
searchStatus = 0 */
searchResults = [...jsonData];
fuseTest(searchResults)
/* } else {
searchStatus = 0
// Filter JSON data based on search query
//searchResults = fuse.search(searchQuery)
fuseTest(searchResults)
} */
// Display filtered search results as Bootstrap list
const searchResultsList = document.getElementById("searchResults");
searchResultsList.innerHTML = "";
if (searchResults.length === 0) {
searchResultsList.innerHTML = "<li class='list-group-item'>No results found.</li>";
} else {
$.each(searchResults, (key, val) => {
const listItem = document.createElement("li");
listItem.classList.add("list-group-item");
listItem.id = val.id
listItem.innerHTML = '<b>' + val.name + '</b><br>Organization: ' + val.org +
'<br>Address: ' + val.address
searchResultsList.appendChild(listItem);
});
}
}
function searchLoop(data, search) {
const fuse1 = new Fuse(data, fuseOptions);
// Perform the first search
const searchResults1 = fuse1.search(search);
// Filter the results to get the data for the second search
const filteredData = searchResults1.map((result) => result.item);
return filteredData
}
function fuseTest(data) {
$.each(searchArr, function (key, val) {
data = searchLoop(data, val)
})
searchResults = data
}
function getObject(n) {
const targetName = n; // The value you want to search for
const selectedObject = jsonData.find(item => item.id === targetName);
return selectedObject
}
// Add input event listener to trigger search as you type
document.getElementById("searchInput").addEventListener("input", searchJson);
$('input[name="trainCheck"]').on("click", function () {
searchJson()
})
$(document).ready(() => {
$("ul").on("click", "li", function () {
selectObject = getObject(parseInt(this.id))
searchWidget.search(selectObject.address)
$('#infoModalLabel').text(selectObject.name);
$('#modalInfo').html('<b>Website:</b> <a href="' + selectObject.website +
'" target="_blank">' + selectObject.website + '</a><br><b>Mission:</b> ' +
selectObject.mission +
'<br><b>Training Type:</b> ' + selectObject.train +
'<br><b>Stewardship Focus:</b> ' + selectObject.focus);
$('#infoModal').modal('show');
});
})
</script>
</body>
</html>