Allow adding new items
This commit is contained in:
+54
-12
@@ -100,23 +100,13 @@ class MainViewModel : BaseViewModel, IFontResolver
|
|||||||
{
|
{
|
||||||
_workingFolder = folder.Path.LocalPath;
|
_workingFolder = folder.Path.LocalPath;
|
||||||
NotifyPropertyChanged(nameof(IsTitleBoxVisible));
|
NotifyPropertyChanged(nameof(IsTitleBoxVisible));
|
||||||
// TODO: Scan folder for saved info from previous reports and reload if needed
|
// TODO: Scan folder for saved info from previous reports and reload that first
|
||||||
// Scan folder for files and display in DataGrid
|
// Scan folder for files and display in DataGrid
|
||||||
var filePaths = Directory.GetFiles(_workingFolder);
|
var filePaths = Directory.GetFiles(_workingFolder);
|
||||||
filePaths.Sort();
|
filePaths.Sort();
|
||||||
foreach (var filePath in filePaths)
|
foreach (var filePath in filePaths)
|
||||||
{
|
{
|
||||||
if (!filePath.Contains(".DS_Store"))
|
AddFileBasedOnPath(filePath);
|
||||||
{
|
|
||||||
// TODO: if date in file name, pull out that date instead
|
|
||||||
ReportFiles.Add(new ReportFile()
|
|
||||||
{
|
|
||||||
Title = Path.GetFileName(filePath),
|
|
||||||
ReceiptDateTime = File.GetCreationTime(filePath),
|
|
||||||
Notes = "",
|
|
||||||
FilePath = filePath,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -147,6 +137,58 @@ class MainViewModel : BaseViewModel, IFontResolver
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async void AddItem()
|
||||||
|
{
|
||||||
|
var topLevel = TopLevelGrabber?.GetTopLevel();
|
||||||
|
if (topLevel is not null)
|
||||||
|
{
|
||||||
|
var files = await topLevel.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions()
|
||||||
|
{
|
||||||
|
Title = "Choose image or PDF files...",
|
||||||
|
AllowMultiple = true,
|
||||||
|
FileTypeFilter = [
|
||||||
|
new FilePickerFileType("All Types")
|
||||||
|
{
|
||||||
|
Patterns = [ "*.png", "*.jpg", "*.jpeg", "*.gif", "*.bmp", "*.webp", "*.pdf", "*.heic", ],
|
||||||
|
AppleUniformTypeIdentifiers = [ "public.image", "com.adobe.pdf", "public.heic" ],
|
||||||
|
MimeTypes = [ "image/*", "application/pdf", "image/heic" ]
|
||||||
|
},
|
||||||
|
FilePickerFileTypes.ImageAll,
|
||||||
|
FilePickerFileTypes.Pdf,
|
||||||
|
new FilePickerFileType("HEIC Images")
|
||||||
|
{
|
||||||
|
Patterns = [ "*.heic" ],
|
||||||
|
AppleUniformTypeIdentifiers = [ "public.heic" ],
|
||||||
|
MimeTypes = [ "image/heic" ]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
if (files.Count > 0)
|
||||||
|
{
|
||||||
|
foreach (var file in files)
|
||||||
|
{
|
||||||
|
var filePath = file.TryGetLocalPath();
|
||||||
|
AddFileBasedOnPath(filePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AddFileBasedOnPath(string? filePath)
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrWhiteSpace(filePath) && File.Exists(filePath) && !filePath.EndsWith(".DS_Store"))
|
||||||
|
{
|
||||||
|
// TODO: if date in file name, pull out that date instead
|
||||||
|
ReportFiles.Add(new ReportFile()
|
||||||
|
{
|
||||||
|
Title = Path.GetFileName(filePath),
|
||||||
|
ReceiptDateTime = File.GetCreationTime(filePath),
|
||||||
|
Notes = "",
|
||||||
|
FilePath = filePath,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async void BuildPDF()
|
public async void BuildPDF()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|||||||
@@ -125,6 +125,10 @@
|
|||||||
Spacing="4"
|
Spacing="4"
|
||||||
Grid.Row="2"
|
Grid.Row="2"
|
||||||
Margin="4">
|
Margin="4">
|
||||||
|
<Button Command="{Binding AddItem}"
|
||||||
|
IsEnabled="{Binding IsTitleBoxVisible}">
|
||||||
|
<TextBlock><Run Text="+" FontFamily="{StaticResource FontAwesomeSolid}"/> Add Item</TextBlock>
|
||||||
|
</Button>
|
||||||
<Button Content="Create Report PDF"
|
<Button Content="Create Report PDF"
|
||||||
Command="{Binding BuildPDF}"
|
Command="{Binding BuildPDF}"
|
||||||
Classes="accent"
|
Classes="accent"
|
||||||
|
|||||||
Reference in New Issue
Block a user