Options fix
clean up and fixes - Heute gefixt - Code Cleanup NotificationScheduleItemViewModel -fixed NotificationScheduleItemViewModel for Windows compat push implementation Push fixes Push benachrichtungen eingebaut - Status bei push - Push auch in background - Toggle für symtome angepasst push system change exporter update Optionen fix - Optionen aufgeteilt auf 3 tabs - Anpassungen haben jetzt Farbslider Optimierung fix
This commit is contained in:
+108
-11
@@ -1,8 +1,6 @@
|
||||
using cfs_tracker.Data;
|
||||
using cfs_tracker.Helpers;
|
||||
using cfs_tracker.Models;
|
||||
using Microsoft.Maui.Graphics;
|
||||
using Microsoft.Maui.Storage;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
|
||||
@@ -47,16 +45,21 @@ public sealed class PdfExportService : IPdfExportService
|
||||
var entries = await _healthEntryRepository.GetEntriesForDateAsync(date);
|
||||
var activityNames = await GetActivityNamesAsync();
|
||||
var symptomNamesByEntry = await GetSymptomNamesByEntryAsync(entries.Select(x => x.Id));
|
||||
var conflicts = DetectDayExportConflicts(entries);
|
||||
|
||||
var sb = new StringBuilder();
|
||||
sb.AppendLine($"<h1>Tagesübersicht – {Encode(date.ToString("dd.MM.yyyy"))}</h1>");
|
||||
|
||||
if (conflicts.Count > 0)
|
||||
sb.AppendLine(BuildConflictHtml(conflicts));
|
||||
|
||||
sb.AppendLine("<table>");
|
||||
sb.AppendLine("<thead><tr><th>Uhrzeit</th><th>Status</th><th>Tätigkeit</th><th>Symptome</th></tr></thead>");
|
||||
sb.AppendLine("<thead><tr><th>Zeit</th><th>Status</th><th>Tätigkeit</th><th>Dauer</th><th>Symptome</th></tr></thead>");
|
||||
sb.AppendLine("<tbody>");
|
||||
|
||||
foreach (var entry in entries.OrderBy(x => x.Timestamp).ThenBy(x => x.Id))
|
||||
{
|
||||
var symptoms = symptomNamesByEntry.TryGetValue(entry.Id, out var symptomList)
|
||||
var symptoms = symptomNamesByEntry.TryGetValue(entry.Id, out var symptomList) && symptomList.Count > 0
|
||||
? string.Join(", ", symptomList)
|
||||
: "—";
|
||||
|
||||
@@ -65,15 +68,16 @@ public sealed class PdfExportService : IPdfExportService
|
||||
: "—";
|
||||
|
||||
sb.AppendLine("<tr>");
|
||||
sb.AppendLine($"<td>{Encode(entry.Timestamp.ToString("HH:mm"))}</td>");
|
||||
sb.AppendLine($"<td>{Encode(GetDayTimeLabel(entry))}</td>");
|
||||
sb.AppendLine(StateCell(entry.State, GetStateText(entry.State)));
|
||||
sb.AppendLine($"<td>{Encode(activity)}</td>");
|
||||
sb.AppendLine($"<td>{Encode(FormatDuration(entry.ActivityDurationMinutes))}</td>");
|
||||
sb.AppendLine($"<td>{Encode(symptoms)}</td>");
|
||||
sb.AppendLine("</tr>");
|
||||
}
|
||||
|
||||
if (entries.Count == 0)
|
||||
sb.AppendLine("<tr><td colspan=\"4\">Keine Einträge vorhanden.</td></tr>");
|
||||
sb.AppendLine("<tr><td colspan=\"5\">Keine Einträge vorhanden.</td></tr>");
|
||||
|
||||
sb.AppendLine("</tbody></table>");
|
||||
|
||||
@@ -310,6 +314,7 @@ public sealed class PdfExportService : IPdfExportService
|
||||
.Distinct()
|
||||
.ToList());
|
||||
}
|
||||
|
||||
private async Task<ExportResult> SaveHtmlAsync(
|
||||
string fileName,
|
||||
string title,
|
||||
@@ -319,17 +324,20 @@ public sealed class PdfExportService : IPdfExportService
|
||||
var folder = GetExportFolderPath();
|
||||
Directory.CreateDirectory(folder);
|
||||
|
||||
var path = Path.Combine(folder, fileName);
|
||||
var html = WrapHtml(title, bodyHtml, compactA4);
|
||||
var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName);
|
||||
var extension = Path.GetExtension(fileName);
|
||||
var path = GetUniqueFilePath(folder, fileNameWithoutExtension, extension);
|
||||
|
||||
var html = WrapHtml(title, bodyHtml, compactA4);
|
||||
await File.WriteAllTextAsync(path, html, Encoding.UTF8);
|
||||
|
||||
return new ExportResult
|
||||
{
|
||||
FilePath = path,
|
||||
FileName = fileName
|
||||
FileName = Path.GetFileName(path)
|
||||
};
|
||||
}
|
||||
|
||||
private string StateCell(HealthState state, string text)
|
||||
{
|
||||
var background = GetStateBackgroundCss(state);
|
||||
@@ -436,8 +444,6 @@ public sealed class PdfExportService : IPdfExportService
|
||||
}
|
||||
catch
|
||||
{
|
||||
// absichtlich ignorieren, damit eine einzelne blockierte Datei
|
||||
// nicht den ganzen Vorgang abbricht
|
||||
}
|
||||
}
|
||||
|
||||
@@ -514,6 +520,18 @@ public sealed class PdfExportService : IPdfExportService
|
||||
.compact-symptoms {
|
||||
width: 32%;
|
||||
}
|
||||
|
||||
.conflict-box {
|
||||
border: 1px solid #000000;
|
||||
background: #fff8e1;
|
||||
padding: {{(compactA4 ? "6px" : "10px")}};
|
||||
margin-bottom: {{(compactA4 ? "8px" : "14px")}};
|
||||
}
|
||||
|
||||
.conflict-box ul {
|
||||
margin: 6px 0 0 18px;
|
||||
padding: 0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
@@ -521,4 +539,83 @@ public sealed class PdfExportService : IPdfExportService
|
||||
</body>
|
||||
</html>
|
||||
""";
|
||||
|
||||
private static string GetUniqueFilePath(string directory, string fileNameWithoutExtension, string extension)
|
||||
{
|
||||
Directory.CreateDirectory(directory);
|
||||
|
||||
var safeExtension = string.IsNullOrWhiteSpace(extension)
|
||||
? ".html"
|
||||
: (extension.StartsWith('.') ? extension : "." + extension);
|
||||
|
||||
var basePath = Path.Combine(directory, fileNameWithoutExtension + safeExtension);
|
||||
if (!File.Exists(basePath))
|
||||
return basePath;
|
||||
|
||||
var counter = 1;
|
||||
while (true)
|
||||
{
|
||||
var candidate = Path.Combine(directory, $"{fileNameWithoutExtension} ({counter}){safeExtension}");
|
||||
if (!File.Exists(candidate))
|
||||
return candidate;
|
||||
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetDayTimeLabel(HealthEntry entry)
|
||||
{
|
||||
if (entry.DayPart == DayPart.Morning)
|
||||
return "Vormittag";
|
||||
|
||||
if (entry.DayPart == DayPart.Afternoon)
|
||||
return "Nachmittag";
|
||||
|
||||
return entry.Timestamp.ToString("HH:mm");
|
||||
}
|
||||
|
||||
private static string FormatDuration(int? durationMinutes)
|
||||
{
|
||||
if (!durationMinutes.HasValue || durationMinutes.Value <= 0)
|
||||
return "—";
|
||||
|
||||
var duration = TimeSpan.FromMinutes(durationMinutes.Value);
|
||||
return duration.ToString(@"hh\:mm");
|
||||
}
|
||||
|
||||
private static List<string> DetectDayExportConflicts(IEnumerable<HealthEntry> entries)
|
||||
{
|
||||
var result = new List<string>();
|
||||
|
||||
var morningCount = entries.Count(x => x.DayPart == DayPart.Morning);
|
||||
var afternoonCount = entries.Count(x => x.DayPart == DayPart.Afternoon);
|
||||
|
||||
if (morningCount > 1)
|
||||
result.Add("Mehrere Vormittag-Einträge gefunden.");
|
||||
|
||||
if (afternoonCount > 1)
|
||||
result.Add("Mehrere Nachmittag-Einträge gefunden.");
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static string BuildConflictHtml(IEnumerable<string> conflicts)
|
||||
{
|
||||
var list = conflicts.ToList();
|
||||
if (list.Count == 0)
|
||||
return string.Empty;
|
||||
|
||||
var sb = new StringBuilder();
|
||||
sb.AppendLine("<div class=\"conflict-box\">");
|
||||
sb.AppendLine("<strong>Hinweis auf mögliche Konflikte:</strong>");
|
||||
sb.AppendLine("<ul>");
|
||||
|
||||
foreach (var item in list)
|
||||
sb.AppendLine($"<li>{Encode(item)}</li>");
|
||||
|
||||
sb.AppendLine("</ul>");
|
||||
sb.AppendLine("</div>");
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user