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
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,19 @@
</div>
<div class="card-body">
//<BlazorViewDistributedData>
<DistributedDataView GroupName="default" Presentation="Command" ConfigSuffix="" EnableExport=true EnableSorting=true DisplayOnePerDataType=true />
<DistributedDataView Presentation="Command"
GroupName="default"
ConfigSuffix=""
DisplayOnePerDataType="true"
EnableCreate="true"
EnableDelete="true"
EnableCopy="true"
EnableFiltering="true"
EnableSorting="false"
EnableExport="true"
EnableSendToPlc="true"
EnableCreateNewFromPlc="true"
/>
//</BlazorViewDistributedData>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -298,25 +298,25 @@ else
</button>
</Authorized>
</AuthorizeView>

@*
@if (EnableUpdateFromPlc)
{
<AuthorizeView Roles="@DataExchangeRoleNames.can_data_update_from_plc">
<Authorized>
<button type="button" class="btn btn-warning px-3 py-0" title="Update" data-bs-toggle="modal" data-bs-target="#createModal-@ViewGuid"
@onclick='() => { Vm.SelectedRecord = item; ButtonOperationName = "UpdateFromPlc"; Vm.Locked(); }'>
@onclick='() => { Vm.SelectedRecord = item; ButtonOperationName = "UpdateFromPlc"; Vm.Locked(); }'>
<i class="bi bi-cloud-upload"></i>
</button>
</Authorized>
</AuthorizeView>
}
} *@

@if (EnableSendToPlc)
{
<AuthorizeView Roles="@DataExchangeRoleNames.can_data_send_to_plc">
<Authorized>
<button type="button" class="btn btn-warning px-3 py-0" title="Send To Plc" data-bs-toggle="modal" data-bs-target="#AckSendToPlcModal-@ViewGuid"
@onclick='() => { Vm.SelectedRecord = item;}'>
@onclick='() => { Vm.SelectedRecord = item;}'>
<i class="bi bi-box-arrow-in-down"></i>
@* <i class="bi bi-pc"></i> *@
</button>
Expand Down Expand Up @@ -552,7 +552,7 @@ else
<span> @Localizer["Load from ALL PLCs"]</span>
</button>
}
else if (ButtonOperationName.Equals("UpdateFromPlc"))
@* else if (ButtonOperationName.Equals("UpdateFromPlc"))
{
<button type="button" class="btn btn-primary @(!Vm.IsLockedByMeOrNull() ? "disabled" : null)" data-bs-dismiss="modal"
@onclick="async () => {
Expand All @@ -564,7 +564,7 @@ else
<i class="bi bi-hdd-rack me-2"></i>
<span> @Localizer["Update from ALL PLCs"]</span>
</button>
}
} *@
}


Expand All @@ -589,13 +589,13 @@ else
<span> @Localizer["Load from PLC into THIS repository"]</span>
</button>
}
else if (ButtonOperationName.Equals("UpdateFromPlc"))
@* else if (ButtonOperationName.Equals("UpdateFromPlc"))
{
<button type="button" class="btn btn-primary @(!Vm.IsLockedByMeOrNull() ? "disabled" : null)" data-bs-dismiss="modal" @onclick="() => { Vm.UpdateFromPlc(); Vm.UnLocked(); }">
<i class="bi bi-hdd me-2"></i>
<span> @Localizer["Update from PLC into THIS repository"]</span>
</button>
}
} *@

<button type="button" class="btn btn-secondary" data-bs-dismiss="modal" @onclick="() => { Vm.UnLocked(); }">@Localizer["Close"]</button>
</div>
Expand All @@ -616,18 +616,24 @@ else
<div class="modal-footer">
@if (Presentation.Equals("Command"))
{
<AuthorizeView Roles="@DataExchangeRoleNames.can_data_item_delete">
<Authorized>
<button type="button" class="btn btn-danger me-auto" data-bs-toggle="modal" data-bs-target="#deleteModal-@ViewGuid" @onclick="() => { Vm.Locked(); }">@Localizer["Delete"]</button>
</Authorized>
</AuthorizeView>
@if (EnableDelete)
{
<AuthorizeView Roles="@DataExchangeRoleNames.can_data_item_delete">
<Authorized>
<button type="button" class="btn btn-danger me-auto" data-bs-toggle="modal" data-bs-target="#deleteModal-@ViewGuid" @onclick="() => { Vm.Locked(); }">@Localizer["Delete"]</button>
</Authorized>
</AuthorizeView>
}

<AuthorizeView Roles="@DataExchangeRoleNames.can_data_item_copy">
<Authorized>
@if (EnableCopy)
{
<AuthorizeView Roles="@DataExchangeRoleNames.can_data_item_copy">
<Authorized>

<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#createModal-@ViewGuid" @onclick='() => { ButtonOperationName = "Copy"; Vm.Locked(); }'>@Localizer["Copy"]</button>
</Authorized>
</AuthorizeView>
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#createModal-@ViewGuid" @onclick='() => { ButtonOperationName = "Copy"; Vm.Locked(); }'>@Localizer["Copy"]</button>
</Authorized>
</AuthorizeView>
}

<AuthorizeView Roles="@DataExchangeRoleNames.can_data_item_edit">
<Authorized>
Expand All @@ -636,19 +642,15 @@ else
</Authorized>
</AuthorizeView>

<AuthorizeView Roles="@DataExchangeRoleNames.can_data_send_to_plc">
<Authorized>

<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#AckSendToPlcModal-@ViewGuid">@Localizer["Send to PLC"]</button>
</Authorized>
</AuthorizeView>

<AuthorizeView Roles="@DataExchangeRoleNames.can_data_item_delete">
<Authorized>

</Authorized>
</AuthorizeView>
@if (EnableSendToPlc)
{
<AuthorizeView Roles="@DataExchangeRoleNames.can_data_send_to_plc">
<Authorized>

<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#AckSendToPlcModal-@ViewGuid">@Localizer["Send to PLC"]</button>
</Authorized>
</AuthorizeView>
}

}
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#changesModal-@ViewGuid">@Localizer["Changes"]</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public partial class DataExchangeView : ComponentBase, IDisposable
[Parameter] public bool EnableExport { get; set; } = false;
[Parameter] public bool EnableSorting { get; set; } = false;

[Parameter] public bool EnableUpdateFromPlc { get; set; } = false;
//[Parameter] public bool EnableUpdateFromPlc { get; set; } = false;

[Parameter] public RenderFragment ChildContent { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,42 +450,42 @@ public async Task LoadFromPlc()
}
}

public async Task UpdateFromPlc()
{
try
{
var identifier = SelectedRecord.DataEntityId;

var refdata = DataExchange.CloneDataObject();

var DataEntityId = (refdata as IAxoDataEntity).DataEntityId;

List<ITwinPrimitive> batchRedElements = new();

batchRedElements.Add(DataEntityId);

await refdata.GetConnector().ReadBatchAsync(batchRedElements);

if (DataEntityId.Cyclic != identifier)
{
AlertDialogService?.AddAlertDialog(eAlertType.Warning, "Update error", $"Online record has different ID that requested to update: {DataEntityId.Cyclic}/{identifier}!", 14);
return;
}

await DataExchange.RemoteUpdate(identifier);
AlertDialogService?.AddAlertDialog(eAlertType.Success, "Update from PLC!", "Item was successfully updated from PLC!", 10);
AxoApplication.Current.Logger.Information($"Updated from Plc {identifier} into {DataExchange.PresentableInstanceName} by user action.", AuthenticationProvider.GetAuthenticationStateAsync().Result.User.Identity);
}
catch (Exception e)
{
AlertDialogService?.AddAlertDialog(eAlertType.Danger, "Failed to update a record from the controller", e.Message, 10);
}
finally
{
await FillObservableRecordsAsync();
CreateItemId = null;
}
}
//public async Task UpdateFromPlc()
//{
// try
// {
// var identifier = SelectedRecord.DataEntityId;

// var refdata = DataExchange.CloneDataObject();

// var DataEntityId = (refdata as IAxoDataEntity).DataEntityId;

// List<ITwinPrimitive> batchRedElements = new();

// batchRedElements.Add(DataEntityId);

// await refdata.GetConnector().ReadBatchAsync(batchRedElements);

// if (DataEntityId.Cyclic != identifier)
// {
// AlertDialogService?.AddAlertDialog(eAlertType.Warning, "Update error", $"Online record has different ID that requested to update: {DataEntityId.Cyclic}/{identifier}!", 14);
// return;
// }

// await DataExchange.RemoteUpdate(identifier);
// AlertDialogService?.AddAlertDialog(eAlertType.Success, "Update from PLC!", "Item was successfully updated from PLC!", 10);
// AxoApplication.Current.Logger.Information($"Updated from Plc {identifier} into {DataExchange.PresentableInstanceName} by user action.", AuthenticationProvider.GetAuthenticationStateAsync().Result.User.Identity);
// }
// catch (Exception e)
// {
// AlertDialogService?.AddAlertDialog(eAlertType.Danger, "Failed to update a record from the controller", e.Message, 10);
// }
// finally
// {
// await FillObservableRecordsAsync();
// CreateItemId = null;
// }
//}


public Task ExportDataAsync(string path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public interface IDataExchangeGlobalActions
public Task Copy(string identifier, string newIdentifier);
public Task Create(string identifier);
public Task CreateNewFromPlc(string identifier);
public Task UpdateFromPlc(string identifier);
//public Task UpdateFromPlc(string identifier);
public Task SendToPlc(string identifier);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,11 @@ public partial class DistributedDataSelectorView
[Parameter, EditorRequired]
public string GroupName { get; set; }

[Parameter]
public string ConfigSuffix { get; set; } = "";
[Parameter] public string ConfigSuffix { get; set; } = "";

[Parameter]
public PredicateContainer? InjectedPredicateContainer { set; get; }
[Parameter] public PredicateContainer? InjectedPredicateContainer { set; get; }

[Parameter]
public Action<string>? OnDataSend { get; set; }
[Parameter] public Action<string>? OnDataSend { get; set; }


[Inject]
Expand Down Expand Up @@ -62,7 +59,7 @@ protected override async Task OnInitializedAsync()

if (DataFragments != null)
{
DistributedVM = new DistributedDataSelectorViewModel(DistributedExchangeService, GroupName, AlertService, InjectedPredicateContainer);
DistributedVM = new DistributedDataSelectorViewModel(AlertService, Authentication, DistributedExchangeService, GroupName, ConfigSuffix, InjectedPredicateContainer);


await DistributedVM.ReadAllCurrentEntityIds();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ public partial class DistributedDataSelectorViewModel
protected volatile object _fragmentEntityIdsLock = new object();
protected volatile object _transmitedEntityIdsLock = new object();

protected readonly AuthenticationStateProvider Authentication;
protected readonly IDistributedDataExchangeService distributedExchangeService;
protected readonly IAlertService AlertService;
protected readonly string ExchangeGroup;
protected readonly string GroupName;

protected readonly PredicateContainer InjectedPredicateContainer;
protected IEnumerable<IAxoDataExchange> RepresentativeExchanges { get; set; } // one per type
Expand Down Expand Up @@ -73,20 +74,27 @@ public List<PlainSymbolBuilder> PlainBuilders
}
}

public DistributedDataSelectorViewModel(IDistributedDataExchangeService distributedExchangeService, string exchangeGroup, IAlertService alertService, PredicateContainer injectePredicateContainer)
public DistributedDataSelectorViewModel(
IAlertService alertService,
AuthenticationStateProvider authentication,
IDistributedDataExchangeService distributedExchangeService,
string groupName,
string configuraionSuffix,
PredicateContainer injectePredicateContainer )
{
this.distributedExchangeService = distributedExchangeService;
this.AlertService = alertService;
this.InjectedPredicateContainer = injectePredicateContainer;
this.ExchangeGroup = exchangeGroup;
this.GroupName = groupName;
this.Authentication = authentication;

InitializeViewModel();
}

private void InitializeViewModel()
{
RepresentativeExchanges = distributedExchangeService.GetExchanges(this.ExchangeGroup, true);
AllExchanges = distributedExchangeService.GetExchanges(this.ExchangeGroup, false);
RepresentativeExchanges = distributedExchangeService.GetExchanges(this.GroupName, true);
AllExchanges = distributedExchangeService.GetExchanges(this.GroupName, false);
MainExchange = RepresentativeExchanges.First();

}
Expand Down Expand Up @@ -216,7 +224,7 @@ public async Task SendToPlc(string identifier)
List<string> sentToPlc = new List<string>();
List<string> notExistInDb = new List<string>();

foreach (var exchangeGroup in distributedExchangeService.GetExchanges(this.ExchangeGroup, false).GroupBy(p => p.GetPlainTypes().First().FullName))
foreach (var exchangeGroup in distributedExchangeService.GetExchanges(this.GroupName, false).GroupBy(p => p.GetPlainTypes().First().FullName))
{
if (!exchangeGroup.First().Repository.Exists(identifier))
{
Expand All @@ -237,15 +245,42 @@ public async Task SendToPlc(string identifier)

if (sentToPlc.Count > 0)
{
string updatedRecords = string.Join(", ", sentToPlc);
AlertService?.AddAlertDialog(eAlertType.Info, "Send record", $"Data with ID: \"{identifier}\" was send for: {updatedRecords}!", 7);
string sentExchanges = string.Join(", ", sentToPlc);

// Alert
AlertService?.AddAlertDialog(
eAlertType.Info,
"Send record",
$"Record \"{identifier}\" was sent to: {sentExchanges}.",
7
);

// Log
AxoApplication.Current.Logger.Information(
$"Sent record \"{identifier}\" to: {sentExchanges} by user action.",
Authentication.GetAuthenticationStateAsync().Result.User.Identity
);
}

if (notExistInDb.Count > 0)
{
string notEqualEntityIds = string.Join(", ", notExistInDb);
AlertService?.AddAlertDialog(eAlertType.Warning, "Send error", $"Rrecord has not exist in a Database for: {notEqualEntityIds}!", 14);

// Alert
AlertService?.AddAlertDialog(
eAlertType.Warning,
"Send error",
$"Record does not exist in the database for: {notEqualEntityIds}.",
14
);

// Log
AxoApplication.Current.Logger.Warning(
$"Sending record \"{identifier}\" by user action failed – record does not exist in database for: {notEqualEntityIds}.",
Authentication.GetAuthenticationStateAsync().Result.User.Identity
);
}

}

public async Task ReadAllCurrentEntityIds()
Expand Down
Loading
Loading