Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/BootstrapBlazor.Server/BootstrapBlazor.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<PackageReference Include="BootstrapBlazor.OctIcon" Version="9.0.4" />
<PackageReference Include="BootstrapBlazor.OfficeViewer" Version="9.0.0" />
<PackageReference Include="BootstrapBlazor.OnScreenKeyboard" Version="9.0.1" />
<PackageReference Include="BootstrapBlazor.OpcDa" Version="9.0.0" />
<PackageReference Include="BootstrapBlazor.OpcDa" Version="9.0.1" />
<PackageReference Include="BootstrapBlazor.PdfReader" Version="9.0.1" />
<PackageReference Include="BootstrapBlazor.PdfViewer" Version="9.0.6" />
<PackageReference Include="BootstrapBlazor.Player" Version="9.0.1" />
Expand Down
16 changes: 13 additions & 3 deletions src/BootstrapBlazor.Server/Components/Samples/OpcDa.razor
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<PackageTips Name="BootstrapBlazor.OpcDa"/>

<DemoBlock Title="@Localizer["OpcDaNormalTitle"]" Introduction="@Localizer["OpcDaNormalIntro"]" Name="Normal">
<DemoBlock Title="@Localizer["OpcDaNormalTitle"]" Introduction="@Localizer["OpcDaNormalIntro"]" ShowCode="false" Name="Normal">
<p class="code-label">1. 点击 <b>连接</b> 按钮与 <code>OpcDa</code> 服务器建立通讯连接</p>
<p>
<BootstrapInputGroup>
Expand Down Expand Up @@ -42,7 +42,7 @@

<p class="code-label">3. 订阅功能</p>
<p>通过订阅可以监控一组 <b>位号</b> 数据改变情况,当数据改变时通过 <code>DataChanged</code> 回调方法通知订阅者</p>
<div class="row g-3">
<p class="row g-3">
<div class="col-12 col-sm-6">
<BootstrapInputGroup>
<BootstrapInputGroupLabel DisplayText="订阅名称"></BootstrapInputGroupLabel>
Expand Down Expand Up @@ -73,5 +73,15 @@
<Button OnClick="OnCreateSubscription" Text="订阅" IsDisabled="@(!OpcDaServer.IsConnected || _subscribed)"></Button>
<Button OnClick="OnCancelSubscription" Text="取消" IsDisabled="!_subscribed"></Button>
</div>
</div>
</p>
Comment on lines 73 to +76
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Using

as a container for form controls may not be semantically correct.

Consider replacing the

tag with a

or another suitable container to ensure valid HTML and proper rendering.


<p class="code-label">4. 浏览</p>
<p>通过调用 <code>OpcDaServer</code> <code>Browse</code> 方法可以构建一个节点树状结构</p>
<p>
<Button OnClick="OnBrowse" Text="浏览" IsDisabled="!OpcDaServer.IsConnected"></Button>
</p>
<p>
<TreeView Items="_roots" AutoCheckChildren="true" AutoCheckParent="true" ShowIcon="true"
OnExpandNodeAsync="OnExpandNodeAsync"></TreeView>
</p>
</DemoBlock>
30 changes: 29 additions & 1 deletion src/BootstrapBlazor.Server/Components/Samples/OpcDa.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,33 @@ private void UpdateValues(List<OpcReadItem> items)

InvokeAsync(StateHasChanged);
}
}

private List<TreeViewItem<OpcBrowseElement>> _roots = [];

private void OnBrowse()
{
var elements = OpcDaServer.Browse("", new OpcBrowseFilters(), out _);
_roots = elements.Select(element => new TreeViewItem<OpcBrowseElement>(element)
{
Text = element.Name,
HasChildren = element.HasChildren,
Icon = "fa-solid fa-fw fa-cubes"
}).ToList();
}

private Task<IEnumerable<TreeViewItem<OpcBrowseElement>>> OnExpandNodeAsync(TreeViewItem<OpcBrowseElement> element)
{
var children = OpcDaServer.Browse(element.Value.ItemName, new OpcBrowseFilters(), out _);
var items = children.Select(i => new TreeViewItem<OpcBrowseElement>(i)
{
Text = i.Name,
HasChildren = i.HasChildren,
Icon = i.HasChildren ? "fa-solid fa-fw fa-cube" : "fa-solid fa-fw fa-wrench"
});
if (!items.Any())
{
element.HasChildren = false;
Comment on lines +108 to +110
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question (bug_risk): Directly mutating element.HasChildren may cause UI inconsistencies.

This mutation may not trigger a UI update if the TreeView relies on its own state. Consider letting the TreeView infer child presence from the returned items instead.

}
return Task.FromResult(items);
}
}
Loading