Skip to content

Commit

Permalink
Add branding reset button. Add numeric inputs for rgb values.
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbound committed May 11, 2021
1 parent 3d55332 commit e47b59c
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 25 deletions.
13 changes: 8 additions & 5 deletions Server/Components/ColorPicker.razor
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
@using Remotely.Server.Models

<div>
<label>Color Sample:</label>
<div class="color-sample mb-1" style="background-color:@($"rgb({Red},{Green},{Blue})")"></div>
<div>Color Sample:</div>
<div class="color-sample mb-4" style="background-color:@($"rgb({Red},{Green},{Blue})")"></div>

<label>Red</label>
<div>Red</div>
<input type="range" min="0" max="255" class="form-control red-picker" @bind="Red" />
<input type="number" min="0" max="255" class="form-control mb-4" style="width: 150px" @bind="Red" />

<label>Green</label>
<div>Green</div>
<input type="range" min="0" max="255" class="form-control green-picker" @bind="Green" />
<input type="number" min="0" max="255" class="form-control mb-4" style="width: 150px" @bind="Green" />

<label>Blue</label>
<div>Blue</div>
<input type="range" min="0" max="255" class="form-control blue-picker" @bind="Blue" />
<input type="number" min="0" max="255" class="form-control mb-4" style="width: 150px" @bind="Blue" />
</div>


Expand Down
61 changes: 41 additions & 20 deletions Server/Components/Branding.razor → Server/Pages/Branding.razor
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
@page "/branding"
@inherits AuthComponentBase
@inject IDataService DataService
@inject IToastService ToastService
@inject IDataService DataService
@inject IToastService ToastService
@inject IJsInterop JsInterop
@using Remotely.Server.Models
@using System.ComponentModel.DataAnnotations
@using System.ComponentModel.DataAnnotations

<h3 class="mb-3">Branding</h3>

Expand Down Expand Up @@ -63,6 +64,7 @@ else
<ColorPicker @bind-Color="_inputModel.TitleButtonColor" />
</div>
<div class="form-group text-right">
<button class="btn btn-secondary mr-3" type="button" @onclick="ResetBranding">Reset</button>
<button class="btn btn-primary" type="submit">Submit</button>
</div>
</EditForm>
Expand All @@ -89,22 +91,11 @@ else
public byte[] IconBytes { get; set; }
}

private async Task IconUploadInputChanged(InputFileChangeEventArgs args)
protected override async Task OnInitializedAsync()
{
if (args.File is null)
{
return;
}

if (args.File.Size > 1_024_000)
{
ToastService.ShowToast("File size must be under 1 MB.", classString: "bg-warning");
return;
}
await base.OnInitializedAsync();

using var rs = args.File.OpenReadStream(1_024_000);
_inputModel.IconBytes = new byte[args.File.Size];
await rs.ReadAsync(_inputModel.IconBytes, 0, (int)args.File.Size);
await LoadBrandingInfo();
}

private async Task HandleValidSubmit(EditContext context)
Expand All @@ -117,16 +108,35 @@ else
_inputModel.TitleBackgroundColor,
_inputModel.TitleButtonColor);

_base64Icon = Convert.ToBase64String(_inputModel.IconBytes);
if (_inputModel?.IconBytes?.Any() == true)
{
_base64Icon = Convert.ToBase64String(_inputModel.IconBytes);
}

_alertMessage = "Branding saved.";
ToastService.ShowToast("Branding saved.");
}

protected override async Task OnInitializedAsync()
private async Task IconUploadInputChanged(InputFileChangeEventArgs args)
{
await base.OnInitializedAsync();
if (args.File is null)
{
return;
}

if (args.File.Size > 1_024_000)
{
ToastService.ShowToast("File size must be under 1 MB.", classString: "bg-warning");
return;
}

using var rs = args.File.OpenReadStream(1_024_000);
_inputModel.IconBytes = new byte[args.File.Size];
await rs.ReadAsync(_inputModel.IconBytes, 0, (int)args.File.Size);
}

private async Task LoadBrandingInfo()
{
var organization = await DataService.GetOrganizationByUserName(User.UserName);

var brandingInfo = await DataService.GetBrandingInfo(organization.ID);
Expand All @@ -151,4 +161,15 @@ else
_inputModel.TitleButtonColor.Green = brandingInfo.ButtonForegroundGreen;
_inputModel.TitleButtonColor.Blue = brandingInfo.ButtonForegroundBlue;
}

private async Task ResetBranding()
{
var result = await JsInterop.Confirm("Are you sure you want to reset branding to default?");
if (result)
{
await DataService.ResetBranding(User.OrganizationID);
await LoadBrandingInfo();
ToastService.ShowToast("Branding reset.");
}
}
}
20 changes: 20 additions & 0 deletions Server/Services/DataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ public interface IDataService
Task<bool> RemoveUserFromDeviceGroup(string orgID, string groupID, string userID);
Task RenameApiToken(string userName, string tokenId, string tokenName);

Task ResetBranding(string organizationId);

void SetAllDevicesNotOnline();

Task SetDisplayName(RemotelyUser user, string displayName);
Expand Down Expand Up @@ -1713,6 +1715,24 @@ public async Task RenameApiToken(string userName, string tokenId, string tokenNa
await dbContext.SaveChangesAsync();
}

public async Task ResetBranding(string organizationId)
{
using var dbContext = _dbFactory.CreateDbContext();

var organization = await dbContext.Organizations
.Include(x => x.BrandingInfo)
.FirstOrDefaultAsync(x => x.ID == organizationId);

if (organization is null)
{
return;
}

organization.BrandingInfo = new BrandingInfo();

await dbContext.SaveChangesAsync();
}

public void SetAllDevicesNotOnline()
{
using var dbContext = _dbFactory.CreateDbContext();
Expand Down

0 comments on commit e47b59c

Please sign in to comment.