ResMan: active/cancelled tables, status field, docker setup
This commit is contained in:
parent
766894bd74
commit
264e7e3ba9
@ -1,171 +1,204 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>ResMan</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<meta charset="UTF-8">
|
||||
<title>ResMan</title>
|
||||
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
|
||||
</head>
|
||||
<body class="bg-light">
|
||||
|
||||
<div class="container mt-4">
|
||||
<h2 class="mb-4">Resource Manager</h2>
|
||||
|
||||
<button class="btn btn-primary mb-3" onclick="openModal()">Neue Ressource</button>
|
||||
<h2 class="mb-4">Resource Manager</h2>
|
||||
|
||||
<button class="btn btn-primary mb-3" onclick="openModal()">Neue Ressource</button>
|
||||
|
||||
<h4>Aktive Ressourcen</h4>
|
||||
|
||||
<table class="table table-bordered table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Produkt</th>
|
||||
<th>Provider</th>
|
||||
<th>CPU</th>
|
||||
<th>RAM</th>
|
||||
<th>Disk</th>
|
||||
<th>Status</th>
|
||||
<th>Aktionen</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="resourceTable"></tbody>
|
||||
</table>
|
||||
|
||||
|
||||
<h4 class="mt-5">Gekündigte Ressourcen</h4>
|
||||
|
||||
<table class="table table-bordered table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Produkt</th>
|
||||
<th>Provider</th>
|
||||
<th>CPU</th>
|
||||
<th>RAM</th>
|
||||
<th>Disk</th>
|
||||
<th>Status</th>
|
||||
<th>Aktionen</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="cancelledTable"></tbody>
|
||||
</table>
|
||||
|
||||
<table class="table table-bordered table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Produkt</th>
|
||||
<th>Provider</th>
|
||||
<th>CPU</th>
|
||||
<th>RAM</th>
|
||||
<th>Disk</th>
|
||||
<th>Status</th>
|
||||
<th>Aktionen</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="resourceTable"></tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- Modal -->
|
||||
<div class="modal fade" id="resourceModal" tabindex="-1">
|
||||
<div class="modal-dialog modal-xl">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">Ressource</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<input type="hidden" id="resourceId">
|
||||
<div class="modal-dialog modal-xl">
|
||||
<div class="modal-content">
|
||||
|
||||
<div class="row g-3">
|
||||
|
||||
<div class="col-md-4">
|
||||
<label class="form-label">Name</label>
|
||||
<input type="text" class="form-control" id="name">
|
||||
</div>
|
||||
|
||||
<div class="col-md-4">
|
||||
<label class="form-label">Produkt</label>
|
||||
<input type="text" class="form-control" id="produkt">
|
||||
</div>
|
||||
|
||||
<div class="col-md-4">
|
||||
<label class="form-label">Provider</label>
|
||||
<input type="text" class="form-control" id="provider">
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">Art</label>
|
||||
<input type="text" class="form-control" id="art">
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">CPU</label>
|
||||
<input type="text" class="form-control" id="cpu">
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">RAM</label>
|
||||
<input type="text" class="form-control" id="ram">
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">Disk</label>
|
||||
<input type="text" class="form-control" id="disk">
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">OS</label>
|
||||
<input type="text" class="form-control" id="os">
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">IPv4</label>
|
||||
<input type="text" class="form-control" id="ipv4_adresse">
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">VLAN IP 1</label>
|
||||
<input type="text" class="form-control" id="vlan_ip1">
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">VLAN IP 2</label>
|
||||
<input type="text" class="form-control" id="vlan_ip2">
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">IPv6 Netz</label>
|
||||
<input type="text" class="form-control" id="ipv6_net">
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">IPv6 Adresse</label>
|
||||
<input type="text" class="form-control" id="ipv6_adresse">
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">Provider Name</label>
|
||||
<input type="text" class="form-control" id="providername">
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">Kosten / Monat</label>
|
||||
<input type="number" step="0.01" class="form-control" id="kosten_monat">
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">Kosten / Jahr</label>
|
||||
<input type="number" step="0.01" class="form-control" id="kosten_jahr">
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">Laufzeit (Monate)</label>
|
||||
<input type="number" class="form-control" id="laufzeit_monate">
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">Bestelldatum</label>
|
||||
<input type="date" class="form-control" id="bestelldatum">
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">Kündbar ab</label>
|
||||
<input type="date" class="form-control" id="kuendbar_ab">
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">Kündigungsdatum</label>
|
||||
<input type="date" class="form-control" id="kuendigungsdatum">
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">Status</label>
|
||||
<select class="form-select" id="status">
|
||||
<option value="aktiv">Aktiv</option>
|
||||
<option value="gekündigt">Gekündigt</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="col-12">
|
||||
<label class="form-label">Bemerkung</label>
|
||||
<textarea class="form-control" id="bemerkung"></textarea>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button class="btn btn-success" type="button" onclick="saveResource()">Speichern</button>
|
||||
<button class="btn btn-secondary" data-bs-dismiss="modal">Abbrechen</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">Ressource</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
|
||||
<div class="modal-body">
|
||||
|
||||
<input type="hidden" id="resourceId">
|
||||
|
||||
<div class="row g-3">
|
||||
|
||||
<div class="col-md-4">
|
||||
<label class="form-label">Name</label>
|
||||
<input type="text" class="form-control" id="name">
|
||||
</div>
|
||||
|
||||
<div class="col-md-4">
|
||||
<label class="form-label">Produkt</label>
|
||||
<input type="text" class="form-control" id="produkt">
|
||||
</div>
|
||||
|
||||
<div class="col-md-4">
|
||||
<label class="form-label">Provider</label>
|
||||
<input type="text" class="form-control" id="provider">
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">Art</label>
|
||||
<input type="text" class="form-control" id="art">
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">CPU</label>
|
||||
<input type="text" class="form-control" id="cpu">
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">RAM</label>
|
||||
<input type="text" class="form-control" id="ram">
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">Disk</label>
|
||||
<input type="text" class="form-control" id="disk">
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">OS</label>
|
||||
<input type="text" class="form-control" id="os">
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">IPv4</label>
|
||||
<input type="text" class="form-control" id="ipv4_adresse">
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">VLAN IP 1</label>
|
||||
<input type="text" class="form-control" id="vlan_ip1">
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">VLAN IP 2</label>
|
||||
<input type="text" class="form-control" id="vlan_ip2">
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">IPv6 Netz</label>
|
||||
<input type="text" class="form-control" id="ipv6_net">
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">IPv6 Adresse</label>
|
||||
<input type="text" class="form-control" id="ipv6_adresse">
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">Provider Name</label>
|
||||
<input type="text" class="form-control" id="providername">
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">Kosten / Monat</label>
|
||||
<input type="number" step="0.01" class="form-control" id="kosten_monat">
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">Kosten / Jahr</label>
|
||||
<input type="number" step="0.01" class="form-control" id="kosten_jahr">
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">Laufzeit (Monate)</label>
|
||||
<input type="number" class="form-control" id="laufzeit_monate">
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">Bestelldatum</label>
|
||||
<input type="date" class="form-control" id="bestelldatum">
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">Kündbar ab</label>
|
||||
<input type="date" class="form-control" id="kuendbar_ab">
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">Kündigungsdatum</label>
|
||||
<input type="date" class="form-control" id="kuendigungsdatum">
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">Status</label>
|
||||
<select class="form-select" id="status">
|
||||
<option value="aktiv">Aktiv</option>
|
||||
<option value="gekündigt">Gekündigt</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="col-12">
|
||||
<label class="form-label">Bemerkung</label>
|
||||
<textarea class="form-control" id="bemerkung"></textarea>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="modal-footer">
|
||||
<button class="btn btn-success" onclick="saveResource()">Speichern</button>
|
||||
<button class="btn btn-secondary" data-bs-dismiss="modal">Abbrechen</button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<script>
|
||||
|
||||
const API = "/resman/api/resources";
|
||||
|
||||
const fields = [
|
||||
@ -178,98 +211,157 @@ const fields = [
|
||||
"kuendigungsdatum","status","bemerkung"
|
||||
];
|
||||
|
||||
function getStatusBadge(r) {
|
||||
if (r.status === "gekündigt") {
|
||||
return '<span class="badge bg-dark">Gekündigt</span>';
|
||||
}
|
||||
return '<span class="badge bg-success">Aktiv</span>';
|
||||
|
||||
function getStatusBadge(r){
|
||||
|
||||
if(r.status === "gekündigt"){
|
||||
return '<span class="badge bg-dark">Gekündigt</span>';
|
||||
}
|
||||
|
||||
async function loadResources() {
|
||||
const res = await fetch(API);
|
||||
const data = await res.json();
|
||||
return '<span class="badge bg-success">Aktiv</span>';
|
||||
|
||||
const table = document.getElementById("resourceTable");
|
||||
table.innerHTML = "";
|
||||
|
||||
data.forEach(r => {
|
||||
table.innerHTML += `
|
||||
<tr>
|
||||
<td>${r.name || ""}</td>
|
||||
<td>${r.produkt || ""}</td>
|
||||
<td>${r.provider || ""}</td>
|
||||
<td>${r.cpu || ""}</td>
|
||||
<td>${r.ram || ""}</td>
|
||||
<td>${r.disk || ""}</td>
|
||||
<td>${getStatusBadge(r)}</td>
|
||||
<td>
|
||||
<button class="btn btn-sm btn-warning" onclick='editResource(${JSON.stringify(r)})'>Edit</button>
|
||||
<button class="btn btn-sm btn-info" onclick='copyResource(${JSON.stringify(r)})'>Copy</button>
|
||||
<button class="btn btn-sm btn-danger" onclick="deleteResource(${r.id})">Delete</button>
|
||||
</td>
|
||||
</tr>
|
||||
`;
|
||||
});
|
||||
}
|
||||
|
||||
function openModal() {
|
||||
document.getElementById("resourceId").value = "";
|
||||
fields.forEach(f => {
|
||||
const el = document.getElementById(f);
|
||||
if (el) el.value = "";
|
||||
});
|
||||
new bootstrap.Modal(document.getElementById("resourceModal")).show();
|
||||
|
||||
function createRow(r){
|
||||
|
||||
return `
|
||||
<tr>
|
||||
<td>${r.name || ""}</td>
|
||||
<td>${r.produkt || ""}</td>
|
||||
<td>${r.provider || ""}</td>
|
||||
<td>${r.cpu || ""}</td>
|
||||
<td>${r.ram || ""}</td>
|
||||
<td>${r.disk || ""}</td>
|
||||
<td>${getStatusBadge(r)}</td>
|
||||
<td>
|
||||
|
||||
<button class="btn btn-sm btn-warning" onclick='editResource(${JSON.stringify(r)})'>Edit</button>
|
||||
|
||||
<button class="btn btn-sm btn-info" onclick='copyResource(${JSON.stringify(r)})'>Copy</button>
|
||||
|
||||
<button class="btn btn-sm btn-danger" onclick="deleteResource(${r.id})">Delete</button>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
`;
|
||||
|
||||
}
|
||||
|
||||
function editResource(r) {
|
||||
document.getElementById("resourceId").value = r.id;
|
||||
fields.forEach(f => {
|
||||
const el = document.getElementById(f);
|
||||
if (el) el.value = r[f] || "";
|
||||
});
|
||||
new bootstrap.Modal(document.getElementById("resourceModal")).show();
|
||||
|
||||
async function loadResources(){
|
||||
|
||||
const activeRes = await fetch(API + "/active");
|
||||
const activeData = await activeRes.json();
|
||||
|
||||
const cancelledRes = await fetch(API + "/cancelled");
|
||||
const cancelledData = await cancelledRes.json();
|
||||
|
||||
const activeTable = document.getElementById("resourceTable");
|
||||
const cancelledTable = document.getElementById("cancelledTable");
|
||||
|
||||
activeTable.innerHTML="";
|
||||
cancelledTable.innerHTML="";
|
||||
|
||||
activeData.forEach(r=>{
|
||||
activeTable.innerHTML+=createRow(r);
|
||||
});
|
||||
|
||||
cancelledData.forEach(r=>{
|
||||
cancelledTable.innerHTML+=createRow(r);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function copyResource(r) {
|
||||
r.id = null;
|
||||
editResource(r);
|
||||
|
||||
function openModal(){
|
||||
|
||||
document.getElementById("resourceId").value="";
|
||||
|
||||
fields.forEach(f=>{
|
||||
const el=document.getElementById(f);
|
||||
if(el) el.value="";
|
||||
});
|
||||
|
||||
new bootstrap.Modal(document.getElementById("resourceModal")).show();
|
||||
|
||||
}
|
||||
|
||||
async function saveResource() {
|
||||
const id = document.getElementById("resourceId").value;
|
||||
let payload = {};
|
||||
fields.forEach(f => {
|
||||
const el = document.getElementById(f);
|
||||
if (el) payload[f] = el.value || null;
|
||||
});
|
||||
|
||||
if (id) {
|
||||
await fetch(API + "/" + id, {
|
||||
method: "PUT",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(payload)
|
||||
});
|
||||
} else {
|
||||
await fetch(API, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(payload)
|
||||
});
|
||||
}
|
||||
function editResource(r){
|
||||
|
||||
document.getElementById("resourceId").value=r.id;
|
||||
|
||||
fields.forEach(f=>{
|
||||
const el=document.getElementById(f);
|
||||
if(el) el.value=r[f] || "";
|
||||
});
|
||||
|
||||
new bootstrap.Modal(document.getElementById("resourceModal")).show();
|
||||
|
||||
loadResources();
|
||||
bootstrap.Modal.getInstance(document.getElementById("resourceModal")).hide();
|
||||
}
|
||||
|
||||
async function deleteResource(id) {
|
||||
if (!confirm("Wirklich löschen?")) return;
|
||||
await fetch(API + "/" + id, { method: "DELETE" });
|
||||
loadResources();
|
||||
|
||||
function copyResource(r){
|
||||
|
||||
r.id=null;
|
||||
editResource(r);
|
||||
|
||||
}
|
||||
|
||||
|
||||
async function saveResource(){
|
||||
|
||||
const id=document.getElementById("resourceId").value;
|
||||
|
||||
let payload={};
|
||||
|
||||
fields.forEach(f=>{
|
||||
const el=document.getElementById(f);
|
||||
if(el) payload[f]=el.value || null;
|
||||
});
|
||||
|
||||
if(id){
|
||||
|
||||
await fetch(API+"/"+id,{
|
||||
method:"PUT",
|
||||
headers:{"Content-Type":"application/json"},
|
||||
body:JSON.stringify(payload)
|
||||
});
|
||||
|
||||
}else{
|
||||
|
||||
await fetch(API,{
|
||||
method:"POST",
|
||||
headers:{"Content-Type":"application/json"},
|
||||
body:JSON.stringify(payload)
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
loadResources();
|
||||
|
||||
bootstrap.Modal.getInstance(document.getElementById("resourceModal")).hide();
|
||||
|
||||
}
|
||||
|
||||
|
||||
async function deleteResource(id){
|
||||
|
||||
if(!confirm("Wirklich löschen?")) return;
|
||||
|
||||
await fetch(API+"/"+id,{method:"DELETE"});
|
||||
|
||||
loadResources();
|
||||
|
||||
}
|
||||
|
||||
loadResources();
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@ -12,12 +12,41 @@ const path = require("path");
|
||||
/* Static Files */
|
||||
app.use("/resman", express.static(path.join(__dirname, "public")));
|
||||
|
||||
/* LIST */
|
||||
app.get(`${BASE_PATH}/resources`, async (req, res) => {
|
||||
const [rows] = await pool.query("SELECT * FROM resources");
|
||||
/* Resourcen laden */
|
||||
app.get("/resman/api/resources", async (req, res) => {
|
||||
const [rows] = await pool.query(
|
||||
"SELECT * FROM resources WHERE status != 'gekündigt'"
|
||||
);
|
||||
res.json(rows);
|
||||
});
|
||||
|
||||
|
||||
/* LIST Aktive resourcen*/
|
||||
app.get("/resman/api/resources/active", async (req, res) => {
|
||||
|
||||
const [rows] = await pool.query(
|
||||
"SELECT * FROM resources WHERE status != 'gekündigt'"
|
||||
);
|
||||
|
||||
res.json(rows);
|
||||
|
||||
});
|
||||
|
||||
|
||||
/* LIST Gekündigte resourcen*/
|
||||
app.get("/resman/api/resources/cancelled", async (req, res) => {
|
||||
|
||||
const [rows] = await pool.query(
|
||||
"SELECT * FROM resources WHERE status = 'gekündigt'"
|
||||
);
|
||||
|
||||
console.log("Cancelled resources:", rows);
|
||||
|
||||
res.json(rows);
|
||||
|
||||
});
|
||||
|
||||
|
||||
/* INSERT */
|
||||
app.post(`${BASE_PATH}/resources`, async (req, res) => {
|
||||
const data = req.body;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user