diff --git a/Moonlight/App/Models/Forms/WebsiteDataModel.cs b/Moonlight/App/Models/Forms/WebsiteDataModel.cs index d4a7f4bf..9bc9d2df 100644 --- a/Moonlight/App/Models/Forms/WebsiteDataModel.cs +++ b/Moonlight/App/Models/Forms/WebsiteDataModel.cs @@ -4,7 +4,7 @@ namespace Moonlight.App.Models.Forms; public class WebsiteDataModel { - [Required(ErrorMessage = "You need a domain")] + [Required(ErrorMessage = "You need to enter a domain")] [RegularExpression(@"([a-z0-9|-]+\.)*[a-z0-9|-]+\.[a-z]+", ErrorMessage = "You need to enter a valid domain")] public string BaseDomain { get; set; } = ""; } \ No newline at end of file diff --git a/Moonlight/App/Models/Forms/WebsiteOrderDataModel.cs b/Moonlight/App/Models/Forms/WebsiteOrderDataModel.cs new file mode 100644 index 00000000..0c5a388e --- /dev/null +++ b/Moonlight/App/Models/Forms/WebsiteOrderDataModel.cs @@ -0,0 +1,10 @@ +using System.ComponentModel.DataAnnotations; + +namespace Moonlight.App.Models.Forms; + +public class WebsiteOrderDataModel +{ + [Required(ErrorMessage = "You need to enter a domain")] + [RegularExpression(@"([a-z0-9|-]+\.)*[a-z0-9|-]+\.[a-z]+", ErrorMessage = "You need to enter a valid domain")] + public string BaseDomain { get; set; } = ""; +} \ No newline at end of file diff --git a/Moonlight/App/Services/SmartDeployService.cs b/Moonlight/App/Services/SmartDeployService.cs index 0585c1dd..57aa4bc8 100644 --- a/Moonlight/App/Services/SmartDeployService.cs +++ b/Moonlight/App/Services/SmartDeployService.cs @@ -6,12 +6,18 @@ namespace Moonlight.App.Services; public class SmartDeployService { private readonly NodeRepository NodeRepository; + private readonly PleskServerRepository PleskServerRepository; + private readonly WebsiteService WebsiteService; private readonly NodeService NodeService; - public SmartDeployService(NodeRepository nodeRepository, NodeService nodeService) + public SmartDeployService( + NodeRepository nodeRepository, + NodeService nodeService, PleskServerRepository pleskServerRepository, WebsiteService websiteService) { NodeRepository = nodeRepository; NodeService = nodeService; + PleskServerRepository = pleskServerRepository; + WebsiteService = websiteService; } public async Task GetNode() @@ -32,6 +38,21 @@ public class SmartDeployService return data.MaxBy(x => x.Value).Key; } + public async Task GetPleskServer() + { + var result = new List(); + + foreach (var pleskServer in PleskServerRepository.Get().ToArray()) + { + if (await WebsiteService.IsHostUp(pleskServer)) + { + result.Add(pleskServer); + } + } + + return result.FirstOrDefault(); + } + private async Task GetUsageScore(Node node) { var score = 0; diff --git a/Moonlight/Shared/Views/Servers/Create.razor b/Moonlight/Shared/Views/Servers/Create.razor index de782e1d..bc372c1c 100644 --- a/Moonlight/Shared/Views/Servers/Create.razor +++ b/Moonlight/Shared/Views/Servers/Create.razor @@ -27,7 +27,7 @@ No node found

- No node found to deploy to found + No node found to deploy to

@@ -36,8 +36,8 @@ else {
-
-
+
+

@@ -48,7 +48,7 @@
- +
@(DeployNode.Name)
@if (Model.Image != null) @@ -159,11 +159,9 @@ Subscription = await SubscriptionService.GetCurrent(); await lazyLoader.SetText(SmartTranslateService.Translate("Searching for deploy node")); - DeployNode = await SmartDeployService.GetNode(); await lazyLoader.SetText(SmartTranslateService.Translate("Searching for available images")); - var images = ImageRepository.Get().ToArray(); foreach (var image in images) @@ -179,7 +177,7 @@ .Where(x => x.Owner.Id == User.Id) .Count(x => x.Image.Id == image.Id); - if(serversCount <= limit.Amount) //TODO: FIX COUNTING + if(serversCount < limit.Amount) Images.Add(image, limit); } } diff --git a/Moonlight/Shared/Views/Websites/Create.razor b/Moonlight/Shared/Views/Websites/Create.razor new file mode 100644 index 00000000..0f936421 --- /dev/null +++ b/Moonlight/Shared/Views/Websites/Create.razor @@ -0,0 +1,138 @@ +@page "/websites/create" +@using Moonlight.App.Services +@using Moonlight.App.Database.Entities +@using Moonlight.App.Models.Forms +@using Moonlight.App.Repositories + +@inject SubscriptionService SubscriptionService +@inject WebsiteService WebsiteService +@inject WebsiteRepository WebsiteRepository +@inject SmartDeployService SmartDeployService +@inject SmartTranslateService SmartTranslateService +@inject NavigationManager NavigationManager + + + @if (PleskServer == null) + { +
+
+ Not found image +
+

+ No plesk server found +

+

+ No plesk server found to deploy to +

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

+ Website details +

+
+
+
+
+
+ +
@(PleskServer.Name)
+
+ @if (AllowOrder) + { +
+ +
@(Model.BaseDomain)
+
+ } +
+
+
+
+
+
+
+
+

+ Configure your website +

+
+
+
+ + @if (AllowOrder) + { + +
+ +
+ + + } + else + { +
+ + You reached the maximum amount of websites in your subscription: @(Subscription == null ? SmartTranslateService.Translate("Default") : Subscription.Name) + +
+ } +
+
+
+
+
+ } +
+ +@code +{ + [CascadingParameter] + public User User { get; set; } + + private Subscription? Subscription; + private PleskServer? PleskServer; + private bool AllowOrder = false; + + private WebsiteOrderDataModel Model = new(); + + private async Task Load(LazyLoader lazyLoader) + { + // Reset state + Model = new(); + + await lazyLoader.SetText(SmartTranslateService.Translate("Loading your subscription")); + Subscription = await SubscriptionService.GetCurrent(); + + await lazyLoader.SetText(SmartTranslateService.Translate("Searching for deploy plesk server")); + PleskServer = await SmartDeployService.GetPleskServer(); + + AllowOrder = WebsiteRepository.Get().Count() < (await SubscriptionService.GetLimit("websites")).Amount; + } + + private async Task OnValidSubmit() + { + if (WebsiteRepository.Get().Count() < (await SubscriptionService.GetLimit("websites")).Amount) + { + var website = await WebsiteService.Create(Model.BaseDomain, User, PleskServer); + + NavigationManager.NavigateTo($"/website/{website.Id}"); + } + } +} \ No newline at end of file diff --git a/Moonlight/Shared/Views/Websites/New.razor b/Moonlight/Shared/Views/Websites/New.razor deleted file mode 100644 index 84255d65..00000000 --- a/Moonlight/Shared/Views/Websites/New.razor +++ /dev/null @@ -1 +0,0 @@ -@page "/websites/new" \ No newline at end of file diff --git a/Moonlight/resources/lang/de_de.lang b/Moonlight/resources/lang/de_de.lang index f0feb020..84e4d1db 100644 --- a/Moonlight/resources/lang/de_de.lang +++ b/Moonlight/resources/lang/de_de.lang @@ -531,3 +531,7 @@ Month;Month Year;Year All time;All time This function is not implemented;This function is not implemented +Searching for deploy plesk server;Searching for deploy plesk server +Website details;Website details +Configure your website;Configure your website +You reached the maximum amount of websites in your subscription;You reached the maximum amount of websites in your subscription