153 lines
6.0 KiB
Plaintext
153 lines
6.0 KiB
Plaintext
@using ZB.MOM.WW.OtOpcUa.Admin.Services
|
|
@using ZB.MOM.WW.OtOpcUa.Configuration.Entities
|
|
@using ZB.MOM.WW.OtOpcUa.Configuration.Validation
|
|
@inject EquipmentService EquipmentSvc
|
|
|
|
<div class="d-flex justify-content-between mb-3">
|
|
<h4>Equipment (draft gen @GenerationId)</h4>
|
|
<button class="btn btn-primary btn-sm" @onclick="StartAdd">Add equipment</button>
|
|
</div>
|
|
|
|
@if (_equipment is null)
|
|
{
|
|
<p>Loading…</p>
|
|
}
|
|
else if (_equipment.Count == 0 && !_showForm)
|
|
{
|
|
<p class="text-muted">No equipment in this draft yet.</p>
|
|
}
|
|
else if (_equipment.Count > 0)
|
|
{
|
|
<table class="table table-sm table-hover">
|
|
<thead>
|
|
<tr>
|
|
<th>EquipmentId</th><th>Name</th><th>MachineCode</th><th>ZTag</th><th>SAPID</th>
|
|
<th>Manufacturer / Model</th><th>Serial</th><th></th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
@foreach (var e in _equipment)
|
|
{
|
|
<tr>
|
|
<td><code>@e.EquipmentId</code></td>
|
|
<td>@e.Name</td>
|
|
<td>@e.MachineCode</td>
|
|
<td>@e.ZTag</td>
|
|
<td>@e.SAPID</td>
|
|
<td>@e.Manufacturer / @e.Model</td>
|
|
<td>@e.SerialNumber</td>
|
|
<td><button class="btn btn-sm btn-outline-danger" @onclick="() => DeleteAsync(e.EquipmentRowId)">Remove</button></td>
|
|
</tr>
|
|
}
|
|
</tbody>
|
|
</table>
|
|
}
|
|
|
|
@if (_showForm)
|
|
{
|
|
<div class="card mt-3">
|
|
<div class="card-body">
|
|
<h5>New equipment</h5>
|
|
<EditForm Model="_draft" OnValidSubmit="SaveAsync" FormName="new-equipment">
|
|
<DataAnnotationsValidator/>
|
|
<div class="row g-3">
|
|
<div class="col-md-4">
|
|
<label class="form-label">Name (UNS segment)</label>
|
|
<InputText @bind-Value="_draft.Name" class="form-control"/>
|
|
<ValidationMessage For="() => _draft.Name"/>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<label class="form-label">MachineCode</label>
|
|
<InputText @bind-Value="_draft.MachineCode" class="form-control"/>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<label class="form-label">DriverInstanceId</label>
|
|
<InputText @bind-Value="_draft.DriverInstanceId" class="form-control"/>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<label class="form-label">UnsLineId</label>
|
|
<InputText @bind-Value="_draft.UnsLineId" class="form-control"/>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<label class="form-label">ZTag</label>
|
|
<InputText @bind-Value="_draft.ZTag" class="form-control"/>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<label class="form-label">SAPID</label>
|
|
<InputText @bind-Value="_draft.SAPID" class="form-control"/>
|
|
</div>
|
|
</div>
|
|
|
|
<h6 class="mt-4">OPC 40010 Identification</h6>
|
|
<div class="row g-3">
|
|
<div class="col-md-4"><label class="form-label">Manufacturer</label><InputText @bind-Value="_draft.Manufacturer" class="form-control"/></div>
|
|
<div class="col-md-4"><label class="form-label">Model</label><InputText @bind-Value="_draft.Model" class="form-control"/></div>
|
|
<div class="col-md-4"><label class="form-label">Serial number</label><InputText @bind-Value="_draft.SerialNumber" class="form-control"/></div>
|
|
<div class="col-md-4"><label class="form-label">Hardware rev</label><InputText @bind-Value="_draft.HardwareRevision" class="form-control"/></div>
|
|
<div class="col-md-4"><label class="form-label">Software rev</label><InputText @bind-Value="_draft.SoftwareRevision" class="form-control"/></div>
|
|
<div class="col-md-4">
|
|
<label class="form-label">Year of construction</label>
|
|
<InputNumber @bind-Value="_draft.YearOfConstruction" class="form-control"/>
|
|
</div>
|
|
</div>
|
|
|
|
@if (_error is not null) { <div class="alert alert-danger mt-3">@_error</div> }
|
|
|
|
<div class="mt-3">
|
|
<button type="submit" class="btn btn-primary btn-sm">Save</button>
|
|
<button type="button" class="btn btn-secondary btn-sm ms-2" @onclick="() => _showForm = false">Cancel</button>
|
|
</div>
|
|
</EditForm>
|
|
</div>
|
|
</div>
|
|
}
|
|
|
|
@code {
|
|
[Parameter] public long GenerationId { get; set; }
|
|
private List<Equipment>? _equipment;
|
|
private bool _showForm;
|
|
private Equipment _draft = NewBlankDraft();
|
|
private string? _error;
|
|
|
|
private static Equipment NewBlankDraft() => new()
|
|
{
|
|
EquipmentId = string.Empty, DriverInstanceId = string.Empty,
|
|
UnsLineId = string.Empty, Name = string.Empty, MachineCode = string.Empty,
|
|
};
|
|
|
|
protected override async Task OnParametersSetAsync() => await ReloadAsync();
|
|
|
|
private async Task ReloadAsync()
|
|
{
|
|
_equipment = await EquipmentSvc.ListAsync(GenerationId, CancellationToken.None);
|
|
}
|
|
|
|
private void StartAdd()
|
|
{
|
|
_draft = NewBlankDraft();
|
|
_error = null;
|
|
_showForm = true;
|
|
}
|
|
|
|
private async Task SaveAsync()
|
|
{
|
|
_error = null;
|
|
_draft.EquipmentUuid = Guid.NewGuid();
|
|
_draft.EquipmentId = DraftValidator.DeriveEquipmentId(_draft.EquipmentUuid);
|
|
_draft.GenerationId = GenerationId;
|
|
try
|
|
{
|
|
await EquipmentSvc.CreateAsync(GenerationId, _draft, CancellationToken.None);
|
|
_showForm = false;
|
|
await ReloadAsync();
|
|
}
|
|
catch (Exception ex) { _error = ex.Message; }
|
|
}
|
|
|
|
private async Task DeleteAsync(Guid id)
|
|
{
|
|
await EquipmentSvc.DeleteAsync(id, CancellationToken.None);
|
|
await ReloadAsync();
|
|
}
|
|
}
|