feat: improve filtered exports and server pagination
This commit is contained in:
1 parent
4e37f3bb5c
commit
1ddfecbecc
26 files changed
+645
-120
No files matched your search
@@ -51,10 +51,24 @@ public sealed class BaseDataExcelController(AppDbContext db, IAppCache cache) :
|
||||
}
|
||||
|
||||
[HttpGet("{kind}/export")]
|
||||
public async Task<IActionResult> Export(string kind, CancellationToken cancellationToken, bool? isArchived = null, string? keyword = null)
|
||||
public async Task<IActionResult> Export(
|
||||
string kind,
|
||||
CancellationToken cancellationToken,
|
||||
bool? isArchived = null,
|
||||
string? keyword = null,
|
||||
Guid? collegeId = null,
|
||||
Guid? majorId = null,
|
||||
int? grade = null,
|
||||
Guid? campusId = null,
|
||||
Guid? buildingId = null,
|
||||
int? minimumCapacity = null,
|
||||
TeachingVenueNature? teachingVenueNature = null,
|
||||
bool? isEnabled = null)
|
||||
{
|
||||
if (!TryGetHeaders(kind, out var headers)) return NotFound();
|
||||
var rows = await GetExportRowsAsync(kind, cancellationToken, isArchived, keyword?.Trim());
|
||||
var rows = await GetExportRowsAsync(kind, cancellationToken, isArchived, keyword?.Trim(),
|
||||
collegeId, majorId, grade, campusId, buildingId, minimumCapacity,
|
||||
teachingVenueNature, isEnabled);
|
||||
var bytes = ExcelWorkbookHelper.Create(KindName(kind), headers, rows);
|
||||
return File(bytes, ExcelWorkbookHelper.ContentType,
|
||||
DownloadFileName.Export(KindName(kind), ".xlsx"));
|
||||
@@ -140,22 +154,42 @@ public sealed class BaseDataExcelController(AppDbContext db, IAppCache cache) :
|
||||
|
||||
private async Task<IReadOnlyList<IReadOnlyList<object?>>> GetExportRowsAsync(
|
||||
string kind,
|
||||
CancellationToken cancellationToken, bool? isArchived, string? keyword) =>
|
||||
CancellationToken cancellationToken,
|
||||
bool? isArchived,
|
||||
string? keyword,
|
||||
Guid? collegeId,
|
||||
Guid? majorId,
|
||||
int? grade,
|
||||
Guid? campusId,
|
||||
Guid? buildingId,
|
||||
int? minimumCapacity,
|
||||
TeachingVenueNature? teachingVenueNature,
|
||||
bool? isEnabled) =>
|
||||
kind.ToLowerInvariant() switch
|
||||
{
|
||||
"campuses" => (await db.Campuses.AsNoTracking().OrderBy(x => x.Code)
|
||||
"campuses" => (await db.Campuses.AsNoTracking()
|
||||
.Where(x => keyword == null || keyword == "" || x.Code.Contains(keyword) || x.Name.Contains(keyword))
|
||||
.OrderBy(x => x.Code)
|
||||
.ToListAsync(cancellationToken))
|
||||
.Select(x => Row(x.Code, x.Name, x.Address, x.SortOrder, Status(x.IsEnabled))).ToList(),
|
||||
"colleges" => (await db.Colleges.AsNoTracking().Include(x => x.Campus)
|
||||
.Where(x => keyword == null || keyword == "" || x.Code.Contains(keyword) || x.Name.Contains(keyword) || x.Campus!.Name.Contains(keyword))
|
||||
.OrderBy(x => x.Code).ToListAsync(cancellationToken))
|
||||
.Select(x => Row(x.Code, x.Name, x.ShortName, x.Campus?.Code, x.SortOrder,
|
||||
Status(x.IsEnabled))).ToList(),
|
||||
"majors" => (await db.Majors.AsNoTracking().Include(x => x.College)
|
||||
.Where(x => keyword == null || keyword == "" || x.Code.Contains(keyword) || x.Name.Contains(keyword) || x.College!.Name.Contains(keyword))
|
||||
.OrderBy(x => x.Code).ToListAsync(cancellationToken))
|
||||
.Select(x => Row(x.Code, x.Name, x.College!.Code, x.DegreeType,
|
||||
x.SchoolingYears, x.SortOrder, Status(x.IsEnabled))).ToList(),
|
||||
"classes" => (await db.AdministrativeClasses.AsNoTracking().Include(x => x.Major)
|
||||
.Include(x => x.CounselorUser).OrderBy(x => x.Code).ToListAsync(cancellationToken))
|
||||
.Include(x => x.CounselorUser)
|
||||
.Where(x => !collegeId.HasValue || x.Major!.CollegeId == collegeId.Value)
|
||||
.Where(x => !majorId.HasValue || x.MajorId == majorId.Value)
|
||||
.Where(x => !grade.HasValue || x.Grade == grade.Value)
|
||||
.Where(x => !isEnabled.HasValue || x.IsEnabled == isEnabled.Value)
|
||||
.Where(x => keyword == null || keyword == "" || x.Code.Contains(keyword) || x.Name.Contains(keyword) || x.Major!.Name.Contains(keyword) || x.Major.College!.Name.Contains(keyword))
|
||||
.OrderBy(x => x.Code).ToListAsync(cancellationToken))
|
||||
.Select(x => Row(x.Code, x.Name, x.Major!.Code, x.Grade,
|
||||
x.CounselorUser?.StaffNumber, x.SortOrder, Status(x.IsEnabled))).ToList(),
|
||||
"terms" => (await db.AcademicTerms.AsNoTracking()
|
||||
@@ -166,15 +200,23 @@ public sealed class BaseDataExcelController(AppDbContext db, IAppCache cache) :
|
||||
.Select(x => Row(x.Code, x.Name, x.AcademicYear, SeasonName(x.Season),
|
||||
x.StartDate, x.EndDate, YesNo(x.IsCurrent), Status(x.IsEnabled))).ToList(),
|
||||
"buildings" => (await db.Buildings.AsNoTracking().Include(x => x.Campus)
|
||||
.Where(x => keyword == null || keyword == "" || x.Code.Contains(keyword) || x.Name.Contains(keyword) || x.Campus!.Name.Contains(keyword))
|
||||
.OrderBy(x => x.Code).ToListAsync(cancellationToken))
|
||||
.Select(x => Row(x.Code, x.Name, x.Campus!.Code, x.SortOrder,
|
||||
Status(x.IsEnabled))).ToList(),
|
||||
"classrooms" => (await db.Classrooms.AsNoTracking().Include(x => x.Building)
|
||||
.Where(x => !campusId.HasValue || x.Building!.CampusId == campusId.Value)
|
||||
.Where(x => !buildingId.HasValue || x.BuildingId == buildingId.Value)
|
||||
.Where(x => !minimumCapacity.HasValue || x.Capacity >= minimumCapacity.Value)
|
||||
.Where(x => !teachingVenueNature.HasValue || (x.TeachingVenueNature & teachingVenueNature.Value) != 0)
|
||||
.Where(x => !isEnabled.HasValue || x.IsEnabled == isEnabled.Value)
|
||||
.Where(x => keyword == null || keyword == "" || x.Code.Contains(keyword) || x.Name.Contains(keyword) || x.Building!.Name.Contains(keyword) || x.Building.Campus!.Name.Contains(keyword))
|
||||
.OrderBy(x => x.Code).ToListAsync(cancellationToken))
|
||||
.Select(x => Row(x.Code, x.Name, x.Building!.Code, x.Capacity, x.RoomType,
|
||||
VenueNatureName(x.TeachingVenueNature),
|
||||
x.Equipment, x.SortOrder, Status(x.IsEnabled))).ToList(),
|
||||
"course-categories" => (await db.CourseCategories.AsNoTracking()
|
||||
.Where(x => keyword == null || keyword == "" || x.Code.Contains(keyword) || x.Name.Contains(keyword))
|
||||
.OrderBy(x => x.SortOrder).ThenBy(x => x.Code)
|
||||
.ToListAsync(cancellationToken))
|
||||
.Select(x => Row(x.Code, x.Name, x.SortOrder, Status(x.IsEnabled))).ToList(),
|
||||
|
||||
Reference in new issue
Block a user