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

Gfs/blazor options configurator #562

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
</Found>
<NotFound>
<PageTitle>Not found</PageTitle>
<LayoutView Layout="@typeof(MainLayout)">
<p role="alert">Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using CommandLine;
using Microsoft.CST.OAT.Utils;

namespace Microsoft.DevSkim.BlazorOptionsConfigurator
{
using Microsoft.DevSkim.CLI.Options;
public static class AppState
{
public static SerializedAnalyzeCommandOptions commandOptions = CreateDefaultCommandOptions();

public static SerializedAnalyzeCommandOptions CreateDefaultCommandOptions()
{
var opts = new SerializedAnalyzeCommandOptions();
foreach (var property in typeof(SerializedAnalyzeCommandOptions).GetProperties())
{
var attrs = property.GetCustomAttributes(true).OfType<OptionAttribute>().FirstOrDefault();
if (attrs is not null && attrs.LongName != "source-code")
{
Helpers.SetValueByPropertyOrFieldName(opts, property.Name, attrs.Default);
}
}

return opts;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Tewr.Blazor.FileReader;

namespace Microsoft.DevSkim.BlazorOptionsConfigurator
{
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.DevSkim.BlazorOptionsConfigurator;

public class Program
{
public static async Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");
builder.Services.AddFileReaderService(options => options.UseWasmSharedBuffer = true);

builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });

await builder.Build().RunAsync();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
@inherits Microsoft.CST.OAT.Blazor.Components.Inputs.BaseInput;
@using Microsoft.CST.OAT.Utils;
@using Serilog;
@using System.Reflection
@using Microsoft.CST.OAT.Blazor.Components
<div class="row">
<div class="col underline">Language :</div>
<div class="col underline">Rule IDs :</div>
<div class="col"></div>
</div>
<div class="row">
<div class="col">
<Microsoft.CST.OAT.Blazor.Components.Inputs.StringInput id="@IdForKey" Object="@this" SubPath="KeyObject" onChangeAction="onChangeAction" />
</div>
<div class="col">
<Microsoft.CST.OAT.Blazor.Components.Inputs.ListStringInput id="@IdForKey" Object="@this" SubPath="ValueObject" onChangeAction="onChangeAction" />
</div>
<div class="col">
<button class="btn-block" @onclick="AddEntry">Add @buttonText</button>
</div>
</div>

@if (SubProperty?.Count > 0)
{
<div class="row">
<div class="col-2 underline">
<span>Key :</span>
</div>
<div class="col">
<select class="form-control" @bind="SelectedKey">
@for (int i = 0; i < Keys.Count; i++)
{
<option value="@i">@Keys[i]</option>
}
</select>
</div>
@if (!isDisabled)
{
<div class="col-4">
<button @onclick="RemoveEntry" disabled="@NoKeys">Remove @buttonText</button>
</div>
}

</div>
<div class="row">
<div class="col-2 underline">
<span>Value : </span>
</div>
<div class="col">
@if (Keys.Count > 0)
{
SelectedKey = Math.Min(Keys.Count - 1, SelectedKey);
if (Keys[SelectedKey] is string key)
{
SelectedValueObject = SubProperty[key];
<Microsoft.CST.OAT.Blazor.Components.Inputs.ListStringInput id="selectedValueObjectId" Object="@this" SubPath="SelectedValueObject" onChangeAction="onChangeAction" />
}
else
{
SelectedValueObject = null;
}
}
</div>
</div>
}

@code {
List<string> selectedValueObject;

public List<string> SelectedValueObject
{
get
{
return selectedValueObject;
}
set
{
selectedValueObject = value;
if (SubProperty is { } && Keys[SelectedKey] is string NotNullKey)
{
SubProperty[NotNullKey] = selectedValueObject;
}
}
}

string IdForKey => $"{id}.KeyInput";
string IdForValue => $"{id}.ValueInput";

public List<string> ValueObject { get; set; }

public string KeyObject { get; set; }

[Parameter]
public string buttonText { get; set; } = "Dictionary Key And Value";

bool NoKeys => Keys.Count == 0;

int SelectedKey
{
get;
set;
}

System.Collections.IList Keys { get; set; } = new List<object>();

void RemoveEntry()
{
if (SelectedKey < Keys.Count)
{
if (Keys[SelectedKey] is string obj)
{
SubProperty?.Remove(obj);
}
}
Setup();
onChangeAction.Invoke();
}

void AddEntry()
{
if (SubProperty is null)
{
SubProperty = new Dictionary<string, List<string>>();
}
if (SubProperty is not null)
{
SubProperty[KeyObject] = ValueObject;
}

Setup();
onChangeAction.Invoke();
}

void Setup()
{
Keys.Clear();

if (SubProperty?.Keys is {})
{
foreach(var key in SubProperty.Keys)
{
Keys.Add(key);
}
}

}

protected override void OnInitialized()
{
Setup();
base.OnInitialized();
}

public IDictionary<string,List<string>> SubProperty
{
get
{
if (Helpers.GetValueByPropertyOrFieldName(Object, SubPath) is IDictionary<string, List<string>> idict)
{
return idict;
}
return null;
}
set
{
Helpers.SetValueByPropertyOrFieldName(Object, SubPath, value);
onChangeAction.Invoke();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
@inherits Microsoft.CST.OAT.Blazor.Components.Inputs.BaseInput;
@using Microsoft.CST.OAT.Utils;
@using System.Collections.Generic;
@using Microsoft.ApplicationInspector.RulesEngine;

<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 (dataProxy.Count > 0)
{
<div class="row">
<div class="col">
<select class="form-control" @bind="SelectedIndex">
@for (int i = 0; i < dataProxy.Count; i++)
{
<option value="@i">@dataProxy[i]</option>
}
</select>
</div>
<div class="col-4">
<button @onclick="RemoveData">Remove @buttonText</button>
</div>
</div>
}

@code {
[Parameter]
public string buttonText { get; set; } = "Confidence";

int AddEnumIndex { get; set; }

int SelectedIndex { get; set; }

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

List<Confidence> dataProxy = new List<Confidence>();

[Parameter]
public Initializer? initializer { get; set; }

protected override void OnInitialized()
{
initializer.init = () => { dataProxy = SubProperty.ToList(); StateHasChanged(); onChangeAction.Invoke(); };
initializer.init.Invoke();
base.OnInitialized();
}

List<Confidence> values
{
get
{
var vals = new List<Confidence>();

foreach(var value in Enum.GetValues(typeof(Confidence)))
{
vals.Add((Confidence)value);
}
return vals;
}
}

void AddData(EventArgs eventArgs)
{
if (SubProperty == null)
{
dataProxy = new List<Confidence>();
}
dataProxy?.Add(values[AddEnumIndex]);
SubProperty = dataProxy;
}

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

public IEnumerable<Confidence>? SubProperty
{
get
{
if (Helpers.GetValueByPropertyOrFieldName(Object, SubPath) is IEnumerable<Confidence> confidences)
{
return confidences;
}
return null;
}
set
{
Helpers.SetValueByPropertyOrFieldName(Object, SubPath, value);
onChangeAction.Invoke();
}
}
}
Loading