From cf3c535fb0ef3140cc7a3a3c74cadd9b1d519bcf Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Wed, 7 Mar 2018 18:30:49 +0200 Subject: Working on users & roles module. --- .../Images/roles.png | Bin 0 -> 3875 bytes .../Images/user.png | Bin 0 -> 20100 bytes .../Tango.MachineStudio.UsersAndRoles.csproj | 10 ++ .../ViewModels/MainViewVM.cs | 61 ++++++++- .../Views/ContactView.xaml | 2 +- .../Views/OrganizationManagementView.xaml | 12 +- .../Views/UserManagementView.xaml | 143 ++++++++++++++++++++- .../Views/UserManagementView.xaml.cs | 23 ++++ 8 files changed, 242 insertions(+), 9 deletions(-) create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Images/roles.png create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Images/user.png (limited to 'Software/Visual_Studio/MachineStudio') 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 new file mode 100644 index 000000000..e7955be04 Binary files /dev/null and b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Images/roles.png differ 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 new file mode 100644 index 000000000..c8b7a3b40 Binary files /dev/null and b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Images/user.png differ 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 @@ {a34ee0f0-649d-41c8-8489-b6f1cc6924ee} Tango.Core + + {b112d89a-a106-41ae-a0c1-4abc84c477f5} + Tango.DragAndDrop + {bc932dbd-7cdb-488c-99e4-f02cf441f55e} Tango.Logging @@ -194,5 +198,11 @@ + + + + + + \ 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 _permissions; - public ObservableCollection Permissions + private ObservableCollection _managedUserRoles; + public ObservableCollection 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 @@ FIRST NAME LAST NAME - + EMAIL PHONE NUMBER 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 @@ ADDRESS - + CONTACT - + + + + 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}"> + - + + + + + + + + + + + + + + + + + + + ADDRESS + + + + + + CONTACT + + + + + + + + + + + + + + ROLES + + DRAG & DROP ROLES + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + AVAILABLE ROLES + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 /// 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); + } } } } -- cgit v1.3.1