set-refresh-changes-and-filepicker
This commit is contained in:
parent
255a13337b
commit
61d110fd62
@ -1,5 +1,7 @@
|
|||||||
using domain.Service;
|
using domain.Service;
|
||||||
using domain.UseCase;
|
using domain.UseCase;
|
||||||
|
using domain.Request;
|
||||||
|
using domain.Service;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Presence.Api.Response;
|
using Presence.Api.Response;
|
||||||
|
|
||||||
@ -32,5 +34,12 @@ namespace Presence.Api.Controllers
|
|||||||
}).ToList();
|
}).ToList();
|
||||||
return Ok(new GroupResponse());
|
return Ok(new GroupResponse());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpPost("/admin/{groupId}/students")]
|
||||||
|
public void AddGroup(int groupId, [FromBody] AddGroupRequest addGroupRequest)
|
||||||
|
{
|
||||||
|
Console.WriteLine(groupId);
|
||||||
|
_groupService.AddGroup(addGroupRequest);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
using domain.UseCase;
|
using domain.UseCase;
|
||||||
using DynamicData;
|
|
||||||
using DynamicData.Binding;
|
|
||||||
using Presence.Desktop.Models;
|
using Presence.Desktop.Models;
|
||||||
using ReactiveUI;
|
using ReactiveUI;
|
||||||
using System;
|
using System;
|
||||||
@ -8,12 +6,23 @@ using System.Collections.Generic;
|
|||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reactive.Linq;
|
using System.Reactive.Linq;
|
||||||
using Tmds.DBus.Protocol;
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Input;
|
||||||
|
|
||||||
namespace Presence.Desktop.ViewModels
|
namespace Presence.Desktop.ViewModels
|
||||||
{
|
{
|
||||||
public class GroupViewModel : ViewModelBase, IRoutableViewModel
|
public class GroupViewModel : ViewModelBase, IRoutableViewModel
|
||||||
{
|
{
|
||||||
|
public ICommand OpenFileDialog { get; }
|
||||||
|
public Interaction<string?, string?> SelectFileInteraction => _SelectFileInteraction;
|
||||||
|
public readonly Interaction<string?, string?> _SelectFileInteraction;
|
||||||
|
private string? _selectedFile;
|
||||||
|
public string? SelectedFile
|
||||||
|
{
|
||||||
|
get => _selectedFile;
|
||||||
|
set => this.RaiseAndSetIfChanged(ref _selectedFile, value);
|
||||||
|
}
|
||||||
|
|
||||||
private readonly List<GroupPresenter> _groupPresentersDataSource = new List<GroupPresenter>();
|
private readonly List<GroupPresenter> _groupPresentersDataSource = new List<GroupPresenter>();
|
||||||
private ObservableCollection<GroupPresenter> _groups;
|
private ObservableCollection<GroupPresenter> _groups;
|
||||||
public ObservableCollection<GroupPresenter> Groups => _groups;
|
public ObservableCollection<GroupPresenter> Groups => _groups;
|
||||||
@ -27,12 +36,40 @@ namespace Presence.Desktop.ViewModels
|
|||||||
private GroupPresenter? _selectedGroupItem;
|
private GroupPresenter? _selectedGroupItem;
|
||||||
|
|
||||||
|
|
||||||
|
private IGroupUseCase _groupUseCase;
|
||||||
public ObservableCollection<UserPresenter> Users { get => _users; }
|
public ObservableCollection<UserPresenter> Users { get => _users; }
|
||||||
public ObservableCollection<UserPresenter> _users;
|
public ObservableCollection<UserPresenter> _users;
|
||||||
public GroupViewModel(IGroupUseCase groupUseCase)
|
public GroupViewModel(IGroupUseCase groupUseCase)
|
||||||
{
|
{
|
||||||
foreach (var item in groupUseCase.GetGroupsWithStudents())
|
_groupUseCase = groupUseCase;
|
||||||
|
_SelectFileInteraction = new Interaction<string?, string?>();
|
||||||
|
OpenFileDialog = ReactiveCommand.CreateFromTask(SelectFile);
|
||||||
|
_users = new ObservableCollection<UserPresenter>();
|
||||||
|
RefreshGroups();
|
||||||
|
this.WhenAnyValue(vm => vm.SelectedGroupItem)
|
||||||
|
.Subscribe(_ =>
|
||||||
|
{
|
||||||
|
RefreshGroups();
|
||||||
|
SetUsers();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetUsers()
|
||||||
|
{
|
||||||
|
if (SelectedGroupItem == null) return;
|
||||||
|
Users.Clear();
|
||||||
|
var group = _groups.First(it => it.Id == SelectedGroupItem.Id);
|
||||||
|
if (group.users == null) return;
|
||||||
|
foreach (var item in group.users)
|
||||||
|
{
|
||||||
|
Users.Add(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RefreshGroups()
|
||||||
|
{
|
||||||
|
_groupPresentersDataSource.Clear();
|
||||||
|
foreach (var item in _groupUseCase.GetGroupsWithStudents())
|
||||||
{
|
{
|
||||||
GroupPresenter groupPresenter = new GroupPresenter
|
GroupPresenter groupPresenter = new GroupPresenter
|
||||||
{
|
{
|
||||||
@ -49,26 +86,15 @@ namespace Presence.Desktop.ViewModels
|
|||||||
_groupPresentersDataSource.Add(groupPresenter);
|
_groupPresentersDataSource.Add(groupPresenter);
|
||||||
}
|
}
|
||||||
_groups = new ObservableCollection<GroupPresenter>(_groupPresentersDataSource);
|
_groups = new ObservableCollection<GroupPresenter>(_groupPresentersDataSource);
|
||||||
|
|
||||||
_users = new ObservableCollection<UserPresenter>();
|
|
||||||
|
|
||||||
this.WhenAnyValue(vm => vm.SelectedGroupItem)
|
|
||||||
.Subscribe(_ => SetUsers());
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetUsers()
|
private async Task SelectFile()
|
||||||
{
|
{
|
||||||
if (SelectedGroupItem == null) return;
|
Console.WriteLine("clock");
|
||||||
if (SelectedGroupItem.users == null) return;
|
SelectedFile = await _SelectFileInteraction.Handle("Chose csv file");
|
||||||
Users.Clear();
|
|
||||||
foreach (var item in SelectedGroupItem.users)
|
|
||||||
{
|
|
||||||
Users.Add(item);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public string? UrlPathSegment { get; }
|
public string? UrlPathSegment { get; }
|
||||||
public IScreen HostScreen { get; }
|
public IScreen HostScreen { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:vm="using:Presence.Desktop.ViewModels"
|
xmlns:vm="using:Presence.Desktop.ViewModels"
|
||||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
x:Class="Presence.Desktop.GroupView"
|
x:Class="Presence.Desktop.Views.GroupView"
|
||||||
x:DataType="vm:GroupViewModel">
|
x:DataType="vm:GroupViewModel">
|
||||||
|
|
||||||
<Design.DataContext>
|
<Design.DataContext>
|
||||||
@ -27,7 +27,7 @@
|
|||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
</ComboBox.ItemTemplate>
|
</ComboBox.ItemTemplate>
|
||||||
</ComboBox>
|
</ComboBox>
|
||||||
<ComboBox/>
|
<Button Width="100" Command="{Binding OpenFileDialog}"/>
|
||||||
<ComboBox/>
|
<ComboBox/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
<Border>
|
<Border>
|
||||||
|
@ -1,17 +1,37 @@
|
|||||||
using Avalonia;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Markup.Xaml;
|
using Avalonia.Markup.Xaml;
|
||||||
|
using Avalonia.Platform.Storage;
|
||||||
using Avalonia.ReactiveUI;
|
using Avalonia.ReactiveUI;
|
||||||
using Presence.Desktop.ViewModels;
|
using Presence.Desktop.ViewModels;
|
||||||
using ReactiveUI;
|
using ReactiveUI;
|
||||||
|
|
||||||
namespace Presence.Desktop;
|
namespace Presence.Desktop.Views
|
||||||
|
|
||||||
public partial class GroupView : ReactiveUserControl<GroupViewModel>
|
|
||||||
{
|
{
|
||||||
public GroupView()
|
public partial class GroupView : ReactiveUserControl<GroupViewModel>
|
||||||
{
|
{
|
||||||
this.WhenActivated(disposables => { });
|
public GroupView()
|
||||||
AvaloniaXamlLoader.Load(this);
|
{
|
||||||
|
this.WhenActivated(action =>
|
||||||
|
{
|
||||||
|
action(ViewModel!.SelectFileInteraction.RegisterHandler(ShowFileDialog));
|
||||||
|
});
|
||||||
|
AvaloniaXamlLoader.Load(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task ShowFileDialog(IInteractionContext<string?, string?> context)
|
||||||
|
{
|
||||||
|
var topLevel = TopLevel.GetTopLevel(this);
|
||||||
|
var storageFile = await topLevel.StorageProvider.OpenFilePickerAsync(
|
||||||
|
new FilePickerOpenOptions()
|
||||||
|
{
|
||||||
|
AllowMultiple = false,
|
||||||
|
Title = context.Input
|
||||||
|
}
|
||||||
|
);
|
||||||
|
context.SetOutput(storageFile.First().Path.ToString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user