forked from alexreich/RulesEngineEditor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputEditor.razor
More file actions
103 lines (92 loc) · 3.45 KB
/
InputEditor.razor
File metadata and controls
103 lines (92 loc) · 3.45 KB
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
@*
// Copyright (c) Alex Reich.
// Licensed under the CC BY 4.0 License.
*@
@using RulesEngineEditor.Models
@inject RulesEngineEditor.Services.WorkflowService WorkflowService
@using RulesEngineEditor.Resources
@if (Input != null)
{
<sp_grid_kvp>
<div>@RulesEngineEditor.Resources.SharedResources.InputName</div>
</sp_grid_kvp>
<EditForm EditContext="@EditContext">
<DataAnnotationsValidator />
<ValidationSummary />
<sp_grid_workflow>
<div>
<InputText title="@RulesEngineEditor.Resources.SharedResources.InputName" class="form-control" @bind-Value="@Input.InputRuleName" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" />
</div>
<div>
<button title="@RulesEngineEditor.Resources.SharedResources.Delete" @onclick="@(e => DeleteInput())" class="btn btn-secondary">
<span class="oi oi-trash"></span>
</button>
</div>
</sp_grid_workflow>
<h5>@RulesEngineEditor.Resources.SharedResources.Parameters</h5>
<button class="reeditor_button" title="@RulesEngineEditor.Resources.SharedResources.AddInputParameter" @onclick="AddParameter">@RulesEngineEditor.Resources.SharedResources.Add</button>
<button class="reeditor_button @IsPressed(sort, "button_depressed")" @onclick="(() => sort = !sort)">@RulesEngineEditor.Resources.SharedResources.Arrange</button>
<sp_grid_kvp>
<div>@RulesEngineEditor.Resources.SharedResources.InputParamName</div>
<div>@RulesEngineEditor.Resources.SharedResources.Value</div>
</sp_grid_kvp>
</EditForm>
@if (sort)
{
<Dropzone Items="Input.Parameters">
<div class="rules_arrange">
<InputParamEditor InputParam="@context" InputParamDelete="DeleteInputParam" />
</div>
</Dropzone>
}
else
{
@foreach (var context in Input.Parameters)
{
<InputParamEditor InputParam="@context" InputParamDelete="DeleteInputParam" />
}
}
}
@code {
public bool sort;
public string IsPressed(bool state, string suffix)
{
return state ? "reeditor_" + suffix : "";
}
[Parameter]
public InputRuleParameter Input { get; set; }
[Parameter]
public EventCallback<InputRuleParameter> InputDeleted { get; set; }
private EditContext EditContext;
protected override void OnInitialized()
{
EditContext = new EditContext(Input);
EditContext.OnFieldChanged += EditContext_OnFieldChanged;
base.OnInitialized();
}
public override async Task SetParametersAsync(ParameterView parameters)
{
await base.SetParametersAsync(parameters);
}
// Note: The OnFieldChanged event is raised for each field in the model
private void EditContext_OnFieldChanged(object sender, FieldChangedEventArgs e)
{
WorkflowService.InputUpdate();
}
private void DeleteInputParam(InputParameter inputParameter)
{
Input.Parameters.Remove(inputParameter);
WorkflowService.WorkflowUpdate();
}
private void AddParameter()
{
InputParameter parameter = new InputParameter();
parameter.Name = $"param{Input.Parameters.Count + 1}";
Input.Parameters.Insert(0, parameter);
}
private void DeleteInput()
{
WorkflowService.Inputs.Remove(Input);
WorkflowService.InputUpdate();
}
}