Skip to content
This repository has been archived by the owner on Jun 24, 2021. It is now read-only.

Commit

Permalink
Bind todo items
Browse files Browse the repository at this point in the history
  • Loading branch information
DanteDeRuwe committed Jan 16, 2021
1 parent 389988b commit 583f2f9
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Vecto.Core/Entities/Section.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Vecto.Core.Entities
{
public abstract class Section : EntityBase, ISection
public class Section : EntityBase, ISection
{
public string Name { get; set; }

Expand Down
3 changes: 1 addition & 2 deletions Vecto.UWP/Pages/MainPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using Vecto.UWP.Services;
using Vecto.UWP.Services;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media.Animation;
Expand Down
4 changes: 2 additions & 2 deletions Vecto.UWP/Pages/Sections/TodoSectionPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:entities="using:Vecto.Core.Entities"
xmlns:entities="using:Vecto.Core.Entities"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<TreeView ItemsSource="{x:Bind _todoItems}" SelectionMode="Multiple" CanDragItems="True" AllowDrop="True">
<TreeView.ItemTemplate>
<DataTemplate x:DataType="entities:TodoItem">
<TreeViewItem Content="{x:Bind Title}" />
<TreeViewItem Content="{x:Bind Title}" IsSelected="{x:Bind Checked}"/>
</DataTemplate>
</TreeView.ItemTemplate>
</TreeView>
Expand Down
19 changes: 10 additions & 9 deletions Vecto.UWP/Pages/Sections/TodoSectionPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
using System.Collections.ObjectModel;
using System;
using System.Collections.ObjectModel;
using Vecto.Core.Entities;
using Vecto.UWP.Services;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;

namespace Vecto.UWP.Pages.Sections
{
public sealed partial class TodoSectionPage : Page
{
private readonly IApiService _service = CustomRefitService.ForAuthenticated<IApiService>();
private ObservableCollection<TodoItem> _todoItems;

protected override void OnNavigatedTo(NavigationEventArgs e)
protected override async void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
var sectionIndex = e.Parameter;

_todoItems = new ObservableCollection<TodoItem>() //TODO
{
new TodoItem(){Title = "test1"},
new TodoItem(){Title = "test2"},
new TodoItem(){Title = "test3"},
};
dynamic guids = e.Parameter;
(var tripId, var sectionId) = ((Guid) guids.TripId, (Guid) guids.SectionId);

var items = await _service.GetTodoItems(tripId, sectionId);
_todoItems = new ObservableCollection<TodoItem>(items);

InitializeComponent();
}
Expand Down
2 changes: 1 addition & 1 deletion Vecto.UWP/Pages/TripDetailsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<Pivot Grid.Row="1" Margin="0 30 0 0" x:Name="SectionsPivot" ItemsSource="{x:Bind _sections}">

<Pivot.HeaderTemplate>
<DataTemplate x:DataType="sections:SectionDTO" >
<DataTemplate x:DataType="entities:Section" >
<TextBlock Text="{Binding Name}" RightTapped="SectionHeaderRightTapped">
<FlyoutBase.AttachedFlyout>
<MenuFlyout>
Expand Down
15 changes: 8 additions & 7 deletions Vecto.UWP/Pages/TripDetailsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public sealed partial class TripDetailsPage : Page
private Trip _trip;
private IEnumerable<string> _sectionTypes;
private NavigationView _navigationView;
private ObservableCollection<SectionDTO> _sections;
private ObservableCollection<Section> _sections;

protected override async void OnNavigatedTo(NavigationEventArgs e)
{
Expand All @@ -34,7 +34,7 @@ protected override async void OnNavigatedTo(NavigationEventArgs e)
_sectionTypes = await _service.GetSectionTypes();

var sections = await _service.GetTripSections(_trip.Id);
_sections = new ObservableCollection<SectionDTO>(sections);
_sections = new ObservableCollection<Section>(sections);

InitializeComponent(); //Initialize here
}
Expand Down Expand Up @@ -82,7 +82,7 @@ private async void AddSectionButton_Click(object sender, RoutedEventArgs e)
};

await _service.AddTripSection(_trip.Id, model);
_sections.Add(model);
_sections.Add(model.MapToSection());
}
catch
{
Expand All @@ -108,13 +108,14 @@ private void DeleteSection_Click(object sender, RoutedEventArgs e)
private void LoadItemsFrame(object sender, RoutedEventArgs e)
{
var frame = sender as Frame;
var selectedSection = SectionsPivot.SelectedItem as SectionDTO;
var sectionType = selectedSection.SectionType;
var selectedSection = SectionsPivot.SelectedItem as Section;

switch (sectionType)
var parameter = new {TripId = _trip.Id, SectionId = selectedSection.Id};

switch (selectedSection.SectionType)
{
case "TodoSection":
frame.Navigate(typeof(TodoSectionPage), SectionsPivot.SelectedIndex);
frame.Navigate(typeof(TodoSectionPage), parameter);
return;
//case "PackingSection":
// frame.Navigate(typeof(PackingSectionPage));
Expand Down
7 changes: 5 additions & 2 deletions Vecto.UWP/Services/IApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,15 @@ public interface IApiService
Task<Trip> UpdateTrip(Guid id, TripDTO tripDTO);

[Get("/trips/{tripId}/sections")]
Task<IEnumerable<SectionDTO>> GetTripSections(Guid tripId);
Task<IEnumerable<Section>> GetTripSections(Guid tripId);

[Post("/trips/{tripId}/sections")]
Task<IEnumerable<SectionDTO>> AddTripSection(Guid tripId, [Body] SectionDTO model);
Task<IEnumerable<Section>> AddTripSection(Guid tripId, [Body] SectionDTO model);

[Get("/sections/types")]
Task<IEnumerable<string>> GetSectionTypes();

[Get("/trips/{tripId}/sections/{sectionId}/items")]
Task<IEnumerable<TodoItem>> GetTodoItems(Guid tripId, Guid sectionId);
}
}

0 comments on commit 583f2f9

Please sign in to comment.