@page "/branding"
@inherits AuthComponentBase
@inject IDataService DataService
@inject IToastService ToastService
@using Remotely.Server.Models
@using System.ComponentModel.DataAnnotations
Branding
@if (User.IsAdministrator != true)
{
Only organization administrators can view this page.
}
else
{
@if (!string.IsNullOrWhiteSpace(_base64Icon))
{
}
}
@code {
private string _alertMessage;
private string _base64Icon;
private InputModel _inputModel = new();
private class InputModel
{
[StringLength(25)]
[Required]
[Display(Name = "Product Name")]
public string ProductName { get; set; }
public ColorPickerModel TitleForegroundColor { get; set; } = new();
public ColorPickerModel TitleBackgroundColor { get; set; } = new();
public ColorPickerModel TitleButtonColor { get; set; } = new();
public byte[] IconBytes { get; set; }
}
private async Task IconUploadInputChanged(InputFileChangeEventArgs args)
{
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 HandleValidSubmit(EditContext context)
{
await DataService.UpdateBrandingInfo(
User.OrganizationID,
_inputModel.ProductName,
_inputModel.IconBytes,
_inputModel.TitleForegroundColor,
_inputModel.TitleBackgroundColor,
_inputModel.TitleButtonColor);
_base64Icon = Convert.ToBase64String(_inputModel.IconBytes);
_alertMessage = "Branding saved.";
ToastService.ShowToast("Branding saved.");
}
protected override async Task OnInitializedAsync()
{
var organization = await DataService.GetOrganizationByUserName(User.UserName);
var brandingInfo = await DataService.GetBrandingInfo(organization.ID);
_inputModel.ProductName = brandingInfo.Product;
if (brandingInfo?.Icon?.Any() == true)
{
_base64Icon = Convert.ToBase64String(brandingInfo.Icon);
}
_inputModel.TitleForegroundColor.Red = brandingInfo.TitleForegroundRed;
_inputModel.TitleForegroundColor.Green = brandingInfo.TitleForegroundGreen;
_inputModel.TitleForegroundColor.Blue = brandingInfo.TitleForegroundBlue;
_inputModel.TitleBackgroundColor.Red = brandingInfo.TitleBackgroundRed;
_inputModel.TitleBackgroundColor.Green = brandingInfo.TitleBackgroundGreen;
_inputModel.TitleBackgroundColor.Blue = brandingInfo.TitleBackgroundBlue;
_inputModel.TitleButtonColor.Red = brandingInfo.ButtonForegroundRed;
_inputModel.TitleButtonColor.Green = brandingInfo.ButtonForegroundGreen;
_inputModel.TitleButtonColor.Blue = brandingInfo.ButtonForegroundBlue;
}
}