diff --git a/SharpRss/DbAccess.cs b/SharpRss/DbAccess.cs index 1ba27f2..813a6c2 100644 --- a/SharpRss/DbAccess.cs +++ b/SharpRss/DbAccess.cs @@ -43,9 +43,9 @@ namespace SharpRss Id = reader["id"].ToString(), Name = reader["name"].ToString(), HexColor = reader["hex_color"].ToString(), - FeedCount = 0, // Not implemented. Icon = reader["icon"].ToString() }; + categoryModel.FeedCount = await dbc.ExecuteScalarAsync($"SELECT COUNT(*) FROM feed WHERE category_id=@CatId", new { CatId = categoryModel.Id }); categories.Add(categoryModel); } return categories; @@ -125,7 +125,7 @@ namespace SharpRss await using SqliteConnection dbc = new SqliteConnection(ConnectionString); dbc.Open(); HashSet feeds = new HashSet(); - await using DbDataReader reader = await dbc.ExecuteReaderAsync(categoryIds == null ? "SELECT * FROM feed WHERE category_id == ''" : "SELECT * FROM feed WHERE category_id IN(@CatIds)", new { CatIds = categoryIds }); + await using DbDataReader reader = await dbc.ExecuteReaderAsync(categoryIds == null ? "SELECT * FROM feed" : "SELECT * FROM feed WHERE category_id IN(@CatIds)", new { CatIds = categoryIds }); while (await reader.ReadAsync()) { FeedModel feedModel = new FeedModel() diff --git a/SharpRss/Models/CategoryModel.cs b/SharpRss/Models/CategoryModel.cs index 6ab5ea7..e24a925 100644 --- a/SharpRss/Models/CategoryModel.cs +++ b/SharpRss/Models/CategoryModel.cs @@ -6,17 +6,12 @@ namespace SharpRss.Models { public class CategoryModel { - private string _id = string.Empty; - public string Id + public CategoryModel() { - get - { - if (_id.IsNullEmptyWhiteSpace()) - _id = Guid.NewGuid().ToString(); - return _id; - } - set => _id = value; + Id = Guid.NewGuid().ToString(); } + /*private string _id = string.Empty;*/ + public string Id { get; set; } public string Name { get; set; } = string.Empty; private string _hexColor = string.Empty; public string HexColor diff --git a/SharpRss/Services/RssService.cs b/SharpRss/Services/RssService.cs index 0fc0f94..a61663d 100644 --- a/SharpRss/Services/RssService.cs +++ b/SharpRss/Services/RssService.cs @@ -70,8 +70,8 @@ namespace SharpRss.Services var feeds = await GetFeedsAsync(); } - public async Task> GetFeedsAsync(string? groupId = null) => await DbAccess.GetFeedsAsync(); - public async Task> GetUngroupedFeedsAsync() => await DbAccess.GetFeedsAsync(); + public async Task> GetFeedsAsync(string? categoryId = null) => await DbAccess.GetFeedsAsync(categoryId == null ? null : new[]{ categoryId }); + public async Task> GetUngroupedFeedsAsync() => await DbAccess.GetFeedsAsync(new []{""}); public async Task> GetFeedItemsAsync(string feedId, string? groupId = null) => await GetFeedItemsFromFeedsAsync(new[] { feedId }, groupId); public async Task> GetFeedItemsFromFeedsAsync(string[] feedIds, string? groupId = null) @@ -94,7 +94,11 @@ namespace SharpRss.Services } private async void SetupTestGroupsAndFeedsAsync() { - /*await AddSubscriptionAsync("https://www.nu.nl/rss/Algemeen");*/ + CategoryModel NewsCat = new CategoryModel() { Name = "News" }; + await AddSubscriptionAsync("https://www.nu.nl/rss/Algemeen", NewsCat); + await AddSubscriptionAsync("https://www.nu.nl/rss/Economie", NewsCat); + await AddSubscriptionAsync("http://fedoramagazine.org/feed/"); + await AddSubscriptionAsync("https://itsfoss.com/feed"); //TODO: Make multiple adding of feed to a transaction, now throws an exception. /*var groupRes = await CreateGroupAsync(new GroupModel() { Name = "Test" }); groupRes = await CreateGroupAsync(new GroupModel() { Name = "News" }); diff --git a/SharpRss/SyndicationManager.cs b/SharpRss/SyndicationManager.cs index d24a882..85726a0 100644 --- a/SharpRss/SyndicationManager.cs +++ b/SharpRss/SyndicationManager.cs @@ -69,7 +69,7 @@ namespace SharpRss container.FeedModel.Description = rssFeed.Channel.Description ?? string.Empty; container.FeedModel.Language = rssFeed.Channel.Language?.ToString() ?? string.Empty; container.FeedModel.Copyright = rssFeed.Channel.Copyright ?? string.Empty; - container.FeedModel.PublicationDate = rssFeed.Channel.LastBuildDate is not { Ticks: > 0 } ? DateTimeOffset.MinValue : new DateTimeOffset(rssFeed.Channel.LastBuildDate); + container.FeedModel.PublicationDate = rssFeed.Channel.LastBuildDate is not { Ticks: > 0 } ? new DateTimeOffset(rssFeed.Channel.LastBuildDate) : DateTimeOffset.MinValue; container.FeedModel.Categories = rssFeed.Channel.Categories?.Select(x => x.Value).ToArray() ?? Array.Empty(); container.FeedModel.ImageUrl = rssFeed.Channel.Image?.Url.ToString() ?? string.Empty; foreach (var rssItem in rssFeed.Channel.Items) @@ -82,7 +82,7 @@ namespace SharpRss Title = rssItem.Title ?? string.Empty, Description = rssItem.Description ?? string.Empty, Link = rssItem.Link?.ToString() ?? string.Empty, - PublishingDate = rssItem.PublicationDate is not { Ticks: <= 0 } ? DateTimeOffset.MinValue : new DateTimeOffset(rssItem.PublicationDate), + PublishingDate = rssItem.PublicationDate is not { Ticks: <= 0 } ? new DateTimeOffset(rssItem.PublicationDate) : DateTimeOffset.MinValue, Authors = rssItem.Author != null ? new []{ rssItem.Author } : Array.Empty(), Categories = rssItem.Categories?.Select(x => x.Value).ToArray() ?? Array.Empty(), Content = rssItem.Extensions?.Where(x => x is SiteSummaryContentSyndicationExtension).Select(x => (x as SiteSummaryContentSyndicationExtension)?.Context.Encoded).FirstOrDefault() ?? string.Empty, @@ -113,8 +113,8 @@ namespace SharpRss Title = entry.Title?.Content ?? string.Empty, Description = entry.Summary?.Content ?? string.Empty, Link = entry.Id?.Uri.ToString() ?? string.Empty, - LastUpdated = entry.UpdatedOn is not { Ticks: <= 0 } ? DateTimeOffset.MinValue : new DateTimeOffset(entry.UpdatedOn), - PublishingDate = entry.PublishedOn is not { Ticks: <= 0 } ? DateTimeOffset.MinValue : new DateTimeOffset(entry.PublishedOn), + LastUpdated = entry.UpdatedOn is not { Ticks: <= 0 } ? new DateTimeOffset(entry.UpdatedOn) : DateTimeOffset.MinValue, + PublishingDate = entry.PublishedOn is not { Ticks: <= 0 } ? new DateTimeOffset(entry.PublishedOn) : DateTimeOffset.MinValue, Authors = entry.Authors?.Select(auth => auth.Name).ToArray() ?? Array.Empty(), Categories = entry.Categories?.Select(cat => cat.Label).ToArray() ?? Array.Empty(), Content = entry.Content?.Content ?? string.Empty diff --git a/WebSharpRSS/Models/TreeItemData.cs b/WebSharpRSS/Models/TreeItemData.cs index 08f765e..b8c99e3 100644 --- a/WebSharpRSS/Models/TreeItemData.cs +++ b/WebSharpRSS/Models/TreeItemData.cs @@ -1,5 +1,7 @@ using System; using System.Collections.Generic; +using System.Configuration; +using System.Linq; using MudBlazor; using SharpRss.Models; using ToolQit; @@ -8,12 +10,12 @@ namespace WebSharpRSS.Models { public class TreeItemData { - public TreeItemData(CategoryModel groupModel) + public TreeItemData(CategoryModel categoryModel) { - GroupModel = groupModel; - Title = groupModel.Name; - Icon = groupModel.Icon == string.Empty ? Icons.Material.Filled.RssFeed : groupModel.Icon; - HasChild = groupModel.FeedCount > 0; + CategoryModel = categoryModel; + Title = categoryModel.Name; + Icon = categoryModel.Icon == string.Empty ? Icons.Material.Filled.RssFeed : categoryModel.Icon; + HasChildren = CategoryModel.FeedCount > 0; } public TreeItemData(FeedModel feedModel) @@ -23,7 +25,7 @@ namespace WebSharpRSS.Models if (FeedModel.OriginalUrl == null) return; FaviconUrl = string.Format(Caretaker.Settings["Paths"].GetString("FaviconResolveUrl"), new Uri(FeedModel.OriginalUrl).Host); } - public readonly CategoryModel? GroupModel; + public readonly CategoryModel? CategoryModel; public readonly FeedModel? FeedModel; public HashSet? Children { get; set; } @@ -31,7 +33,7 @@ namespace WebSharpRSS.Models public bool IsSelected { get; set; } public string? Icon { get; set; } public string? FaviconUrl { get; set; } - public bool HasChild { get; set; } + public bool HasChildren { get; set; } public bool Loading { get; set; } public bool IsExpanded { get; set; } } diff --git a/WebSharpRSS/Pages/List.razor b/WebSharpRSS/Pages/List.razor index dbc1268..c2d2fd4 100644 --- a/WebSharpRSS/Pages/List.razor +++ b/WebSharpRSS/Pages/List.razor @@ -33,17 +33,17 @@ } private string? _fid; [Parameter] - [SupplyParameterFromQuery(Name = "gid")] - public string? Gid + [SupplyParameterFromQuery(Name = "cid")] + public string? Cid { - get => _gid; + get => _cid; set { - _gid = value; + _cid = value; LoadItems(); } } - private string? _gid; + private string? _cid; HashSet items = new HashSet(); bool _isLoading = true; private async void LoadItems() @@ -54,9 +54,9 @@ var fItems = await _rssService.GetFeedItemsAsync(Fid); items = fItems.Select(x => FeedItemData.FromModel(x)).OrderBy(x => x.PublishingDate).Reverse().ToHashSet(); } - else if (Gid != null) + else if (Cid != null) { - var feeds = await _rssService.GetFeedsAsync(Gid); + var feeds = await _rssService.GetFeedsAsync(Cid == string.Empty ? null : Cid); var feedIds = feeds.Select(x => x.OriginalUrl); var feedItems = await _rssService.GetFeedItemsFromFeedsAsync(feedIds.ToArray()); items = feedItems.Select(x => FeedItemData.FromModel(x)).OrderBy(x => x.PublishingDate).Reverse().ToHashSet(); diff --git a/WebSharpRSS/Shared/SideGuide.razor b/WebSharpRSS/Shared/SideGuide.razor index 7704dac..c5d0ed6 100644 --- a/WebSharpRSS/Shared/SideGuide.razor +++ b/WebSharpRSS/Shared/SideGuide.razor @@ -11,14 +11,14 @@ - +
- + @if (context.FaviconUrl == null && context.Icon != null) { - + } else { @@ -53,15 +53,15 @@ { _navigation.NavigateTo($"/list?fid={_selectedItem.FeedModel.OriginalUrl}"); } - else if (_selectedItem.GroupModel != null) + else if (_selectedItem.CategoryModel != null) { - _navigation.NavigateTo($"/list?gid={_selectedItem.GroupModel.Id}"); + _navigation.NavigateTo($"/list?cid={_selectedItem.CategoryModel.Id}"); } } private async void ExpandedChanged(TreeItemData treeItemData) { treeItemData.Loading = true; - var groupedItems = await _rssService.GetFeedsAsync(treeItemData.GroupModel?.Id); + var groupedItems = await _rssService.GetFeedsAsync(treeItemData.CategoryModel?.Id); treeItemData.Children = ModelToTreeItem(groupedItems); treeItemData.IsExpanded = !treeItemData.IsExpanded; treeItemData.Loading = false; @@ -70,6 +70,7 @@ protected override async void OnInitialized() { Log.Verbose("Loading guide data..."); + _guideItems.Add(new TreeItemData(new CategoryModel() { Name = "All", Icon = Icons.Material.Filled.Home, HexColor = Colors.Blue.Accent1, Id = string.Empty })); HashSet items = await _rssService.GetCategoriesFeedsAsync(); _guideItems.UnionWith(ModelToTreeItem(items)); diff --git a/WebSharpRSS/sharp_rss.sqlite b/WebSharpRSS/sharp_rss.sqlite index d1deae3..c6deccd 100644 Binary files a/WebSharpRSS/sharp_rss.sqlite and b/WebSharpRSS/sharp_rss.sqlite differ