فهرست منبع

Fixed my stupid mistakes

Marcel Baumgartner 2 سال پیش
والد
کامیت
0a244ac474

+ 3 - 1
Moonlight/App/Services/ServerService.cs

@@ -259,7 +259,7 @@ public class ServerService
     }
     }
 
 
     public async Task<Server> Create(string name, int cpu, long memory, long disk, User u, Image i, Node? n = null,
     public async Task<Server> Create(string name, int cpu, long memory, long disk, User u, Image i, Node? n = null,
-        Action<Server>? modifyDetails = null, int allocations = 1)
+        Action<Server>? modifyDetails = null)
     {
     {
         var user = UserRepository
         var user = UserRepository
             .Get()
             .Get()
@@ -271,6 +271,8 @@ public class ServerService
             .Include(x => x.DockerImages)
             .Include(x => x.DockerImages)
             .First(x => x.Id == i.Id);
             .First(x => x.Id == i.Id);
 
 
+        var allocations = image.Allocations;
+
         Node node = n ?? NodeRepository.Get().First();
         Node node = n ?? NodeRepository.Get().First();
 
 
         NodeAllocation[] freeAllocations;
         NodeAllocation[] freeAllocations;

+ 42 - 0
Moonlight/Shared/Views/Admin/Nodes/Edit.razor

@@ -109,6 +109,25 @@
                                              OnClick="CreateAllocation">
                                              OnClick="CreateAllocation">
                                     </WButton>
                                     </WButton>
                                 </div>
                                 </div>
+                                <div class="col-auto">
+                                    <label class="form-label">
+                                        <TL>Start</TL>
+                                    </label>
+                                    <input @bind="StartPort" type="number" class="col-auto form-control bg-transparent">
+                                </div>
+                                <div class="col-auto">
+                                    <label class="form-label">
+                                        <TL>End</TL>
+                                    </label>
+                                    <input @bind="EndPort" type="number" class="col-auto form-control bg-transparent">
+                                </div>
+                                <div class="col-auto">
+                                    <WButton Text="@(SmartTranslateService.Translate("Add"))"
+                                             WorkingText="@(SmartTranslateService.Translate("Adding"))"
+                                             CssClasses="col-auto btn-success"
+                                             OnClick="CreateAllocationRange">
+                                    </WButton>
+                                </div>
                             </div>
                             </div>
                         </div>
                         </div>
                         <Table TableItem="NodeAllocation" Items="Node.Allocations" PageSize="25" TableHeadClass="border-bottom border-gray-200 fs-6 text-gray-600 fw-bold bg-light bg-opacity-75">
                         <Table TableItem="NodeAllocation" Items="Node.Allocations" PageSize="25" TableHeadClass="border-bottom border-gray-200 fs-6 text-gray-600 fw-bold bg-light bg-opacity-75">
@@ -142,6 +161,9 @@
 
 
     private int Port = 2000;
     private int Port = 2000;
 
 
+    private int StartPort = 2000;
+    private int EndPort = 3000;
+
     private Task Load(LazyLoader arg)
     private Task Load(LazyLoader arg)
     {
     {
         Node = NodeRepository
         Node = NodeRepository
@@ -183,4 +205,24 @@
 
 
         await LazyLoader.Reload();
         await LazyLoader.Reload();
     }
     }
+    
+    private async Task CreateAllocationRange()
+    {
+        for (int i = StartPort; i < EndPort; i++)
+        {
+            var nodeAllocation = new NodeAllocation()
+            {
+                Port = i
+            };
+
+            Node!.Allocations.Add(nodeAllocation);
+        }
+        
+        NodeRepository.Update(Node);
+
+        StartPort = 2000;
+        EndPort = 3000;
+
+        await LazyLoader.Reload();
+    }
 }
 }

+ 2 - 4
Moonlight/Shared/Views/Servers/Create.razor

@@ -209,10 +209,8 @@
                         disk,
                         disk,
                         User,
                         User,
                         Model.Image,
                         Model.Image,
-                        DeployNode,
-                        null,
-                        Model.Image.Allocations
-                    );
+                        DeployNode
+                        );
                     
                     
                     NavigationManager.NavigateTo($"/server/{server.Uuid}");
                     NavigationManager.NavigateTo($"/server/{server.Uuid}");
                 }
                 }