From 55989e19e54cdcde6a1b84c510d780c0c898db4f Mon Sep 17 00:00:00 2001 From: Robin Weichselbraun Date: Sun, 20 Oct 2024 15:45:16 +0200 Subject: [PATCH] Ready for 1 release --- UWLecturePlan/Controllers/HomeController.cs | 32 -- .../Controllers/LectureController.cs | 51 +- UWLecturePlan/Models/LecturesViewModel.cs | 24 +- UWLecturePlan/Program.cs | 9 +- UWLecturePlan/UWLecturePlan.csproj | 1 + UWLecturePlan/Views/Home/Index.cshtml | 8 - UWLecturePlan/Views/Home/Privacy.cshtml | 6 - UWLecturePlan/Views/Lecture/Index.cshtml | 206 +++++--- UWLecturePlan/Views/Shared/_Layout.cshtml | 44 +- UWLecturePlan/appsettings.json | 15 +- UWLecturePlan/lecture.db | Bin 0 -> 95059968 bytes UWLecturePlan/lecture.db-shm | Bin 0 -> 32768 bytes UWLecturePlan/lecture.db-wal | 0 UWLecturePlan/wwwroot/css/site.css | 4 - UWLib/Lecture.cs | 12 +- UWLib/LectureEvent.cs | 4 +- UWLib/LinkToScrape.cs | 2 +- UWLib/Migrations/20241011153557_Init.cs | 4 +- .../20241013131123_Type.Designer.cs | 129 +++++ UWLib/Migrations/20241013131123_Type.cs | 29 ++ .../Migrations/LectureContextModelSnapshot.cs | 4 + UWLib/ScrapedLink.cs | 2 +- UWScraper/Program.cs | 318 +------------ UWScraper/Properties/launchSettings.json | 2 +- UWScraper/ScrapeCommand.cs | 109 +++++ UWScraper/Scraper.cs | 449 ++++++++++++++++++ UWScraper/UWScraper.csproj | 2 + UWScraper/ValuesColumn.cs | 13 + UWScraper/lecture.db | Bin 40960 -> 49152 bytes 29 files changed, 986 insertions(+), 493 deletions(-) delete mode 100644 UWLecturePlan/Controllers/HomeController.cs delete mode 100644 UWLecturePlan/Views/Home/Index.cshtml delete mode 100644 UWLecturePlan/Views/Home/Privacy.cshtml create mode 100644 UWLecturePlan/lecture.db create mode 100644 UWLecturePlan/lecture.db-shm create mode 100644 UWLecturePlan/lecture.db-wal create mode 100644 UWLib/Migrations/20241013131123_Type.Designer.cs create mode 100644 UWLib/Migrations/20241013131123_Type.cs create mode 100644 UWScraper/ScrapeCommand.cs create mode 100644 UWScraper/Scraper.cs create mode 100644 UWScraper/ValuesColumn.cs diff --git a/UWLecturePlan/Controllers/HomeController.cs b/UWLecturePlan/Controllers/HomeController.cs deleted file mode 100644 index 03fb123..0000000 --- a/UWLecturePlan/Controllers/HomeController.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System.Diagnostics; -using Microsoft.AspNetCore.Mvc; -using UWLecturePlan.Models; - -namespace UWLecturePlan.Controllers -{ - public class HomeController : Controller - { - private readonly ILogger _logger; - - public HomeController(ILogger logger) - { - _logger = logger; - } - - public IActionResult Index() - { - return View(); - } - - public IActionResult Privacy() - { - return View(); - } - - [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] - public IActionResult Error() - { - return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); - } - } -} diff --git a/UWLecturePlan/Controllers/LectureController.cs b/UWLecturePlan/Controllers/LectureController.cs index ec2533a..0447cc9 100644 --- a/UWLecturePlan/Controllers/LectureController.cs +++ b/UWLecturePlan/Controllers/LectureController.cs @@ -3,39 +3,54 @@ using Microsoft.AspNetCore.Mvc; using UWLecturePlan.Models; using UWLib; using Microsoft.EntityFrameworkCore; +using System; namespace UWLecturePlan.Controllers { public class LectureController : Controller { - - + + public IActionResult Index(LecturesViewModel model) { - LectureContext db = new LectureContext(@"D:\Projects\C#\UWScraper\UWScraper\bin\Debug\net8.0\lecture.db"); + LectureContext db = new(@"lecture.db"); - if (model.CurrentSemester == null) - { - model.CurrentSemester = GetSemester(DateTime.Now); - } + model.Semester ??= GetSemester(DateTime.Now); var from = DateTime.Now; - - model.LectureEvents = db.LectureEvents.Include(x=>x.Lecture) - .Where(x => x.From >= from) - .Where(x => x.Lecture.Semester == model.CurrentSemester) - .Where(x => x.Lecture.Branch == model.BranchFilter || model.BranchFilter == null) - .ToList(); + var date = DateTime.ParseExact(model.Date, "dd.MM.yyyy", CultureInfo.InvariantCulture); - if (model.LocationFilter != null) + + model.LectureEvents = [.. db.LectureEvents.Include(x=>x.Lecture) + .Where(x => x.Lecture.Semester == model.Semester) + .Where(x => x.Lecture.Branch == model.Branch || model.Branch == null) + + .Where(x => x.From.Date == date)]; + + if (model.TypeFilter != null) { model.LectureEvents = model.LectureEvents - .Where(x => x.Location.Contains(model.LocationFilter)).ToList(); + .Where(x => x.Lecture.Type == model.TypeFilter).ToList(); } - model.Branches = db.LectureEvents.Select(x => x.Lecture.Branch).Distinct().OrderBy(x=>x).ToList(); - + if (model.Location != null) + { + model.LectureEvents = model.LectureEvents + .Where(x => x.Location?.Contains(model.Location) ?? false).ToList(); + } + + model.Branches = [.. db.LectureEvents.Select(x => x.Lecture.Branch).Distinct().OrderBy(x => x)]; + + model.Types = [.. db.LectureEvents.Select(x => x.Lecture.Type).Distinct().OrderBy(x => x)]; + + model.Semesters = [.. db.LectureEvents.Select(x => x.Lecture.Semester).Distinct().OrderBy(x => x)]; + + model.Days = db.LectureEvents + .Where(x => x.Lecture.Semester == model.Semester) + .Where(x => x.Lecture.Branch == model.Branch || model.Branch == null) + .GroupBy(x => x.From.Date).ToDictionary(x => x.Key, x => x.Count()); + return View(model); } @@ -59,7 +74,7 @@ namespace UWLecturePlan.Controllers public static DateTime FirstDateOfWeekISO8601(int year, int weekOfYear) { - DateTime jan1 = new DateTime(year, 1, 1); + DateTime jan1 = new(year, 1, 1); int daysOffset = DayOfWeek.Thursday - jan1.DayOfWeek; // Use first Thursday in January to get first week of the year as diff --git a/UWLecturePlan/Models/LecturesViewModel.cs b/UWLecturePlan/Models/LecturesViewModel.cs index cd7850a..004e8da 100644 --- a/UWLecturePlan/Models/LecturesViewModel.cs +++ b/UWLecturePlan/Models/LecturesViewModel.cs @@ -1,18 +1,30 @@ -using UWLib; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; +using UWLib; namespace UWLecturePlan.Models { public class LecturesViewModel { - public string CurrentSemester { get; set; } + public string? Semester { get; set; } - public string? LocationFilter { get; set; } + public string? Location { get; set; } - public string? BranchFilter { get; set; } + public string? Branch { get; set; } - public List LectureEvents { get; set; } + public string? TypeFilter { get; set; } - public List Branches { get; set; } + public string Date { get; set; } = DateTime.Today.ToString("dd.MM.yyyy"); + + public List LectureEvents { get; set; } = []; + + public List Branches { get; set; } = []; + + public List Types { get; set; } = []; + + public List Semesters { get; set; } = []; + + public Dictionary Days { get; set; } = []; } } diff --git a/UWLecturePlan/Program.cs b/UWLecturePlan/Program.cs index 2555ff7..f965db2 100644 --- a/UWLecturePlan/Program.cs +++ b/UWLecturePlan/Program.cs @@ -1,7 +1,11 @@ +using System.ComponentModel; +using Microsoft.AspNetCore.Mvc.ModelBinding.Binders; +using UWLecturePlan; + var builder = WebApplication.CreateBuilder(args); // Add services to the container. -builder.Services.AddControllersWithViews(); +builder.Services.AddControllersWithViews(x => x.ModelBinderProviders.Insert(0, new DateTimeModelBinderProvider())).AddRazorRuntimeCompilation(); var app = builder.Build(); @@ -13,6 +17,7 @@ if (!app.Environment.IsDevelopment()) app.UseHsts(); } + app.UseHttpsRedirection(); app.UseStaticFiles(); @@ -20,6 +25,8 @@ app.UseRouting(); app.UseAuthorization(); + + app.MapControllerRoute( name: "default", pattern: "{controller=Lecture}/{action=Index}/{id?}"); diff --git a/UWLecturePlan/UWLecturePlan.csproj b/UWLecturePlan/UWLecturePlan.csproj index 21f1233..72be10c 100644 --- a/UWLecturePlan/UWLecturePlan.csproj +++ b/UWLecturePlan/UWLecturePlan.csproj @@ -9,6 +9,7 @@ + diff --git a/UWLecturePlan/Views/Home/Index.cshtml b/UWLecturePlan/Views/Home/Index.cshtml deleted file mode 100644 index bcfd79a..0000000 --- a/UWLecturePlan/Views/Home/Index.cshtml +++ /dev/null @@ -1,8 +0,0 @@ -@{ - ViewData["Title"] = "Home Page"; -} - -
-

Welcome

-

Learn about building Web apps with ASP.NET Core.

-
diff --git a/UWLecturePlan/Views/Home/Privacy.cshtml b/UWLecturePlan/Views/Home/Privacy.cshtml deleted file mode 100644 index af4fb19..0000000 --- a/UWLecturePlan/Views/Home/Privacy.cshtml +++ /dev/null @@ -1,6 +0,0 @@ -@{ - ViewData["Title"] = "Privacy Policy"; -} -

@ViewData["Title"]

- -

Use this page to detail your site's privacy policy.

diff --git a/UWLecturePlan/Views/Lecture/Index.cshtml b/UWLecturePlan/Views/Lecture/Index.cshtml index d910399..5e5d24f 100644 --- a/UWLecturePlan/Views/Lecture/Index.cshtml +++ b/UWLecturePlan/Views/Lecture/Index.cshtml @@ -1,6 +1,8 @@ @using System.Text.RegularExpressions @model LecturesViewModel @{ + ViewData["Title"] = "Vorlesungsplan"; + string GetBranchName(string branch) { Regex regex = new Regex(@".* - (.*)"); @@ -17,76 +19,152 @@ } } +@section Header { + +
+
+
+ + +
+
+ + +
+
+ +
+
+ + +
+
+ - - - - Semester: - Ort: - Studiengang: - - - +
+
-@foreach (var day in Model.LectureEvents.GroupBy(x => x.From.Date).OrderBy(x => x.Key)) -{ -
- @day.Key.ToString("dd.MM.yyyy") - (@day.Count()) - @foreach (var time in day.GroupBy(x => x.From).OrderBy(x => x.Key)) - { -
- @time.Key.ToString("HH:mm") - (@time.Count()) - @foreach (var eventItem in time.OrderBy(x => x.Lecture.Title)) - { -
- @eventItem.Lecture.Title - -
Zeitraum: @eventItem.From.ToString("HH:mm") - @eventItem.To.ToString("HH:mm")
-
Ort: @eventItem.Location
- - @eventItem.Lecture.Url -
- Infos - @Html.Raw(eventItem.Lecture.Description); -
- -
- } - -
+ \ No newline at end of file diff --git a/UWLecturePlan/Views/Shared/_Layout.cshtml b/UWLecturePlan/Views/Shared/_Layout.cshtml index 7c7b5bf..b768d74 100644 --- a/UWLecturePlan/Views/Shared/_Layout.cshtml +++ b/UWLecturePlan/Views/Shared/_Layout.cshtml @@ -9,41 +9,23 @@ -
- +
+ @await RenderSectionAsync("Header", required: false)
-
-
- @RenderBody() -
-
- -