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

@@ -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>");