From 1384f600007239aa54898ef5aa444e0f5583d6e2 Mon Sep 17 00:00:00 2001 From: jibedoubleve Date: Thu, 29 Mar 2018 10:23:45 +0100 Subject: [PATCH] Dev.1.4.0 (#15) Release V.1.4.0 * Close #14 --- .../Data/LogFilterExtensions.cs | 24 ++++++- .../Properties/Messages.Designer.cs | 27 +++++++ .../Properties/Messages.resx | 9 +++ .../ViewModels/ShellViewModel.cs | 7 +- .../Views/ShellView.xaml | 3 +- .../Views/ShellView.xaml.cs | 72 ++++++++++++++++--- Version.cs | 4 +- build/setup.iss | 2 +- 8 files changed, 132 insertions(+), 16 deletions(-) diff --git a/Probel.JsonReader.Business/Data/LogFilterExtensions.cs b/Probel.JsonReader.Business/Data/LogFilterExtensions.cs index df0514d..b2e020c 100644 --- a/Probel.JsonReader.Business/Data/LogFilterExtensions.cs +++ b/Probel.JsonReader.Business/Data/LogFilterExtensions.cs @@ -9,6 +9,16 @@ public static class LogFilterExtensions { #region Methods + public static IEnumerable GetCategories(this IEnumerable models) + { + var result = (from m in models select m.Logger) + .OrderBy(e => e) + .Distinct() + .ToList(); + return result; + + } + public static IEnumerable Filter(this IEnumerable models, decimal minutes, IFilter filter) { var levels = new List(); @@ -41,8 +51,20 @@ where levels.Contains(l.Level) : result.OrderByDescending(e => e.Time); } + public static IEnumerable Filter(this IEnumerable models, IEnumerable categories, IFilter filter) + { + var result = (from m in models + where categories.Contains(m.Logger) + select m) + .ToList(); + + return (filter.IsSortAscending) + ? result.OrderBy(e => e.Time) + : result.OrderByDescending(e => e.Time); + } + public static async Task> FilterAsync(this IEnumerable models, decimal minutes, IFilter filter) - { + { return await Task.Run(() => Filter(models, minutes, filter)); } diff --git a/Probel.JsonReader.Presentation/Properties/Messages.Designer.cs b/Probel.JsonReader.Presentation/Properties/Messages.Designer.cs index 70ed57e..104d2d4 100644 --- a/Probel.JsonReader.Presentation/Properties/Messages.Designer.cs +++ b/Probel.JsonReader.Presentation/Properties/Messages.Designer.cs @@ -123,6 +123,33 @@ public static string Header_Time { } } + /// + /// Looks up a localized string similar to C_ategories. + /// + public static string Menu_Categories { + get { + return ResourceManager.GetString("Menu_Categories", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to All. + /// + public static string Menu_Category_All { + get { + return ResourceManager.GetString("Menu_Category_All", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to None. + /// + public static string Menu_Category_None { + get { + return ResourceManager.GetString("Menu_Category_None", resourceCulture); + } + } + /// /// Looks up a localized string similar to _Columns. /// diff --git a/Probel.JsonReader.Presentation/Properties/Messages.resx b/Probel.JsonReader.Presentation/Properties/Messages.resx index b856203..dde3f76 100644 --- a/Probel.JsonReader.Presentation/Properties/Messages.resx +++ b/Probel.JsonReader.Presentation/Properties/Messages.resx @@ -210,4 +210,13 @@ (+) + + C_ategories + + + All + + + None + \ No newline at end of file diff --git a/Probel.JsonReader.Presentation/ViewModels/ShellViewModel.cs b/Probel.JsonReader.Presentation/ViewModels/ShellViewModel.cs index c6f84ed..6bcc90b 100644 --- a/Probel.JsonReader.Presentation/ViewModels/ShellViewModel.cs +++ b/Probel.JsonReader.Presentation/ViewModels/ShellViewModel.cs @@ -67,6 +67,8 @@ public decimal FilterMinutes set => SetProperty(ref _filterMinutes, value, nameof(FilterMinutes)); } + internal void FilterCategories(IEnumerable categories) => FillLogs(BufferLogs.Filter(categories, Settings)); + public ObservableCollection Logs { get => _logs; @@ -75,6 +77,8 @@ public ObservableCollection Logs public ICommand OpenCommand { get; } + internal async Task OpenFileAsync(string path) => await Task.Run(() => Open(path)); + [Dependency] public SettingsViewModel Settings { @@ -126,6 +130,7 @@ public async Task Load() } + internal IEnumerable GetCategories() => BufferLogs.GetCategories(); private bool CanFilter(string arg) { @@ -205,7 +210,7 @@ private void AddFileInHistory(string filePath) where f == filePath select f).Count() > 0; - if (!doubloon) { Settings.FileHistory.Add(filePath);} + if (!doubloon) { Settings.FileHistory.Add(filePath); } } private void SetItemsCount() => StatusItemsCount = string.Format(Messages.Status_xxItems, Logs.Count); diff --git a/Probel.JsonReader.Presentation/Views/ShellView.xaml b/Probel.JsonReader.Presentation/Views/ShellView.xaml index ae9b4bf..6a34dbe 100644 --- a/Probel.JsonReader.Presentation/Views/ShellView.xaml +++ b/Probel.JsonReader.Presentation/Views/ShellView.xaml @@ -35,7 +35,7 @@ @@ -85,6 +85,7 @@ Header="{x:Static m:Messages.MenuItem_NoFilter}" IsChecked="{Binding FilterMinutes, Converter={StaticResource MinutesFilterToBooleanConverter}, ConverterParameter=0}" /> + public partial class ShellView : Window { + #region Fields + private readonly ILogService _logger; + + #endregion Fields + #region Constructors public ShellView(ILogService logger) @@ -34,7 +39,21 @@ public ShellView(ILogService logger) #region Methods - private void OnClickHistory(object sender, RoutedEventArgs e) => RefreshFileHistory(); + private void OnCategoryClick(object sender, RoutedEventArgs e) + { + if (sender is MenuItem mi) + { + mi.IsChecked = !mi.IsChecked; + + var categories = (from m in _menuCategories.Items.Cast() + where m.IsChecked == true + select (string)m.Header).ToList(); + + ViewModel.FilterCategories(categories); + } + } + + private void OnClickHistory(object sender, RoutedEventArgs e) => Refresh(); private void OnFileMenuOpenMenu(object sender, RoutedEventArgs e) { @@ -61,19 +80,20 @@ private void OnShowColumn(object sender, RoutedEventArgs e) mi.IsChecked = !mi.IsChecked; } } + private async void OnWindowLoad(object sender, RoutedEventArgs e) { await ViewModel.Load(); - RefreshFileHistory(); + Refresh(); } - private void OpenFile(string path) + private async void OpenFile(string path) { if (File.Exists(path)) { ViewModel.Title = path; - ViewModel.OpenCommand.TryExecute(path); - RefreshFileHistory(); + await ViewModel.OpenFileAsync(path); + Refresh(); } else { @@ -87,25 +107,57 @@ private void OpenFile(string path) if (toRemove != null) { ViewModel.Settings.FileHistory.Remove(toRemove); - RefreshFileHistory(); + Refresh(); } } } + private void RefreshCategories() + { + _menuCategories.Items.Clear(); + var categories = ViewModel.GetCategories(); + + for (var i = 0; i < categories.Count(); i++) + { + var btn = new MenuItem() + { + Header = categories.ElementAt(i), + IsChecked = true + }; + btn.Click += OnCategoryClick; + + _menuCategories.Items.Insert(i, btn); + } + } + private void Refresh() + { + RefreshFileHistory(); + RefreshCategories(); + } private void RefreshFileHistory() { - _buttonHistory.Items.Clear(); - var history = ViewModel.Settings.FileHistory.OrderBy(i => i).ToList(); + _menuHistory.Items.Clear(); + var history = ViewModel.Settings.FileHistory.OrderBy(h => h).ToList(); + var i = 0; - for (var i = 0; i < history.Count(); i++) + for (i = 0; i < history.Count(); i++) { var btn = new MenuItem() { Header = history[i] }; btn.Click += OnMenuClick; - _buttonHistory.Items.Insert(i, btn); + _menuHistory.Items.Insert(i, btn); } + + //var btn_all = new MenuItem() { Header = Messages.Menu_Category_All }; + + //var btn_none = new MenuItem() { Header = Messages.Menu_Category_None }; + + //_menuHistory.Items.Insert(++i, btn_all); + //_menuHistory.Items.Insert(++i, btn_none); + } #endregion Methods + } } \ No newline at end of file diff --git a/Version.cs b/Version.cs index 93acf8d..f2517de 100644 --- a/Version.cs +++ b/Version.cs @@ -11,5 +11,5 @@ // [assembly: AssemblyVersion("1.0.*")] using System.Reflection; -[assembly: AssemblyVersion("1.3.0")] -[assembly: AssemblyFileVersion("1.3.0")] +[assembly: AssemblyVersion("1.4.0")] +[assembly: AssemblyFileVersion("1.4.0")] diff --git a/build/setup.iss b/build/setup.iss index 0d71fdc..39f7869 100644 --- a/build/setup.iss +++ b/build/setup.iss @@ -2,7 +2,7 @@ ; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES! #define MyAppName "Log Reader" -#define MyAppVersion "1.3.0" +#define MyAppVersion "1.4.0" #define MyAppPublisher "Probel" #define MyAppURL "http://www.probel.xyz" #define MyAppExeName "Probel.JsonReader.Presentation.exe"