organized files
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>services</title>
|
||||
<link rel="stylesheet" type="text/css" href="../style.css">
|
||||
<script src="services.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Services</h1>
|
||||
<br>
|
||||
<a href="#add" class="bookmark">Want to add a new line?</a>
|
||||
<br>
|
||||
<br>
|
||||
<table class="queryresults">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Name</th>
|
||||
<th colspan="2">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="resultarea">
|
||||
</tbody>
|
||||
</table>
|
||||
<h2 id="add">Add a new line</h2>
|
||||
<table class="inputs">
|
||||
<tr>
|
||||
<td>ID</td>
|
||||
<td class="inputcell"><input type="text" id="in_id"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Maintainer</td>
|
||||
<td class="inputcell"><input type="text" id="in_maintainer_id"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Name</td>
|
||||
<td class="inputcell"><input type="text" id="in_name"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Version</td>
|
||||
<td class="inputcell"><input type="text" id="in_version"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Account</td>
|
||||
<td class="inputcell"><input type="text" id="in_account"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Notes</td>
|
||||
<td class="inputcell"><input type="text" id="in_notes"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Service domain</td>
|
||||
<td class="inputcell"><input type="text" id="in_domain"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>IP</td>
|
||||
<td class="inputcell"><input type="text" id="in_ip"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Port</td>
|
||||
<td class="inputcell"><input type="text" id="in_port"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2"><button onclick="addService()">Save</button></td>
|
||||
</tr>
|
||||
</table>
|
||||
<div id="addresult"></div>
|
||||
</body>
|
||||
</html>
|
||||
128
WD7UVN_SzTGUI_2023242.Client.JS/wwwroot/services/services.js
Normal file
128
WD7UVN_SzTGUI_2023242.Client.JS/wwwroot/services/services.js
Normal file
@@ -0,0 +1,128 @@
|
||||
let services = [];
|
||||
getServices();
|
||||
|
||||
async function getServices()
|
||||
{
|
||||
await fetch('https://localhost:5001/api/Service')
|
||||
.then(x => x.json())
|
||||
.then(y => {
|
||||
services = y;
|
||||
console.log(services);
|
||||
display();
|
||||
});
|
||||
}
|
||||
|
||||
function display()
|
||||
{
|
||||
document.getElementById('resultarea').innerHTML = '';
|
||||
|
||||
services.forEach(t => {
|
||||
document.getElementById('resultarea').innerHTML +=
|
||||
'<tr><td>'
|
||||
+ t.id +
|
||||
'</td><td>'
|
||||
+ t.name +
|
||||
'</td><td>'
|
||||
+ '<button type="button" onclick="deleteService(' + t.id + ')">Delete</button>'
|
||||
+ '</td><td>'
|
||||
+ '<button type="button" onclick="updateService(' + t.id + ')">Edit</button>'
|
||||
+ '</td></tr>';
|
||||
});
|
||||
|
||||
document.getElementById('resultarea').innerHTML +=
|
||||
'<tr>' +
|
||||
'<td colspan="4">' +
|
||||
'<a class="bookmark" href="#add">Add new</a>' +
|
||||
'</td>' +
|
||||
'</tr>';
|
||||
}
|
||||
|
||||
function updateService(id)
|
||||
{
|
||||
let service_id = document.getElementById('in_id').value;
|
||||
let service_maintainer_id = document.getElementById('in_maintainer_id').value;
|
||||
let service_name = document.getElementById('in_name').value;
|
||||
let service_version = document.getElementById('in_version').value;
|
||||
let service_account = document.getElementById('in_account').value;
|
||||
let service_notes = document.getElementById('in_notes').value;
|
||||
let service_domain = document.getElementById('in_domain').value;
|
||||
let service_ip = document.getElementById('in_ip').value;
|
||||
let service_port = document.getElementById('in_port').value;
|
||||
|
||||
fetch ('https://localhost:5001/api/Service/' + id, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
id: service_id,
|
||||
maintainer_id: service_maintainer_id,
|
||||
name: service_name,
|
||||
version: service_version,
|
||||
account: service_account,
|
||||
notes: service_notes,
|
||||
service_domain: service_domain,
|
||||
ip: service_ip,
|
||||
port: service_port
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function addService()
|
||||
{
|
||||
let service_id = document.getElementById('in_id').value;
|
||||
let service_maintainer_id = document.getElementById('in_maintainer_id').value;
|
||||
let service_name = document.getElementById('in_name').value;
|
||||
let service_version = document.getElementById('in_version').value;
|
||||
let service_account = document.getElementById('in_account').value;
|
||||
let service_notes = document.getElementById('in_notes').value;
|
||||
let service_domain = document.getElementById('in_domain').value;
|
||||
let service_ip = document.getElementById('in_ip').value;
|
||||
let service_port = document.getElementById('in_port').value;
|
||||
|
||||
fetch('https://localhost:5001/api/Service', {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
id: service_id,
|
||||
maintainer_id: service_maintainer_id,
|
||||
name: service_name,
|
||||
version: service_version,
|
||||
account: service_account,
|
||||
notes: service_notes,
|
||||
service_domain: service_domain,
|
||||
ip: service_ip,
|
||||
port: service_port
|
||||
})
|
||||
})
|
||||
.then(response => response)
|
||||
.then(data => {
|
||||
console.log("Success: ", data)
|
||||
|
||||
document.getElementById('addresult').innerHTML = '';
|
||||
document.getElementById('addresult').innerHTML +=
|
||||
'<h2>Added service ' + service_name + ' successfully</h2>';
|
||||
|
||||
getServices();
|
||||
})
|
||||
.catch(error => {
|
||||
console.error("Error: ", error);
|
||||
|
||||
document.getElementById('addresult').innerHTML = '';
|
||||
document.getElementById('addresult').innerHTML +=
|
||||
'<h2>Failed to add service ' + service_name + '</h2>';
|
||||
});
|
||||
}
|
||||
|
||||
function deleteService(id)
|
||||
{
|
||||
fetch('https://localhost:5001/api/Service/' + id, {
|
||||
method: 'DELETE',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
})
|
||||
.then(response => response)
|
||||
.then(data =>
|
||||
{
|
||||
console.log("Success: ", data)
|
||||
getServices();
|
||||
})
|
||||
.catch(error => console.error("Error: ", error));
|
||||
}
|
||||
Reference in New Issue
Block a user