From 75d9c21cb654b410fd3b68895932a8706a94835d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dongmin=20Jang=20=28=EC=9E=A5=EB=8F=99=EB=AF=BC=29?= Date: Mon, 24 Jun 2024 12:55:32 +0900 Subject: [PATCH] Update project and workflow settings --- .../AppUnitTest.cs | 8 +- .../Helpers/FileHelperUnitTest.cs | 17 +++ src/Apps/Corathing.Organizer/App.xaml.cs | 8 +- .../Models/ProjectContext.cs | 17 ++- .../Models/ProjectSettingsContext.cs | 36 ++++++ .../Corathing.Organizer/Natives/FileHelper.cs | 6 + .../Services/AppStateService.cs | 84 ++++++++++++- .../Services/ApplicationService.cs | 12 ++ .../Services/NavigationService.cs | 47 +++++++ .../Utils/ZBase32Encoder.cs | 55 +++++++++ .../ViewModels/DashboardViewModel.cs | 15 ++- .../ViewModels/ProjectSettingsViewModel.cs | 116 +++++++++++++++++- .../Views/OrganizerSettingsView.xaml.cs | 1 + .../Views/ProjectSettingsView.xaml | 88 +++++++++++-- .../Views/ProjectSettingsView.xaml.cs | 3 +- .../Views/WidgetSettingsView.xaml.cs | 5 +- .../Bases/AppDashboardState.cs | 27 +++- .../Bases/Interfaces/IProjectState.cs | 4 +- .../Corathing.Contracts/Bases/ProjectState.cs | 22 +--- .../Services/IAppStateService.cs | 17 ++- .../Services/IApplicationService.cs | 3 + .../Services/INavigationService.cs | 89 ++++++++++++++ .../Corathing.UI.WPF/Themes/Generic.xaml | 2 +- 23 files changed, 628 insertions(+), 54 deletions(-) create mode 100644 src/Apps/Corathing.Organizer.UnitTests/Helpers/FileHelperUnitTest.cs create mode 100644 src/Apps/Corathing.Organizer/Models/ProjectSettingsContext.cs create mode 100644 src/Apps/Corathing.Organizer/Services/NavigationService.cs create mode 100644 src/Apps/Corathing.Organizer/Utils/ZBase32Encoder.cs create mode 100644 src/Shared/Corathing.Contracts/Services/INavigationService.cs diff --git a/src/Apps/Corathing.Organizer.UnitTests/AppUnitTest.cs b/src/Apps/Corathing.Organizer.UnitTests/AppUnitTest.cs index 3194ac2..b0cd034 100644 --- a/src/Apps/Corathing.Organizer.UnitTests/AppUnitTest.cs +++ b/src/Apps/Corathing.Organizer.UnitTests/AppUnitTest.cs @@ -47,10 +47,10 @@ private static async void _internalRunApplicationAction(Action acti [TestMethod] public void App_ConfigureServices_Test() { - var thread = RunApplicationAction(application => - { + //var thread = RunApplicationAction(application => + //{ - }); - thread.Join(); + //}); + //thread.Join(); } } diff --git a/src/Apps/Corathing.Organizer.UnitTests/Helpers/FileHelperUnitTest.cs b/src/Apps/Corathing.Organizer.UnitTests/Helpers/FileHelperUnitTest.cs new file mode 100644 index 0000000..18188f8 --- /dev/null +++ b/src/Apps/Corathing.Organizer.UnitTests/Helpers/FileHelperUnitTest.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Corathing.Organizer.UnitTests.Helpers; + +[TestClass] +public class FileHelperUnitTest +{ + [TestMethod] + public void GenerateUniqueFolder_TestGuid(Guid guid) + { + + } +} diff --git a/src/Apps/Corathing.Organizer/App.xaml.cs b/src/Apps/Corathing.Organizer/App.xaml.cs index 59bf91f..11b7976 100644 --- a/src/Apps/Corathing.Organizer/App.xaml.cs +++ b/src/Apps/Corathing.Organizer/App.xaml.cs @@ -21,8 +21,10 @@ using Wpf.Ui; using Application = System.Windows.Application; +using INavigationService = Corathing.Contracts.Services.INavigationService; using IThemeService = Corathing.Contracts.Services.IThemeService; using MessageBox = System.Windows.MessageBox; +using NavigationService = Corathing.Organizer.Services.NavigationService; using ThemeService = Corathing.Organizer.Services.ThemeService; namespace Corathing.Organizer; @@ -174,6 +176,7 @@ private static IServiceProvider ConfigureServices(string[] args) serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(LocalizationService.Instance); + serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); @@ -188,8 +191,9 @@ private static IServiceProvider ConfigureServices(string[] args) serviceCollection.AddScoped(); serviceCollection.AddScoped(); serviceCollection.AddScoped(); - serviceCollection.AddScoped(); - serviceCollection.AddScoped(); + serviceCollection.AddTransient(); + serviceCollection.AddTransient(); + serviceCollection.AddTransient(); // TODO: // Logger 및 Localizer 설정 diff --git a/src/Apps/Corathing.Organizer/Models/ProjectContext.cs b/src/Apps/Corathing.Organizer/Models/ProjectContext.cs index 9363c58..24159ef 100644 --- a/src/Apps/Corathing.Organizer/Models/ProjectContext.cs +++ b/src/Apps/Corathing.Organizer/Models/ProjectContext.cs @@ -31,7 +31,7 @@ public partial class ProjectContext : ObservableObject /// /// The title. [ObservableProperty] - private string _title = "My Project"; + private string _name = "My Project"; [DefaultValue(false)] [ObservableProperty] @@ -64,7 +64,7 @@ public ObservableCollection Workflows public void AddWorkflow() { var appState = _services.GetService(); - var workflow = appState.AddWorkflow(); + var workflow = appState.CreateAddWorkflow(); //appState.NewWorkflowState(); var workflowContext = _services.GetService(); workflowContext.WorkflowId = workflow.Id; @@ -82,6 +82,19 @@ public ProjectContext(IServiceProvider services) Workflows = new ObservableCollection(); } + public static ProjectContext Create(ProjectState? state = null) + { + if (state == null) + { + var appStateService = App.Current.Services.GetService(); + state = appStateService.CreateAddProject(); + } + var context = App.Current.Services.GetService(); + context.Name = state.Settings.Name; + + return context; + } + public void UpdateProject(ProjectState projectState) { var packageService = _services.GetService(); diff --git a/src/Apps/Corathing.Organizer/Models/ProjectSettingsContext.cs b/src/Apps/Corathing.Organizer/Models/ProjectSettingsContext.cs new file mode 100644 index 0000000..84a7771 --- /dev/null +++ b/src/Apps/Corathing.Organizer/Models/ProjectSettingsContext.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using CommunityToolkit.Mvvm.ComponentModel; + +using Corathing.Contracts.Bases; + +namespace Corathing.Organizer.Models; + +public partial class ProjectSettingsContext : ObservableObject +{ + #region Readonly Properties + private IServiceProvider _services; + #endregion + public Guid ProjectId { get; set; } + public Guid OriginalProjectId { get; set; } + public bool IsAdded { get; set; } + public bool IsRemoved { get; set; } + public bool IsDuplicated { get; set; } + public ProjectState ProjectState { get; set; } + + /// + /// Gets or sets the title. + /// + /// The title. + [ObservableProperty] + private string _name = "My Project"; + + public ProjectSettingsContext(IServiceProvider services) + { + _services = services; + } +} diff --git a/src/Apps/Corathing.Organizer/Natives/FileHelper.cs b/src/Apps/Corathing.Organizer/Natives/FileHelper.cs index bfba006..ecbcb0f 100644 --- a/src/Apps/Corathing.Organizer/Natives/FileHelper.cs +++ b/src/Apps/Corathing.Organizer/Natives/FileHelper.cs @@ -7,6 +7,7 @@ using System.Windows.Media; using System.Windows; using System.Drawing; +using Corathing.Organizer.Utils; namespace Corathing.Organizer.Natives; @@ -20,4 +21,9 @@ public static ImageSource GetIcon(string fileName) Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); } + + public static string GenerateUniqueFolder(Guid guid) + { + return ZBase32Encoder.ToString(guid.ToByteArray()); + } } diff --git a/src/Apps/Corathing.Organizer/Services/AppStateService.cs b/src/Apps/Corathing.Organizer/Services/AppStateService.cs index fe7fbbf..8c254f9 100644 --- a/src/Apps/Corathing.Organizer/Services/AppStateService.cs +++ b/src/Apps/Corathing.Organizer/Services/AppStateService.cs @@ -129,7 +129,7 @@ public bool TryGetProject(Guid id, out ProjectState project) if (_cachedAppDashboardState == null) ReadOrCreateAppStateByAppSettings().Wait(); - project = new ProjectState(); + project = ProjectState.Create(); return true; } @@ -138,7 +138,7 @@ public bool TryGetWorkflow(Guid id, out WorkflowState workflow) if (_cachedAppDashboardState == null) ReadOrCreateAppStateByAppSettings().Wait(); - workflow = new WorkflowState(); + workflow = WorkflowState.Create(); return true; } @@ -205,20 +205,94 @@ public async void UpdateWidget(WidgetState widget) await PendingWriteAppState(); } - public ProjectState AddProject() + public ProjectState CreateAddProject() { var project = ProjectState.Create(); _cachedAppDashboardState.AddProject(project); return project; } - public WorkflowState AddWorkflow() + public WorkflowState CreateAddWorkflow() { var workflow = WorkflowState.Create(); _cachedAppDashboardState.AddWorkflow(workflow); return workflow; } + public ProjectState CopyProject(Guid originalProjectId) + { + if (!TryGetProject(originalProjectId, out var originalProject)) + { + // TODO: + // Change Exception Type; + throw new Exception(); + } + return CopyProject(originalProject); + } + + public ProjectState CopyProject(ProjectState originalProject) + { + var cloneProject = ProjectState.Create(); + foreach (var originalWorkflowId in originalProject.WorkflowIds) + { + var workflowState = CopyWorkflow(originalWorkflowId); + cloneProject.WorkflowIds.Add(workflowState.Id); + } + return cloneProject; + } + + public WorkflowState CopyWorkflow(Guid originalWorkflowId) + { + if (!TryGetWorkflow(originalWorkflowId, out var originalWorkflow)) + { + // TODO: + // Change Exception Type + throw new Exception(); + } + return CopyWorkflow(originalWorkflow); + } + + public WorkflowState CopyWorkflow(WorkflowState workflowState) + { + var cloneWorkflow = WorkflowState.Create(); + + + _cachedAppDashboardState.AddWorkflow(cloneWorkflow); + return cloneWorkflow; + } + + public void RemoveProject(Guid projectid) + { + if (!TryGetProject(projectid, out var project)) + { + // TODO: + // Change Exception Type; + throw new Exception(); + } + RemoveProject(project); + } + + public async void RemoveProject(ProjectState project) + { + _cachedAppDashboardState.RemoveProject(project); + + await PendingWriteAppState(); + } + + public void RemoveWorkflow(Guid guid) + { + + } + + public async void RemoveWorkflow(WorkflowState workflow) + { + _cachedAppDashboardState.RemoveWorkflow(workflow); + + + + await PendingWriteAppState(); + } + #region Private Methods private async Task ReadOrCreateAppSettingsFromAppPath() @@ -331,6 +405,8 @@ private async Task ReadOrCreateAppStateFromPath(string path) _cachedAppDashboardState = document.RootElement .GetProperty("Dashboards") .Deserialize(); + + _cachedAppDashboardState.Refresh(); } } diff --git a/src/Apps/Corathing.Organizer/Services/ApplicationService.cs b/src/Apps/Corathing.Organizer/Services/ApplicationService.cs index b713934..71001d1 100644 --- a/src/Apps/Corathing.Organizer/Services/ApplicationService.cs +++ b/src/Apps/Corathing.Organizer/Services/ApplicationService.cs @@ -6,6 +6,8 @@ using Corathing.Contracts.Services; +using Microsoft.Extensions.DependencyInjection; + namespace Corathing.Organizer.Services { public class ApplicationService : IApplicationService @@ -21,5 +23,15 @@ public async Task DispatchAsync(Func> callback) var result = await App.Current.Dispatcher.InvokeAsync(callback); return result.Result; } + + public IServiceProvider GetServiceProvider() + { + return App.Current.Services; + } + + public TService GetService() + { + return App.Current.Services.GetService(); + } } } diff --git a/src/Apps/Corathing.Organizer/Services/NavigationService.cs b/src/Apps/Corathing.Organizer/Services/NavigationService.cs new file mode 100644 index 0000000..0ad843b --- /dev/null +++ b/src/Apps/Corathing.Organizer/Services/NavigationService.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using Corathing.Contracts.Services; + +namespace Corathing.Organizer.Services; + +public class NavigationService : INavigationService +{ + public bool GoBack() + { + throw new NotImplementedException(); + } + + public bool Navigate(Type pageType) + { + throw new NotImplementedException(); + } + + public bool Navigate(Type pageType, object? dataContext) + { + throw new NotImplementedException(); + } + + public bool Navigate(string pageIdOrTargetTag) + { + throw new NotImplementedException(); + } + + public bool Navigate(string pageIdOrTargetTag, object? dataContext) + { + throw new NotImplementedException(); + } + + public bool NavigateWithHierarchy(Type pageType) + { + throw new NotImplementedException(); + } + + public bool NavigateWithHierarchy(Type pageType, object? dataContext) + { + throw new NotImplementedException(); + } +} diff --git a/src/Apps/Corathing.Organizer/Utils/ZBase32Encoder.cs b/src/Apps/Corathing.Organizer/Utils/ZBase32Encoder.cs new file mode 100644 index 0000000..7a9e5dd --- /dev/null +++ b/src/Apps/Corathing.Organizer/Utils/ZBase32Encoder.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Corathing.Organizer.Utils; + +public class ZBase32Encoder +{ + private const string Charset = "ybndrfg8ejkmcpqxot1uwisza345h769"; + + public static string ToString(byte[] input) + { + if (input == null || input.Length == 0) + { + throw new System.ArgumentNullException("input"); + } + + long returnLength = (input.Length * 8L - 1) / 5 + 1; + if (returnLength > (long)System.Int32.MaxValue) + { + throw new System.ArgumentException("Argument length is too large. (Parameter 'input')"); + } + + char[] returnArray = new char[returnLength]; + + byte nextChar = 0, bitsRemaining = 5; + int arrayIndex = 0; + + foreach (byte b in input) + { + nextChar = (byte)(nextChar | (b >> (8 - bitsRemaining))); + returnArray[arrayIndex++] = Charset[nextChar]; + + if (bitsRemaining < 4) + { + nextChar = (byte)((b >> (3 - bitsRemaining)) & 31); + returnArray[arrayIndex++] = Charset[nextChar]; + bitsRemaining += 5; + } + + bitsRemaining -= 3; + nextChar = (byte)((b << bitsRemaining) & 31); + } + + //if we didn't end with a full char + if (arrayIndex != returnLength) + { + returnArray[arrayIndex++] = Charset[nextChar]; + } + + return new string(returnArray); + } +} diff --git a/src/Apps/Corathing.Organizer/ViewModels/DashboardViewModel.cs b/src/Apps/Corathing.Organizer/ViewModels/DashboardViewModel.cs index 1d0e772..59ce23e 100644 --- a/src/Apps/Corathing.Organizer/ViewModels/DashboardViewModel.cs +++ b/src/Apps/Corathing.Organizer/ViewModels/DashboardViewModel.cs @@ -22,6 +22,7 @@ using Corathing.Organizer.Controls; using Corathing.Organizer.Extensions; using Corathing.Organizer.Models; +using Corathing.Organizer.Services; using Corathing.Organizer.Views; using Microsoft.Extensions.DependencyInjection; @@ -114,6 +115,13 @@ public void AddWorkflow() SelectedProject.AddWorkflow(); } + [RelayCommand] + public void AddProject() + { + var projectContext = ProjectContext.Create(); + Projects.Add(projectContext); + } + [RelayCommand] public async void OpenOrganizerSettings() { @@ -263,7 +271,7 @@ private void UpdateDashboard() foreach (var projectState in dashboardState.Projects) { var projectContext = _services.GetService(); - projectContext.Title = projectState.Settings.Name; + projectContext.Name = projectState.Settings.Name; //projectContext.ProjectId // TODO:::: } @@ -273,8 +281,9 @@ private void UpdateDashboard() // services.GetService() // }); SelectedProject = Projects.FirstOrDefault(); - SelectedProject.AddWorkflow(); - appStateService.AddProject(); + if (SelectedProject != null) + { + } //dashboardState.Projects; //Projects.AddRange() } diff --git a/src/Apps/Corathing.Organizer/ViewModels/ProjectSettingsViewModel.cs b/src/Apps/Corathing.Organizer/ViewModels/ProjectSettingsViewModel.cs index 81c95af..2e3c18a 100644 --- a/src/Apps/Corathing.Organizer/ViewModels/ProjectSettingsViewModel.cs +++ b/src/Apps/Corathing.Organizer/ViewModels/ProjectSettingsViewModel.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -8,19 +9,132 @@ using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; +using Corathing.Contracts.Bases; +using Corathing.Contracts.Services; +using Corathing.Organizer.Models; +using Corathing.Organizer.Services; + +using Microsoft.Extensions.DependencyInjection; + namespace Corathing.Organizer.ViewModels; public partial class ProjectSettingsViewModel : ObservableObject { + private IServiceProvider _services; + [ObservableProperty] + private ObservableCollection _projectSettingsContexts; + + [ObservableProperty] + private ProjectSettingsContext _selectedProjectContext; + public ProjectSettingsViewModel(IServiceProvider services) { + _services = services; + ProjectSettingsContexts = new ObservableCollection(); + + var appStateService = _services.GetService(); + var dashboards = appStateService.GetAppDashboardState(); + + foreach (var projectState in dashboards.Projects) + { + var projectSettingsContext = _services.GetService(); + projectSettingsContext.Name = projectState.Settings.Name; + projectSettingsContext.ProjectId = projectState.Id; + projectSettingsContext.ProjectState = projectState; + ProjectSettingsContexts.Add(projectSettingsContext); + } + } + + [RelayCommand] + public void AddProject() + { + var projectSettingsContext = _services.GetService(); + projectSettingsContext.IsAdded = true; + ProjectSettingsContexts.Add(projectSettingsContext); + } + [RelayCommand] + public void DuplicateProject(ProjectSettingsContext originalContext) + { + var projectSettingsContext = _services.GetService(); + projectSettingsContext.IsDuplicated = true; + projectSettingsContext.Name = $"{originalContext.Name} Copy"; + projectSettingsContext.OriginalProjectId = originalContext.ProjectId; + ProjectSettingsContexts.Add(projectSettingsContext); } [RelayCommand] - public void Close(Window window) + public void RemoveProject(ProjectSettingsContext projectSettingsContext) + { + projectSettingsContext.IsRemoved = true; + ProjectSettingsContexts.Remove(projectSettingsContext); + } + + [RelayCommand] + public void Apply() + { + var appStateService = _services.GetService(); + + foreach (var projectSettingsContext in ProjectSettingsContexts) + { + if (projectSettingsContext.IsRemoved) + { + appStateService.RemoveProject(projectSettingsContext.ProjectId); + } + else if (projectSettingsContext.IsAdded) + { + var projectState = ProjectState.Create(); + projectState.Settings.Name = projectSettingsContext.Name; + appStateService.UpdateProject(projectState); + } + else if (projectSettingsContext.IsDuplicated) + { + var projectState = CopyProject(projectSettingsContext.OriginalProjectId); + projectState.Settings.Name = projectSettingsContext.Name; + appStateService.UpdateProject(projectState); + } + else + { + if (projectSettingsContext.ProjectState.Settings.Name != projectSettingsContext.Name) + { + projectSettingsContext.ProjectState.Settings.Name = projectSettingsContext.Name; + appStateService.UpdateProject(projectSettingsContext.ProjectState); + } + } + } + + appStateService.UpdateForce(); + } + + private ProjectState CopyProject(Guid originalProjectId) + { + var originalProjectSettingsContext = ProjectSettingsContexts.FirstOrDefault(context => context.ProjectId == originalProjectId); + if (originalProjectSettingsContext == null) + { + // TODO: + // Change Exception Type + throw new InvalidOperationException(); + } + if (originalProjectSettingsContext.IsAdded) + { + return ProjectState.Create(); + } + if (originalProjectSettingsContext.IsDuplicated) + { + return CopyProject(originalProjectSettingsContext.OriginalProjectId); + } + var appStateService = _services.GetService(); + return appStateService.CopyProject(originalProjectSettingsContext.ProjectId); + } + + [RelayCommand] + public void GoBack(Window window) { window.Close(); + var navigationService = _services.GetService(); + + // TODO: + // navigationService.GoBack(); } } diff --git a/src/Apps/Corathing.Organizer/Views/OrganizerSettingsView.xaml.cs b/src/Apps/Corathing.Organizer/Views/OrganizerSettingsView.xaml.cs index ff242d0..d4b7e1b 100644 --- a/src/Apps/Corathing.Organizer/Views/OrganizerSettingsView.xaml.cs +++ b/src/Apps/Corathing.Organizer/Views/OrganizerSettingsView.xaml.cs @@ -37,6 +37,7 @@ public OrganizerSettingsView() { var window = Window.GetWindow(this); window.Width = 800; + window.Height = 800; window.CenterWindowToParent(); }; } diff --git a/src/Apps/Corathing.Organizer/Views/ProjectSettingsView.xaml b/src/Apps/Corathing.Organizer/Views/ProjectSettingsView.xaml index 24f0f92..31be6aa 100644 --- a/src/Apps/Corathing.Organizer/Views/ProjectSettingsView.xaml +++ b/src/Apps/Corathing.Organizer/Views/ProjectSettingsView.xaml @@ -4,21 +4,35 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:Corathing.Organizer.Views" + xmlns:models="clr-namespace:Corathing.Organizer.Models" xmlns:viewmodels="clr-namespace:Corathing.Organizer.ViewModels" xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" + xmlns:localizations="clr-namespace:Corathing.Dashboards.WPF.Bindings;assembly=Corathing.Dashboards.WPF" mc:Ignorable="d" - Background="Transparent" Margin="16" + d:Height="800" + d:Width="800" + Background="{DynamicResource ApplicationBackgroundBrush}" + Foreground="{DynamicResource TextFillColorPrimaryBrush}" + d:DataContext="{d:DesignInstance viewmodels:ProjectSettingsViewModel, + IsDesignTimeCreatable=False}" Title="ProjectSettingsView"> + + + + + + + + - - + + + + - + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + diff --git a/src/Apps/Corathing.Organizer/Views/ProjectSettingsView.xaml.cs b/src/Apps/Corathing.Organizer/Views/ProjectSettingsView.xaml.cs index d7a2c02..d598f0d 100644 --- a/src/Apps/Corathing.Organizer/Views/ProjectSettingsView.xaml.cs +++ b/src/Apps/Corathing.Organizer/Views/ProjectSettingsView.xaml.cs @@ -35,7 +35,8 @@ public ProjectSettingsView() Loaded += (s, e) => { var window = Window.GetWindow(this); - window.Width = 1000; + window.Width = 800; + window.Height = 800; window.CenterWindowToParent(); }; } diff --git a/src/Apps/Corathing.Organizer/Views/WidgetSettingsView.xaml.cs b/src/Apps/Corathing.Organizer/Views/WidgetSettingsView.xaml.cs index 97b3b43..5a308ee 100644 --- a/src/Apps/Corathing.Organizer/Views/WidgetSettingsView.xaml.cs +++ b/src/Apps/Corathing.Organizer/Views/WidgetSettingsView.xaml.cs @@ -28,6 +28,8 @@ public partial class WidgetSettingsView : Page { public WidgetSettingsViewModel ViewModel { get; set; } + public ContentPresenter? WidgetPreseneter { get; set; } + public WidgetSettingsView(WidgetHost widgetHost) { InitializeComponent(); @@ -38,7 +40,8 @@ public WidgetSettingsView(WidgetHost widgetHost) Loaded += (s, e) => { var window = Window.GetWindow(this); - window.Width = 1000; + window.Width = 800; + window.Height = 800; window.CenterWindowToParent(); }; } diff --git a/src/Shared/Corathing.Contracts/Bases/AppDashboardState.cs b/src/Shared/Corathing.Contracts/Bases/AppDashboardState.cs index b5609b0..bdccede 100644 --- a/src/Shared/Corathing.Contracts/Bases/AppDashboardState.cs +++ b/src/Shared/Corathing.Contracts/Bases/AppDashboardState.cs @@ -16,7 +16,7 @@ public class AppDashboardState #region Serialized Properties public Guid Id { get; set; } - public Guid SelectedDashboardId { get; set; } + public Guid? SelectedProjectId { get; set; } public List Projects { get; set; } public List Workflows { get; set; } @@ -34,6 +34,7 @@ public class AppDashboardState public AppDashboardState() { + Id = Guid.NewGuid(); Projects = new List(); Workflows = new List(); Widgets = new List(); @@ -87,7 +88,7 @@ public void UpdateProject(ProjectState project) if (HashedProjects.ContainsKey(project.Id)) { var oldProject = HashedProjects[project.Id]; - Projects.Remove(oldProject); + Projects.RemoveAll(item => item.Id == oldProject.Id); } HashedProjects[project.Id] = project; Projects.Add(project); @@ -98,7 +99,7 @@ public void UpdateWorkflow(WorkflowState workflow) if (HashedWorkflows.ContainsKey(workflow.Id)) { var oldWorkflow = HashedWorkflows[workflow.Id]; - Workflows.Remove(oldWorkflow); + Workflows.RemoveAll(item => item.Id == oldWorkflow.Id); } HashedWorkflows[workflow.Id] = workflow; Workflows.Add(workflow); @@ -114,4 +115,24 @@ public void UpdateWidget(WidgetState widget) HashedWidgets[widget.Id] = widget; Widgets.Add(widget); } + + public void Refresh() + { + HashedProjects.Clear(); + HashedWorkflows.Clear(); + HashedWidgets.Clear(); + + foreach (var project in Projects) + { + HashedProjects[project.Id] = project; + } + foreach (var workflow in Workflows) + { + HashedWorkflows[workflow.Id] = workflow; + } + foreach (var widget in Widgets) + { + HashedWidgets[widget.Id] = widget; + } + } } diff --git a/src/Shared/Corathing.Contracts/Bases/Interfaces/IProjectState.cs b/src/Shared/Corathing.Contracts/Bases/Interfaces/IProjectState.cs index 8f0772d..6b74383 100644 --- a/src/Shared/Corathing.Contracts/Bases/Interfaces/IProjectState.cs +++ b/src/Shared/Corathing.Contracts/Bases/Interfaces/IProjectState.cs @@ -20,7 +20,7 @@ public class ProjectSettings : IProjectSettings public interface IProjectState : IEntity { - Guid SelectedWorkflowId { get; } - IProjectSettings Settings { get; } + Guid? SelectedWorkflowId { get; } + ProjectSettings Settings { get; } List WorkflowIds { get; } } diff --git a/src/Shared/Corathing.Contracts/Bases/ProjectState.cs b/src/Shared/Corathing.Contracts/Bases/ProjectState.cs index 1d6f5ce..2210083 100644 --- a/src/Shared/Corathing.Contracts/Bases/ProjectState.cs +++ b/src/Shared/Corathing.Contracts/Bases/ProjectState.cs @@ -12,24 +12,10 @@ namespace Corathing.Contracts.Bases; public class ProjectState : IProjectState { public Guid Id { get; set; } - public Guid SelectedWorkflowId { get; set; } - public IProjectSettings Settings { get; set; } + public Guid? SelectedWorkflowId { get; set; } + public ProjectSettings Settings { get; set; } public List WorkflowIds { get; set; } - public static ProjectState CreateProject(Guid id, string projectName) - { - return new ProjectState - { - Id = id, - Settings = new ProjectSettings - { - Name = projectName - }, - WorkflowIds = new List(), - SelectedWorkflowId = Guid.Empty - }; - } - public static ProjectState Create() { return new ProjectState @@ -40,7 +26,7 @@ public static ProjectState Create() Name = "My Project" }, WorkflowIds = new List(), - SelectedWorkflowId = Guid.Empty + SelectedWorkflowId = null }; } @@ -49,7 +35,7 @@ public static string GenerateProjectName(List usedNames) return NameHelper.GenerateUniqueName("Project", usedNames); } - public static ProjectState UpdateProjectSettings(ProjectState project, IProjectSettings settings) + public static ProjectState UpdateProjectSettings(ProjectState project, ProjectSettings settings) { return new ProjectState { diff --git a/src/Shared/Corathing.Contracts/Services/IAppStateService.cs b/src/Shared/Corathing.Contracts/Services/IAppStateService.cs index 138e74f..07edf6c 100644 --- a/src/Shared/Corathing.Contracts/Services/IAppStateService.cs +++ b/src/Shared/Corathing.Contracts/Services/IAppStateService.cs @@ -17,16 +17,23 @@ public interface IAppStateService AppPackageState GetAppPackageState(); AppDashboardState GetAppDashboardState(); - ProjectState AddProject(); - WorkflowState AddWorkflow(); + ProjectState CreateAddProject(); + WorkflowState CreateAddWorkflow(); + + ProjectState CopyProject(Guid originalProjectId); + ProjectState CopyProject(ProjectState originalProject); + WorkflowState CopyWorkflow(Guid originalWorkflowId); + WorkflowState CopyWorkflow(WorkflowState originalWorkflow); + + void RemoveProject(ProjectState project); + void RemoveProject(Guid projectId); + void RemoveWorkflow(WorkflowState workflow); + void RemoveWorkflow(Guid workflowId); bool TryGetProject(Guid id, out ProjectState project); bool TryGetWorkflow(Guid id, out WorkflowState workflow); bool TryGetWidget(Guid id, out WidgetState widget); - //ProjectState GetOrAddProject(Guid? projectId = null); - //IEnumerable GetWidgets(Guid? workflowId = null); - void UpdateProject(ProjectState project); void UpdateWorkflow(WorkflowState workflow); void UpdateWidget(WidgetState widget); diff --git a/src/Shared/Corathing.Contracts/Services/IApplicationService.cs b/src/Shared/Corathing.Contracts/Services/IApplicationService.cs index 7af7df2..ffc74d4 100644 --- a/src/Shared/Corathing.Contracts/Services/IApplicationService.cs +++ b/src/Shared/Corathing.Contracts/Services/IApplicationService.cs @@ -10,4 +10,7 @@ public interface IApplicationService { Task InvokeAsync(Func callback); Task DispatchAsync(Func> callback); + + IServiceProvider GetServiceProvider(); + TService GetService(); } diff --git a/src/Shared/Corathing.Contracts/Services/INavigationService.cs b/src/Shared/Corathing.Contracts/Services/INavigationService.cs new file mode 100644 index 0000000..8bef6c8 --- /dev/null +++ b/src/Shared/Corathing.Contracts/Services/INavigationService.cs @@ -0,0 +1,89 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +// This Source Code Form is subject to the terms of the MIT License. +// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. +// Copyright (C) Leszek Pomianowski and WPF UI Contributors. +// All Rights Reserved. + +namespace Corathing.Contracts.Services; + +/// +/// Represents a contract with a that contains . +/// Through defined service allows you to use the Dependency Injection pattern in WPF UI navigation. +/// +public interface INavigationService +{ + + /// + /// Lets you navigate to the selected page based on it's type. Should be used with . + /// + /// of the page. + /// if the operation succeeds. otherwise. + bool Navigate(Type pageType); + + /// + /// Lets you navigate to the selected page based on it's type, Should be used with . + /// + /// of the page. + /// DataContext + /// if the operation succeeds. otherwise. + bool Navigate(Type pageType, object? dataContext); + + /// + /// Lets you navigate to the selected page based on it's tag. Should be used with . + /// + /// Id or tag of the page. + /// if the operation succeeds. otherwise. + bool Navigate(string pageIdOrTargetTag); + + /// + /// Lets you navigate to the selected page based on it's tag. Should be used with . + /// + /// Id or tag of the page. + /// DataContext + /// if the operation succeeds. otherwise. + bool Navigate(string pageIdOrTargetTag, object? dataContext); + + /// + /// Synchronously adds an element to the navigation stack and navigates current navigation Frame to the + /// + /// Type of control to be synchronously added to the navigation stack + /// if the operation succeeds. otherwise. + bool NavigateWithHierarchy(Type pageType); + + /// + /// Synchronously adds an element to the navigation stack and navigates current navigation Frame to the + /// + /// Type of control to be synchronously added to the navigation stack + /// DataContext + /// if the operation succeeds. otherwise. + bool NavigateWithHierarchy(Type pageType, object? dataContext); + + ///// + ///// Provides direct access to the control responsible for navigation. + ///// + ///// Instance of the control. + //INavigationView GetNavigationControl(); + + ///// + ///// Lets you attach the control that represents the . + ///// + ///// Instance of the . + //void SetNavigationControl(INavigationView navigation); + + ///// + ///// Lets you attach the service that delivers page instances to . + ///// + ///// Instance of the . + //void SetPageService(IPageService pageService); + + /// + /// Navigates the NavigationView to the previous journal entry. + /// + /// if the operation succeeds. otherwise. + bool GoBack(); +} diff --git a/src/Shared/Corathing.UI.WPF/Themes/Generic.xaml b/src/Shared/Corathing.UI.WPF/Themes/Generic.xaml index 15bf01b..07fe608 100644 --- a/src/Shared/Corathing.UI.WPF/Themes/Generic.xaml +++ b/src/Shared/Corathing.UI.WPF/Themes/Generic.xaml @@ -62,7 +62,7 @@ - #B3FFFFFF + #B3E8E8E8 #60E8E8E8 #4DE0E0E0 #4DE0E0E0