Chnaged README, worked on index strategy

This commit is contained in:
schnulller
2022-06-12 00:20:30 +02:00
parent 5d1dc0a833
commit 6ea1ad9806
16 changed files with 105 additions and 26 deletions

View File

@@ -25,7 +25,7 @@ namespace HaDocument.Interfaces {
Lookup<string, Marginal> MarginalsByLetter { get; }
Lookup<string, Editreason> EditreasonsByLetter { get; }
ImmutableSortedSet<Meta> MetasByDate { get; }
ILookup<string, Meta> MetasByYear { get; }
ILookup<int, Meta> MetasByYear { get; }
ImmutableDictionary<string, Comment> SubCommentsByID { get; }
}
}

View File

@@ -5,7 +5,7 @@ using System.Collections.Generic;
using HaDocument.Models;
using HaDocument.Comparers;
using System.Linq;
using System.Collections.Specialized;
namespace HaDocument.Models
{
public class Library : ILibrary
@@ -40,7 +40,7 @@ namespace HaDocument.Models
// Auswählen von Briefen nach autoptischer Numemr und in zeitlich sortierter Reihenfolge.
public ImmutableSortedSet<Meta> MetasByDate { get; }
// Auswählen von Briefen nach dem Jahr, sortiert nach Datum
public ILookup<string, Meta> MetasByYear { get; }
public ILookup<int, Meta> MetasByYear { get; }
public Library(
@@ -91,7 +91,7 @@ namespace HaDocument.Models
MarginalsByLetter = (Lookup<string, Marginal>)Marginals.Values.ToLookup(x => x.Letter);
EditreasonsByLetter = (Lookup<string, Editreason>)Editreasons.Values.ToLookup(x => x.Letter);
MetasByDate = Metas.Values.ToImmutableSortedSet<Meta>(new DefaultComparer());
MetasByYear = Metas.Values.ToLookup(x => x.Sort.Year.ToString());
MetasByYear = Metas.Values.ToLookup(x => x.Sort.Year);
var tempbuilder = ImmutableDictionary.CreateBuilder<string, Comment>();
foreach (var comm in Comments)

View File

@@ -1,18 +1,58 @@
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using HaWeb.Models;
using HaWeb.FileHelpers;
using HaDocument.Interfaces;
using HaDocument.Models;
using System.Collections.Specialized;
namespace HaWeb.Controllers;
public class SucheController : Controller {
private IHaDocumentWrappper _lib;
private int _lettersForPage;
public SucheController(IHaDocumentWrappper lib, IConfiguration config) {
_lib = lib;
_lettersForPage = config.GetValue<int>("LettersOnPage");
}
[Route("Suche")]
// Filter, Order By Year, Paginate, Order By Date and by Order, Parse
public IActionResult Index() {
var lib = _lib.GetLibrary();
return View();
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error() {
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
private BriefeMetaViewModel generateMetaViewModel(ILibrary lib, Meta meta) {
var hasMarginals = lib.MarginalsByLetter.Contains(meta.Index) ? true : false;
var senders = meta.Senders.Select(x => lib.Persons[x].Name) ?? new List<string>();
var recivers = meta.Receivers.Select(x => lib.Persons[x].Name) ?? new List<string>();
var zhstring = meta.ZH != null ? HaWeb.HTMLHelpers.LetterHelpers.CreateZHString(meta) : null;
return new BriefeMetaViewModel(meta, hasMarginals, false) {
ParsedZHString = zhstring,
ParsedSenders = HTMLHelpers.StringHelpers.GetEnumerationString(senders),
ParsedReceivers = HTMLHelpers.StringHelpers.GetEnumerationString(recivers)
};
}
private List<(int StartYear, int EndYear)>? Paginate(ILookup<int, List<Meta>>? letters) {
if (letters == null || !letters.Any()) return null;
var orderedl = letters.OrderBy(x => x.Key);
List<(int StartYear, int EndYear)>? res = null;
int startyear = 0;
int count = 0;
foreach (var letterlist in orderedl) {
count += letterlist.Count();
if (count == 0) {
startyear = letterlist.Key;
}
if (count >= _lettersForPage) {
if (res == null) res = new List<(int StartYear, int EndYear)>();
res.Add((startyear, letterlist.Key));
count = 0;
}
}
return res;
}
}

View File

@@ -7,32 +7,36 @@ public class HaDocumentWrapper : IHaDocumentWrappper {
private ILibrary Library;
private IXMLProvider _xmlProvider;
private int _startYear;
private int _endYear;
public int StartYear { get; private set; }
public int EndYear { get; private set; }
public HaDocumentWrapper(IXMLProvider xmlProvider, IConfiguration configuration) {
_xmlProvider = xmlProvider;
_startYear = configuration.GetValue<int>("AvailableStartYear");
_endYear = configuration.GetValue<int>("AvailableEndYear");
StartYear = configuration.GetValue<int>("AvailableStartYear");
EndYear = configuration.GetValue<int>("AvailableEndYear");
var filelist = xmlProvider.GetHamannFiles();
if (filelist != null && filelist.Any()) {
_AutoLoad(filelist);
}
// Use Fallback library
if (Library == null)
Library = HaDocument.Document.Create(new HaWeb.Settings.HaDocumentOptions() { AvailableYearRange = (_startYear, _endYear) });
if (Library == null) {
var options = new HaWeb.Settings.HaDocumentOptions();
if (SetLibrary(options.HamannXMLFilePath) == null) {
throw new Exception("Die Fallback Hamann.xml unter " + options.HamannXMLFilePath + " kann nicht geparst werden.");
}
}
}
public ILibrary ResetLibrary() {
Library = HaDocument.Document.Create(new HaWeb.Settings.HaDocumentOptions() { AvailableYearRange = (_startYear, _endYear) });
Library = HaDocument.Document.Create(new HaWeb.Settings.HaDocumentOptions() { AvailableYearRange = (StartYear, EndYear) });
return Library;
}
public ILibrary? SetLibrary(string filepath, ModelStateDictionary? ModelState = null) {
try
{
Library = HaDocument.Document.Create(new HaWeb.Settings.HaDocumentOptions() { HamannXMLFilePath = filepath, AvailableYearRange = (_startYear, _endYear) });
Library = HaDocument.Document.Create(new HaWeb.Settings.HaDocumentOptions() { HamannXMLFilePath = filepath, AvailableYearRange = (StartYear, EndYear) });
}
catch (Exception ex) {
if (ModelState != null) ModelState.AddModelError("Error", "Das Dokument konnte nicht geparst werden: " + ex.Message);

View File

@@ -0,0 +1,15 @@
namespace HaWeb.Models;
public class SucheViewModel {
public List<(int Year, List<BriefeMetaViewModel> LetterList)> Letters { get; private set; }
public int Count { get; private set; }
public int ActiveYears { get; private set; }
public List<(int StartYear, int EndYear)> AvailableYears { get; private set; }
public SucheViewModel(List<(int Year, List<BriefeMetaViewModel> LetterList)> letters, int count, int activeYears, List<(int StartYear, int EndYear)> availableYears) {
Letters = letters;
Count = count;
ActiveYears = activeYears;
AvailableYears = availableYears;
}
}

View File

@@ -22,8 +22,8 @@ Don't forget to place a valid `Hamann.xml`-File in the root of the build to prov
Run
`dotnet watch --project Tailwind.csproj build -- Tailwind.csproj` and
`dotnet watch --project HaWeb.csproj -- run --project HaWeb.csproj`
`dotnet watch --verbose --project Tailwind.csproj build -- Tailwind.csproj` and
`dotnet watch --verbose --project HaWeb.csproj -- run --project HaWeb.csproj`
in two terminal windows to watch for specific file changes in .css / .js / .cshtml / .json / .cs files and to rebuild the css-Files and the app automatically on change.
Recommended vscode plugins include the XML Tools, Prettier, c#, Nuget Gallery, Tailwind CSS IntelliSense & TODO Tree.

View File

@@ -1,4 +1,9 @@
@model UploadViewModel;
@{
ViewData["Title"] = "Upload & Veröffentlichen";
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"] = "false";
}
<div class="ha-adminuploadfields" id="ha-adminuploadfields">
@foreach (var item in Model.AvailableRoots!.OrderBy(x => x.Type)) {

View File

@@ -7,6 +7,11 @@
if (Model.MinWidthTrad)
minwidthtrads = "ha-minwidth";
}
@* No JavaScript Settings *@
<noscript>
@* TODO *@
</noscript>
<div class="ha-letterheader">
@await Html.PartialAsync("/Views/Shared/_LetterHead.cshtml", Model.MetaData)
<div class="ha-letterheadernav">

View File

@@ -6,9 +6,9 @@
<div class="ha-static">
<div class="md:pr-80">
<h1>Kontakt</h1>
<table>
<table class="!w-full">
<tr>
<td>Theodor Springmann Stiftung <br>
<td class="!pl-0">Theodor Springmann Stiftung <br>
Dr. Janina Reibold <br>
Hirschgasse 2 <br>
69120 Heidelberg <br>

View File

@@ -1,5 +1,10 @@
@{
@model SucheViewModel;
@{
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";
}
<div class="ha-search">
</div>

View File

@@ -17,5 +17,6 @@
"StoredFilePathWindows": "D:/test/",
"FileSizeLimit": 52428800,
"AvailableStartYear": 1700,
"AvailableEndYear": 1800
"AvailableEndYear": 1800,
"LettersOnPage": 90
}

File diff suppressed because one or more lines are too long

View File

@@ -22,7 +22,7 @@
}
.ha-register .ha-register-head .ha-register-add a .ha-register-add-text {
@apply ml-1
}
.ha-register .ha-register-head .ha-register-nav a {

View File

@@ -0,0 +1,3 @@
@layer components {
}

View File

@@ -12,6 +12,7 @@
@import "./letterhead.css";
@import "./letter.css";
@import "./upload.css";
@import "./search.css";
@layer components {
/* TODO: check what can be inlined (eg. used once in the code, has no double paths etc...) */

View File

@@ -22,7 +22,7 @@
}
.ha-static h1 {
@apply font-bold text-xl desktop:font-normal desktop:text-4xl mb-6
@apply font-bold text-xl desktop:font-normal desktop:text-4xl mb-9
}
.ha-static h2 {