Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experimental attribute for GraphPresenter and sample updates #148

Merged
merged 3 commits into from
Aug 31, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Threading;
using Microsoft.Graph;
using Microsoft.Toolkit.Uwp;
using Windows.Foundation.Metadata;
using Windows.System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
Expand All @@ -18,9 +19,9 @@ namespace CommunityToolkit.Graph.Uwp.Controls
/// <summary>
/// Specialized <see cref="ContentPresenter"/> to fetch and display data from the Microsoft Graph.
/// </summary>
[Experimental]
public class GraphPresenter : ContentPresenter
{

/// <summary>
/// Identifies the <see cref="RequestBuilder"/> dependency property.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Foundation.Metadata;
using Windows.UI.Xaml;

namespace CommunityToolkit.Graph.Uwp.Controls
{
/// <summary>
/// XAML Proxy for <see cref="Microsoft.Graph.QueryOption"/>.
/// </summary>
[Experimental]
public sealed class QueryOption
{
/// <inheritdoc cref="Microsoft.Graph.Option.Name"/>
Expand Down
40 changes: 37 additions & 3 deletions SampleTest/SampleTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,20 @@
<Compile Include="Samples\GraphPresenterSample.xaml.cs">
<DependentUpon>GraphPresenterSample.xaml</DependentUpon>
</Compile>
<Compile Include="Samples\OneDriveStorageSample.xaml.cs">
<DependentUpon>OneDriveStorageSample.xaml</DependentUpon>
<Compile Include="Samples\GraphPresenter\CalendarViewSample.xaml.cs">
<DependentUpon>CalendarViewSample.xaml</DependentUpon>
</Compile>
<Compile Include="Samples\GraphPresenter\MailMessagesSample.xaml.cs">
<DependentUpon>MailMessagesSample.xaml</DependentUpon>
</Compile>
<Compile Include="Samples\GraphPresenter\OneDriveSample.xaml.cs">
<DependentUpon>OneDriveSample.xaml</DependentUpon>
</Compile>
<Compile Include="Samples\GraphPresenter\PlannerTasksSample.xaml.cs">
<DependentUpon>PlannerTasksSample.xaml</DependentUpon>
</Compile>
<Compile Include="Samples\GraphPresenter\TeamsChannelMessagesSample.xaml.cs">
<DependentUpon>TeamsChannelMessagesSample.xaml</DependentUpon>
</Compile>
<Compile Include="Samples\PeoplePickerSample.xaml.cs">
<DependentUpon>PeoplePickerSample.xaml</DependentUpon>
Expand Down Expand Up @@ -166,7 +178,23 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Samples\OneDriveStorageSample.xaml">
<Page Include="Samples\GraphPresenter\CalendarViewSample.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Samples\GraphPresenter\MailMessagesSample.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Samples\GraphPresenter\OneDriveSample.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Samples\GraphPresenter\PlannerTasksSample.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Samples\GraphPresenter\TeamsChannelMessagesSample.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
Expand All @@ -186,6 +214,12 @@
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
<Version>6.2.12</Version>
</PackageReference>
<PackageReference Include="Microsoft.Toolkit.Mvvm">
<Version>7.1.0-preview1</Version>
</PackageReference>
<PackageReference Include="Microsoft.Toolkit.Uwp.UI.Controls">
<Version>7.1.0-preview1</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CommunityToolkit.Authentication.Msal\CommunityToolkit.Authentication.Msal.csproj">
Expand Down
72 changes: 72 additions & 0 deletions SampleTest/Samples/GraphPresenter/CalendarViewSample.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<Page
x:Class="SampleTest.Samples.GraphPresenter.CalendarViewSample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:SampleTest.Samples.GraphPresenter"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="using:CommunityToolkit.Graph.Uwp.Controls"
xmlns:global="using:System.Globalization"
xmlns:graph="using:Microsoft.Graph"
xmlns:samples="using:SampleTest.Samples"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackPanel>
<TextBlock>
The following example shows the `Me.CalendarView` API.
</TextBlock>
<TextBlock Margin="0,8,0,0" FontWeight="Bold">
My Upcoming Calendar Events:
</TextBlock>
</StackPanel>
<controls:GraphPresenter
Grid.Row="1"
IsCollection="True"
OrderBy="start/dateTime"
RequestBuilder="{x:Bind CalendarViewRequestBuilder, Mode=OneWay}"
ResponseType="graph:Event">
<controls:GraphPresenter.QueryOptions>
<!-- Need to create separate Properties as multiple functions not supported in x:Bind see https://github.com/microsoft/microsoft-ui-xaml/issues/2407 -->
<controls:QueryOption Name="startDateTime" Value="{x:Bind Today.ToString('o', global:CultureInfo.InvariantCulture)}" />
<controls:QueryOption Name="endDateTime" Value="{x:Bind ThreeDaysFromNow.ToString('o', global:CultureInfo.InvariantCulture)}" />
</controls:GraphPresenter.QueryOptions>
<controls:GraphPresenter.ContentTemplate>
<DataTemplate>
<!-- Return result is a collection of Event's as we used 'IsCollection', so bind that first. -->
<ScrollViewer HorizontalScrollMode="Disabled" VerticalScrollBarVisibility="Auto">
<ItemsControl ItemsSource="{Binding}">
<ItemsControl.ItemTemplate>
<DataTemplate x:DataType="graph:Event">
<StackPanel>
<TextBlock Style="{StaticResource TitleTextBlockStyle}" Text="{Binding Subject}" />
<TextBlock FontWeight="Bold">
<Run Text="{x:Bind samples:GraphPresenterSample.ToLocalTime(Start), Mode=OneWay}" />
<Run>-</Run>
<Run Text="{x:Bind samples:GraphPresenterSample.ToLocalTime(End), Mode=OneWay}" />
</TextBlock>
<TextBlock>
<Run FontFamily="Segoe MDL2 Assets" Text="&#xE707;" />
<Run />
<Run Text="{x:Bind Location.DisplayName, Mode=OneWay}" />
</TextBlock>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemContainerStyle>
<Style TargetType="ContentPresenter">
<Setter Property="Margin" Value="0,8,0,8" />
</Style>
</ItemsControl.ItemContainerStyle>
</ItemsControl>
</ScrollViewer>
</DataTemplate>
</controls:GraphPresenter.ContentTemplate>
</controls:GraphPresenter>
</Grid>
</Page>
59 changes: 59 additions & 0 deletions SampleTest/Samples/GraphPresenter/CalendarViewSample.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using CommunityToolkit.Authentication;
using CommunityToolkit.Graph.Extensions;
using Microsoft.Graph;
using Microsoft.Graph.Extensions;
using Windows.UI.Xaml.Controls;

namespace SampleTest.Samples.GraphPresenter
{
public sealed partial class CalendarViewSample : Page
{
// Workaround for https://github.com/microsoft/microsoft-ui-xaml/issues/2407
public DateTime Today => DateTimeOffset.Now.Date.ToUniversalTime();

// Workaround for https://github.com/microsoft/microsoft-ui-xaml/issues/2407
public DateTime ThreeDaysFromNow => Today.AddDays(3);

public IBaseRequestBuilder CalendarViewRequestBuilder { get; set; }

public CalendarViewSample()
{
this.InitializeComponent();

ProviderManager.Instance.ProviderUpdated += OnProviderUpdated;
ProviderManager.Instance.ProviderStateChanged += OnProviderStateChanged;
}

private void OnProviderUpdated(object sender, IProvider provider)
{
if (provider == null)
{
ClearRequestBuilders();
}
}

private void OnProviderStateChanged(object sender, ProviderStateChangedEventArgs e)
{
if (e.NewState == ProviderState.SignedIn)
{
var graphClient = ProviderManager.Instance.GlobalProvider.GetClient();

CalendarViewRequestBuilder = graphClient.Me.CalendarView;
}
else
{
ClearRequestBuilders();
}
}

private void ClearRequestBuilders()
{
CalendarViewRequestBuilder = null;
}
}
}
63 changes: 63 additions & 0 deletions SampleTest/Samples/GraphPresenter/MailMessagesSample.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<Page
x:Class="SampleTest.Samples.GraphPresenter.MailMessagesSample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:SampleTest.Samples.GraphPresenter"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="using:CommunityToolkit.Graph.Uwp.Controls"
xmlns:graph="using:Microsoft.Graph"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackPanel>
<TextBlock>
The following example shows the `Me.Messages` API for getting a user's inbox mail messages.
</TextBlock>
<TextBlock Margin="0,8,0,0" FontWeight="Bold">
My Messages:
</TextBlock>
</StackPanel>
<controls:GraphPresenter
Grid.Row="1"
IsCollection="True"
RequestBuilder="{x:Bind MessagesRequestBuilder, Mode=OneWay}"
ResponseType="graph:Message">
<controls:GraphPresenter.ContentTemplate>
<DataTemplate>
<ScrollViewer HorizontalScrollMode="Disabled" VerticalScrollBarVisibility="Auto">
<ItemsControl ItemsSource="{Binding}">
<ItemsControl.ItemTemplate>
<DataTemplate x:DataType="graph:Message">
<StackPanel>
<controls:PersonView
Margin="-4"
PersonQuery="{x:Bind Sender.EmailAddress.Address}"
PersonViewType="OneLine" />
<TextBlock
Padding="0"
Style="{StaticResource BaseTextBlockStyle}"
Text="{x:Bind Subject}" />
<TextBlock
Text="{x:Bind local:MailMessagesSample.RemoveWhitespace(BodyPreview)}"
TextWrapping="WrapWholeWords" />
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemContainerStyle>
<Style TargetType="ContentPresenter">
<Setter Property="Margin" Value="0,8,0,8" />
</Style>
</ItemsControl.ItemContainerStyle>
</ItemsControl>
</ScrollViewer>
</DataTemplate>
</controls:GraphPresenter.ContentTemplate>
</controls:GraphPresenter>
</Grid>
</Page>
57 changes: 57 additions & 0 deletions SampleTest/Samples/GraphPresenter/MailMessagesSample.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Text.RegularExpressions;
using CommunityToolkit.Authentication;
using CommunityToolkit.Graph.Extensions;
using Microsoft.Graph;
using Windows.UI.Xaml.Controls;

namespace SampleTest.Samples.GraphPresenter
{
public sealed partial class MailMessagesSample : Page
{
public IBaseRequestBuilder MessagesRequestBuilder { get; set; }

public MailMessagesSample()
{
this.InitializeComponent();
ProviderManager.Instance.ProviderUpdated += OnProviderUpdated;
ProviderManager.Instance.ProviderStateChanged += OnProviderStateChanged;
}

private void OnProviderUpdated(object sender, IProvider provider)
{
if (provider == null)
{
ClearRequestBuilders();
}
}

private void OnProviderStateChanged(object sender, ProviderStateChangedEventArgs e)
{
if (e.NewState == ProviderState.SignedIn)
{
var graphClient = ProviderManager.Instance.GlobalProvider.GetClient();

MessagesRequestBuilder = graphClient.Me.Messages;
}
else
{
ClearRequestBuilders();
}
}

private void ClearRequestBuilders()
{
MessagesRequestBuilder = null;
}

public static string RemoveWhitespace(string value)
{
// Workaround for https://github.com/microsoft/microsoft-ui-xaml/issues/2654
return Regex.Replace(value, @"\t|\r|\n", " ");
}
}
}
Loading