aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Views/OrganizationManagementView.xaml
blob: 1572923a63a1ba64702c238016ef5935f632a914 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<UserControl x:Class="Tango.MachineStudio.UsersAndRoles.Views.OrganizationManagementView"
             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:global="clr-namespace:Tango.MachineStudio.UsersAndRoles"
             xmlns:vm="clr-namespace:Tango.MachineStudio.UsersAndRoles.ViewModels"
             xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
             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"
              xmlns:providers="clr-namespace:Tango.MachineStudio.UsersAndRoles.Providers"
             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"
             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">

    <UserControl.Resources>
        <converters:DateTimeUTCToShortDateTimeConverter x:Key="DateTimeUTCToShortDateTimeConverter" />
        <providers:PlacesProvider x:Key="PlacesProvider" />
    </UserControl.Resources>

    <Grid>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="400"/>
                <ColumnDefinition Width="1*"/>
            </Grid.ColumnDefinitions>

            <Border Background="{StaticResource TransparentBackgroundBrush420}" BorderBrush="{StaticResource GrayBrush}" BorderThickness="0 0 1 0">
                <Grid Margin="10 20 10 10">
                    <StackPanel HorizontalAlignment="Center">

                        <StackPanel Orientation="Horizontal" Margin="-30 0 0 30">
                            <Image Source="../Images/organization.png" Width="58" />
                            <TextBlock Margin="10 0 0 0" FontSize="40" VerticalAlignment="Center" Text="{Binding ManagedOrganization.Name}"></TextBlock>
                        </StackPanel>

                        <TextBlock FontSize="14" FontWeight="SemiBold">ADDRESS</TextBlock>

                        <Border BorderBrush="Gray" BorderThickness="1" Width="300" HorizontalAlignment="Left" Padding="5" Margin="0 10 0 0" Background="{StaticResource TransparentBackgroundBrush420}" Height="300">
                            <DockPanel>
                                <DockPanel DockPanel.Dock="Top">
                                    <materialDesign:PackIcon Kind="Magnify" DockPanel.Dock="Left" Width="24" Height="24" />
                                    <autoComplete:AutoCompleteTextBox x:Name="address_auto" Margin="5 0 0 0" Delay="500" DisplayMember="DisplayName" SelectedItem="{Binding SelectedOrganizationPlace,Mode=OneWayToSource}" Provider="{StaticResource PlacesProvider}" materialDesign:HintAssist.Hint="Find address" />
                                </DockPanel>
                                <local:AddressView DataContext="{Binding ManagedOrganization.Address}" />
                            </DockPanel>
                        </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="{StaticResource TransparentBackgroundBrush420}" 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>

            <Grid Grid.Column="1">
                <TextBlock HorizontalAlignment="Left" VerticalAlignment="Top" FontSize="30" FontStyle="Italic" Margin="150 40">
                    <Run Text="{Binding ManagedOrganization.Name}"></Run> <Run Text="Users"></Run>
                </TextBlock>
                <DockPanel Margin="100" MaxWidth="1200">
                    <Grid DockPanel.Dock="Top">
                        <StackPanel>
                            <Image Source="../Images/users.png" Width="300" Height="250" />
                            <Button Margin="0 -210 0 0" MinWidth="160" Height="50" Command="{Binding BackToOrganizationsCommand}" HorizontalAlignment="Left">
                                <StackPanel Orientation="Horizontal">
                                    <materialDesign:PackIcon Kind="KeyboardBackspace" Width="20" Height="20" />
                                    <TextBlock Margin="5 0 0 0" FontSize="16">BACK</TextBlock>
                                </StackPanel>
                            </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" 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}">
                                <StackPanel Orientation="Horizontal">
                                    <materialDesign:PackIcon Kind="Delete" Width="20" Height="20" />
                                    <TextBlock Margin="5 0 0 0" FontSize="16">DELETE</TextBlock>
                                </StackPanel>
                            </Button>
                            <Button Margin="0 0 10 0" MinWidth="160" Height="50" Background="{StaticResource GreenBrush300}" BorderBrush="{StaticResource GreenBrush300}" Command="{Binding AddUserCommand}">
                                <StackPanel Orientation="Horizontal">
                                    <materialDesign:PackIcon Kind="Plus" Width="20" Height="20" />
                                    <TextBlock Margin="5 0 0 0" FontSize="16">NEW USER</TextBlock>
                                </StackPanel>
                            </Button>
                        </StackPanel>
                        <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
                            <Button Margin="50 0 0 0" MinWidth="200" Height="60" Command="{Binding ManageUserCommand}">
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock FontSize="18" VerticalAlignment="Center">MANAGE</TextBlock>
                                    <materialDesign:PackIcon Margin="5 0 0 0" Kind="ChevronRight" Width="30" Height="30" />
                                </StackPanel>
                            </Button>
                        </StackPanel>
                    </Grid>
                    <Grid>
                        <DataGrid Margin="0 0 0 10" ItemsSource="{Binding ManagedOrganization.Users}" SelectedItem="{Binding SelectedUser}"  d:DataContext="{d:DesignInstance Type=entities:User, IsDesignTimeCreatable=False}" BorderBrush="{StaticResource borderBrush}" BorderThickness="1" Background="{StaticResource TransparentBackgroundBrush}" AlternatingRowBackground="{StaticResource Transparent200}" AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" IsReadOnly="True">
                            <DataGrid.CellStyle>
                                <Style TargetType="DataGridCell" BasedOn="{StaticResource {x:Type DataGridCell}}">
                                    <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>
                                <DataGridTextColumn Header="LAST UPDATED" Binding="{Binding LastUpdated,Converter={StaticResource DateTimeUTCToShortDateTimeConverter}}" Width="1*" />
                                <DataGridTextColumn Header="NAME" Binding="{Binding Contact.FullName}" Width="1*" />
                                <DataGridTextColumn Header="LOGIN EMAIL" Binding="{Binding Email}" Width="1*" />
                                <DataGridTextColumn Header="CONTACT EMAIL" Binding="{Binding Contact.Email}" Width="1*" />
                                <DataGridTextColumn Header="ADDRESS" Binding="{Binding Address.AddressString}" Width="1*" />
                                <DataGridTemplateColumn Header="ROLES" Width="1*">
                                    <DataGridTemplateColumn.CellTemplate>
                                        <DataTemplate>
                                            <TextBlock Text="{Binding Roles[0].Name}" TextTrimming="CharacterEllipsis">
                                                <TextBlock.ToolTip>
                                                    <ItemsControl ItemsSource="{Binding Roles}">
                                                        <ItemsControl.ItemTemplate>
                                                            <DataTemplate>
                                                                <StackPanel Orientation="Horizontal" Margin="2">
                                                                    <materialDesign:PackIcon Kind="AccountKey" Width="16" Height="16" />
                                                                    <TextBlock Margin="5 0 0 0" Text="{Binding Name}"></TextBlock>
                                                                </StackPanel>
                                                            </DataTemplate>
                                                        </ItemsControl.ItemTemplate>
                                                    </ItemsControl>
                                                </TextBlock.ToolTip>
                                            </TextBlock>
                                        </DataTemplate>
                                    </DataGridTemplateColumn.CellTemplate>
                                </DataGridTemplateColumn>
                            </DataGrid.Columns>
                        </DataGrid>
                    </Grid>
                </DockPanel>
            </Grid>
        </Grid>
    </Grid>
</UserControl>
pan>AddChild(AXmlObject item) { // Childs can be only added to newly parsed items Assert(this.Parent == null, "I have to be new"); Assert(item.IsCached, "Added item must be in cache"); // Do not set parent pointer this.Children.InsertItemAt(this.Children.Count, item); } /// <summary> To be used exlucively by the parser </summary> internal void AddChildren(IEnumerable<AXmlObject> items) { // Childs can be only added to newly parsed items Assert(this.Parent == null, "I have to be new"); // Do not set parent pointer this.Children.InsertItemsAt(this.Children.Count, items.ToList()); } /// <summary> /// To be used exclusively by the children update algorithm. /// Insert child and keep links consistent. /// </summary> void InsertChild(int index, AXmlObject item) { AXmlParser.Log("Inserting {0} at index {1}", item, index); Assert(this.Document != null, "Can not insert to dangling object"); Assert(item.Parent != this, "Can not own item twice"); SetParentPointersInTree(item); this.Children.InsertItemAt(index, item); this.Document.OnObjectInserted(index, item); } /// <summary> Recursively fix all parent pointer in a tree </summary> /// <remarks> /// Cache constraint: /// If cached item has parent set, then the whole subtree must be consistent and document set /// </remarks> void SetParentPointersInTree(AXmlObject item) { // All items come from the parser cache if (item.Parent == null) { // Dangling object - either a new parser object or removed tree (still cached) item.Parent = this; item.Document = this.Document; AXmlContainer container = item as AXmlContainer; if (container != null) { foreach(AXmlObject child in container.Children) { container.SetParentPointersInTree(child); } } } else if (item.Parent == this) { // If node is attached and then deattached, it will have null parent pointer // but valid subtree - so its children will alredy have correct parent pointer // like in this case // item.DebugCheckConsistency(false); // Rest of the tree is consistent - do not recurse } else { // From cache & parent set => consitent subtree // item.DebugCheckConsistency(false); // The parent (or any futher parents) can not be part of parsed document // becuase otherwise this item would be included twice => safe to change parents // Maintain cache constraint by setting parents to null foreach(AXmlObject ancest in item.GetAncestors().ToList()) { ancest.Parent = null; } item.Parent = this; // Rest of the tree is consistent - do not recurse } } /// <summary> /// To be used exclusively by the children update algorithm. /// Remove child, set parent to null and notify the document /// </summary> void RemoveChild(int index) { AXmlObject removed = this.Children[index]; AXmlParser.Log("Removing {0} at index {1}", removed, index); // Stop tracking if the object can not be used again if (!removed.IsCached) this.Document.Parser.TrackedSegments.RemoveParsedObject(removed); // Null parent pointer Assert(removed.Parent == this, "Inconsistent child"); removed.Parent = null; this.Children.RemoveItemAt(index); this.Document.OnObjectRemoved(index, removed); } /// <summary> Verify that the subtree is consistent. Only in debug build. </summary> /// <remarks> Parent pointers might be null or pointing somewhere else in parse tree </remarks> internal override void DebugCheckConsistency(bool checkParentPointers) { base.DebugCheckConsistency(checkParentPointers); AXmlObject prevChild = null; int myStartOffset = this.StartOffset; int myEndOffset = this.EndOffset; foreach(AXmlObject child in this.Children) { Assert(child.Length != 0, "Empty child"); if (checkParentPointers) { Assert(child.Parent != null, "Null parent reference"); Assert(child.Parent == this, "Inccorect parent reference"); } if (this.Document != null) { Assert(child.Document != null, "Child has null document"); Assert(child.Document == this.Document, "Child is in different document"); } if (this.IsCached) Assert(child.IsCached, "Child not in cache"); Assert(myStartOffset <= child.StartOffset && child.EndOffset <= myEndOffset, "Child not within parent text range"); if (prevChild != null) Assert(prevChild.EndOffset <= child.StartOffset, "Overlaping childs"); child.DebugCheckConsistency(checkParentPointers); prevChild = child; } } /// <remarks> /// Note the the method is not called recuively. /// Only the helper methods are recursive. /// </remarks> internal void UpdateTreeFrom(AXmlContainer srcContainer) { this.StartOffset = srcContainer.StartOffset; // Force the update this.UpdateDataFrom(srcContainer); RemoveChildrenNotIn(srcContainer.Children); InsertAndUpdateChildrenFrom(srcContainer.Children); } void RemoveChildrenNotIn(IList<AXmlObject> srcList) { Dictionary<int, AXmlObject> srcChildren = srcList.ToDictionary(i => i.StartOffset); for(int i = 0; i < this.Children.Count;) { AXmlObject child = this.Children[i]; AXmlObject srcChild; if (srcChildren.TryGetValue(child.StartOffset, out srcChild) && child.CanUpdateDataFrom(srcChild)) { // Keep only one item with given offset (we might have several due to deletion) srcChildren.Remove(child.StartOffset); // If contaner that needs updating AXmlContainer childAsContainer = child as AXmlContainer; if (childAsContainer != null && child.LastUpdatedFrom != srcChild) childAsContainer.RemoveChildrenNotIn(((AXmlContainer)srcChild).Children); i++; } else { RemoveChild(i); } } } void InsertAndUpdateChildrenFrom(IList<AXmlObject> srcList) { for(int i = 0; i < srcList.Count; i++) { // End of our list? if (i == this.Children.Count) { InsertChild(i, srcList[i]); continue; } AXmlObject child = this.Children[i]; AXmlObject srcChild = srcList[i]; if (child.CanUpdateDataFrom(srcChild)) { // includes offset test // Does it need updating? if (child.LastUpdatedFrom != srcChild) { child.UpdateDataFrom(srcChild); AXmlContainer childAsContainer = child as AXmlContainer; if (childAsContainer != null) childAsContainer.InsertAndUpdateChildrenFrom(((AXmlContainer)srcChild).Children); } } else { InsertChild(i, srcChild); } } Assert(this.Children.Count == srcList.Count, "List lengths differ after update"); } } }