6 Commits

Author SHA1 Message Date
d405677420 Merge pull request #10 from frosch95/pr-9
Refresh button for the file list
2023-10-09 20:30:31 +02:00
0e979fad5f Closes #9 : Refresh button for the file list 2023-10-09 20:29:40 +02:00
6754210e9b Merge pull request #7 from frosch95/pr-6
Sort properties in alphabatically order
2023-10-05 14:37:30 +02:00
0d11fdd000 Closes #6 Sort properties in alphabatically order 2023-10-05 14:22:18 +02:00
b33552531a remember last chosen local directory 2023-08-28 20:26:41 +02:00
7f7471d47b show message also in ui thread 2023-08-14 20:30:25 +02:00
3 changed files with 78 additions and 39 deletions

View File

@@ -9,7 +9,7 @@
<Configurations>Debug;Release</Configurations>
<Platforms>AnyCPU</Platforms>
<ApplicationIcon>Assets/app.ico</ApplicationIcon>
<Version>0.0.9</Version>
<Version>0.1.2</Version>
<RuntimeIdentifiers>win-x64;linux-x64</RuntimeIdentifiers>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">

View File

@@ -21,7 +21,7 @@ public class MainWindowViewModel : ViewModelBase
#region Properties
[Reactive]
public string? Version { get; set; } = null!;
public string? Version { get; set; }
[Reactive]
public IEnumerable<ClusterContext> ClusterContexts { get; set; } = null!;
@@ -59,12 +59,15 @@ public class MainWindowViewModel : ViewModelBase
[Reactive]
public Message Message { get; set; } = null!;
private string _lastDirectory = ".";
#endregion Properties
#region Commands
public ReactiveCommand<Unit, Unit> DownloadCommand { get; private set; } = null!;
public ReactiveCommand<Unit, Unit> DownloadLogCommand { get; private set; } = null!;
public ReactiveCommand<Unit, Unit> RefreshCommand { get; private set; } = null!;
public ReactiveCommand<Unit, Unit> ParentCommand { get; private set; } = null!;
public ReactiveCommand<Unit, Unit> OpenCommand { get; private set; } = null!;
private ReactiveCommand<Namespace, IEnumerable<Pod>> GetPodsForNamespace { get; set; } = null!;
@@ -80,6 +83,7 @@ public class MainWindowViewModel : ViewModelBase
// commands
ConfigureOpenDirectoryCommand();
ConfigureDownloadFileCommand(kubernetesService);
ConfigureRefreshCommand(kubernetesService);
ConfigureDownloadLogCommand(kubernetesService);
ConfigureParentDirectoryCommand();
ConfigureGetPodsForNamespaceCommand(kubernetesService);
@@ -108,7 +112,7 @@ public class MainWindowViewModel : ViewModelBase
.Subscribe(x =>
{
ResetNamespaces();
ClusterContexts = x;
ClusterContexts = x.OrderBy(c => c.Name);
// select the current cluster context
SelectedClusterContext = ClusterContexts
@@ -127,7 +131,7 @@ public class MainWindowViewModel : ViewModelBase
.Subscribe(ns =>
{
ResetPods();
Namespaces = ns;
Namespaces = ns.OrderBy(n => n.Name);
});
}
@@ -143,7 +147,7 @@ public class MainWindowViewModel : ViewModelBase
.Subscribe(x =>
{
ResetContainers();
Pods = x;
Pods = x.OrderBy(p => p.Name);
});
}
@@ -232,9 +236,10 @@ public class MainWindowViewModel : ViewModelBase
await Observable.StartAsync(async () =>
{
var fileName = SelectedPod?.Name + ".log";
var saveFileName = await ApplicationHelper.SaveFile(".", fileName);
var saveFileName = await ApplicationHelper.SaveFile(_lastDirectory, fileName);
if (saveFileName != null)
{
SetLastDirectory(saveFileName);
ShowWorkingMessage("Downloading Log...");
await kubernetesService.DownloadLog(SelectedNamespace, SelectedPod, SelectedContainer, saveFileName);
HideWorkingMessage();
@@ -246,6 +251,24 @@ public class MainWindowViewModel : ViewModelBase
.Subscribe(ShowErrorMessage);
}
private void ConfigureRefreshCommand(IKubernetesService kubernetesService)
{
var isSelectedContainer = this
.WhenAnyValue(x => x.SelectedContainer)
.Select(x => x != null);
RefreshCommand = ReactiveCommand.CreateFromTask(async () =>
{
await Observable.Start(() =>
{
FileInformation = GetFileInformation(kubernetesService, SelectedPath!, SelectedPod!, SelectedNamespace!, SelectedContainer!);
}, RxApp.TaskpoolScheduler);
}, isSelectedContainer, RxApp.MainThreadScheduler);
RefreshCommand.ThrownExceptions.ObserveOn(RxApp.MainThreadScheduler)
.Subscribe(ShowErrorMessage);
}
private void ConfigureDownloadFileCommand(IKubernetesService kubernetesService)
{
var isFile = this
@@ -258,9 +281,10 @@ public class MainWindowViewModel : ViewModelBase
{
var fileName = SelectedFile!.Name.Substring(SelectedFile!.Name.LastIndexOf('/') + 1,
SelectedFile!.Name.Length - SelectedFile!.Name.LastIndexOf('/') - 1);
var saveFileName = await ApplicationHelper.SaveFile(".", fileName);
var saveFileName = await ApplicationHelper.SaveFile(_lastDirectory, fileName);
if (saveFileName != null)
{
SetLastDirectory(saveFileName);
ShowWorkingMessage("Downloading File...");
await kubernetesService.DownloadFile(SelectedNamespace, SelectedPod, SelectedContainer, SelectedFile, saveFileName);
HideWorkingMessage();
@@ -272,6 +296,11 @@ public class MainWindowViewModel : ViewModelBase
.Subscribe(ShowErrorMessage);
}
private void SetLastDirectory(string saveFileName)
{
_lastDirectory = saveFileName.Substring(0, saveFileName.LastIndexOf('\\'));
}
private void ConfigureOpenDirectoryCommand()
{
var isDirectory = this
@@ -387,24 +416,31 @@ public class MainWindowViewModel : ViewModelBase
private void ShowWorkingMessage(string message)
{
Message = new Message
RxApp.MainThreadScheduler.Schedule(Action);
return;
void Action()
{
IsVisible = true,
Text = message,
IsError = false
};
Message = new Message
{
IsVisible = true,
Text = message,
IsError = false
};
}
}
private void ShowErrorMessage(string message)
{
RxApp.MainThreadScheduler.Schedule(Action);
return;
async void Action()
{
Message = new Message { IsVisible = true, Text = message, IsError = true };
await Task.Delay(7000);
HideWorkingMessage();
}
RxApp.MainThreadScheduler.Schedule(Action);
}
private void ShowErrorMessage(Exception exception)

View File

@@ -94,6 +94,9 @@
<Button Command="{Binding DownloadLogCommand}" VerticalAlignment="Center" ToolTip.Tip="Download Container Log" Margin="0 0 48 0 ">
<PathIcon Data="{StaticResource document_one_page_regular}"></PathIcon>
</Button>
<Button Command="{Binding RefreshCommand}" VerticalAlignment="Center" ToolTip.Tip="Refresh Directory">
<PathIcon Data="{StaticResource arrow_sync_circle_regular}"></PathIcon>
</Button>
<Button Command="{Binding ParentCommand}" VerticalAlignment="Center" ToolTip.Tip="Go To Parent Directory">
<PathIcon Data="{StaticResource arrow_curve_up_left_regular}"></PathIcon>
</Button>