js client officially done
This commit is contained in:
@@ -2,15 +2,12 @@
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Maintainer Team</title>
|
||||
<title>Teams</title>
|
||||
<link rel="stylesheet" type="text/css" href="../style.css">
|
||||
<script src="maintainerteam.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Maintainer team</h1>
|
||||
<br>
|
||||
<a href="#add" class="bookmark">Want to add a new line?</a>
|
||||
<br>
|
||||
<h1>Maintainer teams</h1>
|
||||
<br>
|
||||
<table class="queryresults">
|
||||
<thead>
|
||||
@@ -23,28 +20,7 @@
|
||||
<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>Name</td>
|
||||
<td class="inputcell"><input type="text" id="in_name"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Email</td>
|
||||
<td class="inputcell"><input type="text" id="in_email"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Leader ID</td>
|
||||
<td class="inputcell"><input type="text" id="in_leader_id"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2"><button onclick="addmaintainerteam()">Save</button></td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2 id="addresult"></h2>
|
||||
<div id="forms"></div>
|
||||
<h2 id="saveresult"></h2>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
@@ -1,13 +1,13 @@
|
||||
let maintainerteams = [];
|
||||
getmaintainerteams();
|
||||
let teams = [];
|
||||
getteams();
|
||||
|
||||
async function getmaintainerteams()
|
||||
async function getteams()
|
||||
{
|
||||
await fetch('https://localhost:5001/api/MaintainerTeam')
|
||||
.then(x => x.json())
|
||||
.then(y => {
|
||||
maintainerteams = y;
|
||||
console.log(maintainerteams);
|
||||
teams = y;
|
||||
console.log(teams);
|
||||
display();
|
||||
});
|
||||
}
|
||||
@@ -16,79 +16,131 @@ function display()
|
||||
{
|
||||
document.getElementById('resultarea').innerHTML = '';
|
||||
|
||||
maintainerteams.forEach(t => {
|
||||
teams.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>'
|
||||
+ '<button type="button" onclick="deleteteam(' + t.id + ')">Delete</button>'
|
||||
+ '</td><td>'
|
||||
+ '<button type="button" onclick="updatemaintainerteam(' + t.id + ')">Edit</button>'
|
||||
+ '<button type="button" onclick="editteam(' + t.id + ')">Edit</button>'
|
||||
+ '</td></tr>';
|
||||
});
|
||||
|
||||
document.getElementById('resultarea').innerHTML +=
|
||||
'<tr>' +
|
||||
'<td colspan="4">' +
|
||||
'<button type="button" onclick="addteam()">Add new</button>' +
|
||||
'</td>' +
|
||||
'</tr>';
|
||||
}
|
||||
|
||||
function updatemaintainerteam(id)
|
||||
function addteam()
|
||||
{
|
||||
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
|
||||
})
|
||||
})
|
||||
document.getElementById('forms').innerHTML = '';
|
||||
document.getElementById('forms').innerHTML +=
|
||||
'<table class="inputs">' +
|
||||
'<tr>' +
|
||||
'<td>ID</td>' +
|
||||
'<td class="inputcell"><input type="text" id="in_id"></td>' +
|
||||
'</tr>' +
|
||||
'<tr>' +
|
||||
'<td>Name</td>' +
|
||||
'<td class="inputcell"><input type="text" id="in_name"></td>' +
|
||||
'</tr>' +
|
||||
'<tr>' +
|
||||
'<td>Email</td>' +
|
||||
'<td class="inputcell"><input type="text" id="in_email"></td>' +
|
||||
'</tr>' +
|
||||
'<tr>' +
|
||||
'<td>Leader ID</td>' +
|
||||
'<td class="inputcell"><input type="text" id="in_leader_id"></td>' +
|
||||
'</tr>' +
|
||||
'<tr>' +
|
||||
'<td colspan="2"><button onclick="saveteam(\'PUT\')">Add</button></td>' +
|
||||
'</tr>' +
|
||||
'</table>';
|
||||
}
|
||||
|
||||
function addmaintainerteam()
|
||||
function editteam(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;
|
||||
existing_item = teams.find(x => x.id == id);
|
||||
|
||||
document.getElementById('forms').innerHTML = '';
|
||||
document.getElementById('forms').innerHTML +=
|
||||
'<table class="inputs">' +
|
||||
'<tr>' +
|
||||
'<td>ID</td>' +
|
||||
'<td style="background-color: rgba(0, 0, 0, 0.1);" class="inputcell"><input type="text" id="in_id" readonly value="' + existing_item.id + '"></td>' +
|
||||
'</tr>' +
|
||||
'<tr>' +
|
||||
'<td>Name</td>' +
|
||||
'<td class="inputcell"><input type="text" id="in_name" value="' + existing_item.name + '"></td>' +
|
||||
'</tr>' +
|
||||
'<tr>' +
|
||||
'<td>Email</td>' +
|
||||
'<td class="inputcell"><input type="text" id="in_email" value="' + existing_item.email + '"></td>' +
|
||||
'</tr>' +
|
||||
'<tr>' +
|
||||
'<td>Leader ID</td>' +
|
||||
'<td class="inputcell"><input type="text" id="in_leader_id" value="' + existing_item.leadeR_ID + '"></td>' +
|
||||
'</tr>' +
|
||||
'<tr>' +
|
||||
'<td colspan="2"><button onclick="saveteam(\'POST\')">Update</button></td>' +
|
||||
'</tr>' +
|
||||
'</table>';
|
||||
}
|
||||
|
||||
function saveteam(method)
|
||||
{
|
||||
if (method != 'POST' && method != 'PUT')
|
||||
{
|
||||
console.error('Invalid method: ' + method);
|
||||
return;
|
||||
}
|
||||
|
||||
team_id = document.getElementById('in_id').value;
|
||||
team_name = document.getElementById('in_name').value;
|
||||
team_email = document.getElementById('in_email').value;
|
||||
team_leader_id = document.getElementById('in_leader_id').value;
|
||||
|
||||
fetch('https://localhost:5001/api/MaintainerTeam', {
|
||||
method: 'PUT',
|
||||
method: method,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
id: maintainerteam_id,
|
||||
name: maintainerteam_name,
|
||||
email: maintainerteam_email,
|
||||
leader_id: maintainerteam_leader_id
|
||||
id: team_id,
|
||||
name: team_name,
|
||||
email: team_email,
|
||||
leadeR_ID: team_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';
|
||||
|
||||
getmaintainerteams();
|
||||
|
||||
|
||||
document.getElementById('forms').innerHTML = '';
|
||||
document.getElementById('saveresult').innerHTML = '';
|
||||
document.getElementById('saveresult').innerHTML +=
|
||||
'Saved team ' + team_name + ' successfully';
|
||||
|
||||
getteams();
|
||||
|
||||
})
|
||||
.catch(error => {
|
||||
console.error("Error: ", error);
|
||||
|
||||
document.getElementById('addresult').innerHTML = '';
|
||||
document.getElementById('addresult').innerHTML +=
|
||||
'Failed to add maintainer team ' + maintainerteam_name;
|
||||
|
||||
document.getElementById('saveresult').innerHTML = '';
|
||||
document.getElementById('saveresult').innerHTML +=
|
||||
'Failed to save team ' + team_name;
|
||||
});
|
||||
}
|
||||
|
||||
function deletemaintainerteam(id)
|
||||
function deleteteam(id)
|
||||
{
|
||||
document.getElementById('forms').innerHTML = '';
|
||||
|
||||
fetch('https://localhost:5001/api/MaintainerTeam/' + id, {
|
||||
method: 'DELETE',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
@@ -97,7 +149,12 @@ function deletemaintainerteam(id)
|
||||
.then(data =>
|
||||
{
|
||||
console.log("Success: ", data)
|
||||
getmaintainerteams();
|
||||
|
||||
document.getElementById('saveresult').innerHTML = '';
|
||||
document.getElementById('saveresult').innerHTML +=
|
||||
'Deleted team number ' + id + ' successfully';
|
||||
|
||||
getteams();
|
||||
})
|
||||
.catch(error => console.error("Error: ", error));
|
||||
}
|
||||
Reference in New Issue
Block a user