Keep doing rework for using PDFReportInfo obj

Still need to think about how this all works...could probably simplify more...
This commit is contained in:
2026-03-30 21:00:19 +09:00
parent 534af58f44
commit 22d896543c
5 changed files with 89 additions and 17 deletions
+7
View File
@@ -1,3 +1,10 @@
----iOS----
-quickstart for loading last edited report on main menu
-option/setting to put picture data into internal data dir for backup (always on for mobile)
-----------
https://stackoverflow.com/questions/78855900/error-ios-projects-must-build-with-publishtrimmed-true-when-trimming-is-disabl https://stackoverflow.com/questions/78855900/error-ios-projects-must-build-with-publishtrimmed-true-when-trimming-is-disabl
https://blog.verslu.is/maui/exclude-assemblies-from-trimming/ https://blog.verslu.is/maui/exclude-assemblies-from-trimming/
+10
View File
@@ -20,6 +20,16 @@ class PDFReport : PDFReportInfo
_lastGenerated = null; _lastGenerated = null;
} }
public PDFReport(PDFReportInfo info) : base()
{
_files = [];
_lastGenerated = null;
BaseFolder = info.BaseFolder;
UUID = info.UUID;
Title = info.Title;
LastSaved = info.LastSaved;
}
public List<ReportFile> Files public List<ReportFile> Files
{ {
get => _files; get => _files;
+10 -1
View File
@@ -12,7 +12,7 @@ namespace MayShow.Models;
class PDFReportInfo : ChangeNotifier class PDFReportInfo : ChangeNotifier
{ {
private string? _baseFolder; // might be null private string? _baseFolder; // might be null; if set, use this to know where (initial) working dir is
private string _uuid; private string _uuid;
private string _title; private string _title;
private DateTime? _lastSaved; private DateTime? _lastSaved;
@@ -54,6 +54,15 @@ class PDFReportInfo : ChangeNotifier
UUID = Guid.NewGuid().ToString(); UUID = Guid.NewGuid().ToString();
} }
public string GetWorkingPath()
{
if (string.IsNullOrWhiteSpace(BaseFolder))
{
return Path.Combine(Utilities.GetInternalDataPath(), UUID);
}
return BaseFolder;
}
public void DeleteInternalFolderFromDisk() public void DeleteInternalFolderFromDisk()
{ {
var path = Path.Combine(Utilities.GetInternalDataPath(), UUID); var path = Path.Combine(Utilities.GetInternalDataPath(), UUID);
@@ -48,12 +48,18 @@ class CreatePDFReportViewModel : BaseViewModel, ICanCheckShutdown, ILogger
private bool _hasUnsavedWork; private bool _hasUnsavedWork;
public CreatePDFReportViewModel(IChangeViewModel viewModelChanger) : base(viewModelChanger) private CreatePDFReportViewModel(IChangeViewModel viewModelChanger) : base(viewModelChanger)
{ {
_isPerformingInitialLoad = true;
_processDir = Path.GetDirectoryName(Environment.ProcessPath) ?? ""; _processDir = Path.GetDirectoryName(Environment.ProcessPath) ?? "";
Console.WriteLine("Internal storage directory is: {0}", Utilities.GetInternalDataPath()); Console.WriteLine("Internal storage directory is: {0}", Utilities.GetInternalDataPath());
_isCreatingPDF = false; _isCreatingPDF = false;
_workingFolder = "";
ReportFiles = _reportFiles = new ObservableCollection<ReportFile>();
_reportTitle = "";
_lastGeneratedTime = null;
_settings = Settings.LoadSettings(); // TODO: needs tweaking
HasUnsavedWork = false;
// setup initial quote and program log data
var quotes = Constants.GetQuotes(); var quotes = Constants.GetQuotes();
Random random = new Random(); Random random = new Random();
var quoteIndex = random.Next(0, quotes.Length); var quoteIndex = random.Next(0, quotes.Length);
@@ -62,21 +68,50 @@ class CreatePDFReportViewModel : BaseViewModel, ICanCheckShutdown, ILogger
_programLog += "---------------------------------------" + Environment.NewLine; _programLog += "---------------------------------------" + Environment.NewLine;
_programLog += "Loaded and ready to create report!" + Environment.NewLine; _programLog += "Loaded and ready to create report!" + Environment.NewLine;
_programLog += "Please copy and send this Program Log when reporting any issues with the software."; _programLog += "Please copy and send this Program Log when reporting any issues with the software.";
_workingFolder = ""; }
ReportFiles = _reportFiles = new ObservableCollection<ReportFile>();
_reportTitle = ""; // this is the "normal path" into the pdf report view
_lastGeneratedTime = null; // pathToLoad is presumably _settings.LastUsedPath but doesn't have to be
_settings = Settings.LoadSettings(); public CreatePDFReportViewModel(string pathToLoad, IChangeViewModel viewModelChanger) : this(viewModelChanger)
if (!string.IsNullOrWhiteSpace(_settings.LastUsedPath))
{ {
LogInfo("Loading data at last used path of {0}", _settings.LastUsedPath); _isPerformingInitialLoad = true;
ScanFolder(_settings.LastUsedPath); // TODO: load settings properly
if (!string.IsNullOrWhiteSpace(pathToLoad))
{
LogInfo("Loading report data at path: {0}", pathToLoad);
ScanFolder(pathToLoad);
} }
else else
{ {
LogInfo("Choose a receipt folder to begin..."); LogInfo("Choose a receipt folder to begin...");
} }
HasUnsavedWork = false; _isPerformingInitialLoad = false;
}
public CreatePDFReportViewModel(PDFReportInfo reportInfo, IChangeViewModel viewModelChanger) : this(viewModelChanger)
{
_isPerformingInitialLoad = true;
// todo: load settings properly!
// if BaseFolder set, regardless of where the JSON data is saved,
// the working data (pictures, etc.) is outside of the current, working folder
if (!string.IsNullOrWhiteSpace(reportInfo.BaseFolder))
{
LogInfo("Loading report data at path: {0}", reportInfo.BaseFolder);
ScanFolder(reportInfo.BaseFolder);
}
else
{
// load data file in internal dir + UUID
var path = Path.Combine(Utilities.GetInternalDataPath(), reportInfo.UUID);
if (Directory.Exists(path))
{
ScanFolder(path); // even if points internally will be A-OK
}
else
{
// TODO: error
}
}
_isPerformingInitialLoad = false; _isPerformingInitialLoad = false;
} }
@@ -44,15 +44,17 @@ class StartNewChooseReportViewModel : BaseViewModel
public async void StartReport() public async void StartReport()
{ {
if (string.IsNullOrWhiteSpace(CreatingReportTitle))
{
await DialogHost.Show(new WarningViewModel("Report title cannot be blank!"));
return;
}
// TODO: if report with name already exists in system, error
var reportInfo = new PDFReportInfo() var reportInfo = new PDFReportInfo()
{ {
Title = CreatingReportTitle, Title = CreatingReportTitle,
LastSaved = DateTime.Now LastSaved = DateTime.Now
}; };
_settings.AllReportInfo.Add(reportInfo);
// ... this sort and save is slow, technically, but we're not going to have millions of items here, so...
SavedReports = new ObservableCollection<PDFReportInfo>(_settings.AllReportInfo.OrderBy(x => x.Title));
await _settings.SaveSettingsAsync();
// create folder for report data // create folder for report data
var path = Path.Combine(Utilities.GetInternalDataPath(), reportInfo.UUID); var path = Path.Combine(Utilities.GetInternalDataPath(), reportInfo.UUID);
while (Directory.Exists(path)) while (Directory.Exists(path))
@@ -61,8 +63,13 @@ class StartNewChooseReportViewModel : BaseViewModel
path = Path.Combine(Utilities.GetInternalDataPath(), reportInfo.UUID); path = Path.Combine(Utilities.GetInternalDataPath(), reportInfo.UUID);
} }
Directory.CreateDirectory(path); Directory.CreateDirectory(path);
reportInfo.BaseFolder = path; // default to internal directory
_settings.AllReportInfo.Add(reportInfo);
// ... this sort and save is slow, technically, but we're not going to have millions of items here, so...
SavedReports = new ObservableCollection<PDFReportInfo>(_settings.AllReportInfo.OrderBy(x => x.Title));
await _settings.SaveSettingsAsync();
// now update UI // now update UI
ViewModelChanger.PushViewModel(new CreatePDFReportViewModel(ViewModelChanger) ViewModelChanger.PushViewModel(new CreatePDFReportViewModel(reportInfo, ViewModelChanger)
{ {
ReportTitle = CreatingReportTitle ReportTitle = CreatingReportTitle
}); });
@@ -73,6 +80,10 @@ class StartNewChooseReportViewModel : BaseViewModel
public void LoadExistingReportImpl(PDFReportInfo reportInfo) public void LoadExistingReportImpl(PDFReportInfo reportInfo)
{ {
// TODO: load data and send to create PDF report view model // TODO: load data and send to create PDF report view model
ViewModelChanger.PushViewModel(new CreatePDFReportViewModel(reportInfo, ViewModelChanger)
{
ReportTitle = CreatingReportTitle
});
} }
public void DeleteExistingReport(object info) => DeleteExistingReportImpl((PDFReportInfo) info); public void DeleteExistingReport(object info) => DeleteExistingReportImpl((PDFReportInfo) info);