diff --git a/CaPPMS/Pages/StudentReviews/ManageStudents.razor b/CaPPMS/Pages/StudentReviews/ManageStudents.razor index f042918..849ff65 100644 --- a/CaPPMS/Pages/StudentReviews/ManageStudents.razor +++ b/CaPPMS/Pages/StudentReviews/ManageStudents.razor @@ -10,110 +10,46 @@ @namespace CaPPMS.Pages.StudentReviews @attribute [Authorize] -@page "/ManageStudents" +@page "/ManageStudents/{*Cohort}" Manage Students - +@if (!consentHandler.User.IsAdmin()) +{ +

User not authorized.

+} -@if (availableClasses.Count() == 0 || !consentHandler.User.IsAdmin()) +@if (availableClasses.Count() == 0) {

No classes available. Please add one.

return; } -
+
-
- Student Directory. -
-
- Class Context: - - - - @foreach (ClassInformation classInfo in availableClasses) - { - - } - +
+ Student Directory. +
+
+ Class Context: + + + + @foreach (ClassInformation classInfo in availableClasses) + { + + } + - -  Upload Class CSV:  -
+ +  Upload Class CSV:  +
- @if(droppedStudents.Any()) + @if (droppedStudents.Any()) {
@@ -145,7 +81,7 @@ } -
+
@@ -173,14 +109,15 @@
-
- +
+ + @@ -201,6 +138,7 @@ } + } @@ -213,22 +151,24 @@
First Name Last Name Email GitHub Assigned TeamTeam Lead?
-
- -
-
-
+ +
+ Adding students. Please wait... +
+ +
@code { private string searchTerm = string.Empty; private IEnumerable availableClasses = []; private bool isAvailableClassLoaded => availableClasses.Any(c => DateTime.Now.Month >= c.StartDate.Month && DateTime.Now.Month <= c.EndDate.Month); - private ClassInformation selectedClass = new ClassInformation(); + private long selectedClass = -1; private IEnumerable teams = new List(); private List students = []; private IEnumerable> droppedStudents = []; - private ClassInformation SelectedClass + private string waitBar = "hidden"; + private long SelectedClass { get { @@ -253,8 +193,25 @@ } } + [Parameter] + public string Cohort { get; set; } = string.Empty; + protected override async Task OnInitializedAsync() { + if (!string.IsNullOrEmpty(Cohort)) + { + availableClasses = await DBOperationsService.GetRecords(); + foreach (ClassInformation classInformation in availableClasses) + { + if (classInformation.Cohort.IndexOf(Cohort, StringComparison.OrdinalIgnoreCase) >= 0) + { + this.selectedClass = classInformation.ClassId; + await Refresh(updateSelectedClass: false); + return; + } + } + } + await Refresh(updateSelectedClass: true); } @@ -263,7 +220,7 @@ availableClasses = await DBOperationsService.GetRecords(); if (updateSelectedClass && availableClasses.Any()) { - this.SelectedClass = availableClasses.First(); + this.SelectedClass = availableClasses.First().ClassId; } await this.InvokeAsync(() => this.StateHasChanged()); @@ -299,20 +256,19 @@ NavigationManager.Refresh(); } - private async Task ClassChangedAsync - (ClassInformation classInformation) + private async Task ClassChangedAsync(long selectedClassId) { // Students associated with the current selected class. - students = (await DBOperationsService.GetStudentsByClassAsync(selectedClass.ClassId)) + students = (await DBOperationsService.GetStudentsByClassAsync(selectedClassId)) .Where(s => s.IsMatch(searchTerm)) .OrderBy(s => s.FirstName) .ToList(); // Add blank if wanting to add a new student manually. - students.Add(new Student() { ClassId = selectedClass.ClassId, TeamId = -1 }); + students.Add(new Student() { ClassId = selectedClassId, TeamId = -1 }); // Teams associated with the current selected class. - teams = (await DBOperationsService.GetRecords()).Where(t => t.ClassId == selectedClass.ClassId).ToList(); + teams = (await DBOperationsService.GetRecords()).Where(t => t.ClassId == selectedClassId).ToList(); // Assign the team to the student. foreach (Student student in students) @@ -351,6 +307,7 @@ private async Task HandleFileSelection(InputFileChangeEventArgs e) { + this.waitBar = "visible"; try { var files = e.GetMultipleFiles(); @@ -372,6 +329,12 @@ { Console.WriteLine(ex.Message); } + finally + { + this.waitBar = "hidden"; + } + + await Refresh(updateSelectedClass: true); } private async Task ProcessStreamAsync(Stream stream, string fileName) @@ -390,11 +353,11 @@ } // TODO: Add dropped records to another table for notification to user. - List students = Student.ParseData(fileContent, selectedClass.ClassId, out List> droppedStudents); + List students = Student.ParseData(fileContent, selectedClass, out List> droppedStudents); var currentStudents = await DBOperationsService.GetRecords(); foreach (Student student in students .Where(s => !currentStudents - .Any(c => string.Equals(c.Email, s.Email, StringComparison.OrdinalIgnoreCase)))) + .Any(c => c.ClassId == this.selectedClass && string.Equals(c.Email, s.Email, StringComparison.OrdinalIgnoreCase)))) { await DBOperationsService.AddRecord(student); }