chore: release v2.4
- Add theme system (Dark/Light palettes, ModernTheme, ThemeManager) - Add InputDialog, Spinner common view - Add DuplicatesCsvExportService - Refresh views, dialogs, and view models across tabs - Update localization strings (en/fr) - Tweak services (transfer, permissions, search, user access, ownership elevation, bulk operations) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -9,6 +9,7 @@ using LiveChartsCore.SkiaSharpView.Painting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Win32;
|
||||
using SharepointToolbox.Core.Models;
|
||||
using SharepointToolbox.Localization;
|
||||
using SharepointToolbox.Services;
|
||||
using SharepointToolbox.Services.Export;
|
||||
using SkiaSharp;
|
||||
@@ -22,6 +23,9 @@ public partial class StorageViewModel : FeatureViewModelBase
|
||||
private readonly StorageCsvExportService _csvExportService;
|
||||
private readonly StorageHtmlExportService _htmlExportService;
|
||||
private readonly IBrandingService? _brandingService;
|
||||
private readonly IOwnershipElevationService? _ownershipService;
|
||||
private readonly SettingsService? _settingsService;
|
||||
private readonly ThemeManager? _themeManager;
|
||||
private readonly ILogger<FeatureViewModelBase> _logger;
|
||||
private TenantProfile? _currentProfile;
|
||||
|
||||
@@ -37,6 +41,14 @@ public partial class StorageViewModel : FeatureViewModelBase
|
||||
[ObservableProperty]
|
||||
private bool _isDonutChart = true;
|
||||
|
||||
/// <summary>0 = Single file, 1 = Split by site.</summary>
|
||||
[ObservableProperty] private int _splitModeIndex;
|
||||
/// <summary>0 = Separate HTML files, 1 = Single tabbed HTML.</summary>
|
||||
[ObservableProperty] private int _htmlLayoutIndex;
|
||||
|
||||
private ReportSplitMode CurrentSplit => SplitModeIndex == 1 ? ReportSplitMode.BySite : ReportSplitMode.Single;
|
||||
private HtmlSplitLayout CurrentLayout => HtmlLayoutIndex == 1 ? HtmlSplitLayout.SingleTabbed : HtmlSplitLayout.SeparateFiles;
|
||||
|
||||
private ObservableCollection<FileTypeMetric> _fileTypeMetrics = new();
|
||||
public ObservableCollection<FileTypeMetric> FileTypeMetrics
|
||||
{
|
||||
@@ -79,6 +91,15 @@ public partial class StorageViewModel : FeatureViewModelBase
|
||||
private set { _barYAxes = value; OnPropertyChanged(); }
|
||||
}
|
||||
|
||||
// Stable paint instances. SKDefaultTooltip/Legend bake the Fill paint reference
|
||||
// into their geometry on first Initialize() and never re-read the chart's paint
|
||||
// properties. Replacing instances on theme change has no effect — we mutate
|
||||
// .Color in place so the new theme color renders on the next frame.
|
||||
public SolidColorPaint LegendTextPaint { get; } = new(default(SKColor));
|
||||
public SolidColorPaint LegendBackgroundPaint { get; } = new(default(SKColor));
|
||||
public SolidColorPaint TooltipTextPaint { get; } = new(default(SKColor));
|
||||
public SolidColorPaint TooltipBackgroundPaint { get; } = new(default(SKColor));
|
||||
|
||||
public bool IsMaxDepth
|
||||
{
|
||||
get => FolderDepth >= 999;
|
||||
@@ -136,7 +157,10 @@ public partial class StorageViewModel : FeatureViewModelBase
|
||||
StorageCsvExportService csvExportService,
|
||||
StorageHtmlExportService htmlExportService,
|
||||
IBrandingService brandingService,
|
||||
ILogger<FeatureViewModelBase> logger)
|
||||
ILogger<FeatureViewModelBase> logger,
|
||||
IOwnershipElevationService? ownershipService = null,
|
||||
SettingsService? settingsService = null,
|
||||
ThemeManager? themeManager = null)
|
||||
: base(logger)
|
||||
{
|
||||
_storageService = storageService;
|
||||
@@ -144,10 +168,17 @@ public partial class StorageViewModel : FeatureViewModelBase
|
||||
_csvExportService = csvExportService;
|
||||
_htmlExportService = htmlExportService;
|
||||
_brandingService = brandingService;
|
||||
_ownershipService = ownershipService;
|
||||
_settingsService = settingsService;
|
||||
_themeManager = themeManager;
|
||||
_logger = logger;
|
||||
|
||||
ExportCsvCommand = new AsyncRelayCommand(ExportCsvAsync, CanExport);
|
||||
ExportHtmlCommand = new AsyncRelayCommand(ExportHtmlAsync, CanExport);
|
||||
|
||||
ApplyChartThemeColors();
|
||||
if (_themeManager is not null)
|
||||
_themeManager.ThemeChanged += (_, _) => UpdateChartSeries();
|
||||
}
|
||||
|
||||
/// <summary>Test constructor — omits export services.</summary>
|
||||
@@ -173,14 +204,14 @@ public partial class StorageViewModel : FeatureViewModelBase
|
||||
{
|
||||
if (_currentProfile == null)
|
||||
{
|
||||
StatusMessage = "No tenant selected. Please connect to a tenant first.";
|
||||
StatusMessage = TranslationSource.Instance["err.no_tenant_connected"];
|
||||
return;
|
||||
}
|
||||
|
||||
var urls = GlobalSites.Select(s => s.Url).Where(u => !string.IsNullOrWhiteSpace(u)).ToList();
|
||||
if (urls.Count == 0)
|
||||
{
|
||||
StatusMessage = "Select at least one site from the toolbar.";
|
||||
StatusMessage = TranslationSource.Instance["err.no_sites_selected"];
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -194,6 +225,8 @@ public partial class StorageViewModel : FeatureViewModelBase
|
||||
var allNodes = new List<StorageNode>();
|
||||
var allTypeMetrics = new List<FileTypeMetric>();
|
||||
|
||||
var autoOwnership = await IsAutoTakeOwnershipEnabled();
|
||||
|
||||
int i = 0;
|
||||
foreach (var url in nonEmpty)
|
||||
{
|
||||
@@ -207,9 +240,30 @@ public partial class StorageViewModel : FeatureViewModelBase
|
||||
ClientId = _currentProfile.ClientId,
|
||||
Name = _currentProfile.Name
|
||||
};
|
||||
|
||||
var ctx = await _sessionManager.GetOrCreateContextAsync(siteProfile, ct);
|
||||
|
||||
var nodes = await _storageService.CollectStorageAsync(ctx, options, progress, ct);
|
||||
IReadOnlyList<StorageNode> nodes;
|
||||
try
|
||||
{
|
||||
nodes = await _storageService.CollectStorageAsync(ctx, options, progress, ct);
|
||||
}
|
||||
catch (Microsoft.SharePoint.Client.ServerUnauthorizedAccessException) when (_ownershipService != null && autoOwnership)
|
||||
{
|
||||
_logger.LogWarning("Access denied on {Url}, auto-elevating ownership...", url);
|
||||
var adminUrl = DeriveAdminUrl(_currentProfile.TenantUrl ?? url);
|
||||
var adminProfile = new TenantProfile
|
||||
{
|
||||
TenantUrl = adminUrl,
|
||||
ClientId = _currentProfile.ClientId,
|
||||
Name = _currentProfile.Name
|
||||
};
|
||||
var adminCtx = await _sessionManager.GetOrCreateContextAsync(adminProfile, ct);
|
||||
await _ownershipService.ElevateAsync(adminCtx, url, string.Empty, ct);
|
||||
|
||||
ctx = await _sessionManager.GetOrCreateContextAsync(siteProfile, ct);
|
||||
nodes = await _storageService.CollectStorageAsync(ctx, options, progress, ct);
|
||||
}
|
||||
|
||||
// Backfill any libraries where StorageMetrics returned zeros
|
||||
await _storageService.BackfillZeroNodesAsync(ctx, nodes, progress, ct);
|
||||
@@ -258,6 +312,24 @@ public partial class StorageViewModel : FeatureViewModelBase
|
||||
ExportHtmlCommand.NotifyCanExecuteChanged();
|
||||
}
|
||||
|
||||
private async Task<bool> IsAutoTakeOwnershipEnabled()
|
||||
{
|
||||
if (_settingsService == null) return false;
|
||||
var settings = await _settingsService.GetSettingsAsync();
|
||||
return settings.AutoTakeOwnership;
|
||||
}
|
||||
|
||||
internal static string DeriveAdminUrl(string tenantUrl)
|
||||
{
|
||||
var uri = new Uri(tenantUrl.TrimEnd('/'));
|
||||
var host = uri.Host;
|
||||
if (host.Contains("-admin.sharepoint.com", StringComparison.OrdinalIgnoreCase))
|
||||
return tenantUrl;
|
||||
var adminHost = host.Replace(".sharepoint.com", "-admin.sharepoint.com",
|
||||
StringComparison.OrdinalIgnoreCase);
|
||||
return $"{uri.Scheme}://{adminHost}";
|
||||
}
|
||||
|
||||
internal void SetCurrentProfile(TenantProfile profile) => _currentProfile = profile;
|
||||
|
||||
internal Task TestRunOperationAsync(CancellationToken ct, IProgress<OperationProgress> progress)
|
||||
@@ -278,7 +350,7 @@ public partial class StorageViewModel : FeatureViewModelBase
|
||||
if (dialog.ShowDialog() != true) return;
|
||||
try
|
||||
{
|
||||
await _csvExportService.WriteAsync(Results, FileTypeMetrics, dialog.FileName, CancellationToken.None);
|
||||
await _csvExportService.WriteAsync(Results, FileTypeMetrics, dialog.FileName, CurrentSplit, CancellationToken.None);
|
||||
OpenFile(dialog.FileName);
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -309,7 +381,7 @@ public partial class StorageViewModel : FeatureViewModelBase
|
||||
branding = new ReportBranding(mspLogo, clientLogo);
|
||||
}
|
||||
|
||||
await _htmlExportService.WriteAsync(Results, FileTypeMetrics, dialog.FileName, CancellationToken.None, branding);
|
||||
await _htmlExportService.WriteAsync(Results, FileTypeMetrics, dialog.FileName, CurrentSplit, CurrentLayout, CancellationToken.None, branding);
|
||||
OpenFile(dialog.FileName);
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -324,11 +396,25 @@ public partial class StorageViewModel : FeatureViewModelBase
|
||||
UpdateChartSeries();
|
||||
}
|
||||
|
||||
private SKColor ChartFgColor => (_themeManager?.IsDarkActive ?? false) ? new SKColor(0xE7, 0xEA, 0xF1) : new SKColor(0x1F, 0x24, 0x30);
|
||||
private SKColor ChartSeparatorColor => (_themeManager?.IsDarkActive ?? false) ? new SKColor(0x32, 0x38, 0x49) : new SKColor(0xE3, 0xE6, 0xEC);
|
||||
private SKColor ChartSurfaceColor => (_themeManager?.IsDarkActive ?? false) ? new SKColor(0x1E, 0x22, 0x30) : new SKColor(0xFF, 0xFF, 0xFF);
|
||||
|
||||
private void ApplyChartThemeColors()
|
||||
{
|
||||
LegendTextPaint.Color = ChartFgColor;
|
||||
LegendBackgroundPaint.Color = ChartSurfaceColor;
|
||||
TooltipTextPaint.Color = ChartFgColor;
|
||||
TooltipBackgroundPaint.Color = ChartSurfaceColor;
|
||||
}
|
||||
|
||||
private void UpdateChartSeries()
|
||||
{
|
||||
var metrics = FileTypeMetrics.ToList();
|
||||
OnPropertyChanged(nameof(HasChartData));
|
||||
|
||||
ApplyChartThemeColors();
|
||||
|
||||
if (metrics.Count == 0)
|
||||
{
|
||||
PieChartSeries = Enumerable.Empty<ISeries>();
|
||||
@@ -361,6 +447,7 @@ public partial class StorageViewModel : FeatureViewModelBase
|
||||
HoverPushout = 8,
|
||||
MaxRadialColumnWidth = 60,
|
||||
DataLabelsFormatter = _ => m.DisplayLabel,
|
||||
DataLabelsPaint = new SolidColorPaint(ChartFgColor),
|
||||
ToolTipLabelFormatter = _ =>
|
||||
$"{m.DisplayLabel}: {FormatBytes(m.TotalSizeBytes)} ({m.FileCount} files)",
|
||||
IsVisibleAtLegend = true,
|
||||
@@ -379,7 +466,8 @@ public partial class StorageViewModel : FeatureViewModelBase
|
||||
{
|
||||
int idx = (int)point.Index;
|
||||
return idx < chartItems.Count ? FormatBytes(chartItems[idx].TotalSizeBytes) : "";
|
||||
}
|
||||
},
|
||||
DataLabelsPaint = new SolidColorPaint(ChartFgColor)
|
||||
}
|
||||
};
|
||||
|
||||
@@ -388,7 +476,10 @@ public partial class StorageViewModel : FeatureViewModelBase
|
||||
new Axis
|
||||
{
|
||||
Labels = chartItems.Select(m => m.DisplayLabel).ToArray(),
|
||||
LabelsRotation = -45
|
||||
LabelsRotation = -45,
|
||||
LabelsPaint = new SolidColorPaint(ChartFgColor),
|
||||
TicksPaint = new SolidColorPaint(ChartFgColor),
|
||||
SeparatorsPaint = new SolidColorPaint(ChartSeparatorColor)
|
||||
}
|
||||
};
|
||||
|
||||
@@ -396,7 +487,10 @@ public partial class StorageViewModel : FeatureViewModelBase
|
||||
{
|
||||
new Axis
|
||||
{
|
||||
Labeler = value => FormatBytes((long)value)
|
||||
Labeler = value => FormatBytes((long)value),
|
||||
LabelsPaint = new SolidColorPaint(ChartFgColor),
|
||||
TicksPaint = new SolidColorPaint(ChartFgColor),
|
||||
SeparatorsPaint = new SolidColorPaint(ChartSeparatorColor)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user