diff --git a/app/Desktop/Common/NumberValueConverter.cs b/app/Desktop/Common/NumberValueConverter.cs index 663a3e1..41b83d0 100644 --- a/app/Desktop/Common/NumberValueConverter.cs +++ b/app/Desktop/Common/NumberValueConverter.cs @@ -5,7 +5,7 @@ using Avalonia.Data.Converters; namespace DHT.Desktop.Common { sealed class NumberValueConverter : IValueConverter { public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) { - return string.Format(Program.Culture, "{0:n0}", value); + return value == null ? "-" : string.Format(Program.Culture, "{0:n0}", value); } public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) { diff --git a/app/Desktop/Main/Pages/ViewerPageModel.cs b/app/Desktop/Main/Pages/ViewerPageModel.cs index 72d5686..57cbc14 100644 --- a/app/Desktop/Main/Pages/ViewerPageModel.cs +++ b/app/Desktop/Main/Pages/ViewerPageModel.cs @@ -35,7 +35,7 @@ namespace DHT.Desktop.Main.Pages { private readonly IDatabaseFile db; private bool isPageVisible = false; - + [Obsolete("Designer")] public ViewerPageModel() : this(null!, DummyDatabaseFile.Instance) {} @@ -46,7 +46,6 @@ namespace DHT.Desktop.Main.Pages { FilterModel = new FilterPanelModel(window, db); FilterModel.FilterPropertyChanged += OnFilterPropertyChanged; db.Statistics.PropertyChanged += OnDbStatisticsChanged; - UpdateStatistics(); } public void Dispose() { @@ -73,13 +72,17 @@ namespace DHT.Desktop.Main.Pages { } private void UpdateStatistics() { - ExportedMessageText = "Will export " + db.CountMessages(FilterModel.CreateFilter()).Format() + " out of " + db.Statistics.TotalMessages.Format() + " message(s)."; + var filter = FilterModel.CreateFilter(); + var allMessagesCount = db.Statistics.TotalMessages?.Format() ?? "?"; + var filteredMessagesCount = filter.IsEmpty ? allMessagesCount : db.CountMessages(filter).Format(); + + ExportedMessageText = "Will export " + filteredMessagesCount + " out of " + allMessagesCount + " message(s)."; OnPropertyChanged(nameof(ExportedMessageText)); } private async Task GenerateViewerContents() { string json = ViewerJsonExport.Generate(db, FilterModel.CreateFilter()); - + string index = await Resources.ReadTextAsync("Viewer/index.html"); string viewer = index.Replace("/*[JS]*/", await Resources.ReadJoinedAsync("Viewer/scripts/", '\n')) .Replace("/*[CSS]*/", await Resources.ReadJoinedAsync("Viewer/styles/", '\n')) diff --git a/app/Server/Data/Filters/MessageFilter.cs b/app/Server/Data/Filters/MessageFilter.cs index 8b2f0f4..efddcc1 100644 --- a/app/Server/Data/Filters/MessageFilter.cs +++ b/app/Server/Data/Filters/MessageFilter.cs @@ -3,11 +3,17 @@ using System.Collections.Generic; namespace DHT.Server.Data.Filters { public sealed class MessageFilter { - public DateTime? StartDate { get; set; } - public DateTime? EndDate { get; set; } + public DateTime? StartDate { get; set; } = null; + public DateTime? EndDate { get; set; } = null; public HashSet? ChannelIds { get; set; } = null; public HashSet? UserIds { get; set; } = null; public HashSet? MessageIds { get; set; } = null; + + public bool IsEmpty => StartDate == null && + EndDate == null && + ChannelIds == null && + UserIds == null && + MessageIds == null; } } diff --git a/app/Server/Database/DatabaseStatistics.cs b/app/Server/Database/DatabaseStatistics.cs index 2a70d2a..abd4dc3 100644 --- a/app/Server/Database/DatabaseStatistics.cs +++ b/app/Server/Database/DatabaseStatistics.cs @@ -5,7 +5,7 @@ namespace DHT.Server.Database { private long totalServers; private long totalChannels; private long totalUsers; - private long totalMessages; + private long? totalMessages; public long TotalServers { get => totalServers; @@ -22,7 +22,7 @@ namespace DHT.Server.Database { internal set => Change(ref totalUsers, value); } - public long TotalMessages { + public long? TotalMessages { get => totalMessages; internal set => Change(ref totalMessages, value); } diff --git a/app/Server/Database/Sqlite/SqliteDatabaseFile.cs b/app/Server/Database/Sqlite/SqliteDatabaseFile.cs index be8e742..f076b1a 100644 --- a/app/Server/Database/Sqlite/SqliteDatabaseFile.cs +++ b/app/Server/Database/Sqlite/SqliteDatabaseFile.cs @@ -46,11 +46,13 @@ namespace DHT.Server.Database.Sqlite { this.Path = path; this.Statistics = new DatabaseStatistics(); - using var conn = pool.Take(); - UpdateServerStatistics(conn); - UpdateChannelStatistics(conn); - UpdateUserStatistics(conn); - UpdateMessageStatistics(conn); + using (var conn = pool.Take()) { + UpdateServerStatistics(conn); + UpdateChannelStatistics(conn); + UpdateUserStatistics(conn); + } + + messageStatisticsThread.RequestUpdate(); } public void Dispose() {