Added logging to module framework
Implemented logging to Adafruit and changed database loading behavior.
This commit is contained in:
parent
c94ea4a624
commit
38ffb3c7e1
@ -1,9 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Props.Shop.Adafruit.Api;
|
||||
using Props.Shop.Framework;
|
||||
|
||||
@ -11,6 +10,8 @@ namespace Props.Shop.Adafruit
|
||||
{
|
||||
public class AdafruitShop : IShop
|
||||
{
|
||||
private ILoggerFactory loggerFactory;
|
||||
private ILogger<AdafruitShop> logger;
|
||||
private SearchManager searchManager;
|
||||
private Configuration configuration;
|
||||
private HttpClient http;
|
||||
@ -29,22 +30,27 @@ namespace Props.Shop.Adafruit
|
||||
false,
|
||||
true
|
||||
);
|
||||
public void Initialize(string workspaceDir)
|
||||
public void Initialize(string workspaceDir, ILoggerFactory loggerFactory)
|
||||
{
|
||||
this.loggerFactory = loggerFactory;
|
||||
http = new HttpClient();
|
||||
http.BaseAddress = new Uri("http://www.adafruit.com/api/");
|
||||
configuration = new Configuration(); // TODO Implement config persistence.
|
||||
}
|
||||
|
||||
public async Task InitializeAsync(string workspaceDir)
|
||||
{
|
||||
ProductListingManager productListingManager = new ProductListingManager(http);
|
||||
configuration = new Configuration();
|
||||
// TODO: Implement config persistence.
|
||||
// TODO: Implement product listing persisted cache.
|
||||
LiveProductListingManager productListingManager = new LiveProductListingManager(http, loggerFactory.CreateLogger<LiveProductListingManager>(), configuration.MinDownloadInterval);
|
||||
this.searchManager = new SearchManager(productListingManager, configuration.Similarity);
|
||||
await productListingManager.DownloadListings();
|
||||
productListingManager.StartUpdateTimer();
|
||||
productListingManager.StartUpdateTimer(delay: 0);
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -7,10 +7,11 @@ namespace Props.Shop.Adafruit.Api
|
||||
{
|
||||
public interface IProductListingManager : IDisposable
|
||||
{
|
||||
public event EventHandler DataUpdateEvent;
|
||||
public IDictionary<string, IList<ProductListing>> ActiveListings { get; }
|
||||
public Task DownloadListings();
|
||||
public Task<IDictionary<string, IList<ProductListing>>> ProductListings { get; }
|
||||
public void RefreshProductListings();
|
||||
public void StartUpdateTimer(int delay = 1000 * 60 * 5, int period = 1000 * 60 * 5);
|
||||
public void StopUpdateTimer();
|
||||
|
||||
public Task<ProductListing> GetProductListingFromUrl(string url);
|
||||
}
|
||||
}
|
@ -4,53 +4,94 @@ using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Props.Shop.Framework;
|
||||
|
||||
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 volatile Dictionary<string, IList<ProductListing>> activeListings;
|
||||
public IDictionary<string, IList<ProductListing>> ActiveListings => activeListings;
|
||||
private int minDownloadInterval;
|
||||
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 HttpClient httpClient;
|
||||
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;
|
||||
}
|
||||
|
||||
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");
|
||||
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");
|
||||
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)
|
||||
{
|
||||
IList<ProductListing> sameProducts = listings.GetValueOrDefault(product.Name);
|
||||
if (sameProducts == null) {
|
||||
activeProductListingUrls.TryAdd(product.URL, product);
|
||||
IList<ProductListing> sameProducts = listingNames.GetValueOrDefault(product.Name);
|
||||
if (sameProducts == null)
|
||||
{
|
||||
sameProducts = new List<ProductListing>();
|
||||
listings.Add(product.Name, sameProducts);
|
||||
listingNames.Add(product.Name, sameProducts);
|
||||
}
|
||||
|
||||
sameProducts.Add(product);
|
||||
}
|
||||
activeListings = listings;
|
||||
DataUpdateEvent?.Invoke(this, null);
|
||||
logger.LogDebug("Downloaded listings organized.");
|
||||
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 (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 (updateTimer != null) throw new InvalidOperationException("Update timer not started.");
|
||||
logger.LogInformation("Stopping update timer.");
|
||||
updateTimer.Dispose();
|
||||
updateTimer = null;
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using FuzzySharp;
|
||||
using FuzzySharp.Extractor;
|
||||
using Props.Shop.Framework;
|
||||
@ -11,44 +12,29 @@ namespace Props.Shop.Adafruit.Api
|
||||
public class SearchManager : IDisposable
|
||||
{
|
||||
public float Similarity { get; set; }
|
||||
private readonly object searchLock = new object();
|
||||
private IDictionary<string, IList<ProductListing>> searched;
|
||||
private IProductListingManager listingManager;
|
||||
public IProductListingManager ProductListingManager { get; private set; }
|
||||
private bool disposedValue;
|
||||
|
||||
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;
|
||||
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()
|
||||
IDictionary<string, IList<ProductListing>> productListings = await ProductListingManager.ProductListings;
|
||||
foreach (ExtractedResult<string> listingNames in Process.ExtractAll(query, productListings.Keys, cutoff: (int)(Similarity * 100)))
|
||||
{
|
||||
lock (searchLock)
|
||||
{
|
||||
searched = new Dictionary<string, IList<ProductListing>>(listingManager.ActiveListings);
|
||||
}
|
||||
}
|
||||
|
||||
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 searched[listingNames.Value])
|
||||
foreach (ProductListing same in productListings[listingNames.Value])
|
||||
{
|
||||
yield return same;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
@ -56,7 +42,7 @@ namespace Props.Shop.Adafruit.Api
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
listingManager.Dispose();
|
||||
ProductListingManager.Dispose();
|
||||
}
|
||||
|
||||
disposedValue = true;
|
||||
|
@ -2,10 +2,13 @@ namespace Props.Shop.Adafruit
|
||||
{
|
||||
public class Configuration
|
||||
{
|
||||
public int MinDownloadInterval { get; set; }
|
||||
|
||||
public float Similarity { get; set; }
|
||||
|
||||
public Configuration()
|
||||
{
|
||||
MinDownloadInterval = 5 * 60 * 1000;
|
||||
Similarity = 0.8f;
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,6 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FuzzySharp" Version="2.0.2" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||
<PackageReference Include="System.Linq.Async" Version="5.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -5,7 +5,19 @@ namespace Props.Shop.Framework
|
||||
public class Filters
|
||||
{
|
||||
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 EnableUpperPrice { get; set; } = false;
|
||||
private int upperPrice;
|
||||
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Props.Shop.Framework
|
||||
{
|
||||
@ -12,10 +13,11 @@ namespace Props.Shop.Framework
|
||||
string ShopDescription { get; }
|
||||
string ShopModuleAuthor { get; }
|
||||
|
||||
public IEnumerable<ProductListing> Search(string query, Filters filters);
|
||||
public IAsyncEnumerable<ProductListing> Search(string query, Filters filters);
|
||||
|
||||
void Initialize(string workspaceDir);
|
||||
Task InitializeAsync(string workspaceDir);
|
||||
public Task<ProductListing> GetProductListingFromUrl(string url);
|
||||
|
||||
void Initialize(string workspaceDir, ILoggerFactory loggerFactory);
|
||||
public SupportedFeatures SupportedFeatures { get; }
|
||||
}
|
||||
}
|
@ -4,4 +4,8 @@
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="5.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -1,5 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Props.Shop.Framework;
|
||||
using Xunit;
|
||||
|
||||
@ -8,16 +10,12 @@ namespace Props.Shop.Adafruit.Tests
|
||||
public class AdafruitShopTest
|
||||
{
|
||||
[Fact]
|
||||
public async Task TestSearch() {
|
||||
public void TestSearch() {
|
||||
AdafruitShop mockAdafruitShop = new AdafruitShop();
|
||||
mockAdafruitShop.Initialize(null);
|
||||
await mockAdafruitShop.InitializeAsync(null);
|
||||
int count = 0;
|
||||
foreach (ProductListing listing in mockAdafruitShop.Search("raspberry pi", new Filters()))
|
||||
{
|
||||
count += 1;
|
||||
}
|
||||
Assert.True(count > 0);
|
||||
mockAdafruitShop.Initialize(null, LoggerFactory.Create(builder => {
|
||||
builder.AddXUnit();
|
||||
}));
|
||||
Assert.NotEmpty(mockAdafruitShop.Search("raspberry pi", new Filters()).ToEnumerable());
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
@ -10,58 +11,65 @@ namespace Props.Shop.Adafruit.Tests.Api
|
||||
{
|
||||
public class FakeProductListingManager : IProductListingManager
|
||||
{
|
||||
private ProductListingsParser parser;
|
||||
private Timer updateTimer;
|
||||
private Timer refreshTimer;
|
||||
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 FakeProductListingManager()
|
||||
public async Task<ProductListing> GetProductListingFromUrl(string url)
|
||||
{
|
||||
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");
|
||||
using (Stream stream = File.OpenRead("./Assets/products.json"))
|
||||
{
|
||||
parser.BuildProductListings(stream);
|
||||
if (disposedValue) throw new ObjectDisposedException("ProductListingManager");
|
||||
if ((lastDownload != null && DateTime.UtcNow - lastDownload <= TimeSpan.FromMilliseconds(5 * 60 * 1000)) || (activeListings != null && !activeListings.IsCompleted)) return;
|
||||
activeListings = DownloadListings();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
IList<ProductListing> sameProducts = results.GetValueOrDefault(product.Name);
|
||||
activeProductListingUrls.TryAdd(product.URL, product);
|
||||
IList<ProductListing> sameProducts = listingNames.GetValueOrDefault(product.Name);
|
||||
if (sameProducts == null) {
|
||||
sameProducts = new List<ProductListing>();
|
||||
results.Add(product.Name, sameProducts);
|
||||
listingNames.Add(product.Name, sameProducts);
|
||||
}
|
||||
|
||||
sameProducts.Add(product);
|
||||
}
|
||||
activeListings = results;
|
||||
DataUpdateEvent?.Invoke(this, null);
|
||||
return Task.CompletedTask;
|
||||
return Task.FromResult<IDictionary<string, IList<ProductListing>>>(listingNames);
|
||||
}
|
||||
|
||||
public void StartUpdateTimer(int delay = 300000, int period = 300000)
|
||||
{
|
||||
if (disposedValue) throw new ObjectDisposedException("FakeProductListingManager");
|
||||
if (updateTimer != null) throw new InvalidOperationException("Update timer already started.");
|
||||
updateTimer = new Timer((state) => DownloadListings(), null, delay, period);
|
||||
if (disposedValue) throw new ObjectDisposedException("ProductListingManager");
|
||||
if (refreshTimer != null) throw new InvalidOperationException("Refresh timer already running.");
|
||||
refreshTimer = new Timer((state) => {
|
||||
RefreshProductListings();
|
||||
}, null, delay, period);
|
||||
}
|
||||
|
||||
public void StopUpdateTimer()
|
||||
{
|
||||
if (disposedValue) throw new ObjectDisposedException("FakeProductListingManager");
|
||||
if (updateTimer == null) throw new InvalidOperationException("Update timer not started.");
|
||||
updateTimer.Dispose();
|
||||
updateTimer = null;
|
||||
if (disposedValue) throw new ObjectDisposedException("ProductListingManager");
|
||||
if (refreshTimer == null) throw new InvalidOperationException("Refresh timer not running.");
|
||||
refreshTimer.Dispose();
|
||||
refreshTimer = null;
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
@ -70,8 +78,8 @@ namespace Props.Shop.Adafruit.Tests.Api
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
updateTimer?.Dispose();
|
||||
updateTimer = null;
|
||||
refreshTimer?.Dispose();
|
||||
refreshTimer = null;
|
||||
}
|
||||
|
||||
disposedValue = true;
|
||||
|
@ -1,3 +1,4 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Props.Shop.Adafruit.Api;
|
||||
using Xunit;
|
||||
@ -7,13 +8,13 @@ namespace Props.Shop.Adafruit.Tests.Api
|
||||
public class SearchManagerTest
|
||||
{
|
||||
[Fact]
|
||||
public async Task SearchTest()
|
||||
public void SearchTest()
|
||||
{
|
||||
FakeProductListingManager stubProductListingManager = new FakeProductListingManager();
|
||||
SearchManager searchManager = new SearchManager(stubProductListingManager);
|
||||
await stubProductListingManager.DownloadListings();
|
||||
stubProductListingManager.RefreshProductListings();
|
||||
searchManager.Similarity = 0.8f;
|
||||
Assert.NotEmpty(searchManager.Search("Raspberry Pi"));
|
||||
Assert.NotEmpty(searchManager.Search("Raspberry Pi").ToEnumerable());
|
||||
searchManager.Dispose();
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,10 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<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="System.Linq.Async" Version="5.0.0" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
|
@ -1,8 +0,0 @@
|
||||
namespace Props.Options
|
||||
{
|
||||
public class ContentOptions
|
||||
{
|
||||
public const string Content = "Content";
|
||||
public string Dir { get; set; }
|
||||
}
|
||||
}
|
@ -3,7 +3,8 @@ namespace Props.Options
|
||||
public class ModulesOptions
|
||||
{
|
||||
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 string ShopRegex { get; set; }
|
||||
}
|
||||
|
8
Props/Options/TextualOptions.cs
Normal file
8
Props/Options/TextualOptions.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace Props.Options
|
||||
{
|
||||
public class TextualOptions
|
||||
{
|
||||
public const string Textual = "Textual";
|
||||
public string Dir { get; set; }
|
||||
}
|
||||
}
|
@ -1,14 +1,15 @@
|
||||
@page
|
||||
@using Props.Services.Content
|
||||
@model IndexModel
|
||||
@inject IContentManager<IndexModel> ContentManager
|
||||
@inject ITextualManager<IndexModel> ContentManager
|
||||
@{
|
||||
ViewData["Title"] = "Home page";
|
||||
}
|
||||
|
||||
<section class="jumbotron d-flex flex-column align-items-center">
|
||||
<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 class="text-center px-3 my-2 concise">
|
||||
<h1 class="my-2 display-1">Props</h1>
|
||||
@ -24,7 +25,8 @@
|
||||
<h2 class="mb-3 mt-4">@ContentManager.Json.help.title</h2>
|
||||
<form class="concise my-4">
|
||||
<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>
|
||||
</div>
|
||||
</form>
|
||||
|
@ -1,28 +1,26 @@
|
||||
@page
|
||||
@using Props.Services.Content
|
||||
@model SearchModel
|
||||
@inject IContentManager<SearchModel> ContentManager
|
||||
@inject ITextualManager<SearchModel> ContentManager
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Search";
|
||||
ViewData["Specific"] = "Search";
|
||||
}
|
||||
|
||||
<div class="mt-4 mb-3">
|
||||
<div class="less-concise mx-auto">
|
||||
<form method="GET">
|
||||
<div class="mt-4 mb-3 less-concise mx-auto">
|
||||
<div class="input-group">
|
||||
<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"
|
||||
data-bs-target="#configuration"><i class="bi bi-sliders"></i></button>
|
||||
<button class="btn btn-primary" type="button" id="search-btn">Search</button>
|
||||
</div>
|
||||
<button class="btn btn-primary" type="submit" id="search-btn">Search</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="collapse tear" id="configuration" x-data="configuration">
|
||||
<div class="p-3">
|
||||
<div class="container">
|
||||
<div class="collapse tear" id="configuration">
|
||||
<div class="container my-3">
|
||||
<div class="d-flex">
|
||||
<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"
|
||||
@ -36,10 +34,13 @@
|
||||
<div class="input-group">
|
||||
<div class="input-group-text">
|
||||
<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>
|
||||
<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>
|
||||
</div>
|
||||
</div>
|
||||
@ -47,7 +48,9 @@
|
||||
<label for="min-price" class="form-label">Minimum Price</label>
|
||||
<div class="input-group">
|
||||
<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>
|
||||
</div>
|
||||
</div>
|
||||
@ -55,17 +58,22 @@
|
||||
<label for="max-shipping" class="form-label">Maximum Shipping Fee</label>
|
||||
<div class="input-group">
|
||||
<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>
|
||||
<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>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<div class="form-check">
|
||||
<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>
|
||||
</div>
|
||||
</div>
|
||||
@ -75,28 +83,34 @@
|
||||
<div class="mb-3">
|
||||
<label for="min-purchases" class="form-label">Minimum Purchases</label>
|
||||
<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>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<div class="form-check">
|
||||
<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>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="min-reviews" class="form-label">Minimum Reviews</label>
|
||||
<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>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<div class="form-check">
|
||||
<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
|
||||
Reviews</label>
|
||||
</div>
|
||||
@ -104,12 +118,15 @@
|
||||
<div class="mb-1">
|
||||
<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"
|
||||
x-model="minRating">
|
||||
<div id="min-rating-display" class="form-text">Minimum rating: <b x-text="minRating"></b>%</div>
|
||||
value="@Model.ActiveSearchOutline.Filters.MinRating"
|
||||
name="ActiveSearchOutline.Filters.MinRating">
|
||||
<div id="min-rating-display" class="form-text"></div>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<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>
|
||||
</div>
|
||||
</div>
|
||||
@ -117,20 +134,20 @@
|
||||
<section class="col-lg px-4">
|
||||
<h3>Shops Enabled</h3>
|
||||
<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">
|
||||
<input class="form-check-input" type="checkbox" :id="`${shop}-enabled`"
|
||||
x-model="shops[shop]">
|
||||
<label class="form-check-label" :for="`${shop}-enabled`"><span
|
||||
x-text="shop"></span></label>
|
||||
<input class="form-check-input" type="checkbox" id="@($"{shopName}-enabled")"
|
||||
checked="@Model.ActiveSearchOutline.Enabled[shopName]">
|
||||
<label class="form-check-label" for="@($"{shopName}-enabled")">@shopName</label>
|
||||
</div>
|
||||
</template>
|
||||
}
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div id="content-pages" class="multipage mt-3 invisible">
|
||||
<ul class="nav nav-pills selectors">
|
||||
@ -186,7 +203,10 @@
|
||||
|
||||
@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. *@
|
||||
|
@ -28,22 +28,24 @@ namespace Props.Pages
|
||||
public ProductListing MostReviews { get; private set; }
|
||||
public ProductListing BestPrice { get; private set; }
|
||||
|
||||
private ISearchManager searchManager;
|
||||
public ISearchManager SearchManager { get; private set; }
|
||||
private UserManager<ApplicationUser> userManager;
|
||||
private IMetricsManager analytics;
|
||||
public SearchOutline ActiveSearchOutline { get; private set; }
|
||||
|
||||
public SearchModel(ISearchManager searchManager, UserManager<ApplicationUser> userManager, IMetricsManager analyticsManager)
|
||||
{
|
||||
this.searchManager = searchManager;
|
||||
this.SearchManager = searchManager;
|
||||
this.userManager = userManager;
|
||||
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;
|
||||
SearchOutline activeSearchOutline = User.Identity.IsAuthenticated ? (await userManager.GetUserAsync(User)).searchOutlinePreferences.ActiveSearchOutline : new SearchOutline();
|
||||
this.SearchResults = searchManager.Search(SearchQuery, activeSearchOutline);
|
||||
Console.WriteLine(SearchQuery);
|
||||
this.SearchResults = await SearchManager.Search(SearchQuery, ActiveSearchOutline);
|
||||
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();
|
||||
MostPurchases = (from result in SearchResults orderby result.PurchaseCount descending select result).FirstOrDefault();
|
||||
|
@ -31,15 +31,6 @@
|
||||
<ProjectReference Include="..\Props-Modules\Props.Shop\Framework\Props.Shop.Framework.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include=".\content\**\*">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include=".\shops\**\*">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Watch Include="**\*.js;**\*.scss" Exclude="node_modules\**\*;**\*.js.map;obj\**\*;bin\**\*" />
|
||||
</ItemGroup>
|
||||
|
@ -7,6 +7,7 @@ namespace Props.Services.Modules
|
||||
{
|
||||
public interface ISearchManager
|
||||
{
|
||||
public IEnumerable<ProductListing> Search(string query, SearchOutline searchOutline);
|
||||
public IShopManager ShopManager { get; }
|
||||
public Task<IEnumerable<ProductListing>> Search(string query, SearchOutline searchOutline);
|
||||
}
|
||||
}
|
@ -14,17 +14,17 @@ namespace Props.Services.Modules
|
||||
{
|
||||
private ILogger<LiveSearchManager> logger;
|
||||
private SearchOptions searchOptions;
|
||||
private IShopManager shopManager;
|
||||
public IShopManager ShopManager { get; private set; }
|
||||
private IMetricsManager metricsManager;
|
||||
|
||||
public LiveSearchManager(IMetricsManager metricsManager, IShopManager shopManager, IConfiguration configuration, ILogger<LiveSearchManager> logger)
|
||||
{
|
||||
this.logger = logger;
|
||||
this.metricsManager = metricsManager;
|
||||
this.shopManager = shopManager;
|
||||
this.ShopManager = shopManager;
|
||||
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 (searchOutline == null) throw new ArgumentNullException("searchOutline");
|
||||
@ -32,13 +32,13 @@ namespace Props.Services.Modules
|
||||
metricsManager.RegisterSearchQuery(query);
|
||||
logger.LogDebug("Searching for \"{0}\".", query);
|
||||
|
||||
foreach (string shopName in shopManager.GetAllShopNames())
|
||||
foreach (string shopName in ShopManager.GetAllShopNames())
|
||||
{
|
||||
if (searchOutline.Enabled[shopName])
|
||||
{
|
||||
logger.LogDebug("Checking \"{0}\".", shopName);
|
||||
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))
|
||||
{
|
||||
|
@ -9,6 +9,7 @@ using System.Threading.Tasks;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.VisualStudio.Web.CodeGeneration;
|
||||
using Props.Data;
|
||||
using Props.Models.Search;
|
||||
using Props.Options;
|
||||
@ -18,26 +19,22 @@ namespace Props.Services.Modules
|
||||
{
|
||||
public class ModularShopManager : IShopManager
|
||||
{
|
||||
private ILoggerFactory loggerFactory;
|
||||
private ILogger<ModularShopManager> logger;
|
||||
private Dictionary<string, IShop> shops;
|
||||
private ModulesOptions options;
|
||||
private IConfiguration configuration;
|
||||
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.configuration = configuration;
|
||||
options = configuration.GetSection(ModulesOptions.Modules).Get<ModulesOptions>();
|
||||
|
||||
Directory.CreateDirectory(options.ModuleDataDir);
|
||||
shops = new Dictionary<string, IShop>();
|
||||
foreach (IShop shop in LoadShops(options.ShopsDir, options.ShopRegex, options.RecursiveLoad))
|
||||
{
|
||||
if (!shops.TryAdd(shop.ShopName, shop))
|
||||
{
|
||||
logger.LogWarning("Duplicate shop {0} detected. Ignoring the latter.", shop.ShopName);
|
||||
}
|
||||
}
|
||||
LoadShops();
|
||||
}
|
||||
|
||||
public IEnumerable<string> GetAllShopNames()
|
||||
@ -56,9 +53,13 @@ namespace Props.Services.Modules
|
||||
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>();
|
||||
directories.Push(shopsDir);
|
||||
string currentDirectory = null;
|
||||
@ -86,12 +87,14 @@ namespace Props.Services.Modules
|
||||
IShop shop = Activator.CreateInstance(type) as IShop;
|
||||
if (shop != null)
|
||||
{
|
||||
// TODO: load persisted shop data.
|
||||
shop.Initialize(null);
|
||||
asyncInitTasks.Push(shop.InitializeAsync(null));
|
||||
DirectoryInfo dataDir = Directory.CreateDirectory(Path.Combine(options.ModuleDataDir, file));
|
||||
shop.Initialize(dataDir.FullName, loggerFactory);
|
||||
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);
|
||||
yield return shop;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -103,7 +106,6 @@ namespace Props.Services.Modules
|
||||
}
|
||||
}
|
||||
logger.LogDebug("Waiting for all shops to finish asynchronous initialization.");
|
||||
Task.WaitAll(asyncInitTasks.ToArray());
|
||||
logger.LogDebug("All shops finished asynchronous initialization.");
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@ using System;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Loader;
|
||||
using Microsoft.Extensions.DependencyModel;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Props.Shop.Framework;
|
||||
|
||||
namespace Props.Services.Modules
|
||||
@ -18,6 +19,7 @@ namespace Props.Services.Modules
|
||||
protected override Assembly Load(AssemblyName assemblyName)
|
||||
{
|
||||
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);
|
||||
return assemblyPath != null ? LoadFromAssemblyPath(assemblyPath) : null;
|
||||
}
|
||||
|
@ -5,13 +5,13 @@ using Props.Options;
|
||||
|
||||
namespace Props.Services.Content
|
||||
{
|
||||
public class CachedContentManager<TPage> : IContentManager<TPage>
|
||||
public class CachedTextualManager<TPage> : ITextualManager<TPage>
|
||||
{
|
||||
private dynamic data;
|
||||
private readonly ContentOptions options;
|
||||
private readonly TextualOptions options;
|
||||
private readonly string fileName;
|
||||
|
||||
dynamic IContentManager<TPage>.Json
|
||||
dynamic ITextualManager<TPage>.Json
|
||||
{
|
||||
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";
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
namespace Props.Services.Content
|
||||
{
|
||||
public interface IContentManager<out TModel>
|
||||
public interface ITextualManager<out TModel>
|
||||
{
|
||||
dynamic Json { get; }
|
||||
}
|
@ -54,7 +54,7 @@ namespace Props
|
||||
.AddEntityFrameworkStores<ApplicationDbContext>();
|
||||
services.AddRazorPages();
|
||||
|
||||
services.AddSingleton(typeof(IContentManager<>), typeof(CachedContentManager<>));
|
||||
services.AddSingleton(typeof(ITextualManager<>), typeof(CachedTextualManager<>));
|
||||
services.AddSingleton<IShopManager, ModularShopManager>();
|
||||
services.AddScoped<IMetricsManager, LiveMetricsManager>();
|
||||
services.AddScoped<ISearchManager, LiveSearchManager>();
|
||||
|
@ -37,7 +37,6 @@ namespace Props.TagHelpers
|
||||
{
|
||||
output.AddClass(ActiveClass, HtmlEncoder.Default);
|
||||
output.Attributes.Add("aria-current", "page");
|
||||
output.Attributes.RemoveAll("href");
|
||||
}
|
||||
output.TagName = "a";
|
||||
}
|
||||
|
@ -10,15 +10,16 @@
|
||||
}
|
||||
},
|
||||
"Modules": {
|
||||
"ShopsDir": "./shops",
|
||||
"ModulesDir": "./shops",
|
||||
"ModuleDataDir": "./shop-data",
|
||||
"RecursiveLoad": "false",
|
||||
"ShopRegex": "Props\\.Shop\\.."
|
||||
},
|
||||
"Search": {
|
||||
"MaxResults": 100
|
||||
},
|
||||
"Content": {
|
||||
"Dir": "./content"
|
||||
"Textual": {
|
||||
"Dir": "./textual"
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
@ -1,6 +1,3 @@
|
||||
import Alpine from "alpinejs";
|
||||
import { apiHttp } from "~/assets/js/services/http.js";
|
||||
|
||||
const startingSlide = "#quick-picks-slide";
|
||||
|
||||
function initInteractiveElements() {
|
||||
@ -14,33 +11,14 @@ function initInteractiveElements() {
|
||||
});
|
||||
}
|
||||
|
||||
async function initConfigurationData() {
|
||||
const givenConfig = (await apiHttp.get("/SearchOutline/Filters")).data;
|
||||
const disabledShops = (await apiHttp.get("/SearchOutline/DisabledShops")).data;
|
||||
const availableShops = (await apiHttp.get("/Search/Available")).data;
|
||||
document.addEventListener("alpine:init", () => {
|
||||
Alpine.data("configuration", () => {
|
||||
const configuration = {
|
||||
maxPriceEnabled: givenConfig.enableUpperPrice,
|
||||
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: {},
|
||||
function initConfigVisuals() {
|
||||
const minRatingDisplay = document.querySelector("#configuration #min-rating-display");
|
||||
const minRatingSlider = document.querySelector("#configuration #min-rating");
|
||||
const updateDisplay = function () {
|
||||
minRatingDisplay.innerHTML = `Minimum rating: ${minRatingSlider.value}%`;
|
||||
};
|
||||
availableShops.forEach(shop => {
|
||||
configuration.shops[shop] = !disabledShops.includes(shop);
|
||||
});
|
||||
return configuration;
|
||||
});
|
||||
});
|
||||
minRatingSlider.addEventListener("input", updateDisplay);
|
||||
updateDisplay();
|
||||
}
|
||||
|
||||
function initSlides() {
|
||||
@ -68,9 +46,8 @@ function initSlides() {
|
||||
|
||||
async function main() {
|
||||
initInteractiveElements();
|
||||
await initConfigurationData();
|
||||
initConfigVisuals();
|
||||
initSlides();
|
||||
Alpine.start();
|
||||
}
|
||||
|
||||
main();
|
||||
|
BIN
Props/shops/Microsoft.Extensions.Logging.Abstractions.dll
Normal file
BIN
Props/shops/Microsoft.Extensions.Logging.Abstractions.dll
Normal file
Binary file not shown.
@ -10,8 +10,7 @@
|
||||
"dependencies": {
|
||||
"FuzzySharp": "2.0.2",
|
||||
"Newtonsoft.Json": "13.0.1",
|
||||
"Props.Shop.Framework": "1.0.0",
|
||||
"System.Linq.Async": "5.0.0"
|
||||
"Props.Shop.Framework": "1.0.0"
|
||||
},
|
||||
"runtime": {
|
||||
"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": {
|
||||
"runtime": {
|
||||
"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": {
|
||||
"dependencies": {
|
||||
"Microsoft.Extensions.Logging.Abstractions": "5.0.0"
|
||||
},
|
||||
"runtime": {
|
||||
"Props.Shop.Framework.dll": {}
|
||||
}
|
||||
@ -61,6 +63,13 @@
|
||||
"path": "fuzzysharp/2.0.2",
|
||||
"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": {
|
||||
"type": "package",
|
||||
"serviceable": true,
|
||||
@ -68,13 +77,6 @@
|
||||
"path": "newtonsoft.json/13.0.1",
|
||||
"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": {
|
||||
"type": "project",
|
||||
"serviceable": false,
|
||||
|
Binary file not shown.
BIN
Props/shops/Props.Shop.Framework.dll
Normal file
BIN
Props/shops/Props.Shop.Framework.dll
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user