Skip to content

Commit

Permalink
All changes to add X functionality to Login UI and remove unused fiel…
Browse files Browse the repository at this point in the history
…ds from interface (#223)

* changes to LoginUI and IDeveloper interface

* test

* add loginuicontent

* additional changes

* fix bad merge

* modify one more reference of unused developer id fields

---------

Co-authored-by: Kristen Schau <[email protected]>
  • Loading branch information
ssparach and krschau authored Apr 15, 2023
1 parent 0026e05 commit 2f281e7
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 127 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ namespace Microsoft.Windows.DevHome.SDK
interface IDeveloperId
{
String LoginId();
String DisplayName();
String Email();
String Url();
};

Expand Down
62 changes: 3 additions & 59 deletions settings/DevHome.Settings/Strings/en-us/Resources.resw
Original file line number Diff line number Diff line change
@@ -1,64 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
Expand Down Expand Up @@ -247,4 +188,7 @@
<data name="Settings_SubTitle.Text" xml:space="preserve">
<value>Settings</value>
</data>
<data name="LoginUIDialogTitle.Text" xml:space="preserve">
<value>Connect your account</value>
</data>
</root>
38 changes: 5 additions & 33 deletions settings/DevHome.Settings/ViewModels/AccountsProviderViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,58 +4,30 @@
using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.ComponentModel;
using DevHome.Common.Views;
using DevHome.Settings.Helpers;
using DevHome.Settings.Models;
using DevHome.Settings.Views;
using DevHome.Telemetry;
using Microsoft.UI.Xaml.Controls;
using Microsoft.Windows.DevHome.SDK;

namespace DevHome.Settings.ViewModels;
public partial class AccountsProviderViewModel : ObservableObject
{
private readonly IDeveloperIdProvider _devIdProvider;
public IDeveloperIdProvider DevIdProvider { get; }

public ObservableCollection<Account> LoggedInAccounts { get; } = new ();

public AccountsProviderViewModel(IDeveloperIdProvider devIdProvider)
{
_devIdProvider = devIdProvider;
DevIdProvider = devIdProvider;
RefreshLoggedInAccounts();
}

public string ProviderName => _devIdProvider.GetName();

public async Task ShowLoginUIAsync(string loginEntryPoint, Page parentPage)
{
string[] args = { loginEntryPoint };
var loginUIAdaptiveCardController = _devIdProvider.GetAdaptiveCardController(args);
var pluginAdaptiveCardPanel = new PluginAdaptiveCardPanel();
pluginAdaptiveCardPanel.Bind(loginUIAdaptiveCardController, AdaptiveCardRendererHelper.GetLoginUIRenderer());
pluginAdaptiveCardPanel.RequestedTheme = parentPage.ActualTheme;

// TODO: Replace Close button with "X"
var loginUIContentDialog = new LoginUIDialog
{
Content = pluginAdaptiveCardPanel,
XamlRoot = parentPage.XamlRoot,
RequestedTheme = parentPage.ActualTheme,
CloseButtonText = "Close",
};
await loginUIContentDialog.ShowAsync();
RefreshLoggedInAccounts();

// TODO: Await Login event to match up the loginEntryPoint and return DeveloperId
loginUIAdaptiveCardController.Dispose();
}
public string ProviderName => DevIdProvider.GetName();

public void RefreshLoggedInAccounts()
{
LoggedInAccounts.Clear();
_devIdProvider.GetLoggedInDeveloperIds().ToList().ForEach((devId) =>
DevIdProvider.GetLoggedInDeveloperIds().ToList().ForEach((devId) =>
{
LoggedInAccounts.Add(new Account(this, devId));
});
Expand All @@ -68,7 +40,7 @@ public void RemoveAccount(string loginId)
{
try
{
_devIdProvider.LogoutDeveloperId(accountToRemove.GetDevId());
DevIdProvider.LogoutDeveloperId(accountToRemove.GetDevId());
}
catch (Exception ex)
{
Expand Down
10 changes: 6 additions & 4 deletions settings/DevHome.Settings/Views/AccountsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@
<Button x:Uid="Settings_Accounts_AddAccountButton" HorizontalAlignment="Right">
<Button.Flyout>
<Flyout Placement="Bottom">
<ItemsRepeater ItemsSource="{x:Bind ViewModel.AccountsProviders}" ItemTemplate="{StaticResource AccountsProviderButtonTemplate}"
HorizontalAlignment="Stretch" VerticalAlignment="Center" Visibility="Visible">
<ItemsRepeater ItemsSource="{x:Bind ViewModel.AccountsProviders}"
ItemTemplate="{StaticResource AccountsProviderButtonTemplate}"
HorizontalAlignment="Stretch" VerticalAlignment="Center">
</ItemsRepeater>
<Flyout.FlyoutPresenterStyle>
<Style TargetType="FlyoutPresenter">
Expand All @@ -73,8 +74,9 @@
</StackPanel>

<StackPanel>
<ItemsRepeater ItemsSource="{x:Bind ViewModel.AccountsProviders}" ItemTemplate="{StaticResource AccountsProviderViewTemplate}"
HorizontalAlignment="Stretch" VerticalAlignment="Center" Visibility="Visible">
<ItemsRepeater ItemsSource="{x:Bind ViewModel.AccountsProviders}"
ItemTemplate="{StaticResource AccountsProviderViewTemplate}"
HorizontalAlignment="Stretch" VerticalAlignment="Center">
</ItemsRepeater>
</StackPanel>
</StackPanel>
Expand Down
27 changes: 26 additions & 1 deletion settings/DevHome.Settings/Views/AccountsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
// Licensed under the MIT License.

using System;
using System.Threading.Tasks;
using DevHome.Common.Extensions;
using DevHome.Common.Views;
using DevHome.Settings.Helpers;
using DevHome.Settings.Models;
using DevHome.Settings.ViewModels;
using DevHome.Telemetry;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.Windows.ApplicationModel.Resources;
using Microsoft.Windows.DevHome.SDK;

namespace DevHome.Settings.Views;

Expand Down Expand Up @@ -47,7 +51,7 @@ private async void AddDeveloperId_Click(object sender, RoutedEventArgs e)
{
try
{
await accountProvider.ShowLoginUIAsync("Settings", this);
await ShowLoginUIAsync("Settings", this, accountProvider);
}
catch (Exception ex)
{
Expand All @@ -64,6 +68,27 @@ private async void AddDeveloperId_Click(object sender, RoutedEventArgs e)
}
}

public async Task ShowLoginUIAsync(string loginEntryPoint, Page parentPage, AccountsProviderViewModel accountProvider)
{
string[] args = { loginEntryPoint };
var loginUIAdaptiveCardController = accountProvider.DevIdProvider.GetAdaptiveCardController(args);
var pluginAdaptiveCardPanel = new PluginAdaptiveCardPanel();
pluginAdaptiveCardPanel.Bind(loginUIAdaptiveCardController, AdaptiveCardRendererHelper.GetLoginUIRenderer());
pluginAdaptiveCardPanel.RequestedTheme = parentPage.ActualTheme;

var loginUIContentDialog = new LoginUIDialog(pluginAdaptiveCardPanel)
{
XamlRoot = parentPage.XamlRoot,
RequestedTheme = parentPage.ActualTheme,
};

await loginUIContentDialog.ShowAsync();
accountProvider.RefreshLoggedInAccounts();

// TODO: Await Login event to match up the loginEntryPoint and return DeveloperId
loginUIAdaptiveCardController.Dispose();
}

private async void Logout_Click(object sender, RoutedEventArgs e)
{
var resourceLoader = new ResourceLoader(ResourceLoader.GetDefaultResourceFilePath(), "DevHome.Settings/Resources");
Expand Down
27 changes: 15 additions & 12 deletions settings/DevHome.Settings/Views/LoginUIDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,20 @@
<x:Double x:Key="ContentDialogMaxHeight">502</x:Double>
<Thickness x:Key="ContentDialogTitleMargin">0,0,0,0</Thickness>
</ContentDialog.Resources>

<StackPanel>
<!-- Title and Close button -->
<Grid>
<TextBlock x:Uid="LoginUIDialogTitle" HorizontalAlignment="Left" Text="Connect your account"/>
<Button HorizontalAlignment="Right" Click="CloseButton_Click"
BorderThickness="0" Background="Red" Foreground="Red">
<TextBlock FontFamily="{ThemeResource SymbolThemeFontFamily}"
FontSize="{ThemeResource BodyTextBlockFontSize}"
Text="&#xE10A;" />
</Button>
</Grid>

<StackPanel>
<!-- Title and Close button -->
<Grid>
<TextBlock x:Uid="LoginUIDialogTitle" HorizontalAlignment="Left"
Style="{ThemeResource SubtitleTextBlockStyle}"/>
<Button HorizontalAlignment="Right" Click="CloseButton_Click"
BorderThickness="0" Background="Transparent" Padding="5">
<TextBlock FontFamily="{ThemeResource SymbolThemeFontFamily}"
FontSize="{ThemeResource BodyTextBlockFontSize}"
Text="&#xE10A;" />
</Button>
</Grid>

<Frame x:Name="LoginUIContent" />
</StackPanel>
</ContentDialog>
5 changes: 3 additions & 2 deletions settings/DevHome.Settings/Views/LoginUIDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
namespace DevHome.Settings.Views;
public sealed partial class LoginUIDialog : ContentDialog
{
public LoginUIDialog()
public LoginUIDialog(StackPanel pluginAdaptiveCardPanel)
{
this.InitializeComponent();
LoginUIContent.Content = pluginAdaptiveCardPanel;
}

private void CloseButton_Click(object sender, RoutedEventArgs e)
{
Hide();
this.Hide();
}
}
12 changes: 1 addition & 11 deletions tools/SetupFlow/DevHome.SetupFlow/Models/DeveloperId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,16 @@ namespace DevHome.SetupFlow.Models;
/// </summary>
public class DeveloperId : IDeveloperId
{
private readonly string _displayName;

private readonly string _email;

private readonly string _loginId;

private readonly string _url;

public string DisplayName() => _displayName;

public string Email() => _email;

public string LoginId() => _loginId;

public string Url() => _url;

public DeveloperId(string displayName, string email, string loginId, string url)
public DeveloperId(string loginId, string url)
{
_displayName = displayName;
_email = email;
_loginId = loginId;
_url = url;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public IEnumerable<IDeveloperId> GetAllLoggedInAccounts(string providerName)
/// <returns>All the repositories for an account and provider.</returns>
public IEnumerable<IRepository> GetAllRepositories(string providerName, IDeveloperId developerId)
{
Log.Logger?.ReportInfo(Log.Component.RepoConfig, $"Getting all repositories for repository provider {providerName} and account {developerId.DisplayName}");
Log.Logger?.ReportInfo(Log.Component.RepoConfig, $"Getting all repositories for repository provider {providerName}");
return _providers.GetValueOrDefault(providerName)?.GetAllRepositories(developerId) ?? new List<IRepository>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ public void AddRepositoryViaUri(string url, string cloneLocation)
{
// a provider parsed the Url and returned a valid IRepository
var repository = providerNameAndRepo.Item2;
var developerId = new DeveloperId(repository.OwningAccountName, string.Empty, repository.OwningAccountName, Url);
var developerId = new DeveloperId(repository.OwningAccountName, Url);
cloningInformation.ProviderName = providerNameAndRepo.Item1;
cloningInformation.OwningAccount = developerId;
cloningInformation.RepositoryToClone = repository;
Expand All @@ -333,7 +333,7 @@ public void AddRepositoryViaUri(string url, string cloneLocation)
cloningInformation.ProviderName = "git";

// Because the user is cloning via URL the developer account is unknown.
var gitDeveloperId = new DeveloperId("Unknown", string.Empty, "FromGitUrl", Url);
var gitDeveloperId = new DeveloperId("FromGitUrl", Url);
cloningInformation.OwningAccount = gitDeveloperId;
cloningInformation.RepositoryToClone = new GenericRepository(uriToParse);
cloningInformation.CloningLocation = new DirectoryInfo(cloneLocation);
Expand Down

0 comments on commit 2f281e7

Please sign in to comment.