From 0a9e9589fc3d612015be19634878ef7730e3b30b Mon Sep 17 00:00:00 2001 From: Marcel Baumgartner Date: Fri, 5 May 2023 04:45:55 +0200 Subject: [PATCH] Removed legacy setup and config save --- Moonlight/App/Helpers/ConfigUtils.cs | 43 ------ Moonlight/App/Services/ConfigService.cs | 5 - Moonlight/Shared/Views/Setup/Features.razor | 69 ---------- Moonlight/Shared/Views/Setup/Final.razor | 40 ------ Moonlight/Shared/Views/Setup/Index.razor | 53 -------- Moonlight/Shared/Views/Setup/Users.razor | 142 -------------------- 6 files changed, 352 deletions(-) delete mode 100644 Moonlight/App/Helpers/ConfigUtils.cs delete mode 100644 Moonlight/Shared/Views/Setup/Features.razor delete mode 100644 Moonlight/Shared/Views/Setup/Final.razor delete mode 100644 Moonlight/Shared/Views/Setup/Index.razor delete mode 100644 Moonlight/Shared/Views/Setup/Users.razor diff --git a/Moonlight/App/Helpers/ConfigUtils.cs b/Moonlight/App/Helpers/ConfigUtils.cs deleted file mode 100644 index 1f5196a4..00000000 --- a/Moonlight/App/Helpers/ConfigUtils.cs +++ /dev/null @@ -1,43 +0,0 @@ -using Newtonsoft.Json; - -namespace Moonlight.App.Helpers; - -public class ConfigUtils -{ - public static void SaveConfigurationAsJson(IConfiguration configuration, string filePath) - { - // Serialize the configuration to a JSON object - var jsonObject = new Dictionary(); - foreach (var section in configuration.GetChildren()) - { - SerializeSection(section, jsonObject); - } - - // Convert the JSON object to a JSON string - var jsonString = JsonConvert.SerializeObject(jsonObject); - - // Write the JSON string to a file - File.WriteAllText(filePath, jsonString); - } - - private static void SerializeSection(IConfigurationSection section, IDictionary jsonObject) - { - var children = section.GetChildren(); - - if (!children.Any()) - { - // Leaf node - jsonObject[section.Key] = section.Value; - } - else - { - // Non-leaf node - var childObject = new Dictionary(); - foreach (var childSection in children) - { - SerializeSection(childSection, childObject); - } - jsonObject[section.Key] = childObject; - } - } -} \ No newline at end of file diff --git a/Moonlight/App/Services/ConfigService.cs b/Moonlight/App/Services/ConfigService.cs index 6aa11c43..f57d9c06 100644 --- a/Moonlight/App/Services/ConfigService.cs +++ b/Moonlight/App/Services/ConfigService.cs @@ -74,9 +74,4 @@ public class ConfigService : IConfiguration get => Configuration[key]; set => Configuration[key] = value; } - - public void Save() - { - ConfigUtils.SaveConfigurationAsJson(Configuration, "..\\..\\appsettings.json"); - } } \ No newline at end of file diff --git a/Moonlight/Shared/Views/Setup/Features.razor b/Moonlight/Shared/Views/Setup/Features.razor deleted file mode 100644 index 50febfd5..00000000 --- a/Moonlight/Shared/Views/Setup/Features.razor +++ /dev/null @@ -1,69 +0,0 @@ -@page "/setup/features" - -@using Moonlight.App.Services - -@inject ConfigService ConfigService -@inject NavigationManager NavigationManager -@inject SmartTranslateService SmartTranslateService - - -
-
- Configure features (3/4) -
-
-
- -
-
- - -
-
-
- -
-
-
- - - - -@code -{ - private bool EnableSupportChat - { - get => bool.Parse( - ConfigService - .GetSection("Moonlight") - .GetSection("SupportChat") - ["Enabled"]! - ); - set => ConfigService - .GetSection("Moonlight") - .GetSection("SupportChat") - ["Enabled"] = value.ToString(); - } - - private Task Save() - { - ConfigService.Save(); - NavigationManager.NavigateTo("/setup/final"); - - return Task.CompletedTask; - } -} \ No newline at end of file diff --git a/Moonlight/Shared/Views/Setup/Final.razor b/Moonlight/Shared/Views/Setup/Final.razor deleted file mode 100644 index b259144c..00000000 --- a/Moonlight/Shared/Views/Setup/Final.razor +++ /dev/null @@ -1,40 +0,0 @@ -@page "/setup/final" - -@using Moonlight.App.Services -@using Moonlight.App.Services.Interop - -@inject ConfigService ConfigService -@inject NavigationManager NavigationManager -@inject SmartTranslateService SmartTranslateService -@inject ToastService ToastService - - -
-
- Finalize installation (4/4) -
-
-
- - -
-
-
-
- - - - -@code -{ - private async Task Save() - { - ConfigService.GetSection("Moonlight")["SetupComplete"] = true.ToString(); - ConfigService.Save(); - await ToastService.Success(SmartTranslateService.Translate("Moonlight basic settings successfully configured")); - NavigationManager.NavigateTo("/"); - } -} \ No newline at end of file diff --git a/Moonlight/Shared/Views/Setup/Index.razor b/Moonlight/Shared/Views/Setup/Index.razor deleted file mode 100644 index dbdf13b4..00000000 --- a/Moonlight/Shared/Views/Setup/Index.razor +++ /dev/null @@ -1,53 +0,0 @@ -@page "/setup" -@using Moonlight.App.Services - -@inject ConfigService ConfigService -@inject NavigationManager NavigationManager -@inject SmartTranslateService SmartTranslateService - - -
-
- Configure basics (1/4) -
-
- -
- - - - -
-
- - - - Next - -
-
-
-
- - - - -@code -{ - private Task Save() - { - ConfigService.Save(); - NavigationManager.NavigateTo("/setup/users"); - - return Task.CompletedTask; - } -} \ No newline at end of file diff --git a/Moonlight/Shared/Views/Setup/Users.razor b/Moonlight/Shared/Views/Setup/Users.razor deleted file mode 100644 index ab887fcb..00000000 --- a/Moonlight/Shared/Views/Setup/Users.razor +++ /dev/null @@ -1,142 +0,0 @@ -@page "/setup/users" -@using Moonlight.App.Services -@using Microsoft.AspNetCore.Components -@using Moonlight.App.Database.Entities -@using Moonlight.App.Exceptions -@using Moonlight.App.Services.Interop -@using Logging.Net -@using Moonlight.App.Repositories - -@inject UserService UserService -@inject UserRepository UserRepository -@inject SmartTranslateService SmartTranslateService -@inject AlertService AlertService -@inject ToastService ToastService - - -
-
- Add admin accounts (2/4) -
-
- -
- - - - -
- -
- - - - -
- -
- - - - -
- -
- - - - -
- -
-
-
- - - - -@code -{ - private User NewUser = new(); - - private async Task Save() - { - try - { - await UserService.Register( - NewUser.Email, - NewUser.Password, - NewUser.FirstName, - NewUser.LastName - ); - - var user = UserRepository.Get().First(x => x.Email == NewUser.Email); - user.Admin = true; - UserRepository.Update(user); - - await ToastService.Success( - SmartTranslateService.Translate("User successfully created") - ); - } - catch (DisplayException e) - { - await AlertService.Error( - SmartTranslateService.Translate("Error"), - e.Message - ); - } - catch (Exception e) - { - await AlertService.Error( - SmartTranslateService.Translate("Error"), - SmartTranslateService.Translate("An error occured while creating user") - ); - - Logger.Error("Error while creating user"); - Logger.Error(e); - } - - NewUser = new(); - - await InvokeAsync(StateHasChanged); - } -} \ No newline at end of file