From 3189f901a833888cd3cfc1e3d4367816d6eae756 Mon Sep 17 00:00:00 2001 From: Marcel Baumgartner Date: Tue, 11 Apr 2023 21:36:25 +0200 Subject: [PATCH] Implemented domain order. Fixed some bugs --- .../App/Models/Forms/DomainOrderDataModel.cs | 15 ++ Moonlight/App/Services/DomainService.cs | 22 +++ .../Shared/Views/Admin/Domains/Index.razor | 14 +- .../Shared/Views/Admin/Domains/New.razor | 11 +- Moonlight/Shared/Views/Domains/Create.razor | 156 ++++++++++++++++++ .../{Domains.razor => Domains/Index.razor} | 0 Moonlight/Shared/Views/Websites/Create.razor | 6 +- Moonlight/resources/lang/de_de.lang | 5 + Moonlight/resources/lang/en_us.lang | 64 +++++++ 9 files changed, 278 insertions(+), 15 deletions(-) create mode 100644 Moonlight/App/Models/Forms/DomainOrderDataModel.cs create mode 100644 Moonlight/Shared/Views/Domains/Create.razor rename Moonlight/Shared/Views/{Domains.razor => Domains/Index.razor} (100%) diff --git a/Moonlight/App/Models/Forms/DomainOrderDataModel.cs b/Moonlight/App/Models/Forms/DomainOrderDataModel.cs new file mode 100644 index 0000000..c49dd8e --- /dev/null +++ b/Moonlight/App/Models/Forms/DomainOrderDataModel.cs @@ -0,0 +1,15 @@ +using System.ComponentModel.DataAnnotations; +using Moonlight.App.Database.Entities; + +namespace Moonlight.App.Models.Forms; + +public class DomainOrderDataModel +{ + [Required(ErrorMessage = "You need to specify a name")] + [MaxLength(32, ErrorMessage = "The max lenght for the name is 32 characters")] + [RegularExpression(@"^[a-z]+$", ErrorMessage = "The name should only consist of lower case characters")] + public string Name { get; set; } = ""; + + [Required(ErrorMessage = "You need to specify a shared domain")] + public SharedDomain SharedDomain { get; set; } +} \ No newline at end of file diff --git a/Moonlight/App/Services/DomainService.cs b/Moonlight/App/Services/DomainService.cs index 4bdbf9b..1b2cb98 100644 --- a/Moonlight/App/Services/DomainService.cs +++ b/Moonlight/App/Services/DomainService.cs @@ -48,6 +48,28 @@ public class DomainService ); } + public Task Create(string domain, SharedDomain sharedDomain, User user) + { + if (DomainRepository.Get().Where(x => x.SharedDomain.Id == sharedDomain.Id).Any(x => x.Name == domain)) + throw new DisplayException("A domain with this name does already exist for this shared domain"); + + var res = DomainRepository.Add(new() + { + Name = domain, + SharedDomain = sharedDomain, + Owner = user + }); + + return Task.FromResult(res); + } + + public Task Delete(Domain domain) + { + DomainRepository.Delete(domain); + + return Task.CompletedTask; + } + public async Task GetAvailableDomains() // This method returns all available domains which are not added as a shared domain { diff --git a/Moonlight/Shared/Views/Admin/Domains/Index.razor b/Moonlight/Shared/Views/Admin/Domains/Index.razor index 0f5cfc4..09c0d30 100644 --- a/Moonlight/Shared/Views/Admin/Domains/Index.razor +++ b/Moonlight/Shared/Views/Admin/Domains/Index.razor @@ -6,10 +6,11 @@ @using Moonlight.App.Services @inject DomainRepository DomainRepository +@inject DomainService DomainService @inject SmartTranslateService SmartTranslateService - +
@@ -47,11 +48,9 @@ @@ -65,6 +64,7 @@ @code { private Domain[] Domains; + private LazyLoader LazyLoader; private Task Load(LazyLoader arg) { @@ -79,5 +79,7 @@ private async Task Delete(Domain context) { + await DomainService.Delete(context); + await LazyLoader.Reload(); } } \ No newline at end of file diff --git a/Moonlight/Shared/Views/Admin/Domains/New.razor b/Moonlight/Shared/Views/Admin/Domains/New.razor index 203456a..0b08c4c 100644 --- a/Moonlight/Shared/Views/Admin/Domains/New.razor +++ b/Moonlight/Shared/Views/Admin/Domains/New.razor @@ -4,13 +4,12 @@ @using Moonlight.App.Models.Forms @using Moonlight.App.Repositories @using Moonlight.App.Repositories.Domains -@using Mappy.Net @inject SmartTranslateService SmartTranslateService @inject SharedDomainRepository SharedDomainRepository -@inject DomainRepository DomainRepository @inject UserRepository UserRepository @inject NavigationManager NavigationManager +@inject DomainService DomainService
@@ -66,14 +65,10 @@ return Task.CompletedTask; } - private Task Add() + private async Task Add() { - var domain = Mapper.Map(Model); - - DomainRepository.Add(domain); + await DomainService.Create(Model.Name, Model.SharedDomain, Model.Owner); NavigationManager.NavigateTo("/admin/domains"); - - return Task.CompletedTask; } } \ No newline at end of file diff --git a/Moonlight/Shared/Views/Domains/Create.razor b/Moonlight/Shared/Views/Domains/Create.razor new file mode 100644 index 0000000..d731acd --- /dev/null +++ b/Moonlight/Shared/Views/Domains/Create.razor @@ -0,0 +1,156 @@ +@page "/domains/create" +@using Moonlight.App.Services +@using Moonlight.App.Database.Entities +@using Moonlight.App.Models.Forms +@using Moonlight.App.Repositories.Domains +@using Microsoft.EntityFrameworkCore + +@inject SubscriptionService SubscriptionService +@inject DomainService DomainService +@inject DomainRepository DomainRepository +@inject SharedDomainRepository SharedDomainRepository +@inject NavigationManager NavigationManager +@inject SmartTranslateService SmartTranslateService + + + @if (!SharedDomains.Any()) + { +
+
+ Not found image +
+

+ No shared domain found +

+

+ No shared domain found +

+
+
+
+ } + else + { +
+
+
+
+
+

+ Domain details +

+
+
+
+
+ @if (AllowOrder) + { +
+ +
@(Model.Name)
+
+
+ +
@(Model.SharedDomain == null ? "" : Model.SharedDomain.Name)
+
+ } +
+
+
+
+
+
+
+
+

+ Configure your domain +

+
+
+
+ + @if (AllowOrder) + { + +
+ +
+ +
+ + + +
+ + + } + else + { +
+ + You reached the maximum amount of domains in your subscription: @(Subscription == null ? SmartTranslateService.Translate("Default") : Subscription.Name) + +
+ } +
+
+
+
+
+ } +
+ +@code +{ + [CascadingParameter] + public User User { get; set; } + + private SharedDomain[] SharedDomains; + + private Subscription? Subscription; + + private bool AllowOrder = false; + + private DomainOrderDataModel Model = new(); + + private async Task Load(LazyLoader lazyLoader) + { + Model = new(); + + await lazyLoader.SetText(SmartTranslateService.Translate("Loading your subscription")); + Subscription = await SubscriptionService.GetCurrent(); + + AllowOrder = DomainRepository + .Get() + .Include(x => x.Owner) + .Count(x => x.Owner.Id == User.Id) < (await SubscriptionService.GetLimit("domains")).Amount; + + await lazyLoader.SetText("Loading shared domains"); + SharedDomains = SharedDomainRepository.Get().ToArray(); + } + + private async Task OnValidSubmit() + { + if (DomainRepository + .Get() + .Include(x => x.Owner) + .Count(x => x.Owner.Id == User.Id) < (await SubscriptionService.GetLimit("domains")).Amount) + { + var domain = await DomainService.Create(Model.Name, Model.SharedDomain, User); + + NavigationManager.NavigateTo($"/domain/{domain.Id}"); + } + } +} diff --git a/Moonlight/Shared/Views/Domains.razor b/Moonlight/Shared/Views/Domains/Index.razor similarity index 100% rename from Moonlight/Shared/Views/Domains.razor rename to Moonlight/Shared/Views/Domains/Index.razor diff --git a/Moonlight/Shared/Views/Websites/Create.razor b/Moonlight/Shared/Views/Websites/Create.razor index 0f93642..5533cd1 100644 --- a/Moonlight/Shared/Views/Websites/Create.razor +++ b/Moonlight/Shared/Views/Websites/Create.razor @@ -3,6 +3,7 @@ @using Moonlight.App.Database.Entities @using Moonlight.App.Models.Forms @using Moonlight.App.Repositories +@using Microsoft.EntityFrameworkCore @inject SubscriptionService SubscriptionService @inject WebsiteService WebsiteService @@ -123,7 +124,10 @@ await lazyLoader.SetText(SmartTranslateService.Translate("Searching for deploy plesk server")); PleskServer = await SmartDeployService.GetPleskServer(); - AllowOrder = WebsiteRepository.Get().Count() < (await SubscriptionService.GetLimit("websites")).Amount; + AllowOrder = WebsiteRepository + .Get() + .Include(x => x.Owner) + .Count(x => x.Owner.Id == User.Id) < (await SubscriptionService.GetLimit("websites")).Amount; } private async Task OnValidSubmit() diff --git a/Moonlight/resources/lang/de_de.lang b/Moonlight/resources/lang/de_de.lang index f0feb02..1b1909d 100644 --- a/Moonlight/resources/lang/de_de.lang +++ b/Moonlight/resources/lang/de_de.lang @@ -531,3 +531,8 @@ Month;Month Year;Year All time;All time This function is not implemented;This function is not implemented +Domain details;Domain details +Configure your domain;Configure your domain +You reached the maximum amount of domains in your subscription;You reached the maximum amount of domains in your subscription +You need to specify a shared domain;You need to specify a shared domain +A domain with this name does already exist for this shared domain;A domain with this name does already exist for this shared domain diff --git a/Moonlight/resources/lang/en_us.lang b/Moonlight/resources/lang/en_us.lang index 75bac75..88f53b6 100644 --- a/Moonlight/resources/lang/en_us.lang +++ b/Moonlight/resources/lang/en_us.lang @@ -19,3 +19,67 @@ Forgot password?;Forgot password? Sign-in;Sign-in Not registered yet?;Not registered yet? Sign up;Sign up +Profile;Profile +Logout;Logout +Dashboard;Dashboard +Servers;Servers +Websites;Websites +Domains;Domains +Changelog;Changelog +Admin;Admin +System;System +Overview;Overview +Manager;Manager +Cleanup;Cleanup +Nodes;Nodes +Images;Images +Users;Users +Shared domains;Shared domains +Support;Support +Subscriptions;Subscriptions +Statistics;Statistics +Create something new;Create something new +Create a gameserver;Create a gameserver +A new gameserver in just a few minutes;A new gameserver in just a few minutes +Create a website;Create a website +Make your own websites with a webspace;Make your own websites with a webspace +Create a domain;Create a domain +Make your servvices accessible throught your own domain;Make your servvices accessible throught your own domain +Manage your services;Manage your services +Manage your gameservers;Manage your gameservers +Adjust your gameservers;Adjust your gameservers +Manage your websites;Manage your websites +Modify the content of your websites;Modify the content of your websites +Manage your domains;Manage your domains +Add, edit and delete dns records;Add, edit and delete dns records +New server;New server +Id;Id +Name;Name +Cores;Cores +Memory;Memory +Disk;Disk +Owner;Owner +Manage;Manage +Node offline;Node offline +The node the server is running on is currently offline;The node the server is running on is currently offline +Sessions;Sessions +New user;New user +First name;First name +Last name;Last name +Created at;Created at +Refresh;Refresh +Send a message to all users;Send a message to all users +IP;IP +URL;URL +Device;Device +Time;Time +Actions;Actions +Change url;Change url +Message;Message +Enter url;Enter url +Send;Send +Sending;Sending +Welcome to the support chat. Ask your question here and we will help you;Welcome to the support chat. Ask your question here and we will help you +less than a minute ago;less than a minute ago +The support team has been notified. Please be patient;The support team has been notified. Please be patient +is typing;is typing