diff --git a/CTF/CTF-Frontend/src/app/admin-profile/admin-profile.component.html b/CTF/CTF-Frontend/src/app/admin-profile/admin-profile.component.html
index ce3cb03..2545817 100644
--- a/CTF/CTF-Frontend/src/app/admin-profile/admin-profile.component.html
+++ b/CTF/CTF-Frontend/src/app/admin-profile/admin-profile.component.html
@@ -40,9 +40,7 @@
you can search for specific students
- or filter them how you would like. For searching a specific Student, make sure
-
- Name is selected in the dropdown
+ or filter them how you would like
diff --git a/CTF/CTF-Frontend/src/app/admin-profile/admin-profile.component.ts b/CTF/CTF-Frontend/src/app/admin-profile/admin-profile.component.ts
index adf2a45..ff58231 100644
--- a/CTF/CTF-Frontend/src/app/admin-profile/admin-profile.component.ts
+++ b/CTF/CTF-Frontend/src/app/admin-profile/admin-profile.component.ts
@@ -23,7 +23,6 @@ export class AdminProfileComponent implements OnInit{
subs: Submission[] = []
flags: Flag[] = []
selectedContest: string = '';
- sortOption: string = '';
constructor(private router: Router, private adminProfileService: AdminProfileService){}
emailToDelete = '';
searchText: string = '';
@@ -138,22 +137,18 @@ export class AdminProfileComponent implements OnInit{
this.emailToDelete = '';
}
+ // sort the students table
sortTable(): void{
+
+ // get the name and the option selected
const name = this.searchText.trim().toLowerCase();
- const option = this.sortOption;
- let sorted = [...this.users];
+ let optionElement = document.getElementById('Options') as HTMLSelectElement;
+ let option = optionElement.value;
- if((option === 'Name (A->Z)' || option === 'Name (Z->A)') && name !== ''){
- const targetIndex = sorted.findIndex(s => s.Name.toLowerCase() === name);
- if(targetIndex !== -1){
- const student = sorted.splice(targetIndex, 1)[0];
- sorted.unshift(student);
- }
- else{
- alert('Student is not in database');
- }
- }
+
+ let sorted = this.users;
+ // sort the students first
if(option === 'Name (A->Z)'){
sorted.sort((a, b) => a.Name.localeCompare(b.Name));
}
@@ -164,8 +159,29 @@ export class AdminProfileComponent implements OnInit{
sorted.sort((a, b) => b.Flags - a.Flags);
}
else if(option === 'Flags (L->H)'){
- sorted.sort((b, a) => a.Flags - b.Flags);
+ sorted.sort((b, a) => b.Flags - a.Flags);
+ }
+
+ // search for specific student
+ if (name !== '') {
+ let targetIndex = sorted.findIndex(s => s.Name.toLowerCase() === name);
+
+ // if no match of student then look for partial
+ if (targetIndex === -1) {
+ targetIndex = sorted.findIndex(s => s.Name.toLowerCase().includes(name));
+ }
+
+ // student in database
+ if(targetIndex !== -1){
+ const [student] = sorted.splice(targetIndex, 1);
+ sorted.unshift(student);
+ }
+ else {
+ alert('Student is not in the database');
+ }
}
+
+ // display sorted array
this.displayedUsers = sorted;
}