-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.html
121 lines (96 loc) · 2.8 KB
/
index.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
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Readwell</title>
<style>
body {
font-family: Georgia, serif;
margin: auto;
max-width: 400px;
text-align: center;
}
h1 {
text-align: center;
}
p {
text-align: left;
}
.result {
align-items: center;
border: 2px solid grey;
display: flex;
height: 50px;
justify-content: space-between;
margin: 20px auto;
overflow: hidden;
padding: 10px;
width: 300px;
}
.no-results {
text-align: center;
}
.title {
text-align: left;
}
</style>
</head>
<body>
<h1>BednMongo</h1>
<p>
Search for the best rooms and apartments, all powered by mongodb
</p>
<div>
<input id="title" placeholder="Search">
<br>
<input id="price_from" placeholder="Price from">
<input id="price_to" placeholder="Price to">
</div>
<button onclick="search()">Search</button>
<div id="results">
<!-- The results go here. -->
</div>
<script>
function showResults(results) {
const resultsNode = document.getElementById('results')
resultsNode.innerHTML = 'result'
if (!results.length) {
resultsNode.innerHTML = `<p class="no-results">No results</p>`
}
for (const result of results) {
const resultNode = document.createElement('div')
resultNode.className = 'result'
resultNode.innerHTML = `
<span class="title">
<a href="/api/results/${result._id}">${result.name}</a>
</span>
<span class="author">${result.summary}</span>
`
resultsNode.appendChild(resultNode)
}
}
function search() {
const search_input = document.getElementById('title')
const search_value = search_input.value
const pricefrom_input = document.getElementById('price_from')
const pricefrom_value = pricefrom_input.value
const priceto_input = document.getElementById('price_to')
const priceto_value = priceto_input.value
let queryString = ''
if (search_value) {
queryString = queryString + 'title=' + search_value + '&'
}
if (pricefrom_value) {
queryString = queryString + 'from=' + pricefrom_value + '&'
}
if (priceto_value) {
queryString = queryString + 'to=' + priceto_value
}
fetch('/api/search?' + queryString)
.then(response => response.json())
.then(json => showResults(json))
}
search()
</script>
</body>
</html>