Implemented functional method to add a new system to a new through web app
This commit is contained in:
@@ -117,6 +117,44 @@ exports.getNodeInfo = async (req, res) => {
|
||||
})
|
||||
}
|
||||
|
||||
/** Adds a specific system/preset on a given node
|
||||
*
|
||||
* @param {*} req Default express req from router
|
||||
* @param {*} res Defualt express res from router
|
||||
* @param {*} req.params.nodeId The Node ID to add the preset/system to
|
||||
* @param {*} req.body.systemName The name of the system to add
|
||||
* @param {*} req.body.mode The radio mode of the preset
|
||||
* @param {*} req.body.frequencies The frequencies of the preset
|
||||
* @param {*} req.body.trunkFile The trunk file to use for digital stations
|
||||
*/
|
||||
exports.addNodeSystem = async (req, res) => {
|
||||
if (!req.params.nodeId) return res.status(400).json("No id specified");
|
||||
if (!req.body.systemName) return res.status(400).json("No system specified");
|
||||
log.DEBUG("Adding system for node: ", req.params.nodeId, req.body);
|
||||
getNodeInfoFromId(req.params.nodeId, (node) => {
|
||||
const reqOptions = new requestOptions("/client/addPreset", "POST", node.ip, node.port);
|
||||
const reqBody = {
|
||||
'systemName': req.body.systemName,
|
||||
'mode': req.body.mode,
|
||||
'frequencies': req.body.frequencies,
|
||||
}
|
||||
if(digitalModes.includes(req.body.mode)) reqBody['trunkFile'] = req.body.trunkFile ?? 'none'
|
||||
|
||||
log.DEBUG("Request body for adding node system: ", reqBody, reqOptions);
|
||||
sendHttpRequest(reqOptions, JSON.stringify(reqBody), async (responseObj) => {
|
||||
if(responseObj){
|
||||
// Good
|
||||
log.DEBUG("Response from adding node system: ", reqBody, responseObj);
|
||||
return res.sendStatus(200)
|
||||
} else {
|
||||
// Bad
|
||||
log.DEBUG("No Response from adding Node system");
|
||||
return res.status(400).json("No Response from adding Node, could be offline");
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/** Updates a specific system/preset on a given node
|
||||
*
|
||||
* @param {*} req Default express req from router
|
||||
@@ -144,11 +182,11 @@ exports.updateNodeSystem = async (req, res) => {
|
||||
sendHttpRequest(reqOptions, JSON.stringify(reqBody), async (responseObj) => {
|
||||
if(responseObj){
|
||||
// Good
|
||||
log.DEBUG("Response from updating node: ", reqBody, responseObj);
|
||||
log.DEBUG("Response from updating node system: ", reqBody, responseObj);
|
||||
return res.sendStatus(200)
|
||||
} else {
|
||||
// Bad
|
||||
log.DEBUG("No Response from updating Node");
|
||||
log.DEBUG("No Response from updating Node system");
|
||||
return res.status(400).json("No Response from updating Node, could be offline");
|
||||
}
|
||||
})
|
||||
|
||||
@@ -185,8 +185,35 @@ function saveNodeDetails() {
|
||||
}
|
||||
}
|
||||
|
||||
function addNewSystem() {
|
||||
function addNewSystem(systemName) {
|
||||
const nodeId = document.getElementById("nodeId").value;
|
||||
const systemMode = document.getElementById(`${systemName}_systemMode`).value;
|
||||
const inputSystemFreqs = $(`[id^="${systemName}_systemFreq_"]`);
|
||||
let systemFreqs = [];
|
||||
for (const inputFreq of inputSystemFreqs){
|
||||
systemFreqs.push(inputFreq.value);
|
||||
}
|
||||
|
||||
const reqBody = {
|
||||
'systemName': systemName,
|
||||
'mode': systemMode,
|
||||
'frequencies': systemFreqs
|
||||
}
|
||||
|
||||
console.log("Request Body: ", reqBody);
|
||||
const Http = new XMLHttpRequest();
|
||||
const url='/nodes/'+nodeId+"/systems";
|
||||
Http.open("POST", url);
|
||||
Http.setRequestHeader("Content-Type", "application/json");
|
||||
Http.send(JSON.stringify(reqBody));
|
||||
|
||||
Http.onloadend = (e) => {
|
||||
const responseObject = JSON.parse(Http.responseText)
|
||||
console.log(Http.status);
|
||||
console.log(responseObject);
|
||||
createToast(`${systemName} Added!`);
|
||||
location.reload();
|
||||
}
|
||||
}
|
||||
|
||||
function updateSystem(systemName) {
|
||||
@@ -216,6 +243,7 @@ function updateSystem(systemName) {
|
||||
console.log(Http.status);
|
||||
console.log(responseObject);
|
||||
createToast(`${systemName} Updated!`);
|
||||
location.reload();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,10 @@ router.get('/:nodeId', nodesController.getNodeInfo);
|
||||
// Update an existing node
|
||||
router.put('/:nodeId', nodesController.updateExistingNode);
|
||||
|
||||
// Update an existing node's system
|
||||
// Add a system to an existing node
|
||||
router.post('/:nodeId/systems', nodesController.addNodeSystem);
|
||||
|
||||
// Update a system on an existing node
|
||||
router.put('/:nodeId/systems', nodesController.updateNodeSystem);
|
||||
|
||||
// TODO Need to authenticate this request
|
||||
|
||||
@@ -113,7 +113,7 @@
|
||||
</td>
|
||||
</tr>
|
||||
<% // Update system modal %>
|
||||
<%- include("partials/modifySystemModal.ejs", {'system': system, 'frequencies': node.nearbySystems[system].frequencies}) %>
|
||||
<%- include("partials/modifySystemModal.ejs", {'system': system, 'frequencies': node.nearbySystems[system].frequencies, 'mode': node.nearbySystems[system].mode}) %>
|
||||
<% } %>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -126,31 +126,14 @@
|
||||
<button class="btn btn-primary <% if(!node.online) { %>disabled<% } %>" type="button" onclick="saveNodeDetails()">Save changes</button>
|
||||
<!-- Button trigger modal -->
|
||||
<button type="button" class="btn btn-primary float-right <% if(!node.online) { %>disabled<% } %>" data-bs-toggle="modal"
|
||||
data-bs-target="#newSystemModal">Add New System</button>
|
||||
data-bs-target="#updateSystemModal_New_System">Add New System</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<% // new System Modal %>
|
||||
<div class="modal fade" id="newSystemModal" tabindex="-1" aria-labelledby="newSystemModal" aria-hidden="true">
|
||||
<div class="modal-dialog modal-dialog-centered">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h1 class="modal-title fs-5" id="newSystemModal">Add a New System</h1>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
...
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
|
||||
<button type="button" class="btn btn-primary">Save changes</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<%- include('partials/joinModal.ejs', {'nearbySystems': node.nearbySystems}) %>
|
||||
<%- include("partials/modifySystemModal.ejs", {'system': "New System", 'frequencies': [], 'mode': ''}) %>
|
||||
<%- include('partials/bodyEnd.ejs') %>
|
||||
<script src="/res/js/node.js"></script>
|
||||
<%- include('partials/htmlFooter.ejs') %>
|
||||
@@ -3,7 +3,7 @@
|
||||
<div class="modal-dialog modal-dialog-centered">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h1 class="modal-title fs-5" id="updateSystemModal_<%=system.replaceAll(" ", "_")%>">Update <%=system%></h1>
|
||||
<h1 class="modal-title fs-5" id="updateSystemModal_<%=system.replaceAll(" ", "_")%>"><%if (!system == "New System") {%>Update<%} else {%>Add a<%}%> <%=system%></h1>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
@@ -12,7 +12,7 @@
|
||||
<form>
|
||||
<div class="row gx-3 mb-3">
|
||||
<label class="small mb-1 fs-6" for="systemName">System Name</label>
|
||||
<input class="form-control" id="systemName" type="text" value="<%= system %>"></input>
|
||||
<input class="form-control" id="systemName" type="text" value="<%if (!system == "New System") {%><%= system %><%} else {%>Local Radio System<%}%>"></input>
|
||||
</div>
|
||||
<div class="row gx-3 mb-3" id="frequencyRow_<%=system.replaceAll(" ", "_")%>">
|
||||
<label class="small mb-1 fs-6" for="systemFreq">Frequencies</label>
|
||||
@@ -36,12 +36,15 @@
|
||||
<label class="small mb-1 fs-6" for="<%=system%>_systemMode">Mode</label>
|
||||
<br>
|
||||
<select class="custom-select" id="<%=system%>_systemMode">
|
||||
<option value="<%= node.nearbySystems[system].mode %>" selected><span class="text-uppercase"><%= node.nearbySystems[system].mode %></span></option>
|
||||
<% if(node.nearbySystems[system].mode == "p25") { %>
|
||||
<option value="<%= mode ?? 'select' %>" selected><span class="text-uppercase"><%= mode ?? 'Select' %></span></option>
|
||||
<% if(mode == "p25") { %>
|
||||
<option value="nbfm">NBFM</option>
|
||||
<% } else if (node.nearbySystems[system].mode == "nbfm") { %>
|
||||
<% } else if (mode == "nbfm") { %>
|
||||
<option value="p25">P25</option>
|
||||
<% } %>
|
||||
<% } else { %>
|
||||
<option value="nbfm">NBFM</option>
|
||||
<option value="p25">P25</option>
|
||||
<%}%>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
@@ -51,7 +54,7 @@
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal" onclick="location.reload()">Close</button>
|
||||
<button type="button" class="btn btn-primary" onclick="updateSystem('<%=system%>')">Save changes</button>
|
||||
<button type="button" class="btn btn-primary" data-bs-dismiss="modal" <%if(!system == "New System") {%>onclick="updateSystem('<%=system%>')"<%} else {%>onclick="addNewSystem('<%=system%>')"<%}%>>Save changes</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user