Add bulk editing of roles

This commit is contained in:
Brant Martin
2019-04-22 15:44:34 -04:00
parent 56f7578d13
commit 92406a051a
2 changed files with 24 additions and 0 deletions

View File

@@ -20,6 +20,7 @@
<RowDefinition />
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<DataGrid x:Name="ItemGrid" AutoGenerateColumns="false" CanUserAddRows="true" Grid.Row="0">
<DataGrid.Columns>
@@ -36,6 +37,16 @@
<Button Grid.Column="0" Content="Cancel" Margin="5" Click="Cancel_OnClick" />
<Button Grid.Column="1" Content="OK" Margin="5" Click="Ok_OnClick" />
</Grid>
<Grid Grid.Row="3">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<ComboBox Name="BulkSelect" ItemsSource="{Binding Source={StaticResource GetEnumValues}}" SelectedValue ="{Binding
RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:RoleEditor}},
Path = BulkPromote, Mode=TwoWay}" Margin="5"/>
<Button Grid.Column="1" Content="Bulk edit" Margin ="5" Click="BulkEdit"/>
</Grid>
</Grid>
</Window>

View File

@@ -35,6 +35,7 @@ namespace Torch.Server.Views
private Type _itemType;
private Action _commitChanges;
public MyPromoteLevel BulkPromote { get; set; } = MyPromoteLevel.Scripter;
public void Edit(IDictionary dict)
{
@@ -106,5 +107,17 @@ namespace Torch.Server.Views
{
Items.Add((IDictionaryItem)Activator.CreateInstance(_itemType));
}
private void BulkEdit(object sender, RoutedEventArgs e)
{
List<ulong> l = Items.Where(i => i.Value.Equals(BulkPromote)).Select(i => (ulong)i.Key).ToList();
var w = new CollectionEditor();
w.Edit((ICollection<ulong>)l, "Bulk edit");
var r = Items.Where(j => j.Value.Equals(BulkPromote) || l.Contains((ulong)j.Key)).ToList();
foreach (var k in r)
Items.Remove(k);
foreach (var m in l)
Items.Add(new DictionaryItem<ulong, MyPromoteLevel>(m, BulkPromote));
}
}
}