Added collection classes. Will not do extra collection for subcomments rn.

This commit is contained in:
schnulller
2022-06-26 22:48:25 +02:00
parent 056ab77888
commit 0fa0ff6a88
22 changed files with 490 additions and 226 deletions

View File

@@ -1,3 +1,5 @@
using System.Reflection.Emit;
using System.Collections;
namespace HaWeb.Models;
using HaWeb.SearchHelpers;
using HaWeb.XMLParser;
@@ -5,25 +7,30 @@ using System.Xml.Linq;
public class CollectedItem : ISearchable {
public string Index { get; private set; }
public string Collection { get; private set; }
public string? SearchText { get; private set; }
public Dictionary<string, string[]>? Fields { get; private set; }
public IDictionary<string, string>? Fields { get; private set; }
public XElement ELement { get; private set; }
public IXMLRoot Root { get; private set; }
public IXMLCollection Collection { get; private set; }
public CollectedItem(
string index,
XElement element,
IXMLRoot root,
string collection,
Dictionary<string, string[]>? fields,
IXMLCollection collection,
IDictionary<string, string>? fields,
string? searchtext = null
) {
this.Index = index;
this.SearchText = searchtext;
this.Collection = collection;
this.Root = root;
this.ELement = element;
this.Fields = fields;
}
public string? this[string v] {
get {
if (Fields != null && Fields.ContainsKey(v))
return Fields[v];
return null;
}
}
}

View File

@@ -3,45 +3,40 @@ using HaWeb.XMLParser;
public class ItemsCollection {
public string Name { get; private set; }
public Dictionary<string, CollectedItem> Items { get; private set; }
public bool Searchable { get; private set; }
public IXMLRoot Root { get; private set; }
public Func<List<CollectedItem>, Dictionary<string, Lookup<string, CollectedItem>>?>? GroupingsGeneration { get; private set; }
public Func<List<CollectedItem>, Dictionary<string, List<CollectedItem>>?>? SortingsGeneration { get; private set; }
public IDictionary<string, CollectedItem> Items { get; private set; }
public IXMLCollection Collection { get; private set; }
public Dictionary<string, Lookup<string, CollectedItem>>? Groupings { get; private set; }
public Dictionary<string, List<CollectedItem>>? Sortings { get; private set; }
public IDictionary<string, ILookup<string, CollectedItem>>? Groupings { get; private set; }
public IDictionary<string, IEnumerable<CollectedItem>>? Sortings { get; private set; }
public ItemsCollection(
string name,
bool searchable,
IXMLRoot root,
Func<List<CollectedItem>, Dictionary<string, Lookup<string, CollectedItem>>?>? groupingsFunc = null,
Func<List<CollectedItem>, Dictionary<string, List<CollectedItem>>?>? sortingsFunc = null
IXMLCollection collection
) {
this.Name = name;
this.Searchable = searchable;
this.Root = root;
this.GroupingsGeneration = groupingsFunc;
this.SortingsGeneration = sortingsFunc;
this.Collection = collection;
this.Items = new Dictionary<string, CollectedItem>();
}
public void GenerateGroupings(
Func<List<CollectedItem>, Dictionary<string, Lookup<string, CollectedItem>>?>? groupingsFunc = null
Func<IEnumerable<CollectedItem>, Dictionary<string, ILookup<string, CollectedItem>>?>? groupingsFunc = null
) {
if (groupingsFunc != null)
this.GroupingsGeneration = groupingsFunc;
if (this.GroupingsGeneration != null && this.Items.Any())
this.Groupings = GroupingsGeneration(this.Items.Values.ToList());
if (groupingsFunc != null) {
this.Groupings = groupingsFunc(this.Items.Values.ToList());
return;
}
if (Collection.GroupingsGeneration != null && this.Items.Any())
this.Groupings = Collection.GroupingsGeneration(this.Items.Values.ToList());
}
public void GenerateSortings(
Func<List<CollectedItem>, Dictionary<string, List<CollectedItem>>?>? sortingsFunc = null
Func<IEnumerable<CollectedItem>, Dictionary<string, IEnumerable<CollectedItem>>?>? sortingsFunc = null
) {
if (sortingsFunc != null)
this.SortingsGeneration = sortingsFunc;
if (this.SortingsGeneration != null && this.Items.Any())
this.Sortings = SortingsGeneration(this.Items.Values.ToList());
if (sortingsFunc != null) {
this.Sortings = sortingsFunc(this.Items.Values.ToList());
return;
}
if (Collection.SortingsGeneration != null && this.Items.Any())
this.Sortings = Collection.SortingsGeneration(this.Items.Values.ToList());
}
}