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

Commit

Permalink
Merge pull request #13 from DanteDeRuwe/uwp
Browse files Browse the repository at this point in the history
Merge UWP into master
  • Loading branch information
DanteDeRuwe authored Jan 17, 2021
2 parents eb7debb + 6910c9f commit 9ad22d8
Show file tree
Hide file tree
Showing 69 changed files with 760 additions and 80 deletions.
23 changes: 19 additions & 4 deletions Vecto.Api/Controllers/ItemsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,28 @@ public IActionResult Add(Guid tripId, Guid sectionId, [FromBody] ItemDTO itemDTO
var section = trip.Sections.SingleOrDefault(s => s.Id == sectionId);
if (section is null) return NotFound("section not found");

if (section is TodoSection todoSection) todoSection.Items.Add(itemDTO.MapToTodoItem());
else if (section is PackingSection packingSection) packingSection.Items.Add(itemDTO.MapToPackingItem());
IActionResult res;
switch (section)
{
case TodoSection ts:
var todo = itemDTO.MapToTodoItem();
ts.Items.Add(todo);
res = Ok(todo);
break;
case PackingSection ps:
var pack = itemDTO.MapToPackingItem();
ps.Items.Add(pack);
res = Ok(pack);
break;
default:
res = BadRequest();
return res;
}

_tripsRepository.Update(trip);
_tripsRepository.SaveChanges();

return Ok();
return res;
}

[HttpPatch("{itemId}")]
Expand All @@ -105,7 +120,7 @@ public IActionResult Update(Guid tripId, Guid sectionId, Guid itemId, ItemDTO it
_tripsRepository.Update(trip);
_tripsRepository.SaveChanges();

return Ok();
return Ok(item);
}

[HttpDelete("{itemId}")]
Expand Down
4 changes: 2 additions & 2 deletions Vecto.Api/Controllers/SectionsController.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using FluentValidation;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using FluentValidation;
using Vecto.Application.Helpers;
using Vecto.Application.Sections;
using Vecto.Core.Entities;
Expand Down Expand Up @@ -104,7 +104,7 @@ public async Task<IActionResult> Update(Guid tripId, Guid sectionId, SectionDTO
_tripsRepository.Update(trip);
_tripsRepository.SaveChanges();

return Ok();
return Ok(section);
}

[HttpDelete("{sectionId}")]
Expand Down
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
4 changes: 3 additions & 1 deletion Vecto.UWP/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
>

<Application.Resources>
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
</Application.Resources>
</Application>
Binary file added Vecto.UWP/Assets/LargeTile.scale-100.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Vecto.UWP/Assets/LargeTile.scale-125.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Vecto.UWP/Assets/LargeTile.scale-150.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Vecto.UWP/Assets/LargeTile.scale-200.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Vecto.UWP/Assets/LargeTile.scale-400.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Vecto.UWP/Assets/LockScreenLogo.scale-200.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Vecto.UWP/Assets/SmallTile.scale-100.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Vecto.UWP/Assets/SmallTile.scale-125.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Vecto.UWP/Assets/SmallTile.scale-150.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Vecto.UWP/Assets/SmallTile.scale-200.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Vecto.UWP/Assets/SmallTile.scale-400.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Vecto.UWP/Assets/SplashScreen.scale-100.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Vecto.UWP/Assets/SplashScreen.scale-125.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Vecto.UWP/Assets/SplashScreen.scale-150.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Vecto.UWP/Assets/SplashScreen.scale-200.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Vecto.UWP/Assets/SplashScreen.scale-400.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Vecto.UWP/Assets/Square150x150Logo.scale-100.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Vecto.UWP/Assets/Square150x150Logo.scale-125.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Vecto.UWP/Assets/Square150x150Logo.scale-150.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Vecto.UWP/Assets/Square150x150Logo.scale-200.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Vecto.UWP/Assets/Square150x150Logo.scale-400.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Vecto.UWP/Assets/Square44x44Logo.scale-100.png
Binary file added Vecto.UWP/Assets/Square44x44Logo.scale-125.png
Binary file added Vecto.UWP/Assets/Square44x44Logo.scale-150.png
Binary file modified Vecto.UWP/Assets/Square44x44Logo.scale-200.png
Binary file added Vecto.UWP/Assets/Square44x44Logo.scale-400.png
Binary file added Vecto.UWP/Assets/Square44x44Logo.targetsize-16.png
Binary file added Vecto.UWP/Assets/Square44x44Logo.targetsize-24.png
Binary file added Vecto.UWP/Assets/Square44x44Logo.targetsize-32.png
Binary file added Vecto.UWP/Assets/Square44x44Logo.targetsize-48.png
Binary file modified Vecto.UWP/Assets/StoreLogo.png
Binary file added Vecto.UWP/Assets/StoreLogo.scale-100.png
Binary file added Vecto.UWP/Assets/StoreLogo.scale-125.png
Binary file added Vecto.UWP/Assets/StoreLogo.scale-150.png
Binary file added Vecto.UWP/Assets/StoreLogo.scale-200.png
Binary file added Vecto.UWP/Assets/StoreLogo.scale-400.png
Binary file added Vecto.UWP/Assets/Wide310x150Logo.scale-100.png
Binary file added Vecto.UWP/Assets/Wide310x150Logo.scale-125.png
Binary file added Vecto.UWP/Assets/Wide310x150Logo.scale-150.png
Binary file modified Vecto.UWP/Assets/Wide310x150Logo.scale-200.png
Binary file added Vecto.UWP/Assets/Wide310x150Logo.scale-400.png
9 changes: 1 addition & 8 deletions Vecto.UWP/Pages/Authentication/RegisterPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,8 @@ private async void RegisterButton_Click(object sender, RoutedEventArgs e)
}
catch (ApiException ex)
{
StringBuilder sb = new StringBuilder();

dynamic errors = JObject.Parse(ex.Content)["errors"];
foreach (var error in errors)
{
sb.AppendFormat($"- {error.errorMessage}\n");
}

ErrorTextBlock.Text = sb.ToString();
ErrorTextBlock.Text = errors[0].errorMessage;
}
catch (HttpRequestException)
{
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
29 changes: 20 additions & 9 deletions Vecto.UWP/Pages/ProfilePage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Vecto.UWP.Pages.Authentication;
using System;
using Vecto.UWP.Pages.Authentication;
using Windows.Security.Credentials;
using Windows.Storage;
using Windows.UI.Xaml;
Expand All @@ -10,7 +11,7 @@ public sealed partial class ProfilePage : Page
{
public ProfilePage()
{
this.InitializeComponent();
InitializeComponent();
}

private void LogOutButton_Click(object sender, RoutedEventArgs e)
Expand All @@ -19,15 +20,25 @@ private void LogOutButton_Click(object sender, RoutedEventArgs e)
var localSettings = ApplicationData.Current.LocalSettings;
localSettings.Values.Remove("token");

// clear password
// clear password if found in vault
var passwordVault = new PasswordVault();
var credentialEnumerator = passwordVault.FindAllByResource("Vecto").GetEnumerator();
credentialEnumerator.MoveNext();
passwordVault.Remove(credentialEnumerator.Current);
try
{
var credentials = passwordVault.FindAllByResource("Vecto");
if(credentials.Count < 1) throw new Exception();

// get root frame and use that to navigate otherwise we navigate within the nav menu
var parentFrame = Window.Current.Content as Frame;
parentFrame.Navigate(typeof(LoginPage));
var credentialEnumerator = credentials.GetEnumerator();
credentialEnumerator.MoveNext();
passwordVault.Remove(credentialEnumerator.Current);
credentialEnumerator.Dispose();
}
catch { }
finally
{
// get root frame and use that to navigate otherwise we navigate within the nav menu
var parentFrame = Window.Current.Content as Frame;
parentFrame.Navigate(typeof(LoginPage));
}
}
}
}
79 changes: 79 additions & 0 deletions Vecto.UWP/Pages/Sections/PackingSectionPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<Page
x:Class="Vecto.UWP.Pages.Sections.PackingSectionPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
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:muxc="using:Microsoft.UI.Xaml.Controls"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<StackPanel>
<ListView ItemsSource="{x:Bind _items}" >
<ListView.ItemTemplate>
<DataTemplate x:DataType="entities:PackingItem">
<CheckBox
IsChecked="{x:Bind Checked}"
Checked="CheckBox_Toggle"
Unchecked="CheckBox_Toggle"
Tag="{x:Bind Id}"
RightTapped="ItemRightTapped">
<CheckBox.ContentTemplate>
<DataTemplate x:DataType="entities:PackingItem">
<StackPanel Orientation="Horizontal">
<Border Background="{ThemeResource SystemControlBackgroundChromeMediumLowBrush}" CornerRadius="5" Padding="10 1 10 1" Margin="5 0 10 0">
<TextBlock Text="{x:Bind Amount}"/>
</Border>
<TextBlock Text="{x:Bind Title}"/>
</StackPanel>
</DataTemplate>
</CheckBox.ContentTemplate>
<FlyoutBase.AttachedFlyout>
<MenuFlyout>
<MenuFlyoutItem Text="Edit" Icon="Edit" Click="EditItem_Click" />
<MenuFlyoutItem Text="Delete" Icon="Delete" Click="DeleteItem_Click" />
</MenuFlyout>
</FlyoutBase.AttachedFlyout>
</CheckBox>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<Button Content="Add Packing Item" Click="AddItem_Button_OnClick"></Button>

<ContentDialog
Name="AddItemDialog"
Title="Add Packing Item"
PrimaryButtonText="Add"
CloseButtonText="Cancel">
<StackPanel Spacing="12" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<TextBox Name="AddItemName" Header="Title" />
<TextBox Name="AddItemDesc" Header="Description" />
<muxc:NumberBox x:Name="AddItemAmount"
Header="Amount"
Value="1"
SpinButtonPlacementMode="Inline"
SmallChange="1"
LargeChange="10" />
</StackPanel>
</ContentDialog>

<ContentDialog
Name="EditItemDialog"
Title="Edit Packing Item"
PrimaryButtonText="Apply"
CloseButtonText="Cancel">
<StackPanel Spacing="12" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<TextBox Name="EditItemName" Header="Title" />
<TextBox Name="EditItemDesc" Header="Description" />
<muxc:NumberBox x:Name="EditItemAmount"
Header="Amount"
Value="1"
SpinButtonPlacementMode="Inline"
SmallChange="1"
LargeChange="10" />
</StackPanel>
</ContentDialog>
</StackPanel>
</Page>


140 changes: 140 additions & 0 deletions Vecto.UWP/Pages/Sections/PackingSectionPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
using System;
using System.Collections.ObjectModel;
using Vecto.Application.Items;
using Vecto.Core.Entities;
using Vecto.UWP.Services;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Navigation;

namespace Vecto.UWP.Pages.Sections
{
public sealed partial class PackingSectionPage : Page
{
private readonly IApiService _service = CustomRefitService.ForAuthenticated<IApiService>();
private TripDetailsPage _tripDetailsPage;
private ObservableCollection<PackingItem> _items;
private Guid _tripId, _sectionId;

protected override async void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);

dynamic parameter = e.Parameter;
_tripId = parameter.TripId;
_sectionId = parameter.SectionId;
_tripDetailsPage = parameter.TripDetailsPage;

var items = await _service.GetPackingItems(_tripId, _sectionId);
_items = new ObservableCollection<PackingItem>(items);

InitializeComponent();
//AddItemAmount.NumberFormatter = new DecimalFormatter() { FractionDigits = 0 };
}

private async void CheckBox_Toggle(object sender, RoutedEventArgs e)
{
try
{
var itemId = GetItemIdFromCheckBox(sender as CheckBox);
await _service.ToggleItem(_tripId, _sectionId, itemId);
Bindings.Update();
_tripDetailsPage.UpdateProgressBar();
}
catch
{
//
// error handling
}
}

private Guid GetItemIdFromCheckBox(CheckBox cb)
{
if (cb is null || cb.Tag is null) throw new Exception();

var success = Guid.TryParse(cb.Tag.ToString(), out var itemId);
return success ? itemId : throw new Exception();
}


private async void AddItem_Button_OnClick(object sender, RoutedEventArgs e)
{
AddItemName.Text = "";
AddItemName.Description = "";
AddItemAmount.Value = 1;

if (await AddItemDialog.ShowAsync() != ContentDialogResult.Primary) return;

try
{
var item = new ItemDTO()
{
Title = AddItemName.Text,
Description = AddItemDesc.Text,
Amount = (int) Math.Ceiling(AddItemAmount.Value)
};

var newItem = await _service.AddPackingItem(_tripId, _sectionId, item);
_items.Add(newItem);
_tripDetailsPage.UpdateProgressBar();
Bindings.Update();
}
catch
{
//TODO exception handling
}
}

private async void EditItem_Click(object sender, RoutedEventArgs e)
{
var item = (sender as MenuFlyoutItem).DataContext as PackingItem;

EditItemName.Text = item.Title;
EditItemDesc.Text = item.Description;
EditItemAmount.Value = item.Amount;

if (await EditItemDialog.ShowAsync() != ContentDialogResult.Primary) return;

try
{
var editedItem = new ItemDTO()
{
Title = EditItemName.Text,
Description = EditItemDesc.Text,
Amount= (int)EditItemAmount.Value
};

var updated = (PackingItem)await _service.UpdatePackingItem(_tripId, _sectionId, item.Id, editedItem);
var index = _items.IndexOf(item);
if (index != -1) _items[index] = updated;
}
catch
{
//TODO exception handling
}
}

private async void DeleteItem_Click(object sender, RoutedEventArgs e)
{
try
{
var item = (sender as MenuFlyoutItem).DataContext as PackingItem;
await _service.DeleteItem(_tripId, _sectionId, item.Id);
_items.Remove(item);
_tripDetailsPage.UpdateProgressBar();
Bindings.Update();
}
catch
{
//TODO error handling
}
}

private void ItemRightTapped(object sender, RightTappedRoutedEventArgs e)
{
FlyoutBase.ShowAttachedFlyout(sender as FrameworkElement);
}
}
}
Loading

0 comments on commit 9ad22d8

Please sign in to comment.