Skip to content

Commit

Permalink
Add Dashboard Sample
Browse files Browse the repository at this point in the history
  • Loading branch information
dogzz9445 committed Jun 12, 2024
1 parent 078b899 commit 5427d32
Show file tree
Hide file tree
Showing 43 changed files with 1,274 additions and 134 deletions.
25 changes: 24 additions & 1 deletion Corathing.sln
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Corathing.Dashboards", "src
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Corathing.Widgets.Basics", "src\Widgets\Corathing.Widgets.Basics\Corathing.Widgets.Basics.csproj", "{8BB7B29E-4684-4F2F-9932-698FDAD2FCDA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Corathing.UI.WPF", "src\Shared\Corathing.UI.WPF\Corathing.UI.WPF.csproj", "{F0AF90D5-5E28-4FC1-8DBD-8B3F68A285DB}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Corathing.UI.WPF", "src\Shared\Corathing.UI.WPF\Corathing.UI.WPF.csproj", "{F0AF90D5-5E28-4FC1-8DBD-8B3F68A285DB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Corathing.Dashboards.Sample", "src\Apps\Corathing.Dashboards.Sample\Corathing.Dashboards.Sample.csproj", "{D56E1CDF-FCC6-476C-BEC3-C13239A3BEFD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -221,6 +223,26 @@ Global
{F0AF90D5-5E28-4FC1-8DBD-8B3F68A285DB}.Release|x64.Build.0 = Release|Any CPU
{F0AF90D5-5E28-4FC1-8DBD-8B3F68A285DB}.Release|x86.ActiveCfg = Release|Any CPU
{F0AF90D5-5E28-4FC1-8DBD-8B3F68A285DB}.Release|x86.Build.0 = Release|Any CPU
{D56E1CDF-FCC6-476C-BEC3-C13239A3BEFD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D56E1CDF-FCC6-476C-BEC3-C13239A3BEFD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D56E1CDF-FCC6-476C-BEC3-C13239A3BEFD}.Debug|ARM.ActiveCfg = Debug|Any CPU
{D56E1CDF-FCC6-476C-BEC3-C13239A3BEFD}.Debug|ARM.Build.0 = Debug|Any CPU
{D56E1CDF-FCC6-476C-BEC3-C13239A3BEFD}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{D56E1CDF-FCC6-476C-BEC3-C13239A3BEFD}.Debug|ARM64.Build.0 = Debug|Any CPU
{D56E1CDF-FCC6-476C-BEC3-C13239A3BEFD}.Debug|x64.ActiveCfg = Debug|Any CPU
{D56E1CDF-FCC6-476C-BEC3-C13239A3BEFD}.Debug|x64.Build.0 = Debug|Any CPU
{D56E1CDF-FCC6-476C-BEC3-C13239A3BEFD}.Debug|x86.ActiveCfg = Debug|Any CPU
{D56E1CDF-FCC6-476C-BEC3-C13239A3BEFD}.Debug|x86.Build.0 = Debug|Any CPU
{D56E1CDF-FCC6-476C-BEC3-C13239A3BEFD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D56E1CDF-FCC6-476C-BEC3-C13239A3BEFD}.Release|Any CPU.Build.0 = Release|Any CPU
{D56E1CDF-FCC6-476C-BEC3-C13239A3BEFD}.Release|ARM.ActiveCfg = Release|Any CPU
{D56E1CDF-FCC6-476C-BEC3-C13239A3BEFD}.Release|ARM.Build.0 = Release|Any CPU
{D56E1CDF-FCC6-476C-BEC3-C13239A3BEFD}.Release|ARM64.ActiveCfg = Release|Any CPU
{D56E1CDF-FCC6-476C-BEC3-C13239A3BEFD}.Release|ARM64.Build.0 = Release|Any CPU
{D56E1CDF-FCC6-476C-BEC3-C13239A3BEFD}.Release|x64.ActiveCfg = Release|Any CPU
{D56E1CDF-FCC6-476C-BEC3-C13239A3BEFD}.Release|x64.Build.0 = Release|Any CPU
{D56E1CDF-FCC6-476C-BEC3-C13239A3BEFD}.Release|x86.ActiveCfg = Release|Any CPU
{D56E1CDF-FCC6-476C-BEC3-C13239A3BEFD}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -234,6 +256,7 @@ Global
{B07D1162-D70E-4CCB-8F13-2E21611B9214} = {89CC8AAB-466A-47B6-98B9-93EB379F55A7}
{8BB7B29E-4684-4F2F-9932-698FDAD2FCDA} = {B32F5E62-3357-4FE1-BEB3-7CDED236BA66}
{F0AF90D5-5E28-4FC1-8DBD-8B3F68A285DB} = {89CC8AAB-466A-47B6-98B9-93EB379F55A7}
{D56E1CDF-FCC6-476C-BEC3-C13239A3BEFD} = {5BF1289A-1427-4306-B2E1-51E0770B6B75}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {FC027A8C-0C58-494B-BE76-F403F0336A74}
Expand Down
9 changes: 9 additions & 0 deletions src/Apps/Corathing.Dashboards.Sample/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Application x:Class="Corathing.Dashboards.Sample.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Corathing.Dashboards.Sample"
StartupUri="MainWindow.xaml">
<Application.Resources>

</Application.Resources>
</Application>
14 changes: 14 additions & 0 deletions src/Apps/Corathing.Dashboards.Sample/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Configuration;
using System.Data;
using System.Windows;

namespace Corathing.Dashboards.Sample
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}

}
10 changes: 10 additions & 0 deletions src/Apps/Corathing.Dashboards.Sample/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Windows;

[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UseWPF>true</UseWPF>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\Shared\Corathing.Contracts\Corathing.Contracts.csproj" />
<ProjectReference Include="..\..\Shared\Corathing.Dashboards.WPF\Corathing.Dashboards.WPF.csproj" />
<ProjectReference Include="..\..\Shared\Corathing.Dashboards\Corathing.Dashboards.csproj" />
</ItemGroup>

</Project>
11 changes: 11 additions & 0 deletions src/Apps/Corathing.Dashboards.Sample/MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Window x:Class="Corathing.Dashboards.Sample.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Corathing.Dashboards.Sample"
xmlns:views="clr-namespace:Corathing.Dashboards.Sample.Views"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<views:DashboardView />
</Window>
24 changes: 24 additions & 0 deletions src/Apps/Corathing.Dashboards.Sample/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Corathing.Dashboards.Sample
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;

using Corathing.Contracts.Bases;
using Corathing.Dashboards.Sample.Widgets;
using Corathing.Dashboards.WPF.Controls;

namespace Corathing.Dashboards.Sample.ViewModels;

public partial class DashboardViewModel : ObservableObject
{
[ObservableProperty]
private ObservableCollection<WidgetContext> _widgets;
[ObservableProperty]
private bool? _editMode;

[RelayCommand]
public void ToggleEditMode()
{
EditMode = !EditMode;
}

[RelayCommand]
public void AddWidget()
{
Widgets.Add(new EmptyWidgetContext());
}

[RelayCommand]
public void RemoveWidget(WidgetHost host)
{
var context = host.DataContext as WidgetContext;
Widgets.Remove(context);
}

[RelayCommand]
public void ConfigureWidget(WidgetHost host)
{
var context = host.DataContext as WidgetContext;
// Do Something
}

public DashboardViewModel()
{
Widgets = new ObservableCollection<WidgetContext>();
EditMode = false;
}

protected override void OnPropertyChanged(PropertyChangedEventArgs e)
{
base.OnPropertyChanged(e);

foreach (var widget in Widgets)
{
widget.EditMode = EditMode;
}
}
}
44 changes: 44 additions & 0 deletions src/Apps/Corathing.Dashboards.Sample/Views/DashboardView.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<Page x:Class="Corathing.Dashboards.Sample.Views.DashboardView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Corathing.Dashboards.Sample.Views"
xmlns:widgets="clr-namespace:Corathing.Dashboards.Sample.Widgets"
xmlns:dashboardControl="clr-namespace:Corathing.Dashboards.WPF.Controls;assembly=Corathing.Dashboards.WPF"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
Title="DashboardView">
<Page.Resources>
<DataTemplate DataType="{x:Type widgets:EmptyWidgetContext}">
<widgets:EmptyWidget />
</DataTemplate>
<Style TargetType="{x:Type dashboardControl:WidgetHost}">
<Setter Property="BorderBrush"
Value="Black" />
<Setter Property="BorderThickness"
Value="1" />
<Setter Property="Background"
Value="#24242424" />
</Style>
</Page.Resources>
<Grid>
<Border Margin="4"
BorderBrush="Black"
BorderThickness="1">
<dashboardControl:DashboardHost Margin="4"
MaxNumColumns="10"
EditMode="{Binding EditMode}"
ItemsSource="{Binding Widgets}" />
</Border>
<StackPanel HorizontalAlignment="Right"
VerticalAlignment="Top"
Orientation="Vertical"
Margin="8">
<ToggleButton Content="Toggle Edit Mode"
Command="{Binding ToggleEditModeCommand}" />
<Button Content="Create Widget from Button"
Command="{Binding AddWidgetCommand}" />
</StackPanel>
</Grid>
</Page>
33 changes: 33 additions & 0 deletions src/Apps/Corathing.Dashboards.Sample/Views/DashboardView.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using Corathing.Dashboards.Sample.ViewModels;

namespace Corathing.Dashboards.Sample.Views
{
/// <summary>
/// Interaction logic for DashboardView.xaml
/// </summary>
public partial class DashboardView : Page
{
public DashboardViewModel ViewModel;
public DashboardView()
{
InitializeComponent();

DataContext = ViewModel = new DashboardViewModel();
}
}
}
12 changes: 12 additions & 0 deletions src/Apps/Corathing.Dashboards.Sample/Widgets/EmptyWidget.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<UserControl x:Class="Corathing.Dashboards.Sample.Widgets.EmptyWidget"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Corathing.Dashboards.Sample.Widgets"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid Background="#24242424">
<TextBlock Text="Widget from context" />
</Grid>
</UserControl>
38 changes: 38 additions & 0 deletions src/Apps/Corathing.Dashboards.Sample/Widgets/EmptyWidget.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using Corathing.Contracts.Bases;

namespace Corathing.Dashboards.Sample.Widgets
{
public partial class EmptyWidgetContext : WidgetContext
{
public EmptyWidgetContext()
{
WidgetTitle = "Empty Widget";
}
}

/// <summary>
/// Interaction logic for WidgetFromContext.xaml
/// </summary>
public partial class EmptyWidget
{
public EmptyWidget()
{
InitializeComponent();
}
}
}
23 changes: 15 additions & 8 deletions src/Apps/Corathing.Organizer/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Corathing.Organizer.Utils;
using Corathing.Organizer.ViewModels;
using Corathing.Organizer.Views;
using Corathing.Widgets.Basics.Resources;

using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
Expand Down Expand Up @@ -76,13 +77,18 @@ protected override async void OnStartup(StartupEventArgs e)
{
themeService.Register(
"Corathing.Dashboards.WPF",
@"pack://application:,,,/Corathing.Dashboards.WPF;component/Themes/Light.xaml",
@"pack://application:,,,/Corathing.Dashboards.WPF;component/Themes/Dark.xaml"
"pack://application:,,,/Corathing.Dashboards.WPF;component/Themes/Light.xaml",
"pack://application:,,,/Corathing.Dashboards.WPF;component/Themes/Dark.xaml"
);
themeService.Register(
"MaterialDesignThemes.Wpf",
@"pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml",
@"pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Dark.xaml"
"pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml",
"pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Dark.xaml"
);
themeService.Register(
"MahApps.Metro",
"pack://application:,,,/MahApps.Metro;component/Styles/Themes/Light.Blue.xaml",
"pack://application:,,,/MahApps.Metro;component/Styles/Themes/Dark.Cyan.xaml"
);

if (appPreferences.UseSystemTheme)
Expand All @@ -100,6 +106,11 @@ protected override async void OnStartup(StartupEventArgs e)
//widgetService.LoadWidgetsFromDLL("DDT.Core.WidgetSystems.DefaultWidgets.dll");
//widgetService.RegisterWidgets(new List<WidgetGenerator> { new WidgetGenerator() });

LocalizationService.Instance.RegisterStringResourceManager("Corathing.Organizer",
CorathingOrganizerLocalizationStringResources.ResourceManager);

LocalizationService.Instance.RegisterStringResourceManager("Corathing.Widgets.Basics",
BasicWidgetStringResources.ResourceManager);

Check failure on line 113 in src/Apps/Corathing.Organizer/App.xaml.cs

View workflow job for this annotation

GitHub Actions / build (x64)

'BasicWidgetStringResources' is inaccessible due to its protection level

Check failure on line 113 in src/Apps/Corathing.Organizer/App.xaml.cs

View workflow job for this annotation

GitHub Actions / build (x64)

'BasicWidgetStringResources' is inaccessible due to its protection level

IAuthService authService = App.Current.Services.GetService<IAuthService>();
if (authService != null && authService.UseAuthService)
Expand Down Expand Up @@ -153,16 +164,12 @@ private static IServiceProvider ConfigureServices(string[] args)
serviceCollection.AddSingleton<IThemeService, ThemeService>();
serviceCollection.AddSingleton<ILocalizationService>(LocalizationService.Instance);

LocalizationService.Instance.RegisterStringResourceManager("Corathing.Organizer",
CorathingOrganizerLocalizationStringResources.ResourceManager);

// Register viewmodels
serviceCollection.AddScoped<OrganizerSettingsViewModel>();
serviceCollection.AddScoped<WidgetSettingsViewModel>();
serviceCollection.AddScoped<ProjectSettingsViewModel>();

//Logger.Configure(configuration);
//serviceCollection.AddSingleton<SettingsController>();
//Localizer.Configure(configuration);

return serviceCollection.BuildServiceProvider();
Expand Down
Loading

0 comments on commit 5427d32

Please sign in to comment.