Skip to content

Commit 9a375f8

Browse files
committed
CactuseSecurity#2867: Changed icons to open iconic, fixed bug and refactored to avoid warnings
1 parent c635829 commit 9a375f8

File tree

3 files changed

+60
-42
lines changed

3 files changed

+60
-42
lines changed

roles/lib/files/FWO.Api.Client/Data/Icons.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ public struct Icons
2929
public const string CollapseLeft = "oi oi-collapse-left";
3030
public const string CollapseRight = "oi oi-collapse-right";
3131
public const string Share = "oi oi-fork"; // oi-share-boxed? oi-share?
32+
public const string OrderByAsc = "oi oi-caret-top";
33+
public const string OrderByDesc = "oi oi-caret-bottom";
3234

3335
// Object types: General
3436
public const string Ldap = "oi oi-key";

roles/lib/files/FWO.Basics/IpOperations.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,11 @@ public static int CompareSubnetMasks(string subnetMask1, string subnetMask2)
245245
if (subnet2IsInt) return 1;
246246

247247

248-
IPAddress subnet1IP;
249-
IPAddress subnet2IP;
248+
IPAddress? subnet1IP;
249+
IPAddress? subnet2IP;
250250
bool subnet1IsIp = IPAddress.TryParse(subnetMask1, out subnet1IP);
251251
bool subnet2IsIp = IPAddress.TryParse(subnetMask2, out subnet2IP);
252-
if (subnet1IsIp && subnet2IsIp)
252+
if (subnet1IP != null && subnet2IP != null && subnet1IsIp && subnet2IsIp)
253253
{
254254
// if both in ip format order by value
255255
int compareIpValuesResult = CompareIpValues(subnet1IP, subnet2IP);

roles/ui/files/FWO.UI/Shared/OrderByDropdown.razor

Lines changed: 55 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,9 @@
2222
@((MarkupString) property)
2323
</ElementTemplate>
2424
</Dropdown>
25-
<div class="unicode-icons">
26-
<Dropdown @ref="orderModeDropdown"
27-
ElementType="OrderMode"
28-
@bind-SelectedElement="SelectedOrderMode"
29-
Elements="orderModes"
30-
ElementToString="@(a => DisplayOrderMode(a))">
31-
<ElementTemplate Context="orderMode">
32-
@((MarkupString) DisplayOrderMode(orderMode))
33-
</ElementTemplate>
34-
</Dropdown>
35-
</div>
25+
<button id="toggle-order-mode-button" type="button" class="btn btn-sm" @onclick="OnToggleOrderModeButtonClick">
26+
<span class="@DisplayOrderModeButton()"/>
27+
</button>
3628
</div>
3729

3830
@code
@@ -41,12 +33,12 @@
4133
/// List of the properties, that the user can order the collection by.
4234
/// </summary>
4335
[Parameter, EditorRequired]
44-
public List<string> ElementProperties { get; set; }
36+
public List<string>? ElementProperties { get; set; }
4537
/// <summary>
4638
/// Collection of items, that the user can order by the selected property and order mode.
4739
/// </summary>
4840
[Parameter, EditorRequired]
49-
public List<TCollectionItem> Collection { get; set; }
41+
public List<TCollectionItem>? Collection { get; set; }
5042
/// <summary>
5143
/// Callback to communicate that the reordering process has been completed.
5244
/// </summary>
@@ -98,22 +90,18 @@
9890
/// </summary>
9991
private Dropdown<string>? propertyDropdown;
10092
/// <summary>
101-
/// Reference to the dropdown component for the order mode.
102-
/// </summary>
103-
private Dropdown<OrderMode>? orderModeDropdown;
104-
/// <summary>
10593
/// The visual elements for the implemented order modes.
10694
/// </summary>
10795
private List<OrderMode> orderModes = new List<OrderMode> {OrderMode.Asc, OrderMode.Desc};
10896

97+
10998
protected override void OnAfterRender(bool firstRender)
11099
{
111100
if (firstRender)
112101
{
113-
if(propertyDropdown != null)
102+
if(propertyDropdown != null && propertyDropdown.Elements != null && propertyDropdown.Elements.Any())
114103
{
115-
//selectedOrderMode = OrderMode.Asc; // TODO: admissiable because of l. 74?
116-
selectedProperty = propertyDropdown.Elements.First();
104+
SelectedProperty = propertyDropdown.Elements.First();
117105
}
118106

119107
StateHasChanged();
@@ -125,23 +113,31 @@
125113
/// </summary>
126114
private void ReorderCollection()
127115
{
128-
if(SelectedProperty.Equals("Ip") && typeof(TCollectionItem) == typeof(ModellingAppServer))
116+
if(propertyDropdown != null && Collection != null && !string.IsNullOrEmpty(propertyDropdown.SelectedElement))
129117
{
130-
Collection = Collection.OrderBy(GetIPAddressRange, new IPAddressRangeComparer()).ToList<TCollectionItem>();
118+
if(SelectedProperty.Equals("Ip") && typeof(TCollectionItem) == typeof(ModellingAppServer))
119+
{
120+
Collection = Collection.OrderBy(GetIPAddressRange, new IPAddressRangeComparer()).ToList<TCollectionItem>();
121+
}
122+
else
123+
{
124+
string keySelectorProperty = propertyDropdown.SelectedElement;
125+
Func<TCollectionItem, object> keySelector = GetGenericOrderByExpression<TCollectionItem>(keySelectorProperty);
126+
Collection = Collection.OrderBy(keySelector).ToList();
127+
}
128+
129+
if (SelectedOrderMode == OrderMode.Desc)
130+
{
131+
Collection.Reverse();
132+
}
133+
134+
InvokeAsync(StateHasChanged);
135+
CollectionReordered.InvokeAsync();
131136
}
132137
else
133138
{
134-
Func<TCollectionItem, object> keySelector = GetGenericOrderByExpression<TCollectionItem>(propertyDropdown.SelectedElement);
135-
Collection = Collection.OrderBy(keySelector).ToList();
136-
}
137-
138-
if (SelectedOrderMode == OrderMode.Desc)
139-
{
140-
Collection.Reverse();
139+
throw new NullReferenceException();
141140
}
142-
143-
InvokeAsync(StateHasChanged);
144-
CollectionReordered.InvokeAsync();
145141
}
146142

147143
/// <summary>
@@ -168,7 +164,13 @@
168164
private Func<T, object> GetGenericOrderByExpression<T>(string propertyName)
169165
{
170166
ParameterExpression param = Expression.Parameter(typeof(T), "x");
171-
PropertyInfo propertyInfo = typeof(T).GetProperty(propertyName);
167+
168+
if (string.IsNullOrWhiteSpace(propertyName))
169+
{
170+
throw new ArgumentException();
171+
}
172+
173+
PropertyInfo? propertyInfo = typeof(T).GetProperty(propertyName);
172174

173175
if (propertyInfo == null)
174176
{
@@ -182,23 +184,37 @@
182184
}
183185

184186
/// <summary>
185-
/// Converts OrderMode to symbol.
187+
/// Displays icon of selected order mode.
186188
/// </summary>
187-
private string DisplayOrderMode(OrderMode orderMode)
189+
private string DisplayOrderModeButton()
188190
{
189-
switch (orderMode)
191+
switch (SelectedOrderMode)
190192
{
191193
case (OrderMode.Asc):
192-
return "";
194+
return Icons.OrderByAsc;
195+
196+
case (OrderMode.Desc):
197+
return Icons.OrderByDesc;
198+
199+
default:
200+
throw new NotImplementedException();
201+
}
202+
}
203+
204+
private void OnToggleOrderModeButtonClick()
205+
{
206+
switch (SelectedOrderMode)
207+
{
208+
case (OrderMode.Asc):
209+
SelectedOrderMode = OrderMode.Desc;
193210
break;
194211

195212
case (OrderMode.Desc):
196-
return "";
213+
SelectedOrderMode = OrderMode.Asc;
197214
break;
198215

199216
default:
200217
throw new NotImplementedException();
201-
break;
202218
}
203219
}
204220
}

0 commit comments

Comments
 (0)