Möglichkeit zur Angabe eines zeitraumes für die angezeigten Briefe

This commit is contained in:
Simon Martens
2023-05-08 16:39:14 +02:00
parent 5093951f7a
commit 87337ea992
15 changed files with 91 additions and 19 deletions

View File

@@ -10,6 +10,7 @@ namespace HaDocument.Interfaces {
ImmutableDictionary<string, Tradition> Traditions { get; }
ImmutableDictionary<string, Person> Persons { get; }
ImmutableDictionary<string, Meta> Metas { get; }
ImmutableDictionary<string, Meta> ExcludedMetas { get; }
ImmutableDictionary<string, Marginal> Marginals { get; }
ImmutableDictionary<string, Location> Locations { get; }
ImmutableDictionary<string, Letter> Letters { get; }
@@ -27,6 +28,7 @@ namespace HaDocument.Interfaces {
Lookup<string, Editreason> EditreasonsByLetter { get; }
ImmutableSortedSet<Meta> MetasByDate { get; }
ILookup<int, Meta> MetasByYear { get; }
ILookup<int, Meta> ExcludedMetasByYear { get; }
ImmutableDictionary<string, Comment> SubCommentsByID { get; }
}
}

View File

@@ -8,6 +8,7 @@ namespace HaDocument.Models
public Dictionary<string, Tradition> Traditions;
public Dictionary<string, Person> Persons;
public Dictionary<string, Meta> Metas;
public Dictionary<string, Meta> ExcludedMetas;
public Dictionary<string, Marginal> Marginals;
public Dictionary<string, Location> Locations;
public Dictionary<string, Letter> Letters;
@@ -55,6 +56,7 @@ namespace HaDocument.Models
Traditions,
Persons,
Metas,
ExcludedMetas,
Marginals,
Locations,
Letters,

View File

@@ -14,6 +14,7 @@ namespace HaDocument.Models
public ImmutableDictionary<string, Tradition> Traditions { get; }
public ImmutableDictionary<string, Person> Persons { get; }
public ImmutableDictionary<string, Meta> Metas { get; }
public ImmutableDictionary<string, Meta> ExcludedMetas { get; }
public ImmutableDictionary<string, Marginal> Marginals { get; }
public ImmutableDictionary<string, Location> Locations { get; }
public ImmutableDictionary<string, Letter> Letters { get; }
@@ -42,12 +43,14 @@ namespace HaDocument.Models
public ImmutableSortedSet<Meta> MetasByDate { get; }
// Auswählen von Briefen nach dem Jahr, sortiert nach Datum
public ILookup<int, Meta> MetasByYear { get; }
public ILookup<int, Meta> ExcludedMetasByYear { get; }
public Library(
Dictionary<string, Tradition> traditions,
Dictionary<string, Person> persons,
Dictionary<string, Meta> meta,
Dictionary<string, Meta> excludedMeta,
Dictionary<string, Marginal> marginals,
Dictionary<string, Location> locations,
Dictionary<string, Letter> letters,
@@ -72,6 +75,7 @@ namespace HaDocument.Models
Editreasons = ImmutableDictionary.ToImmutableDictionary(editReasons);
Comments = ImmutableDictionary.ToImmutableDictionary(comments);
Apps = ImmutableDictionary.ToImmutableDictionary(apps);
ExcludedMetas = ImmutableDictionary.ToImmutableDictionary(excludedMeta);
var backbuilder = ImmutableDictionary.CreateBuilder<string, ImmutableList<Backlink>>();
foreach (var entry in backlinks)
@@ -95,6 +99,7 @@ namespace HaDocument.Models
EditreasonsByLetter = (Lookup<string, Editreason>)Editreasons.Values.ToLookup(x => x.Letter);
MetasByDate = Metas.Values.ToImmutableSortedSet<Meta>(new DefaultComparer());
MetasByYear = Metas.Values.ToLookup(x => x.Sort.Year);
ExcludedMetasByYear = ExcludedMetas.Values.ToLookup(x => x.Sort.Year);
var tempbuilder = ImmutableDictionary.CreateBuilder<string, Comment>();
foreach (var comm in Comments)

View File

@@ -9,7 +9,7 @@ namespace HaDocument.Reactors {
class MetaReactor : Reactor {
internal Dictionary<string, Meta> CreatedInstances { get; }
internal Dictionary<string, Meta> ExcludedInstances { get; }
private string[] _availableVolumes;
private (int, int) _availableYearRange;
@@ -36,6 +36,8 @@ namespace HaDocument.Reactors {
_availableYearRange = availableYearRange;
lib.Metas = new Dictionary<string, Meta>();
CreatedInstances = lib.Metas;
lib.ExcludedMetas = new Dictionary<string, Meta>();
ExcludedInstances = lib.ExcludedMetas;
reader.OpenTag += Listen;
}
@@ -150,13 +152,8 @@ namespace HaDocument.Reactors {
}
private void Add() {
if (
_availableVolumes.Contains(Volume) ||
(Sort.Year >= _availableYearRange.Item1 && Sort.Year <= _availableYearRange.Item2) ||
(_availableVolumes == null && _availableYearRange.Item1 == 0 && _availableYearRange.Item2 == 0)
) {
var ZHInfo = !inZH ? null : new ZHInfo(AltLineNumbering, dateChanged, Volume, Page);
var meta = new Meta(
var ZHInfo = !inZH ? null : new ZHInfo(AltLineNumbering, dateChanged, Volume, Page);
var meta = new Meta(
Index,
Autopsic,
Date,
@@ -170,8 +167,16 @@ namespace HaDocument.Reactors {
Receivers,
ZHInfo
);
if (
_availableVolumes.Contains(Volume) ||
(Sort.Year >= _availableYearRange.Item1 && Sort.Year <= _availableYearRange.Item2) ||
(_availableVolumes == null && _availableYearRange.Item1 == 0 && _availableYearRange.Item2 == 0)
) {
CreatedInstances.TryAdd(meta.Index, meta);
}
else {
ExcludedInstances.TryAdd(meta.Index, meta);
}
}
protected override void Reset() {

View File

@@ -343,8 +343,18 @@ public class APIController : Controller {
if (!ModelState.IsValid) return BadRequest(ModelState);
_xmlProvider.SetInProduction(newFile.First());
_xmlService.UnUseProduction();
return Created("/", newFile.First());
}
[HttpPost]
[Route("API/SetStartEndYear")]
[ValidateAntiForgeryToken]
[FeatureGate(Features.UploadService, Features.AdminService)]
public async Task<IActionResult>? SetStartEndYear(StartEndYear startendyear) {
if (startendyear.StartYear > startendyear.EndYear) return BadRequest();
_lib.SetStartEndYear(startendyear.StartYear, startendyear.EndYear);
return Created("/", "");;
}
}

View File

@@ -44,6 +44,7 @@ public class UploadController : Controller {
[FeatureGate(Features.AdminService)]
[GenerateAntiforgeryTokenCookie]
public IActionResult Index(string? id) {
var library = _lib.GetLibrary();
var roots = _xmlService.GetRootsList();
if (roots == null) return error404();
@@ -76,20 +77,22 @@ public class UploadController : Controller {
}
}
var availableYears = library.MetasByYear.Select(x => x.Key).Union(library.ExcludedMetasByYear.Select(x => x.Key)).ToList();
availableYears.Sort();
if (id != null) {
id = id.ToLower();
var root = _xmlService.GetRoot(id);
if (root == null) return error404();
var model = new UploadViewModel(root.Type, id, roots, usedFiles);
var model = new UploadViewModel(root.Type, id, roots, usedFiles, _lib.GetStartYear(), _lib.GetEndYear(), availableYears);
model.ProductionFiles = productionFiles;
model.HamannFiles = hamannFiles;
model.AvailableFiles = XMLFileHelpers.ToFileModel(_xmlProvider.GetFiles(id), pF, uF);
return View("~/Views/Admin/Dynamic/Upload.cshtml", model);
} else {
var model = new UploadViewModel("Upload & Veröffentlichen", id, roots, usedFiles);
var model = new UploadViewModel("Upload & Veröffentlichen", id, roots, usedFiles, _lib.GetStartYear(), _lib.GetEndYear(), availableYears);
model.ProductionFiles = productionFiles;
model.HamannFiles = hamannFiles;

View File

@@ -14,6 +14,8 @@ public class HaDocumentWrapper : IHaDocumentWrappper {
private IXMLProvider _xmlProvider;
private IXMLService _xmlService;
private string _filepath;
public int StartYear { get; private set; }
public int EndYear { get; private set; }
@@ -38,8 +40,20 @@ public class HaDocumentWrapper : IHaDocumentWrappper {
}
}
public int GetStartYear() => StartYear;
public int GetEndYear() => EndYear;
public void SetStartEndYear(int start, int end) {
this.StartYear = start;
this.EndYear = end;
SetLibrary(_filepath);
}
public ILibrary ResetLibrary() {
Library = HaDocument.Document.Create(new HaWeb.Settings.HaDocumentOptions() { AvailableYearRange = (StartYear, EndYear) });
var options = new HaWeb.Settings.HaDocumentOptions() { AvailableYearRange = (StartYear, EndYear )};
Library = HaDocument.Document.Create(options);
_filepath = options.HamannXMLFilePath;
return Library;
}
@@ -60,7 +74,7 @@ public class HaDocumentWrapper : IHaDocumentWrappper {
_xmlService.SetInProduction(System.Xml.Linq.XDocument.Load(filepath, System.Xml.Linq.LoadOptions.PreserveWhitespace));
sw.Stop();
Console.WriteLine("COLLECTIONS: " + sw.ElapsedMilliseconds);
_filepath = filepath;
return Library;
}

View File

@@ -7,4 +7,9 @@ public interface IHaDocumentWrappper {
public ILibrary ResetLibrary();
public ILibrary? SetLibrary(string filepath, ModelStateDictionary ModelState);
public ILibrary GetLibrary();
public int GetStartYear();
public int GetEndYear();
public void SetStartEndYear(int start, int end);
}

View File

@@ -5,6 +5,7 @@ using HaWeb.Models;
using HaWeb.XMLParser;
using System.Xml.Linq;
// XMLService provides a wrapper around the available XML data on a FILE basis
public class XMLProvider : IXMLProvider {
private IFileProvider _fileProvider;
private Dictionary<string, FileList?>? _Files;

View File

@@ -0,0 +1,9 @@
namespace HaWeb.Models;
using System.ComponentModel.DataAnnotations;
public class StartEndYear {
[Required]
public int StartYear { get; set; }
[Required]
public int EndYear { get; set; }
}

View File

@@ -10,13 +10,18 @@ public class UploadViewModel {
public List<FileModel>? AvailableFiles { get; set; }
public Dictionary<string, List<FileModel>?>? UsedFiles { get; private set; }
public Dictionary<string, List<FileModel>?>? ProductionFiles { get; set; }
public List<int> AvailableYears { get; private set; }
public int StartYear { get; private set; }
public int EndYear { get; private set; }
public List<FileModel>? HamannFiles { get; set; }
public UploadViewModel(string title, string? prefix, List<IXMLRoot>? roots, Dictionary<string, List<FileModel>?>? usedFiles) {
public UploadViewModel(string title, string? prefix, List<IXMLRoot>? roots, Dictionary<string, List<FileModel>?>? usedFiles, int startYear, int endYear, List<int> availableYears) {
Prefix = prefix;
ActiveTitle = title;
AvailableRoots = roots;
UsedFiles = usedFiles;
StartYear = startYear;
EndYear = endYear;
AvailableYears = availableYears;
}
}

View File

@@ -30,7 +30,6 @@ public class XMLRootDocument {
_file = value;
// After saving, we don't need to save the ELement anymore, it can get read in if it's used.
// We do this to prevent memory hogging. TODO: MAKE IT MORE EFFICIENT, EG ALL USED FILES HAVE SET ELEMENTS OR SO
// TODO Also make the file directory more efficient by reading in the directories as they are requested.
if (value != null) _Element = null;
} }
public string Prefix { get; private set; }

View File

@@ -95,6 +95,20 @@
<div class="ha-hamannfilechooser">
@await Html.PartialAsync("/Views/Shared/_FileListForm.cshtml", (Model.HamannFiles, "Verfügbare Hamann-Dateien", "API", "SetUsedHamann", string.Empty, "/Download/XML/", false))
</div>
<form id="seatstartendyearform" enctype="application/x-www-form-urlencoded" asp-controller="API" asp-action="SetStartEndYear">
<select name="StartYear" id="">
@foreach (var y in Model.AvailableYears) {
<option>@y</option>
}
</select>
<select name="EndYear" id="">
@foreach (var y in Model.AvailableYears) {
<option>@y</option>
}
</select>
<button type="submit">Setzen</button>
</form>
}
</div>

View File

@@ -18,7 +18,6 @@ public interface IXMLService {
public void AutoUse(FileList filelist);
public Dictionary<string, FileList?>? GetInProduction();
public void UnUse(string prefix);
public void UnUseProduction();
public void SetInProduction();
public void SetInProduction(XDocument document);
public List<(string Index, List<(string Page, string Line, string Preview, string Identifier)> Results)>? SearchCollection(string collection, string searchword, IReaderService reader, ILibrary? lib);

View File

@@ -11,6 +11,7 @@ using HaXMLReader.Interfaces;
using HaDocument.Interfaces;
using HaDocument.Models;
// XMLService provides a wrapper around the loaded and used XML data
public class XMLService : IXMLService {
private Dictionary<string, FileList?>? _Used;
private Dictionary<string, IXMLRoot>? _Roots;
@@ -200,8 +201,6 @@ public class XMLService : IXMLService {
return res.ToList();
}
public void UnUseProduction() => this._InProduction = null;
public List<XMLRootDocument>? ProbeFile(XDocument document, ModelStateDictionary ModelState) {
if (document.Root!.Name != "opus") {
ModelState.AddModelError("Error", "A valid Hamann-Docuemnt must begin with <opus>");