diff options
| author | Roy Ben Shabat <Roy@twine-s.com> | 2020-12-30 15:11:34 +0000 |
|---|---|---|
| committer | Roy Ben Shabat <Roy@twine-s.com> | 2020-12-30 15:11:34 +0000 |
| commit | d33c19b3ac6803de4b5c8d475832efef131c1a45 (patch) | |
| tree | ea725abc39def99a755b041c13cba1fe0d594ddc /Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles | |
| parent | 1bdcaa9f51303bbff682507f31fb3b4414692ca4 (diff) | |
| download | Tango-d33c19b3ac6803de4b5c8d475832efef131c1a45.tar.gz Tango-d33c19b3ac6803de4b5c8d475832efef131c1a45.zip | |
Revert "Hope it is fine"
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles')
11 files changed, 359 insertions, 21 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Converters/RoleEnumToVisibleConverter.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Converters/RoleEnumToVisibleConverter.cs new file mode 100644 index 000000000..350257fdd --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Converters/RoleEnumToVisibleConverter.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Data; +using Tango.BL.Enumerations; + +namespace Tango.MachineStudio.UsersAndRoles.Converters +{ + public class RoleEnumToVisibleConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if(value.GetType().IsEnum && Enum.IsDefined(typeof(Roles), value)) + { + Roles roleEnum = (Roles)value; + if (roleEnum.ToString().StartsWith("FSE")) + return Visibility.Collapsed; + } + + return Visibility.Visible; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Images/login.png b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Images/login.png Binary files differnew file mode 100644 index 000000000..9f7d0b9ba --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Images/login.png diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Tango.MachineStudio.UsersAndRoles.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Tango.MachineStudio.UsersAndRoles.csproj index 82376b751..687544c1b 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Tango.MachineStudio.UsersAndRoles.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Tango.MachineStudio.UsersAndRoles.csproj @@ -49,6 +49,9 @@ <Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> <HintPath>..\..\..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath> </Reference> + <Reference Include="SimpleValidator, Version=0.6.1.0, Culture=neutral, processorArchitecture=MSIL"> + <HintPath>..\..\..\packages\SimpleValidator.0.6.1.0\lib\net40\SimpleValidator.dll</HintPath> + </Reference> <Reference Include="System" /> <Reference Include="System.ComponentModel.DataAnnotations" /> <Reference Include="System.Data" /> @@ -72,6 +75,7 @@ <Compile Include="..\..\..\Versioning\GlobalVersionInfo.cs"> <Link>GlobalVersionInfo.cs</Link> </Compile> + <Compile Include="Converters\RoleEnumToVisibleConverter.cs" /> <Compile Include="Navigation\UsersAndRolesNavigationManager.cs" /> <Compile Include="Navigation\UsersAndRolesNavigationView.cs" /> <Compile Include="Providers\PlaceAddress.cs" /> @@ -80,6 +84,7 @@ <Compile Include="UsersAndRolesModule.cs" /> <Compile Include="ViewModelLocator.cs" /> <Compile Include="ViewModels\MainViewVM.cs" /> + <Compile Include="ViewModels\UserCreationDialogVM.cs" /> <Compile Include="Views\AddressView.xaml.cs"> <DependentUpon>AddressView.xaml</DependentUpon> </Compile> @@ -95,6 +100,9 @@ <Compile Include="Views\OrganizationSelectionView.xaml.cs"> <DependentUpon>OrganizationSelectionView.xaml</DependentUpon> </Compile> + <Compile Include="Views\UserCreationDialog.xaml.cs"> + <DependentUpon>UserCreationDialog.xaml</DependentUpon> + </Compile> <Compile Include="Views\UserManagementView.xaml.cs"> <DependentUpon>UserManagementView.xaml</DependentUpon> </Compile> @@ -120,7 +128,9 @@ <Generator>ResXFileCodeGenerator</Generator> <LastGenOutput>Resources.Designer.cs</LastGenOutput> </EmbeddedResource> - <None Include="app.config" /> + <None Include="app.config"> + <SubType>Designer</SubType> + </None> <None Include="packages.config" /> <None Include="Properties\Settings.settings"> <Generator>SettingsSingleFileGenerator</Generator> @@ -186,6 +196,10 @@ <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> + <Page Include="Views\UserCreationDialog.xaml"> + <SubType>Designer</SubType> + <Generator>MSBuild:Compile</Generator> + </Page> <Page Include="Views\UserManagementView.xaml"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> @@ -210,6 +224,9 @@ <ItemGroup> <Resource Include="Images\roles.png" /> </ItemGroup> + <ItemGroup> + <Resource Include="Images\login.png" /> + </ItemGroup> <ItemGroup /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <ProjectExtensions> diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/ViewModels/MainViewVM.cs index a46d5f456..16395d6bc 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/ViewModels/MainViewVM.cs @@ -15,6 +15,10 @@ using Tango.MachineStudio.UsersAndRoles.Providers; using Tango.SharedUI; using System.Data.Entity; using Tango.BL.Builders; +using Tango.BL.ActionLogs; +using Tango.BL.DTO; +using Tango.BL.Enumerations; +using Tango.MachineStudio.Common.Authentication; namespace Tango.MachineStudio.UsersAndRoles.ViewModels { @@ -25,6 +29,10 @@ namespace Tango.MachineStudio.UsersAndRoles.ViewModels private ObservablesContext _userContext; private UsersAndRolesNavigationManager _navigation; private INotificationProvider _notification; + private IActionLogManager _actionLogManager; + private OrganizationDTO _organizationBeforeSave; + private IAuthenticationProvider _authenticationProvider; + private UserDTO _userBeforeSave; private ObservableCollection<Organization> _organizations; public ObservableCollection<Organization> Organizations @@ -105,6 +113,21 @@ namespace Tango.MachineStudio.UsersAndRoles.ViewModels } } + private bool _showDeleted; + public bool ShowDeleted + { + get { return _showDeleted; } + set + { + _showDeleted = value; + if (_showDeleted) + { + //ShowDeletedUsers(); + } + } + } + + public RelayCommand ManageOrganizationCommand { get; set; } public RelayCommand BackToOrganizationsCommand { get; set; } @@ -123,14 +146,18 @@ namespace Tango.MachineStudio.UsersAndRoles.ViewModels public RelayCommand SaveManagedUserCommand { get; set; } + public RelayCommand RestoreAndSaveManagedUserCommand { get; set; } + public RelayCommand AddUserCommand { get; set; } public RelayCommand RemoveUserCommand { get; set; } - public MainViewVM(UsersAndRolesNavigationManager navigation, INotificationProvider notification) + public MainViewVM(UsersAndRolesNavigationManager navigation, INotificationProvider notification, IActionLogManager actionLogManager, IAuthenticationProvider authenticationProvider) { _navigation = navigation; _notification = notification; + _actionLogManager = actionLogManager; + _authenticationProvider = authenticationProvider; ManageOrganizationCommand = new RelayCommand(LoadSelectedOrganization, () => SelectedOrganization != null); BackToOrganizationsCommand = new RelayCommand(BackToOrganizations); @@ -141,8 +168,10 @@ namespace Tango.MachineStudio.UsersAndRoles.ViewModels BackToManagedOrganizationCommand = new RelayCommand(BackToManagedOrganization); RemoveRoleCommand = new RelayCommand<Role>(RemoveUserRole); SaveManagedUserCommand = new RelayCommand(SaveManagedUser); + RestoreAndSaveManagedUserCommand = new RelayCommand(RestoreAndSaveManagedUser); AddUserCommand = new RelayCommand(AddNewUser); RemoveUserCommand = new RelayCommand(RemoveSelectedUser, () => SelectedUser != null); + _showDeleted = false; } public override void OnApplicationReady() @@ -164,6 +193,7 @@ namespace Tango.MachineStudio.UsersAndRoles.ViewModels org.Contact = new Contact(); _organizationsContext.Organizations.Add(org); await org.SaveAsync(_organizationsContext); + _actionLogManager.InsertLog(ActionLogType.OrganizationCreated, _authenticationProvider.CurrentUser, org.Name, org, "Organization created using Machine Studio."); Organizations = _organizationsContext.Organizations.ToObservableCollection(); SelectedOrganization = org; LoadSelectedOrganization(); @@ -178,6 +208,7 @@ namespace Tango.MachineStudio.UsersAndRoles.ViewModels using (_notification.PushTaskItem("Removing organization...")) { await SelectedOrganization.DeleteCascadeAsync(_organizationsContext); + _actionLogManager.InsertLog(ActionLogType.OrganizationDeleted, _authenticationProvider.CurrentUser, SelectedOrganization.Name, SelectedOrganization, "Organization deleted using Machine Studio."); await LoadOrganizations(); } } @@ -187,7 +218,13 @@ namespace Tango.MachineStudio.UsersAndRoles.ViewModels { using (_notification.PushTaskItem("Saving organization address and contact...")) { + var organizationAfter = OrganizationDTO.FromObservable(ManagedOrganization); + await ManagedOrganization.SaveAsync(_manageContext); + _actionLogManager.InsertLog(ActionLogType.OrganizationSaved, _authenticationProvider.CurrentUser, ManagedOrganization.Name, _organizationBeforeSave, organizationAfter, "Organization saved using Machine Studio."); + + _organizationBeforeSave = organizationAfter; + await LoadOrganizations(); SelectedOrganization = Organizations.SingleOrDefault(x => x.Guid == ManagedOrganization.Guid); } @@ -202,8 +239,10 @@ namespace Tango.MachineStudio.UsersAndRoles.ViewModels _userContext = ObservablesContext.CreateDefault(); Roles = new RolesCollectionBuilder(_userContext).SetAll().WithPermission().Build(); - ManagedUser = new UserBuilder(_userContext).Set(SelectedUser.Guid).WithRolesAndPermissions().Build(); + ManagedUser = new UserBuilder(_userContext).WithDeleted().Set(SelectedUser.Guid).WithRolesAndPermissions().Build(); ManagedUserRoles = ManagedUser.Roles.ToObservableCollection(); + + _userBeforeSave = UserDTO.FromObservable(ManagedUser); }); _navigation.NavigateTo(UsersAndRolesNavigationView.UserManagementView); @@ -235,6 +274,11 @@ namespace Tango.MachineStudio.UsersAndRoles.ViewModels try { ManagedUser.Validate(_userContext); + + if (ManagedUser.Roles.GroupBy(x => x.RoleEnum).Any(x => x.Count() > 1)) + { + throw new InvalidOperationException("Cannot save user with duplicate roles."); + } } catch (Exception ex) { @@ -244,11 +288,45 @@ namespace Tango.MachineStudio.UsersAndRoles.ViewModels using (_notification.PushTaskItem("Saving user details...")) { + var userAfter = UserDTO.FromObservable(ManagedUser); await ManagedUser.SaveAsync(_userContext); + _actionLogManager.InsertLog(ActionLogType.UserSaved, _authenticationProvider.CurrentUser, ManagedUser.Email, _userBeforeSave, userAfter, "User saved using Machine Studio."); + _userBeforeSave = userAfter; LoadSelectedOrganization(); } } + private async void RestoreAndSaveManagedUser() + { + try + { + ManagedUser.Validate(_userContext); + + if (ManagedUser.Roles.GroupBy(x => x.RoleEnum).Any(x => x.Count() > 1)) + { + throw new InvalidOperationException("Cannot save user with duplicate roles."); + } + } + catch (Exception ex) + { + _notification.ShowError(ex.Message); + return; + } + if (_notification.ShowQuestion("Are you sure you wish to re-activate this account?")) + { + using (_notification.PushTaskItem("Saving user details...")) + { + ManagedUser.Deleted = false; + + var userAfter = UserDTO.FromObservable(ManagedUser); + await ManagedUser.SaveAsync(_userContext); + _actionLogManager.InsertLog(ActionLogType.UserRestored, _authenticationProvider.CurrentUser, ManagedUser.Email, _userBeforeSave, userAfter, "User restored using Machine Studio."); + _userBeforeSave = userAfter; + LoadSelectedOrganization(); + } + } + } + private async void LoadSelectedOrganization() { using (_notification.PushTaskItem("Loading organization...")) @@ -257,7 +335,9 @@ namespace Tango.MachineStudio.UsersAndRoles.ViewModels { _manageContext = ObservablesContext.CreateDefault(); - ManagedOrganization = new OrganizationBuilder(_manageContext).Set(SelectedOrganization.Guid).WithUsers().Build(); + ManagedOrganization = new OrganizationBuilder(_manageContext).Set(SelectedOrganization.Guid).WithUsers(true).Build(); + + _organizationBeforeSave = OrganizationDTO.FromObservable(ManagedOrganization); }); _navigation.NavigateTo(UsersAndRolesNavigationView.OrganizationManagementView); @@ -294,25 +374,25 @@ namespace Tango.MachineStudio.UsersAndRoles.ViewModels using (_notification.PushTaskItem("Removing user...")) { await SelectedUser.DeleteCascadeAsync(_manageContext); + _actionLogManager.InsertLog(ActionLogType.UserDeleted, _authenticationProvider.CurrentUser, SelectedUser.Email, SelectedUser, "User deleted using Machine Studio."); LoadSelectedOrganization(); } } } - private async void AddNewUser() + private void AddNewUser() { - String email = _notification.ShowTextInput("Enter user email", "email"); - - if (!String.IsNullOrWhiteSpace(email)) + _notification.ShowModalDialog<UserCreationDialogVM>(async (vm) => { User user = new User(); - user.Email = email; - user.Password = "1111"; + user.Email = vm.Email; + user.Password = User.GetPasswordHash(vm.Password); + user.PasswordChangeRequired = true; user.Contact = new Contact() { - FirstName = "Twine", - LastName = "User", - Email = email, + FirstName = vm.FirstName, + LastName = vm.LastName, + Email = vm.Email, }; user.Address = new Address(); @@ -323,9 +403,25 @@ namespace Tango.MachineStudio.UsersAndRoles.ViewModels Role = _manageContext.Roles.SingleOrDefault(x => x.Code == (int)BL.Enumerations.Roles.User) }); + user.UsersRoles.Add(new UsersRole() + { + User = user, + Role = _manageContext.Roles.SingleOrDefault(x => x.Code == (int)BL.Enumerations.Roles.MachineStudioUser) + }); + + user.UsersRoles.Add(new UsersRole() + { + User = user, + Role = _manageContext.Roles.SingleOrDefault(x => x.Code == (int)BL.Enumerations.Roles.PPCUser) + }); + try { - user.Validate(_manageContext); + if (!user.Validate(_manageContext)) + { + _notification.ShowError(String.Join(Environment.NewLine, user.ValidationErrors)); + return; + } } catch (Exception ex) { @@ -338,10 +434,13 @@ namespace Tango.MachineStudio.UsersAndRoles.ViewModels using (_notification.PushTaskItem("Adding new user...")) { await ManagedOrganization.SaveAsync(_manageContext); + _actionLogManager.InsertLog(ActionLogType.UserCreated, _authenticationProvider.CurrentUser, user.Email, user, "User created using Machine Studio."); await LoadOrganizations(); SelectedOrganization = Organizations.SingleOrDefault(x => x.Guid == ManagedOrganization.Guid); + SelectedUser = user; + LoadSelectedUser(); } - } + }); } private void SetUserPlace(Place place) diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/ViewModels/UserCreationDialogVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/ViewModels/UserCreationDialogVM.cs new file mode 100644 index 000000000..08762ac96 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/ViewModels/UserCreationDialogVM.cs @@ -0,0 +1,74 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SimpleValidator.Extensions; +using Tango.SharedUI; + +namespace Tango.MachineStudio.UsersAndRoles.ViewModels +{ + public class UserCreationDialogVM : DialogViewVM + { + private static Random rnd = new Random(); + + private String _email; + [Required(ErrorMessage = "Email is required")] + [EmailAddress(ErrorMessage = "Please provide a valid email")] + public String Email + { + get { return _email; } + set { _email = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); } + } + + private String _password; + public String Password + { + get { return _password; } + set { _password = value; RaisePropertyChangedAuto(); } + } + + private String _firstName; + [Required(ErrorMessage = "First name is required")] + public String FirstName + { + get { return _firstName; } + set { _firstName = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); } + } + + private String _lastName; + [Required(ErrorMessage = "Last name is required")] + public String LastName + { + get { return _lastName; } + set { _lastName = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); } + } + + protected override void Accept() + { + if (Validate()) + { + base.Accept(); + } + } + + public override void OnShow() + { + base.OnShow(); + Password = GetRandomPassword(4); + } + + private String GetRandomPassword(int count) + { + String pass = String.Empty; + + for (int i = 0; i < count; i++) + { + pass += rnd.Next(0, 9).ToString(); + } + + return pass; + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Views/OrganizationManagementView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Views/OrganizationManagementView.xaml index d5a5d41d7..a14d59949 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Views/OrganizationManagementView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Views/OrganizationManagementView.xaml @@ -82,6 +82,10 @@ </Button> </StackPanel> </Grid> + <StackPanel Orientation="Horizontal" DockPanel.Dock="Bottom" VerticalAlignment="Center" Margin="0 10 0 5" HorizontalAlignment="Left"> + <CheckBox Name="cbShowDeleted" IsChecked="{Binding ShowDeleted}" VerticalAlignment="Center"></CheckBox> + <TextBlock Margin="10 0 0 0" VerticalAlignment="Center" Text="Show deleted accounts" FontSize="16" FontWeight="Normal"></TextBlock> + </StackPanel> <Grid DockPanel.Dock="Bottom"> <StackPanel VerticalAlignment="Center" Orientation="Horizontal" HorizontalAlignment="Left" Margin="0 0 0 0"> <Button Margin="0 0 10 0" MinWidth="160" Height="50" Background="{StaticResource RedBrush300}" BorderBrush="{StaticResource RedBrush300}" Command="{Binding RemoveUserCommand}"> @@ -113,6 +117,28 @@ <Setter Property="BorderThickness" Value="0"/> <Setter Property="FocusVisualStyle" Value="{x:Null}"/> <Setter Property="VerticalContentAlignment" Value="Center"></Setter> + <Setter Property="Visibility" Value="Visible" /> + <Style.Triggers> + <MultiDataTrigger> + <MultiDataTrigger.Conditions> + <Condition Binding="{Binding ElementName=cbShowDeleted, Path=IsChecked}" Value="False"/> + <Condition Binding="{Binding Deleted}" Value="True"/> + </MultiDataTrigger.Conditions> + <MultiDataTrigger.Setters> + <Setter Property="Visibility" Value="Collapsed" /> + </MultiDataTrigger.Setters> + </MultiDataTrigger> + <MultiDataTrigger> + <MultiDataTrigger.Conditions> + <Condition Binding="{Binding ElementName=cbShowDeleted, Path=IsChecked}" Value="true"/> + <Condition Binding="{Binding Deleted}" Value="True"/> + </MultiDataTrigger.Conditions> + <MultiDataTrigger.Setters> + <Setter Property="Visibility" Value="Visible" /> + <Setter Property="Foreground" Value="{StaticResource RedBrush100}" /> + </MultiDataTrigger.Setters> + </MultiDataTrigger> + </Style.Triggers> </Style> </DataGrid.CellStyle> <DataGrid.Columns> diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Views/UserCreationDialog.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Views/UserCreationDialog.xaml new file mode 100644 index 000000000..7433d3768 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Views/UserCreationDialog.xaml @@ -0,0 +1,53 @@ +<UserControl x:Class="Tango.MachineStudio.UsersAndRoles.Views.UserCreationDialog" + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:controls="clr-namespace:Tango.SharedUI.Controls;assembly=Tango.SharedUI" + xmlns:global="clr-namespace:Tango.MachineStudio.UsersAndRoles" + xmlns:vm="clr-namespace:Tango.MachineStudio.UsersAndRoles.ViewModels" + xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" + xmlns:local="clr-namespace:Tango.MachineStudio.UsersAndRoles.Views" + mc:Ignorable="d" + d:DesignHeight="400" d:DesignWidth="700" Height="400" Width="700" Background="{StaticResource WhiteBackgroundBrush}" d:DataContext="{d:DesignInstance Type=vm:UserCreationDialogVM, IsDesignTimeCreatable=False}"> + <Grid Margin="10"> + <DockPanel> + <Grid DockPanel.Dock="Top"> + <StackPanel Orientation="Horizontal"> + <Grid> + <Image Source="../Images/login.png" Width="80" RenderOptions.BitmapScalingMode="Fant"></Image> + <materialDesign:PackIcon HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="0 0 -14 -10" Kind="PlusCircle" Foreground="#15C315" Width="42" Height="42" /> + </Grid> + <TextBlock Margin="30 0 0 0" VerticalAlignment="Bottom" FontSize="22">NEW USER</TextBlock> + </StackPanel> + </Grid> + + <Grid DockPanel.Dock="Bottom"> + <StackPanel Orientation="Horizontal" VerticalAlignment="Bottom" HorizontalAlignment="Right" DockPanel.Dock="Bottom"> + <Button Command="{Binding CloseCommand}" Width="140" Height="40" Margin="0 0 10 0"> + CANCEL + </Button> + <Button Command="{Binding OKCommand}" IsDefault="True" Width="140" Height="40"> + CREATE + </Button> + </StackPanel> + </Grid> + + <Grid> + <StackPanel Width="400" HorizontalAlignment="Center" Margin="20"> + <controls:TableGrid RowHeight="40"> + <TextBlock>EMAIL</TextBlock> + <TextBox Text="{Binding Email,UpdateSourceTrigger=LostFocus,NotifyOnValidationError=True,ValidatesOnDataErrors=True,ValidatesOnNotifyDataErrors=True}"></TextBox> + <TextBlock>FIRST NAME</TextBlock> + <TextBox Text="{Binding FirstName,UpdateSourceTrigger=LostFocus,NotifyOnValidationError=True,ValidatesOnDataErrors=True,ValidatesOnNotifyDataErrors=True}"></TextBox> + <TextBlock>LAST NAME</TextBlock> + <TextBox Text="{Binding LastName,UpdateSourceTrigger=LostFocus,NotifyOnValidationError=True,ValidatesOnDataErrors=True,ValidatesOnNotifyDataErrors=True}"></TextBox> + </controls:TableGrid> + + <TextBox Margin="0 -15 0 0" Style="{x:Null}" BorderThickness="0" FontSize="30" HorizontalAlignment="Center" Text="{Binding Password}" IsReadOnly="True"></TextBox> + <TextBlock HorizontalAlignment="Center" Margin="0 5 0 0" Foreground="{StaticResource GrayBrush}">Provide this password to the user</TextBlock> + </StackPanel> + </Grid> + </DockPanel> + </Grid> +</UserControl> diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Views/UserCreationDialog.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Views/UserCreationDialog.xaml.cs new file mode 100644 index 000000000..cfa389ed1 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Views/UserCreationDialog.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Tango.MachineStudio.UsersAndRoles.Views +{ + /// <summary> + /// Interaction logic for UserCreationDialog.xaml + /// </summary> + public partial class UserCreationDialog : UserControl + { + public UserCreationDialog() + { + InitializeComponent(); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Views/UserManagementView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Views/UserManagementView.xaml index bb003f525..2a8621e5c 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Views/UserManagementView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Views/UserManagementView.xaml @@ -14,11 +14,15 @@ xmlns:entities="clr-namespace:Tango.BL.Entities;assembly=Tango.BL" xmlns:local="clr-namespace:Tango.MachineStudio.UsersAndRoles.Views" xmlns:converters="clr-namespace:Tango.SharedUI.Converters;assembly=Tango.SharedUI" + xmlns:localconverters="clr-namespace:Tango.MachineStudio.UsersAndRoles.Converters" mc:Ignorable="d" d:DesignHeight="1080" d:DesignWidth="1920" d:DataContext="{d:DesignInstance Type=vm:MainViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.MainViewVM}"> <UserControl.Resources> <providers:PlacesProvider x:Key="PlacesProvider" /> + <converters:BooleanToVisibilityConverter x:Key="BoolToVisibilityConverter"></converters:BooleanToVisibilityConverter> + <converters:BooleanToVisibilityInverseConverter x:Key="BooleanToVisibilityInverseConverter"></converters:BooleanToVisibilityInverseConverter> + <localconverters:RoleEnumToVisibleConverter x:Key="RoleEnumToVisibleConverter"/> </UserControl.Resources> <Grid> @@ -48,7 +52,7 @@ <StackPanel> <TextBlock FontSize="16" FontWeight="SemiBold">LOGIN</TextBlock> <Border Width="300" BorderThickness="1" BorderBrush="Gray" Margin="0 5 0 0" Padding="15 5" Height="150" Background="{StaticResource TransparentBackgroundBrush500}"> - <local:UserView FontSize="10" DataContext="{Binding ManagedUser}" /> + <local:UserView VerticalAlignment="Top" Margin="0 15 0 0" FontSize="10" DataContext="{Binding ManagedUser}" /> </Border> </StackPanel> <StackPanel Margin="10 0 0 0"> @@ -74,12 +78,18 @@ </Grid> </Grid> <Grid DockPanel.Dock="Bottom"> - <Button Margin="0 10 0 0" MinWidth="200" Height="60" Command="{Binding SaveManagedUserCommand}" HorizontalAlignment="Right"> + <Button Margin="0 10 0 0" MinWidth="200" Height="60" Command="{Binding SaveManagedUserCommand}" HorizontalAlignment="Right" Visibility="{Binding Path=ManagedUser.Deleted, Converter={StaticResource BooleanToVisibilityInverseConverter}}"> <StackPanel Orientation="Horizontal"> <TextBlock FontSize="18" VerticalAlignment="Center">SAVE</TextBlock> <materialDesign:PackIcon Margin="5 0 0 0" Kind="ContentSave" Width="30" Height="30" /> </StackPanel> </Button> + <Button Margin="0 10 0 0" MinWidth="200" Height="60" Background="{StaticResource OrangeBrush300}" BorderBrush="{StaticResource OrangeBrush300}" Command="{Binding RestoreAndSaveManagedUserCommand}" HorizontalAlignment="Right" Visibility="{Binding Path=ManagedUser.Deleted, Converter={StaticResource BoolToVisibilityConverter}}"> + <StackPanel Orientation="Horizontal"> + <TextBlock FontSize="18" VerticalAlignment="Center" Text="RESTORE & SAVE"/> + <materialDesign:PackIcon Margin="5 0 0 0" Kind="ContentSave" Width="30" Height="30" /> + </StackPanel> + </Button> </Grid> <Grid> <DockPanel Margin="0 20 0 0"> @@ -95,7 +105,7 @@ </ListBox.ItemsPanel> <ListBox.ItemTemplate> <DataTemplate DataType="{x:Type entities:Role}"> - <Grid> + <Grid Visibility="{Binding RoleEnum, Converter={StaticResource RoleEnumToVisibleConverter}}"> <Grid.ToolTip> <StackPanel Background="Transparent"> <TextBlock Text="{Binding Description}" FontSize="10" Margin="0 0 0 10"></TextBlock> @@ -167,7 +177,7 @@ <ListBox ItemsSource="{Binding Roles}" ItemContainerStyle="{StaticResource basicListBoxItem}" HorizontalContentAlignment="Stretch" Background="Transparent"> <ListBox.ItemTemplate> <DataTemplate> - <Grid Background="Transparent" IsHitTestVisible="True" Style="{StaticResource draggableGrid}" dragAndDrop:DragAndDropService.DraggableBorderBrush="{StaticResource AccentColorBrush}" dragAndDrop:DragAndDropService.Draggable="True" dragAndDrop:DragAndDropService.DraggingSurface="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DraggingSurface}"> + <Grid Background="Transparent" IsHitTestVisible="True" Style="{StaticResource draggableGrid}" dragAndDrop:DragAndDropService.DraggableBorderBrush="{StaticResource AccentColorBrush}" dragAndDrop:DragAndDropService.Draggable="True" dragAndDrop:DragAndDropService.DraggingSurface="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DraggingSurface}" Visibility="{Binding RoleEnum, Converter={StaticResource RoleEnumToVisibleConverter}}"> <Grid.ToolTip> <StackPanel Background="Transparent"> <TextBlock Text="{Binding Description}" FontSize="10" Margin="0 0 0 10"></TextBlock> diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Views/UserView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Views/UserView.xaml index 0858d7e08..37f649a7a 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Views/UserView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Views/UserView.xaml @@ -16,8 +16,6 @@ <controls:TableGrid> <TextBlock Text="EMAIL"></TextBlock> <TextBox Text="{Binding Email}"></TextBox> - <TextBlock Text="PASSWORD"></TextBlock> - <PasswordBox MaxLength="30" pass:PasswordHelper.Attach="True" pass:PasswordHelper.Password="{Binding PasswordGateWay,Mode=TwoWay}"></PasswordBox> </controls:TableGrid> </Grid> </UserControl> diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/packages.config b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/packages.config index fe4f26e87..8696cb880 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/packages.config +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/packages.config @@ -7,4 +7,5 @@ <package id="MaterialDesignColors" version="1.1.2" targetFramework="net46" /> <package id="MaterialDesignThemes" version="2.3.1.953" targetFramework="net46" /> <package id="Newtonsoft.Json" version="9.0.1" targetFramework="net461" /> + <package id="SimpleValidator" version="0.6.1.0" targetFramework="net461" /> </packages>
\ No newline at end of file |
