Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Da/component updates #65

Merged
merged 27 commits into from
Jul 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<PackageReference Include="Nerdbank.GitVersioning">
<Version>3.3.37</Version>
<Version>3.4.228</Version>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion OAT.Benchmarks/OAT.Benchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Update="Nerdbank.GitVersioning" Version="3.4.194" />
<PackageReference Update="Nerdbank.GitVersioning" Version="3.4.228" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions OAT.Blazor.Components/Inputs/BoolInput.razor
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@using Microsoft.CST.OAT.Utils;

<div class="form-check">
<input type="checkbox" class="form-check-input" id="@id" @bind="SubProperty" data-input-type="bool-input"/>
<div class="form-check form-check-inline ml-1">
<input class="form-check-input" type="checkbox" id="@id" @bind="SubProperty" data-input-type="bool-input"/>
</div>

@code {
Expand Down
20 changes: 15 additions & 5 deletions OAT.Blazor.Components/Inputs/DictionaryStringListStringInput.razor
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<button class="btn-block" @onclick="AddEntry">Add @buttonText</button>
</div>
</div>
@if (SubProperty.Count > 0)
@if (SubProperty?.Count > 0)
{
<div class="row">
<div class="col">
Expand All @@ -29,7 +29,7 @@
}

@code {
[Parameter]
[Parameter]
public object? Object { get; set; }

[Parameter]
Expand All @@ -50,20 +50,30 @@
void RemoveEntry()
{
if (SelectedKey is not null){
SubProperty.Remove(SelectedKey);
SubProperty?.Remove(SelectedKey);
}
}

void AddEntry()
{
if (SubProperty is null)
{
SubProperty = new Dictionary<string, List<string>>();
}
SubProperty[CurrentInputKey] = CurrentInputValue;
CurrentInputKey = string.Empty;
CurrentInputValue = new List<string>();
}

public Dictionary<string, List<String>> SubProperty
public Dictionary<string, List<String>>? SubProperty
{
get
{
return (Dictionary<string, List<string>>)(Helpers.GetValueByPropertyOrFieldName(Object, SubPath) ?? new Dictionary<string, List<string>>());
if (Helpers.GetValueByPropertyOrFieldName(Object, SubPath) is Dictionary<string, List<string>> val)
{
return val;
}
return null;
}
set
{
Expand Down
20 changes: 15 additions & 5 deletions OAT.Blazor.Components/Inputs/DictionaryStringStringInput.razor
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<button class="btn-block" @onclick="AddEntry">Add @buttonText</button>
</div>
</div>
@if (SubProperty.Count > 0)
@if (SubProperty?.Count > 0)
{
<div class="row">
<div class="col">
Expand All @@ -27,7 +27,7 @@
}

@code {
[Parameter]
[Parameter]
public object? Object { get; set; }

[Parameter]
Expand All @@ -47,19 +47,29 @@

void RemoveEntry()
{
SubProperty.Remove(SelectedKey);
SubProperty?.Remove(SelectedKey);
}

void AddEntry()
{
if (SubProperty is null)
{
SubProperty = new Dictionary<string, string>();
}
SubProperty[CurrentInputKey] = CurrentInputValue;
CurrentInputKey = string.Empty;
CurrentInputValue = string.Empty;
}

public Dictionary<string, string> SubProperty
public Dictionary<string, string>? SubProperty
{
get
{
return (Dictionary<string, string>)(Helpers.GetValueByPropertyOrFieldName(Object, SubPath) ?? new Dictionary<string, string>());
if (Helpers.GetValueByPropertyOrFieldName(Object, SubPath) is Dictionary<string, string> val)
{
return val;
}
return null;
}
set
{
Expand Down
8 changes: 1 addition & 7 deletions OAT.Blazor.Components/Inputs/EnumInput.razor
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,12 @@
public string id { get; set; } = string.Empty;

[Parameter]
public Action? OnChange { get; set; }

Type? type;
public Type? type { get; set; }

List<Enum> values = new List<Enum>();

protected override void OnInitialized()
{
type = Helpers.GetValueByPropertyOrFieldName(Object, SubPath)?.GetType();
if (type is not null)
{
foreach (var value in Enum.GetValues(type))
Expand All @@ -50,9 +47,6 @@
set
{
Helpers.SetValueByPropertyOrFieldName(Object, SubPath, values[value]);
if (OnChange != null) {
OnChange();
}
}
}
}
46 changes: 26 additions & 20 deletions OAT.Blazor.Components/Inputs/FlagsInput.razor
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@using Microsoft.CST.OAT.Utils;
<br />

<div class="flags-input">
@{
var type = Helpers.GetValueByPropertyOrFieldName(Object, SubPath)?.GetType();
if (type != null)
{
var enums = Enum.GetValues(type);
Expand All @@ -14,21 +14,32 @@
{
if (val.HasFlag(curEnum))
{
<input type="checkbox" checked="checked" value="@curEnum" id="@curEnum" @onchange="eventArgs => { CheckboxClicked(curEnum, eventArgs.Value ?? false); }" /><label for="@curEnum">@curEnum</label>
<div class="form-check form-check-inline mr-2">
<input class="form-check-input" type="checkbox" checked="checked" id="@curEnum" value="@curEnum" @onchange="eventArgs => { CheckboxClicked(curEnum, eventArgs.Value ?? false); }" data-input-type="flags-input"/>
<label class="form-check-label" for="@curEnum">@curEnum</label>
</div>
}
else
{
<input type="checkbox" value="@curEnum" id="@curEnum" @onchange="eventArgs => { CheckboxClicked(curEnum, eventArgs.Value ?? false); }" /><label for="@curEnum">@curEnum</label>
}
if (i < enums.Length - 1)
{
<br />
<div class="form-check form-check-inline mr-2">
<input class="form-check-input" type="checkbox" id="@curEnum" value="@curEnum" @onchange="eventArgs => { CheckboxClicked(curEnum, eventArgs.Value ?? false); }" data-input-type="flags-input"/>
<label class="form-check-label" for="@curEnum">@curEnum</label>
</div>
}
}
else if (Helpers.GetValueByPropertyOrFieldName(Object, SubPath) is null)
{
<div class="form-check form-check-inline mr-2">
<input class="form-check-input" type="checkbox" id="@curEnum" value="@curEnum" @onchange="eventArgs => { CheckboxClicked(curEnum, eventArgs.Value ?? false); }" data-input-type="flags-input"/>
<label class="form-check-label" for="@curEnum">@curEnum</label>
</div>
}
}
}
}
}
</div>

@code {
[Parameter]
public object? Object { get; set; }
Expand All @@ -39,25 +50,20 @@
[Parameter]
public string id { get; set; } = string.Empty;

Type? type;

protected override void OnInitialized()
{
type = Helpers.GetValueByPropertyOrFieldName(Object, SubPath)?.GetType();
base.OnInitialized();
}
[Parameter]
public Type? type { get; set; }

void CheckboxClicked(Enum enumValue, object checkedValue)
{
if (type is not null)
{
if ((bool)checkedValue)
{
if (SubProperty?.GetType().IsDefined(typeof(FlagsAttribute), false) is true)
if (type?.IsDefined(typeof(FlagsAttribute), false) is true)
{
if (!SubProperty.HasFlag(enumValue))
if (!(SubProperty?.HasFlag(enumValue) ?? false))
{
object val = Convert.ChangeType(SubProperty, SubProperty.GetTypeCode());
object val = SubProperty is null ? 0 : Convert.ChangeType(SubProperty, SubProperty.GetTypeCode());
object val2 = Convert.ChangeType(enumValue, enumValue.GetTypeCode());
if (val is int)
{
Expand Down Expand Up @@ -96,9 +102,9 @@
}
else
{
if (SubProperty?.GetType().IsDefined(typeof(FlagsAttribute), false) is true)
if (type?.IsDefined(typeof(FlagsAttribute), false) is true)
{
if (SubProperty.HasFlag(enumValue))
if (SubProperty?.HasFlag(enumValue) ?? false)
{
object val = Convert.ChangeType(SubProperty, SubProperty.GetTypeCode());
object val2 = Convert.ChangeType(enumValue, enumValue.GetTypeCode());
Expand Down
98 changes: 98 additions & 0 deletions OAT.Blazor.Components/Inputs/ListEnumInput.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
@using Microsoft.CST.OAT.Utils;

<div class="row">
<div class="col">
<select class="form-control" id="@id" @bind="AddEnumIndex" data-input-type="enum-input">
@for (int i = 0; i < values.Count; i++)
{
<option value="@i">@values[i].ToString()</option>
}
</select>
</div>
<div class="col-4">
<button @onclick="AddData">Add @buttonText</button>
</div>
</div>
@if (SubProperty?.Count > 0)
{
<div class="row">
<div class="col">
<select class="form-control" @bind="SelectedIndex">
@for (int i = 0; i < SubProperty.Count; i++)
{
<option value="@i">@SubProperty[i]</option>
}
</select>
</div>
<div class="col-4">
<button @onclick="RemoveData">Remove @buttonText</button>
</div>
</div>
}

@code {
[Parameter]
public object? Object { get; set; }

[Parameter]
public string? SubPath { get; set; }

[Parameter]
public string buttonText { get; set; } = "Enum";

[Parameter]
public string id { get; set; } = string.Empty;

[Parameter]
public Type? enumType { get; set; }

int AddEnumIndex { get; set; }

int SelectedIndex { get; set; }

string CurrentInput { get; set; } = string.Empty;

List<Enum> values = new List<Enum>();

protected override void OnInitialized()
{
if (enumType is not null)
{
foreach (var value in Enum.GetValues(enumType))
{
values.Add((Enum)value);
}
}
base.OnInitialized();
}

void AddData(EventArgs eventArgs)
{
if (SubProperty == null)
{
Helpers.SetValueByPropertyOrFieldName(Object, SubPath, new List<string>());
}
SubProperty?.Add(values[AddEnumIndex]);
}

void RemoveData(EventArgs eventArgs)
{
SubProperty?.RemoveAt(SelectedIndex);
}

public System.Collections.IList? SubProperty
{
get
{
if (Helpers.GetValueByPropertyOrFieldName(Object, SubPath) is System.Collections.IList val && val.GetType().GetGenericArguments()[0].IsEnum)
{
return val;
}
return null;
}
set
{
Helpers.SetValueByPropertyOrFieldName(Object, SubPath, value);
}
}
}