Skip to content

Commit

Permalink
Renaming of badly named variables
Browse files Browse the repository at this point in the history
  • Loading branch information
thom776g committed Dec 7, 2023
1 parent 6b666b1 commit 9303f4d
Showing 1 changed file with 63 additions and 63 deletions.
126 changes: 63 additions & 63 deletions CentralHub.WebUI/Pages/Rooms.razor
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<p>This component demonstrates fetching data from a service.</p>

@if (_treeRoomItems == null)
@if (_wRooms == null)
{
<p>
<em>Loading...</em>
Expand All @@ -28,29 +28,29 @@ else
</div>
<table class="table" style="margin-top: 0px">
<tbody>
@foreach (var item in _treeRoomItems)
@foreach (var wRoom in _wRooms)
{
<tr style="border-top-width: 1px" >
<td>
<span class="oi oi-home"></span>
@item.ItemsRoom.Name
@wRoom.Room.Name
</td>
<td class="align-right">
<div align="right">
<button type="button" class="btn btn-light" onclick="location.href='/charts/@item.ItemsRoom.RoomId'"><span class="oi oi-graph"></span></button>
<button type="button" class="btn btn-light" @onclick="() => EditRoomModal(item)"><span class="oi oi-pencil"></span></button>
<button type="button" class="btn btn-light" @onclick="() => AddTrackerModal(item)"><span class="oi oi-plus"></span></button>
<button type="button" class="btn btn-light" @onclick="() => ToggleNode(item)"><span class="oi oi-chevron-bottom"></span></button>
<button type="button" class="btn btn-light" onclick="location.href='/charts/@wRoom.Room.RoomId'"><span class="oi oi-graph"></span></button>
<button type="button" class="btn btn-light" @onclick="() => EditRoomModal(wRoom)"><span class="oi oi-pencil"></span></button>
<button type="button" class="btn btn-light" @onclick="() => AddTrackerModal(wRoom)"><span class="oi oi-plus"></span></button>
<button type="button" class="btn btn-light" @onclick="() => ToggleNode(wRoom)"><span class="oi oi-chevron-bottom"></span></button>
</div>
</td>
</tr>
@if (item.IsExpanded)
@if (wRoom.IsExpanded)
{
<tr align="center">
<td colspan="2" style="padding-left: 20px; padding-right: 20px; padding-top: 0px; padding-bottom: 0px">
<table class="table" style="margin: -1px">
<tbody>
@foreach (var tracker in item.Children)
@foreach (var tracker in wRoom.Children)
{
<tr>
<td>
Expand All @@ -59,7 +59,7 @@ else
</td>
<td>
<div align="right">
<button type="button" class="btn btn-light" @onclick="()=> EditTrackerModal(item, tracker)"><span class="oi oi-pencil"></span></button>
<button type="button" class="btn btn-light" @onclick="()=> EditTrackerModal(wRoom, tracker)"><span class="oi oi-pencil"></span></button>
</div>
</td>
</tr>
Expand Down Expand Up @@ -143,7 +143,7 @@ else
<input type="text" class="form-control" @bind="_roomName"/>
</td>
<td>
@_selectedRoomItem?.TrackerCount
@_selectedWRoom?.TrackerCount
</td>
</tr>
<tr>
Expand All @@ -161,9 +161,9 @@ else

<!-- Modal footer -->
<div class="modal-footer">
<button type="button" class="btn btn-danger" @onclick="() => DeleteRoomModal(_selectedRoomItem!)">Delete</button>
<button type="button" class="btn btn-danger" @onclick="() => DeleteRoomModal(_selectedWRoom!)">Delete</button>
<button type="button" class="btn" @onclick= '()=> HideModal("editRoomModal")'>Cancel</button>
<button type="button" class="btn btn-main" @onclick='() => ConfirmEditRoom(_selectedRoomItem!, _roomName, _roomDescription)'>Confirm</button>
<button type="button" class="btn btn-main" @onclick='() => ConfirmEditRoom(_selectedWRoom!, _roomName, _roomDescription)'>Confirm</button>
</div>
</div>
</div>
Expand Down Expand Up @@ -205,9 +205,9 @@ else
<tr>
<td>
<select class="form-control" @bind="@_selectedRoomId">
@foreach (var item in _treeRoomItems!)
@foreach (var wRoom in _wRooms!)
{
<option value="@item.ItemsRoom.RoomId">@item.ItemsRoom.Name</option>
<option value="@wRoom.Room.RoomId">@wRoom.Room.Name</option>
}
</select>
</td>
Expand Down Expand Up @@ -270,9 +270,9 @@ else
</td>
<td>
<select class="form-control" @bind="@_selectedRoomId">
@foreach (var item in _treeRoomItems)
@foreach (var wRoom in _wRooms)
{
<option value="@item.ItemsRoom.RoomId">@item.ItemsRoom.Name</option>
<option value="@wRoom.Room.RoomId">@wRoom.Room.Name</option>
}
</select>
</td>
Expand All @@ -296,7 +296,7 @@ else

<!-- Modal footer -->
<div class="modal-footer">
<button type="button" class="btn btn-danger" @onclick="() => DeleteTrackerModal(_selectedRoomItem!, _selectedTracker!)">Delete</button>
<button type="button" class="btn btn-danger" @onclick="() => DeleteTrackerModal(_selectedWRoom!, _selectedTracker!)">Delete</button>
<button type="button" class="btn" @onclick= '()=> HideModal("editTrackerModal")'>Cancel</button>
<button type="button" class="btn btn-main" @onclick='() => ConfirmEditTracker(_selectedTracker!, _selectedRoomId!, _trackerName!, _trackerDescription!)'>Confirm</button>
</div>
Expand All @@ -307,9 +307,9 @@ else
@code {
private readonly CancellationTokenSource _cancellationTokenSource = new CancellationTokenSource();
private List<Room> _rooms = new List<Room>();
private List<TreeItem> _treeRoomItems = new List<TreeItem>();
private List<RoomWrapper> _wRooms = new List<RoomWrapper>();
private UnregisteredTracker[] _unregisteredTrackers = new UnregisteredTracker[0];
private TreeItem? _selectedRoomItem;
private RoomWrapper? _selectedWRoom;
private Tracker? _selectedTracker;
private int _selectedRoomId = -1;
private String _roomName = "Your room name";
Expand Down Expand Up @@ -338,14 +338,14 @@ else
}
}

async Task EditRoomModal(TreeItem item)
async Task EditRoomModal(RoomWrapper wRoom)
{
if(item != null)
if(wRoom != null)
{
_selectedRoomItem = item;
_roomName = _selectedRoomItem!.ItemsRoom.Name;
_roomDescription = _selectedRoomItem.ItemsRoom.Description;
item!.TrackerCount = await GetTrackerCountAsync(item.ItemsRoom);
_selectedWRoom = wRoom;
_roomName = _selectedWRoom!.Room.Name;
_roomDescription = _selectedWRoom.Room.Description;
wRoom!.TrackerCount = await GetTrackerCountAsync(wRoom.Room);
await ShowModal("editRoomModal");
StateHasChanged();
}
Expand All @@ -355,11 +355,11 @@ else
}
}

async Task DeleteRoomModal(TreeItem item)
async Task DeleteRoomModal(RoomWrapper wRoom)
{
if(item != null)
if(wRoom != null)
{
await DeleteRoom(item!);
await DeleteRoom(wRoom!);
await HideModal("editRoomModal");
StateHasChanged();
}
Expand All @@ -369,15 +369,15 @@ else
}
}

async Task ConfirmEditRoom(TreeItem item, String name, String description)
async Task ConfirmEditRoom(RoomWrapper wRoom, String name, String description)
{
if(item != null && name != "" && name != null)
if(wRoom != null && name != "" && name != null)
{
await RoomService.UpdateRoomAsync(item!.ItemsRoom, name!, description, _cancellationTokenSource.Token);
await RoomService.UpdateRoomAsync(wRoom!.Room, name!, description, _cancellationTokenSource.Token);
await HideModal("editRoomModal");
NavigationManager.NavigateTo(NavigationManager.Uri, forceLoad: true);
}
else if(item == null)
else if(wRoom == null)
{
await JSRuntime.InvokeVoidAsync("alert", "Room is null");
}
Expand All @@ -387,12 +387,12 @@ else
}
}

async Task AddTrackerModal(TreeItem item)
async Task AddTrackerModal(RoomWrapper wRoom)
{
if(item != null)
if(wRoom != null)
{
_selectedRoomItem = item;
_selectedRoomId = item!.ItemsRoom.RoomId;
_selectedWRoom = wRoom;
_selectedRoomId = wRoom!.Room.RoomId;
_unregisteredTrackers = await TrackerService.GetUnregisteredTrackersAsync(_cancellationTokenSource.Token);
_selectedTrackerMacAdress = _unregisteredTrackers[0].WifiMacAddress;
await ShowModal("addTrackerModal");
Expand Down Expand Up @@ -428,19 +428,19 @@ else
}
}

async Task EditTrackerModal(TreeItem item, Tracker tracker)
async Task EditTrackerModal(RoomWrapper wRoom, Tracker tracker)
{
if(item != null && tracker != null)
if(wRoom != null && tracker != null)
{
_selectedRoomItem = item;
_selectedRoomId = item!.ItemsRoom.RoomId;
_selectedWRoom = wRoom;
_selectedRoomId = wRoom!.Room.RoomId;
_selectedTracker = tracker;
_trackerName = tracker!.Name;
_trackerDescription = tracker.Description;
await ShowModal("editTrackerModal");
StateHasChanged();
}
else if(item == null)
else if(wRoom == null)
{
await JSRuntime.InvokeVoidAsync("alert", "Room is null");
}
Expand Down Expand Up @@ -473,15 +473,15 @@ else
}
}

async Task DeleteTrackerModal(TreeItem item, Tracker tracker)
async Task DeleteTrackerModal(RoomWrapper wRoom, Tracker tracker)
{
if(item != null && tracker != null)
if(wRoom != null && tracker != null)
{
await DeleteTracker(item!, tracker!);
await DeleteTracker(wRoom!, tracker!);
await HideModal("editTrackerModal");
StateHasChanged();
}
else if(item == null)
else if(wRoom == null)
{
await JSRuntime.InvokeVoidAsync("alert", "Room is null");
}
Expand All @@ -491,15 +491,15 @@ else
}
}

protected class TreeItem
protected class RoomWrapper
{
public TreeItem(Room room, Tracker[] children, bool isExpanded = false)
public RoomWrapper(Room room, Tracker[] children, bool isExpanded = false)
{
ItemsRoom = room;
Room = room;
Children = children;
TrackerCount = children.Length;
}
public Room ItemsRoom { get; set; }
public Room Room { get; set; }
public Tracker[] Children { get; set; }
public int TrackerCount { get; set; }
public bool IsExpanded { get; set; }
Expand All @@ -510,15 +510,15 @@ else
_rooms = (await RoomService.GetRoomsAsync(_cancellationTokenSource.Token)).ToList();
_unregisteredTrackers = await TrackerService.GetUnregisteredTrackersAsync(_cancellationTokenSource.Token);

List<TreeItem> treeItems = new List<TreeItem>();
List<RoomWrapper> RoomWrappers = new List<RoomWrapper>();
foreach (var room in _rooms)
{
treeItems.Add(new TreeItem(
RoomWrappers.Add(new RoomWrapper(
room,
await TrackerService.GetTrackersAsync(room, _cancellationTokenSource.Token)
));
}
_treeRoomItems = treeItems;
_wRooms = RoomWrappers;
AssignStandardValues();
}
private async Task<int> GetTrackerCountAsync(Room room)
Expand All @@ -528,24 +528,24 @@ else
return trackers.Length;
}

protected async Task DeleteRoom(TreeItem item)
protected async Task DeleteRoom(RoomWrapper wRoom)
{
// Remove the room on the server
await RoomService.RemoveRoomAsync(item.ItemsRoom, _cancellationTokenSource.Token);
await RoomService.RemoveRoomAsync(wRoom.Room, _cancellationTokenSource.Token);
// Remove the room in memory
_rooms!.Remove(item.ItemsRoom);
_treeRoomItems!.Remove(item);
_rooms!.Remove(wRoom.Room);
_wRooms!.Remove(wRoom);

StateHasChanged();
}

protected async Task DeleteTracker(TreeItem item, Tracker tracker)
protected async Task DeleteTracker(RoomWrapper wRoom, Tracker tracker)
{
// Remove the tracker on the server
await TrackerService.RemoveTrackerAsync(tracker, _cancellationTokenSource.Token);
// Remove the tracker in memory
Tracker[] newTrackers = await TrackerService.GetTrackersAsync(item.ItemsRoom, _cancellationTokenSource.Token);
item.Children = newTrackers;
Tracker[] newTrackers = await TrackerService.GetTrackersAsync(wRoom.Room, _cancellationTokenSource.Token);
wRoom.Children = newTrackers;

StateHasChanged();
}
Expand All @@ -556,9 +556,9 @@ else
_cancellationTokenSource.Dispose();
}

void ToggleNode(TreeItem item)
void ToggleNode(RoomWrapper wRoom)
{
item.IsExpanded = !item.IsExpanded;
wRoom.IsExpanded = !wRoom.IsExpanded;
}

async Task HideModal(String modalId)
Expand All @@ -575,7 +575,7 @@ async Task HideModal(String modalId)

void AssignStandardValues()
{
_selectedRoomItem = null;
_selectedWRoom = null;
_selectedTracker = null;

_selectedRoomId = -1;
Expand Down

0 comments on commit 9303f4d

Please sign in to comment.