-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #211 from MartinZikmund/feature/post-editor-pt2
- Loading branch information
Showing
8 changed files
with
126 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<local:CategoryPickerDialogBase | ||
x:Class="MZikmund.Dialogs.Admin.CategoryPickerDialog" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="using:MZikmund.Dialogs.Admin" | ||
xmlns:xaml="using:MZikmund.Extensions.Xaml" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:blog="using:MZikmund.DataContracts.Blog" | ||
Style="{ThemeResource DefaultContentDialogStyle}" | ||
Title="{xaml:Localize Key=PickCategories}" | ||
CloseButtonText="{xaml:Localize Key=Cancel}" | ||
DefaultButton="Primary" | ||
PrimaryButtonText="{xaml:Localize Key=Save}"> | ||
<Grid> | ||
<ListView x:Name="CategoriesListView" Height="240" SelectionMode="Multiple" SelectionChanged="ListView_SelectionChanged" ItemsSource="{x:Bind ViewModel.AllCategories, Mode=OneWay}"> | ||
<ListView.ItemTemplate> | ||
<DataTemplate x:DataType="blog:Category"> | ||
<TextBlock Text="{x:Bind DisplayName}" /> | ||
</DataTemplate> | ||
</ListView.ItemTemplate> | ||
</ListView> | ||
</Grid> | ||
</local:CategoryPickerDialogBase> |
34 changes: 34 additions & 0 deletions
34
src/app/MZikmund/Dialogs/Admin/CategoryPickerDialog.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using MZikmund.DataContracts.Blog; | ||
using MZikmund.ViewModels.Admin; | ||
|
||
namespace MZikmund.Dialogs.Admin; | ||
|
||
public sealed partial class CategoryPickerDialog : CategoryPickerDialogBase | ||
{ | ||
public CategoryPickerDialog() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
internal void SetSelectedItems(IEnumerable<Category> itemsToSelect) | ||
{ | ||
foreach (var category in itemsToSelect) | ||
{ | ||
CategoriesListView.SelectedItems.Add(category); | ||
} | ||
} | ||
|
||
private void ListView_SelectionChanged(object sender, SelectionChangedEventArgs e) | ||
{ | ||
if (ViewModel is null) | ||
{ | ||
return; | ||
} | ||
|
||
ViewModel.SelectedCategories = CategoriesListView.SelectedItems.Cast<Category>().ToArray(); | ||
} | ||
} | ||
|
||
public abstract partial class CategoryPickerDialogBase : DialogBase<CategoryPickerDialogViewModel> | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/app/MZikmund/ViewModels/Admin/CategoryPickerDialogViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using MZikmund.Api.Client; | ||
using MZikmund.DataContracts.Blog; | ||
using MZikmund.Dialogs.Admin; | ||
|
||
namespace MZikmund.ViewModels.Admin; | ||
|
||
public class CategoryPickerDialogViewModel : DialogViewModel | ||
{ | ||
private readonly Guid[] _initialSelection; | ||
private readonly IMZikmundApi _api; | ||
|
||
public CategoryPickerDialogViewModel(Guid[] selectedCategoryIds, IMZikmundApi api) | ||
{ | ||
_initialSelection = selectedCategoryIds; | ||
_api = api; | ||
} | ||
|
||
public override async void OnOpened(ContentDialog contentDialog) | ||
{ | ||
try | ||
{ | ||
var dialog = (CategoryPickerDialog)contentDialog; | ||
AllCategories = (await _api.GetCategoriesAsync()).Content!; | ||
dialog.SetSelectedItems(AllCategories.Where(c => _initialSelection.Contains(c.Id))); | ||
} | ||
catch (Exception) | ||
{ | ||
// TODO: Handle dialog exception | ||
} | ||
} | ||
|
||
public Category[] AllCategories { get; private set; } = Array.Empty<Category>(); | ||
|
||
public Category[] SelectedCategories { get; set; } = Array.Empty<Category>(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters