|
1 | 1 | using Microsoft.UI.Xaml; |
2 | 2 | using Microsoft.UI.Xaml.Controls; |
3 | | -using OpenClawTray.Helpers; |
4 | 3 | using OpenClawTray.Services; |
5 | | -using System; |
| 4 | +using OpenClawTray.ViewModels; |
6 | 5 | using System.Collections.ObjectModel; |
7 | | -using System.Globalization; |
8 | | -using System.Linq; |
9 | 6 |
|
10 | 7 | namespace OpenClawTray.Pages; |
11 | 8 |
|
@@ -98,82 +95,4 @@ private void OnNotificationActionClick(object sender, RoutedEventArgs e) |
98 | 95 | ((IAppCommands)CurrentApp).Navigate(item.ActionRoute); |
99 | 96 | _notificationService?.Dismiss(item.Id); |
100 | 97 | } |
101 | | - |
102 | | - private sealed record NotificationItemViewModel( |
103 | | - string Id, |
104 | | - string SeverityGlyph, |
105 | | - string Title, |
106 | | - string Message, |
107 | | - string Metadata, |
108 | | - string? ActionLabel, |
109 | | - string? ActionRoute, |
110 | | - Visibility ActionVisibility, |
111 | | - string OccurrenceText, |
112 | | - Visibility OccurrenceVisibility, |
113 | | - string DismissAutomationName) |
114 | | - { |
115 | | - public static NotificationItemViewModel From(AppNotification notification) |
116 | | - { |
117 | | - var metadata = new[] |
118 | | - { |
119 | | - LocalizeMetadataValue(notification.Source), |
120 | | - LocalizeMetadataValue(notification.Category), |
121 | | - notification.CreatedAt.ToLocalTime().ToString("g", CultureInfo.CurrentCulture) |
122 | | - } |
123 | | - .Where(value => !string.IsNullOrWhiteSpace(value)); |
124 | | - |
125 | | - var occurrenceText = LocalizationHelper.Format( |
126 | | - "AppNotification_RepeatedBadgeFormat", |
127 | | - notification.OccurrenceCount); |
128 | | - |
129 | | - return new( |
130 | | - notification.Id, |
131 | | - ToSeverityGlyph(notification.Severity), |
132 | | - notification.Title, |
133 | | - notification.Message, |
134 | | - string.Join(" - ", metadata), |
135 | | - notification.ActionLabel, |
136 | | - notification.ActionRoute, |
137 | | - !string.IsNullOrWhiteSpace(notification.ActionLabel) && |
138 | | - !string.IsNullOrWhiteSpace(notification.ActionRoute) |
139 | | - ? Visibility.Visible |
140 | | - : Visibility.Collapsed, |
141 | | - occurrenceText, |
142 | | - notification.OccurrenceCount > 1 ? Visibility.Visible : Visibility.Collapsed, |
143 | | - LocalizationHelper.Format("NotificationsPage_DismissAutomationNameFormat", notification.Title)); |
144 | | - } |
145 | | - |
146 | | - private static string ToSeverityGlyph(AppNotificationSeverity severity) => severity switch |
147 | | - { |
148 | | - AppNotificationSeverity.Success => "\uE930", |
149 | | - AppNotificationSeverity.Warning => "\uE7BA", |
150 | | - AppNotificationSeverity.Error => "\uE783", |
151 | | - _ => "\uE946" |
152 | | - }; |
153 | | - |
154 | | - private static string? LocalizeMetadataValue(string? value) => value switch |
155 | | - { |
156 | | - null or "" => null, |
157 | | - "authentication" => LocalizationHelper.GetString("NotificationsPage_MetadataAuthentication"), |
158 | | - "bindings" => LocalizationHelper.GetString("NotificationsPage_MetadataBindings"), |
159 | | - "channels" => LocalizationHelper.GetString("NotificationsPage_MetadataChannels"), |
160 | | - "config" => LocalizationHelper.GetString("NotificationsPage_MetadataConfig"), |
161 | | - "connection" => LocalizationHelper.GetString("NotificationsPage_MetadataConnection"), |
162 | | - "cron" => LocalizationHelper.GetString("NotificationsPage_MetadataCron"), |
163 | | - "exec-approval" => LocalizationHelper.GetString("NotificationsPage_MetadataSourceExecApproval"), |
164 | | - "gateway" => LocalizationHelper.GetString("NotificationsPage_MetadataGateway"), |
165 | | - "jobs" => LocalizationHelper.GetString("NotificationsPage_MetadataJobs"), |
166 | | - "load" => LocalizationHelper.GetString("NotificationsPage_MetadataLoad"), |
167 | | - "lifecycle" => LocalizationHelper.GetString("NotificationsPage_MetadataLifecycle"), |
168 | | - "local-gateway" => LocalizationHelper.GetString("NotificationsPage_MetadataLocalGateway"), |
169 | | - "node.invoke" => LocalizationHelper.GetString("NotificationsPage_MetadataCategoryNodeInvoke"), |
170 | | - "node" => LocalizationHelper.GetString("NotificationsPage_MetadataNode"), |
171 | | - "pairing" => LocalizationHelper.GetString("NotificationsPage_MetadataPairing"), |
172 | | - "sandbox" => LocalizationHelper.GetString("NotificationsPage_MetadataSandbox"), |
173 | | - "settings" => LocalizationHelper.GetString("NotificationsPage_MetadataSettings"), |
174 | | - "status" => LocalizationHelper.GetString("NotificationsPage_MetadataStatus"), |
175 | | - "system.run" => LocalizationHelper.GetString("NotificationsPage_MetadataSystemRun"), |
176 | | - _ => value |
177 | | - }; |
178 | | - } |
179 | 98 | } |
0 commit comments