Skip to content

Commit

Permalink
Merge pull request #353 from ix-ax/AxoArray_VisualImprovement
Browse files Browse the repository at this point in the history
Some vissual changes
  • Loading branch information
PTKu authored Mar 8, 2024
2 parents fac5d63 + 1164a32 commit f9613a4
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 124 deletions.
25 changes: 9 additions & 16 deletions src/core/src/AXOpen.Core.Blazor/AxoArrays/AxoBoolArrayView.razor
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,25 @@
@using AXSharp.Presentation.Blazor.Controls.Layouts.TabControlComponents;
@inherits RenderableComplexComponentBase<AxoBoolArray>;

<div >
<div class="row ">
<div class="col">
@Component.AttributeName
<button class="btn btn-primary" type="button" @onclick="@Refresh">
<div>
<div class="row justify-content-between">
<div class="col-auto d-flex align-items-center">
<p class="mb-0">@Component.AttributeName</p>
</div>
<div class="col-auto d-flex justify-content-end">
<button class="btn btn-primary" type="button" @onclick="() => UpdateData(null, null)">
<span class="oi oi-reload" aria-hidden="true" />
</button>
</div>
</div>
<div class="row flex-nowrap">
<div class="row mx-1 flex-nowrap gx-0" style="overflow-x: auto; width: 70vw;">
@if (this.Data != null)
{
@foreach (IndexedData<bool> item in this.Data)
{
if (item != null && @item.Index != null && @item.Data != null)
{
<div class="col">
<div class="col-auto mx-1">
<div>
@item.Index
</div>
Expand All @@ -34,13 +36,4 @@
}
}
</div>

</div>

@code {

private async Task Refresh()
{
UpdateData(null, null);
}
}
114 changes: 32 additions & 82 deletions src/core/src/AXOpen.Core.Blazor/AxoArrays/AxoByteArrayView.razor
Original file line number Diff line number Diff line change
Expand Up @@ -4,129 +4,80 @@
@using AXSharp.Presentation.Blazor.Controls.Layouts.TabControlComponents;
@inherits RenderableComplexComponentBase<AxoByteArray>;

<div @oncontextmenu="Show" @oncontextmenu:preventDefault="true">
<div class="row ">
<div class="col">
@Component.AttributeName
<div>
<div class="row justify-content-between">
<div class="col-auto d-flex align-items-center">
<p class="mb-0">@Component.AttributeName</p>
</div>
<div class="col-auto d-flex justify-content-end">
<button type="button" class="btn btn-secondary me-1" data-bs-toggle="modal" data-bs-target="#formatModal-@_id">Format</button>
@if (IsControllable & !IsReadOnly)
{
<button class="btn btn-primary" type="button" @onclick="@Upload">
<button class="btn btn-primary" type="button" @onclick="() => UploadAndFormatData(null, null)">
<span class="oi oi-data-transfer-upload" aria-hidden="true" />
</button>
<button class="btn btn-primary" type="button" @onclick="@Download">
<button class="btn btn-primary" type="button" @onclick="() => Download()">
<span class="oi oi-data-transfer-download" aria-hidden="true" />
</button>
}
else
{
<button class="btn btn-primary" type="button" @onclick="@Upload">
<button class="btn btn-primary" type="button" @onclick="() => UploadAndFormatData(null, null)">
<span class="oi oi-reload" aria-hidden="true" />
</button>
}
</div>
</div>
<div class="row ms-1 me-1 flex-nowrap" style="overflow-x: scroll; width: 75em;">
<div class="row mx-1 flex-nowrap gx-0" style="overflow-x: auto; width: 70vw;">
@if (this.Data != null)
{
@foreach (IndexedData<string> item in this.Data)
{
if (item != null && @item.Index != null && @item.Data != null)
{
<div class="col">
<div class="col-auto mx-1">
<label>@item.Index</label>
<div>
<input type="text" @bind=item.Data maxlength="@MaxLen" style="@Style">
<input class="form-control p-1" type="text" @bind=item.Data maxlength="@MaxLen" style="width: 2.5rem;">
</div>
</div>
}
}
}
</div>
<div class="container">
<div class="modal modal-xl @_modalClass" tabindex="-1" role="dialog" style="display:@_modalDisplay; overflow-y: auto; ">
<div class="modal-dialog mw-75 w-50 modal-dialog-centered" style="align-items: flex-end;" role="document">
<div class="modal-content">
<div class="modal-header">
<div class="text-center d-flex">
<div class="col">
<h3 class="modal-title m-2 ">Display format</h3>
</div>
<div class="d-flex justify-content-center ">
<button type="button" class="btn-close topright" data-dismiss="modal" aria-label="Close" @onclick="Close" />
</div>
</div>
</div>
<div class="modal-body">
<p>Display data as:</p>
<select class="form-control" @bind="@SelectedFormatID">
</div>

@foreach (var displayedFormat in DisplayedFormatList)
{
<option value="@displayedFormat.DisplayFormat"> @displayedFormat.Description </option>
}
<div class="modal fade" id="formatModal-@_id" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="exampleModalLabel">Display format</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<select class="form-control" @bind="@DisplayFormat">

</select>
<div class="d-flex justify-content-center ">
<button type="button" class="btn btn-primary m-2 w-50" @onclick="ChangeFormat">Change format</button>
<button type="button" class="btn btn-primary m-2 w-50" @onclick="Close">Cancel</button>
</div>
</div>
</div>
@foreach (var displayedFormat in DisplayedFormatList)
{
<option value="@displayedFormat.DisplayFormat"> @displayedFormat.Description </option>
}
</select>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
</div>
</div>
</div>
@if (_showBackdrop)
{
<div class="modal-backdrop fade show"></div>
}
</div>

@code {

private string _modalDisplay = "none;";
private string _modalClass = string.Empty;
private bool _showBackdrop = false;
private eDisplayFormat previousDisplayFormat;
private eDisplayFormat selectedFormatID;

private eDisplayFormat SelectedFormatID
{
get => selectedFormatID;
set { selectedFormatID = value; }
}
private Guid _id = Guid.NewGuid();

private List<DisplayedFormat> DisplayedFormatList = new List<DisplayedFormat>()
{new DisplayedFormat(eDisplayFormat.Array_of_decimals, "array of decimals"),
new DisplayedFormat(eDisplayFormat.Array_of_hexdecimals, "array of hexadecimals"),
new DisplayedFormat(eDisplayFormat.String, "string") };

private async Task Show()
{
_modalDisplay = "flex";
_modalClass = "show";
_showBackdrop = true;
previousDisplayFormat = CurrentDisplayFormat;
SelectedFormatID = previousDisplayFormat;
await InvokeAsync(StateHasChanged);
}

private async Task Close()
{
_modalDisplay = "none";
_modalClass = string.Empty;
_showBackdrop = false;
await InvokeAsync(StateHasChanged);
}

private async Task ChangeFormat()
{
if (SelectedFormatID != previousDisplayFormat)
{
CurrentDisplayFormat = SelectedFormatID;
}
await Close();
}

private async Task Upload()
{
UploadAndFormatData(null, null);
Expand All @@ -140,7 +91,6 @@

private class DisplayedFormat
{

public DisplayedFormat(eDisplayFormat displayFormat, string description)
{
DisplayFormat = displayFormat;
Expand Down
42 changes: 16 additions & 26 deletions src/core/src/AXOpen.Core.Blazor/AxoArrays/AxoByteArrayView.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,19 @@ namespace AXOpen.Core
public enum eDisplayFormat { Array_of_hexdecimals , Array_of_decimals, String };
public partial class AxoByteArrayView : RenderableComplexComponentBase<AxoByteArray>, IDisposable
{

private eDisplayFormat _currentDisplayFormat;
private eDisplayFormat _displayFormat;
private uint _maxLen = 3;
private string _style = "width: 2.1em";
private bool _isReadOnly = false;

[Parameter]
public bool IsControllable { get; set; }

public eDisplayFormat CurrentDisplayFormat
public eDisplayFormat DisplayFormat
{
get => _currentDisplayFormat;
get => _displayFormat;
set
{
_currentDisplayFormat = value;
_displayFormat = value;
FormatData(null, null);
}
}
Expand All @@ -36,11 +34,6 @@ public uint MaxLen
private set { _maxLen = value; }
}

public string Style
{
get => _style;
private set { _style = value; }
}
public bool IsReadOnly
{
get => _isReadOnly;
Expand Down Expand Up @@ -92,9 +85,9 @@ private async void UploadAndFormatData(ITwinPrimitive sender, ValueChangedEventA
{
string _displayFormat = Component.DisplayFormat.ToString().ToLower();
_isReadOnly = _data[0].ReadWriteAccess.Equals(ReadWriteAccess.Read);
CurrentDisplayFormat = eDisplayFormat.Array_of_hexdecimals;
if (_displayFormat.Equals("decimal")) CurrentDisplayFormat = eDisplayFormat.Array_of_decimals;
if (_displayFormat.Equals("string")) CurrentDisplayFormat = eDisplayFormat.String;
DisplayFormat = eDisplayFormat.Array_of_hexdecimals;
if (_displayFormat.Equals("decimal")) DisplayFormat = eDisplayFormat.Array_of_decimals;
if (_displayFormat.Equals("string")) DisplayFormat = eDisplayFormat.String;
}

initialized = true;
Expand Down Expand Up @@ -139,9 +132,9 @@ private async void FormatData(ITwinPrimitive sender, ValueChangedEventArgs args)
if (Component.DisplayFormat != null)
{
string _displayFormat = Component.DisplayFormat.ToString().ToLower();
CurrentDisplayFormat = eDisplayFormat.Array_of_hexdecimals;
if (_displayFormat.Equals("decimal")) CurrentDisplayFormat = eDisplayFormat.Array_of_decimals;
if (_displayFormat.Equals("string")) CurrentDisplayFormat = eDisplayFormat.String;
DisplayFormat = eDisplayFormat.Array_of_hexdecimals;
if (_displayFormat.Equals("decimal")) DisplayFormat = eDisplayFormat.Array_of_decimals;
if (_displayFormat.Equals("string")) DisplayFormat = eDisplayFormat.String;
}

initialized = true;
Expand All @@ -156,23 +149,20 @@ private async void FormatData(ITwinPrimitive sender, ValueChangedEventArgs args)
for (int i = 0; i < length; i++)
{
byte _byte = _data[i] != null ? _data[i].Shadow : (byte)0;
if (CurrentDisplayFormat == eDisplayFormat.Array_of_decimals)
if (DisplayFormat == eDisplayFormat.Array_of_decimals)
{
Data[i] = new IndexedData<string>(i, _byte.ToString());
MaxLen = 3;
Style = "width: 2.1em; border:hidden";
}
else if (CurrentDisplayFormat == eDisplayFormat.Array_of_hexdecimals)
else if (DisplayFormat == eDisplayFormat.Array_of_hexdecimals)
{
Data[i] = new IndexedData<string>(i, _byte.ToString("X"));
MaxLen = 2;
Style = "width: 1.8em; border:hidden";
}
else if (CurrentDisplayFormat == eDisplayFormat.String)
else if (DisplayFormat == eDisplayFormat.String)
{
Data[i] = new IndexedData<string>(i, Encoding.UTF8.GetString(new byte[] { _byte }));
MaxLen = 1;
Style = "width: 1.3em; border:hidden";
}
}
}
Expand Down Expand Up @@ -212,15 +202,15 @@ private async void Download(ITwinPrimitive sender, ValueChangedEventArgs args)
for (int i = 0; i < length; i++)
{
byte _byte = _data[i] != null ? _data[i].Shadow : (byte)0;
if (CurrentDisplayFormat == eDisplayFormat.Array_of_decimals)
if (DisplayFormat == eDisplayFormat.Array_of_decimals)
{
_data[i].Shadow = (byte)Decimal.Parse(Data[i].Data as string, NumberStyles.None);
}
else if (CurrentDisplayFormat == eDisplayFormat.Array_of_hexdecimals)
else if (DisplayFormat == eDisplayFormat.Array_of_hexdecimals)
{
_data[i].Shadow = (byte)Convert.ToInt32(Data[i].Data as string, 16);
}
else if (CurrentDisplayFormat == eDisplayFormat.String)
else if (DisplayFormat == eDisplayFormat.String)
{
if (Data[i].Data.Length == 1)
{
Expand Down

0 comments on commit f9613a4

Please sign in to comment.