Compare commits
No commits in common. "255a13337b74a092e18ce32ac0ff0c158a1a54c5" and "b8e7249ec6100070d4c2068d0dc0d625342d361b" have entirely different histories.
255a13337b
...
b8e7249ec6
@ -16,19 +16,18 @@ namespace Presence.Api.Controllers
|
||||
_groupService = groupService;
|
||||
}
|
||||
|
||||
[HttpGet("/group")]
|
||||
public async Task<ActionResult<GroupResponse>> GetAllGroups()
|
||||
[HttpGet]
|
||||
public ActionResult<GroupResponse> GetAllGroups()
|
||||
{
|
||||
var result = _groupService
|
||||
.GetGroupsWithStudents();
|
||||
var response = result
|
||||
.GetGroupsWithStudents()
|
||||
.Select(group => new GroupResponse {
|
||||
Id = group.Id,
|
||||
Name = group.Name,
|
||||
Users = group.Users.Select(user => new UserResponse {
|
||||
Guid = user.Guid,
|
||||
Name = user.Name
|
||||
}).ToList(),
|
||||
}).Take(10).ToList(),
|
||||
}).ToList();
|
||||
return Ok(new GroupResponse());
|
||||
}
|
||||
|
@ -1,9 +1,14 @@
|
||||
<Application xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
x:Class="Presence.Desktop.App"
|
||||
xmlns:local="using:Presence.Desktop"
|
||||
RequestedThemeVariant="Default">
|
||||
<!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->
|
||||
|
||||
<Application.DataTemplates>
|
||||
<local:ViewLocator/>
|
||||
</Application.DataTemplates>
|
||||
|
||||
<Application.Styles>
|
||||
<FluentTheme />
|
||||
</Application.Styles>
|
||||
|
@ -20,13 +20,13 @@ namespace Presence.Desktop
|
||||
var serviceCollection = new ServiceCollection();
|
||||
serviceCollection.AddCommonService();
|
||||
var services = serviceCollection.BuildServiceProvider();
|
||||
var mainViewModel = services.GetRequiredService<GroupViewModel>();
|
||||
var mainViewModel = services.GetRequiredService<MainWindowViewModel>();
|
||||
|
||||
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||
{
|
||||
desktop.MainWindow = new MainWindow()
|
||||
desktop.MainWindow = new MainWindow
|
||||
{
|
||||
DataContext = new MainWindowViewModel(services),
|
||||
DataContext = mainViewModel,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@ namespace Presence.Desktop.DI
|
||||
.AddDbContext<RemoteDatabaseContext>()
|
||||
.AddSingleton<IGroupRepository, SQLGroupRepository>()
|
||||
.AddTransient<IGroupUseCase, GroupService>()
|
||||
.AddTransient<GroupViewModel>();
|
||||
.AddTransient<MainWindowViewModel>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +0,0 @@
|
||||
using Avalonia.Controls;
|
||||
using ReactiveUI;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Presence.Desktop.Models
|
||||
{
|
||||
public class GroupPresenter
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public IEnumerable<UserPresenter>? users { get; set; } = null;
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Presence.Desktop.Models
|
||||
{
|
||||
public class UserPresenter
|
||||
{
|
||||
public Guid Guid { get; set; }
|
||||
public string Name { get; set; }
|
||||
public GroupPresenter Group { get; set; }
|
||||
}
|
||||
}
|
@ -9,6 +9,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Models\" />
|
||||
<AvaloniaResource Include="Assets\**" />
|
||||
</ItemGroup>
|
||||
|
||||
|
@ -2,18 +2,31 @@ using Avalonia.Controls;
|
||||
using Avalonia.Controls.Templates;
|
||||
using Presence.Desktop.ViewModels;
|
||||
using System;
|
||||
using Presence.Desktop.Views;
|
||||
using ReactiveUI;
|
||||
|
||||
namespace Presence.Desktop
|
||||
{
|
||||
public class ViewLocator : IViewLocator
|
||||
public class ViewLocator : IDataTemplate
|
||||
{
|
||||
public IViewFor? ResolveView<T>(T? viewModel, string? contract = null) => viewModel switch
|
||||
|
||||
public Control? Build(object? param)
|
||||
{
|
||||
GroupViewModel groupViewModel => new GroupView { DataContext = groupViewModel },
|
||||
PresenceViewModel presenceViewModel => new PresenceView { DataContext = presenceViewModel },
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(viewModel))
|
||||
};
|
||||
if (param is null)
|
||||
return null;
|
||||
|
||||
var name = param.GetType().FullName!.Replace("ViewModel", "View", StringComparison.Ordinal);
|
||||
var type = Type.GetType(name);
|
||||
|
||||
if (type != null)
|
||||
{
|
||||
return (Control)Activator.CreateInstance(type)!;
|
||||
}
|
||||
|
||||
return new TextBlock { Text = "Not Found: " + name };
|
||||
}
|
||||
|
||||
public bool Match(object? data)
|
||||
{
|
||||
return data is ViewModelBase;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,74 +0,0 @@
|
||||
using domain.UseCase;
|
||||
using DynamicData;
|
||||
using DynamicData.Binding;
|
||||
using Presence.Desktop.Models;
|
||||
using ReactiveUI;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using Tmds.DBus.Protocol;
|
||||
|
||||
namespace Presence.Desktop.ViewModels
|
||||
{
|
||||
public class GroupViewModel : ViewModelBase, IRoutableViewModel
|
||||
{
|
||||
private readonly List<GroupPresenter> _groupPresentersDataSource = new List<GroupPresenter>();
|
||||
private ObservableCollection<GroupPresenter> _groups;
|
||||
public ObservableCollection<GroupPresenter> Groups => _groups;
|
||||
|
||||
public GroupPresenter? SelectedGroupItem
|
||||
{
|
||||
get => _selectedGroupItem;
|
||||
set => this.RaiseAndSetIfChanged(ref _selectedGroupItem, value);
|
||||
}
|
||||
|
||||
private GroupPresenter? _selectedGroupItem;
|
||||
|
||||
|
||||
|
||||
public ObservableCollection<UserPresenter> Users { get => _users; }
|
||||
public ObservableCollection<UserPresenter> _users;
|
||||
public GroupViewModel(IGroupUseCase groupUseCase)
|
||||
{
|
||||
foreach (var item in groupUseCase.GetGroupsWithStudents())
|
||||
{
|
||||
GroupPresenter groupPresenter = new GroupPresenter
|
||||
{
|
||||
Id = item.Id,
|
||||
Name = item.Name,
|
||||
users = item.Users?.Select(user => new UserPresenter
|
||||
{
|
||||
Name = user.Name,
|
||||
Guid = user.Guid,
|
||||
Group = new GroupPresenter { Id = item.Id, Name = item.Name }
|
||||
}
|
||||
).ToList()
|
||||
};
|
||||
_groupPresentersDataSource.Add(groupPresenter);
|
||||
}
|
||||
_groups = new ObservableCollection<GroupPresenter>(_groupPresentersDataSource);
|
||||
|
||||
_users = new ObservableCollection<UserPresenter>();
|
||||
|
||||
this.WhenAnyValue(vm => vm.SelectedGroupItem)
|
||||
.Subscribe(_ => SetUsers());
|
||||
|
||||
}
|
||||
|
||||
private void SetUsers()
|
||||
{
|
||||
if (SelectedGroupItem == null) return;
|
||||
if (SelectedGroupItem.users == null) return;
|
||||
Users.Clear();
|
||||
foreach (var item in SelectedGroupItem.users)
|
||||
{
|
||||
Users.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
public string? UrlPathSegment { get; }
|
||||
public IScreen HostScreen { get; }
|
||||
}
|
||||
}
|
@ -1,16 +1,15 @@
|
||||
using System;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ReactiveUI;
|
||||
using domain.UseCase;
|
||||
|
||||
namespace Presence.Desktop.ViewModels;
|
||||
|
||||
public class MainWindowViewModel : ViewModelBase, IScreen
|
||||
namespace Presence.Desktop.ViewModels
|
||||
{
|
||||
public RoutingState Router { get; } = new RoutingState();
|
||||
|
||||
public MainWindowViewModel(IServiceProvider serviceProvider)
|
||||
public class MainWindowViewModel : ViewModelBase
|
||||
{
|
||||
var groupViewModel = serviceProvider.GetRequiredService<GroupViewModel>();
|
||||
Router.Navigate.Execute(groupViewModel);
|
||||
private readonly IGroupUseCase _groupService;
|
||||
public MainWindowViewModel(IGroupUseCase groupService)
|
||||
{
|
||||
_groupService = groupService;
|
||||
}
|
||||
|
||||
public string Greeting { get; } = "Welcome to Avalonia!";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +0,0 @@
|
||||
using ReactiveUI;
|
||||
|
||||
namespace Presence.Desktop.ViewModels;
|
||||
|
||||
public class PresenceViewModel : ViewModelBase, IRoutableViewModel
|
||||
{
|
||||
public string? UrlPathSegment { get; }
|
||||
public IScreen HostScreen { get; }
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
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:vm="using:Presence.Desktop.ViewModels"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Presence.Desktop.GroupView"
|
||||
x:DataType="vm:GroupViewModel">
|
||||
|
||||
<Design.DataContext>
|
||||
<vm:GroupViewModel/>
|
||||
</Design.DataContext>
|
||||
<DockPanel Background="Azure">
|
||||
<StackPanel DockPanel.Dock="Bottom">
|
||||
<TextBlock Text="List ↑" HorizontalAlignment="Center"/>
|
||||
</StackPanel>
|
||||
<StackPanel
|
||||
Spacing="10"
|
||||
HorizontalAlignment="Center"
|
||||
DockPanel.Dock="Top"
|
||||
Orientation="Horizontal">
|
||||
<TextBlock Text="Combobox ->"/>
|
||||
<ComboBox ItemsSource="{Binding Groups}" SelectedValue="{Binding SelectedGroupItem}">
|
||||
<ComboBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding Name}"/>
|
||||
</DataTemplate>
|
||||
</ComboBox.ItemTemplate>
|
||||
</ComboBox>
|
||||
<ComboBox/>
|
||||
<ComboBox/>
|
||||
</StackPanel>
|
||||
<Border>
|
||||
<ListBox Background="Bisque" ItemsSource="{Binding Users}">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Text="{Binding Name}" />
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
</Border>
|
||||
</DockPanel>
|
||||
</UserControl>
|
@ -1,17 +0,0 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.ReactiveUI;
|
||||
using Presence.Desktop.ViewModels;
|
||||
using ReactiveUI;
|
||||
|
||||
namespace Presence.Desktop;
|
||||
|
||||
public partial class GroupView : ReactiveUserControl<GroupViewModel>
|
||||
{
|
||||
public GroupView()
|
||||
{
|
||||
this.WhenActivated(disposables => { });
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
}
|
@ -1,19 +1,20 @@
|
||||
<Window xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:app="clr-namespace:Presence.Desktop"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:vm="using:Presence.Desktop.ViewModels"
|
||||
xmlns:reactiveUi="http://reactiveui.net"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Presence.Desktop.Views.MainWindow"
|
||||
x:DataType="vm:MainWindowViewModel"
|
||||
Title="MainWindow">
|
||||
<DockPanel>
|
||||
<reactiveUi:RoutedViewHost Router="{Binding Router}" DockPanel.Dock="Right" Background="AliceBlue">
|
||||
<reactiveUi:RoutedViewHost.ViewLocator>
|
||||
<app:ViewLocator/>
|
||||
</reactiveUi:RoutedViewHost.ViewLocator>
|
||||
</reactiveUi:RoutedViewHost>
|
||||
</DockPanel>
|
||||
Icon="/Assets/avalonia-logo.ico"
|
||||
Title="Presence.Desktop">
|
||||
|
||||
<Design.DataContext>
|
||||
<!-- This only sets the DataContext for the previewer in an IDE,
|
||||
to set the actual DataContext for runtime, set the DataContext property in code (look at App.axaml.cs) -->
|
||||
<vm:MainWindowViewModel/>
|
||||
</Design.DataContext>
|
||||
|
||||
<TextBlock Text="{Binding Greeting}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
|
||||
</Window>
|
||||
|
@ -1,18 +1,12 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.ReactiveUI;
|
||||
using Presence.Desktop.ViewModels;
|
||||
using ReactiveUI;
|
||||
|
||||
namespace Presence.Desktop.Views;
|
||||
|
||||
public partial class MainWindow : ReactiveWindow<MainWindowViewModel>
|
||||
namespace Presence.Desktop.Views
|
||||
{
|
||||
public MainWindow()
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
this.WhenActivated(disposables => { });
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
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"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Presence.Desktop.Views.PresenceView">
|
||||
Welcome to Avalonia!
|
||||
</UserControl>
|
@ -1,17 +0,0 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.ReactiveUI;
|
||||
using Presence.Desktop.ViewModels;
|
||||
using ReactiveUI;
|
||||
|
||||
namespace Presence.Desktop.Views;
|
||||
|
||||
public partial class PresenceView : ReactiveUserControl<PresenceViewModel>
|
||||
{
|
||||
public PresenceView()
|
||||
{
|
||||
this.WhenActivated(disposables => { });
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
}
|
@ -10,7 +10,6 @@ namespace data.Repository
|
||||
public interface IGroupRepository
|
||||
{
|
||||
public IEnumerable<GroupDAO> getAllGroup();
|
||||
public Task<IEnumerable<GroupDAO>> getAllGroupAsync();
|
||||
public bool addGroup(GroupDAO group);
|
||||
public bool addGroupWithStudents(GroupDAO group, IEnumerable<UserDAO> userDAOs);
|
||||
}
|
||||
|
@ -59,10 +59,5 @@ namespace data.Repository
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<GroupDAO>> getAllGroupAsync()
|
||||
{
|
||||
return await dbContext.groups.Include(group => group.Users).ToListAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ namespace domain.Entity
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public List<UserEntity> Users { get; set; } = null;
|
||||
public IEnumerable<UserEntity> Users { get; set; } = null;
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -52,28 +52,5 @@ namespace domain.Service
|
||||
}).ToList()
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<GroupEntity>> GetGroupsWithStudentsAsync()
|
||||
{
|
||||
var result = await _groupRepository.getAllGroupAsync();
|
||||
|
||||
return result.Select(
|
||||
group => new GroupEntity
|
||||
{
|
||||
Id = group.Id,
|
||||
Name = group.Name,
|
||||
Users = group.Users.Select(
|
||||
user => new UserEntity
|
||||
{
|
||||
Guid = user.Guid,
|
||||
Name = user.Name,
|
||||
Group = new GroupEntity
|
||||
{
|
||||
Id = group.Id,
|
||||
Name = group.Name,
|
||||
}
|
||||
}).ToList()
|
||||
}).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,6 @@ namespace domain.UseCase
|
||||
public interface IGroupUseCase
|
||||
{
|
||||
public IEnumerable<GroupEntity> GetGroupsWithStudents();
|
||||
public Task<IEnumerable<GroupEntity>> GetGroupsWithStudentsAsync();
|
||||
public void AddGroup(AddGroupRequest addGroupRequest);
|
||||
public void AddGroupWithStudents(AddGroupWithStudentsRequest addGroupWithStudents);
|
||||
}
|
||||
|
@ -7,14 +7,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "console_ui", "console_ui\co
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "data", "data\data.csproj", "{28FE5F1E-5D2B-4750-AE24-A15BB8A5972D}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "domain", "domain\domain.csproj", "{78C8AC9B-2B4D-4C71-8469-C6DAE16C9A63}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Presence.Api", "Presence.Api\Presence.Api.csproj", "{0493354A-C0C0-49FC-A143-28F2268309E2}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{78C8AC9B-2B4D-4C71-8469-C6DAE16C9A63} = {78C8AC9B-2B4D-4C71-8469-C6DAE16C9A63}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Presence.Desktop", "Presence.Desktop\Presence.Desktop.csproj", "{D646BC7E-8025-4985-AF9B-5E4474AD7F66}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "domain", "domain\domain.csproj", "{78C8AC9B-2B4D-4C71-8469-C6DAE16C9A63}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -34,14 +27,6 @@ Global
|
||||
{78C8AC9B-2B4D-4C71-8469-C6DAE16C9A63}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{78C8AC9B-2B4D-4C71-8469-C6DAE16C9A63}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{78C8AC9B-2B4D-4C71-8469-C6DAE16C9A63}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{0493354A-C0C0-49FC-A143-28F2268309E2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{0493354A-C0C0-49FC-A143-28F2268309E2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{0493354A-C0C0-49FC-A143-28F2268309E2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{0493354A-C0C0-49FC-A143-28F2268309E2}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{D646BC7E-8025-4985-AF9B-5E4474AD7F66}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{D646BC7E-8025-4985-AF9B-5E4474AD7F66}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{D646BC7E-8025-4985-AF9B-5E4474AD7F66}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{D646BC7E-8025-4985-AF9B-5E4474AD7F66}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
Loading…
Reference in New Issue
Block a user