Added logging to module framework

Implemented logging to Adafruit and changed database loading behavior.
This commit is contained in:
Harrison Deng 2021-08-07 17:20:46 -05:00
parent c94ea4a624
commit 38ffb3c7e1
36 changed files with 304 additions and 240 deletions

View File

@ -1,9 +1,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Net.Http; using System.Net.Http;
using System.Text.Json;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Props.Shop.Adafruit.Api; using Props.Shop.Adafruit.Api;
using Props.Shop.Framework; using Props.Shop.Framework;
@ -11,6 +10,8 @@ namespace Props.Shop.Adafruit
{ {
public class AdafruitShop : IShop public class AdafruitShop : IShop
{ {
private ILoggerFactory loggerFactory;
private ILogger<AdafruitShop> logger;
private SearchManager searchManager; private SearchManager searchManager;
private Configuration configuration; private Configuration configuration;
private HttpClient http; private HttpClient http;
@ -29,22 +30,27 @@ namespace Props.Shop.Adafruit
false, false,
true true
); );
public void Initialize(string workspaceDir) public void Initialize(string workspaceDir, ILoggerFactory loggerFactory)
{ {
this.loggerFactory = loggerFactory;
http = new HttpClient(); http = new HttpClient();
http.BaseAddress = new Uri("http://www.adafruit.com/api/"); http.BaseAddress = new Uri("http://www.adafruit.com/api/");
configuration = new Configuration(); // TODO Implement config persistence. configuration = new Configuration();
} // TODO: Implement config persistence.
// TODO: Implement product listing persisted cache.
public async Task InitializeAsync(string workspaceDir) LiveProductListingManager productListingManager = new LiveProductListingManager(http, loggerFactory.CreateLogger<LiveProductListingManager>(), configuration.MinDownloadInterval);
{
ProductListingManager productListingManager = new ProductListingManager(http);
this.searchManager = new SearchManager(productListingManager, configuration.Similarity); this.searchManager = new SearchManager(productListingManager, configuration.Similarity);
await productListingManager.DownloadListings(); productListingManager.StartUpdateTimer(delay: 0);
productListingManager.StartUpdateTimer();
logger = loggerFactory.CreateLogger<AdafruitShop>();
} }
public IEnumerable<ProductListing> Search(string query, Filters filters) public Task<ProductListing> GetProductListingFromUrl(string url)
{
return searchManager.ProductListingManager.GetProductListingFromUrl(url);
}
public IAsyncEnumerable<ProductListing> Search(string query, Filters filters)
{ {
return searchManager.Search(query); return searchManager.Search(query);
} }

View File

@ -7,10 +7,11 @@ namespace Props.Shop.Adafruit.Api
{ {
public interface IProductListingManager : IDisposable public interface IProductListingManager : IDisposable
{ {
public event EventHandler DataUpdateEvent; public Task<IDictionary<string, IList<ProductListing>>> ProductListings { get; }
public IDictionary<string, IList<ProductListing>> ActiveListings { get; } public void RefreshProductListings();
public Task DownloadListings();
public void StartUpdateTimer(int delay = 1000 * 60 * 5, int period = 1000 * 60 * 5); public void StartUpdateTimer(int delay = 1000 * 60 * 5, int period = 1000 * 60 * 5);
public void StopUpdateTimer(); public void StopUpdateTimer();
public Task<ProductListing> GetProductListingFromUrl(string url);
} }
} }

View File

@ -4,53 +4,94 @@ using System.Collections.Generic;
using System.Net.Http; using System.Net.Http;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Props.Shop.Framework; using Props.Shop.Framework;
namespace Props.Shop.Adafruit.Api namespace Props.Shop.Adafruit.Api
{ {
public class ProductListingManager : IProductListingManager public class LiveProductListingManager : IProductListingManager
{ {
public event EventHandler DataUpdateEvent; private ILogger<LiveProductListingManager> logger;
private bool disposedValue; private bool disposedValue;
private volatile Dictionary<string, IList<ProductListing>> activeListings; private int minDownloadInterval;
public IDictionary<string, IList<ProductListing>> ActiveListings => activeListings; private DateTime? lastDownload;
private object refreshLock = new object();
private volatile Task<IDictionary<string, IList<ProductListing>>> productListingsTask;
public Task<IDictionary<string, IList<ProductListing>>> ProductListings => productListingsTask;
private readonly ConcurrentDictionary<string, ProductListing> activeProductListingUrls = new ConcurrentDictionary<string, ProductListing>();
private ProductListingsParser parser = new ProductListingsParser(); private ProductListingsParser parser = new ProductListingsParser();
private HttpClient httpClient; private HttpClient httpClient;
private Timer updateTimer; private Timer updateTimer;
public ProductListingManager(HttpClient httpClient) public LiveProductListingManager(HttpClient httpClient, ILogger<LiveProductListingManager> logger, int minDownloadInterval = 5 * 60 * 1000)
{ {
this.logger = logger;
this.minDownloadInterval = minDownloadInterval;
this.httpClient = httpClient; this.httpClient = httpClient;
} }
public async Task DownloadListings() { public void RefreshProductListings()
{
lock (refreshLock)
{
if (disposedValue) throw new ObjectDisposedException("ProductListingManager");
if ((lastDownload != null && DateTime.UtcNow - lastDownload <= TimeSpan.FromMilliseconds(minDownloadInterval)) || (productListingsTask != null && !productListingsTask.IsCompleted)) return;
lastDownload = DateTime.UtcNow;
logger.LogDebug("Refreshing listings ({0}).", lastDownload);
productListingsTask = DownloadListings();
}
}
public async Task<ProductListing> GetProductListingFromUrl(string url)
{
if (disposedValue) throw new ObjectDisposedException("ProductListingManager"); if (disposedValue) throw new ObjectDisposedException("ProductListingManager");
await productListingsTask;
return activeProductListingUrls[url];
}
private async Task<IDictionary<string, IList<ProductListing>>> DownloadListings()
{
if (disposedValue) throw new ObjectDisposedException("ProductListingManager");
logger.LogDebug("Beginning listing database download.");
HttpResponseMessage responseMessage = await httpClient.GetAsync("products"); HttpResponseMessage responseMessage = await httpClient.GetAsync("products");
parser.BuildProductListings(responseMessage.Content.ReadAsStream()); parser.BuildProductListings(responseMessage.Content.ReadAsStream());
Dictionary<string, IList<ProductListing>> listings = new Dictionary<string, IList<ProductListing>>(); logger.LogDebug("Listing database parsed.");
Dictionary<string, IList<ProductListing>> listingNames = new Dictionary<string, IList<ProductListing>>();
activeProductListingUrls.Clear();
foreach (ProductListing product in parser.ProductListings) foreach (ProductListing product in parser.ProductListings)
{ {
IList<ProductListing> sameProducts = listings.GetValueOrDefault(product.Name); activeProductListingUrls.TryAdd(product.URL, product);
if (sameProducts == null) { IList<ProductListing> sameProducts = listingNames.GetValueOrDefault(product.Name);
if (sameProducts == null)
{
sameProducts = new List<ProductListing>(); sameProducts = new List<ProductListing>();
listings.Add(product.Name, sameProducts); listingNames.Add(product.Name, sameProducts);
} }
sameProducts.Add(product); sameProducts.Add(product);
} }
activeListings = listings; logger.LogDebug("Downloaded listings organized.");
DataUpdateEvent?.Invoke(this, null); return listingNames;
} }
public void StartUpdateTimer(int delay = 1000 * 60 * 5, int period = 1000 * 60 * 5) { public void StartUpdateTimer(int delay = 1000 * 60 * 5, int period = 1000 * 60 * 5)
{
if (disposedValue) throw new ObjectDisposedException("ProductListingManager"); if (disposedValue) throw new ObjectDisposedException("ProductListingManager");
if (updateTimer != null) throw new InvalidOperationException("Update timer already started."); if (updateTimer != null) throw new InvalidOperationException("Update timer already started.");
updateTimer = new Timer(async (state) => await DownloadListings(), null, delay, period); logger.LogInformation("Starting update timer.");
updateTimer = new Timer((state) =>
{
RefreshProductListings();
}, null, delay, period);
} }
public void StopUpdateTimer() { public void StopUpdateTimer()
{
if (disposedValue) throw new ObjectDisposedException("ProductListingManager"); if (disposedValue) throw new ObjectDisposedException("ProductListingManager");
if (updateTimer != null) throw new InvalidOperationException("Update timer not started."); if (updateTimer != null) throw new InvalidOperationException("Update timer not started.");
logger.LogInformation("Stopping update timer.");
updateTimer.Dispose(); updateTimer.Dispose();
updateTimer = null; updateTimer = null;
} }

View File

@ -2,6 +2,7 @@ using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks;
using FuzzySharp; using FuzzySharp;
using FuzzySharp.Extractor; using FuzzySharp.Extractor;
using Props.Shop.Framework; using Props.Shop.Framework;
@ -11,41 +12,26 @@ namespace Props.Shop.Adafruit.Api
public class SearchManager : IDisposable public class SearchManager : IDisposable
{ {
public float Similarity { get; set; } public float Similarity { get; set; }
private readonly object searchLock = new object(); public IProductListingManager ProductListingManager { get; private set; }
private IDictionary<string, IList<ProductListing>> searched;
private IProductListingManager listingManager;
private bool disposedValue; private bool disposedValue;
public SearchManager(IProductListingManager productListingManager, float similarity = 0.8f) public SearchManager(IProductListingManager productListingManager, float similarity = 0.8f)
{ {
this.listingManager = productListingManager ?? throw new ArgumentNullException("productListingManager"); this.ProductListingManager = productListingManager ?? throw new ArgumentNullException("productListingManager");
this.Similarity = similarity; this.Similarity = similarity;
listingManager.DataUpdateEvent += OnDataUpdate;
} }
private void OnDataUpdate(object sender, EventArgs eventArgs) public async IAsyncEnumerable<ProductListing> Search(string query)
{ {
BuildSearchIndex(); if (ProductListingManager.ProductListings == null) {
} ProductListingManager.RefreshProductListings();
private void BuildSearchIndex()
{
lock (searchLock)
{
searched = new Dictionary<string, IList<ProductListing>>(listingManager.ActiveListings);
} }
} IDictionary<string, IList<ProductListing>> productListings = await ProductListingManager.ProductListings;
foreach (ExtractedResult<string> listingNames in Process.ExtractAll(query, productListings.Keys, cutoff: (int)(Similarity * 100)))
public IEnumerable<ProductListing> Search(string query)
{
lock (searchLock)
{ {
foreach (ExtractedResult<string> listingNames in Process.ExtractAll(query, searched.Keys, cutoff: (int)(Similarity * 100))) foreach (ProductListing same in productListings[listingNames.Value])
{ {
foreach (ProductListing same in searched[listingNames.Value]) yield return same;
{
yield return same;
}
} }
} }
} }
@ -56,7 +42,7 @@ namespace Props.Shop.Adafruit.Api
{ {
if (disposing) if (disposing)
{ {
listingManager.Dispose(); ProductListingManager.Dispose();
} }
disposedValue = true; disposedValue = true;

View File

@ -2,10 +2,13 @@ namespace Props.Shop.Adafruit
{ {
public class Configuration public class Configuration
{ {
public int MinDownloadInterval { get; set; }
public float Similarity { get; set; } public float Similarity { get; set; }
public Configuration() public Configuration()
{ {
MinDownloadInterval = 5 * 60 * 1000;
Similarity = 0.8f; Similarity = 0.8f;
} }
} }

View File

@ -7,7 +7,6 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="FuzzySharp" Version="2.0.2" /> <PackageReference Include="FuzzySharp" Version="2.0.2" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="System.Linq.Async" Version="5.0.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -5,7 +5,19 @@ namespace Props.Shop.Framework
public class Filters public class Filters
{ {
public Currency Currency { get; set; } = Currency.CAD; public Currency Currency { get; set; } = Currency.CAD;
public float MinRating { get; set; } = 0.8f; private float minRatingNormalized;
public int MinRating
{
get
{
return (int)(minRatingNormalized * 100);
}
set
{
if (value < 0 || value > 100) return;
minRatingNormalized = value / 100f;
}
}
public bool KeepUnrated { get; set; } = true; public bool KeepUnrated { get; set; } = true;
public bool EnableUpperPrice { get; set; } = false; public bool EnableUpperPrice { get; set; } = false;
private int upperPrice; private int upperPrice;

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Net.Http; using System.Net.Http;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
namespace Props.Shop.Framework namespace Props.Shop.Framework
{ {
@ -12,10 +13,11 @@ namespace Props.Shop.Framework
string ShopDescription { get; } string ShopDescription { get; }
string ShopModuleAuthor { get; } string ShopModuleAuthor { get; }
public IEnumerable<ProductListing> Search(string query, Filters filters); public IAsyncEnumerable<ProductListing> Search(string query, Filters filters);
void Initialize(string workspaceDir); public Task<ProductListing> GetProductListingFromUrl(string url);
Task InitializeAsync(string workspaceDir);
void Initialize(string workspaceDir, ILoggerFactory loggerFactory);
public SupportedFeatures SupportedFeatures { get; } public SupportedFeatures SupportedFeatures { get; }
} }
} }

View File

@ -4,4 +4,8 @@
<TargetFramework>net5.0</TargetFramework> <TargetFramework>net5.0</TargetFramework>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="5.0.0" />
</ItemGroup>
</Project> </Project>

View File

@ -1,5 +1,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Props.Shop.Framework; using Props.Shop.Framework;
using Xunit; using Xunit;
@ -8,16 +10,12 @@ namespace Props.Shop.Adafruit.Tests
public class AdafruitShopTest public class AdafruitShopTest
{ {
[Fact] [Fact]
public async Task TestSearch() { public void TestSearch() {
AdafruitShop mockAdafruitShop = new AdafruitShop(); AdafruitShop mockAdafruitShop = new AdafruitShop();
mockAdafruitShop.Initialize(null); mockAdafruitShop.Initialize(null, LoggerFactory.Create(builder => {
await mockAdafruitShop.InitializeAsync(null); builder.AddXUnit();
int count = 0; }));
foreach (ProductListing listing in mockAdafruitShop.Search("raspberry pi", new Filters())) Assert.NotEmpty(mockAdafruitShop.Search("raspberry pi", new Filters()).ToEnumerable());
{
count += 1;
}
Assert.True(count > 0);
} }
} }
} }

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Threading; using System.Threading;
@ -10,58 +11,65 @@ namespace Props.Shop.Adafruit.Tests.Api
{ {
public class FakeProductListingManager : IProductListingManager public class FakeProductListingManager : IProductListingManager
{ {
private ProductListingsParser parser; private Timer refreshTimer;
private Timer updateTimer;
private bool disposedValue; private bool disposedValue;
private volatile Task<IDictionary<string, IList<ProductListing>>> activeListings;
private DateTime? lastDownload;
private ProductListingsParser parser = new ProductListingsParser();
private readonly ConcurrentDictionary<string, ProductListing> activeProductListingUrls = new ConcurrentDictionary<string, ProductListing>();
private volatile Dictionary<string, IList<ProductListing>> activeListings;
public IDictionary<string, IList<ProductListing>> ActiveListings => activeListings; public Task<IDictionary<string, IList<ProductListing>>> ProductListings => activeListings;
public event EventHandler DataUpdateEvent; public async Task<ProductListing> GetProductListingFromUrl(string url)
public FakeProductListingManager()
{ {
parser = new ProductListingsParser(); if (disposedValue) throw new ObjectDisposedException("ProductListingManager");
await activeListings;
return activeProductListingUrls[url];
} }
public Task DownloadListings() public void RefreshProductListings()
{ {
if (disposedValue) throw new ObjectDisposedException("FakeProductListingManager"); if (disposedValue) throw new ObjectDisposedException("ProductListingManager");
using (Stream stream = File.OpenRead("./Assets/products.json")) if ((lastDownload != null && DateTime.UtcNow - lastDownload <= TimeSpan.FromMilliseconds(5 * 60 * 1000)) || (activeListings != null && !activeListings.IsCompleted)) return;
{ activeListings = DownloadListings();
parser.BuildProductListings(stream); }
}
Dictionary<string, IList<ProductListing>> results = new Dictionary<string, IList<ProductListing>>(); private Task<IDictionary<string, IList<ProductListing>>> DownloadListings() {
if (disposedValue) throw new ObjectDisposedException("ProductListingManager");
lastDownload = DateTime.UtcNow;
parser.BuildProductListings(File.OpenRead("./Assets/products.json"));
Dictionary<string, IList<ProductListing>> listingNames = new Dictionary<string, IList<ProductListing>>();
activeProductListingUrls.Clear();
foreach (ProductListing product in parser.ProductListings) foreach (ProductListing product in parser.ProductListings)
{ {
IList<ProductListing> sameProducts = results.GetValueOrDefault(product.Name); activeProductListingUrls.TryAdd(product.URL, product);
IList<ProductListing> sameProducts = listingNames.GetValueOrDefault(product.Name);
if (sameProducts == null) { if (sameProducts == null) {
sameProducts = new List<ProductListing>(); sameProducts = new List<ProductListing>();
results.Add(product.Name, sameProducts); listingNames.Add(product.Name, sameProducts);
} }
sameProducts.Add(product); sameProducts.Add(product);
} }
activeListings = results; return Task.FromResult<IDictionary<string, IList<ProductListing>>>(listingNames);
DataUpdateEvent?.Invoke(this, null);
return Task.CompletedTask;
} }
public void StartUpdateTimer(int delay = 300000, int period = 300000) public void StartUpdateTimer(int delay = 300000, int period = 300000)
{ {
if (disposedValue) throw new ObjectDisposedException("FakeProductListingManager"); if (disposedValue) throw new ObjectDisposedException("ProductListingManager");
if (updateTimer != null) throw new InvalidOperationException("Update timer already started."); if (refreshTimer != null) throw new InvalidOperationException("Refresh timer already running.");
updateTimer = new Timer((state) => DownloadListings(), null, delay, period); refreshTimer = new Timer((state) => {
RefreshProductListings();
}, null, delay, period);
} }
public void StopUpdateTimer() public void StopUpdateTimer()
{ {
if (disposedValue) throw new ObjectDisposedException("FakeProductListingManager"); if (disposedValue) throw new ObjectDisposedException("ProductListingManager");
if (updateTimer == null) throw new InvalidOperationException("Update timer not started."); if (refreshTimer == null) throw new InvalidOperationException("Refresh timer not running.");
updateTimer.Dispose(); refreshTimer.Dispose();
updateTimer = null; refreshTimer = null;
} }
protected virtual void Dispose(bool disposing) protected virtual void Dispose(bool disposing)
@ -70,8 +78,8 @@ namespace Props.Shop.Adafruit.Tests.Api
{ {
if (disposing) if (disposing)
{ {
updateTimer?.Dispose(); refreshTimer?.Dispose();
updateTimer = null; refreshTimer = null;
} }
disposedValue = true; disposedValue = true;

View File

@ -1,3 +1,4 @@
using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Props.Shop.Adafruit.Api; using Props.Shop.Adafruit.Api;
using Xunit; using Xunit;
@ -7,13 +8,13 @@ namespace Props.Shop.Adafruit.Tests.Api
public class SearchManagerTest public class SearchManagerTest
{ {
[Fact] [Fact]
public async Task SearchTest() public void SearchTest()
{ {
FakeProductListingManager stubProductListingManager = new FakeProductListingManager(); FakeProductListingManager stubProductListingManager = new FakeProductListingManager();
SearchManager searchManager = new SearchManager(stubProductListingManager); SearchManager searchManager = new SearchManager(stubProductListingManager);
await stubProductListingManager.DownloadListings(); stubProductListingManager.RefreshProductListings();
searchManager.Similarity = 0.8f; searchManager.Similarity = 0.8f;
Assert.NotEmpty(searchManager.Search("Raspberry Pi")); Assert.NotEmpty(searchManager.Search("Raspberry Pi").ToEnumerable());
searchManager.Dispose(); searchManager.Dispose();
} }
} }

View File

@ -7,7 +7,10 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="MartinCostello.Logging.XUnit" Version="0.1.2" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="System.Linq.Async" Version="5.0.0" />
<PackageReference Include="xunit" Version="2.4.1" /> <PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3"> <PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

View File

@ -1,8 +0,0 @@
namespace Props.Options
{
public class ContentOptions
{
public const string Content = "Content";
public string Dir { get; set; }
}
}

View File

@ -3,7 +3,8 @@ namespace Props.Options
public class ModulesOptions public class ModulesOptions
{ {
public const string Modules = "Modules"; public const string Modules = "Modules";
public string ShopsDir { get; set; } public string ModulesDir { get; set; }
public string ModuleDataDir { get; set; }
public bool RecursiveLoad { get; set; } public bool RecursiveLoad { get; set; }
public string ShopRegex { get; set; } public string ShopRegex { get; set; }
} }

View File

@ -0,0 +1,8 @@
namespace Props.Options
{
public class TextualOptions
{
public const string Textual = "Textual";
public string Dir { get; set; }
}
}

View File

@ -1,14 +1,15 @@
@page @page
@using Props.Services.Content @using Props.Services.Content
@model IndexModel @model IndexModel
@inject IContentManager<IndexModel> ContentManager @inject ITextualManager<IndexModel> ContentManager
@{ @{
ViewData["Title"] = "Home page"; ViewData["Title"] = "Home page";
} }
<section class="jumbotron d-flex flex-column align-items-center"> <section class="jumbotron d-flex flex-column align-items-center">
<div> <div>
<img alt="Props logo" src="~/images/logo.svg" class="img-fluid" style="max-height: 540px;" asp-append-version="true" /> <img alt="Props logo" src="~/images/logo.svg" class="img-fluid" style="max-height: 540px;"
asp-append-version="true" />
</div> </div>
<div class="text-center px-3 my-2 concise"> <div class="text-center px-3 my-2 concise">
<h1 class="my-2 display-1">Props</h1> <h1 class="my-2 display-1">Props</h1>
@ -24,7 +25,8 @@
<h2 class="mb-3 mt-4">@ContentManager.Json.help.title</h2> <h2 class="mb-3 mt-4">@ContentManager.Json.help.title</h2>
<form class="concise my-4"> <form class="concise my-4">
<div class="input-group"> <div class="input-group">
<input type="text" class="form-control" placeholder="What are you looking for?" aria-label="Search" aria-describedby="search-btn"> <input type="text" class="form-control" placeholder="What are you looking for?" aria-label="Search"
aria-describedby="search-btn">
<button class="btn btn-outline-primary" type="button" id="search-btn">Search</button> <button class="btn btn-outline-primary" type="button" id="search-btn">Search</button>
</div> </div>
</form> </form>

View File

@ -1,28 +1,26 @@
@page @page
@using Props.Services.Content @using Props.Services.Content
@model SearchModel @model SearchModel
@inject IContentManager<SearchModel> ContentManager @inject ITextualManager<SearchModel> ContentManager
@{ @{
ViewData["Title"] = "Search"; ViewData["Title"] = "Search";
ViewData["Specific"] = "Search"; ViewData["Specific"] = "Search";
} }
<div class="mt-4 mb-3"> <form method="GET">
<div class="less-concise mx-auto"> <div class="mt-4 mb-3 less-concise mx-auto">
<div class="input-group"> <div class="input-group">
<input type="text" class="form-control border-primary" placeholder="What are you looking for?" <input type="text" class="form-control border-primary" placeholder="What are you looking for?"
aria-label="Search" aria-describedby="search-btn" id="search-bar" value="@Model.SearchQuery"> aria-label="Search" aria-describedby="search-btn" id="search-bar" value="@Model.SearchQuery" name="q">
<button class="btn btn-outline-secondary" type="button" id="configuration-toggle" data-bs-toggle="collapse" <button class="btn btn-outline-secondary" type="button" id="configuration-toggle" data-bs-toggle="collapse"
data-bs-target="#configuration"><i class="bi bi-sliders"></i></button> data-bs-target="#configuration"><i class="bi bi-sliders"></i></button>
<button class="btn btn-primary" type="button" id="search-btn">Search</button> <button class="btn btn-primary" type="submit" id="search-btn">Search</button>
</div> </div>
</div> </div>
</div>
<div class="collapse tear" id="configuration" x-data="configuration"> <div class="collapse tear" id="configuration">
<div class="p-3"> <div class="container my-3">
<div class="container">
<div class="d-flex"> <div class="d-flex">
<h1 class="my-2 display-2 me-auto">Configuration</h1> <h1 class="my-2 display-2 me-auto">Configuration</h1>
<button class="btn align-self-start" type="button" id="configuration-close" data-bs-toggle="collapse" <button class="btn align-self-start" type="button" id="configuration-close" data-bs-toggle="collapse"
@ -36,10 +34,13 @@
<div class="input-group"> <div class="input-group">
<div class="input-group-text"> <div class="input-group-text">
<input class="form-check-input mt-0" type="checkbox" id="max-price-enabled" <input class="form-check-input mt-0" type="checkbox" id="max-price-enabled"
x-model="maxPriceEnabled"> checked="@Model.ActiveSearchOutline.Filters.EnableUpperPrice"
name="ActiveSearchOutline.Filters.EnableUpperPrice">
</div> </div>
<span class="input-group-text">$</span> <span class="input-group-text">$</span>
<input type="number" class="form-control" min="0" id="max-price" x-model="maxPrice"> <input type="number" class="form-control" min="0" id="max-price"
value="@Model.ActiveSearchOutline.Filters.UpperPrice"
name="ActiveSearchOutline.Filters.UpperPrice">
<span class="input-group-text">.00</span> <span class="input-group-text">.00</span>
</div> </div>
</div> </div>
@ -47,7 +48,9 @@
<label for="min-price" class="form-label">Minimum Price</label> <label for="min-price" class="form-label">Minimum Price</label>
<div class="input-group"> <div class="input-group">
<span class="input-group-text">$</span> <span class="input-group-text">$</span>
<input type="number" class="form-control" min="0" id="min-price" x-model="minPrice"> <input type="number" class="form-control" min="0" id="min-price"
value="@Model.ActiveSearchOutline.Filters.LowerPrice"
name="ActiveSearchOutline.Filters.LowerPrice">
<span class="input-group-text">.00</span> <span class="input-group-text">.00</span>
</div> </div>
</div> </div>
@ -55,17 +58,22 @@
<label for="max-shipping" class="form-label">Maximum Shipping Fee</label> <label for="max-shipping" class="form-label">Maximum Shipping Fee</label>
<div class="input-group"> <div class="input-group">
<div class="input-group-text"> <div class="input-group-text">
<input class="form-check-input mt-0" type="checkbox" id="max-shipping-enabled"> <input class="form-check-input mt-0" type="checkbox" id="max-shipping-enabled"
checked="@Model.ActiveSearchOutline.Filters.EnableMaxShippingFee"
name="ActiveSearchOutline.Filters.EnableMaxShippingFee">
</div> </div>
<span class="input-group-text">$</span> <span class="input-group-text">$</span>
<input type="number" class="form-control" min="0" id="max-shipping" x-model="maxShipping"> <input type="number" class="form-control" min="0" id="max-shipping"
value="@Model.ActiveSearchOutline.Filters.MaxShippingFee"
name="ActiveSearchOutline.Filters.MaxShippingFee">
<span class="input-group-text">.00</span> <span class="input-group-text">.00</span>
</div> </div>
</div> </div>
<div class="mb-3"> <div class="mb-3">
<div class="form-check"> <div class="form-check">
<input class="form-check-input" type="checkbox" id="keep-unknown-shipping" <input class="form-check-input" type="checkbox" id="keep-unknown-shipping"
x-model="keepUnknownShipping"> checked="@Model.ActiveSearchOutline.Filters.KeepUnknownShipping"
name="ActiveSearchOutline.Filters.KeepUnknownShipping">
<label class="form-check-label" for="keep-unknown-shipping">Keep Unknown Shipping</label> <label class="form-check-label" for="keep-unknown-shipping">Keep Unknown Shipping</label>
</div> </div>
</div> </div>
@ -75,28 +83,34 @@
<div class="mb-3"> <div class="mb-3">
<label for="min-purchases" class="form-label">Minimum Purchases</label> <label for="min-purchases" class="form-label">Minimum Purchases</label>
<div class="input-group"> <div class="input-group">
<input type="number" class="form-control" min="0" id="min-purchases" x-model="minPurchases"> <input type="number" class="form-control" min="0" id="min-purchases"
value="@Model.ActiveSearchOutline.Filters.MinPurchases"
name="ActiveSearchOutline.Filters.MinPurchases">
<span class="input-group-text">Purchases</span> <span class="input-group-text">Purchases</span>
</div> </div>
</div> </div>
<div class="mb-3"> <div class="mb-3">
<div class="form-check"> <div class="form-check">
<input class="form-check-input" type="checkbox" id="keep-unknown-purchases" <input class="form-check-input" type="checkbox" id="keep-unknown-purchases"
x-model="keepUnknownPurchases"> checked="@Model.ActiveSearchOutline.Filters.KeepUnknownPurchaseCount"
name="ActiveSearchOutline.Filters.KeepUnknownPurchaseCount">
<label class="form-check-label" for="keep-unknown-purchases">Keep Unknown Purchases</label> <label class="form-check-label" for="keep-unknown-purchases">Keep Unknown Purchases</label>
</div> </div>
</div> </div>
<div class="mb-3"> <div class="mb-3">
<label for="min-reviews" class="form-label">Minimum Reviews</label> <label for="min-reviews" class="form-label">Minimum Reviews</label>
<div class="input-group"> <div class="input-group">
<input type="number" class="form-control" min="0" id="min-reviews" x-model="minReviews"> <input type="number" class="form-control" min="0" id="min-reviews"
value="@Model.ActiveSearchOutline.Filters.MinReviews"
name="ActiveSearchOutline.Filters.MinReviews">
<span class="input-group-text">Reviews</span> <span class="input-group-text">Reviews</span>
</div> </div>
</div> </div>
<div class="mb-3"> <div class="mb-3">
<div class="form-check"> <div class="form-check">
<input class="form-check-input" type="checkbox" id="keep-unknown-reviews" <input class="form-check-input" type="checkbox" id="keep-unknown-reviews"
x-model="keepUnknownReviews"> checked="@Model.ActiveSearchOutline.Filters.KeepUnknownReviewCount"
name="ActiveSearchOutline.Filters.KeepUnknownReviewCount">
<label class="form-check-label" for="keep-unknown-reviews">Keep Unknown Number of <label class="form-check-label" for="keep-unknown-reviews">Keep Unknown Number of
Reviews</label> Reviews</label>
</div> </div>
@ -104,12 +118,15 @@
<div class="mb-1"> <div class="mb-1">
<label for="min-rating" class="form-label">Minimum Rating</label> <label for="min-rating" class="form-label">Minimum Rating</label>
<input type="range" class="form-range" id="min-rating" min="0" max="100" step="1" <input type="range" class="form-range" id="min-rating" min="0" max="100" step="1"
x-model="minRating"> value="@Model.ActiveSearchOutline.Filters.MinRating"
<div id="min-rating-display" class="form-text">Minimum rating: <b x-text="minRating"></b>%</div> name="ActiveSearchOutline.Filters.MinRating">
<div id="min-rating-display" class="form-text"></div>
</div> </div>
<div class="mb-3"> <div class="mb-3">
<div class="form-check"> <div class="form-check">
<input class="form-check-input" type="checkbox" id="keep-unrated" x-model="keepUnrated"> <input class="form-check-input" type="checkbox" id="keep-unrated"
checked="@Model.ActiveSearchOutline.Filters.KeepUnrated"
name="ActiveSearchOutline.Filters.KeepUnrated">
<label class="form-check-label" for="keep-unrated">Keep Unrated Items</label> <label class="form-check-label" for="keep-unrated">Keep Unrated Items</label>
</div> </div>
</div> </div>
@ -117,20 +134,20 @@
<section class="col-lg px-4"> <section class="col-lg px-4">
<h3>Shops Enabled</h3> <h3>Shops Enabled</h3>
<div class="mb-3 px-3" id="shop-checkboxes"> <div class="mb-3 px-3" id="shop-checkboxes">
<template x-for="shop in Object.keys(shops)"> @foreach (string shopName in Model.SearchManager.ShopManager.GetAllShopNames())
{
<div class="form-check"> <div class="form-check">
<input class="form-check-input" type="checkbox" :id="`${shop}-enabled`" <input class="form-check-input" type="checkbox" id="@($"{shopName}-enabled")"
x-model="shops[shop]"> checked="@Model.ActiveSearchOutline.Enabled[shopName]">
<label class="form-check-label" :for="`${shop}-enabled`"><span <label class="form-check-label" for="@($"{shopName}-enabled")">@shopName</label>
x-text="shop"></span></label>
</div> </div>
</template> }
</div> </div>
</section> </section>
</div> </div>
</div> </div>
</div> </div>
</div> </form>
<div id="content-pages" class="multipage mt-3 invisible"> <div id="content-pages" class="multipage mt-3 invisible">
<ul class="nav nav-pills selectors"> <ul class="nav nav-pills selectors">
@ -186,7 +203,10 @@
@if (Model.BestPrice != null) @if (Model.BestPrice != null)
{ {
<p>Looking for the lowest price? Well here it is.</p> <p>Here's the listing with the lowest price.</p>
<div>
@Model.BestPrice.Name
</div>
} }
@* TODO: Add display for top results. *@ @* TODO: Add display for top results. *@

View File

@ -28,22 +28,24 @@ namespace Props.Pages
public ProductListing MostReviews { get; private set; } public ProductListing MostReviews { get; private set; }
public ProductListing BestPrice { get; private set; } public ProductListing BestPrice { get; private set; }
private ISearchManager searchManager; public ISearchManager SearchManager { get; private set; }
private UserManager<ApplicationUser> userManager; private UserManager<ApplicationUser> userManager;
private IMetricsManager analytics; private IMetricsManager analytics;
public SearchOutline ActiveSearchOutline { get; private set; }
public SearchModel(ISearchManager searchManager, UserManager<ApplicationUser> userManager, IMetricsManager analyticsManager) public SearchModel(ISearchManager searchManager, UserManager<ApplicationUser> userManager, IMetricsManager analyticsManager)
{ {
this.searchManager = searchManager; this.SearchManager = searchManager;
this.userManager = userManager; this.userManager = userManager;
this.analytics = analyticsManager; this.analytics = analyticsManager;
} }
public async Task OnGet() public async Task OnGetAsync()
{ {
ActiveSearchOutline = User.Identity.IsAuthenticated ? (await userManager.GetUserAsync(User)).searchOutlinePreferences.ActiveSearchOutline : new SearchOutline();
if (string.IsNullOrWhiteSpace(SearchQuery)) return; if (string.IsNullOrWhiteSpace(SearchQuery)) return;
SearchOutline activeSearchOutline = User.Identity.IsAuthenticated ? (await userManager.GetUserAsync(User)).searchOutlinePreferences.ActiveSearchOutline : new SearchOutline(); Console.WriteLine(SearchQuery);
this.SearchResults = searchManager.Search(SearchQuery, activeSearchOutline); this.SearchResults = await SearchManager.Search(SearchQuery, ActiveSearchOutline);
BestRatingPriceRatio = (from result in SearchResults orderby result.GetRatingToPriceRatio() descending select result).FirstOrDefault((listing) => listing.GetRatingToPriceRatio() >= 0.5f); BestRatingPriceRatio = (from result in SearchResults orderby result.GetRatingToPriceRatio() descending select result).FirstOrDefault((listing) => listing.GetRatingToPriceRatio() >= 0.5f);
TopRated = (from result in SearchResults orderby result.Rating descending select result).FirstOrDefault(); TopRated = (from result in SearchResults orderby result.Rating descending select result).FirstOrDefault();
MostPurchases = (from result in SearchResults orderby result.PurchaseCount descending select result).FirstOrDefault(); MostPurchases = (from result in SearchResults orderby result.PurchaseCount descending select result).FirstOrDefault();

View File

@ -31,15 +31,6 @@
<ProjectReference Include="..\Props-Modules\Props.Shop\Framework\Props.Shop.Framework.csproj" /> <ProjectReference Include="..\Props-Modules\Props.Shop\Framework\Props.Shop.Framework.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Content Include=".\content\**\*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include=".\shops\**\*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup> <ItemGroup>
<Watch Include="**\*.js;**\*.scss" Exclude="node_modules\**\*;**\*.js.map;obj\**\*;bin\**\*" /> <Watch Include="**\*.js;**\*.scss" Exclude="node_modules\**\*;**\*.js.map;obj\**\*;bin\**\*" />
</ItemGroup> </ItemGroup>

View File

@ -7,6 +7,7 @@ namespace Props.Services.Modules
{ {
public interface ISearchManager public interface ISearchManager
{ {
public IEnumerable<ProductListing> Search(string query, SearchOutline searchOutline); public IShopManager ShopManager { get; }
public Task<IEnumerable<ProductListing>> Search(string query, SearchOutline searchOutline);
} }
} }

View File

@ -14,17 +14,17 @@ namespace Props.Services.Modules
{ {
private ILogger<LiveSearchManager> logger; private ILogger<LiveSearchManager> logger;
private SearchOptions searchOptions; private SearchOptions searchOptions;
private IShopManager shopManager; public IShopManager ShopManager { get; private set; }
private IMetricsManager metricsManager; private IMetricsManager metricsManager;
public LiveSearchManager(IMetricsManager metricsManager, IShopManager shopManager, IConfiguration configuration, ILogger<LiveSearchManager> logger) public LiveSearchManager(IMetricsManager metricsManager, IShopManager shopManager, IConfiguration configuration, ILogger<LiveSearchManager> logger)
{ {
this.logger = logger; this.logger = logger;
this.metricsManager = metricsManager; this.metricsManager = metricsManager;
this.shopManager = shopManager; this.ShopManager = shopManager;
this.searchOptions = configuration.GetSection(SearchOptions.Search).Get<SearchOptions>(); this.searchOptions = configuration.GetSection(SearchOptions.Search).Get<SearchOptions>();
} }
public IEnumerable<ProductListing> Search(string query, SearchOutline searchOutline) public async Task<IEnumerable<ProductListing>> Search(string query, SearchOutline searchOutline)
{ {
if (string.IsNullOrWhiteSpace(query)) throw new ArgumentException($"Query \"{query}\" is null or whitepsace."); if (string.IsNullOrWhiteSpace(query)) throw new ArgumentException($"Query \"{query}\" is null or whitepsace.");
if (searchOutline == null) throw new ArgumentNullException("searchOutline"); if (searchOutline == null) throw new ArgumentNullException("searchOutline");
@ -32,13 +32,13 @@ namespace Props.Services.Modules
metricsManager.RegisterSearchQuery(query); metricsManager.RegisterSearchQuery(query);
logger.LogDebug("Searching for \"{0}\".", query); logger.LogDebug("Searching for \"{0}\".", query);
foreach (string shopName in shopManager.GetAllShopNames()) foreach (string shopName in ShopManager.GetAllShopNames())
{ {
if (searchOutline.Enabled[shopName]) if (searchOutline.Enabled[shopName])
{ {
logger.LogDebug("Checking \"{0}\".", shopName); logger.LogDebug("Checking \"{0}\".", shopName);
int amount = 0; int amount = 0;
foreach (ProductListing product in shopManager.GetShop(shopName).Search(query, searchOutline.Filters)) await foreach (ProductListing product in ShopManager.GetShop(shopName).Search(query, searchOutline.Filters))
{ {
if (searchOutline.Filters.Validate(product)) if (searchOutline.Filters.Validate(product))
{ {

View File

@ -9,6 +9,7 @@ using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.VisualStudio.Web.CodeGeneration;
using Props.Data; using Props.Data;
using Props.Models.Search; using Props.Models.Search;
using Props.Options; using Props.Options;
@ -18,26 +19,22 @@ namespace Props.Services.Modules
{ {
public class ModularShopManager : IShopManager public class ModularShopManager : IShopManager
{ {
private ILoggerFactory loggerFactory;
private ILogger<ModularShopManager> logger; private ILogger<ModularShopManager> logger;
private Dictionary<string, IShop> shops; private Dictionary<string, IShop> shops;
private ModulesOptions options; private ModulesOptions options;
private IConfiguration configuration; private IConfiguration configuration;
private bool disposedValue; private bool disposedValue;
public ModularShopManager(IConfiguration configuration, ILogger<ModularShopManager> logger) public ModularShopManager(IConfiguration configuration, ILogger<ModularShopManager> logger, ILoggerFactory loggerFactory)
{ {
this.configuration = configuration; this.loggerFactory = loggerFactory;
this.logger = logger; this.logger = logger;
this.configuration = configuration;
options = configuration.GetSection(ModulesOptions.Modules).Get<ModulesOptions>(); options = configuration.GetSection(ModulesOptions.Modules).Get<ModulesOptions>();
Directory.CreateDirectory(options.ModuleDataDir);
shops = new Dictionary<string, IShop>(); shops = new Dictionary<string, IShop>();
foreach (IShop shop in LoadShops(options.ShopsDir, options.ShopRegex, options.RecursiveLoad)) LoadShops();
{
if (!shops.TryAdd(shop.ShopName, shop))
{
logger.LogWarning("Duplicate shop {0} detected. Ignoring the latter.", shop.ShopName);
}
}
} }
public IEnumerable<string> GetAllShopNames() public IEnumerable<string> GetAllShopNames()
@ -56,9 +53,13 @@ namespace Props.Services.Modules
return shops.Values; return shops.Values;
} }
private IEnumerable<IShop> LoadShops(string shopsDir, string shopRegex, bool recursiveLoad) public void LoadShops()
{ {
Stack<Task> asyncInitTasks = new Stack<Task>(); // TODO: Figure out how to best call this.
string shopsDir = options.ModulesDir;
string shopRegex = options.ShopRegex;
bool recursiveLoad = options.RecursiveLoad;
Stack<string> directories = new Stack<string>(); Stack<string> directories = new Stack<string>();
directories.Push(shopsDir); directories.Push(shopsDir);
string currentDirectory = null; string currentDirectory = null;
@ -86,12 +87,14 @@ namespace Props.Services.Modules
IShop shop = Activator.CreateInstance(type) as IShop; IShop shop = Activator.CreateInstance(type) as IShop;
if (shop != null) if (shop != null)
{ {
// TODO: load persisted shop data. DirectoryInfo dataDir = Directory.CreateDirectory(Path.Combine(options.ModuleDataDir, file));
shop.Initialize(null); shop.Initialize(dataDir.FullName, loggerFactory);
asyncInitTasks.Push(shop.InitializeAsync(null));
success += 1; success += 1;
if (!shops.TryAdd(shop.ShopName, shop))
{
logger.LogWarning("Duplicate shop {0} detected. Ignoring the latter.", shop.ShopName);
}
logger.LogDebug("Loaded \"{0}\".", shop.ShopName); logger.LogDebug("Loaded \"{0}\".", shop.ShopName);
yield return shop;
} }
} }
} }
@ -103,7 +106,6 @@ namespace Props.Services.Modules
} }
} }
logger.LogDebug("Waiting for all shops to finish asynchronous initialization."); logger.LogDebug("Waiting for all shops to finish asynchronous initialization.");
Task.WaitAll(asyncInitTasks.ToArray());
logger.LogDebug("All shops finished asynchronous initialization."); logger.LogDebug("All shops finished asynchronous initialization.");
} }

View File

@ -2,6 +2,7 @@ using System;
using System.Reflection; using System.Reflection;
using System.Runtime.Loader; using System.Runtime.Loader;
using Microsoft.Extensions.DependencyModel; using Microsoft.Extensions.DependencyModel;
using Microsoft.Extensions.Logging;
using Props.Shop.Framework; using Props.Shop.Framework;
namespace Props.Services.Modules namespace Props.Services.Modules
@ -18,6 +19,7 @@ namespace Props.Services.Modules
protected override Assembly Load(AssemblyName assemblyName) protected override Assembly Load(AssemblyName assemblyName)
{ {
if (assemblyName.FullName.Equals(typeof(IShop).Assembly.FullName)) return null; if (assemblyName.FullName.Equals(typeof(IShop).Assembly.FullName)) return null;
if (assemblyName.FullName.Equals(typeof(ILoggerFactory).Assembly.FullName)) return null;
string assemblyPath = resolver.ResolveAssemblyToPath(assemblyName); string assemblyPath = resolver.ResolveAssemblyToPath(assemblyName);
return assemblyPath != null ? LoadFromAssemblyPath(assemblyPath) : null; return assemblyPath != null ? LoadFromAssemblyPath(assemblyPath) : null;
} }

View File

@ -5,13 +5,13 @@ using Props.Options;
namespace Props.Services.Content namespace Props.Services.Content
{ {
public class CachedContentManager<TPage> : IContentManager<TPage> public class CachedTextualManager<TPage> : ITextualManager<TPage>
{ {
private dynamic data; private dynamic data;
private readonly ContentOptions options; private readonly TextualOptions options;
private readonly string fileName; private readonly string fileName;
dynamic IContentManager<TPage>.Json dynamic ITextualManager<TPage>.Json
{ {
get get
{ {
@ -20,9 +20,9 @@ namespace Props.Services.Content
} }
} }
public CachedContentManager(IConfiguration configuration) public CachedTextualManager(IConfiguration configuration)
{ {
this.options = configuration.GetSection(ContentOptions.Content).Get<ContentOptions>(); this.options = configuration.GetSection(TextualOptions.Textual).Get<TextualOptions>();
this.fileName = typeof(TPage).Name.Replace("Model", "") + ".json"; this.fileName = typeof(TPage).Name.Replace("Model", "") + ".json";
} }
} }

View File

@ -1,6 +1,6 @@
namespace Props.Services.Content namespace Props.Services.Content
{ {
public interface IContentManager<out TModel> public interface ITextualManager<out TModel>
{ {
dynamic Json { get; } dynamic Json { get; }
} }

View File

@ -54,7 +54,7 @@ namespace Props
.AddEntityFrameworkStores<ApplicationDbContext>(); .AddEntityFrameworkStores<ApplicationDbContext>();
services.AddRazorPages(); services.AddRazorPages();
services.AddSingleton(typeof(IContentManager<>), typeof(CachedContentManager<>)); services.AddSingleton(typeof(ITextualManager<>), typeof(CachedTextualManager<>));
services.AddSingleton<IShopManager, ModularShopManager>(); services.AddSingleton<IShopManager, ModularShopManager>();
services.AddScoped<IMetricsManager, LiveMetricsManager>(); services.AddScoped<IMetricsManager, LiveMetricsManager>();
services.AddScoped<ISearchManager, LiveSearchManager>(); services.AddScoped<ISearchManager, LiveSearchManager>();

View File

@ -37,7 +37,6 @@ namespace Props.TagHelpers
{ {
output.AddClass(ActiveClass, HtmlEncoder.Default); output.AddClass(ActiveClass, HtmlEncoder.Default);
output.Attributes.Add("aria-current", "page"); output.Attributes.Add("aria-current", "page");
output.Attributes.RemoveAll("href");
} }
output.TagName = "a"; output.TagName = "a";
} }

View File

@ -10,15 +10,16 @@
} }
}, },
"Modules": { "Modules": {
"ShopsDir": "./shops", "ModulesDir": "./shops",
"ModuleDataDir": "./shop-data",
"RecursiveLoad": "false", "RecursiveLoad": "false",
"ShopRegex": "Props\\.Shop\\.." "ShopRegex": "Props\\.Shop\\.."
}, },
"Search": { "Search": {
"MaxResults": 100 "MaxResults": 100
}, },
"Content": { "Textual": {
"Dir": "./content" "Dir": "./textual"
}, },
"AllowedHosts": "*" "AllowedHosts": "*"
} }

View File

@ -1,6 +1,3 @@
import Alpine from "alpinejs";
import { apiHttp } from "~/assets/js/services/http.js";
const startingSlide = "#quick-picks-slide"; const startingSlide = "#quick-picks-slide";
function initInteractiveElements() { function initInteractiveElements() {
@ -14,33 +11,14 @@ function initInteractiveElements() {
}); });
} }
async function initConfigurationData() { function initConfigVisuals() {
const givenConfig = (await apiHttp.get("/SearchOutline/Filters")).data; const minRatingDisplay = document.querySelector("#configuration #min-rating-display");
const disabledShops = (await apiHttp.get("/SearchOutline/DisabledShops")).data; const minRatingSlider = document.querySelector("#configuration #min-rating");
const availableShops = (await apiHttp.get("/Search/Available")).data; const updateDisplay = function () {
document.addEventListener("alpine:init", () => { minRatingDisplay.innerHTML = `Minimum rating: ${minRatingSlider.value}%`;
Alpine.data("configuration", () => { };
const configuration = { minRatingSlider.addEventListener("input", updateDisplay);
maxPriceEnabled: givenConfig.enableUpperPrice, updateDisplay();
maxPrice: givenConfig.upperPrice,
minPrice: givenConfig.lowerPrice,
maxShippingEnabled: givenConfig.enableMaxShippingFee,
maxShipping: givenConfig.maxShippingFee,
keepUnknownShipping: givenConfig.keepUnknownShipping,
minRating: givenConfig.minRating * 100,
keepUnrated: givenConfig.keepUnrated,
minReviews: givenConfig.minReviews,
keepUnknownReviews: givenConfig.keepUnknownReviewCount,
keepUnknownPurchases: givenConfig.keepUnknownPurchaseCount,
minPurchases: givenConfig.minPurchases,
shops: {},
};
availableShops.forEach(shop => {
configuration.shops[shop] = !disabledShops.includes(shop);
});
return configuration;
});
});
} }
function initSlides() { function initSlides() {
@ -68,9 +46,8 @@ function initSlides() {
async function main() { async function main() {
initInteractiveElements(); initInteractiveElements();
await initConfigurationData(); initConfigVisuals();
initSlides(); initSlides();
Alpine.start();
} }
main(); main();

View File

@ -10,8 +10,7 @@
"dependencies": { "dependencies": {
"FuzzySharp": "2.0.2", "FuzzySharp": "2.0.2",
"Newtonsoft.Json": "13.0.1", "Newtonsoft.Json": "13.0.1",
"Props.Shop.Framework": "1.0.0", "Props.Shop.Framework": "1.0.0"
"System.Linq.Async": "5.0.0"
}, },
"runtime": { "runtime": {
"Props.Shop.Adafruit.dll": {} "Props.Shop.Adafruit.dll": {}
@ -25,6 +24,14 @@
} }
} }
}, },
"Microsoft.Extensions.Logging.Abstractions/5.0.0": {
"runtime": {
"lib/netstandard2.0/Microsoft.Extensions.Logging.Abstractions.dll": {
"assemblyVersion": "5.0.0.0",
"fileVersion": "5.0.20.51904"
}
}
},
"Newtonsoft.Json/13.0.1": { "Newtonsoft.Json/13.0.1": {
"runtime": { "runtime": {
"lib/netstandard2.0/Newtonsoft.Json.dll": { "lib/netstandard2.0/Newtonsoft.Json.dll": {
@ -33,15 +40,10 @@
} }
} }
}, },
"System.Linq.Async/5.0.0": {
"runtime": {
"lib/netcoreapp3.1/System.Linq.Async.dll": {
"assemblyVersion": "5.0.0.0",
"fileVersion": "5.0.0.1"
}
}
},
"Props.Shop.Framework/1.0.0": { "Props.Shop.Framework/1.0.0": {
"dependencies": {
"Microsoft.Extensions.Logging.Abstractions": "5.0.0"
},
"runtime": { "runtime": {
"Props.Shop.Framework.dll": {} "Props.Shop.Framework.dll": {}
} }
@ -61,6 +63,13 @@
"path": "fuzzysharp/2.0.2", "path": "fuzzysharp/2.0.2",
"hashPath": "fuzzysharp.2.0.2.nupkg.sha512" "hashPath": "fuzzysharp.2.0.2.nupkg.sha512"
}, },
"Microsoft.Extensions.Logging.Abstractions/5.0.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-NxP6ahFcBnnSfwNBi2KH2Oz8Xl5Sm2krjId/jRR3I7teFphwiUoUeZPwTNA21EX+5PtjqmyAvKaOeBXcJjcH/w==",
"path": "microsoft.extensions.logging.abstractions/5.0.0",
"hashPath": "microsoft.extensions.logging.abstractions.5.0.0.nupkg.sha512"
},
"Newtonsoft.Json/13.0.1": { "Newtonsoft.Json/13.0.1": {
"type": "package", "type": "package",
"serviceable": true, "serviceable": true,
@ -68,13 +77,6 @@
"path": "newtonsoft.json/13.0.1", "path": "newtonsoft.json/13.0.1",
"hashPath": "newtonsoft.json.13.0.1.nupkg.sha512" "hashPath": "newtonsoft.json.13.0.1.nupkg.sha512"
}, },
"System.Linq.Async/5.0.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-cPtIuuH8TIjVHSi2ewwReWGW1PfChPE0LxPIDlfwVcLuTM9GANFTXiMB7k3aC4sk3f0cQU25LNKzx+jZMxijqw==",
"path": "system.linq.async/5.0.0",
"hashPath": "system.linq.async.5.0.0.nupkg.sha512"
},
"Props.Shop.Framework/1.0.0": { "Props.Shop.Framework/1.0.0": {
"type": "project", "type": "project",
"serviceable": false, "serviceable": false,

Binary file not shown.

Binary file not shown.