Fixed a few bugs; fixed marginals; fixed google indexing

This commit is contained in:
Simon Martens
2024-11-14 17:24:17 +01:00
parent c9617a8ea6
commit 822cad09de
6 changed files with 238 additions and 226 deletions

1
HaWeb/.gitignore vendored
View File

@@ -23,3 +23,4 @@ bin/*
*.njsproj *.njsproj
*.sln *.sln
*.sw? *.sw?
testdata/

View File

@@ -13,7 +13,7 @@ using System.Xml.Linq;
using System.Diagnostics; using System.Diagnostics;
public class HaDocumentWrapper : IHaDocumentWrappper { public class HaDocumentWrapper : IHaDocumentWrappper {
private IFileInfo _ActiveFile; private IFileInfo? _ActiveFile;
private ILibrary? Library; private ILibrary? Library;
private IXMLInteractionService _xmlService; private IXMLInteractionService _xmlService;
private int _startYear; private int _startYear;
@@ -60,7 +60,8 @@ public class HaDocumentWrapper : IHaDocumentWrappper {
// 2. Set ILibrary // 2. Set ILibrary
try { try {
Library = HaDocument.Document.Create(new HaWeb.Settings.HaDocumentOptions() { HamannXMLFilePath = path, AvailableYearRange = (_startYear, _endYear) }, doc.Root); Library = HaDocument.Document.Create(new HaWeb.Settings.HaDocumentOptions() { HamannXMLFilePath = path, AvailableYearRange = (_startYear, _endYear) }, doc.Root);
} catch (Exception ex) { }
catch (Exception ex) {
if (ModelState != null) ModelState.AddModelError("Error", "Das Dokument konnte nicht geparst werden: " + ex.Message); if (ModelState != null) ModelState.AddModelError("Error", "Das Dokument konnte nicht geparst werden: " + ex.Message);
return null; return null;
} }

View File

@@ -3,10 +3,8 @@ using Microsoft.Extensions.FileProviders;
using Microsoft.AspNetCore.Mvc.ModelBinding; using Microsoft.AspNetCore.Mvc.ModelBinding;
using HaWeb.Models; using HaWeb.Models;
using HaWeb.XMLParser; using HaWeb.XMLParser;
using HaWeb.XMLTests;
using System.Xml.Linq; using System.Xml.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Diagnostics;
using Microsoft.Extensions.Primitives; using Microsoft.Extensions.Primitives;
// XMLProvider provides a wrapper around the available XML data on a FILE basis // XMLProvider provides a wrapper around the available XML data on a FILE basis
@@ -165,7 +163,7 @@ public class XMLFileProvider : IXMLFileProvider {
public IFileInfo? SaveHamannFile(XElement element, string basefilepath, ModelStateDictionary? ModelState) { public IFileInfo? SaveHamannFile(XElement element, string basefilepath, ModelStateDictionary? ModelState) {
if (_GitState == null) return null; if (_GitState == null) return null;
var filename = "hamann_" + _GitState.PullTime.Year + "-" + _GitState.PullTime.Month + "-" + _GitState.PullTime.Day + "_" + _GitState.PullTime.Hour + "-" + _GitState.PullTime.Minute + "." + _GitState.Commit.Substring(0,7) + ".xml"; var filename = "hamann_" + _GitState.PullTime.Year + "-" + _GitState.PullTime.Month + "-" + _GitState.PullTime.Day + "_" + _GitState.PullTime.Hour + "-" + _GitState.PullTime.Minute + "." + _GitState.Commit.Substring(0, 7) + ".xml";
var path = Path.Combine(basefilepath, filename); var path = Path.Combine(basefilepath, filename);
try { try {
@@ -173,7 +171,8 @@ public class XMLFileProvider : IXMLFileProvider {
Directory.CreateDirectory(basefilepath); Directory.CreateDirectory(basefilepath);
using (var targetStream = System.IO.File.Create(path)) using (var targetStream = System.IO.File.Create(path))
element.Save(targetStream, SaveOptions.DisableFormatting); element.Save(targetStream, SaveOptions.DisableFormatting);
} catch (Exception ex) { }
catch (Exception ex) {
if (ModelState != null) ModelState.AddModelError("Error", "Die Datei konnte nicht gespeichert werden: " + ex.Message); if (ModelState != null) ModelState.AddModelError("Error", "Die Datei konnte nicht gespeichert werden: " + ex.Message);
return null; return null;
} }
@@ -237,7 +236,7 @@ public class XMLFileProvider : IXMLFileProvider {
private bool _IsAlreadyParsed() { private bool _IsAlreadyParsed() {
if (_HamannFiles == null || !_HamannFiles.Any() || _GitState == null) return false; if (_HamannFiles == null || !_HamannFiles.Any() || _GitState == null) return false;
var fhash = _GetHashFromHamannFilename(_HamannFiles.First().Name); var fhash = _GetHashFromHamannFilename(_HamannFiles.First().Name);
var ghash = _GitState.Commit.Substring(0,7); var ghash = _GitState.Commit.Substring(0, 7);
return fhash == ghash; return fhash == ghash;
} }

View File

@@ -53,7 +53,7 @@ var app = builder.Build();
// // Websockets for realtime notification of changes // // Websockets for realtime notification of changes
app.UseWebSockets(new WebSocketOptions { app.UseWebSockets(new WebSocketOptions {
KeepAliveInterval = TimeSpan.FromMinutes(180), KeepAliveInterval = TimeSpan.FromMinutes(30),
}); });
app.UseMiddleware<WebSocketMiddleware>(); app.UseMiddleware<WebSocketMiddleware>();

View File

@@ -13,13 +13,13 @@
}, },
"AllowedWebSocketConnections": "*", "AllowedWebSocketConnections": "*",
"AllowedHosts": "*", "AllowedHosts": "*",
"HamannFileStoreLinux": "/home/simon/test/", "HamannFileStoreLinux": "/home/simon/source/hamann-ausgabe-core/HaWeb/testdata/",
"HamannFileStoreWindows": "C:/Users/simon/Downloads/test/", "HamannFileStoreWindows": "C:/Users/simon/Downloads/test/",
"BareRepositoryPathLinux": "/home/simon/source/hamann-xml/.git/", "BareRepositoryPathLinux": "/home/simon/source/hamann-xml/.git/",
"BareRepositoryPathWindows": "D:/Simon/source/hamann-xml/.git/", "BareRepositoryPathWindows": "D:/Simon/source/hamann-xml/.git/",
"WorkingTreePathLinux": "/home/simon/source/hamann-xml/", "WorkingTreePathLinux": "/home/simon/source/hamann-xml/",
"WorkingTreePathWindows": "D:/Simon/source/hamann-xml/", "WorkingTreePathWindows": "D:/Simon/source/hamann-xml/",
"RepositoryBranch": "Release", "RepositoryBranch": "Main",
"RepositoryURL": "https://github.com/Theodor-Springmann-Stiftung/hamann-xml", "RepositoryURL": "https://github.com/Theodor-Springmann-Stiftung/hamann-xml",
"StoredPDFPathWindows": "", "StoredPDFPathWindows": "",
"StoredPDFPathLinux": "", "StoredPDFPathLinux": "",

View File

@@ -21,15 +21,22 @@ const startup_marginals = function () {
setTimeout(function () { setTimeout(function () {
element.classList.remove("transition-all"); element.classList.remove("transition-all");
}, 130); }, 130);
element.style.bottom = "unset";
}; };
const uncollapsebox = function (element) { const uncollapsebox = function (element, topmove = false) {
element.classList.add("transition-all"); element.classList.add("transition-all");
element.classList.remove("ha-collapsed-box"); element.classList.remove("ha-collapsed-box");
element.classList.add("ha-expanded-box"); element.classList.add("ha-expanded-box");
if (topmove > 0) element.style.bottom = "5px";
}; };
const addbuttoncaollapsebox = function (element, height, hoverfunction, topmove) { const addbuttoncaollapsebox = function (
element,
height,
hoverfunction,
topmove = false,
) {
let btn = document.createElement("div"); let btn = document.createElement("div");
btn.classList.add("ha-btn-collapsed-box"); btn.classList.add("ha-btn-collapsed-box");
@@ -42,13 +49,11 @@ const startup_marginals = function () {
btn.addEventListener("click", function (ev) { btn.addEventListener("click", function (ev) {
ev.stopPropagation(); ev.stopPropagation();
if (element.classList.contains("ha-collapsed-box")) { if (element.classList.contains("ha-collapsed-box")) {
uncollapsebox(element); uncollapsebox(element, topmove);
if (topmove > 0) element.style.bottom = "5px";
btn.classList.add("ha-close-btn-collapsed-box"); btn.classList.add("ha-close-btn-collapsed-box");
btn.classList.add("ha-collapsed-box-manually-toggled"); btn.classList.add("ha-collapsed-box-manually-toggled");
} else { } else {
collapsebox(element, height, 0); collapsebox(element, height, 0);
btn.classList.remove("ha-close-btn-collapsed-box"); btn.classList.remove("ha-close-btn-collapsed-box");
btn.classList.remove("ha-collapsed-box-manually-toggled"); btn.classList.remove("ha-collapsed-box-manually-toggled");
} }
@@ -59,20 +64,18 @@ const startup_marginals = function () {
element.addEventListener("mouseenter", function (ev) { element.addEventListener("mouseenter", function (ev) {
ev.stopPropagation(); ev.stopPropagation();
timer = setTimeout(function () { if (timer != null) {
clearTimeout(timer);
}
if (element.classList.contains("ha-collapsed-box")) { if (element.classList.contains("ha-collapsed-box")) {
uncollapsebox(element); uncollapsebox(element, topmove);
if (topmove > 0) element.style.bottom = "5px";
btn.classList.add("ha-close-btn-collapsed-box"); btn.classList.add("ha-close-btn-collapsed-box");
} }
}, 80);
}); });
element.addEventListener("mouseleave", function (ev) { element.addEventListener("mouseleave", function (ev) {
ev.stopPropagation(); ev.stopPropagation();
if (timer != null) { timer = setTimeout(function () {
clearTimeout(timer);
}
if ( if (
element.classList.contains("ha-expanded-box") && element.classList.contains("ha-expanded-box") &&
!btn.classList.contains("ha-collapsed-box-manually-toggled") !btn.classList.contains("ha-collapsed-box-manually-toggled")
@@ -80,16 +83,22 @@ const startup_marginals = function () {
collapsebox(element, height, 0); collapsebox(element, height, 0);
btn.classList.remove("ha-close-btn-collapsed-box"); btn.classList.remove("ha-close-btn-collapsed-box");
} }
}, 200);
}); });
} }
element.parentNode.insertBefore(btn, element); element.parentNode.insertBefore(btn, element);
}; };
const overlappingcollapsebox = function (selector, hoverfunction, containerid) { const overlappingcollapsebox = function (
selector,
hoverfunction,
containerid,
) {
let container = document.getElementById(containerid); let container = document.getElementById(containerid);
if (!container) return; if (!container) return;
container.classList.add("overflow-hidden"); let containerrect = document
let containerrect = document.getElementById(containerid).getBoundingClientRect();; .getElementById(containerid)
.getBoundingClientRect();
let boxes = document.querySelectorAll(selector); let boxes = document.querySelectorAll(selector);
let lineheight = 1; let lineheight = 1;
@@ -101,27 +110,29 @@ const startup_marginals = function () {
let element = boxes[i]; let element = boxes[i];
let thisrect = element.getBoundingClientRect(); let thisrect = element.getBoundingClientRect();
let overlap = -2; let overlap = -2;
let topmove = 0; let topmove = false;
if (thisrect.bottom > containerrect.bottom) { // Check if this works
overlap = thisrect.bottom - containerrect.bottom;
topmove = thisrect.bottom - containerrect.bottom; if (i < boxes.length - 1) {
console.log("topmove", topmove);
} else if (i < boxes.length - 1) {
let nextrect = boxes[i + 1].getBoundingClientRect(); let nextrect = boxes[i + 1].getBoundingClientRect();
overlap = thisrect.bottom - nextrect.top; overlap = thisrect.bottom - nextrect.top;
} else if (thisrect.bottom > containerrect.bottom) {
overlap = thisrect.bottom - containerrect.bottom;
} }
if (thisrect.bottom > containerrect.bottom) {
topmove = true;
}
if ( if (
// -1 for catching lines that perfectly close up on each other // -1 for catching lines that perfectly close up on each other
overlap >= -1 && overlap >= -1 &&
!(window.getComputedStyle(element).display === "none") !(window.getComputedStyle(element).display === "none")
) { ) {
let newlength = 0; let newlength = 0;
if (overlap >= 0) if (overlap >= 0) newlength = thisrect.height - overlap;
newlength = thisrect.height - overlap; else newlength = thisrect.height - lineheight;
else if (newlength % (lineheight * 3) <= 2) newlength -= lineheight;
newlength = thisrect.height - lineheight;
if (newlength % (lineheight * 3) <= 2)
newlength -= lineheight;
let remainder = newlength % lineheight; let remainder = newlength % lineheight;
newlength = newlength - remainder; newlength = newlength - remainder;
@@ -136,7 +147,8 @@ const startup_marginals = function () {
if (h >= newlength) { if (h >= newlength) {
let lines = Math.floor(eh / lineheight); let lines = Math.floor(eh / lineheight);
let cutoff = Math.floor((h - newlength) / lineheight); let cutoff = Math.floor((h - newlength) / lineheight);
m.style.cssText += "-webkit-line-clamp: " + (lines - cutoff) + ";"; m.style.cssText +=
"-webkit-line-clamp: " + (lines - cutoff) + ";";
m.style.cssText += "line-clamp: " + (lines - cutoff) + ";"; m.style.cssText += "line-clamp: " + (lines - cutoff) + ";";
} }
} }
@@ -147,7 +159,6 @@ const startup_marginals = function () {
collapsebox(element, newlength, lineheight); collapsebox(element, newlength, lineheight);
addbuttoncaollapsebox(element, newlength, hoverfunction, topmove); addbuttoncaollapsebox(element, newlength, hoverfunction, topmove);
}); });
} }
} }
}; };
@@ -170,17 +181,17 @@ const startup_marginals = function () {
const clearcollapsedboxes = function () { const clearcollapsedboxes = function () {
let elements = document.querySelectorAll(".ha-marginalbox"); let elements = document.querySelectorAll(".ha-marginalbox");
elements.forEach(element => { elements.forEach((element) => {
element.removeAttribute("style"); element.removeAttribute("style");
}); });
collapsedboxes.forEach(element => { collapsedboxes.forEach((element) => {
element.classList.remove("ha-expanded-box"); element.classList.remove("ha-expanded-box");
element.classList.remove("ha-collapsed-box"); element.classList.remove("ha-collapsed-box");
element.outerHTML = element.outerHTML; element.outerHTML = element.outerHTML;
}); });
collapsedboxes = []; collapsedboxes = [];
elements = document.querySelectorAll(".ha-btn-collapsed-box"); elements = document.querySelectorAll(".ha-btn-collapsed-box");
elements.forEach(element => { elements.forEach((element) => {
element.remove(); element.remove();
}); });
}; };