From 09abdc41fb38cc95ee0e963489a0fc2d99b5d35e Mon Sep 17 00:00:00 2001 From: Alexandre Agostinho Date: Sat, 10 Jun 2023 10:44:09 +0200 Subject: [PATCH] export functionality ok --- MCTG/Views/ContentPages/Home.xaml | 16 +++++++++++++--- MCTG/Views/ContentPages/Home.xaml.cs | 18 ++++++++++++++++++ MCTG/Views/ContentPages/MyPosts.xaml | 12 ++++++++++-- MCTG/Views/ContentPages/MyPosts.xaml.cs | 17 +++++++++++++++++ MCTG/Views/ContentViews/RecipeCase.xaml | 2 ++ MCTG/Views/ContentViews/RecipeCase.xaml.cs | 1 + 6 files changed, 61 insertions(+), 5 deletions(-) diff --git a/MCTG/Views/ContentPages/Home.xaml b/MCTG/Views/ContentPages/Home.xaml index 1c3a23c..afe84f7 100644 --- a/MCTG/Views/ContentPages/Home.xaml +++ b/MCTG/Views/ContentPages/Home.xaml @@ -66,7 +66,7 @@ FontSize="24" Padding="15"/> - - + + RecipeTitle="{Binding Title}"> + + + + + + + + + diff --git a/MCTG/Views/ContentPages/Home.xaml.cs b/MCTG/Views/ContentPages/Home.xaml.cs index 506989b..4928d94 100644 --- a/MCTG/Views/ContentPages/Home.xaml.cs +++ b/MCTG/Views/ContentPages/Home.xaml.cs @@ -1,4 +1,6 @@ using AppException; +using CommunityToolkit.Maui.Storage; +using Microsoft.Maui.Controls; using Model; using System.Collections.ObjectModel; @@ -99,5 +101,21 @@ namespace Views description: "Suggestions", recipes: Master.Recipe.GetRecipesByPriorityOrder(Master.User.CurrentConnected.Priorities))); } + + private async void ExportRecipe_Clicked(object sender, EventArgs e) + { + var result = await FolderPicker.Default.PickAsync(FileSystem.Current.AppDataDirectory, new CancellationToken()); + Master.Recipe.CurrentSelected = (Recipe)(sender as MenuFlyoutItem).BindingContext; + + if (result.IsSuccessful) + { + Master.Data.Export(Recipe, Path.Combine(result.Folder.Path, $"{Recipe.Id}.{Recipe.Title.Replace(" ", "")}.json")); + await DisplayAlert("Export", "Recipe was successfully exported.", "Ok"); + } + else + { + await DisplayAlert("Export", "Unable to export recipe.", "Ok"); + } + } } } diff --git a/MCTG/Views/ContentPages/MyPosts.xaml b/MCTG/Views/ContentPages/MyPosts.xaml index fc7bc07..cb2464e 100644 --- a/MCTG/Views/ContentPages/MyPosts.xaml +++ b/MCTG/Views/ContentPages/MyPosts.xaml @@ -50,11 +50,19 @@ BindableLayout.ItemsSource="{Binding RecipesDisplayed}"> - + + RecipeTitle="{Binding Title}"> + + + + + + + diff --git a/MCTG/Views/ContentPages/MyPosts.xaml.cs b/MCTG/Views/ContentPages/MyPosts.xaml.cs index 2feebf1..be3887d 100644 --- a/MCTG/Views/ContentPages/MyPosts.xaml.cs +++ b/MCTG/Views/ContentPages/MyPosts.xaml.cs @@ -1,3 +1,4 @@ +using CommunityToolkit.Maui.Storage; using Model; namespace Views; @@ -31,4 +32,20 @@ public partial class MyPosts : ContentPage { Navigation.PushModalAsync(new AddRecipe()); } + + private async void ExportRecipe_Clicked(object sender, EventArgs e) + { + var result = await FolderPicker.Default.PickAsync(FileSystem.Current.AppDataDirectory, new CancellationToken()); + Master.Recipe.CurrentSelected = (Recipe)(sender as MenuFlyoutItem).BindingContext; + + if (result.IsSuccessful) + { + Master.Data.Export(Recipe, Path.Combine(result.Folder.Path, $"{Recipe.Id}.{Recipe.Title.Replace(" ", "")}.json")); + await DisplayAlert("Export", "Recipe was successfully exported.", "Ok"); + } + else + { + await DisplayAlert("Export", "Unable to export recipe.", "Ok"); + } + } } diff --git a/MCTG/Views/ContentViews/RecipeCase.xaml b/MCTG/Views/ContentViews/RecipeCase.xaml index 49ae6e3..b2f20a1 100644 --- a/MCTG/Views/ContentViews/RecipeCase.xaml +++ b/MCTG/Views/ContentViews/RecipeCase.xaml @@ -17,6 +17,8 @@ Grid.Row="1" HorizontalOptions="Center" VerticalOptions="Center" Text="{Binding RecipeTitle, Source={x:Reference rCase}}"/> + + diff --git a/MCTG/Views/ContentViews/RecipeCase.xaml.cs b/MCTG/Views/ContentViews/RecipeCase.xaml.cs index e707ce0..d8fc744 100644 --- a/MCTG/Views/ContentViews/RecipeCase.xaml.cs +++ b/MCTG/Views/ContentViews/RecipeCase.xaml.cs @@ -1,4 +1,5 @@ using Model; +using CommunityToolkit.Maui.Storage; namespace Views;