btcpayserver/BTCPayServer/Views/UIInvoice/PosData.cshtml

61 lines
2 KiB
Text

@model (Dictionary<string, object> Items, int Level)
@functions{
public bool IsValidURL(string source)
{
Uri uriResult;
return Uri.TryCreate(source, UriKind.Absolute, out uriResult) &&
(uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps);
}
}
<table class="table my-0">
@foreach (var (key, value) in Model.Items)
{
<tr>
@if (value is string str)
{
if (!string.IsNullOrEmpty(key))
{
<th class="w-150px">@Safe.Raw(key)</th>
}
<td>
@if (IsValidURL(str))
{
<a href="@Safe.Raw(str)" target="_blank" rel="noreferrer noopener">@Safe.Raw(str)</a>
}
else
{
@Safe.Raw(value?.ToString())
}
</td>
}
else if (value is Dictionary<string, object>subItems)
{
@* This is the array case *@
if (subItems.Count == 1 && subItems.First().Value is string str2)
{
<th class="w-150px">@Safe.Raw(key)</th>
<td>
@if (IsValidURL(str2))
{
<a href="@Safe.Raw(str2)" target="_blank" rel="noreferrer noopener">@Safe.Raw(str2)</a>
}
else
{
@Safe.Raw(subItems.First().Value?.ToString())
}
</td>
}
else
{
<td colspan="2" >
@Safe.Raw($"<h{Model.Level + 3} class=\"mt-4 mb-3\">{key}</h{Model.Level + 3}>")
<partial name="PosData" model="(subItems, Model.Level + 1)"/>
</td>
}
}
</tr>
}
</table>