From 87337ea992c66086499847462b3ba7f3ac0de3fa Mon Sep 17 00:00:00 2001 From: Simon Martens Date: Mon, 8 May 2023 16:39:14 +0200 Subject: [PATCH] =?UTF-8?q?M=C3=B6glichkeit=20zur=20Angabe=20eines=20zeitr?= =?UTF-8?q?aumes=20f=C3=BCr=20die=20angezeigten=20Briefe?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HaDocumentV6/Interfaces/ILibrary.cs | 2 ++ HaDocumentV6/Models/IntermediateLibrary.cs | 2 ++ HaDocumentV6/Models/Library.cs | 5 +++++ HaDocumentV6/Reactors/MetaReactor.cs | 21 +++++++++++++-------- HaWeb/Controllers/APIController.cs | 12 +++++++++++- HaWeb/Controllers/UploadController.cs | 7 +++++-- HaWeb/FileHelpers/HaDocumentWrapper.cs | 18 ++++++++++++++++-- HaWeb/FileHelpers/IHaDocumentWrapper.cs | 5 +++++ HaWeb/FileHelpers/XMLProvider.cs | 1 + HaWeb/Models/StartEndYear.cs | 9 +++++++++ HaWeb/Models/UploadViewModel.cs | 9 +++++++-- HaWeb/Models/XMLRootDocument.cs | 1 - HaWeb/Views/Admin/Dynamic/Upload.cshtml | 14 ++++++++++++++ HaWeb/XMLParser/IXMLService.cs | 1 - HaWeb/XMLParser/XMLService.cs | 3 +-- 15 files changed, 91 insertions(+), 19 deletions(-) create mode 100644 HaWeb/Models/StartEndYear.cs diff --git a/HaDocumentV6/Interfaces/ILibrary.cs b/HaDocumentV6/Interfaces/ILibrary.cs index 39fc1ef..b156e96 100644 --- a/HaDocumentV6/Interfaces/ILibrary.cs +++ b/HaDocumentV6/Interfaces/ILibrary.cs @@ -10,6 +10,7 @@ namespace HaDocument.Interfaces { ImmutableDictionary Traditions { get; } ImmutableDictionary Persons { get; } ImmutableDictionary Metas { get; } + ImmutableDictionary ExcludedMetas { get; } ImmutableDictionary Marginals { get; } ImmutableDictionary Locations { get; } ImmutableDictionary Letters { get; } @@ -27,6 +28,7 @@ namespace HaDocument.Interfaces { Lookup EditreasonsByLetter { get; } ImmutableSortedSet MetasByDate { get; } ILookup MetasByYear { get; } + ILookup ExcludedMetasByYear { get; } ImmutableDictionary SubCommentsByID { get; } } } \ No newline at end of file diff --git a/HaDocumentV6/Models/IntermediateLibrary.cs b/HaDocumentV6/Models/IntermediateLibrary.cs index fa366eb..f129602 100644 --- a/HaDocumentV6/Models/IntermediateLibrary.cs +++ b/HaDocumentV6/Models/IntermediateLibrary.cs @@ -8,6 +8,7 @@ namespace HaDocument.Models public Dictionary Traditions; public Dictionary Persons; public Dictionary Metas; + public Dictionary ExcludedMetas; public Dictionary Marginals; public Dictionary Locations; public Dictionary Letters; @@ -55,6 +56,7 @@ namespace HaDocument.Models Traditions, Persons, Metas, + ExcludedMetas, Marginals, Locations, Letters, diff --git a/HaDocumentV6/Models/Library.cs b/HaDocumentV6/Models/Library.cs index 818447e..21a84b4 100644 --- a/HaDocumentV6/Models/Library.cs +++ b/HaDocumentV6/Models/Library.cs @@ -14,6 +14,7 @@ namespace HaDocument.Models public ImmutableDictionary Traditions { get; } public ImmutableDictionary Persons { get; } public ImmutableDictionary Metas { get; } + public ImmutableDictionary ExcludedMetas { get; } public ImmutableDictionary Marginals { get; } public ImmutableDictionary Locations { get; } public ImmutableDictionary Letters { get; } @@ -42,12 +43,14 @@ namespace HaDocument.Models public ImmutableSortedSet MetasByDate { get; } // Auswählen von Briefen nach dem Jahr, sortiert nach Datum public ILookup MetasByYear { get; } + public ILookup ExcludedMetasByYear { get; } public Library( Dictionary traditions, Dictionary persons, Dictionary meta, + Dictionary excludedMeta, Dictionary marginals, Dictionary locations, Dictionary 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>(); foreach (var entry in backlinks) @@ -95,6 +99,7 @@ namespace HaDocument.Models EditreasonsByLetter = (Lookup)Editreasons.Values.ToLookup(x => x.Letter); MetasByDate = Metas.Values.ToImmutableSortedSet(new DefaultComparer()); MetasByYear = Metas.Values.ToLookup(x => x.Sort.Year); + ExcludedMetasByYear = ExcludedMetas.Values.ToLookup(x => x.Sort.Year); var tempbuilder = ImmutableDictionary.CreateBuilder(); foreach (var comm in Comments) diff --git a/HaDocumentV6/Reactors/MetaReactor.cs b/HaDocumentV6/Reactors/MetaReactor.cs index 766bb1f..3fa0fa4 100644 --- a/HaDocumentV6/Reactors/MetaReactor.cs +++ b/HaDocumentV6/Reactors/MetaReactor.cs @@ -9,7 +9,7 @@ namespace HaDocument.Reactors { class MetaReactor : Reactor { internal Dictionary CreatedInstances { get; } - + internal Dictionary ExcludedInstances { get; } private string[] _availableVolumes; private (int, int) _availableYearRange; @@ -36,6 +36,8 @@ namespace HaDocument.Reactors { _availableYearRange = availableYearRange; lib.Metas = new Dictionary(); CreatedInstances = lib.Metas; + lib.ExcludedMetas = new Dictionary(); + 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() { diff --git a/HaWeb/Controllers/APIController.cs b/HaWeb/Controllers/APIController.cs index 2489a34..dc47791 100644 --- a/HaWeb/Controllers/APIController.cs +++ b/HaWeb/Controllers/APIController.cs @@ -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? SetStartEndYear(StartEndYear startendyear) { + if (startendyear.StartYear > startendyear.EndYear) return BadRequest(); + _lib.SetStartEndYear(startendyear.StartYear, startendyear.EndYear); + return Created("/", "");; + } } \ No newline at end of file diff --git a/HaWeb/Controllers/UploadController.cs b/HaWeb/Controllers/UploadController.cs index 20cd6cc..f6d2f7d 100644 --- a/HaWeb/Controllers/UploadController.cs +++ b/HaWeb/Controllers/UploadController.cs @@ -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; diff --git a/HaWeb/FileHelpers/HaDocumentWrapper.cs b/HaWeb/FileHelpers/HaDocumentWrapper.cs index f5a25ce..4f247b0 100644 --- a/HaWeb/FileHelpers/HaDocumentWrapper.cs +++ b/HaWeb/FileHelpers/HaDocumentWrapper.cs @@ -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; } diff --git a/HaWeb/FileHelpers/IHaDocumentWrapper.cs b/HaWeb/FileHelpers/IHaDocumentWrapper.cs index bec96ae..b255ccc 100644 --- a/HaWeb/FileHelpers/IHaDocumentWrapper.cs +++ b/HaWeb/FileHelpers/IHaDocumentWrapper.cs @@ -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); } \ No newline at end of file diff --git a/HaWeb/FileHelpers/XMLProvider.cs b/HaWeb/FileHelpers/XMLProvider.cs index 26f7104..86c3149 100644 --- a/HaWeb/FileHelpers/XMLProvider.cs +++ b/HaWeb/FileHelpers/XMLProvider.cs @@ -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? _Files; diff --git a/HaWeb/Models/StartEndYear.cs b/HaWeb/Models/StartEndYear.cs new file mode 100644 index 0000000..1549ee6 --- /dev/null +++ b/HaWeb/Models/StartEndYear.cs @@ -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; } +} \ No newline at end of file diff --git a/HaWeb/Models/UploadViewModel.cs b/HaWeb/Models/UploadViewModel.cs index 2742b01..e7a66e1 100644 --- a/HaWeb/Models/UploadViewModel.cs +++ b/HaWeb/Models/UploadViewModel.cs @@ -10,13 +10,18 @@ public class UploadViewModel { public List? AvailableFiles { get; set; } public Dictionary?>? UsedFiles { get; private set; } public Dictionary?>? ProductionFiles { get; set; } - + public List AvailableYears { get; private set; } + public int StartYear { get; private set; } + public int EndYear { get; private set; } public List? HamannFiles { get; set; } - public UploadViewModel(string title, string? prefix, List? roots, Dictionary?>? usedFiles) { + public UploadViewModel(string title, string? prefix, List? roots, Dictionary?>? usedFiles, int startYear, int endYear, List availableYears) { Prefix = prefix; ActiveTitle = title; AvailableRoots = roots; UsedFiles = usedFiles; + StartYear = startYear; + EndYear = endYear; + AvailableYears = availableYears; } } \ No newline at end of file diff --git a/HaWeb/Models/XMLRootDocument.cs b/HaWeb/Models/XMLRootDocument.cs index 5bfb306..56ac8a1 100644 --- a/HaWeb/Models/XMLRootDocument.cs +++ b/HaWeb/Models/XMLRootDocument.cs @@ -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; } diff --git a/HaWeb/Views/Admin/Dynamic/Upload.cshtml b/HaWeb/Views/Admin/Dynamic/Upload.cshtml index c5fde79..4eea827 100644 --- a/HaWeb/Views/Admin/Dynamic/Upload.cshtml +++ b/HaWeb/Views/Admin/Dynamic/Upload.cshtml @@ -95,6 +95,20 @@
@await Html.PartialAsync("/Views/Shared/_FileListForm.cshtml", (Model.HamannFiles, "Verfügbare Hamann-Dateien", "API", "SetUsedHamann", string.Empty, "/Download/XML/", false))
+ +
+ + + +
} \ No newline at end of file diff --git a/HaWeb/XMLParser/IXMLService.cs b/HaWeb/XMLParser/IXMLService.cs index cc9919c..fc8bfb1 100644 --- a/HaWeb/XMLParser/IXMLService.cs +++ b/HaWeb/XMLParser/IXMLService.cs @@ -18,7 +18,6 @@ public interface IXMLService { public void AutoUse(FileList filelist); public Dictionary? 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); diff --git a/HaWeb/XMLParser/XMLService.cs b/HaWeb/XMLParser/XMLService.cs index 5fc423d..29774d0 100644 --- a/HaWeb/XMLParser/XMLService.cs +++ b/HaWeb/XMLParser/XMLService.cs @@ -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? _Used; private Dictionary? _Roots; @@ -200,8 +201,6 @@ public class XMLService : IXMLService { return res.ToList(); } - public void UnUseProduction() => this._InProduction = null; - public List? ProbeFile(XDocument document, ModelStateDictionary ModelState) { if (document.Root!.Name != "opus") { ModelState.AddModelError("Error", "A valid Hamann-Docuemnt must begin with ");