Skip to content

Commit 3962777

Browse files
committed
[UX] Template windowed editor
1 parent 3edd459 commit 3962777

File tree

5 files changed

+46
-6
lines changed

5 files changed

+46
-6
lines changed

WDE.DatabaseEditors.Avalonia/Views/Template/TemplateDbTableEditorToolBar.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
IsEnabled="{Binding TaskInProgress, Converter={x:Static converters:InverseBoolConverter.Instance}}"
1313
x:Class="WDE.DatabaseEditors.Avalonia.Views.Template.TemplateDbTableEditorToolBar">
1414
<controls:ToolbarPanel>
15-
<components:ButtonImage Command="{CompiledBinding AddNewCommand, Mode=OneTime}" Text="Add new" Image="Icons/icon_add.png" />
15+
<components:ButtonImage IsVisible="{CompiledBinding AllowMultipleKeys}" Command="{CompiledBinding AddNewCommand, Mode=OneTime}" Text="Add new" Image="Icons/icon_add.png" />
1616
<ItemsPresenter Items="{CompiledBinding Commands}">
1717
<ItemsPresenter.ItemsPanel>
1818
<ItemsPanelTemplate>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System.Collections.Generic;
2+
using WDE.Common.Services;
3+
using WDE.DatabaseEditors.Models;
4+
using WDE.Module.Attributes;
5+
using WDE.SqlQueryGenerator;
6+
7+
namespace WDE.DatabaseEditors.QueryGenerators;
8+
9+
[NonUniqueProvider]
10+
public interface ICustomQueryGenerator
11+
{
12+
string TableName { get; }
13+
IQuery Generate(IReadOnlyList<DatabaseKey> keys, IReadOnlyList<DatabaseKey>? deletedKeys, IDatabaseTableData data);
14+
}

WDE.DatabaseEditors/QueryGenerators/QueryGenerator.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,22 @@ public class QueryGenerator : IQueryGenerator
2626
private readonly IQueryGenerator<ConditionDeleteModel> conditionDeleteGenerator;
2727
private readonly IConditionQueryGenerator conditionQueryGenerator;
2828

29+
private Dictionary<string, ICustomQueryGenerator> customQueryGenerators = new();
30+
2931
public QueryGenerator(ICreatureStatCalculatorService calculatorService,
3032
IParameterFactory parameterFactory,
3133
IQueryGenerator<ConditionDeleteModel> conditionDeleteGenerator,
32-
IConditionQueryGenerator conditionQueryGenerator)
34+
IConditionQueryGenerator conditionQueryGenerator,
35+
IEnumerable<ICustomQueryGenerator> customQueryGenerators)
3336
{
3437
this.calculatorService = calculatorService;
3538
this.parameterFactory = parameterFactory;
3639
this.conditionDeleteGenerator = conditionDeleteGenerator;
3740
this.conditionQueryGenerator = conditionQueryGenerator;
41+
foreach (var gen in customQueryGenerators)
42+
{
43+
this.customQueryGenerators[gen.TableName] = gen;
44+
}
3845
}
3946

4047
public IQuery GenerateQuery(IReadOnlyList<DatabaseKey> keys, IReadOnlyList<DatabaseKey>? deletedKeys, IDatabaseTableData tableData)
@@ -65,6 +72,11 @@ public IQuery GenerateSingleRecordQuery(IReadOnlyList<DatabaseKey> keys, IReadOn
6572
query.Add(GenerateUpdateQuery(tableData.TableDefinition, entity));
6673
}
6774

75+
if (customQueryGenerators.TryGetValue(tableData.TableDefinition.TableName, out var customQueryGenerator))
76+
{
77+
query.Add(customQueryGenerator.Generate(keys, deletedKeys, tableData));
78+
}
79+
6880
return query.Close();
6981
}
7082

WDE.DatabaseEditors/Services/TableEditorPickerService.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using WDE.DatabaseEditors.ViewModels.MultiRow;
1818
using WDE.DatabaseEditors.ViewModels.OneToOneForeignKey;
1919
using WDE.DatabaseEditors.ViewModels.SingleRow;
20+
using WDE.DatabaseEditors.ViewModels.Template;
2021
using WDE.Module.Attributes;
2122
using WDE.MVVM;
2223
using WDE.MVVM.Observable;
@@ -156,9 +157,6 @@ public async Task ShowTable(string table, string? condition, DatabaseKey? defaul
156157
if (definition == null)
157158
throw new UnsupportedTableException(table);
158159

159-
if (definition.RecordMode == RecordMode.Template)
160-
throw new Exception("TemplateMode not (yet?) supported");
161-
162160
ViewModelBase viewModelBase;
163161
bool openIsNoSaveMode = false;
164162
if (definition.RecordMode == RecordMode.SingleRow)
@@ -174,7 +172,7 @@ public async Task ShowTable(string table, string? condition, DatabaseKey? defaul
174172
singleRow.FilterViewModel.ApplyFilter.Execute(null);
175173
}
176174
}
177-
else
175+
else if (definition.RecordMode == RecordMode.MultiRecord)
178176
{
179177
Debug.Assert(definition.RecordMode == RecordMode.MultiRecord);
180178
Debug.Assert(condition == null);
@@ -185,6 +183,17 @@ public async Task ShowTable(string table, string? condition, DatabaseKey? defaul
185183
multiRow.AllowMultipleKeys = false;
186184
viewModelBase = multiRow;
187185
}
186+
else
187+
{
188+
Debug.Assert(definition.RecordMode == RecordMode.Template);
189+
Debug.Assert(condition == null);
190+
Debug.Assert(defaultPartialKey.HasValue);
191+
var solutionItem = new DatabaseTableSolutionItem(defaultPartialKey.Value, true, false, definition.Id, false);
192+
openIsNoSaveMode = await CheckIfItemIsOpened(solutionItem, definition);
193+
var template = containerProvider.Resolve<TemplateDbTableEditorViewModel>((typeof(DatabaseTableSolutionItem), solutionItem));
194+
template.AllowMultipleKeys = false;
195+
viewModelBase = template;
196+
}
188197

189198
var viewModel = containerProvider.Resolve<RowPickerViewModel>((typeof(ViewModelBase), viewModelBase), (typeof(bool), openIsNoSaveMode));
190199
viewModel.DisablePicking = true;

WDE.DatabaseEditors/ViewModels/Template/TemplateDbTableEditorViewModel.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ public partial class TemplateDbTableEditorViewModel : ViewModelBase
6060
public IObservable<Func<DatabaseRowViewModel, bool>> CurrentFilter { get; }
6161
public SourceList<DatabaseRowViewModel> Rows { get; } = new();
6262
private HashSet<(DatabaseKey key, string columnName)> forceUpdateCells = new HashSet<(DatabaseKey, string)>();
63+
64+
[Notify] private bool allowMultipleKeys = true;
6365

6466
public AsyncAutoCommand<DatabaseCellViewModel?> RemoveTemplateCommand { get; }
6567
public AsyncAutoCommand<DatabaseCellViewModel?> RevertCommand { get; }
@@ -143,6 +145,9 @@ protected override void UpdateSolutionItem()
143145

144146
private async Task AddNewEntity()
145147
{
148+
if (!allowMultipleKeys)
149+
return;
150+
146151
var parameter = parameterFactory.Factory(tableDefinition.Picker);
147152
var selected = await itemFromListProvider.GetItemFromList(parameter.Items, false);
148153
if (!selected.HasValue)

0 commit comments

Comments
 (0)