diff --git a/Server/Components/ColorPicker.razor b/Server/Components/ColorPicker.razor index 1b83dc80..1c3e15f9 100644 --- a/Server/Components/ColorPicker.razor +++ b/Server/Components/ColorPicker.razor @@ -1,17 +1,20 @@ @using Remotely.Server.Models
- -
+
Color Sample:
+
- +
Red
+ - +
Green
+ - +
Blue
+
diff --git a/Server/Components/Branding.razor b/Server/Pages/Branding.razor similarity index 86% rename from Server/Components/Branding.razor rename to Server/Pages/Branding.razor index 7cae9b95..0387247d 100644 --- a/Server/Components/Branding.razor +++ b/Server/Pages/Branding.razor @@ -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

Branding

@@ -63,6 +64,7 @@ else
+
@@ -89,6 +91,32 @@ else public byte[] IconBytes { get; set; } } + protected override async Task OnInitializedAsync() + { + await base.OnInitializedAsync(); + + await LoadBrandingInfo(); + } + + private async Task HandleValidSubmit(EditContext context) + { + await DataService.UpdateBrandingInfo( + User.OrganizationID, + _inputModel.ProductName, + _inputModel.IconBytes, + _inputModel.TitleForegroundColor, + _inputModel.TitleBackgroundColor, + _inputModel.TitleButtonColor); + + if (_inputModel?.IconBytes?.Any() == true) + { + _base64Icon = Convert.ToBase64String(_inputModel.IconBytes); + } + + _alertMessage = "Branding saved."; + ToastService.ShowToast("Branding saved."); + } + private async Task IconUploadInputChanged(InputFileChangeEventArgs args) { if (args.File is null) @@ -107,26 +135,8 @@ else await rs.ReadAsync(_inputModel.IconBytes, 0, (int)args.File.Size); } - private async Task HandleValidSubmit(EditContext context) + private async Task LoadBrandingInfo() { - 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() - { - await base.OnInitializedAsync(); - var organization = await DataService.GetOrganizationByUserName(User.UserName); var brandingInfo = await DataService.GetBrandingInfo(organization.ID); @@ -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."); + } + } } diff --git a/Server/Services/DataService.cs b/Server/Services/DataService.cs index a68f2b73..a31b9a7e 100644 --- a/Server/Services/DataService.cs +++ b/Server/Services/DataService.cs @@ -186,6 +186,8 @@ namespace Remotely.Server.Services Task 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); @@ -1713,6 +1715,24 @@ namespace Remotely.Server.Services 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();