mirror of
https://github.com/Theodor-Springmann-Stiftung/hamann-ausgabe-core.git
synced 2025-10-30 01:35:32 +00:00
JavaScript Refactor p1
This commit is contained in:
@@ -9,9 +9,9 @@ using Microsoft.AspNetCore.HttpOverrides;
|
|||||||
using Microsoft.Extensions.Primitives;
|
using Microsoft.Extensions.Primitives;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
List<string> configpaths = new List<string>();
|
|
||||||
|
|
||||||
// Add additional configuration
|
// Add additional configuration
|
||||||
|
List<string> configpaths = new List<string>();
|
||||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) {
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) {
|
||||||
var p = builder.Configuration.GetValue<string>("WorkingTreePathWindows") + "settings.json";
|
var p = builder.Configuration.GetValue<string>("WorkingTreePathWindows") + "settings.json";
|
||||||
configpaths.Add(p);
|
configpaths.Add(p);
|
||||||
@@ -38,6 +38,8 @@ builder.Services.AddSingleton<IXMLFileProvider, XMLFileProvider>(_ => XMLFP);
|
|||||||
builder.Services.AddSingleton<WebSocketMiddleware>();
|
builder.Services.AddSingleton<WebSocketMiddleware>();
|
||||||
builder.Services.AddTransient<IReaderService, ReaderService>();
|
builder.Services.AddTransient<IReaderService, ReaderService>();
|
||||||
builder.Services.AddFeatureManagement();
|
builder.Services.AddFeatureManagement();
|
||||||
|
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
// Reload config on change
|
// Reload config on change
|
||||||
@@ -48,12 +50,13 @@ ChangeToken.OnChange(
|
|||||||
app.Environment
|
app.Environment
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Websockets for realtime notification of changes
|
||||||
app.UseWebSockets( new WebSocketOptions {
|
app.UseWebSockets( new WebSocketOptions {
|
||||||
KeepAliveInterval = TimeSpan.FromMinutes(180),
|
KeepAliveInterval = TimeSpan.FromMinutes(180),
|
||||||
});
|
});
|
||||||
app.UseMiddleware<WebSocketMiddleware>();
|
app.UseMiddleware<WebSocketMiddleware>();
|
||||||
|
|
||||||
// Configure the HTTP request pipeline.
|
// Production Options
|
||||||
if (!app.Environment.IsDevelopment())
|
if (!app.Environment.IsDevelopment())
|
||||||
{
|
{
|
||||||
app.UseExceptionHandler("/Home/Error");
|
app.UseExceptionHandler("/Home/Error");
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
const startup_active = function () {
|
||||||
// Gives active classes to links with active URLs
|
// Gives active classes to links with active URLs
|
||||||
// Marks links as active which target URL starts with the current URL
|
// Marks links as active which target URL starts with the current URL
|
||||||
const markactive_startswith = function (element) {
|
const markactive_startswith = function (element) {
|
||||||
@@ -66,3 +67,7 @@ if (document.getElementById("ha-register-nav") !== null)
|
|||||||
markactive_exact(document.getElementById("ha-register-nav"));
|
markactive_exact(document.getElementById("ha-register-nav"));
|
||||||
if (this.document.getElementById("ha-adminuploadfields") !== null)
|
if (this.document.getElementById("ha-adminuploadfields") !== null)
|
||||||
markactive_exact(document.getElementById("ha-adminuploadfields"));
|
markactive_exact(document.getElementById("ha-adminuploadfields"));
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
startup_active();
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
// Marks anchors, if anchors are present in the URL
|
// Marks anchors, if anchors are present in the URL
|
||||||
const markanchor = function () {
|
const startup_markanchor = function () {
|
||||||
var currentUrl = document.URL,
|
var currentUrl = document.URL,
|
||||||
urlParts = currentUrl.split('#');
|
urlParts = currentUrl.split('#');
|
||||||
var anchor = (urlParts.length > 1) ? urlParts[1] : null;
|
var anchor = (urlParts.length > 1) ? urlParts[1] : null;
|
||||||
@@ -19,4 +19,4 @@ const markanchor = function () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
markanchor();
|
startup_markanchor();
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
// // Code specifically for the letter view
|
// // Code specifically for the letter view
|
||||||
|
|
||||||
|
const startup_briefe = function () {
|
||||||
let activetab = null;
|
let activetab = null;
|
||||||
let activetabbtn = null;
|
let activetabbtn = null;
|
||||||
let activetabbtn2 = null;
|
let activetabbtn2 = null;
|
||||||
@@ -31,3 +33,6 @@ for (let i = 0; i < tabbtnlist.length; i++) {
|
|||||||
|
|
||||||
if (tabbtnlist.length > 0)
|
if (tabbtnlist.length > 0)
|
||||||
tabbtnlist[0].click();
|
tabbtnlist[0].click();
|
||||||
|
};
|
||||||
|
|
||||||
|
startup_briefe();
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
|
||||||
|
const startup_clipboard = function () {
|
||||||
document.addEventListener('copy', function (e) {
|
document.addEventListener('copy', function (e) {
|
||||||
var e = navigator.clipboard.read();
|
var e = navigator.clipboard.read();
|
||||||
|
|
||||||
@@ -5,3 +7,7 @@ document.addEventListener('copy', function(e){
|
|||||||
e.clipboardData.setData('text/plain', text);
|
e.clipboardData.setData('text/plain', text);
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
startup_clipboard();
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
const startup_filelistform = function () {
|
||||||
function getCookie(name) {
|
function getCookie(name) {
|
||||||
var value = "; " + document.cookie;
|
var value = "; " + document.cookie;
|
||||||
var parts = value.split("; " + name + "=");
|
var parts = value.split("; " + name + "=");
|
||||||
@@ -82,17 +83,6 @@ const GETSyntaxCheck = async function (oFormElement, file = null) {
|
|||||||
}
|
}
|
||||||
console.log(e, h, i, a);
|
console.log(e, h, i, a);
|
||||||
});
|
});
|
||||||
// let coll = document.getElementsByClassName("ha-managedfile");
|
|
||||||
// for (i = 0; i < coll.length; i++) {
|
|
||||||
// let e = coll[i];
|
|
||||||
// if (j[e.id] !== null) {
|
|
||||||
// if(j[e.id].errors === null) {
|
|
||||||
// console.log(e.id + " hat keine errors");
|
|
||||||
// } else {
|
|
||||||
// console.log(e.id + " hat errors");
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
document.getElementById("ha-scbutton").classList.toggle("hidden");
|
document.getElementById("ha-scbutton").classList.toggle("hidden");
|
||||||
|
|
||||||
})
|
})
|
||||||
@@ -104,10 +94,12 @@ const GETSyntaxCheck = async function (oFormElement, file = null) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var coll = document.getElementsByClassName("expandable");
|
var coll = document.getElementsByClassName("expandable");
|
||||||
|
|
||||||
for (i = 0; i < coll.length; i++) {
|
for (i = 0; i < coll.length; i++) {
|
||||||
let element = coll[i]
|
let element = coll[i]
|
||||||
coll[i].addEventListener("click", () => {
|
coll[i].addEventListener("click", () => {
|
||||||
element.classList.toggle("expanded");
|
element.classList.toggle("expanded");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
startup_filelistform();
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
const startup_index = function () {
|
||||||
|
|
||||||
function encode(e) { return e.replace(/[^]/g, function (e) { return "&#" + e.charCodeAt(0) + ";" }) }
|
function encode(e) { return e.replace(/[^]/g, function (e) { return "&#" + e.charCodeAt(0) + ";" }) }
|
||||||
|
|
||||||
const ACTIVATEGOTOFILTER = function (filter, button) {
|
const ACTIVATEGOTOFILTER = function (filter, button) {
|
||||||
@@ -89,3 +91,6 @@ let searchsubmitbtn = document.getElementById("ha-searchformsubmit");
|
|||||||
let searchform = document.getElementById("ha-searchform");
|
let searchform = document.getElementById("ha-searchform");
|
||||||
ACTIVATESEARCHFILTER(searchfilter, searchsubmitbtn);
|
ACTIVATESEARCHFILTER(searchfilter, searchsubmitbtn);
|
||||||
searchfilter.addEventListener("input", () => ACTIVATESEARCHFILTER(searchfilter, searchsubmitbtn));
|
searchfilter.addEventListener("input", () => ACTIVATESEARCHFILTER(searchfilter, searchsubmitbtn));
|
||||||
|
};
|
||||||
|
|
||||||
|
startup_index();
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
// Script for auto collapsing marginal boxes
|
// Script for auto collapsing marginal boxes
|
||||||
|
const startup_marginals = function () {
|
||||||
const getLineHeight = function (element) {
|
const getLineHeight = function (element) {
|
||||||
var temp = document.createElement(element.nodeName),
|
var temp = document.createElement(element.nodeName),
|
||||||
ret;
|
ret;
|
||||||
@@ -146,8 +147,6 @@ const marginalboxwidthset = function () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const collapseboxes = function () {
|
const collapseboxes = function () {
|
||||||
overlappingcollapsebox(".ha-neuzeit .ha-letlinks", true);
|
overlappingcollapsebox(".ha-neuzeit .ha-letlinks", true);
|
||||||
overlappingcollapsebox(".ha-forschung .ha-letlinks", true);
|
overlappingcollapsebox(".ha-forschung .ha-letlinks", true);
|
||||||
@@ -180,6 +179,7 @@ const resetall = function() {
|
|||||||
collapseboxes();
|
collapseboxes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
marginalboxwidthset();
|
marginalboxwidthset();
|
||||||
collapseboxes();
|
collapseboxes();
|
||||||
|
|
||||||
@@ -188,3 +188,6 @@ this.window.addEventListener("resize", function () {
|
|||||||
this.clearTimeout(doit);
|
this.clearTimeout(doit);
|
||||||
doit = this.setTimeout(resetall, 17);
|
doit = this.setTimeout(resetall, 17);
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
startup_marginals();
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
// Code for showing and hiding the mobile menu
|
// Code for showing and hiding the mobile menu
|
||||||
|
const startup_mobilemenu = function () {
|
||||||
const openmenu = function () {
|
const openmenu = function () {
|
||||||
var x = document.getElementById("ha-topnav");
|
var x = document.getElementById("ha-topnav");
|
||||||
if (x !== null) x.className += " ha-topnav-collapsed";
|
if (x !== null) x.className += " ha-topnav-collapsed";
|
||||||
@@ -29,3 +30,6 @@ if (
|
|||||||
.getElementById("closemenubutton")
|
.getElementById("closemenubutton")
|
||||||
.addEventListener("click", closemenu);
|
.addEventListener("click", closemenu);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
startup_mobilemenu();
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
const startup_publishform = function () {
|
||||||
|
|
||||||
const LOCALPUBLISHSubmit = async function (oFormElement) {
|
const LOCALPUBLISHSubmit = async function (oFormElement) {
|
||||||
var fd = new FormData();
|
var fd = new FormData();
|
||||||
document.getElementById("ha-publishfilelabel").style.pointerEvents = "none";
|
document.getElementById("ha-publishfilelabel").style.pointerEvents = "none";
|
||||||
@@ -34,4 +36,6 @@ const LOCALPUBLISHSubmit = async function (oFormElement) {
|
|||||||
var publishelement = document.getElementById("ha-publishform");
|
var publishelement = document.getElementById("ha-publishform");
|
||||||
var publishbutton = document.getElementById("ha-publishfilelabel");
|
var publishbutton = document.getElementById("ha-publishfilelabel");
|
||||||
publishbutton.addEventListener("click", () => LOCALPUBLISHSubmit(publishelement));
|
publishbutton.addEventListener("click", () => LOCALPUBLISHSubmit(publishelement));
|
||||||
|
};
|
||||||
|
|
||||||
|
startup_publishform();
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
const startup_scrollbutton = function () {
|
||||||
|
|
||||||
// Script for showing and acting upon the "scroll to top button"
|
// Script for showing and acting upon the "scroll to top button"
|
||||||
const scrollFunction = function () {
|
const scrollFunction = function () {
|
||||||
button = document.getElementById("ha-scrollbutton");
|
button = document.getElementById("ha-scrollbutton");
|
||||||
@@ -24,3 +26,6 @@ if (document.getElementById("ha-scrollbutton") !== null) {
|
|||||||
// TODO: workaround, bc window does not recieve scroll events anymore
|
// TODO: workaround, bc window does not recieve scroll events anymore
|
||||||
setInterval(() => scrollFunction(), 1500);
|
setInterval(() => scrollFunction(), 1500);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
startup_scrollbutton();
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
const startup_search = function () {
|
||||||
|
|
||||||
const ACTIVATESEARCHFILTER = function (filter, button) {
|
const ACTIVATESEARCHFILTER = function (filter, button) {
|
||||||
let f = filter.value;
|
let f = filter.value;
|
||||||
if (f === "") {
|
if (f === "") {
|
||||||
@@ -12,3 +14,6 @@ let searchsubmitbtn = document.getElementById("ha-searchformsubmit");
|
|||||||
let searchform = document.getElementById("ha-searchform");
|
let searchform = document.getElementById("ha-searchform");
|
||||||
ACTIVATESEARCHFILTER(searchfilter, searchsubmitbtn);
|
ACTIVATESEARCHFILTER(searchfilter, searchsubmitbtn);
|
||||||
searchfilter.addEventListener("input", () => ACTIVATESEARCHFILTER(searchfilter, searchsubmitbtn));
|
searchfilter.addEventListener("input", () => ACTIVATESEARCHFILTER(searchfilter, searchsubmitbtn));
|
||||||
|
}
|
||||||
|
|
||||||
|
startup_search();
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
// Functions for switching theme
|
// Functions for switching theme
|
||||||
|
const startup_theme = function () {
|
||||||
|
|
||||||
const go_to_dark = function () {
|
const go_to_dark = function () {
|
||||||
localStorage.setItem("theme", "ha-toggledark");
|
localStorage.setItem("theme", "ha-toggledark");
|
||||||
document.documentElement.classList.add("dark");
|
document.documentElement.classList.add("dark");
|
||||||
@@ -28,3 +30,6 @@ if (
|
|||||||
.addEventListener("click", go_to_dark);
|
.addEventListener("click", go_to_dark);
|
||||||
}
|
}
|
||||||
get_theme_settings("ha-togglebright");
|
get_theme_settings("ha-togglebright");
|
||||||
|
};
|
||||||
|
|
||||||
|
startup_theme();
|
||||||
@@ -1,73 +0,0 @@
|
|||||||
const dropHandler = function (formelement, ev, dropzone) {
|
|
||||||
ev.preventDefault();
|
|
||||||
if (ev.dataTransfer.items) {
|
|
||||||
if (ev.dataTransfer.items[0].kind === 'file') {
|
|
||||||
var file = ev.dataTransfer.items[0].getAsFile();
|
|
||||||
UPLOADSubmit(formelement, file);
|
|
||||||
} else {
|
|
||||||
var file = ev.dataTransfer.files[0];
|
|
||||||
UPLOADSubmit(formelement, file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const dragOverHandler = function (ev, dropzone) {
|
|
||||||
ev.preventDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
const dragLeaveHander = function (ev, dropzone) {
|
|
||||||
ev.preventDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
const dragEnterHandler = function (ev, dropzone) {
|
|
||||||
ev.preventDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
const UPLOADSubmit = async function (oFormElement, file = null) {
|
|
||||||
var fd = new FormData();
|
|
||||||
if (file !== null) fd.append("file", file);
|
|
||||||
else fd = new FormData(oFormElement);
|
|
||||||
document.getElementById("dropzone").style.pointerEvents = "none";
|
|
||||||
document.getElementById("ha-lds-ellipsis-upload").style.display = "inline-block";
|
|
||||||
document.getElementById("ha-uploadmessage").style.opacity = "0";
|
|
||||||
await fetch(oFormElement.action, {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'RequestVerificationToken': getCookie('RequestVerificationToken')
|
|
||||||
},
|
|
||||||
body: fd
|
|
||||||
})
|
|
||||||
.then(response => response.json())
|
|
||||||
.then(json => {
|
|
||||||
if ("Error" in json) {
|
|
||||||
document.getElementById("dropzone").style.pointerEvents = "auto";
|
|
||||||
document.getElementById("ha-lds-ellipsis-upload").style.display = "none";
|
|
||||||
document.getElementById("ha-uploadmessage").style.opacity = "1";
|
|
||||||
oFormElement.elements.namedItem("upload-result").value = json.Error;
|
|
||||||
} else {
|
|
||||||
document.getElementById("dropzone").style.pointerEvents = "auto";
|
|
||||||
document.getElementById("ha-lds-ellipsis-upload").style.display = "none";
|
|
||||||
oFormElement.elements.namedItem("upload-result").value = "Erfolg!";
|
|
||||||
if ("Prefix" in json[0]) {
|
|
||||||
document.getElementById("dropzone").style.pointerEvents = "auto";
|
|
||||||
document.getElementById("ha-lds-ellipsis-upload").style.display = "none";
|
|
||||||
window.location.replace("/Admin/Upload/" + json[0].Prefix);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch ((e) => {
|
|
||||||
document.getElementById("dropzone").style.pointerEvents = "auto";
|
|
||||||
document.getElementById("ha-lds-ellipsis-upload").style.display = "none";
|
|
||||||
document.getElementById("ha-uploadmessage").style.opacity = "1";
|
|
||||||
oFormElement.elements.namedItem("upload-result").value = "Keine Antwort. Bitte Seite neu laden!";
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
var submitelement = document.getElementById("file");
|
|
||||||
var formelement = document.getElementById("uploadForm");
|
|
||||||
var dropzone = document.getElementById("dropzone");
|
|
||||||
submitelement.addEventListener("change", () => UPLOADSubmit(formelement));
|
|
||||||
dropzone.addEventListener("drop", (ev) => dropHandler(formelement, ev, dropzone));
|
|
||||||
dropzone.addEventListener("dragover", (ev) => dragOverHandler(ev, dropzone));
|
|
||||||
dropzone.addEventListener("dragleave", (ev) => dragLeaveHander(ev, dropzone));
|
|
||||||
dropzone.addEventListener("dragenter", (ev) => dragEnterHandler(ev, dropzone));
|
|
||||||
@@ -1,3 +1,15 @@
|
|||||||
|
// Functions for change notifications and automatic reload via websockets
|
||||||
|
const startup_websocket = function () {
|
||||||
|
function htmlEscape(str) {
|
||||||
|
return str.toString()
|
||||||
|
.replace(/&/g, '&')
|
||||||
|
.replace(/"/g, '"')
|
||||||
|
.replace(/'/g, ''')
|
||||||
|
.replace(/</g, '<')
|
||||||
|
.replace(/>/g, '>');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
var stateSC = null;
|
var stateSC = null;
|
||||||
var stateValidation = null;
|
var stateValidation = null;
|
||||||
var stateReload = null;
|
var stateReload = null;
|
||||||
@@ -13,16 +25,6 @@ var port = document.location.port ? (":" + document.location.port) : "";
|
|||||||
var wsPingInterval;
|
var wsPingInterval;
|
||||||
var connectionUrl = scheme + "://" + document.location.hostname + port + "/WS";
|
var connectionUrl = scheme + "://" + document.location.hostname + port + "/WS";
|
||||||
|
|
||||||
function htmlEscape(str) {
|
|
||||||
return str.toString()
|
|
||||||
.replace(/&/g, '&')
|
|
||||||
.replace(/"/g, '"')
|
|
||||||
.replace(/'/g, ''')
|
|
||||||
.replace(/</g, '<')
|
|
||||||
.replace(/>/g, '>');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
socket = new WebSocket(connectionUrl);
|
socket = new WebSocket(connectionUrl);
|
||||||
socket.onopen = function (event) {
|
socket.onopen = function (event) {
|
||||||
socket.send("Hello");
|
socket.send("Hello");
|
||||||
@@ -143,23 +145,6 @@ function updateMessage() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// closeButton.onclick = function () {
|
startup_websocket();
|
||||||
// if (!socket || socket.readyState !== WebSocket.OPEN) {
|
|
||||||
// alert("socket not connected");
|
|
||||||
// }
|
|
||||||
// socket.close(1000, "Closing from client");
|
|
||||||
// };
|
|
||||||
|
|
||||||
// sendButton.onclick = function () {
|
|
||||||
// if (!socket || socket.readyState !== WebSocket.OPEN) {
|
|
||||||
// alert("socket not connected");
|
|
||||||
// }
|
|
||||||
// var data = sendMessage.value;
|
|
||||||
// socket.send(data);
|
|
||||||
// commsLog.innerHTML += '<tr>' +
|
|
||||||
// '<td class="commslog-client">Client</td>' +
|
|
||||||
// '<td class="commslog-server">Server</td>' +
|
|
||||||
// '<td class="commslog-data">' + htmlEscape(data) + '</td></tr>';
|
|
||||||
// };
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user