export functionality ok

pull/67/head
Alexandre AGOSTINHO 2 years ago
parent 96c9fec521
commit 09abdc41fb

@ -66,7 +66,7 @@
FontSize="24" FontSize="24"
Padding="15"/> Padding="15"/>
<FlexLayout <FlexLayout x:Name="rc_flex"
Margin="0, 15" Margin="0, 15"
Wrap="Wrap" Wrap="Wrap"
JustifyContent="Start" JustifyContent="Start"
@ -76,11 +76,21 @@
BindableLayout.ItemsSource="{Binding RecipesDisplayed}"> BindableLayout.ItemsSource="{Binding RecipesDisplayed}">
<BindableLayout.ItemTemplate> <BindableLayout.ItemTemplate>
<DataTemplate x:DataType="model:Recipe"> <DataTemplate x:DataType="model:Recipe" x:Name="rc_case">
<local:RecipeCase <local:RecipeCase
CaseImageSource="{Binding Image}" CaseImageSource="{Binding Image}"
RecipeTitle="{Binding Title}"/> RecipeTitle="{Binding Title}">
<FlyoutBase.ContextFlyout>
<MenuFlyout>
<MenuFlyoutItem Text="Export recipe"
Clicked="ExportRecipe_Clicked"/>
</MenuFlyout>
</FlyoutBase.ContextFlyout>
</local:RecipeCase>
</DataTemplate> </DataTemplate>
</BindableLayout.ItemTemplate> </BindableLayout.ItemTemplate>

@ -1,4 +1,6 @@
using AppException; using AppException;
using CommunityToolkit.Maui.Storage;
using Microsoft.Maui.Controls;
using Model; using Model;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
@ -99,5 +101,21 @@ namespace Views
description: "Suggestions", description: "Suggestions",
recipes: Master.Recipe.GetRecipesByPriorityOrder(Master.User.CurrentConnected.Priorities))); 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");
}
}
} }
} }

@ -50,11 +50,19 @@
BindableLayout.ItemsSource="{Binding RecipesDisplayed}"> BindableLayout.ItemsSource="{Binding RecipesDisplayed}">
<BindableLayout.ItemTemplate> <BindableLayout.ItemTemplate>
<DataTemplate x:DataType="model:Recipe"> <DataTemplate x:DataType="model:Recipe" x:Name="rc_case">
<local:RecipeCase <local:RecipeCase
CaseImageSource="{Binding Image}" CaseImageSource="{Binding Image}"
RecipeTitle="{Binding Title}"/> RecipeTitle="{Binding Title}">
<FlyoutBase.ContextFlyout>
<MenuFlyout>
<MenuFlyoutItem Text="Export recipe"
Clicked="ExportRecipe_Clicked"/>
</MenuFlyout>
</FlyoutBase.ContextFlyout>
</local:RecipeCase>
</DataTemplate> </DataTemplate>
</BindableLayout.ItemTemplate> </BindableLayout.ItemTemplate>

@ -1,3 +1,4 @@
using CommunityToolkit.Maui.Storage;
using Model; using Model;
namespace Views; namespace Views;
@ -31,4 +32,20 @@ public partial class MyPosts : ContentPage
{ {
Navigation.PushModalAsync(new AddRecipe()); 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");
}
}
} }

@ -17,6 +17,8 @@
Grid.Row="1" HorizontalOptions="Center" VerticalOptions="Center" Grid.Row="1" HorizontalOptions="Center" VerticalOptions="Center"
Text="{Binding RecipeTitle, Source={x:Reference rCase}}"/> Text="{Binding RecipeTitle, Source={x:Reference rCase}}"/>
</Grid> </Grid>
</Border> </Border>
</ContentView> </ContentView>

@ -1,4 +1,5 @@
using Model; using Model;
using CommunityToolkit.Maui.Storage;
namespace Views; namespace Views;

Loading…
Cancel
Save