-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGlossary.html
296 lines (274 loc) · 10.1 KB
/
Glossary.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Glossary</title>
<script src="https://cdn.jsdelivr.net/npm/@supabase/supabase-js"></script>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 20px;
background-color: #f9f9f9;
color: #333;
line-height: 1.6;
}
.container {
display: flex;
max-width: 1200px;
margin: 0 auto;
gap: 20px;
flex-wrap: wrap;
}
.section {
background-color: #ffffff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
margin-bottom: 20px;
}
.add-section {
flex: 1;
min-width: 300px;
}
.glossary-section {
flex: 2;
min-width: 500px;
}
.search-section {
flex: 1;
min-width: 300px;
}
h1 {
color: #2c3e50;
font-size: 32px;
margin-bottom: 30px;
}
h2 {
color: #34495e;
font-size: 24px;
margin-bottom: 20px;
border-bottom: 2px solid #eee;
padding-bottom: 10px;
}
input[type="text"],
textarea {
width: 100%;
padding: 10px;
margin-bottom: 15px;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 16px;
box-sizing: border-box;
}
textarea {
height: 100px;
resize: vertical;
font-family: Arial, sans-serif;
}
button, input[type="submit"] {
background-color: #3498db;
color: white;
padding: 10px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
transition: background-color 0.3s ease;
}
button:hover, input[type="submit"]:hover {
background-color: #2980b9;
}
.delete-button {
background-color: #e74c3c;
padding: 5px 10px;
font-size: 14px;
}
.delete-button:hover {
background-color: #c0392b;
}
.glossary-item {
border-bottom: 1px solid #eee;
padding: 15px 0;
display: flex;
justify-content: space-between;
align-items: flex-start;
}
.glossary-item:last-child {
border-bottom: none;
}
.term {
font-weight: bold;
margin-right: 10px;
color: #2c3e50;
}
.definition {
flex: 1;
margin-right: 20px;
line-height: 1.5;
}
.letter-section {
margin-bottom: 30px;
}
.letter-header {
font-size: 24px;
color: #2c3e50;
margin-bottom: 15px;
padding-bottom: 5px;
border-bottom: 2px solid #3498db;
}
#notification {
position: fixed;
top: 20px;
right: 20px;
padding: 10px 20px;
border-radius: 4px;
display: none;
color: white;
z-index: 1000;
}
.success {
background-color: #2ecc71;
}
.error {
background-color: #e74c3c;
}
</style>
</head>
<body>
<div id="notification"></div>
<h1>Glossary</h1>
<div class="container">
<div class="section add-section">
<h2>Add New Term</h2>
<form id="glossaryForm">
<input type="text" id="term" placeholder="Term" required>
<textarea id="definition" placeholder="Definition" required></textarea>
<button type="submit">Add Term</button>
</form>
</div>
<div class="section glossary-section">
<h2>Glossary List</h2>
<div id="glossaryList"></div>
</div>
<div class="section search-section">
<h2>Search</h2>
<input type="text" id="searchInput" placeholder="Type to search...">
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
// Initialize Supabase
const { createClient } = supabase;
const supabaseClient = createClient(
'https://itpqpqtvtpdyraookiqf.supabase.co',
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Iml0cHFwcXR2dHBkeXJhb29raXFmIiwicm9sZSI6ImFub24iLCJpYXQiOjE3Mjk4NTc5MjYsImV4cCI6MjA0NTQzMzkyNn0.WVVtHy1spmEjl3_A2i8jEETyzgxmyAFM7yGhJ3oSp5w'
);
const glossaryForm = document.getElementById('glossaryForm');
const glossaryList = document.getElementById('glossaryList');
const searchInput = document.getElementById('searchInput');
const notification = document.getElementById('notification');
let glossary = [];
function showNotification(message, type) {
notification.textContent = message;
notification.className = type;
notification.style.display = 'block';
setTimeout(() => {
notification.style.display = 'none';
}, 3000);
}
async function loadGlossary() {
try {
const { data, error } = await supabaseClient
.from('glossary_entries')
.select('*')
.order('term');
if (error) throw error;
glossary = data || [];
updateGlossaryDisplay();
} catch (error) {
console.error('Error loading glossary:', error);
showNotification('Error loading glossary', 'error');
}
}
glossaryForm.addEventListener('submit', async function(event) {
event.preventDefault();
const term = document.getElementById('term').value.trim();
const definition = document.getElementById('definition').value.trim();
try {
const { error } = await supabaseClient
.from('glossary_entries')
.insert([{ term, definition }]);
if (error) throw error;
glossaryForm.reset();
showNotification('Term added successfully', 'success');
await loadGlossary();
} catch (error) {
console.error('Error adding term:', error);
showNotification('Error adding term', 'error');
}
});
searchInput.addEventListener('input', updateGlossaryDisplay);
function updateGlossaryDisplay() {
const searchTerm = searchInput.value.toLowerCase();
const filteredGlossary = glossary
.filter(item =>
item.term.toLowerCase().includes(searchTerm) ||
item.definition.toLowerCase().includes(searchTerm)
)
.sort((a, b) => a.term.localeCompare(b.term));
glossaryList.innerHTML = '';
const sections = {};
filteredGlossary.forEach(item => {
const firstLetter = item.term[0].toUpperCase();
if (!sections[firstLetter]) {
sections[firstLetter] = [];
}
sections[firstLetter].push(item);
});
Object.keys(sections).sort().forEach(letter => {
const sectionElement = document.createElement('div');
sectionElement.className = 'letter-section';
sectionElement.innerHTML = `<div class="letter-header">${letter}</div>`;
sections[letter].forEach(item => {
const itemElement = document.createElement('div');
itemElement.className = 'glossary-item';
itemElement.innerHTML = `
<div class="definition">
<span class="term">${item.term}:</span>
${item.definition}
</div>
<button class="delete-button" onclick="deleteEntry(${item.id})">Delete</button>
`;
sectionElement.appendChild(itemElement);
});
glossaryList.appendChild(sectionElement);
});
if (filteredGlossary.length === 0) {
glossaryList.innerHTML = '<p style="text-align: center; color: #666;">No terms found.</p>';
}
}
// Make deleteEntry function global so the onclick handler can find it
window.deleteEntry = async function(id) {
if (confirm("Are you sure you want to delete this entry?")) {
try {
const { error } = await supabaseClient
.from('glossary_entries')
.delete()
.eq('id', id);
if (error) throw error;
showNotification('Term deleted successfully', 'success');
await loadGlossary();
} catch (error) {
console.error('Error deleting term:', error);
showNotification('Error deleting term', 'error');
}
}
}
// Initial load
loadGlossary();
});
</script>
</body>
</html>