Improved UI a bit.

This commit is contained in:
Andrew Lalis 2021-11-25 11:58:09 +01:00
parent fd2cf357dd
commit e7274cb6d0
2 changed files with 51 additions and 33 deletions

View File

@ -145,8 +145,8 @@ function railSystemChanged() {
});
}
// Updates the current rail system's information from the API.
function railSystemUpdated() {
console.log("Refreshing...");
$.get("/api/railSystems/" + railSystem.id + "/signals")
.done(signals => {
railSystem.signals = signals;
@ -280,11 +280,12 @@ function addNewSignal() {
data: JSON.stringify(data),
contentType: "application/json"
})
.done((response) => {
.done(() => {
form.trigger("reset");
railSystemChanged();
railSystemUpdated();
})
.fail((response) => {
console.error(response);
$('#addSignalAlertsContainer').append($('<div class="alert alert-danger">An error occurred.</div>'));
modal.show();
});
@ -295,6 +296,22 @@ function addNewSignal() {
});
}
function removeSignal(signalId) {
confirm(`Are you sure you want to remove signal ${signalId}? This cannot be undone.`)
.then(() => {
$.ajax({
url: `/api/railSystems/${railSystem.id}/signals/${signalId}`,
type: "DELETE"
})
.always(() => {
railSystemUpdated();
})
.fail((response) => {
console.error(response);
})
})
}
function removeReachableConnection(signalId, fromId, toId) {
confirm(`Are you sure you want to remove the connection from ${fromId} to ${toId} from signal ${signalId}?`)
.then(() => {
@ -312,8 +329,8 @@ function removeReachableConnection(signalId, fromId, toId) {
data: JSON.stringify({connections: connections}),
contentType: "application/json"
})
.done((response) => {
railSystemChanged();
.done(() => {
railSystemUpdated();
})
.fail((response) => {
console.error(response);
@ -348,7 +365,7 @@ function addReachableConnection(signalId, fromId, toId) {
data: JSON.stringify({connections: connections}),
contentType: "application/json"
})
.done((response) => {
.done(() => {
railSystemChanged();
})
.fail((response) => {

View File

@ -34,6 +34,12 @@
</div>
</div>
<div class="row">
<div class="col">
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addSignalModal">Add Signal</button>
</div>
</div>
<hr class="my-4"/>
<div class="row">
@ -43,14 +49,6 @@
<div id="railMapDetailPanel" class="col p-2 border">
</div>
</div>
<hr class="my-4"/>
<div class="row">
<div class="col">
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addSignalModal">Add Signal</button>
</div>
</div>
</div>
<div>
@ -69,25 +67,23 @@
<hr>
{{#each branchConnections}}
<h5>{{this.direction}} <small class="text-muted">{{this.id}}</small></h5>
<dl class="row">
<dt class="col-sm-3">Branch</dt>
<dd class="col-sm-9">{{this.branch.name}} <small class="text-muted">{{this.branch.id}}</small></dd>
<dt class="col-sm-3">Reachable Signals</dt>
<dd class="col-sm-9">
{{#each this.reachableSignalConnections}}
<p>
<a onclick="selectSignalById({{this.signalId}})" href="#">{{this.signalName}}</a>
<small class="text-muted">{{this.signalId}}</small> via
{{this.direction}} connection {{this.connectionId}}
<span
class="btn btn-sm btn-danger js_removeSignalConnection"
onclick="removeReachableConnection({{../../id}}, {{../id}}, {{this.connectionId}})"
>Remove</span>
</p>
{{/each}}
</dd>
</dl>
<h5>{{this.direction}} <small class="text-muted">ID: {{this.id}}</small></h5>
<p>
On branch <span class="badge bg-dark">{{this.branch.name}} <small class="text-muted">ID: {{this.branch.id}}</small></span>
</p>
<h6>Connected to Signals:</h6>
<ul class="list-unstyled">
{{#each this.reachableSignalConnections}}
<li>
<a onclick="selectSignalById({{this.signalId}})" href="#">{{this.signalName}}</a>
via {{this.direction}} <small class="text-muted">ID: {{this.connectionId}}</small>
<span
class="btn btn-sm btn-secondary js_removeSignalConnection"
onclick="removeReachableConnection({{../../id}}, {{../id}}, {{this.connectionId}})"
>Remove</span>
</li>
{{/each}}
</ul>
<div class="row" id="signalPotentialConnectionsRow-{{this.id}}">
<div class="col-auto">
<select id="signalPotentialConnectionsSelect-{{this.id}}" class="form-select form-select-sm">
@ -101,6 +97,11 @@
</div>
</div>
{{/each}}
<div class="row">
<div class="col">
<button type="button" class="btn btn-secondary" onclick="removeSignal({{id}})">Remove this Signal</button>
</div>
</div>
</script>
<div class="modal fade" tabindex="-1" id="confirmModal" aria-hidden="true" data-bs-backdrop="static" data-bs-keyboard="false">