Skip to content

Commit

Permalink
Add "monaco", the vscode web editor
Browse files Browse the repository at this point in the history
  • Loading branch information
GTC6244 committed May 9, 2024
1 parent aba2bf2 commit 2c76662
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 15 deletions.
1 change: 1 addition & 0 deletions NodeView/NodeView.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

<ItemGroup>
<PackageReference Include="Blazored.LocalStorage" Version="4.4.0" />
<PackageReference Include="BlazorMonaco" Version="3.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.10" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.10" PrivateAssets="all" />
<PackageReference Include="Nethereum.Web3" Version="4.17.1" />
Expand Down
87 changes: 73 additions & 14 deletions NodeView/Pages/Explorer/ActionPlayground.razor
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

<PageTitle>LNE - Playground</PageTitle>



<div class="card border-primary">
<div class="card-header ">
<div class="row no-gutters">
Expand Down Expand Up @@ -52,35 +50,75 @@
</div>


<div class="input-group mb-3">
@* <div class="input-group mb-3">
<span class="input-group-text" id="basic-addon1">Action:</span>
<textarea class="form-control" style="height:300px;" id="action_code" value="@action_code" onchange="@ActionCodeChanged" height=30 rows="3"></textarea>
</div> *@

<div class="card">
<div class="card-header ">
<div class="row no-gutters">
<div class="col">
Lit Action Code
</div>
</div>
</div>
<div class="card-body">
<div class="row">
<div class="col">
<StandaloneCodeEditor @ref="_editor" Id="my-editor-instance-id" ConstructionOptions="EditorConstructionOptions" />
</div>
</div>
</div>
</div>
<br/>

<div class="card">
<div class="card-header ">
<div class="row no-gutters">
<div class="col">
Node Responses
</div>
</div>
</div>
<div class="card-body">
<div class="row">
<div class="col">
<StandaloneCodeEditor @ref="_responses" Id="my-responses-instance-id" ConstructionOptions="ResponseConstructionOptions" />
</div>
</div>
</div>
</div>
<br/>

<div class="input-group mb-3">
@* <div class="input-group mb-3">
<span class="input-group-text" id="basic-addon1">Responses:</span>
<textarea class="form-control" style="height:150px;" id="action_response" value="@action_response" height=30 rows="3"></textarea>
</div>
</div> *@

<button type="button" class="btn btn-primary" @onclick="() => ExecuteLitAction()">Execute Action </button>

</div>

</div>
</div>
</div>
<div class="form-group">
<button type="button" class="btn btn-primary" @onclick="() => ExecuteLitAction()">Execute Action </button>
</div>
</div>





<style>
#my-editor-instance-id { /* for all editor instances */
height: 400px;
}
#my-responses-instance-id { /* for all response instances */
height: 150px;
}
</style>



@code {
private StandaloneCodeEditor _editor = null!;
private StandaloneCodeEditor _responses = null!;
private List<Validator> ? current_validators = null;
class LocalConfig {
public string wallet_address { get; set;} = "";
Expand Down Expand Up @@ -126,6 +164,22 @@
public string action_code { get; set; } = "";
public string action_response { get; set; } = "";

private StandaloneEditorConstructionOptions EditorConstructionOptions(StandaloneCodeEditor editor)
{
return new StandaloneEditorConstructionOptions
{
AutomaticLayout = true,
Language = "javascript",
};
}
private StandaloneEditorConstructionOptions ResponseConstructionOptions(StandaloneCodeEditor editor)
{
return new StandaloneEditorConstructionOptions
{
AutomaticLayout = true,
Language = "javascript",
};
}
async void ActionCodeChanged(ChangeEventArgs e)
{
if ( e.Value == null ) return;
Expand Down Expand Up @@ -204,6 +258,8 @@

public async Task<bool> ExecuteLitAction() {

action_code = await _editor.GetValue();

if (current_validators == null) {
Console.WriteLine("No validators found");
return false;
Expand Down Expand Up @@ -274,18 +330,21 @@

foreach (ActionResult result in results) {

if (result.response.Length > 1) {
@* if (result.response.Length > 1) {
combined_output.AppendLine("Node #" + result.node_port + " response: " + result.response);
}
if (result.signedData != null) {
if (result.signedData.ToString().Length > 10) {
combined_output.AppendLine("Node #" + result.node_port + " signedData: " + result.signedData);
}
}
@* Console.WriteLine("Result: " + result.response); *@
Console.WriteLine("Result: " + result.response); *@
combined_output.AppendLine("// Node #" + result.node_port + " response: " );
combined_output.AppendLine( System.Text.Json.JsonSerializer.Serialize( result));
}

action_response = combined_output.ToString();
await _responses.SetValue(action_response);

return true;
}
Expand Down
5 changes: 4 additions & 1 deletion NodeView/_Imports.razor
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@
@using NodeView
@using NodeView.Shared
@using Radzen
@using Radzen.Blazor
@using Radzen.Blazor
@using BlazorMonaco
@using BlazorMonaco.Editor
@using BlazorMonaco.Languages
3 changes: 3 additions & 0 deletions NodeView/wwwroot/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
<a href="" class="reload">Reload</a>
<a class="dismiss">🗙</a>
</div>
<script src="_content/BlazorMonaco/jsInterop.js"></script>
<script src="_content/BlazorMonaco/lib/monaco-editor/min/vs/loader.js"></script>
<script src="_content/BlazorMonaco/lib/monaco-editor/min/vs/editor/editor.main.js"></script>
<script src="_framework/blazor.webassembly.js"></script>
<script src="_content/Z.Blazor.Diagrams/script.min.js"></script>
<script src="_content/Radzen.Blazor/Radzen.Blazor.js"></script>
Expand Down

0 comments on commit 2c76662

Please sign in to comment.