organized files
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Employees</title>
|
||||
<link rel="stylesheet" type="text/css" href="../style.css">
|
||||
<script src="employees.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Employees</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>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>Phone</td>
|
||||
<td class="inputcell"><input type="text" id="in_phone"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Maintainer ID</td>
|
||||
<td class="inputcell"><input type="text" id="in_maintainer_id"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Manager ID</td>
|
||||
<td class="inputcell"><input type="text" id="in_manager_id"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2"><button onclick="addemployee()">Save</button></td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2 id="addresult"></h2>
|
||||
</body>
|
||||
</html>
|
||||
117
WD7UVN_SzTGUI_2023242.Client.JS/wwwroot/employees/employees.js
Normal file
117
WD7UVN_SzTGUI_2023242.Client.JS/wwwroot/employees/employees.js
Normal file
@@ -0,0 +1,117 @@
|
||||
let employees = [];
|
||||
getemployees();
|
||||
|
||||
async function getemployees()
|
||||
{
|
||||
await fetch('https://localhost:5001/api/Employee')
|
||||
.then(x => x.json())
|
||||
.then(y => {
|
||||
employees = y;
|
||||
console.log(employees);
|
||||
display();
|
||||
});
|
||||
}
|
||||
|
||||
function display()
|
||||
{
|
||||
document.getElementById('resultarea').innerHTML = '';
|
||||
|
||||
employees.forEach(t => {
|
||||
document.getElementById('resultarea').innerHTML +=
|
||||
'<tr><td>'
|
||||
+ t.id +
|
||||
'</td><td>'
|
||||
+ t.name +
|
||||
'</td><td>'
|
||||
+ '<button type="button" onclick="deleteemployee(' + t.id + ')">Delete</button>'
|
||||
+ '</td><td>'
|
||||
+ '<button type="button" onclick="updateemployee(' + 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 updateemployee(id)
|
||||
{
|
||||
let employee_id = document.getElementById('in_id').value;
|
||||
let employee_name = document.getElementById('in_name').value;
|
||||
let employee_email = document.getElementById('in_email').value;
|
||||
let employee_phone = document.getElementById('in_phone').value;
|
||||
let employee_manager_id = document.getElementById('in_manager_id').value;
|
||||
let employee_maintainer_id = document.getElementById('in_maintainer_id').value;
|
||||
|
||||
fetch ('https://localhost:5001/api/Employee/' + id, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
id: employee_id,
|
||||
name: employee_name,
|
||||
email: employee_email,
|
||||
phone: employee_phone,
|
||||
manager_id: employee_manager_id,
|
||||
maintainer_id: employee_maintainer_id
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function addemployee()
|
||||
{
|
||||
let employee_id = document.getElementById('in_id').value;
|
||||
let employee_name = document.getElementById('in_name').value;
|
||||
let employee_email = document.getElementById('in_email').value;
|
||||
let employee_phone = document.getElementById('in_phone').value;
|
||||
let employee_manager_id = document.getElementById('in_manager_id').value;
|
||||
let employee_maintainer_id = document.getElementById('in_maintainer_id').value;
|
||||
|
||||
fetch('https://localhost:5001/api/Employee', {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
id: employee_id,
|
||||
name: employee_name,
|
||||
email: employee_email,
|
||||
phone: employee_phone,
|
||||
manager_id: employee_manager_id,
|
||||
maintainer_id: employee_maintainer_id
|
||||
})
|
||||
})
|
||||
.then(response => response)
|
||||
.then(data => {
|
||||
console.log("Success: ", data)
|
||||
|
||||
document.getElementById('addresult').innerHTML = '';
|
||||
document.getElementById('addresult').innerHTML +=
|
||||
'Added employee ' + employee_name + ' successfully';
|
||||
|
||||
getemployees();
|
||||
|
||||
})
|
||||
.catch(error => {
|
||||
console.error("Error: ", error);
|
||||
|
||||
document.getElementById('addresult').innerHTML = '';
|
||||
document.getElementById('addresult').innerHTML +=
|
||||
'Failed to add maintainer team ' + employee_name;
|
||||
});
|
||||
}
|
||||
|
||||
function deleteemployee(id)
|
||||
{
|
||||
fetch('https://localhost:5001/api/Employee/' + id, {
|
||||
method: 'DELETE',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
})
|
||||
.then(response => response)
|
||||
.then(data =>
|
||||
{
|
||||
console.log("Success: ", data)
|
||||
getemployees();
|
||||
})
|
||||
.catch(error => console.error("Error: ", error));
|
||||
}
|
||||
Reference in New Issue
Block a user