Skip to content

Commit

Permalink
add module list to server page
Browse files Browse the repository at this point in the history
  • Loading branch information
burdoto committed Dec 23, 2023
1 parent cfe9c3e commit 0dfcfce
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public void playerEvent(
}

@ResponseBody
@GetMapping("/module/state/{id}")
@GetMapping("/webapp/module/state/{id}")
public boolean moduleState(
@Autowired HttpSession session,
@PathVariable UUID id,
Expand All @@ -225,7 +225,7 @@ public boolean moduleState(
@Nullable @RequestParam(value = "fullReload", required = false) Boolean fullReload
) {
// check request validity; set and toggle must not both be present
new Constraint.API(() -> set != null && toggle != null)
new Constraint.API(() -> !(set != null && toggle != null))
.setConstraint("request validity")
.setNameof("set and toggle param")
.setShouldBe("not both present")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ public String entityEdit(HttpSession session, Model model,
.or(authorizationLinkRepo.validate(user, id, code, AbstractEntity.Permission.Modify).cast())
.orElseThrow(() -> new InsufficientPermissionsException(user, id, AbstractEntity.Permission.Modify));
var target = core.findEntity(type, id);
if (target instanceof Server)
model.addAttribute("modules", Streams.of(mcsd.getModules().findAllByServerId(target.getId())).toList());
model.addAttribute("user", user)
.addAttribute("edit", true)
.addAttribute("editKey", null)
Expand Down
4 changes: 4 additions & 0 deletions src/hub/main/resources/static/common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
function confirmAction(what, warn, action) {
if (window.confirm("Are you sure you want to "+what+"? "+warn+"!"))
action();
}
23 changes: 23 additions & 0 deletions src/hub/main/resources/static/modules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
function load() {
document.querySelectorAll('.state-switch').forEach(checkbox => checkbox.addEventListener('click', switchModuleState))
}

function unload() {
}

function addModule() {
}

function switchModuleState(event) {
var id = event.target.id.substring('state_'.length);
fetch('/api/webapp/module/state/'+id+'?toggle=true')
.then(rsp => rsp.json())
.then(state => document.querySelector('#state_'+id).checked = state)
.catch(console.error);
}

function reload(full) {
let id = document.querySelector('[name=id]').value;
fetch('/api/webapp/module/state/'+id+'?fullReload='+full)
.catch(console.error);
}
6 changes: 4 additions & 2 deletions src/hub/main/resources/templates/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ <h2>Servers</h2>
<td th:text="${server.getHost()}">Host</td>
<td>:</td>
<td th:text="${server.getPort()}">Port</td>
<td><a class="ui-button" th:href="@{'/server/edit/'+${server.id}}">Edit</a>
<a class="ui-button" th:href="@{'/server/delete/'+${server.id}}">Delete</a></td>
<td>
<a class="ui-button" th:href="@{'/server/edit/'+${server.id}}">Edit</a>
<a class="ui-button" th:href="@{'/server/delete/'+${server.id}}">Delete</a>
</td>
</tr></tbody>
</table>
</div>
Expand Down
75 changes: 24 additions & 51 deletions src/hub/main/resources/templates/server/view.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
<!--suppress HtmlFormInputWithoutLabel -->
<html xmlns:th="http://www.thymeleaf.org">
<head th:insert="~{/head}"></head>
<body onbeforeunload="unload()" onload="load()">
<script type="text/javascript" th:src="@{/static/modules.js}"></script>
<script type="text/javascript" th:src="@{/static/common.js}"></script>
<body onload="load()" onbeforeunload="unload()">
<div class="ui-menubar" th:insert="~{/menubar}"></div>
<div class="ui-container-page">
<div class="ui-content">
Expand Down Expand Up @@ -85,59 +87,30 @@ <h3>Advanced configuration</h3>
th:value="${target.queryPort}"
type="number"></td>
</tr>
<tr>
<td>Rcon Port</td>
<td><input max="65535" min="1" name="rConPort" th:readonly="${!edit}" th:value="${target.RConPort}"
type="number"></td>
</tr>
<tr>
<td>Rcon Password</td>
<td><input name="rConPassword"
th:readonly="${!edit}"
th:value="${edit?'':(target.getRConPassword()!=null?'hidden':'rcon disabled')}"
type="password"></td>
</tr>
</tbody>
</table>
<h3>Discord Integration</h3>
<h5 class="error-text" th:unless="${target.getDiscordBot() != null}">Not configured</h5>
<table th:if="${target.getDiscordBot() != null}">
<tbody>
<tr>
<td>Bot</td>
<td><input name="discordBot" th:readonly="${!edit}"
th:value="${edit?target.discordBot.id:target.discordBot.bestName}"
type="text"></td>
</tr>
<tr>
<td>Public Channel ID</td>
<td><input name="publicChannelId" th:readonly="${!edit}" th:value="${target.publicChannelId}"
type="number"></td>
</tr>
<tr>
<td>Moderation Channel ID</td>
<td><input name="moderationChannelId" th:readonly="${!edit}"
th:value="${target.moderationChannelId}"
type="number"></td>
</tr>
<tr>
<td>Console Channel ID</td>
<td><input name="consoleChannelId" th:readonly="${!edit}" th:value="${target.consoleChannelId}"
type="number"></td>
</tr>
<tr>
<td>Console Prefix</td>
<td><input name="consoleChannelPrefix" th:readonly="${!edit}"
th:value="${target.consoleChannelPrefix}"
type="text"></td>
</tr>
<tr>
<td>Fancier Console</td>
<td><input name="fancyConsole" th:readonly="${!edit}" th:value="${target.fancyConsole}"
type="checkbox">
<h3>Modules</h3>
<table>
<thead><tr>
<th><button class="ui-button" onclick="addModule()">Add</button></th>
<th>Name</th>
<th>Description</th>
<th>
<!-- todo: both of these cause NS_BINDING_ABORTED errors for some reason
<button onclick="reload(false)">Refresh Config</button>
<button onclick="confirmAction('do a full reload', 'This will restart the server', ()=>reload(true))">Full Reload</button>
-->
</th>
</tr></thead>
<tbody><tr th:each="module: ${modules}">
<td><input th:id="'state_'+${module.id}" class="state-switch" type="checkbox" th:checked="${module.enabled}"></td>
<td th:text="${module.dtype.name}"></td>
<td th:text="${module.dtype.description}"></td>
<td>
<a class="ui-button" th:href="@{'/module/edit/'+${module.id}}">Edit</a>
<a class="ui-button" th:href="@{'/module/delete/'+${module.id}}">Delete</a>
</td>
</tr>
</tbody>
</tr></tbody>
</table>
<input th:if="${editKey!=null}" type="hidden" name="auth_key" th:value="${editKey}">
<input th:if="${edit}" type="submit" value="Apply">
Expand Down

0 comments on commit 0dfcfce

Please sign in to comment.