Person Pages

This commit is contained in:
Simon Martens
2023-06-26 22:30:05 +02:00
parent e18f053865
commit cf0bc3cddf
18 changed files with 8571 additions and 495514 deletions

View File

@@ -4,17 +4,20 @@ namespace HaDocument.Models {
public string Name { get; } = "";
public string Prename { get; } = "";
public string Surname { get; } = "";
public string? Komm { get; }
public Person(
string index,
string name,
string prename,
string surname
string surname,
string? komm
) {
Index = index;
Name = name;
Prename = prename;
Surname = surname;
Komm = komm;
}
}
}

View File

@@ -13,6 +13,7 @@ namespace HaDocument.Reactors {
// State
private string Index;
private string Name;
private string? Komm;
internal HandDefsReactor(IReader reader, IntermediateLibrary lib) : base(reader, lib) {
lib.HandPersons = new Dictionary<string, Person>();
@@ -38,6 +39,7 @@ namespace HaDocument.Reactors {
_active = true;
Index = tag["index"];
Name = tag["name"];
if (!String.IsNullOrWhiteSpace(tag["komm"])) Komm = tag["komm"];
Add();
_active = false;
}
@@ -49,7 +51,7 @@ namespace HaDocument.Reactors {
}
protected void Add() {
CreatedInstances.Add(Index, new Person(Index, Name, "", ""));
CreatedInstances.Add(Index, new Person(Index, Name, "", "", Komm));
}
}
}

View File

@@ -15,6 +15,7 @@ namespace HaDocument.Reactors {
private string Name;
private string Prename = "";
private string Surname = "";
private string? Komm;
internal PersonDefsReactor(IReader reader, IntermediateLibrary lib) : base(reader, lib) {
lib.Persons = new Dictionary<string, Person>();
@@ -41,6 +42,7 @@ namespace HaDocument.Reactors {
Name = tag["name"];
Prename = tag["vorname"];
Surname = tag["nachname"];
if (!String.IsNullOrWhiteSpace(tag["komm"])) Komm = tag["komm"];
Add();
_active = false;
}
@@ -51,10 +53,11 @@ namespace HaDocument.Reactors {
Name = "";
Prename = "";
Surname = "";
Komm = null;
}
public void Add() {
CreatedInstances.Add(Index, new Person(Index, Name, Prename, Surname));
CreatedInstances.Add(Index, new Person(Index, Name, Prename, Surname, Komm));
}
}
}

View File

@@ -58,9 +58,9 @@ public class Briefecontroller : Controller {
// Model creation
var hasMarginals = false;
if (marginals != null && marginals.Any()) hasMarginals = true;
var model = new BriefeViewModel(id, index, GenerateMetaViewModel(lib, meta));
if (nextmeta != null) model.MetaData.Next = (GenerateMetaViewModel(lib, nextmeta), url + nextmeta.Autopsic);
if (prevmeta != null) model.MetaData.Prev = (GenerateMetaViewModel(lib, prevmeta), url + prevmeta.Autopsic);
var model = new BriefeViewModel(id, index, GenerateMetaViewModel(lib, meta, true));
if (nextmeta != null) model.MetaData.Next = (GenerateMetaViewModel(lib, nextmeta, false), url + nextmeta.Autopsic);
if (prevmeta != null) model.MetaData.Prev = (GenerateMetaViewModel(lib, prevmeta, false), url + prevmeta.Autopsic);
if (hands != null && hands.Any()) model.ParsedHands = HaWeb.HTMLHelpers.LetterHelpers.CreateHands(lib, hands);
if (editreasons != null && editreasons.Any()) model.ParsedEdits = HaWeb.HTMLHelpers.LetterHelpers.CreateEdits(lib, _readerService, editreasons);
model.DefaultCategory = lib.Apps.ContainsKey("-1") ? lib.Apps["-1"].Category : null;
@@ -129,40 +129,68 @@ public class Briefecontroller : Controller {
return Redirect("/Error404");
}
internal static BriefeMetaViewModel GenerateMetaViewModel(ILibrary lib, Meta meta) {
internal static BriefeMetaViewModel GenerateMetaViewModel(ILibrary lib, Meta meta, bool generatePersonLinks) {
var hasText = lib.Letters.ContainsKey(meta.Index) ? true : false;
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 senders = meta.Senders.Select(x => lib.Persons[x]).ToList() ?? new List<Person>();
var receivers = meta.Receivers.Select(x => lib.Persons[x]).ToList() ?? new List<Person>();
var zhstring = meta.ZH != null ? HaWeb.HTMLHelpers.LetterHelpers.CreateZHString(meta) : null;
return new BriefeMetaViewModel(meta, hasMarginals) {
ParsedZHString = zhstring,
SenderReceiver = generateSendersRecievers(senders, recivers),
SenderReceiver = generateSendersRecievers(senders, receivers, generatePersonLinks),
HasText = hasText,
};
}
private static List<(string Sender, string Receiver)> generateSendersRecievers(IEnumerable<string>? senders, IEnumerable<string>? receivers) {
private static List<(string Sender, string Receiver)> generateSendersRecievers(List<Person>? senders, List<Person>? receivers, bool generatePersonLinks) {
var res = new List<(string Sender, string Receiver)>();
if (senders != null && receivers != null) {
if (senders == null || receivers == null) return null;
if (!generatePersonLinks) {
if (senders.Any(x => receivers.Contains(x))) {
var s = senders.ToList();
var r = receivers.ToList();
for (var i = 0; i < r.Count || i < s.Count; i++) {
for (var i = 0; i < receivers.Count || i < senders.Count; i++) {
res.Add((
s[i],
r[i]
senders[i].Name,
receivers[i].Name
));
}
}
else {
res.Add((
HTMLHelpers.StringHelpers.GetEnumerationString(senders),
HTMLHelpers.StringHelpers.GetEnumerationString(receivers)
HTMLHelpers.StringHelpers.GetEnumerationString(senders.Select(x => x.Name)),
HTMLHelpers.StringHelpers.GetEnumerationString(receivers.Select(x => x.Name))
));
}
} else {
if (senders.Any(x => receivers.Contains(x))) {
for (var i = 0; i < receivers.Count || i < senders.Count; i++) {
res.Add((
HTMLHelpers.TagHelpers.CreateElement("a", "", "/HKB/Person/" + senders[i].Index) + senders[i].Name + HTMLHelpers.TagHelpers.CreateEndElement("a"),
HTMLHelpers.TagHelpers.CreateElement("a", "", "/HKB/Person/" + receivers[i].Index) + receivers[i].Name + HTMLHelpers.TagHelpers.CreateEndElement("a")
));
}
}
else {
res.Add((
GetEnumerationStringLinks(senders),
GetEnumerationStringLinks(receivers)
));
}
}
return res;
}
public static string GetEnumerationStringLinks(IEnumerable<Person> strlist) {
var res = string.Empty;
foreach (var str in strlist) {
if (str != strlist.First())
if (str == strlist.Last())
res += " und " + HTMLHelpers.TagHelpers.CreateElement("a", "", "/HKB/Person/" + str.Index) + str.Name + HTMLHelpers.TagHelpers.CreateEndElement("a");
else
res += ", " + HTMLHelpers.TagHelpers.CreateElement("a", "", "/HKB/Person/" + str.Index) + str.Name + HTMLHelpers.TagHelpers.CreateEndElement("a");
else
res += HTMLHelpers.TagHelpers.CreateElement("a", "", "/HKB/Person/" + str.Index) + str.Name + HTMLHelpers.TagHelpers.CreateEndElement("a");
}
return res;
}
}

View File

@@ -59,7 +59,7 @@ public class IndexController : Controller {
var metas = lib.Metas.Where(x => letters.Contains(x.Key)).Select(x => x.Value);
if (metas == null) return _error404();
var metasbyyear = metas.ToLookup(x => x.Sort.Year).OrderBy(x => x.Key).ToList();
return _paginateSend(lib, 0, metasbyyear, null, zhvolume, zhpage);
return _paginateSend(lib, 0, metasbyyear, null, null, zhvolume, zhpage);
}
return _error404();
}
@@ -76,25 +76,27 @@ public class IndexController : Controller {
[Route("/HKB/Person/{person}")]
public IActionResult Person(string person, int page = 0) {
var lib = _lib.GetLibrary();
if (String.IsNullOrWhiteSpace(person)) return _error404();
person = person.Trim();
var lib = _lib.GetLibrary();
if (!lib.Persons.ContainsKey(person)) return _error404();
List<IGrouping<int, Meta>>? metasbyyear = null;
Person p = lib.Persons[person];
CommentModel? comment = null;
if (p.Komm != null) comment = _getPersonComment(p.Komm);
var letters = lib.Metas
.Where(x => x.Value.Senders.Contains(person) || x.Value.Receivers.Contains(person))
.Select(x => x.Value);
if (letters == null) return _error404();
metasbyyear = letters.ToLookup(x => x.Sort.Year).OrderBy(x => x.Key).ToList();
return _paginateSend(lib, page, metasbyyear, person);
return _paginateSend(lib, page, metasbyyear, person, comment);
}
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)
.Select(x => (x.Key, x.Value.Name))
private List<(string Key, string Person)>? _getAvailablePersons() {
if (_lib.GetAvailablePersons() == null || !_lib.GetAvailablePersons()!.Any()) return null;
return _lib.GetAvailablePersons()!
.Select(x => (x.Index, x.Name))
.ToList();
}
@@ -126,6 +128,7 @@ public class IndexController : Controller {
int page,
List<IGrouping<int, Meta>> metasbyyear,
string? person = null,
CommentModel? personcomment = null,
string? zhvolume = null,
string? zhpage = null) {
var pages = Paginate(metasbyyear, _lettersForPage);
@@ -136,7 +139,7 @@ public class IndexController : Controller {
letters = metasbyyear
.Where(x => x.Key >= pages[page].StartYear && x.Key <= pages[page].EndYear)
.Select(x => (x.Key, x
.Select(y => Briefecontroller.GenerateMetaViewModel(lib, y))
.Select(y => Briefecontroller.GenerateMetaViewModel(lib, y, false))
.OrderBy(x => x.Meta.Sort)
.ThenBy(x => x.Meta.Order)
.ToList()))
@@ -152,15 +155,31 @@ public class IndexController : Controller {
_endYear.ToString(),
"ZH " + HTMLHelpers.ConversionHelpers.ToRoman(Int32.Parse(lastletter.ZH.Volume)) + ", S. " + lastletter.ZH.Page,
pages,
_getAvailablePersons(lib),
_getAvailablePersons(),
availablePages.OrderBy(x => x.Volume).ToList(),
zhvolume,
zhpage,
person
);
model.PersonComment = personcomment;
return View("~/Views/HKB/Dynamic/Index.cshtml", model);
}
private CommentModel? _getPersonComment(string comment) {
var lib = _lib.GetLibrary();
if (!lib.Comments.ContainsKey(comment)) return null;
var comm = lib.Comments[comment];
var parsedComment = HTMLHelpers.CommentHelpers.CreateHTML(lib, _readerService, comm, "neuzeit", Settings.ParsingState.CommentType.Comment, true); // Maybe true for Backlinks
List<string>? parsedSubComments = null;
if (comm.Kommentare != null) {
parsedSubComments = new List<string>();
foreach (var subcomm in comm.Kommentare.OrderBy(x => x.Value.Order)) {
parsedSubComments.Add(HTMLHelpers.CommentHelpers.CreateHTML(lib, _readerService, subcomm.Value, "neuzeit", Settings.ParsingState.CommentType.Subcomment, true));
}
}
return new CommentModel(parsedComment, parsedSubComments);
}
private IActionResult _error404() {
Response.StatusCode = 404;
return Redirect("/Error404");

View File

@@ -1,27 +1,9 @@
namespace HaWeb.Controllers;
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using HaWeb.Models;
using HaDocument.Interfaces;
using HaXMLReader.Interfaces;
using System.Text;
using HaXMLReader;
using HaXMLReader.EvArgs;
using HaDocument.Models;
using System.Collections.Concurrent;
using HaWeb.FileHelpers;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.WebUtilities;
using Microsoft.Extensions.Configuration;
using Microsoft.Net.Http.Headers;
using HaWeb.Filters;
using HaWeb.XMLParser;
using System.Text.Json.Serialization;
using System.Text.Json;
using Microsoft.FeatureManagement.Mvc;
using System.Runtime.InteropServices;
using Microsoft.AspNetCore.Http.Features;
[Route("/HKB/Register/[action]/{id?}")]
public class RegisterController : Controller {

View File

@@ -137,7 +137,7 @@ public class SucheController : Controller {
letters = metasbyyear
.Where(x => x.Key >= pages[page].StartYear && x.Key <= pages[page].EndYear)
.Select(x => (x.Key, x
.Select(y => Briefecontroller.GenerateMetaViewModel(lib, y))
.Select(y => Briefecontroller.GenerateMetaViewModel(lib, y, true))
.OrderBy(x => x.Meta.Sort)
.ThenBy(x => x.Meta.Order)
.ToList()))

View File

@@ -1,5 +1,6 @@
namespace HaWeb.FileHelpers;
using HaDocument.Interfaces;
using HaDocument.Models;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.Extensions.FileProviders;
using System.Collections.Concurrent;
@@ -13,19 +14,19 @@ public class HaDocumentWrapper : IHaDocumentWrappper {
private ILibrary Library;
private IXMLProvider _xmlProvider;
private IXMLService _xmlService;
private string _filepath;
public int StartYear { get; private set; }
public int EndYear { get; private set; }
private int _startYear;
private int _endYear;
private List<Person>? _availablePersons;
private Dictionary<string, Person>? _personsWithLetters;
// public List<SearchHelpers.CollectedItem>? SearchableLetters { get; private set; }
public HaDocumentWrapper(IXMLProvider xmlProvider, IXMLService service, IConfiguration configuration) {
_xmlProvider = xmlProvider;
_xmlService = service;
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);
@@ -40,39 +41,47 @@ public class HaDocumentWrapper : IHaDocumentWrappper {
}
}
public int GetStartYear() => StartYear;
public List<Person>? GetAvailablePersons() => _availablePersons;
public int GetEndYear() => EndYear;
public Dictionary<string, Person>? GetPersonsWithLetters() => _personsWithLetters;
public int GetStartYear() => _startYear;
public int GetEndYear() => _endYear;
public void SetEndYear(int end) {
this.EndYear = end;
this._endYear = end;
SetLibrary(_filepath);
}
public ILibrary ResetLibrary() {
var options = new HaWeb.Settings.HaDocumentOptions() { AvailableYearRange = (StartYear, EndYear )};
Library = HaDocument.Document.Create(options);
_filepath = options.HamannXMLFilePath;
return Library;
}
public ILibrary? SetLibrary(string filepath, ModelStateDictionary? ModelState = null) {
var sw = new System.Diagnostics.Stopwatch();
sw.Start();
// 1. Set ILibrary
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);
return null;
}
sw.Stop();
Console.WriteLine("ILIB: " + sw.ElapsedMilliseconds);
sw.Restart();
// 1a. Set Available Persons
var persons = Library.Metas.SelectMany(x => x.Value.Senders.Union(x.Value.Receivers)).Distinct();
_availablePersons = persons.Select(x => Library.Persons[x]).OrderBy(x => x.Surname).ThenBy(x => x.Prename).ToList();
// 1b. Setup a Dictionary with available Person ovierview Pages
_personsWithLetters = new Dictionary<string, Person>();
var availablePersonPages = Library.Persons.Where(x => !String.IsNullOrWhiteSpace(x.Value.Komm));
foreach (var p in availablePersonPages) {
if (!_personsWithLetters.ContainsKey(p.Value.Komm!)) {
_personsWithLetters.Add(p.Value.Komm, p.Value);
}
}
// 2. Set Library in Production, collect some Objects
if (_xmlService != null)
_xmlService.SetInProduction(System.Xml.Linq.XDocument.Load(filepath, System.Xml.Linq.LoadOptions.PreserveWhitespace));
sw.Stop();
Console.WriteLine("COLLECTIONS: " + sw.ElapsedMilliseconds);
// 3. Set Filepath
_filepath = filepath;
return Library;
}

View File

@@ -1,15 +1,16 @@
namespace HaWeb.FileHelpers;
using HaDocument.Interfaces;
using HaDocument.Models;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using HaXMLReader.Interfaces;
public interface IHaDocumentWrappper {
public ILibrary ResetLibrary();
public ILibrary? SetLibrary(string filepath, ModelStateDictionary ModelState);
public ILibrary GetLibrary();
public int GetStartYear();
public int GetEndYear();
public List<Person>? GetAvailablePersons();
public Dictionary<string, Person>? GetPersonsWithLetters();
public void SetEndYear(int end);
}

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@@ -15,10 +15,6 @@ public class BriefeMetaViewModel {
get => _SenderReceiver;
set {
if (value != null)
value.ForEach(x => {
HttpUtility.HtmlEncode(x.Sender);
HttpUtility.HtmlEncode(x.Receiver);
});
_SenderReceiver = value;
}
}

View File

@@ -7,6 +7,7 @@ public class IndexViewModel {
public int ActiveYear { get; private set; }
public List<(int StartYear, int EndYear)>? AvailableYears { get; private set; }
public string? ActivePerson { get; set; }
public CommentModel? PersonComment { get; set; }
public List<(string Key, string Name)>? AvailablePersons { get; private set; }
public List<(string Volume, List<string> Pages)>? AvailablePages { get; private set; }
public string? ActiveVolume { get; private set; }

View File

@@ -11,9 +11,22 @@
@if (Model.Letters != null) {
<div class="ha-indexhead">
@if (Model.PersonComment == null) {
<h1>Briefauswahl</h1>
<div class="ha-indexnav">
}
@if(Model.PersonComment != null) {
<div class="ha-comment">
<div class="ha-headcomment">
<div class="ha-commentmetatext">
Briefe von und an &emsp;
<a class="ha-reversefilter" asp-controller="Index" asp-action="Index">←&nbsp;Alle&nbsp;Briefe</a>
</div>
@Html.Raw(Model.PersonComment.ParsedComment)
</div>
</div>
}
@if (Model.AvailableYears != null && Model.AvailableYears.Any() && Model.AvailableYears.Count > 1) {
<div class="ha-indexnav">
@for(var i = 0; i < Model.AvailableYears.Count; i++) {
<a class="@(Model.ActiveYear == i ? "active" : "")" asp-route-person="@Model.ActivePerson" asp-controller="Index" asp-route-page="@i">
@if (Model.AvailableYears[i].StartYear != Model.AvailableYears[i].EndYear) {
@@ -28,8 +41,8 @@
}
</a>
}
}
</div>
}
</div>
<div class="ha-indexbody">

File diff suppressed because it is too large Load Diff

View File

@@ -38,15 +38,15 @@
/* NON THEME RULES */
.ha-index .ha-indexhead {
@apply pt-9 md:pt-12 px-9 md:px-16 border-b-2
@apply border-b-2
}
.ha-index .ha-indexhead h1 {
@apply font-bold text-2xl desktop:font-normal desktop:text-5xl mb-6 inline-block font-serif
@apply font-bold mt-9 md:mt-12 px-9 md:px-16 text-2xl desktop:font-normal desktop:text-5xl mb-7 inline-block font-serif
}
.ha-index .ha-indexhead .ha-indexnav {
@apply font-sans oldstyle-nums
@apply font-sans oldstyle-nums px-9 md:px-16 mt-2
}
.ha-index .ha-indexhead .ha-indexnav a {
@@ -61,6 +61,38 @@
@apply pt-6 clear-both flex flex-row gap-x-4
}
.ha-index .ha-comment {
@apply font-serif hyphenate px-9 md:px-16 py-3 pb-12 border-l-2
}
.ha-index .ha-comment .ha-commentmetatext {
@apply mt-9 md:mt-12
}
.ha-index .ha-comment .ha-commentmetatext a {
@apply float-right bg-slate-200 text-sm inline-block px-2 rounded
}
.ha-index .ha-comment .ha-lemma {
@apply font-bold font-bold text-2xl desktop:font-normal desktop:text-5xl mb-3 inline-block font-serif
}
.ha-index .ha-comment .ha-entry {
@apply max-w-[calc(780px-4rem)]
}
.ha-index .ha-comment a {
@apply underline decoration-dotted hover:decoration-solid
}
.ha-index .ha-comment .ha-letlinks {
@apply hidden
}
.ha-index .ha-comment .ha-letlinks .ha-hkb {
@apply inline
}
.ha-index .ha-indexbody .ha-letterlist {
@apply pb-4 basis-2/3 grow-0
}

File diff suppressed because one or more lines are too long