-
Notifications
You must be signed in to change notification settings - Fork 0
/
groups_edit.html
478 lines (415 loc) · 20.2 KB
/
groups_edit.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
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
<!--
This HTML file represents the Groups Management page of the AthletiLink application.
It contains the necessary HTML structure, styles, and scripts to manage groups.
The page includes a search bar, a list of groups, and modals for adding, updating, and deleting groups.
Users can search for groups, add new groups, update existing groups, and delete groups.
The file also includes external dependencies such as Bootstrap, Font Awesome, and jQuery.
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<title>Groups Management</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
<link rel="stylesheet" href="assets/css/styles.css">
<link rel="icon" type="image/x-icon" href="/assets/images/Favicon/Regular/favicon-32x32.png" />
<script src="assets/js/image_upload.js"></script>
<style>
#sports-cards-container {
display: flex;
flex-wrap: wrap;
}
#save-button-container {
display: none;
}
input.form-check-input.default-checkboxs {
width: 30px;
height: 30px;
border: 2px solid #ffffff;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
}
.search-container {
width: 50%;
margin: 0 auto;
}
.input-group-text {
cursor: pointer;
}
.add-group-btn {
margin-left: 10px;
}
</style>
</head>
<body>
<h1 class="d-flex justify-content-center">Groups Management</h1>
<div class="search-container input-group mb-3 mt-3">
<div class="input-group-prepend">
<button class="btn btn-dark dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true"
aria-expanded="false" value="group_name" id="dropdownButton">By Group Name <i class="fa fa-caret-down"
aria-hidden="true"></i></button>
<div class="dropdown-menu">
<a class="dropdown-item" value="group_name">By Group Name</a>
<a class="dropdown-item" value="active">By Active Groups</a>
<a class="dropdown-item" value="inactive">By Inactive Groups</a>
</div>
</div>
<input type="text" class="form-control" id="searchText" placeholder="Search everything...">
<div class="input-group-append">
<span class="input-group-text" id="clearSearch">
<i class="fa fa-times" aria-hidden="true"></i>
</span>
</div>
<button class="btn btn-primary add-group-btn" data-toggle="modal" data-target="#addGroupModal">Add
Group</button>
</div>
<div id="main-container" class="container mt-5 effect-fadeIn" style="margin-bottom: 80px;">
<div class="row" id="sports-cards-container">
<!-- Groups rendered here! -->
</div>
<div id="close-icon" class="position-fixed" style="top: 30px; right: 30px; font-size: 20px; cursor: pointer;">
<a href="control_panel.html" style="text-decoration: none;"><span class="fa-stack fa-lg"
style="color:#343a40;">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-times fa-stack-1x fa-inverse"></i>
</span></a>
</div>
</div>
<div class="modal fade" id="deleteGroupModal" tabindex="-1" role="dialog" aria-labelledby="deleteGroupModalLabel"
aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="deleteGroupModalLabel">Confirm Deletion</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
Are you sure you want to delete this group?
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-danger" id="confirmDeleteBtn">Delete</button>
</div>
</div>
</div>
</div>
<div class="modal fade" id="addGroupModal" tabindex="-1" role="dialog" aria-labelledby="addGroupModalModalLabel"
aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="addGroupModalLabel">Add Group</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="form-group">
<label for="group_name">Group Name</label>
<input type="text" id="group_name" name="group_name" class="form-control" required />
</div>
<div class="form-group">
<label for="profilePicture">Cover Picture</label>
<div class="custom-file">
<input type="file" class="custom-file-input" id="profilePicture" name="profilePicture"
accept="image/*" onchange="fileChange()" required>
<label class="custom-file-label" id="profilePictureLabel" for="profilePicture">Choose
file</label>
</div>
</div>
<div class="form-group">
<div class="progress" style="margin-top: 10px; display: none;">
<div class="progress-bar" role="progressbar" id="uploadProgressBar" style="width: 0%;"
aria-valuenow="0" aria-valuemin="0" aria-valuemax="100">0%</div>
</div>
</div>
<input type="hidden" id="profilePictureUrl" name="profilePictureUrl">
<div class="form-group">
<label for="status">Status</label>
<select id="status" name="status" class="form-control" required>
<option value="active">Active</option>
<option value="inactive">Inactive</option>
</select>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" id="AddGroupBtn">Add</button>
</div>
</div>
</div>
</div>
<div class="modal fade" id="updateGroupModal" tabindex="-1" role="dialog"
aria-labelledby="updateGroupModalModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="updateGroupModalLabel">Update Group</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="form-group">
<label for="group_name_update">Group Name</label>
<input type="text" id="group_name_update" name="group_name_update" class="form-control" required
disabled />
</div>
<div class="form-group">
<label for="profilePicture2">Cover Picture</label>
<div class="custom-file">
<input type="file" class="custom-file-input" id="profilePicture2" name="profilePicture2"
accept="image/*" onchange="fileChange('2')" required>
<label class="custom-file-label" id="profilePictureLabel2" for="profilePicture2">Choose
file</label>
</div>
</div>
<div class="form-group">
<div class="progress" style="margin-top: 10px; display: none;">
<div class="progress-bar" role="progressbar" id="uploadProgressBar2" style="width: 0%;"
aria-valuenow="0" aria-valuemin="0" aria-valuemax="100">0%</div>
</div>
</div>
<input type="hidden" id="profilePictureUrl2" name="profilePictureUrl2">
<div class="form-group">
<label for="status_update">Status</label>
<select id="status_update" name="status_update" class="form-control" required>
<option value="active">Active</option>
<option value="inactive">Inactive</option>
</select>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" id="updateGroupBtn">Save Changes</button>
</div>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
</body>
</html>
<script>
var uploaded = false;
document.addEventListener("DOMContentLoaded", function () {
let groups;
fetchGroups();
if (uploaded) {
this.submit();
}
$('.dropdown-item').click(function () {
console.log($(this).attr('value'));
var selectedValue = $(this).attr('value');
$('#dropdownButton').html($(this).text() + ' <i class="fa fa-caret-down" aria-hidden="true"></i>');
$('#dropdownButton').attr('value', selectedValue);
searchGroups(selectedValue); // Add this line to pass the selected value
});
$("#clearSearch").on("click", function () {
// Clear the search input
$("#searchText").val("");
const selectedValue = $("#dropdownButton").attr('value');
// Filter users after clearing search input
searchGroups(selectedValue);
});
$("#searchText").on("input", function () {
const selectedValue = $("#dropdownButton").attr('value');
searchGroups(selectedValue);
});
$("#AddGroupBtn").on("click", function () {
const newGroup = {
group_name: $("#group_name").val(),
pic: $("#profilePictureUrl").val(),
status: $("#status").val(),
};
// Send POST request to add group
fetch(`http://localhost:5500/create_group`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(newGroup),
})
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
return response.json();
})
.then(data => {
console.log("Group added successfully:", data);
fetchGroups();
$('#addGroupModal').modal('hide');
})
.catch(error => {
console.error("Error adding group:", error);
});
});
// Function to handle file upload
function searchGroups(criteria) {
const searchText = $("#searchText").val().toLowerCase();
const filteredGroups = filterByText(searchText, criteria);
clearGroups();
createSportsCards(filteredGroups);
}
// Function to filter users by text
function filterByText(text, criteria) {
const lowercaseText = text.toLowerCase();
console.log(`Filtering by ${criteria} for ${text}`);
if (criteria == "active") {
return groups.filter(function (group) {
const value = group["status"].toLowerCase();
const value_name = group["group_name"].toLowerCase();
return value == "active" && value_name.includes(text);
});
}
if (criteria == "inactive") {
return groups.filter(function (group) {
const value = group["status"].toLowerCase();
const value_name = group["group_name"].toLowerCase();
return value == "inactive" && value_name.includes(text);
});
}
if (criteria == "group_name") {
return groups.filter(function (group) {
const value = group["group_name"].toLowerCase();
return value.includes(text);
});
}
}
//// Clear the search input
function createSportsCards(groups) {
var mainContainer = document.getElementById("main-container");
var container = document.getElementById("sports-cards-container");
groups.forEach(function (group) {
var isChecked = group.status == "active" ? true : false;
var cardDiv = document.createElement("div");
var statusDot = document.createElement("div");
statusDot.className = "status-dot";
statusDot.style.backgroundColor = group.status == "active" ? "green" : "red";
statusDot.style.zIndex = "100";
var deleteIcon = document.createElement("button");
deleteIcon.className = "btn btn-danger ml-auto mt-2 mr-2 deleteIconGroups";
deleteIcon.style.display = "inline";
deleteIcon.style.zIndex = "100";
deleteIcon.innerHTML = '<i class="fa fa-times"></i>';
deleteIcon.addEventListener("click", function () {
console.log(group._id);
deleteGroup(group._id);
});
var updateIcon = document.createElement("button");
updateIcon.className = "btn btn-info ml-auto mt-2 mr-2 updateIconGroups";
updateIcon.style.display = "inline";
updateIcon.style.zIndex = "100";
updateIcon.innerHTML = '<i class="fa fa-pencil fa-xs"></i>';
updateIcon.addEventListener("click", function () {
updateGroup(group._id);
});
cardDiv.className = "col-md-3 mb-4";
var card = document.createElement("div");
card.className = "card";
card.style.cursor = "pointer";
card.style.backgroundColor = "white";
card.style.color = "white";
card.style.height = "300px";
card.style.border = "1px solid #dee2e6";
// Set background image if available
if (group.pic) {
card.style.backgroundImage = `url(${group.pic})`;
}
else {
card.style.backgroundImage = `url('https://upload.wikimedia.org/wikipedia/commons/thumb/6/65/No-Image-Placeholder.svg/1665px-No-Image-Placeholder.svg.png')`;
}
card.style.backgroundSize = "cover";
card.style.backgroundPosition = "center";
var cardBody = document.createElement("div");
cardBody.className = "card-body d-flex flex-column align-items-center justify-content-center";
var cardTitle = document.createElement("div");
cardTitle.className = "card-title";
cardTitle.style = "font-size: 40px;";
// Add black shadow to the title
cardTitle.style.textShadow = "2px 2px 2px black";
cardTitle.textContent = group.group_name;
var formCheckDiv = document.createElement("div");
cardBody.appendChild(cardTitle);
cardBody.appendChild(formCheckDiv);
card.appendChild(cardBody);
cardDiv.appendChild(card);
cardDiv.appendChild(deleteIcon);
cardDiv.appendChild(updateIcon);
cardDiv.appendChild(statusDot);
container.appendChild(cardDiv);
mainContainer.appendChild(container);
});
}
// Function to clear the groups container
function clearGroups() {
console.log("clearGroups");
var groupContainer = document.getElementById("sports-cards-container");
groupContainer.innerHTML = "";
console.log("DONE");
}
// Function to fetch groups from the server
function fetchGroups() {
$.get("http://localhost:5500/groups", function (data) {
groups = data.groups;
clearGroups();
createSportsCards(groups);
});
}
window.updateGroup = function (group_id) {
console.log(`Update group with ID: ${group_id}`);
const groupToUpdate = groups.find(group => group._id === group_id);
console.log(groupToUpdate);
$("#group_name_update").val(groupToUpdate.group_name);
$("#profilePictureUrl2").val(groupToUpdate.pic);
$("#status_update").val(groupToUpdate.status);
$('#updateGroupModal').modal('show');
$("#updateGroupBtn").off('click').on("click", function () {
const updatedGroup = {
group_name: $("#group_name_update").val(),
pic: $("#profilePictureUrl2").val(),
status: $("#status_update").val(),
};
// Send PUT request to update group
fetch(`http://localhost:5500/update_group/${group_id}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(updatedGroup),
})
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
return response.json();
})
.then(data => {
console.log("Group updated successfully:", data);
fetchGroups();
$('#updateGroupModal').modal('hide');
})
.catch(error => {
console.error("Error updating group:", error);
});
});
};
window.deleteGroup = function (group_id) {
console.log(`Delete group with ID: ${group_id}`);
$('#deleteGroupModal').modal('show');
str_group_id = group_id.toString();
$('#confirmDeleteBtn').off('click').on('click', function () {
console.log(`Delete group with ID: ${group_id}`);
$.post(`http://localhost:5500/delete_group/${str_group_id}`, function (data) {
fetchGroups();
$('#deleteGroupModal').modal('hide');
});
});
};
});
</script>