diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-03-07 18:30:49 +0200 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-03-07 18:30:49 +0200 |
| commit | cf3c535fb0ef3140cc7a3a3c74cadd9b1d519bcf (patch) | |
| tree | 942ff2f666552dc488095881baa2f3b4c18c1bb1 /Software/Visual_Studio/MachineStudio | |
| parent | e317a7943e47c34e731729eacc46f8ce48905927 (diff) | |
| download | Tango-cf3c535fb0ef3140cc7a3a3c74cadd9b1d519bcf.tar.gz Tango-cf3c535fb0ef3140cc7a3a3c74cadd9b1d519bcf.zip | |
Working on users & roles module.
Diffstat (limited to 'Software/Visual_Studio/MachineStudio')
8 files changed, 242 insertions, 9 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Images/roles.png b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Images/roles.png Binary files differnew file mode 100644 index 000000000..e7955be04 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Images/roles.png diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Images/user.png b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Images/user.png Binary files differnew file mode 100644 index 000000000..c8b7a3b40 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Images/user.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 cfba775b8..fb134fdfd 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 @@ -142,6 +142,10 @@ <Project>{a34ee0f0-649d-41c8-8489-b6f1cc6924ee}</Project> <Name>Tango.Core</Name> </ProjectReference> + <ProjectReference Include="..\..\..\Tango.DragAndDrop\Tango.DragAndDrop.csproj"> + <Project>{b112d89a-a106-41ae-a0c1-4abc84c477f5}</Project> + <Name>Tango.DragAndDrop</Name> + </ProjectReference> <ProjectReference Include="..\..\..\Tango.Logging\Tango.Logging.csproj"> <Project>{bc932dbd-7cdb-488c-99e4-f02cf441f55e}</Project> <Name>Tango.Logging</Name> @@ -194,5 +198,11 @@ <ItemGroup> <Resource Include="Images\users.png" /> </ItemGroup> + <ItemGroup> + <Resource Include="Images\user.png" /> + </ItemGroup> + <ItemGroup> + <Resource Include="Images\roles.png" /> + </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> </Project>
\ No newline at end of file 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 9c10dc126..fdb0f8983 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 @@ -50,11 +50,11 @@ namespace Tango.MachineStudio.UsersAndRoles.ViewModels set { _roles = value; RaisePropertyChangedAuto(); } } - private ObservableCollection<Permission> _permissions; - public ObservableCollection<Permission> Permissions + private ObservableCollection<Role> _managedUserRoles; + public ObservableCollection<Role> ManagedUserRoles { - get { return _permissions; } - set { _permissions = value; RaisePropertyChangedAuto(); } + get { return _managedUserRoles; } + set { _managedUserRoles = value; RaisePropertyChangedAuto(); } } private User _selectedUser; @@ -77,6 +77,10 @@ namespace Tango.MachineStudio.UsersAndRoles.ViewModels public RelayCommand ManageUserCommand { get; set; } + public RelayCommand SaveOrganizationCommand { get; set; } + + public RelayCommand AddOrganizationCommand { get; set; } + public MainViewVM(UsersAndRolesNavigationManager navigation, INotificationProvider notification) { _navigation = navigation; @@ -87,6 +91,40 @@ namespace Tango.MachineStudio.UsersAndRoles.ViewModels ManageOrganizationCommand = new RelayCommand(ManageOrganization, () => SelectedOrganization != null); BackToOrganizationsCommand = new RelayCommand(BackToOrganizations); ManageUserCommand = new RelayCommand(ManageUser, () => SelectedUser != null); + SaveOrganizationCommand = new RelayCommand(SaveOrganization); + AddOrganizationCommand = new RelayCommand(AddOrganization); + } + + private async void AddOrganization() + { + String name = _notification.ShowTextInput("Enter organization name", "Name"); + + if (!String.IsNullOrWhiteSpace(name)) + { + using (_notification.PushTaskItem("Adding new organization...")) + { + Organization org = new Organization(); + org.Name = name; + org.Address = new Address(); + org.Contact = new Contact(); + _organizationsContext.Organizations.Add(org); + await org.SaveAsync(_organizationsContext); + Organizations = _organizationsContext.Organizations.ToObservableCollection(); + SelectedOrganization = org; + ManageOrganization(); + } + } + } + + private async void SaveOrganization() + { + using (_notification.PushTaskItem("Saving organization address and contact...")) + { + ManagedOrganization.Contact.FullName = ManagedOrganization.Contact.FirstName + " " + ManagedOrganization.Contact.LastName; + await ManagedOrganization.SaveAsync(_manageContext); + LoadOrganizations(); + SelectedOrganization = Organizations.SingleOrDefault(x => x.Guid == ManagedOrganization.Guid); + } } private void ManageUser() @@ -96,7 +134,9 @@ namespace Tango.MachineStudio.UsersAndRoles.ViewModels Task.Factory.StartNew(() => { _userContext = ObservablesContext.CreateDefault(); + Roles = _manageContext.Roles.ToObservableCollection(); ManagedUser = _manageContext.Users.SingleOrDefault(x => x.Guid == SelectedUser.Guid); + ManagedUserRoles = ManagedUser.Roles.ToObservableCollection(); InvokeUI(() => _navigation.NavigateTo(UsersAndRolesNavigationView.UserManagementView)); }); @@ -135,6 +175,19 @@ namespace Tango.MachineStudio.UsersAndRoles.ViewModels Organizations = _organizationsContext.Organizations.ToObservableCollection(); } + public void OnDropRole(Role role) + { + ManagedUser.UsersRoles.Add(new UsersRole() + { + Role = role, + RoleGuid = role.Guid, + User = ManagedUser, + UserGuid = ManagedUser.Guid, + }); + + ManagedUserRoles.Add(role); + } + protected override void RaisePropertyChangedAuto([CallerMemberName] string caller = null) { base.RaisePropertyChangedAuto(caller); diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Views/ContactView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Views/ContactView.xaml index dfff19f12..cdfa28c50 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Views/ContactView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Views/ContactView.xaml @@ -17,7 +17,7 @@ <TextBlock>FIRST NAME</TextBlock> <TextBox Text="{Binding FirstName}"></TextBox> <TextBlock>LAST NAME</TextBlock> - <TextBox Text="{Binding FirstName}"></TextBox> + <TextBox Text="{Binding LastName}"></TextBox> <TextBlock>EMAIL</TextBlock> <TextBox Text="{Binding Email}"></TextBox> <TextBlock>PHONE NUMBER</TextBlock> 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 b91a22750..7769f65ed 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 @@ -37,15 +37,23 @@ <TextBlock FontSize="14" FontWeight="SemiBold">ADDRESS</TextBlock> - <Border BorderBrush="Gray" BorderThickness="1" Width="300" HorizontalAlignment="Left" Padding="5" Margin="0 10 0 0" Background="#A9FFFFFF"> + <Border BorderBrush="Gray" BorderThickness="1" Width="300" HorizontalAlignment="Left" Padding="5" Margin="0 10 0 0" Background="#A9FFFFFF" Height="300"> <local:AddressView DataContext="{Binding ManagedOrganization.Address}" /> </Border> <TextBlock FontSize="14" FontWeight="SemiBold" Margin="0 40 0 0">CONTACT</TextBlock> - <Border BorderBrush="Gray" BorderThickness="1" Width="300" HorizontalAlignment="Left" Padding="5" Margin="0 10 0 0" Background="#A9FFFFFF"> + <Border BorderBrush="Gray" BorderThickness="1" Width="300" HorizontalAlignment="Left" Padding="5" Margin="0 10 0 0" Background="#A9FFFFFF" Height="250"> <local:ContactView DataContext="{Binding ManagedOrganization.Contact}" /> </Border> + + <Button Margin="0 40 0 0" MinWidth="160" Height="50" Command="{Binding SaveOrganizationCommand}" Background="Gray" BorderBrush="Gray"> + <StackPanel Orientation="Horizontal"> + <materialDesign:PackIcon Kind="ContentSave" Width="20" Height="20" /> + <TextBlock Margin="5 0 0 0" FontSize="16">SAVE</TextBlock> + </StackPanel> + </Button> + </StackPanel> </Grid> </Border> 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 0a3fec2ff..eaeb180ab 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 @@ -6,6 +6,7 @@ xmlns:global="clr-namespace:Tango.MachineStudio.UsersAndRoles" xmlns:vm="clr-namespace:Tango.MachineStudio.UsersAndRoles.ViewModels" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" + xmlns:dragAndDrop="clr-namespace:Tango.DragAndDrop;assembly=Tango.DragAndDrop" xmlns:autoComplete="clr-namespace:Tango.AutoComplete.Editors;assembly=Tango.AutoComplete" xmlns:controls="clr-namespace:Tango.SharedUI.Controls;assembly=Tango.SharedUI" xmlns:mahApps="http://metro.mahapps.com/winfx/xaml/controls" @@ -13,8 +14,146 @@ xmlns:local="clr-namespace:Tango.MachineStudio.UsersAndRoles.Views" xmlns:converters="clr-namespace:Tango.SharedUI.Converters;assembly=Tango.SharedUI" mc:Ignorable="d" - d:DesignHeight="1080" d:DesignWidth="1920" d:DataContext="{d:DesignInstance Type=vm:MainViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.MainViewVM}" Background="Transparent"> + d:DesignHeight="1080" d:DesignWidth="1920" d:DataContext="{d:DesignInstance Type=vm:MainViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.MainViewVM}"> + <Grid> - <TextBlock Text="{Binding ManagedUser.Contact.FullName}"></TextBlock> + <Grid> + <Grid.ColumnDefinitions> + <ColumnDefinition Width="1*"/> + <ColumnDefinition Width="300"/> + </Grid.ColumnDefinitions> + + <Grid Margin="10"> + <DockPanel Margin="100" MaxWidth="1200"> + <Grid DockPanel.Dock="Top"> + <Grid> + <StackPanel> + <StackPanel Orientation="Horizontal"> + <Image Source="../Images/user.png" Width="100" RenderOptions.BitmapScalingMode="Fant"></Image> + <TextBlock Text="{Binding ManagedUser.Contact.FullName,FallbackValue='Roy Ben Shabat'}" VerticalAlignment="Center" FontSize="30" Margin="10 0 0 0"></TextBlock> + </StackPanel> + + <StackPanel Orientation="Horizontal" Margin="0 10 0 0"> + <StackPanel> + <TextBlock FontSize="16" FontWeight="SemiBold">ADDRESS</TextBlock> + <Border Width="300" BorderThickness="1" BorderBrush="Gray" Margin="0 5 0 0" Padding="5" Height="300"> + <local:AddressView FontSize="10" /> + </Border> + </StackPanel> + <StackPanel Margin="10 0 0 0"> + <TextBlock FontSize="16" FontWeight="SemiBold">CONTACT</TextBlock> + <Border Width="300" BorderThickness="1" BorderBrush="Gray" Margin="0 5 0 0" Padding="5" Height="300"> + <local:ContactView FontSize="10" /> + </Border> + </StackPanel> + </StackPanel> + </StackPanel> + </Grid> + </Grid> + <Grid DockPanel.Dock="Bottom"> + <Button Margin="0 10 0 0" MinWidth="200" Height="60" Command="{Binding ManageUserCommand}" HorizontalAlignment="Right"> + <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> + </Grid> + <Grid> + <DockPanel Margin="0 20 0 0"> + <TextBlock DockPanel.Dock="Top" FontSize="16" FontWeight="SemiBold">ROLES</TextBlock> + <Grid Margin="0 5 0 0" Style="{StaticResource droppableGrid}" dragAndDrop:DragAndDropService.Drop="OnDropRole"> + <TextBlock HorizontalAlignment="Center" VerticalAlignment="Top" Foreground="Silver" FontSize="20">DRAG & DROP ROLES</TextBlock> + <Border BorderBrush="Gray" BorderThickness="1" Padding="10"> + <ListBox ItemsSource="{Binding ManagedUserRoles}" ItemContainerStyle="{StaticResource basicListBoxItem}" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Disabled"> + <ListBox.ItemsPanel> + <ItemsPanelTemplate> + <WrapPanel Orientation="Horizontal" /> + </ItemsPanelTemplate> + </ListBox.ItemsPanel> + <ListBox.ItemTemplate> + <DataTemplate DataType="{x:Type entities:Role}"> + <Grid Style="{StaticResource draggableGrid}"> + <Border Margin="5" CornerRadius="5" Width="100" Height="100" BorderThickness="1" Padding="2" IsHitTestVisible="False"> + <Border.Style> + <Style TargetType="Border"> + <Setter Property="BorderBrush" Value="Silver"></Setter> + <Style.Triggers> + <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=ListBoxItem},Path=IsSelected}" Value="True"> + <Setter Property="BorderBrush" Value="{StaticResource AccentColorBrush}"></Setter> + </DataTrigger> + </Style.Triggers> + </Style> + </Border.Style> + <Border.Background> + <LinearGradientBrush> + <GradientStop Color="White"/> + <GradientStop Color="#FFD6D6D6" Offset="1"/> + </LinearGradientBrush> + </Border.Background> + <Grid> + <TextBlock Text="{Binding Name}"></TextBlock> + </Grid> + </Border> + </Grid> + </DataTemplate> + </ListBox.ItemTemplate> + </ListBox> + </Border> + </Grid> + </DockPanel> + </Grid> + </DockPanel> + </Grid> + + <Grid Grid.Column="1" Background="#A9FFFFFF"> + <DockPanel Margin="10"> + <StackPanel Orientation="Horizontal" DockPanel.Dock="Top"> + <Image Source="../Images/roles.png" Width="70" RenderOptions.BitmapScalingMode="Fant"></Image> + <TextBlock FontSize="16" FontWeight="SemiBold" VerticalAlignment="Center" Margin="10 0 0 0">AVAILABLE ROLES</TextBlock> + </StackPanel> + + <Grid> + <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}"> + <DockPanel> + <Border DockPanel.Dock="Left" Width="100" Height="100" IsHitTestVisible="False" BorderBrush="Silver" BorderThickness="1" CornerRadius="5" Margin="5" Padding="2"> + <Border.Background> + <LinearGradientBrush> + <GradientStop Color="White"/> + <GradientStop Color="#FFD6D6D6" Offset="1"/> + </LinearGradientBrush> + </Border.Background> + <Grid> + <StackPanel VerticalAlignment="Center" HorizontalAlignment="Center"> + <Image Source="../Images/roles.png" Width="32" RenderOptions.BitmapScalingMode="Fant"></Image> + <TextBlock Text="{Binding Name}" HorizontalAlignment="Center" TextAlignment="Center" FontSize="13" FontWeight="SemiBold" Margin="5"></TextBlock> + </StackPanel> + </Grid> + </Border> + <Grid> + <ItemsControl ItemsSource="{Binding RolesPermissions}"> + <ItemsControl.ItemTemplate> + <DataTemplate> + <StackPanel Orientation="Horizontal"> + <materialDesign:PackIcon Kind="Security" Width="16" /> + <TextBlock Text="{Binding Permission.Name}"></TextBlock> + </StackPanel> + </DataTemplate> + </ItemsControl.ItemTemplate> + </ItemsControl> + </Grid> + </DockPanel> + </Grid> + </DataTemplate> + </ListBox.ItemTemplate> + </ListBox> + </Grid> + </DockPanel> + </Grid> + </Grid> + + <dragAndDrop:DraggingSurface x:Name="dragSurface" /> </Grid> </UserControl> diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Views/UserManagementView.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Views/UserManagementView.xaml.cs index 88319cbb3..b26f0ea03 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Views/UserManagementView.xaml.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Views/UserManagementView.xaml.cs @@ -12,6 +12,9 @@ using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; +using Tango.BL.Entities; +using Tango.DragAndDrop; +using Tango.MachineStudio.UsersAndRoles.ViewModels; namespace Tango.MachineStudio.UsersAndRoles.Views { @@ -20,9 +23,29 @@ namespace Tango.MachineStudio.UsersAndRoles.Views /// </summary> public partial class UserManagementView : UserControl { + private MainViewVM _vm; + + public DraggingSurface DraggingSurface + { + get { return (DraggingSurface)GetValue(DraggingSurfaceProperty); } + set { SetValue(DraggingSurfaceProperty, value); } + } + public static readonly DependencyProperty DraggingSurfaceProperty = + DependencyProperty.Register("DraggingSurface", typeof(DraggingSurface), typeof(UserManagementView), new PropertyMetadata(null)); + public UserManagementView() { InitializeComponent(); + DraggingSurface = dragSurface; + Loaded += (_, __) => _vm = DataContext as MainViewVM; + } + + private void OnDropRole(object sender, DropEventArgs e) + { + if (e.Draggable.DataContext is Role) + { + _vm.OnDropRole(e.Draggable.DataContext as Role); + } } } } |
