mirror of
https://github.com/Theodor-Springmann-Stiftung/hamann-ausgabe-core.git
synced 2025-10-29 09:15:33 +00:00
A lot of stuff related to parsing; index page input validation
This commit is contained in:
@@ -7,6 +7,7 @@ using HaDocument.Models;
|
||||
using HaXMLReader.Interfaces;
|
||||
using System.Collections.Specialized;
|
||||
using HaWeb.XMLParser;
|
||||
using System.Collections.Immutable;
|
||||
|
||||
namespace HaWeb.Controllers;
|
||||
|
||||
@@ -144,8 +145,7 @@ public class IndexController : Controller {
|
||||
.ThenBy(x => x.Meta.Order)
|
||||
.ToList()))
|
||||
.ToList();
|
||||
List<(string Volume, List<string> Pages)>? availablePages = null;
|
||||
availablePages = lib.Structure.Where(x => x.Key != "-1").Select(x => (x.Key, x.Value.Select(x => x.Key).ToList())).ToList();
|
||||
var availablePages = lib.Structure.Where(x => x.Key != "-1").ToDictionary(x => x.Key, y => y.Value.Keys.ToList());
|
||||
zhvolume = zhvolume == null ? "1" : zhvolume;
|
||||
|
||||
var lastletter = lib.MetasByDate.Last();
|
||||
@@ -156,7 +156,8 @@ public class IndexController : Controller {
|
||||
"ZH " + HTMLHelpers.ConversionHelpers.ToRoman(Int32.Parse(lastletter.ZH.Volume)) + ", S. " + lastletter.ZH.Page,
|
||||
pages,
|
||||
_getAvailablePersons(),
|
||||
availablePages.OrderBy(x => x.Volume).ToList(),
|
||||
availablePages,
|
||||
lib.Letters.Keys.ToList(),
|
||||
zhvolume,
|
||||
zhpage,
|
||||
person
|
||||
|
||||
@@ -49,8 +49,14 @@ public class HaDocumentWrapper : IHaDocumentWrappper {
|
||||
if (doc == null) doc = XDocument.Load(path, LoadOptions.PreserveWhitespace);
|
||||
|
||||
// 1. Parse the Document, create search Index
|
||||
var sw = new Stopwatch();
|
||||
sw.Start();
|
||||
if (_xmlService != null)
|
||||
_xmlService.CreateSearchables(doc);
|
||||
_xmlService.CreateCollections(doc);
|
||||
sw.Stop();
|
||||
Console.WriteLine("Parsed Collections, elapsed: " + sw.ElapsedMilliseconds);
|
||||
sw.Restart();
|
||||
|
||||
// 2. Set ILibrary
|
||||
try {
|
||||
Library = HaDocument.Document.Create(new HaWeb.Settings.HaDocumentOptions() { HamannXMLFilePath = path, AvailableYearRange = (_startYear, _endYear) }, doc.Root);
|
||||
@@ -58,6 +64,7 @@ public class HaDocumentWrapper : IHaDocumentWrappper {
|
||||
if (ModelState != null) ModelState.AddModelError("Error", "Das Dokument konnte nicht geparst werden: " + ex.Message);
|
||||
return null;
|
||||
}
|
||||
Console.WriteLine("Parsed ILib, elapsed: " + sw.ElapsedMilliseconds);
|
||||
|
||||
// 3a. Set Available Persons
|
||||
var persons = Library.Metas.SelectMany(x => x.Value.Senders.Union(x.Value.Receivers)).Distinct();
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace HaWeb.Models;
|
||||
|
||||
using System.Collections.Immutable;
|
||||
using HaDocument.Models;
|
||||
|
||||
public class IndexViewModel {
|
||||
@@ -8,15 +10,16 @@ public class IndexViewModel {
|
||||
public List<(int StartYear, int EndYear)>? AvailableYears { get; private set; }
|
||||
public string? ActivePerson { get; set; }
|
||||
public CommentModel? PersonComment { get; set; }
|
||||
public List<string>? AvailableLetters { get; private set; }
|
||||
public List<(string Key, string Name)>? AvailablePersons { get; private set; }
|
||||
public List<(string Volume, List<string> Pages)>? AvailablePages { get; private set; }
|
||||
public Dictionary<string, List<string>>? AvailablePages { get; private set; }
|
||||
public string? ActiveVolume { get; private set; }
|
||||
public string? ActivePage { get; private set; }
|
||||
|
||||
public string EndYear { get; private set; }
|
||||
|
||||
public string EndPageString { get; private set; }
|
||||
|
||||
|
||||
|
||||
public IndexViewModel(
|
||||
List<(int Year, List<BriefeMetaViewModel> LetterList)>? letters,
|
||||
int activeYear,
|
||||
@@ -24,7 +27,8 @@ public class IndexViewModel {
|
||||
string endPageString,
|
||||
List<(int StartYear, int EndYear)>? availableYears,
|
||||
List<(string Key, string Name)>? availablePersons,
|
||||
List<(string Volume, List<string> Pages)>? availablePages,
|
||||
Dictionary<string, List<string>>? availablePages,
|
||||
List<string>? availableLetters,
|
||||
string? activeVolume,
|
||||
string? activePage,
|
||||
string? activePerson
|
||||
@@ -34,6 +38,7 @@ public class IndexViewModel {
|
||||
Count = letters.Select(x => x.LetterList.Count).Aggregate(0, (x, y) => { x += y; return x; });
|
||||
else
|
||||
Count = 0;
|
||||
AvailableLetters = availableLetters;
|
||||
ActiveYear = activeYear;
|
||||
AvailableYears = availableYears;
|
||||
AvailablePersons = availablePersons;
|
||||
|
||||
@@ -5,7 +5,7 @@ using System.Xml.Linq;
|
||||
public class BackLinkCollection : HaWeb.XMLParser.IXMLCollection {
|
||||
private static readonly Random _random = new Random();
|
||||
public string Key { get; } = "backlinks";
|
||||
public string[] xPath { get; } = new string[] { "/opus/data/marginalien/marginal/link", "/opus/marginalien/marginal/link" };
|
||||
public string[] xPath { get; } = new string[] { "/opus/data/marginalien/marginal//link", "/opus/marginalien/marginal//link", "/opus/kommentare/kommentar//link", "/opus/data/kommentare/kommentar//link" };
|
||||
public Func<XElement, string?> GenerateKey { get; } = GetKey;
|
||||
public Func<XElement, IDictionary<string, string>?>? GenerateDataFields { get; } = GetDataFields;
|
||||
public Func<IEnumerable<CollectedItem>, IDictionary<string, ILookup<string, CollectedItem>>?>? GroupingsGeneration { get; } = GetLookups;
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
namespace HaWeb.Settings.XMLCollections;
|
||||
using HaWeb.Models;
|
||||
using System.Xml.Linq;
|
||||
using HaWeb.Models;
|
||||
|
||||
public class EditCollection : HaWeb.XMLParser.IXMLCollection {
|
||||
public string Key { get; } = "edits";
|
||||
public string[] xPath { get; } = new string[] { "/opus/edits/editreason", "/opus/data/edits/editreason" };
|
||||
public string[] xPath { get; } = new string[] {
|
||||
"/opus/data/document/letterText//edit",
|
||||
"/opus/document/letterText//edit",
|
||||
"/opus/data/traditions/letterTradition//edit",
|
||||
"/opus/traditions/letterTradition//edit"
|
||||
};
|
||||
public Func<XElement, string?> GenerateKey { get; } = GetKey;
|
||||
public Func<XElement, IDictionary<string, string>?>? GenerateDataFields { get; } = null;
|
||||
public Func<IEnumerable<CollectedItem>, IDictionary<string, ILookup<string, CollectedItem>>?>? GroupingsGeneration { get; } = null;
|
||||
@@ -13,7 +17,7 @@ public class EditCollection : HaWeb.XMLParser.IXMLCollection {
|
||||
public bool Searchable { get; } = true;
|
||||
|
||||
public static Func<XElement, string?> GetKey { get; } = (elem) => {
|
||||
var index = elem.Attribute("index");
|
||||
var index = elem.Attribute("ref");
|
||||
if (index != null && !String.IsNullOrWhiteSpace(index.Value))
|
||||
return index.Value;
|
||||
else return null;
|
||||
|
||||
21
HaWeb/Settings/XMLCollections/EditreasonCollection.cs
Normal file
21
HaWeb/Settings/XMLCollections/EditreasonCollection.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
namespace HaWeb.Settings.XMLCollections;
|
||||
using HaWeb.Models;
|
||||
using System.Xml.Linq;
|
||||
|
||||
public class EditreasonCollection : HaWeb.XMLParser.IXMLCollection {
|
||||
public string Key { get; } = "editreasons";
|
||||
public string[] xPath { get; } = new string[] { "/opus/edits/editreason", "/opus/data/edits/editreason" };
|
||||
public Func<XElement, string?> GenerateKey { get; } = GetKey;
|
||||
public Func<XElement, IDictionary<string, string>?>? GenerateDataFields { get; } = null;
|
||||
public Func<IEnumerable<CollectedItem>, IDictionary<string, ILookup<string, CollectedItem>>?>? GroupingsGeneration { get; } = null;
|
||||
public Func<IEnumerable<CollectedItem>, IDictionary<string, IEnumerable<CollectedItem>>?>? SortingsGeneration { get; } = null;
|
||||
public HaWeb.XMLParser.IXMLCollection[]? SubCollections { get; } = null;
|
||||
public bool Searchable { get; } = true;
|
||||
|
||||
public static Func<XElement, string?> GetKey { get; } = (elem) => {
|
||||
var index = elem.Attribute("index");
|
||||
if (index != null && !String.IsNullOrWhiteSpace(index.Value))
|
||||
return index.Value;
|
||||
else return null;
|
||||
};
|
||||
}
|
||||
23
HaWeb/Settings/XMLCollections/HandCollection.cs
Normal file
23
HaWeb/Settings/XMLCollections/HandCollection.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System.Xml.Linq;
|
||||
using HaWeb.Models;
|
||||
|
||||
public class HandCollection : HaWeb.XMLParser.IXMLCollection {
|
||||
public string Key { get; } = "hands";
|
||||
public string[] xPath { get; } = new string[] {
|
||||
"/opus/data/document/letterText//hand",
|
||||
"/opus/document/letterText//hand",
|
||||
"/opus/data/traditions/letterTradition//hand",
|
||||
"/opus/traditions/letterTradition//hand"
|
||||
};
|
||||
public Func<XElement, string?> GenerateKey { get; } = GetKey;
|
||||
public Func<XElement, IDictionary<string, string>?>? GenerateDataFields { get; } = null;
|
||||
public Func<IEnumerable<CollectedItem>, IDictionary<string, ILookup<string, CollectedItem>>?>? GroupingsGeneration { get; } = null;
|
||||
public Func<IEnumerable<CollectedItem>, IDictionary<string, IEnumerable<CollectedItem>>?>? SortingsGeneration { get; } = null;
|
||||
public HaWeb.XMLParser.IXMLCollection[]? SubCollections { get; } = null;
|
||||
public bool Searchable { get; } = true;
|
||||
|
||||
public static Func<XElement, string?> GetKey { get; } = (elem) => {
|
||||
// TODO IMPLEMENT
|
||||
return null;
|
||||
};
|
||||
}
|
||||
@@ -5,7 +5,6 @@
|
||||
ViewData["showCredits"] = "true";
|
||||
}
|
||||
|
||||
<script defer src="/js/index.js" asp-append-version="true"></script>
|
||||
|
||||
<div class="ha-index">
|
||||
@if (Model.Letters != null) {
|
||||
@@ -77,6 +76,7 @@
|
||||
<input name="id" type="text" id="ha-gotoletternumber" class="ha-gotoletternumber" />
|
||||
<button type="submit" id="ha-gotoformsubmit">Nachschlagen</button>
|
||||
</form>
|
||||
<div class="mr-2 leading-snug text-base px-1 text-red-700 bg-red-50 text-left h-5 whitespace-nowrap overflow-hidden opacity-0" id="ha-gotoinfo"></div>
|
||||
</div>
|
||||
|
||||
@* ZH Loopkup *@
|
||||
@@ -97,15 +97,15 @@
|
||||
<form class="ha-zhform" id="ha-zhform">
|
||||
<span>Z H Band</span>
|
||||
<select name="zhvolume" id="ha-zhformvolume">
|
||||
@foreach (var volume in Model.AvailablePages) {
|
||||
<option>@volume.Volume</option>
|
||||
@foreach (var volume in Model.AvailablePages.OrderBy(x => x.Key)) {
|
||||
<option>@volume.Key</option>
|
||||
}
|
||||
</select>
|
||||
<span>/ </span>
|
||||
<input name="zhpage" id="ha-zhformpage" type="text" value="@Model.ActivePage" placeholder="Seite"/>
|
||||
<button id="ha-zhformsubmit" type="submit">Nachschlagen</button>
|
||||
</form>
|
||||
|
||||
<div class="mr-2 leading-snug text-base px-1 text-red-700 bg-red-50 text-left h-5 whitespace-nowrap overflow-hidden opacity-0" id="ha-zhsearchinfo"></div>
|
||||
</div>
|
||||
|
||||
}
|
||||
@@ -150,4 +150,10 @@
|
||||
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
var AvailableLetters = new Set(@Html.Raw(Json.Serialize(Model.AvailableLetters)))
|
||||
var AvailablePages = @Html.Raw(Json.Serialize(Model.AvailablePages))
|
||||
</script>
|
||||
<script defer src="/js/index.js" asp-append-version="true"></script>
|
||||
@@ -18,16 +18,17 @@
|
||||
<div class="ha-activefilterinfo">
|
||||
@if (Model.SearchType == SearchType.Letters) {
|
||||
<span><span class="">Briefe</span>@if(Model.IncludeComments == true) {<span> und Stellenkommentare</span>}, die »@Model.ActiveSearch« enthalten. </span><br>
|
||||
<a class="ha-reversefilter" asp-controller="Index" asp-action="Index">← Briefübersicht</a>
|
||||
}
|
||||
@if (Model.SearchType == SearchType.Register) {
|
||||
<span><span class="">Registereinträge</span>, die »@Model.ActiveSearch« enthalten. </span><br>
|
||||
<a class="ha-reversefilter" asp-controller="Register" asp-action="Allgemein">← Registerübersicht</a><span> / </span>
|
||||
<a class="ha-reversefilter" asp-controller="Register" asp-action="Allgemein">← Register</a><span></span>
|
||||
}
|
||||
@if (Model.SearchType == SearchType.Science) {
|
||||
<span><span class="">Bibliografische Einträge</span>, die »@Model.ActiveSearch« enthalten. </span><br>
|
||||
<a class="ha-reversefilter" asp-controller="Register" asp-action="Forschung">← Forschungsbibliographie</a><span> / </span>
|
||||
<a class="ha-reversefilter" asp-controller="Register" asp-action="Forschung">← Forschungsbibliographie</a><span></span>
|
||||
}
|
||||
<a class="ha-reversefilter" asp-controller="Index" asp-action="Index">← Briefübersicht</a>
|
||||
|
||||
</div>
|
||||
}
|
||||
|
||||
@@ -47,17 +48,17 @@
|
||||
<div class="ha-alternativesearches">
|
||||
@if (Model.SearchType != SearchType.Letters) {
|
||||
<a asp-controller="Suche" asp-action="Briefe" asp-route-search="@Model.ActiveSearch" asp-route-comments="true" >
|
||||
Stattdessen Briefe / Stellenkommentare nach »@Model.ActiveSearch« durchsuchen →
|
||||
Briefe & Stellenkommentare nach »@Model.ActiveSearch« durchsuchen →
|
||||
</a>
|
||||
}
|
||||
@if (Model.SearchType != SearchType.Register) {
|
||||
<a asp-controller="Suche" asp-action="Register" asp-route-search="@Model.ActiveSearch" >
|
||||
Stattdessen Register nach »@Model.ActiveSearch« durchsuchen →
|
||||
Register nach »@Model.ActiveSearch« durchsuchen →
|
||||
</a>
|
||||
}
|
||||
@if (Model.SearchType != SearchType.Science) {
|
||||
<a asp-controller="Suche" asp-action="Science" asp-route-search="@Model.ActiveSearch" >
|
||||
Stattdessen Forschungsbibliographie nach »@Model.ActiveSearch« durchsuchen →
|
||||
Forschungsbibliographie nach »@Model.ActiveSearch« durchsuchen →
|
||||
</a>
|
||||
}
|
||||
</div>
|
||||
|
||||
@@ -16,7 +16,7 @@ public interface IXMLInteractionService {
|
||||
public Dictionary<string, SyntaxCheckModel>? GetSCCache();
|
||||
public void SetSCCache(Dictionary<string, SyntaxCheckModel>? cache);
|
||||
public XMLParsingState? Collect(List<IFileInfo> Files, Dictionary<string, IXMLRoot>? rootDefs); // XMLFileProvider
|
||||
public void CreateSearchables(XDocument document); // XMLFileProvider
|
||||
public void CreateCollections(XDocument document); // XMLFileProvider
|
||||
public Dictionary<string, SyntaxCheckModel>? Test(XMLParsingState? state, string gitcommit); // XMLFileProvider (optimal), Controller (right now)
|
||||
// Controller
|
||||
public List<(CollectedItem Item, List<(string Page, string Line, string Preview, string? Identifier)> Results)>? SearchCollection(string collection, string searchword, IReaderService reader, ILibrary? lib);
|
||||
|
||||
@@ -260,7 +260,7 @@ public class XMLInteractionService : IXMLInteractionService {
|
||||
return res.ToList();
|
||||
}
|
||||
|
||||
public void CreateSearchables(XDocument document) {
|
||||
public void CreateCollections(XDocument document) {
|
||||
if (document == null || _RootDefs == null) return;
|
||||
int numProcs = Environment.ProcessorCount;
|
||||
int concurrencyLevel = numProcs * 2;
|
||||
|
||||
@@ -155,7 +155,7 @@
|
||||
}
|
||||
|
||||
.ha-index .ha-indexbody .ha-filterlist {
|
||||
@apply hidden md:flex flex-col gap-y-9 pb-4 float-right max-w-lg basis-1/3 min-w-0 shrink
|
||||
@apply hidden md:flex flex-col gap-y-5 pb-4 float-right max-w-lg basis-1/3 min-w-0 shrink
|
||||
}
|
||||
|
||||
.ha-index .ha-indexbody .ha-filterlist .ha-filtertitle {
|
||||
@@ -194,6 +194,7 @@
|
||||
@apply float-right inline-block px-2 border bg-slate-50 disabled:bg-gray-200 border-slate-200 hover:border-black disabled:hover:border-slate-200 disabled:text-gray-600
|
||||
}
|
||||
|
||||
|
||||
.ha-index .ha-indexbody .ha-filterlist .ha-zhsearchfilter .ha-zhform {
|
||||
@apply py-1 pl-1 pr-2
|
||||
}
|
||||
@@ -213,6 +214,10 @@
|
||||
.ha-index .ha-indexbody .ha-filterlist .ha-zhsearchfilter .ha-zhform select {
|
||||
@apply px-1
|
||||
}
|
||||
|
||||
.ha-index .ha-indexbody .ha-filterlist .ha-searchfilter {
|
||||
@apply mb-5
|
||||
}
|
||||
|
||||
.ha-index .ha-indexbody .ha-filterlist .ha-searchfilter .ha-searchform {
|
||||
@apply py-1 pl-1 pr-2 flex flex-row gap-x-2
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,19 +1,49 @@
|
||||
function encode(e){return e.replace(/[^]/g,function(e){return"&#"+e.charCodeAt(0)+";"})}
|
||||
|
||||
const ACTIVATEGOTOFILTER = function(filter, button) {
|
||||
let f = filter.value;
|
||||
let gotoinfo = document.getElementById("ha-gotoinfo");
|
||||
|
||||
if (f === "") {
|
||||
if (gotoinfo != null && !gotoinfo.classList.contains("opacity-0")) gotoinfo.classList.add("opacity-0");
|
||||
button.disabled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof AvailableLetters !== 'undefined' && AvailableLetters != null && !AvailableLetters.has(f)) {
|
||||
if (gotoinfo != null) {
|
||||
gotoinfo.classList.remove("opacity-0");
|
||||
gotoinfo.innerHTML = "Brief Nr. " + encode(f) + " gibt es nicht.";
|
||||
}
|
||||
button.disabled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (gotoinfo != null && !gotoinfo.classList.contains("opacity-0")) gotoinfo.classList.add("opacity-0");
|
||||
button.disabled = false;
|
||||
}
|
||||
|
||||
const ACTIVATEZHSEARCH = function(volume, page, button) {
|
||||
let vol = volume.options[volume.selectedIndex].value;
|
||||
let pg = page.value;
|
||||
let gotoinfo = document.getElementById("ha-zhsearchinfo");
|
||||
|
||||
if (pg === "") {
|
||||
if (gotoinfo != null && !gotoinfo.classList.contains("opacity-0")) gotoinfo.classList.add("opacity-0");
|
||||
button.disabled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof AvailablePages !== 'undefined' && AvailablePages != null && AvailablePages[vol] != null && !(AvailablePages[vol].indexOf(pg) >= 0)) {
|
||||
if (gotoinfo != null) {
|
||||
gotoinfo.classList.remove("opacity-0");
|
||||
gotoinfo.innerHTML = "ZH Bd. " + encode(vol) + ", S. " + encode(pg) + " gibt es nicht.";
|
||||
}
|
||||
button.disabled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (gotoinfo != null && !gotoinfo.classList.contains("opacity-0")) gotoinfo.classList.add("opacity-0");
|
||||
button.disabled = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,5 +22,5 @@ if (document.getElementById("ha-scrollbutton") !== null) {
|
||||
document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera
|
||||
})
|
||||
// TODO: workaround, bc window does not recieve scroll events anymore
|
||||
setInterval(() => scrollFunction(), 2500);
|
||||
setInterval(() => scrollFunction(), 1500);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user