wrote js script for maitainer team table

This commit is contained in:
2024-04-30 12:45:03 +02:00
parent 7ea7bc3b11
commit cb7a1123ca
2 changed files with 112 additions and 2 deletions

View File

@@ -4,6 +4,7 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Maintainer Team</title> <title>Maintainer Team</title>
<link rel="stylesheet" type="text/css" href="style.css"> <link rel="stylesheet" type="text/css" href="style.css">
<script src="maintainerteam.js"></script>
</head> </head>
<body> <body>
<h1>Maintainer team</h1> <h1>Maintainer team</h1>
@@ -41,9 +42,9 @@
<td class="inputcell"><input type="text" id="in_leader_id"></td> <td class="inputcell"><input type="text" id="in_leader_id"></td>
</tr> </tr>
<tr> <tr>
<td colspan="2"><button onclick="addService()">Save</button></td> <td colspan="2"><button onclick="addmaintainerteam()">Save</button></td>
</tr> </tr>
</table> </table>
<div id="addresult"></div> <h2 id="addresult"></h2>
</body> </body>
</html> </html>

View File

@@ -0,0 +1,109 @@
let maintainerteams = [];
getmaintainerteams();
async function getmaintainerteams()
{
await fetch('https://localhost:5001/api/MaintainerTeam')
.then(x => x.json())
.then(y => {
maintainerteams = y;
console.log(maintainerteams);
display();
});
}
function display()
{
document.getElementById('resultarea').innerHTML = '';
maintainerteams.forEach(t => {
document.getElementById('resultarea').innerHTML +=
'<tr><td>'
+ t.id +
'</td><td>'
+ t.name +
'</td><td>'
+ '<button type="button" onclick="deletemaintainerteam(' + t.id + ')">Delete</button>'
+ '</td><td>'
+ '<button type="button" onclick="updatemaintainerteam(' + 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 updatemaintainerteam(id)
{
let maintainerteam_id = document.getElementById('in_id').value;
let maintainerteam_name = document.getElementById('in_name').value;
let maintainerteam_email = document.getElementById('in_email').value;
let maintainerteam_leader_id = document.getElementById('in_leader_id').value;
fetch ('https://localhost:5001/api/MaintainerTeam/' + id, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
id: maintainerteam_id,
name: maintainerteam_name,
email: maintainerteam_email,
leader_id: maintainerteam_leader_id
})
})
}
function addmaintainerteam()
{
let maintainerteam_id = document.getElementById('in_id').value;
let maintainerteam_name = document.getElementById('in_name').value;
let maintainerteam_email = document.getElementById('in_email').value;
let maintainerteam_leader_id = document.getElementById('in_leader_id').value;
fetch('https://localhost:5001/api/MaintainerTeam', {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
id: maintainerteam_id,
name: maintainerteam_name,
email: maintainerteam_email,
leader_id: maintainerteam_leader_id
})
})
.then(response => response)
.then(data => {
console.log("Success: ", data)
document.getElementById('addresult').innerHTML = '';
document.getElementById('addresult').innerHTML +=
'Added maintainer team ' + maintainerteam_name + ' successfully';
})
.catch(error => {
console.error("Error: ", error);
document.getElementById('addresult').innerHTML = '';
document.getElementById('addresult').innerHTML +=
'Failed to add maintainer team ' + maintainerteam_name;
});
getmaintainerteams();
}
function deletemaintainerteam(id)
{
fetch('https://localhost:5001/api/MaintainerTeam/' + id, {
method: 'DELETE',
headers: { 'Content-Type': 'application/json' },
})
.then(response => response)
.then(data =>
{
console.log("Success: ", data)
getmaintainerteams();
})
.catch(error => console.error("Error: ", error));
}