mirror of
https://github.com/Theodor-Springmann-Stiftung/hamann-ausgabe-core.git
synced 2025-10-29 09:15:33 +00:00
Indexnumber parsing disabled
This commit is contained in:
@@ -33,24 +33,22 @@ public class Briefecontroller : Controller {
|
||||
// Normalisation and Validation, (some) data aquisition
|
||||
if (id == null) return Redirect(url + defaultID);
|
||||
id = id.ToLower();
|
||||
var preliminarymeta = lib.Metas.Where(x => x.Value.Autopsic == id);
|
||||
if (preliminarymeta == null || !preliminarymeta.Any()) return error404();
|
||||
Meta? meta;
|
||||
if (!lib.Metas.TryGetValue(id, out meta)) return error404();
|
||||
|
||||
// Get all neccessary data
|
||||
var index = preliminarymeta.First().Key;
|
||||
var meta = preliminarymeta.First().Value;
|
||||
var text = lib.Letters.ContainsKey(index) ? lib.Letters[index] : null;
|
||||
var marginals = lib.MarginalsByLetter.Contains(index) ? lib.MarginalsByLetter[index] : null;
|
||||
var tradition = lib.Traditions.ContainsKey(index) ? lib.Traditions[index] : null;
|
||||
var editreasons = lib.Editreasons.ContainsKey(index) ? lib.EditreasonsByLetter[index] : null; // TODO: Order
|
||||
var hands = lib.Hands.ContainsKey(index) ? lib.Hands[index] : null;
|
||||
var text = lib.Letters.ContainsKey(id) ? lib.Letters[id] : null;
|
||||
var marginals = lib.Marginals.ContainsKey(id) ? lib.Marginals[id] : null;
|
||||
var tradition = lib.Traditions.ContainsKey(id) ? lib.Traditions[id] : null;
|
||||
var editreasons = lib.Editreasons.ContainsKey(id) ? lib.EditreasonsByLetter[id] : null; // TODO: Order
|
||||
var hands = lib.Hands.ContainsKey(id) ? lib.Hands[id] : null;
|
||||
var nextmeta = meta != lib.MetasByDate.Last() ? lib.MetasByDate.ItemRef(lib.MetasByDate.IndexOf(meta) + 1) : null;
|
||||
var prevmeta = meta != lib.MetasByDate.First() ? lib.MetasByDate.ItemRef(lib.MetasByDate.IndexOf(meta) - 1) : null;
|
||||
|
||||
// More Settings and variables
|
||||
ViewData["Title"] = "HKB – Brief " + id.ToLower();
|
||||
ViewData["SEODescription"] = "HKB – Brief " + id.ToLower();
|
||||
ViewData["Filename"] = "HKB_" + meta.Autopsic + ".pdf";
|
||||
ViewData["Filename"] = "HKB_" + meta.ID + ".pdf";
|
||||
if (!string.IsNullOrWhiteSpace(search)) {
|
||||
ViewData["Mark"] = search;
|
||||
}
|
||||
@@ -58,9 +56,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, 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);
|
||||
var model = new BriefeViewModel(id, id, GenerateMetaViewModel(lib, meta, true));
|
||||
if (nextmeta != null) model.MetaData.Next = (GenerateMetaViewModel(lib, nextmeta, false), url + nextmeta.ID);
|
||||
if (prevmeta != null) model.MetaData.Prev = (GenerateMetaViewModel(lib, prevmeta, false), url + prevmeta.ID);
|
||||
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;
|
||||
@@ -130,8 +128,8 @@ public class Briefecontroller : Controller {
|
||||
}
|
||||
|
||||
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 hasText = lib.Letters.ContainsKey(meta.ID) ? true : false;
|
||||
var hasMarginals = lib.Marginals.ContainsKey(meta.ID) ? true : false;
|
||||
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;
|
||||
|
||||
@@ -30,7 +30,7 @@ public class IndexController : Controller {
|
||||
if (String.IsNullOrWhiteSpace(letterno)) return _error404();
|
||||
letterno = letterno.Trim();
|
||||
var lib = _lib.GetLibrary();
|
||||
var letter = lib.Metas.Where(x => x.Value.Autopsic == letterno);
|
||||
var letter = lib.Metas.ContainsKey(letterno) ? lib.Metas[letterno] : null;
|
||||
if (letter != null)
|
||||
return RedirectToAction("Index", "Briefe", new { id = letterno });
|
||||
return _error404();
|
||||
@@ -50,7 +50,7 @@ public class IndexController : Controller {
|
||||
if (letters != null && letters.Any() && letters.Count == 1) {
|
||||
string? autopsic = null;
|
||||
if (lib.Metas.ContainsKey(letters.First())) {
|
||||
autopsic = lib.Metas[letters.First()].Autopsic;
|
||||
autopsic = lib.Metas[letters.First()].ID;
|
||||
}
|
||||
if (autopsic == null) return _error404();
|
||||
return RedirectToAction("Index", "Briefe", new { id = autopsic });
|
||||
|
||||
@@ -41,7 +41,7 @@ public class SucheController : Controller {
|
||||
|
||||
// Letter & comment search and search result creation
|
||||
var resletter = _xmlService.SearchCollection("letters", search, _readerService, null);
|
||||
List<(string Index, List<(string Page, string Line, string Preview, string Identifier)> Results)>? rescomments = null;
|
||||
List<(CollectedItem, List<(string Page, string Line, string Preview, string Identifier)> Results)>? rescomments = null;
|
||||
if (comments == true)
|
||||
rescomments = _xmlService.SearchCollection("marginals", search, _readerService, lib);
|
||||
|
||||
@@ -54,17 +54,15 @@ public class SucheController : Controller {
|
||||
if (resletter != null)
|
||||
metas.AddRange(
|
||||
resletter
|
||||
.Select(x => x.Index)
|
||||
.Select(x => x.Item.ID)
|
||||
.Where(x => lib.Metas.ContainsKey(x))
|
||||
.Select(x => lib.Metas[x])
|
||||
);
|
||||
if (rescomments != null)
|
||||
metas.AddRange(
|
||||
rescomments
|
||||
.Where(x => lib.Marginals.ContainsKey(x.Index))
|
||||
.Select(x => lib.Marginals[x.Index])
|
||||
.Where(x => lib.Metas.ContainsKey(x.Letter))
|
||||
.Select(x => lib.Metas[x.Letter])
|
||||
.Where(x => lib.Metas.ContainsKey(x.Item1.ID.Split('-').First()))
|
||||
.Select(x => lib.Metas[x.Item1.ID.Split('-').First()])
|
||||
);
|
||||
|
||||
// Return
|
||||
@@ -83,14 +81,12 @@ public class SucheController : Controller {
|
||||
search = search.Trim();
|
||||
|
||||
// Search
|
||||
List<(string Index, List<(string Page, string Line, string Preview, string Identifier)> Results)>? res = null;
|
||||
|
||||
res = _xmlService.SearchCollection("register-comments", search, _readerService, lib);
|
||||
var res = _xmlService.SearchCollection("register-comments", search, _readerService, lib);
|
||||
if (res == null || !res.Any())
|
||||
return _paginateSendRegister(lib, search, SearchType.Register, SearchResultType.NotFound, null);
|
||||
|
||||
// Return
|
||||
return _paginateSendRegister(lib, search, SearchType.Register, SearchResultType.Success, _createComments("neuzeit", res.Select((x) => (x.Index, x.Results.Select((y) => y.Identifier).ToList())).OrderBy(x => x.Index).ToList()));
|
||||
return _paginateSendRegister(lib, search, SearchType.Register, SearchResultType.Success, _createComments("neuzeit", res.Select((x) => (x.Item.ID, x.Results.Select((y) => y.Identifier).ToList())).OrderBy(x => x.ID).ToList()));
|
||||
|
||||
}
|
||||
|
||||
@@ -105,13 +101,12 @@ public class SucheController : Controller {
|
||||
search = search.Trim();
|
||||
|
||||
// Search
|
||||
List<(string Index, List<(string Page, string Line, string Preview, string Identifier)> Results)>? res = null;
|
||||
res = _xmlService.SearchCollection("forschung-comments", search, _readerService, lib);
|
||||
var res = _xmlService.SearchCollection("forschung-comments", search, _readerService, lib);
|
||||
if (res == null || !res.Any())
|
||||
return _paginateSendRegister(lib, search, SearchType.Science, SearchResultType.NotFound, null);
|
||||
|
||||
// Return
|
||||
return _paginateSendRegister(lib, search, SearchType.Science, SearchResultType.Success, _createComments("neuzeit", res.Select((x) => (x.Index, x.Results.Select((y) => y.Identifier).ToList())).OrderBy(x => x.Index).ToList()));
|
||||
return _paginateSendRegister(lib, search, SearchType.Science, SearchResultType.Success, _createComments("neuzeit", res.Select((x) => (x.Item.ID, x.Results.Select((y) => y.Identifier).ToList())).OrderBy(x => x.ID).ToList()));
|
||||
|
||||
}
|
||||
|
||||
@@ -122,8 +117,8 @@ public class SucheController : Controller {
|
||||
bool? comments,
|
||||
SearchResultType SRT,
|
||||
List<Meta>? metas,
|
||||
List<(string Index, List<(string Page, string Line, string Preview, string Identifier)> Results)>? resletters,
|
||||
List<(string Index, List<(string Page, string Line, string Preview, string Identifier)> Results)>? rescomments
|
||||
List<(CollectedItem, List<(string Page, string Line, string Preview, string Identifier)> Results)>? resletters,
|
||||
List<(CollectedItem, List<(string Page, string Line, string Preview, string Identifier)> Results)>? rescomments
|
||||
) {
|
||||
// Sorting, get Pages & Error Checking
|
||||
var metasbyyear = metas!.Distinct().ToLookup(x => x.Sort.Year).OrderBy(x => x.Key).ToList();
|
||||
@@ -148,31 +143,31 @@ public class SucheController : Controller {
|
||||
Dictionary<string, List<(Marginal, string)>>? parsedMarginals = null;
|
||||
if (resletters != null)
|
||||
foreach (var res in resletters) {
|
||||
if (!searchResults.ContainsKey(res.Index))
|
||||
searchResults.Add(res.Index, new List<SearchResult>());
|
||||
if (!searchResults.ContainsKey(res.Item1.ID))
|
||||
searchResults.Add(res.Item1.ID, new List<SearchResult>());
|
||||
foreach (var r in res.Results) {
|
||||
if(!searchResults[res.Index].Where(x => x.Page == r.Page && x.Line == r.Line).Any())
|
||||
searchResults[res.Index].Add(new SearchResult(search, res.Index) { Page = r.Page, Line = r.Line, Preview = r.Preview });
|
||||
if(!searchResults[res.Item1.ID].Where(x => x.Page == r.Page && x.Line == r.Line).Any())
|
||||
searchResults[res.Item1.ID].Add(new SearchResult(search, res.Item1.ID) { Page = r.Page, Line = r.Line, Preview = r.Preview });
|
||||
}
|
||||
if (searchResults[res.Index].Any()) {
|
||||
searchResults[res.Index] = searchResults[res.Index].OrderBy(x => HaWeb.HTMLHelpers.ConversionHelpers.RomanOrNumberToInt(x.Page)).ThenBy(x => HaWeb.HTMLHelpers.ConversionHelpers.RomanOrNumberToInt(x.Line)).ToList();
|
||||
if (searchResults[res.Item1.ID].Any()) {
|
||||
searchResults[res.Item1.ID] = searchResults[res.Item1.ID].OrderBy(x => HaWeb.HTMLHelpers.ConversionHelpers.RomanOrNumberToInt(x.Page)).ThenBy(x => HaWeb.HTMLHelpers.ConversionHelpers.RomanOrNumberToInt(x.Line)).ToList();
|
||||
}
|
||||
}
|
||||
if (rescomments != null) {
|
||||
var marginals = rescomments.Where(x => lib.Marginals.ContainsKey(x.Index)).Select(x => lib.Marginals[x.Index]).ToLookup(x => x.Letter);
|
||||
var shownletters = letters!.SelectMany(x => x.LetterList.Select(y => y.Meta.Index)).ToHashSet();
|
||||
var marginals = rescomments.Select(x => Marginal.FromXElement(x.Item1.Element)).ToLookup(x => x.Letter);
|
||||
var shownletters = letters!.SelectMany(x => x.LetterList.Select(y => y.Meta.ID)).ToHashSet();
|
||||
var shownmarginals = marginals!.Where(x => shownletters.Contains(x.Key)).Select(x => (x.Key, x.ToList())).ToList();
|
||||
var previews = _xmlService != null ? _xmlService.GetPreviews(shownmarginals, _readerService ,lib) : null;
|
||||
if (previews != null)
|
||||
foreach (var p in previews) {
|
||||
if (!searchResults.ContainsKey(p.Index))
|
||||
searchResults.Add(p.Index, new List<SearchResult>());
|
||||
if (!searchResults.ContainsKey(p.Item.ID))
|
||||
searchResults.Add(p.Item.ID, new List<SearchResult>());
|
||||
foreach (var res in p.Results) {
|
||||
if (!searchResults[p.Index].Where(x => x.Page == res.Page && x.Line == res.Line).Any())
|
||||
searchResults[p.Index].Add(new SearchResult(search, p.Index) { Page = res.Page, Line = res.Line, Preview = res.Preview });
|
||||
if (!searchResults[p.Item.ID].Where(x => x.Page == res.Page && x.Line == res.Line).Any())
|
||||
searchResults[p.Item.ID].Add(new SearchResult(search, p.Item.ID) { Page = res.Page, Line = res.Line, Preview = res.Preview });
|
||||
}
|
||||
if (searchResults[p.Index].Any()) {
|
||||
searchResults[p.Index] = searchResults[p.Index].OrderBy(x => HaWeb.HTMLHelpers.ConversionHelpers.RomanOrNumberToInt(x.Page)).ThenBy(x => HaWeb.HTMLHelpers.ConversionHelpers.RomanOrNumberToInt(x.Line)).ToList();
|
||||
if (searchResults[p.Item.ID].Any()) {
|
||||
searchResults[p.Item.ID] = searchResults[p.Item.ID].OrderBy(x => HaWeb.HTMLHelpers.ConversionHelpers.RomanOrNumberToInt(x.Page)).ThenBy(x => HaWeb.HTMLHelpers.ConversionHelpers.RomanOrNumberToInt(x.Line)).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,10 +38,10 @@ public static class CommentHelpers {
|
||||
sb.Append(HTMLHelpers.TagHelpers.CreateEndElement(DEFAULTELEMENT));
|
||||
arrow = true;
|
||||
}
|
||||
sb.Append(HTMLHelpers.TagHelpers.CreateElement("a", LETLINKCLASS, "/HKB/Briefe/" + let.Autopsic + "#" + blk.Page + "-" + blk.Line));
|
||||
sb.Append(HTMLHelpers.TagHelpers.CreateElement("a", LETLINKCLASS, "/HKB/Briefe/" + let.ID + "#" + blk.Page + "-" + blk.Line));
|
||||
var linkstring = string.Empty;
|
||||
var pglnstring = string.Empty;
|
||||
linkstring += let.Autopsic;
|
||||
linkstring += let.ID;
|
||||
pglnstring += " ( " + blk.Page + "/" + blk.Line + " )";
|
||||
linkstring += pglnstring;
|
||||
sb.Append(linkstring);
|
||||
|
||||
@@ -46,12 +46,12 @@ public class LinkHelper {
|
||||
new HaWeb.HTMLHelpers.TagHelpers.Attribute() { Name = "rel", Value = "noopener noreferrer" }));
|
||||
if (tag.Name == "intlink" && tag.Values.ContainsKey("letter") && _lib.Metas.ContainsKey(tag["letter"])) {
|
||||
var letter = _lib.Metas[tag["letter"]];
|
||||
_sb.Append(HTMLHelpers.TagHelpers.CreateElement("a", LETLINKCLASS, "/HKB/Briefe/" + letter.Autopsic + "#" + tag["page"] + "-" + tag["line"]));
|
||||
_sb.Append(HTMLHelpers.TagHelpers.CreateElement("a", LETLINKCLASS, "/HKB/Briefe/" + letter.ID + "#" + tag["page"] + "-" + tag["line"]));
|
||||
if (!tag.Values.ContainsKey("linktext") || tag.Values["linktext"] == "true") {
|
||||
var linkstring = string.Empty;
|
||||
var ZHstring = string.Empty;
|
||||
var pglnstring = string.Empty;
|
||||
linkstring += "HKB " + letter.Autopsic;
|
||||
linkstring += "HKB " + letter.ID;
|
||||
if (tag.Values.ContainsKey("page")) {
|
||||
pglnstring += tag["page"];
|
||||
if (tag.Values.ContainsKey("line")) {
|
||||
|
||||
@@ -6,29 +6,29 @@ using HaWeb.XMLParser;
|
||||
using System.Xml.Linq;
|
||||
|
||||
public class CollectedItem : ISearchable {
|
||||
public string Index { get; private set; }
|
||||
public string ID { get; private set; }
|
||||
public string? SearchText { get; private set; }
|
||||
public IDictionary<string, string>? Fields { get; private set; }
|
||||
public XElement ELement { get; private set; }
|
||||
public XElement Element { get; private set; }
|
||||
public IXMLCollection Collection { get; private set; }
|
||||
public IDictionary<string, CollectedItem>? Items { get; set; }
|
||||
|
||||
public CollectedItem(
|
||||
string index,
|
||||
string id,
|
||||
XElement element,
|
||||
IXMLCollection collection,
|
||||
IDictionary<string, string>? fields,
|
||||
string? searchtext = null
|
||||
) {
|
||||
this.Index = index;
|
||||
this.ID = id;
|
||||
this.SearchText = searchtext;
|
||||
this.Collection = collection;
|
||||
this.ELement = element;
|
||||
this.Fields = fields;
|
||||
this.Element = element;
|
||||
}
|
||||
|
||||
public string? this[string v] {
|
||||
get {
|
||||
if (Fields == null && Collection.GenerateDataFields != null)
|
||||
Fields = Collection.GenerateDataFields(this.Element);
|
||||
if (Fields != null && Fields.ContainsKey(v))
|
||||
return Fields[v];
|
||||
return null;
|
||||
|
||||
@@ -63,7 +63,7 @@ ChangeToken.OnChange(
|
||||
);
|
||||
|
||||
app.UseWebSockets( new WebSocketOptions {
|
||||
KeepAliveInterval = TimeSpan.FromMinutes(180)
|
||||
KeepAliveInterval = TimeSpan.FromMinutes(180),
|
||||
});
|
||||
app.UseMiddleware<WebSocketMiddleware>();
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace HaWeb.SearchHelpers;
|
||||
|
||||
public interface ISearchable {
|
||||
public string Index { get; }
|
||||
public string ID { get; }
|
||||
public string? SearchText { get; }
|
||||
}
|
||||
@@ -10,8 +10,8 @@ public class LetterDescNode : INodeRule
|
||||
Documents = new[] { "metadaten" },
|
||||
XPath = "//letterDesc"
|
||||
};
|
||||
public string[]? Attributes { get; } = { "ref" };
|
||||
public string? uniquenessAttribute => "ref" ;
|
||||
public string[]? Attributes { get; } = { "letter" };
|
||||
public string? uniquenessAttribute => "letter" ;
|
||||
public List<(string, HamannXPath, string)>? References { get; } = new List<(string, HamannXPath, string)>()
|
||||
{
|
||||
};
|
||||
|
||||
@@ -10,8 +10,8 @@ public class LetterTextNode : INodeRule
|
||||
Documents = new[] { "brieftext" },
|
||||
XPath = "//letterText"
|
||||
};
|
||||
public string[]? Attributes { get; } = { "index" };
|
||||
public string? uniquenessAttribute => "index" ;
|
||||
public string[]? Attributes { get; } = { "letter" };
|
||||
public string? uniquenessAttribute => "letter" ;
|
||||
public List<(string, HamannXPath, string)>? References { get; } = new List<(string, HamannXPath, string)>()
|
||||
{
|
||||
};
|
||||
|
||||
@@ -10,8 +10,8 @@ public class LetterTraditionNode : INodeRule
|
||||
Documents = new[] { "ueberlieferung" },
|
||||
XPath = "//letterTradition"
|
||||
};
|
||||
public string[]? Attributes { get; } = { "ref" };
|
||||
public string? uniquenessAttribute => "ref" ;
|
||||
public string[]? Attributes { get; } = { "letter" };
|
||||
public string? uniquenessAttribute => "letter" ;
|
||||
public List<(string, HamannXPath, string)>? References { get; } = new List<(string, HamannXPath, string)>()
|
||||
{
|
||||
};
|
||||
|
||||
@@ -10,8 +10,8 @@ public class MarginalNode : INodeRule
|
||||
Documents = new[] { "stellenkommentar" },
|
||||
XPath = "//marginal"
|
||||
};
|
||||
public string[]? Attributes { get; } = { "index", "letter", "page", "line" };
|
||||
public string? uniquenessAttribute => "index";
|
||||
public string[]? Attributes { get; } = { "letter", "page", "line" };
|
||||
public string? uniquenessAttribute { get; }
|
||||
public List<(string, HamannXPath, string)>? References { get; } = new List<(string, HamannXPath, string)>()
|
||||
{
|
||||
};
|
||||
|
||||
@@ -16,7 +16,7 @@ public class StructureCollection : ICollectionRule {
|
||||
|
||||
public IEnumerable<(string, XElement, XMLRootDocument)> GenerateIdentificationStrings(IEnumerable<(XElement, XMLRootDocument)> list) {
|
||||
foreach (var e in list) {
|
||||
var id = e.Item1.Name == "letterText" ? e.Item1.Attribute("index")!.Value : e.Item1.Attribute("ref")!.Value;
|
||||
var id = e.Item1.Attribute("letter")!.Value;
|
||||
var currpage = String.Empty;
|
||||
var currline = String.Empty;
|
||||
foreach (var el in e.Item1.Descendants()) {
|
||||
|
||||
@@ -233,7 +233,7 @@ public class TextRules {
|
||||
{
|
||||
if(reader.State.ParsedMarginals == null) reader.State.ParsedMarginals = new List<(string, string, string)>();
|
||||
var sb2 = new StringBuilder();
|
||||
margs = margs.OrderBy(x => Int32.Parse(x.Index));
|
||||
if (margs.Count() > 1) margs = margs.OrderBy(x => Int32.Parse(x.Sort));
|
||||
sb.Append(HaWeb.HTMLHelpers.TagHelpers.CreateElement(DEFAULTELEMENT, CSSClasses.COMMENTMARKERCLASS, "ma-" + reader.State.currpage + "-" + reader.State.currline));
|
||||
sb.Append(HaWeb.HTMLHelpers.TagHelpers.CreateEndElement(DEFAULTELEMENT));
|
||||
sb.Append(HaWeb.HTMLHelpers.TagHelpers.CreateElement(DEFAULTELEMENT, CSSClasses.MARGINGALBOXCLASS));
|
||||
|
||||
@@ -14,24 +14,26 @@ public class BackLinkCollection : HaWeb.XMLParser.IXMLCollection {
|
||||
public bool Searchable { get; } = true;
|
||||
|
||||
public static Func<XElement, string?> GetKey { get; } = (elem) => {
|
||||
var margid = (string?)elem.Ancestors("marginal").First().Attribute("index");
|
||||
if (String.IsNullOrWhiteSpace(margid)) return null;
|
||||
return margid + _random.Next().ToString();
|
||||
var letter = (string?)elem.Attribute("letter");
|
||||
var page = (string?)elem.Attribute("page");
|
||||
var line = (string?)elem.Attribute("line");
|
||||
if (letter == null) return null;
|
||||
var index = letter + "-" + page ?? "" + "-" + line ?? "";
|
||||
if (String.IsNullOrWhiteSpace(index)) return null;
|
||||
return index + _random.Next().ToString();
|
||||
};
|
||||
|
||||
public static IDictionary<string, string>? GetDataFields(XElement element) {
|
||||
var res = new Dictionary<string, string>();
|
||||
var marg = element.Ancestors("marginal").First();
|
||||
var index = (string?)marg.Attribute("index");
|
||||
var letter = (string?)marg.Attribute("letter");
|
||||
var page = (string?)marg.Attribute("page");
|
||||
var line = (string?)marg.Attribute("line");
|
||||
var refere = (string?)element.Attribute("ref");
|
||||
var subref = (string?)element.Attribute("subref");
|
||||
if (index == null || letter == null || (refere == null && subref == null)) return null;
|
||||
if (letter == null || (refere == null && subref == null)) return null;
|
||||
if (subref != null) res.Add("ref", subref);
|
||||
else res.Add("ref", refere!);
|
||||
res.Add("index", index);
|
||||
res.Add("letter", letter);
|
||||
if (page != null) res.Add("page", page);
|
||||
if (line != null) res.Add("line", line);
|
||||
|
||||
@@ -22,9 +22,9 @@ public static class CommentCollectionHelpers {
|
||||
|
||||
public static IDictionary<string, ILookup<string, CollectedItem>>? GetLookups(IEnumerable<CollectedItem> items) {
|
||||
var res = new Dictionary<string, ILookup<string, CollectedItem>>();
|
||||
var lemmas = items.Where(x => !String.IsNullOrWhiteSpace(x.Index));
|
||||
var lemmas = items.Where(x => !String.IsNullOrWhiteSpace(x.ID));
|
||||
if (lemmas != null && lemmas.Any())
|
||||
res.Add("lemma", lemmas.ToLookup(x => x.Index.Substring(0, 1).ToUpper()));
|
||||
res.Add("lemma", lemmas.ToLookup(x => x.ID.Substring(0, 1).ToUpper()));
|
||||
// If we use lemmas
|
||||
// var lemmas = items.Where(x => x.Fields != null && x.Fields.ContainsKey("lemma"));
|
||||
// if (lemmas != null && lemmas.Any())
|
||||
|
||||
@@ -13,7 +13,7 @@ public class LetterCollection : 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("letter");
|
||||
if (index != null && !String.IsNullOrWhiteSpace(index.Value))
|
||||
return index.Value;
|
||||
else return null;
|
||||
|
||||
@@ -13,9 +13,14 @@ public class MarginalCollection : HaWeb.XMLParser.IXMLCollection {
|
||||
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;
|
||||
var letter = (string?)elem.Attribute("letter");
|
||||
var page = (string?)elem.Attribute("page");
|
||||
var line = (string?)elem.Attribute("line");
|
||||
var sort = (string?)elem.Attribute("sort");
|
||||
if (letter == null || page == null || line == null) return null;
|
||||
var index = letter + "-" + page + "-" + line + sort ?? "";
|
||||
if (index != null && !String.IsNullOrWhiteSpace(index))
|
||||
return index;
|
||||
else return null;
|
||||
};
|
||||
|
||||
@@ -24,10 +29,12 @@ public class MarginalCollection : HaWeb.XMLParser.IXMLCollection {
|
||||
var letter = (string?)element.Attribute("letter");
|
||||
var page = (string?)element.Attribute("page");
|
||||
var line = (string?)element.Attribute("line");
|
||||
var sort = (string?)element.Attribute("sort");
|
||||
if (letter == null || page == null || line == null) return null;
|
||||
res.Add("letter", letter);
|
||||
res.Add("page", page);
|
||||
res.Add("line", line);
|
||||
if (sort != null) res.Add("sort", sort);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ public class MetaCollection : HaWeb.XMLParser.IXMLCollection {
|
||||
public bool Searchable { get; } = false;
|
||||
|
||||
public static Func<XElement, string?> GetKey { get; } = (elem) => {
|
||||
var index = elem.Attribute("ref");
|
||||
var index = elem.Attribute("letter");
|
||||
if (index != null && !String.IsNullOrWhiteSpace(index.Value))
|
||||
return index.Value;
|
||||
return null;
|
||||
|
||||
@@ -13,7 +13,7 @@ public class TraditionCollection : HaWeb.XMLParser.IXMLCollection {
|
||||
public bool Searchable { get; } = true;
|
||||
|
||||
public static Func<XElement, string?> GetKey { get; } = (elem) => {
|
||||
var index = elem.Attribute("ref");
|
||||
var index = elem.Attribute("letter");
|
||||
if (index != null && !String.IsNullOrWhiteSpace(index.Value))
|
||||
return index.Value;
|
||||
return null;
|
||||
|
||||
@@ -53,7 +53,7 @@
|
||||
{
|
||||
|
||||
<a class="ml-1" href="@Model.PDFFilePath">
|
||||
<div class="inline-block bg-slate-100 hover:bg-slate-200 border px-1.5 rounded">Brief @Model.MetaData.Meta.Autopsic</div>
|
||||
<div class="inline-block bg-slate-100 hover:bg-slate-200 border px-1.5 rounded">Brief @Model.MetaData.Meta.ID</div>
|
||||
</a>
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@
|
||||
@if (Model.MetaData.Prev != null)
|
||||
{
|
||||
<a href="@Model.MetaData.Prev.Value.Item2">
|
||||
@Model.MetaData.Prev.Value.Model.Meta.Autopsic ◀
|
||||
@Model.MetaData.Prev.Value.Model.Meta.ID ◀
|
||||
</a>
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@
|
||||
@if (Model.MetaData.Next != null)
|
||||
{
|
||||
<a href="@Model.MetaData.Next.Value.Item2">
|
||||
▶ @Model.MetaData.Next.Value.Model.Meta.Autopsic
|
||||
▶ @Model.MetaData.Next.Value.Model.Meta.ID
|
||||
</a>
|
||||
}
|
||||
</div>
|
||||
|
||||
@@ -56,7 +56,7 @@
|
||||
@foreach (var year in Model.Letters) {
|
||||
foreach (var letter in year.LetterList) {
|
||||
<div class="ha-letterlistentry">
|
||||
<a asp-controller="Briefe" asp-action="Index" asp-route-id="@letter.Meta.Autopsic">
|
||||
<a asp-controller="Briefe" asp-action="Index" asp-route-id="@letter.Meta.ID">
|
||||
@await Html.PartialAsync("/Views/Shared/_LetterHead.cshtml", (letter, true, false))
|
||||
</a>
|
||||
</div>
|
||||
|
||||
@@ -84,27 +84,27 @@
|
||||
@foreach (var year in Model.Letters) {
|
||||
foreach (var letter in year.LetterList) {
|
||||
<div class="ha-letterlistentry">
|
||||
<a asp-controller="Briefe" asp-action="Index" asp-route-id="@letter.Meta.Autopsic">
|
||||
<a asp-controller="Briefe" asp-action="Index" asp-route-id="@letter.Meta.ID">
|
||||
@Html.Partial("/Views/Shared/_LetterHead.cshtml", (letter, true, false))
|
||||
</a>
|
||||
|
||||
@if (Model.SearchResults != null && Model.SearchResults.ContainsKey(letter.Meta.Index)) {
|
||||
@if (Model.SearchResults != null && Model.SearchResults.ContainsKey(letter.Meta.ID)) {
|
||||
<div class="ha-letterlistsearchresults">
|
||||
@foreach (var sr in Model.SearchResults[letter.Meta.Index])
|
||||
@foreach (var sr in Model.SearchResults[letter.Meta.ID])
|
||||
{
|
||||
<div class="ha-letterlistsearchresult">
|
||||
<div class="ha-searchresultlocation">
|
||||
<a asp-controller="Briefe" asp-action="Index" asp-route-id="@letter.Meta.Autopsic" asp-route-search="@Model.ActiveSearch" asp-fragment="@sr.Page-@sr.Line">
|
||||
HKB @letter.Meta.Autopsic @sr.Page/@sr.Line
|
||||
<a asp-controller="Briefe" asp-action="Index" asp-route-id="@letter.Meta.ID" asp-route-search="@Model.ActiveSearch" asp-fragment="@sr.Page-@sr.Line">
|
||||
HKB @letter.Meta.ID @sr.Page/@sr.Line
|
||||
</a>
|
||||
</div>
|
||||
<div class="ha-searchresultpreview">
|
||||
<a asp-controller="Briefe" asp-action="Index" asp-route-id="@letter.Meta.Autopsic" asp-route-search="@Model.ActiveSearch" asp-fragment="@sr.Page-@sr.Line">
|
||||
<a asp-controller="Briefe" asp-action="Index" asp-route-id="@letter.Meta.ID" asp-route-search="@Model.ActiveSearch" asp-fragment="@sr.Page-@sr.Line">
|
||||
@sr.Preview
|
||||
</a>
|
||||
@if (Model.Marginals != null && Model.Marginals.Any()) {
|
||||
@if (Model.Marginals.ContainsKey(letter.Meta.Index)) {
|
||||
@foreach (var c in Model.Marginals[letter.Meta.Index]) {
|
||||
@if (Model.Marginals.ContainsKey(letter.Meta.ID)) {
|
||||
@foreach (var c in Model.Marginals[letter.Meta.ID]) {
|
||||
@if (c.Item1.Page == sr.Page && c.Item1.Line == sr.Line) {
|
||||
<div class="ha-seachresultmarginal">
|
||||
<div class="ha-searchresultcommentpill">Kommentar</div>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
@if (!Model.Compact) {
|
||||
<div class="ha-letternumber">
|
||||
<div class="ha-letternumberinline">
|
||||
@Model.Letter.Meta.Autopsic
|
||||
@Model.Letter.Meta.ID
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
@@ -20,7 +20,7 @@
|
||||
</div>
|
||||
<div class="ha-metadatapersons">
|
||||
@foreach(var pair in Model.Letter.SenderReceiver) {
|
||||
@if (Model.Letter.Meta.isDraft == HaDocument.Models.OptionalBool.True) {
|
||||
@if (Model.Letter.Meta.isDraft.HasValue && Model.Letter.Meta.isDraft.Value) {
|
||||
<span>@Html.Raw(pair.Sender)</span>
|
||||
<div class="ha-tooltip">
|
||||
↛
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (Model.Letter.Meta.hasOriginal != HaDocument.Models.OptionalBool.True) {
|
||||
@if (Model.Letter.Meta.hasOriginal.HasValue && Model.Letter.Meta.hasOriginal.Value == true) {
|
||||
<div class="ha-tooltip">
|
||||
<div class="ha-pill">
|
||||
<span class="ha-cross">Orig</span>
|
||||
|
||||
@@ -80,13 +80,13 @@ public class WebSocketMiddleware : IMiddleware {
|
||||
await webSocket.SendAsync(_SerializeToBytes(new { Ping = true}), WebSocketMessageType.Text, true, CancellationToken.None);
|
||||
}
|
||||
result = await webSocket.ReceiveAsync(new ArraySegment<byte>(buffer), CancellationToken.None);
|
||||
} catch (ConnectionAbortedException ex) {
|
||||
} catch (WebSocketException ex) {
|
||||
_openSockets!.Remove(webSocket);
|
||||
}
|
||||
}
|
||||
try {
|
||||
await webSocket.CloseAsync(result.CloseStatus.Value, result.CloseStatusDescription, CancellationToken.None);
|
||||
} catch (ConnectionAbortedException ex) {
|
||||
} catch (WebSocketException ex) {
|
||||
_openSockets.Remove(webSocket);
|
||||
}
|
||||
_openSockets!.Remove(webSocket);
|
||||
@@ -127,7 +127,7 @@ public class WebSocketMiddleware : IMiddleware {
|
||||
foreach (var socket in _openSockets) {
|
||||
try {
|
||||
await socket.SendAsync(_SerializeToBytes(msg), WebSocketMessageType.Text, true, CancellationToken.None);
|
||||
} catch (ConnectionAbortedException ex) {
|
||||
} catch (WebSocketException ex) {
|
||||
_openSockets.Remove(socket);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,9 @@ public interface IXMLInteractionService {
|
||||
public void CreateSearchables(XDocument document); // XMLFileProvider
|
||||
public Dictionary<string, SyntaxCheckModel>? Test(XMLParsingState? state, string gitcommit); // XMLFileProvider (optimal), Controller (right now)
|
||||
// Controller
|
||||
public List<(string Index, List<(string Page, string Line, string Preview, string Identifier)> Results)>? SearchCollection(string collection, string searchword, IReaderService reader, ILibrary? lib);
|
||||
public List<(CollectedItem Item, List<(string Page, string Line, string Preview, string? Identifier)> Results)>? SearchCollection(string collection, string searchword, IReaderService reader, ILibrary? lib);
|
||||
// Controller
|
||||
public List<(string Index, List<(string Page, string Line, string Preview, string Identifier)> Results)>? GetPreviews(List<(string, List<Marginal>)> places, IReaderService reader, ILibrary lib);
|
||||
public List<(CollectedItem Item, List<(string Page, string Line, string Preview, string? Identifier)> Results)>? GetPreviews(List<(string, List<Marginal>)> places, IReaderService reader, ILibrary lib);
|
||||
|
||||
public CollectedItem? GetCollectedItem(string collection, string id);
|
||||
}
|
||||
@@ -166,10 +166,10 @@ public class XMLInteractionService : IXMLInteractionService {
|
||||
return opus;
|
||||
}
|
||||
|
||||
public List<(string Index, List<(string Page, string Line, string Preview, string Identifier)> Results)>? GetPreviews(List<(string, List<Marginal>)> places, IReaderService reader, ILibrary lib) {
|
||||
if (!_Collection.ContainsKey("letters")) return null;
|
||||
public List<(CollectedItem Item, List<(string Page, string Line, string Preview, string? Identifier)> Results)>? GetPreviews(List<(string, List<Marginal>)> places, IReaderService reader, ILibrary lib) {
|
||||
if (_Collection == null || !_Collection.ContainsKey("letters")) return null;
|
||||
var searchableObjects = _Collection["letters"].Items;
|
||||
var res = new ConcurrentBag<(string Index, List<(string Page, string Line, string preview, string identifier)> Results)>();
|
||||
var res = new ConcurrentBag<(CollectedItem item, List<(string Page, string Line, string preview, string? identifier)> Results)>();
|
||||
|
||||
Parallel.ForEach(places, (obj) => {
|
||||
var text = searchableObjects[obj.Item1];
|
||||
@@ -180,7 +180,7 @@ public class XMLInteractionService : IXMLInteractionService {
|
||||
rd.Read();
|
||||
|
||||
res.Add((
|
||||
obj.Item1,
|
||||
text,
|
||||
obj.Item2.Select(x => (
|
||||
x.Page,
|
||||
x.Line,
|
||||
@@ -190,7 +190,7 @@ public class XMLInteractionService : IXMLInteractionService {
|
||||
.Select(y => y.Text)
|
||||
.FirstOrDefault(string.Empty)
|
||||
: string.Empty,
|
||||
String.Empty
|
||||
(string?)null
|
||||
) ).ToList()
|
||||
));
|
||||
});
|
||||
@@ -198,10 +198,17 @@ public class XMLInteractionService : IXMLInteractionService {
|
||||
return res.ToList();
|
||||
}
|
||||
|
||||
public List<(string Index, List<(string Page, string Line, string Preview, string Identifier)> Results)>? SearchCollection(string collection, string searchword, IReaderService reader, ILibrary lib) {
|
||||
if (!_Collection.ContainsKey(collection)) return null;
|
||||
public CollectedItem? GetCollectedItem(string collection, string id) {
|
||||
if (_Collection == null || !_Collection.ContainsKey(collection)) return null;
|
||||
var objects = _Collection[collection].Items;
|
||||
if (objects == null || !objects.ContainsKey(id)) return null;
|
||||
return objects[id];
|
||||
}
|
||||
|
||||
public List<(CollectedItem Item, List<(string Page, string Line, string Preview, string? Identifier)> Results)>? SearchCollection(string collection, string searchword, IReaderService reader, ILibrary? lib) {
|
||||
if (_Collection == null || !_Collection.ContainsKey(collection)) return null;
|
||||
var searchableObjects = _Collection[collection].Items;
|
||||
var res = new ConcurrentBag<(string Index, List<(string Page, string Line, string preview, string identifier)> Results)>();
|
||||
var res = new ConcurrentBag<(CollectedItem item, List<(string Page, string Line, string preview, string? identifier)> Results)>();
|
||||
var sw = StringHelpers.NormalizeWhiteSpace(searchword.Trim());
|
||||
|
||||
// Non Parallel:
|
||||
@@ -236,7 +243,7 @@ public class XMLInteractionService : IXMLInteractionService {
|
||||
rd.Read();
|
||||
if (state.Results != null)
|
||||
res.Add((
|
||||
obj.Value.Index,
|
||||
obj.Value,
|
||||
state.Results.Select(x => (
|
||||
x.Page,
|
||||
x.Line,
|
||||
@@ -272,10 +279,7 @@ public class XMLInteractionService : IXMLInteractionService {
|
||||
var searchtext = coll.Value.Searchable ?
|
||||
StringHelpers.NormalizeWhiteSpace(e.ToString(), ' ', false) :
|
||||
null;
|
||||
var datafileds = coll.Value.GenerateDataFields != null ?
|
||||
coll.Value.GenerateDataFields(e) :
|
||||
null;
|
||||
items[k] = new CollectedItem(k, e, coll.Value, datafileds, searchtext);
|
||||
items[k] = new CollectedItem(k, e, coll.Value, searchtext);
|
||||
}
|
||||
}
|
||||
if (items.Any()) {
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
"BareRepositoryPathLinux": "/var/www/vhosts/development.hamann-ausgabe.de/httpdocs/Bare/",
|
||||
"BareRepositoryPathWindows": "C:/Users/simon/source/hamann-xml/.git/",
|
||||
"WorkingTreePathLinux": "/var/www/vhosts/development.hamann-ausgabe.de/httpdocs/Repo/",
|
||||
"WorkingTreePathWindows": "C:/Users/simon/source/hamann-xml/",
|
||||
"WorkingTreePathWindows": "C:/Users/simon/source/hamann-xml/transformations_2023-9-14_test/",
|
||||
"RepositoryBranch": "testdata",
|
||||
"RepositoryURL": "https://github.com/Theodor-Springmann-Stiftung/hamann-xml",
|
||||
"StoredPDFPathWindows": "",
|
||||
|
||||
Reference in New Issue
Block a user