feat: Add main application views and structure
Some checks failed
Build and Publish Docker Image / build-and-push (push) Has been cancelled
Some checks failed
Build and Publish Docker Image / build-and-push (push) Has been cancelled
- Implemented CreateInstanceView for creating new instances. - Added HostsView for managing SSH hosts with CRUD operations. - Created InstancesView for displaying and managing instances. - Developed LogsView for viewing operation logs. - Introduced SecretsView for managing secrets associated with hosts. - Established SettingsView for configuring application settings. - Created MainWindow as the main application window with navigation. - Added app manifest and configuration files for logging and settings.
This commit is contained in:
56
OTSSignsOrchestrator.Desktop/ViewModels/LogsViewModel.cs
Normal file
56
OTSSignsOrchestrator.Desktop/ViewModels/LogsViewModel.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using OTSSignsOrchestrator.Core.Data;
|
||||
using OTSSignsOrchestrator.Core.Models.Entities;
|
||||
|
||||
namespace OTSSignsOrchestrator.Desktop.ViewModels;
|
||||
|
||||
/// <summary>
|
||||
/// ViewModel for viewing operation logs.
|
||||
/// </summary>
|
||||
public partial class LogsViewModel : ObservableObject
|
||||
{
|
||||
private readonly IServiceProvider _services;
|
||||
|
||||
[ObservableProperty] private ObservableCollection<OperationLog> _logs = new();
|
||||
[ObservableProperty] private string _statusMessage = string.Empty;
|
||||
[ObservableProperty] private bool _isBusy;
|
||||
[ObservableProperty] private int _maxEntries = 100;
|
||||
|
||||
public LogsViewModel(IServiceProvider services)
|
||||
{
|
||||
_services = services;
|
||||
_ = LoadLogsAsync();
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private async Task LoadLogsAsync()
|
||||
{
|
||||
IsBusy = true;
|
||||
try
|
||||
{
|
||||
using var scope = _services.CreateScope();
|
||||
var db = scope.ServiceProvider.GetRequiredService<XiboContext>();
|
||||
|
||||
var items = await db.OperationLogs
|
||||
.Include(l => l.Instance)
|
||||
.OrderByDescending(l => l.Timestamp)
|
||||
.Take(MaxEntries)
|
||||
.ToListAsync();
|
||||
|
||||
Logs = new ObservableCollection<OperationLog>(items);
|
||||
StatusMessage = $"Showing {items.Count} log entries.";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
StatusMessage = $"Error loading logs: {ex.Message}";
|
||||
}
|
||||
finally
|
||||
{
|
||||
IsBusy = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user