mirror of
https://github.com/hmaxnl/SharpRSS.git
synced 2025-01-18 21:04:21 +01:00
Added guide load implmentation
This commit is contained in:
parent
898e649697
commit
65a964b7ee
|
@ -13,6 +13,7 @@ namespace SharpRss.Models
|
||||||
|
|
||||||
public string Name { get; set; } = string.Empty;
|
public string Name { get; set; } = string.Empty;
|
||||||
public string HexColor { get; set; }
|
public string HexColor { get; set; }
|
||||||
|
public int FeedCount { get; set; }
|
||||||
public string Icon { get; set; } = string.Empty;
|
public string Icon { get; set; } = string.Empty;
|
||||||
public string Id { get; set; }
|
public string Id { get; set; }
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,11 +36,18 @@ namespace SharpRss.Services
|
||||||
};
|
};
|
||||||
await using SqliteDataReader reader = await cmd.ExecuteReaderAsync();
|
await using SqliteDataReader reader = await cmd.ExecuteReaderAsync();
|
||||||
HashSet<GroupModel> groups = new HashSet<GroupModel>();
|
HashSet<GroupModel> groups = new HashSet<GroupModel>();
|
||||||
|
using SqliteCommand cmdFeedCount = new SqliteCommand($"SELECT COUNT(*) FROM {_feedTable} WHERE group_id=@groupId", _sqlConn);
|
||||||
while (reader.Read())
|
while (reader.Read())
|
||||||
{
|
{
|
||||||
groups.Add(new GroupModel()
|
cmdFeedCount.Parameters.Clear();
|
||||||
|
cmdFeedCount.Parameters.Add(new SqliteParameter("groupId", reader["id"].ToString()));
|
||||||
|
using SqliteDataReader countReader = await cmdFeedCount.ExecuteReaderAsync();
|
||||||
|
int count = countReader.Read() ? countReader.GetInt32(0) : 0;
|
||||||
|
|
||||||
|
groups.Add(new GroupModel()
|
||||||
{
|
{
|
||||||
Name = reader["name"].ToString(),
|
Name = reader["name"].ToString(),
|
||||||
|
FeedCount = count,
|
||||||
HexColor = reader["hex_color"].ToString(),
|
HexColor = reader["hex_color"].ToString(),
|
||||||
Icon = reader["icon"].ToString(),
|
Icon = reader["icon"].ToString(),
|
||||||
Id = reader["id"].ToString()
|
Id = reader["id"].ToString()
|
||||||
|
@ -95,15 +102,15 @@ namespace SharpRss.Services
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
// Feeds
|
// Feeds
|
||||||
public async Task<HashSet<FeedModel>> GetFeedsAsync(GroupModel? group = null)
|
public async Task<HashSet<FeedModel>> GetFeedsAsync(string? groupId = null)
|
||||||
{
|
{
|
||||||
HashSet<FeedModel> feeds = new HashSet<FeedModel>();
|
HashSet<FeedModel> feeds = new HashSet<FeedModel>();
|
||||||
_sqlConn.Open();
|
_sqlConn.Open();
|
||||||
using SqliteCommand cmd = new SqliteCommand(group != null ? $"SELECT * FROM {_feedTable} WHERE group_id=@groupid" : $"SELECT * FROM {_feedTable}", _sqlConn)
|
using SqliteCommand cmd = new SqliteCommand(groupId != null ? $"SELECT * FROM {_feedTable} WHERE group_id=@groupId" : $"SELECT * FROM {_feedTable}", _sqlConn)
|
||||||
{
|
{
|
||||||
Parameters =
|
Parameters =
|
||||||
{
|
{
|
||||||
new SqliteParameter("groupId", group?.Id == string.Empty ? null : group?.Id)
|
new SqliteParameter("groupId", groupId == null ? string.Empty : groupId)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
await using SqliteDataReader reader = await cmd.ExecuteReaderAsync();
|
await using SqliteDataReader reader = await cmd.ExecuteReaderAsync();
|
||||||
|
|
|
@ -15,10 +15,17 @@ namespace SharpRss.Services
|
||||||
{
|
{
|
||||||
public RssService()
|
public RssService()
|
||||||
{
|
{
|
||||||
SetupTestCategoriesAndFeedsAsync();
|
//SetupTestCategoriesAndFeedsAsync();
|
||||||
}
|
}
|
||||||
private readonly DatabaseService _dbService = new DatabaseService();
|
private readonly DatabaseService _dbService = new DatabaseService();
|
||||||
|
|
||||||
|
public async Task<HashSet<object>> GetItemsAsync()
|
||||||
|
{
|
||||||
|
HashSet<object> items = new HashSet<object>();
|
||||||
|
items.UnionWith(await GetGroupsAsync());
|
||||||
|
items.UnionWith(await GetUngroupedFeedsAsync());
|
||||||
|
return items;
|
||||||
|
}
|
||||||
public async Task<bool> CreateGroupAsync(GroupModel group) => await _dbService.SetGroupAsync(group);
|
public async Task<bool> CreateGroupAsync(GroupModel group) => await _dbService.SetGroupAsync(group);
|
||||||
public async Task<HashSet<GroupModel>> GetGroupsAsync() => await _dbService.GetGroupsAsync();
|
public async Task<HashSet<GroupModel>> GetGroupsAsync() => await _dbService.GetGroupsAsync();
|
||||||
|
|
||||||
|
@ -49,8 +56,8 @@ namespace SharpRss.Services
|
||||||
Log.Warning("No feed items added to feed: {FeedUrl}", feedModel.Url);
|
Log.Warning("No feed items added to feed: {FeedUrl}", feedModel.Url);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
public async Task<HashSet<FeedModel>> GetFeedsAsync(GroupModel? group = null) => await _dbService.GetFeedsAsync(group);
|
public async Task<HashSet<FeedModel>> GetFeedsAsync(GroupModel? group = null) => await _dbService.GetFeedsAsync(group?.Id);
|
||||||
public async Task<HashSet<FeedModel>> GetUngroupedFeedsAsync() => await _dbService.GetFeedsAsync(new GroupModel() { Id = "" });
|
public async Task<HashSet<FeedModel>> GetUngroupedFeedsAsync() => await _dbService.GetFeedsAsync("");
|
||||||
private async Task<int> AddFeedItems(IList<FeedItem> items, FeedModel feedModel)
|
private async Task<int> AddFeedItems(IList<FeedItem> items, FeedModel feedModel)
|
||||||
{
|
{
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
|
|
@ -1,33 +1,37 @@
|
||||||
|
using CodeHollow.FeedReader;
|
||||||
|
using MudBlazor;
|
||||||
using SharpRss.Models;
|
using SharpRss.Models;
|
||||||
using SharpRss.Services;
|
using SharpRss.Services;
|
||||||
|
using ToolQit;
|
||||||
|
|
||||||
namespace WebSharpRSS.Models
|
namespace WebSharpRSS.Models
|
||||||
{
|
{
|
||||||
public class TreeItemData
|
public class TreeItemData
|
||||||
{
|
{
|
||||||
public TreeItemData(GroupModel catModel, RssService rssService)
|
public TreeItemData(GroupModel groupModel)
|
||||||
{
|
{
|
||||||
_service = rssService;
|
GroupModel = groupModel;
|
||||||
CategoryModel = catModel;
|
Title = groupModel.Name;
|
||||||
}
|
Icon = groupModel.Icon == string.Empty ? Icons.Material.Filled.RssFeed : groupModel.Icon;
|
||||||
|
HasChild = groupModel.FeedCount > 0;
|
||||||
|
}
|
||||||
|
|
||||||
public TreeItemData(FeedModel feedModel, RssService rssService)
|
public TreeItemData(FeedModel feedModel)
|
||||||
{
|
{
|
||||||
_service = rssService;
|
|
||||||
FeedModel = feedModel;
|
FeedModel = feedModel;
|
||||||
}
|
Title = feedModel.Title;
|
||||||
|
FaviconUrl = string.Format(Caretaker.Settings["Paths"].GetString("FaviconResolveUrl"), feedModel.Url.Remove(feedModel.Url.IndexOf("http", StringComparison.Ordinal), feedModel.Url.IndexOf("://", StringComparison.Ordinal) + 3)); ;
|
||||||
private readonly RssService _service;
|
}
|
||||||
public readonly GroupModel? CategoryModel;
|
public readonly GroupModel? GroupModel;
|
||||||
public readonly FeedModel? FeedModel;
|
public readonly FeedModel? FeedModel;
|
||||||
|
|
||||||
|
public HashSet<TreeItemData>? Children { get; set; }
|
||||||
public string Title { get; set; } = string.Empty;
|
public string Title { get; set; } = string.Empty;
|
||||||
public bool IsSelected { get; set; }
|
public bool IsSelected { get; set; }
|
||||||
public string? Icon { get; set; }
|
public string? Icon { get; set; }
|
||||||
public string? FaviconUrl { get; set; }
|
public string? FaviconUrl { get; set; }
|
||||||
|
|
||||||
// Category
|
|
||||||
public bool HasChild { get; set; }
|
public bool HasChild { get; set; }
|
||||||
|
public bool Loading { get; set; }
|
||||||
public bool IsExpanded { get; set; }
|
public bool IsExpanded { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -9,17 +9,17 @@
|
||||||
@inject FeedStateContainer _stateContainer;
|
@inject FeedStateContainer _stateContainer;
|
||||||
@inject RssService _rssService
|
@inject RssService _rssService
|
||||||
|
|
||||||
@*<MudStack Spacing="2">
|
<MudStack Spacing="2">
|
||||||
<MudTreeView Items="_guideItems" @bind-SelectedValue="SelectedItem" Hover="true">
|
<MudTreeView Items="_guideItems" @bind-SelectedValue="SelectedItem" Hover="true">
|
||||||
<ItemTemplate>
|
<ItemTemplate>
|
||||||
<MudTreeViewItem @bind-Expanded="@context.IsExpanded" Items="@context.Feeds" Value="@context" CanExpand="@context.HasChild" @onclick="ItemClicked">
|
<MudTreeViewItem @bind-Expanded="@context.IsExpanded" Value="@context" Items="@context.Children" CanExpand="@context.HasChild" @onclick="ItemClicked">
|
||||||
<Content>
|
<Content>
|
||||||
<div style="display: grid; grid-template-columns: 1fr auto; align-items: center; width: 100%">
|
<div style="display: grid; grid-template-columns: 1fr auto; align-items: center; width: 100%">
|
||||||
<div style="justify-self: start;" class="d-flex align-center">
|
<div style="justify-self: start;" class="d-flex align-center">
|
||||||
<MudTreeViewItemToggleButton @bind-Expanded="@context.IsExpanded" Visible="@context.HasChild" LoadingIconColor="Color.Info"/>
|
<MudTreeViewItemToggleButton @bind-Expanded="@context.IsExpanded" Loading="@context.Loading" Visible="@context.HasChild" LoadingIconColor="Color.Info" />
|
||||||
@if (context.FaviconUrl.IsNullEmptyWhiteSpace() && context.Icon != null)
|
@if (context.FaviconUrl == null && context.Icon != null)
|
||||||
{
|
{
|
||||||
<MudIcon Icon="@context.Icon" Style="@($"color:{context.CategoryModel?.HexColor ?? Theme.Palette.Primary.Value}")"/>
|
<MudIcon Icon="@context.Icon" Style="@($"color:{context.GroupModel?.HexColor ?? Theme.Palette.Primary.Value}")"/>
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -28,19 +28,19 @@
|
||||||
<MudText Class="ml-2">@context.Title</MudText>
|
<MudText Class="ml-2">@context.Title</MudText>
|
||||||
</div>
|
</div>
|
||||||
<div style="justify-self: end;">
|
<div style="justify-self: end;">
|
||||||
<MudText Color="Color.Dark" Style="justify-self: end;" Typo="Typo.caption">@context.FeeditemCount</MudText>
|
@*<MudText Color="Color.Dark" Style="justify-self: end;" Typo="Typo.caption">@context.FeeditemCount</MudText>*@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Content>
|
</Content>
|
||||||
</MudTreeViewItem>
|
</MudTreeViewItem>
|
||||||
</ItemTemplate>
|
</ItemTemplate>
|
||||||
</MudTreeView>
|
</MudTreeView>
|
||||||
</MudStack>*@
|
</MudStack>
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
private MudTheme Theme = new MudTheme();
|
private MudTheme Theme = new MudTheme();
|
||||||
private readonly HashSet<TreeItemData> _guideItems = new HashSet<TreeItemData>();
|
private readonly HashSet<TreeItemData> _guideItems = new HashSet<TreeItemData>();
|
||||||
/*private TreeItemData? _selectedItem;
|
private TreeItemData? _selectedItem;
|
||||||
private TreeItemData? SelectedItem
|
private TreeItemData? SelectedItem
|
||||||
{
|
{
|
||||||
get => _selectedItem;
|
get => _selectedItem;
|
||||||
|
@ -49,18 +49,26 @@
|
||||||
_selectedItem = value;
|
_selectedItem = value;
|
||||||
ItemClicked();
|
ItemClicked();
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
private void ItemClicked()
|
private void ItemClicked()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
//private async void ExpandedClicked(TreeItemData treeItemData)
|
||||||
|
//{
|
||||||
|
// treeItemData.Loading = true;
|
||||||
|
// var groupedItems = await _rssService.GetFeedsAsync(treeItemData.GroupModel);
|
||||||
|
// treeItemData.Children = ModelToTreeItem(groupedItems);
|
||||||
|
// treeItemData.Loading = false;
|
||||||
|
//}
|
||||||
protected override async void OnInitialized()
|
protected override async void OnInitialized()
|
||||||
{
|
{
|
||||||
Log.Verbose("Loading guide data...");
|
Log.Verbose("Loading guide data...");
|
||||||
/*HashSet<object> items = await _rssService.GetAllUnsortedAsync();
|
HashSet<object> items = await _rssService.GetItemsAsync();
|
||||||
_guideItems.UnionWith(items.Select(x => x is CategoryModel model ? new TreeItemData(model, _rssService) : x is FeedModel feedModel ? new TreeItemData(feedModel, _rssService) : throw new ArgumentException("Arg x is invalid!")));*/
|
_guideItems.UnionWith(ModelToTreeItem(items));
|
||||||
|
|
||||||
StateHasChanged();
|
StateHasChanged();
|
||||||
Log.Verbose("Guide initialized!");
|
Log.Verbose("Guide initialized!");
|
||||||
}
|
}
|
||||||
|
private HashSet<TreeItemData> ModelToTreeItem<T>(HashSet<T> model) => model.Select(x => x is GroupModel model ? new TreeItemData(model) : x is FeedModel feedModel ? new TreeItemData(feedModel) : throw new ArgumentException("Item arg is invalid!")).ToHashSet();
|
||||||
}
|
}
|
|
@ -8,6 +8,13 @@
|
||||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Remove="Core\**" />
|
||||||
|
<Content Remove="Core\**" />
|
||||||
|
<EmbeddedResource Remove="Core\**" />
|
||||||
|
<None Remove="Core\**" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="MudBlazor" Version="6.2.2" />
|
<PackageReference Include="MudBlazor" Version="6.2.2" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -16,8 +23,4 @@
|
||||||
<ProjectReference Include="..\SharpRss\SharpRss.csproj" />
|
<ProjectReference Include="..\SharpRss\SharpRss.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Folder Include="Core" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user