Skip to content

Commit a379185

Browse files
feat: Add map rotation assignments and display in Manage Maps view
1 parent de2fc43 commit a379185

3 files changed

Lines changed: 137 additions & 1 deletion

File tree

src/XtremeIdiots.Portal.Web/Controllers/MapManagerController.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using XtremeIdiots.Portal.Integrations.Servers.Api.Client.V1;
66
using XtremeIdiots.Portal.Repository.Abstractions.Constants.V1;
7+
using XtremeIdiots.Portal.Repository.Abstractions.Models.V1.MapRotations;
78
using XtremeIdiots.Portal.Repository.Api.Client.V1;
89
using XtremeIdiots.Portal.Web.Auth.Constants;
910
using XtremeIdiots.Portal.Web.Extensions;
@@ -57,11 +58,34 @@ public async Task<IActionResult> Manage(Guid id, CancellationToken cancellationT
5758
getServerMapsResult.Result?.Data?.Items?.Select(m => m.MapName).ToArray(),
5859
null, null, 0, 50, MapsOrder.MapNameAsc).ConfigureAwait(false);
5960

61+
// Fetch rotation assignments for this server
62+
var assignmentsResponse = await repositoryApiClient.MapRotations.V1.GetServerAssignments(
63+
null, id, null, 0, 20, cancellationToken).ConfigureAwait(false);
64+
65+
var assignments = assignmentsResponse.IsSuccess && assignmentsResponse.Result?.Data?.Items != null
66+
? assignmentsResponse.Result.Data.Items
67+
.Where(a => a.DeploymentState != DeploymentState.Removed)
68+
.ToList()
69+
: [];
70+
71+
var rotations = new Dictionary<Guid, MapRotationDto>();
72+
foreach (var assignment in assignments)
73+
{
74+
if (!rotations.ContainsKey(assignment.MapRotationId))
75+
{
76+
var rotationResponse = await repositoryApiClient.MapRotations.V1.GetMapRotation(assignment.MapRotationId, cancellationToken).ConfigureAwait(false);
77+
if (rotationResponse.IsSuccess && rotationResponse.Result?.Data != null)
78+
rotations[assignment.MapRotationId] = rotationResponse.Result.Data;
79+
}
80+
}
81+
6082
var viewModel = new ManageMapsViewModel(gameServerData)
6183
{
6284
Maps = mapsCollectionApiResponse.Result?.Data?.Items?.ToList() ?? [],
6385
ServerMaps = getLoadedServerMapsFromHostResult.Result?.Data?.Items?.ToList() ?? [],
64-
RconMaps = getServerMapsResult.Result?.Data?.Items?.ToList() ?? []
86+
RconMaps = getServerMapsResult.Result?.Data?.Items?.ToList() ?? [],
87+
RotationAssignments = assignments,
88+
Rotations = rotations
6589
};
6690

6791
return View(viewModel);

src/XtremeIdiots.Portal.Web/ViewModels/ManageMapsViewModel.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using XtremeIdiots.Portal.Integrations.Servers.Abstractions.Models.V1.Maps;
22
using XtremeIdiots.Portal.Integrations.Servers.Abstractions.Models.V1.Rcon;
33
using XtremeIdiots.Portal.Repository.Abstractions.Models.V1.GameServers;
4+
using XtremeIdiots.Portal.Repository.Abstractions.Models.V1.MapRotations;
45
using XtremeIdiots.Portal.Repository.Abstractions.Models.V1.Maps;
56

67
namespace XtremeIdiots.Portal.Web.ViewModels;
@@ -11,4 +12,6 @@ public class ManageMapsViewModel(GameServerDto gameServer)
1112
public List<MapDto> Maps { get; set; } = [];
1213
public List<ServerMapDto> ServerMaps { get; set; } = [];
1314
public List<RconMapDto> RconMaps { get; set; } = [];
15+
public List<MapRotationServerAssignmentDto> RotationAssignments { get; set; } = [];
16+
public Dictionary<Guid, MapRotationDto> Rotations { get; set; } = [];
1417
}

src/XtremeIdiots.Portal.Web/Views/MapManager/Manage.cshtml

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@using XtremeIdiots.Portal.Web.Extensions
22
@using XtremeIdiots.Portal.Web.ViewModels
3+
@using XtremeIdiots.Portal.Repository.Abstractions.Constants.V1
34
@model ManageMapsViewModel
45

56
@{
@@ -78,6 +79,114 @@
7879
<partial name="PushMapToRemotePartial"
7980
model="@(new PushMapToRemoteViewModel(Model.GameServer.GameServerId))"></partial>
8081

82+
<div class="ibox">
83+
<div class="ibox-title">
84+
<h5>Map Rotations (@Model.RotationAssignments.Count)</h5>
85+
<div class="ibox-tools">
86+
<a asp-controller="MapRotations" asp-action="Index" asp-route-gameType="@Model.GameServer.GameType" class="btn btn-outline-secondary btn-sm me-1">
87+
<i class="fa-solid fa-fw fa-list"></i> All Rotations
88+
</a>
89+
</div>
90+
</div>
91+
92+
<div class="ibox-content">
93+
@if (Model.RotationAssignments.Count == 0)
94+
{
95+
<div class="text-center text-muted py-3">
96+
<i class="fa-solid fa-rotate fa-2x mb-2 d-block"></i>
97+
<p>No map rotations assigned to this server.</p>
98+
<a asp-controller="MapRotations" asp-action="Index" asp-route-gameType="@Model.GameServer.GameType" class="btn btn-outline-primary btn-sm">
99+
<i class="fa-solid fa-fw fa-plus"></i> Manage Rotations
100+
</a>
101+
</div>
102+
}
103+
else
104+
{
105+
<div class="table-responsive">
106+
<table class="table table-striped table-hover mb-0">
107+
<thead>
108+
<tr>
109+
<th>Rotation</th>
110+
<th style="width: 80px;">Mode</th>
111+
<th style="width: 90px;">Deploy</th>
112+
<th style="width: 90px;">Active</th>
113+
<th style="width: 80px;"></th>
114+
</tr>
115+
</thead>
116+
<tbody>
117+
@foreach (var assignment in Model.RotationAssignments)
118+
{
119+
Model.Rotations.TryGetValue(assignment.MapRotationId, out var rotation);
120+
<tr>
121+
<td>
122+
<a asp-controller="MapRotations" asp-action="Details" asp-route-id="@assignment.MapRotationId">
123+
<strong>@(rotation?.Title ?? "Unknown")</strong>
124+
</a>
125+
<br />
126+
<small class="text-muted">
127+
<code>@assignment.ConfigVariableName</code>
128+
@if (rotation?.MapRotationMaps != null)
129+
{
130+
<span@rotation.MapRotationMaps.Count maps</span>
131+
}
132+
</small>
133+
</td>
134+
<td><span class="badge bg-info">@(rotation?.GameMode ?? "")</span></td>
135+
<td>
136+
@switch (assignment.DeploymentState)
137+
{
138+
case DeploymentState.Pending:
139+
<span class="badge bg-warning text-dark">Pending</span>
140+
break;
141+
case DeploymentState.Syncing:
142+
<span class="badge bg-info">Syncing</span>
143+
break;
144+
case DeploymentState.Synced:
145+
<span class="badge bg-success">Synced</span>
146+
break;
147+
case DeploymentState.Failed:
148+
<span class="badge bg-danger">Failed</span>
149+
break;
150+
default:
151+
<span class="badge bg-secondary">@assignment.DeploymentState</span>
152+
break;
153+
}
154+
</td>
155+
<td>
156+
@switch (assignment.ActivationState)
157+
{
158+
case ActivationState.Active:
159+
<span class="badge bg-success">Active</span>
160+
break;
161+
case ActivationState.Activating:
162+
<span class="badge bg-info">Activating</span>
163+
break;
164+
case ActivationState.Inactive:
165+
<span class="badge bg-secondary">Inactive</span>
166+
break;
167+
case ActivationState.Failed:
168+
<span class="badge bg-danger">Failed</span>
169+
break;
170+
default:
171+
<span class="badge bg-secondary">@assignment.ActivationState</span>
172+
break;
173+
}
174+
</td>
175+
<td>
176+
<a asp-controller="MapRotations" asp-action="AssignmentStatus" asp-route-id="@assignment.MapRotationServerAssignmentId"
177+
class="btn btn-outline-secondary btn-xs" title="View Status">
178+
<i class="fa-solid fa-fw fa-eye"></i>
179+
</a>
180+
</td>
181+
</tr>
182+
}
183+
</tbody>
184+
</table>
185+
</div>
186+
}
187+
</div>
188+
</div>
189+
81190
</div>
82191

83192
<div class="col-sm-6">

0 commit comments

Comments
 (0)