This commit is contained in:
despiegk 2025-05-24 10:42:24 +04:00
parent c9b14730ad
commit 0b62ac9ecd

View File

@ -1,12 +1,14 @@
{{ extends "../layouts/base" }} {{extends "../layouts/base"}}
{{ block title() }}OpenRPC UI - HeroApp UI{{ end }} {{block title()}}
OpenRPC UI
{{end}}
{{ block css() }} {{block css()}}
<link rel="stylesheet" href="/static/css/rpcui.css"> <link rel="stylesheet" href="/static/css/rpcui.css">
{{ end }} {{end}}
{{ block body() }} {{block body()}}
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom"> <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
<h1 class="h2">OpenRPC UI</h1> <h1 class="h2">OpenRPC UI</h1>
</div> </div>
@ -23,9 +25,9 @@
<label for="spec" class="form-label">Specification</label> <label for="spec" class="form-label">Specification</label>
<select class="form-select" id="spec" name="spec" onchange="this.form.submit()"> <select class="form-select" id="spec" name="spec" onchange="this.form.submit()">
<option value="">Select a specification</option> <option value="">Select a specification</option>
{{ if .SpecList }} {{ if SpecList }}
{{ range .SpecList }} {{ range spec := SpecList }}
<option value="{{ . }}" {{ if eq . $.SelectedSpec }}selected{{ end }}>{{ . }}</option> <option value="{{ spec }}" >
{{ end }} {{ end }}
{{ else }} {{ else }}
<option value="" disabled>No specifications available</option> <option value="" disabled>No specifications available</option>
@ -34,7 +36,7 @@
</div> </div>
<div class="col-md-4"> <div class="col-md-4">
<label for="socketPath" class="form-label">Socket Path</label> <label for="socketPath" class="form-label">Socket Path</label>
<input type="text" class="form-control" id="socketPath" name="socketPath" value="{{ .SocketPath }}" placeholder="e.g., /tmp/rpc.sock"> <input type="text" class="form-control" id="socketPath" name="socketPath" value="{{ SocketPath }}" placeholder="e.g., /tmp/rpc.sock">
</div> </div>
<div class="col-md-4 d-flex align-items-end"> <div class="col-md-4 d-flex align-items-end">
<button type="submit" class="btn btn-primary">Apply</button> <button type="submit" class="btn btn-primary">Apply</button>
@ -49,26 +51,24 @@
<div class="col-md-12"> <div class="col-md-12">
<div class="alert alert-info"> <div class="alert alert-info">
<p>This is the OpenRPC UI page. It allows you to interact with OpenRPC specifications.</p> <p>This is the OpenRPC UI page. It allows you to interact with OpenRPC specifications.</p>
<p>Currently available specs: {{ if .SpecList }}{{ len(.SpecList) }}{{ else }}0{{ end }}</p> <p>Currently available specs: {{ if SpecList }}{{ len(SpecList) }}{{ else }}0{{ end }}</p>
</div> </div>
</div> </div>
</div> </div>
{{ if .SelectedSpec }} {{ if SelectedSpec }}
<div class="row"> <div class="row">
<!-- Method Tree --> <!-- Method Tree -->
<div class="col-md-3"> <div class="col-md-3">
<div class="card"> <div class="card">
<div class="card-header"> <div class="card-header"><h5>Methods</h5></div>
<h5>Methods</h5>
</div>
<div class="card-body p-0"> <div class="card-body p-0">
<div class="method-tree list-group list-group-flush"> <div class="method-tree list-group list-group-flush">
{{ if .Methods }} {{ if Methods }}
{{ range .Methods }} {{ range m := Methods }}
<a href="/rpcui?spec={{ $.SelectedSpec }}&method={{ . }}&socketPath={{ $.SocketPath }}" <a href="/rpcui?spec={{ SelectedSpec }}&method={{ m }}&socketPath={{ SocketPath }}"
class="list-group-item list-group-item-action method-item {{ if eq . $.SelectedMethod }}active{{ end }}"> class="list-group-item list-group-item-action method-item {{ if eq(m, SelectedMethod) }}active{{ end }}">
{{ . }} {{ m }}
</a> </a>
{{ end }} {{ end }}
{{ else }} {{ else }}
@ -81,46 +81,29 @@
<!-- Method Details --> <!-- Method Details -->
<div class="col-md-9"> <div class="col-md-9">
{{ if .Method }} {{ if Method }}
<div class="card mb-4"> <div class="card mb-4">
<div class="card-header"> <div class="card-header">
<h5>{{ .Method.Name }}</h5> <h5>{{ Method.Name }}</h5>
{{ if .Method.Description }} {{ if Method.Description }}<p class="text-muted mb-0">{{ Method.Description }}</p>{{ end }}
<p class="text-muted mb-0">{{ .Method.Description }}</p>
{{ end }}
</div> </div>
<div class="card-body"> <div class="card-body">
<!-- Parameters --> <!-- Parameters -->
<h6>Parameters</h6> <h6>Parameters</h6>
<table class="table table-sm schema-table"> <table class="table table-sm schema-table">
<thead> <thead><tr><th>Name</th><th>Type</th><th>Required</th><th>Description</th></tr></thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Required</th>
<th>Description</th>
</tr>
</thead>
<tbody> <tbody>
{{ if .Method.Params }} {{ if Method.Params }}
{{ range .Method.Params }} {{ range p := Method.Params }}
<tr> <tr>
<td>{{ .Name }}</td> <td>{{ p.Name }}</td>
<td><code>{{ .Schema.Type }}</code></td> <td><code>{{ p.Schema.Type }}</code></td>
<td> <td>{{ if p.Required }}<span class="schema-required">Yes</span>{{ else }}<span class="schema-optional">No</span>{{ end }}</td>
{{ if .Required }} <td>{{ p.Description }}</td>
<span class="schema-required">Yes</span>
{{ else }}
<span class="schema-optional">No</span>
{{ end }}
</td>
<td>{{ .Description }}</td>
</tr> </tr>
{{ end }} {{ end }}
{{ else }} {{ else }}
<tr> <tr><td colspan="4">No parameters</td></tr>
<td colspan="4">No parameters</td>
</tr>
{{ end }} {{ end }}
</tbody> </tbody>
</table> </table>
@ -128,18 +111,12 @@
<!-- Result --> <!-- Result -->
<h6 class="mt-4">Result</h6> <h6 class="mt-4">Result</h6>
<table class="table table-sm schema-table"> <table class="table table-sm schema-table">
<thead> <thead><tr><th>Name</th><th>Type</th><th>Description</th></tr></thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody> <tbody>
<tr> <tr>
<td>{{ .Method.Result.Name }}</td> <td>{{ Method.Result.Name }}</td>
<td><code>{{ .Method.Result.Schema.Type }}</code></td> <td><code>{{ Method.Result.Schema.Type }}</code></td>
<td>{{ .Method.Result.Description }}</td> <td>{{ Method.Result.Description }}</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
@ -147,10 +124,10 @@
<!-- Try It --> <!-- Try It -->
<h6 class="mt-4">Try It</h6> <h6 class="mt-4">Try It</h6>
<form id="rpcForm" class="mb-3"> <form id="rpcForm" class="mb-3">
<input type="hidden" name="selectedMethod" value="{{ .SelectedMethod }}"> <input type="hidden" name="selectedMethod" value="{{ SelectedMethod }}">
<div class="mb-3"> <div class="mb-3">
<label for="paramsEditor" class="form-label">Parameters:</label> <label for="paramsEditor" class="form-label">Parameters:</label>
<textarea class="form-control code-editor" id="paramsEditor" rows="10">{{ .ExampleParams }}</textarea> <textarea class="form-control code-editor" id="paramsEditor" rows="10">{{ ExampleParams }}</textarea>
</div> </div>
<button type="submit" class="btn btn-primary">Execute</button> <button type="submit" class="btn btn-primary">Execute</button>
</form> </form>
@ -159,27 +136,22 @@
<h6>Result:</h6> <h6>Result:</h6>
<pre id="resultOutput" class="bg-light p-2 rounded"></pre> <pre id="resultOutput" class="bg-light p-2 rounded"></pre>
</div> </div>
<div id="errorContainer" class="result-container d-none"> <div id="errorContainer" class="result-container d-none">
<h6>Error:</h6> <h6>Error:</h6>
<pre id="errorOutput" class="bg-light p-2 rounded text-danger"></pre> <pre id="errorOutput" class="bg-light p-2 rounded text-danger"></pre>
</div> </div>
</div> </div>
</div> </div>
{{ else if .SelectedMethod }} {{ else if SelectedMethod }}
<div class="alert alert-warning"> <div class="alert alert-warning">Method not found: {{ SelectedMethod }}</div>
Method not found: {{ .SelectedMethod }}
</div>
{{ else }} {{ else }}
<div class="alert alert-info"> <div class="alert alert-info">Select a method from the list to view details.</div>
Select a method from the list to view details.
</div>
{{ end }} {{ end }}
</div> </div>
</div> </div>
{{ end }} {{ end }}
{{ end }} {{end}}
{{ block scripts() }} {{block scripts()}}
<script src="/static/js/rpcui.js"></script> <script src="/static/js/rpcui.js"></script>
{{ end }} {{end}}