From 898029713e213e02cad45e12008c3fa06f9eb43a Mon Sep 17 00:00:00 2001 From: Simon Martens Date: Wed, 2 Nov 2022 16:37:50 +0100 Subject: [PATCH] Added Search Page. Final Version for 1st internal relaese --- HaWeb/Controllers/IndexController.cs | 15 +- HaWeb/Controllers/RegisterController.cs | 12 +- HaWeb/Controllers/SucheController.cs | 57 +++- HaWeb/Models/IndexViewModel.cs | 4 +- HaWeb/Models/SearchResult.cs | 4 +- HaWeb/Models/SucheViewModel.cs | 16 +- HaWeb/SearchHelpers/SearchRules.cs | 12 +- HaWeb/SearchHelpers/SearchState.cs | 3 +- .../Views/Datenschutzerklaerung/Index.cshtml | 0 HaWeb/Views/HKB/Dynamic/Index.cshtml | 16 +- HaWeb/Views/HKB/Dynamic/Register.cshtml | 30 ++- HaWeb/Views/HKB/Dynamic/Suche.cshtml | 153 +++++++---- HaWeb/Views/Home/Index.cshtml | 2 +- HaWeb/XMLParser/IXMLService.cs | 2 +- HaWeb/XMLParser/XMLService.cs | 9 +- HaWeb/appsettings.json | 2 +- HaWeb/wwwroot/css/index.css | 6 +- HaWeb/wwwroot/css/output.css | 2 +- HaWeb/wwwroot/css/search.css | 244 +++++++++++------- HaWeb/wwwroot/js/site.js | 2 + 20 files changed, 387 insertions(+), 204 deletions(-) delete mode 100644 HaWeb/Views/Datenschutzerklaerung/Index.cshtml diff --git a/HaWeb/Controllers/IndexController.cs b/HaWeb/Controllers/IndexController.cs index 29c8e82..c17f3d3 100644 --- a/HaWeb/Controllers/IndexController.cs +++ b/HaWeb/Controllers/IndexController.cs @@ -87,7 +87,8 @@ public class IndexController : Controller { } - private List<(string Key, string Person)> _getAvailablePersons(ILibrary lib) { + private List<(string Key, string Person)>? _getAvailablePersons(ILibrary lib) { + if (!lib.Persons.Any()) return null; return lib.Persons .OrderBy(x => x.Value.Surname) .ThenBy(x => x.Value.Prename) @@ -153,8 +154,16 @@ public class IndexController : Controller { List<(string Volume, List Pages)>? availablePages = null; availablePages = lib.Structure.Where(x => x.Key != "-1").Select(x => (x.Key, x.Value.Select(x => x.Key).ToList())).ToList(); zhvolume = zhvolume == null ? "1" : zhvolume; - var model = new IndexViewModel(letters, page, pages, _getAvailablePersons(lib), availablePages.OrderBy(x => x.Volume).ToList(), zhvolume, zhpage); - if (person != null) model.ActivePerson = person; + var model = new IndexViewModel( + letters, + page, + pages, + _getAvailablePersons(lib), + availablePages.OrderBy(x => x.Volume).ToList(), + zhvolume, + zhpage, + person + ); return View("~/Views/HKB/Dynamic/Index.cshtml", model); } diff --git a/HaWeb/Controllers/RegisterController.cs b/HaWeb/Controllers/RegisterController.cs index acecb4d..52d798f 100644 --- a/HaWeb/Controllers/RegisterController.cs +++ b/HaWeb/Controllers/RegisterController.cs @@ -105,7 +105,7 @@ public class RegisterController : Controller { } [HttpGet] - public IActionResult Forschung(string? id, string? search) { + public IActionResult Forschung(string? id) { // Setup settings and variables var lib = _lib.GetLibrary(); var url = "/HKB/Register/Forschung/"; @@ -146,16 +146,6 @@ public class RegisterController : Controller { return View("~/Views/HKB/Dynamic/Register.cshtml", model); } - [HttpPost] - [DisableFormValueModelBinding] - [ValidateAntiForgeryToken] - [Route("/HKB/Register/Forschung/{id}")] - [Route("/HKB/Register/Register/{id}")] - [Route("/HKB/Register/Bibelstellen/{id}")] - public IActionResult Search(string? id) { - return Ok(); - } - private string? normalizeID(string? id, string defaultid) { if (id == null) return null; return id.ToUpper(); diff --git a/HaWeb/Controllers/SucheController.cs b/HaWeb/Controllers/SucheController.cs index 32d9732..a2fea89 100644 --- a/HaWeb/Controllers/SucheController.cs +++ b/HaWeb/Controllers/SucheController.cs @@ -28,9 +28,6 @@ public class SucheController : Controller { if (search == null) return _error404(); var lib = _lib.GetLibrary(); - var stopwatch = new System.Diagnostics.Stopwatch(); - stopwatch.Start(); - if (category == "letters") { if (String.IsNullOrWhiteSpace(search)) return _paginateSendLetters(lib, page, search, SearchResultType.InvalidSearchTerm, null, null); @@ -46,13 +43,24 @@ public class SucheController : Controller { ); var keys = res.Select(x => x.Index).Where(x => lib.Metas.ContainsKey(x)).Select(x => lib.Metas[x]); var letters = keys.ToLookup(x => x.Sort.Year).OrderBy(x => x.Key).ToList(); - return _paginateSendLetters(lib, page, search, SearchResultType.Success, ret, letters); - } else if (category == " register") { + return _paginateSendLetters(lib, page, search, SearchResultType.Success, ret, letters); + } else if (category == "register") { + if (String.IsNullOrWhiteSpace(search)) + return _paginateSendRegister(lib, page, search, SearchResultType.InvalidSearchTerm, null); + search = search.Trim(); + + List<(string Index, List<(string Page, string Line, string Preview, string Identifier)> Results)>? res = null; + if (page == 0) + res = _xmlService.SearchCollection("register-comments", search, _readerService); + if (page == 1) + res = _xmlService.SearchCollection("forschung-comments", search, _readerService); + if (res == null || !res.Any()) + return _paginateSendRegister(lib, page, search, SearchResultType.NotFound, null); + + return _paginateSendRegister(lib, page, search, SearchResultType.Success, _createComments("neuzeit", res.Select((x) => (x.Index, x.Results.Select((y) => y.Identifier).ToList())).OrderBy(x => x.Index).ToList())); } - stopwatch.Stop(); - Console.WriteLine("SEARCH: " + stopwatch.ElapsedMilliseconds); return _error404(); } @@ -101,7 +109,7 @@ public class SucheController : Controller { if (pages != null && page >= pages.Count) return _error404(); if (pages == null && page > 0) return _error404(); List<(int Year, List LetterList)>? letters = null; - if (pages != null) + if (pages != null && metasbyyear != null) letters = metasbyyear .Where(x => x.Key >= pages[page].StartYear && x.Key <= pages[page].EndYear) .Select(x => (x.Key, x @@ -110,10 +118,41 @@ public class SucheController : Controller { .ThenBy(x => x.Meta.Order) .ToList())) .ToList(); - var model = new SucheViewModel(SearchType.Letter, SearchResultType.Success, page, _paginate(pages), activeSearch, searchResults, letters); + var model = new SucheViewModel("letters", SRT, page, _paginate(pages), activeSearch, searchResults, letters, null); return View("~/Views/HKB/Dynamic/Suche.cshtml", model); } + private IActionResult _paginateSendRegister( + ILibrary lib, + int page, + string activeSearch, + SearchResultType SRT, + List comments) { + var model = new SucheViewModel("register", SRT, page, new List() { "Allgmeines Register", "Forschungsbibliographie" }, activeSearch, null, null, comments); + return View("~/Views/HKB/Dynamic/Suche.cshtml", model); + } + + + private List _createComments(string category, List<(string, List)>? comments) { + var lib = _lib.GetLibrary(); + var res = new List(); + if (comments == null) return res; + foreach (var comm in comments) { + var commobj = lib.Comments[comm.Item1]; + var parsedComment = HTMLHelpers.CommentHelpers.CreateHTML(lib, _readerService, commobj, category, Settings.ParsingState.CommentType.Comment); + List? parsedSubComments = new List(); + var distinctList = comm.Item2.Distinct().ToList(); + foreach (var subcomm in distinctList) { + if (subcomm != comm.Item1) { + var subcommobj = lib.SubCommentsByID[subcomm]; + parsedSubComments.Add(HTMLHelpers.CommentHelpers.CreateHTML(lib, _readerService, subcommobj, category, Settings.ParsingState.CommentType.Subcomment)); + } + } + res.Add(new CommentModel(parsedComment, parsedSubComments)); + } + return res; + } + private IActionResult _error404() { Response.StatusCode = 404; return Redirect("/Error404"); diff --git a/HaWeb/Models/IndexViewModel.cs b/HaWeb/Models/IndexViewModel.cs index 237a8eb..6f9a320 100644 --- a/HaWeb/Models/IndexViewModel.cs +++ b/HaWeb/Models/IndexViewModel.cs @@ -19,7 +19,8 @@ public class IndexViewModel { List<(string Key, string Name)>? availablePersons, List<(string Volume, List Pages)>? availablePages, string? activeVolume, - string? activePage + string? activePage, + string? activePerson ) { Letters = letters; if (letters != null) @@ -32,5 +33,6 @@ public class IndexViewModel { AvailablePages = availablePages; ActiveVolume = activeVolume; ActivePage = activePage; + ActivePerson = activePerson; } } \ No newline at end of file diff --git a/HaWeb/Models/SearchResult.cs b/HaWeb/Models/SearchResult.cs index 67d3689..d4032ea 100644 --- a/HaWeb/Models/SearchResult.cs +++ b/HaWeb/Models/SearchResult.cs @@ -7,11 +7,11 @@ using System.Collections.Generic; public class SearchResult { public string Search { get; private set; } public string Index { get; private set; } + public string Identifier { get; set; } public string? Page { get; set; } public string? Line { get; set; } - public string? Lemma { get; set; } - public string? Link { get; set; } public string? Preview { get; set; } + // TODO: public string? ParsedPreview { get; set; } diff --git a/HaWeb/Models/SucheViewModel.cs b/HaWeb/Models/SucheViewModel.cs index 867be42..c0627cd 100644 --- a/HaWeb/Models/SucheViewModel.cs +++ b/HaWeb/Models/SucheViewModel.cs @@ -1,12 +1,6 @@ namespace HaWeb.Models; using HaDocument.Models; -public enum SearchType { - Letter, - Register, - Marginals -} - public enum SearchResultType { Success, OutOfBounds, @@ -16,22 +10,25 @@ public enum SearchResultType { public class SucheViewModel { public List<(int Year, List LetterList)>? Letters { get; private set; } + public List? Comments { get; private set; } + public int Count { get; private set; } public int ActivePage { get; private set; } public List? AvailablePages { get; private set; } public string ActiveSearch { get; private set; } public Dictionary>? SearchResults { get; private set; } public SearchResultType SearchResultType { get; private set; } - public SearchType SearchType { get; private set; } + public string SearchType { get; private set; } public SucheViewModel( - SearchType searchType, + string searchType, SearchResultType searchResultType, int activePage, List? availablePages, string activeSearch, Dictionary>? searchResults, - List<(int Year, List LetterList)>? letters + List<(int Year, List LetterList)>? letters, + List? comments ) { Letters = letters; if (letters != null) @@ -45,5 +42,6 @@ public class SucheViewModel { AvailablePages = availablePages; ActiveSearch = activeSearch; SearchResults = searchResults; + Comments = comments; } } \ No newline at end of file diff --git a/HaWeb/SearchHelpers/SearchRules.cs b/HaWeb/SearchHelpers/SearchRules.cs index b2a6513..ade5af4 100644 --- a/HaWeb/SearchHelpers/SearchRules.cs +++ b/HaWeb/SearchHelpers/SearchRules.cs @@ -8,6 +8,10 @@ using WhitespaceFuncList = List<(Func x.Name.ToLower() == "kommentar" || x.Name.ToLower() == "subsection", (_, tag, reader) => reader.State.CurrentIdentifier = tag["id"]), + }; + public static readonly TextFuncList TextRules = new TextFuncList() { ( (x, _) => true, (sb, text, reader) => { var t = text.Value; @@ -18,8 +22,8 @@ public class SearchRules { if (sb.Length >= sw.Length) { if (sb.ToString().ToUpperInvariant().Contains(sw)) { if (reader.State.Results == null) - reader.State.Results = new List<(string Page, string Line)>(); - reader.State.Results.Add((reader.CurrentPage, reader.CurrentLine)); + reader.State.Results = new List<(string Page, string Line, string Identifier)>(); + reader.State.Results.Add((reader.CurrentPage, reader.CurrentLine, reader.State.CurrentIdentifier)); } sb.Remove(0, sb.Length - sw.Length); } @@ -36,8 +40,8 @@ public class SearchRules { if (sb.Length >= sw.Length) { if (sb.ToString().Contains(sw)) { if (reader.State.Results == null) - reader.State.Results = new List<(string Page, string Line)>(); - reader.State.Results.Add((reader.CurrentPage, reader.CurrentLine)); + reader.State.Results = new List<(string Page, string Line, string Identifier)>(); + reader.State.Results.Add((reader.CurrentPage, reader.CurrentLine, reader.State.CurrentIdentifier)); } sb.Remove(0, sb.Length - sw.Length); } diff --git a/HaWeb/SearchHelpers/SearchState.cs b/HaWeb/SearchHelpers/SearchState.cs index e19f2a6..9c0a0ee 100644 --- a/HaWeb/SearchHelpers/SearchState.cs +++ b/HaWeb/SearchHelpers/SearchState.cs @@ -3,8 +3,9 @@ using System.Text; public class SearchState : HaWeb.HTMLParser.IState { internal string SearchWord; + internal string? CurrentIdentifier; internal bool Normalize; - internal List<(string Page, string Line)>? Results; + internal List<(string Page, string Line, string Identifier)>? Results; public SearchState(string searchword, bool normalize = false) { Normalize = normalize; diff --git a/HaWeb/Views/Datenschutzerklaerung/Index.cshtml b/HaWeb/Views/Datenschutzerklaerung/Index.cshtml deleted file mode 100644 index e69de29..0000000 diff --git a/HaWeb/Views/HKB/Dynamic/Index.cshtml b/HaWeb/Views/HKB/Dynamic/Index.cshtml index 09d8a51..72b8b24 100644 --- a/HaWeb/Views/HKB/Dynamic/Index.cshtml +++ b/HaWeb/Views/HKB/Dynamic/Index.cshtml @@ -91,7 +91,10 @@
Suche in Z H @if (Model.ActivePage != null) { - ← Auswahl aufheben +
+ Briefe auf ZH @Model.ActiveVolume / @Model.ActivePage  + ← Auswahl aufheben +
}
@@ -172,9 +175,14 @@ @if(Model.AvailablePersons != null) {
- Korrespondenzpartner:innen - @if (Model.ActivePerson != null) { - ← Auswahl aufheben +
+ Korrespondenzpartner:innen +
+ @if (Model.ActivePerson != null && Model.AvailablePersons.Where(x => x.Key == Model.ActivePerson).Any()) { +
+ Briefe von und an @Model.AvailablePersons.Where(x => x.Key == Model.ActivePerson).First().Name.  + ← Auswahl aufheben +
}
diff --git a/HaWeb/Views/HKB/Dynamic/Register.cshtml b/HaWeb/Views/HKB/Dynamic/Register.cshtml index 3a20186..a561c8c 100644 --- a/HaWeb/Views/HKB/Dynamic/Register.cshtml +++ b/HaWeb/Views/HKB/Dynamic/Register.cshtml @@ -37,10 +37,36 @@
} @if (Model.AllowSearch) { - + + + + + + + + + + @*
-
+ *@ }
diff --git a/HaWeb/Views/HKB/Dynamic/Suche.cshtml b/HaWeb/Views/HKB/Dynamic/Suche.cshtml index 3c4fadf..398aad5 100644 --- a/HaWeb/Views/HKB/Dynamic/Suche.cshtml +++ b/HaWeb/Views/HKB/Dynamic/Suche.cshtml @@ -2,63 +2,93 @@ @{ ViewData["Title"] = "Briefauswahl & Suche"; ViewData["SEODescription"] = "Johann Georg Hamann: Kommentierte Briefausgabe, Hg. v. Leonard Keidel und Janina Reibold. Durchsuchbare Online-Ausgabe der Briefe von und an Johann Georg Hamann."; - ViewData["showCredits"] = "true"; + ViewData["showCredits"] = "false"; }