Skip to content

Commit

Permalink
Make device ID optional on device details. Add it to the nav menu.
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbound committed Apr 16, 2021
1 parent e605f17 commit 7ac9800
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 31 deletions.
7 changes: 5 additions & 2 deletions Server/Components/Devices/DeviceCard.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
@inherits AuthComponentBase

<div @ref="_card" class="card border-secondary my-3 mr-3 device-card @Theme @GetCardStateClass(Device)"
@onclick="() => ExpandCard()"
@onclick:stopPropagation="true">
@onclick="ExpandCard"
@onclick:stopPropagation="true"
@oncontextmenu="ContextMenuOpening"
@oncontextmenu:preventDefault="GetCardState() == DeviceCardState.Normal"
@oncontextmenu:stopPropagation="GetCardState() == DeviceCardState.Normal">

<div class="card-header">
<div>
Expand Down
12 changes: 10 additions & 2 deletions Server/Components/Devices/DeviceCard.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private string GetProgressMessage(string key)
return string.Empty;
}

private void ExpandCard()
private void ExpandCard(MouseEventArgs args)
{
if (AppState.DevicesFrameFocusedDevice == Device.ID)
{
Expand All @@ -105,6 +105,14 @@ private void ExpandCard()
JsInterop.ScrollToElement(_card);
}

private void ContextMenuOpening(MouseEventArgs args)
{
if (GetCardState() == DeviceCardState.Normal)
{
JsInterop.OpenWindow($"/device-details/{Device.ID}", "_blank");
}
}

private DeviceCardState GetCardState()
{
if (AppState.DevicesFrameFocusedDevice == Device.ID)
Expand Down Expand Up @@ -173,7 +181,7 @@ private Task HandleValidSubmit()

private void OpenDeviceDetails()
{
JsInterop.OpenWindow($"/DeviceDetails/{Device.ID}", "_blank");
JsInterop.OpenWindow($"/device-details/{Device.ID}", "_blank");
}

private void SetCardStateNormal()
Expand Down
2 changes: 1 addition & 1 deletion Server/Components/Scripts/ScriptSchedules.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private async Task DeleteSelectedSchedule()
{
if (User.Id != _selectedSchedule.CreatorId)
{
ToastService.ShowToast("You can't delete other people's scripts.", classString: "bg-warning");
ToastService.ShowToast("You can't delete other people's script schedules.", classString: "bg-warning");
return;
}

Expand Down
67 changes: 46 additions & 21 deletions Server/Pages/DeviceDetails.razor
Original file line number Diff line number Diff line change
@@ -1,10 +1,35 @@
@page "/DeviceDetails/{deviceId}"
@page "/device-details/{deviceId?}"

@attribute [Authorize]
@inherits AuthComponentBase


@if (Device is null)
@if (string.IsNullOrWhiteSpace(DeviceId))
{
<div class="row mt-5">
<div class="col-sm-6 offset-2">

<h3>Device ID:</h3>
<div class="input-group mb-2">
<input type="text" class="form-control" placeholder="Enter a device ID to see its details"
@bind="_inputDeviceId"
@bind:event="oninput"
@onkeydown="EvaluateDeviceIdInputKeyDown">
<div class="input-group-append">
<button class="btn btn-primary" @onclick="NavigateToDeviceId">Go</button>
</div>
</div>
<div class="text-muted">
You can also go directly to a device's details by:
<ul>
<li>Right-clicking a device card on the main page while it's collapsed</li>
<li>Clicking the "Open in New Tab" button in a device card's header while it's expanded</li>
</ul>
</div>
</div>
</div>
}
else if (Device is null)
{
<h3>Device not found.</h3>
}
Expand Down Expand Up @@ -121,9 +146,9 @@ else
<div class="col-sm-10">
<InputSelect @bind-Value="Device.WebRtcSetting" class="form-control">
@foreach (var setting in Enum.GetValues(typeof(WebRtcSetting)))
{
{
<option @key="setting" value="@setting">@setting</option>
}
}
</InputSelect>
<ValidationMessage For="() => Device.WebRtcSetting" />
</div>
Expand All @@ -136,9 +161,9 @@ else
<option value="">None</option>

@foreach (var group in DataService.GetDeviceGroups(Username))
{
{
<option @key="group.ID" value="@group.ID">@group.Name</option>
}
}
</InputSelect>
<ValidationMessage For="() => Device.DeviceGroupID" />
</div>
Expand All @@ -163,7 +188,7 @@ else
</EditForm>
</div>
</TabContent>

<TabContent Name="remote-logs">
<div class="py-3">
@if (!Device.IsOnline)
Expand All @@ -190,7 +215,7 @@ else
</div>

</TabContent>

<TabContent Name="script-history">

<h3 class="mb-3 mt-3">
Expand All @@ -212,19 +237,19 @@ else
<tbody>
@foreach (var scriptResult in _scriptResults)
{
<tr>
<td>@scriptResult.Shell</td>
<td>@scriptResult.TimeStamp</td>
<td>@scriptResult.SenderUserName</td>
<td>@scriptResult.RunTime</td>
<td>@GetTrimmedText(scriptResult.ScriptInput, 25)</td>
<td>@GetTrimmedText(scriptResult.StandardOutput, 25)</td>
<td>@GetTrimmedText(scriptResult.ErrorOutput, 25)</td>
<td>
<button class="btn btn-sm btn-primary" @onclick="() => ShowFullScriptOutput(scriptResult)">Show Full</button>
</td>
</tr>
}
<tr>
<td>@scriptResult.Shell</td>
<td>@scriptResult.TimeStamp</td>
<td>@scriptResult.SenderUserName</td>
<td>@scriptResult.RunTime</td>
<td>@GetTrimmedText(scriptResult.ScriptInput, 25)</td>
<td>@GetTrimmedText(scriptResult.StandardOutput, 25)</td>
<td>@GetTrimmedText(scriptResult.ErrorOutput, 25)</td>
<td>
<button class="btn btn-sm btn-primary" @onclick="() => ShowFullScriptOutput(scriptResult)">Show Full</button>
</td>
</tr>
}
</tbody>
</table>

Expand Down
26 changes: 22 additions & 4 deletions Server/Pages/DeviceDetails.razor.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Rendering;
using Microsoft.AspNetCore.Components.Web;
using Remotely.Server.Components;
using Remotely.Server.Hubs;
using Remotely.Server.Services;
using Remotely.Shared.Models;
using Remotely.Shared.Utilities;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;

Expand All @@ -21,6 +20,7 @@ public partial class DeviceDetails : AuthComponentBase
private readonly ConcurrentQueue<ScriptResult> _scriptResults = new();

private string _alertMessage;
private string _inputDeviceId;

[Parameter]
public string DeviceId { get; set; }
Expand All @@ -36,8 +36,12 @@ public partial class DeviceDetails : AuthComponentBase
[Inject]
private IModalService ModalService { get; set; }

[Inject]
private NavigationManager NavManager { get; set; }

[Inject]
private IToastService ToastService { get; set; }

protected override Task OnInitializedAsync()
{
if (!string.IsNullOrWhiteSpace(DeviceId))
Expand Down Expand Up @@ -65,6 +69,14 @@ private void EditFormKeyDown()
_alertMessage = string.Empty;
}

private void EvaluateDeviceIdInputKeyDown(KeyboardEventArgs args)
{
if (args.Key.Equals("Enter", StringComparison.OrdinalIgnoreCase))
{
NavManager.NavigateTo($"/device-details/{_inputDeviceId}");
}
}

private void GetRemoteLogs()
{
_logLines.Clear();
Expand All @@ -84,7 +96,7 @@ private void GetScriptHistory()
var results = DataService
.GetAllScriptResults(User.OrganizationID, Device.ID)
.OrderByDescending(x => x.TimeStamp);

foreach (var result in results)
{
_scriptResults.Enqueue(result);
Expand Down Expand Up @@ -117,6 +129,7 @@ private string GetTrimmedText(string source, int stringLength)

return source[0..25] + "...";
}

private string GetTrimmedText(string[] source, int stringLength)
{
return GetTrimmedText(string.Join("", source), stringLength);
Expand All @@ -137,6 +150,11 @@ private Task HandleValidSubmit()
return Task.CompletedTask;
}

private void NavigateToDeviceId()
{
NavManager.NavigateTo($"/device-details/{_inputDeviceId}");
}

private void ShowAllDisks()
{
var disksString = JsonSerializer.Serialize(Device.Drives, JsonSerializerHelper.IndentedOptions);
Expand Down Expand Up @@ -166,4 +184,4 @@ void outputModal(RenderTreeBuilder builder)
ModalService.ShowModal("Script Input/Output", outputModal);
}
}
}
}
6 changes: 5 additions & 1 deletion Server/Shared/NavMenu.razor
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@
<span class="oi oi-script" aria-hidden="true"></span> Scripts
</NavLink>
</li>

<li class="nav-item px-3">
<NavLink class="nav-link" href="device-details">
<span class="oi oi-info" aria-hidden="true"></span> Device Details
</NavLink>
</li>
<li class="nav-item px-3">
<NavLink class="nav-link" href="user-options">
<span class="oi oi-pencil" aria-hidden="true"></span> User Options
Expand Down

0 comments on commit 7ac9800

Please sign in to comment.