Skip to content

Commit

Permalink
front end is done
Browse files Browse the repository at this point in the history
  • Loading branch information
hajekad3 committed Jan 4, 2023
1 parent be8da2f commit b18be0a
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 10 deletions.
8 changes: 4 additions & 4 deletions frontEnd/trainee.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ <h2>Find Match</h2>
<label for="range-find-match">Range:</label><br>
<input type="number" id="range-find-match"><br><br>
<label for="username-find-match">Username:</label><br>
<input type="number" id="username-find-match"><br>
<input type="text" id="username-find-match"><br>
<label for="password-find-match">Password:</label><br>
<input type="password" id="password-find-match"><br>
<label for="email-find-match">Email:</label><br>
Expand All @@ -46,7 +46,7 @@ <h2>Assign training</h2>
<label for="id-assign-training">Trainee ID:</label><br>
<input type="number" id="id-assign-training"><br>
<label for="username-assign-training">Username:</label><br>
<input type="number" id="username-assign-training"><br>
<input type="text" id="username-assign-training"><br>
<label for="password-assign-training">Password:</label><br>
<input type="password" id="password-assign-training"><br>
<label for="email-assign-training">Email:</label><br>
Expand All @@ -58,9 +58,9 @@ <h2>Assign training</h2>
<label for="skill-cap-assign-training">Skill Cap:</label><br>
<input type="number" id="skill-cap-assign-training"><br>

<label for="from-assign-training">Second Name:</label><br>
<label for="from-assign-training">From:</label><br>
<input type="datetime-local" id="from-assign-training"><br>
<label for="to-assign-training">Skill Cap:</label><br>
<label for="to-assign-training">To:</label><br>
<input type="datetime-local" id="to-assign-training"><br>

<button type="button" onclick="assignTraining()">Create Trainee</button>
Expand Down
31 changes: 28 additions & 3 deletions frontEnd/trainee.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async function findMatch() {

try {
const response = await fetch(`http://localhost:6060/trainee/bussiness?range=${range}`, {
method: 'GET',
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(traineeDto)
});
Expand Down Expand Up @@ -52,9 +52,14 @@ async function assignTraining() {
const inputs = document.querySelectorAll('.trainingInputAssignTraining');
const trainings = Array.from(inputs).map(input => Number(input.value));

const from = document.getElementById('from-assign-training').value;
const to = document.getElementById('to-assign-training').value;
const fromDL = document.getElementById('from-assign-training').value;
const toDL = document.getElementById('to-assign-training').value;

const from = convertDatetimeLocal(fromDL);
const to = convertDatetimeLocal(toDL);

console.log(`${fromDL} -> ${from}\n${toDL} -> ${to}`);

const traineeDto = {
id: id,
username: username,
Expand Down Expand Up @@ -141,6 +146,26 @@ async function updateTrainee() {
update(traineeDto, '/trainee');
}

function convertDatetimeLocal(input) {
const timestamp = Date.parse(input);

if (isNaN(timestamp)) {
return 'Invalid Date';
}

const date = new Date(timestamp);

const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');

const hour = String(date.getHours()).padStart(2, '0');
const minute = String(date.getMinutes()).padStart(2, '0');

return `${year}-${month}-${day} ${hour}:${minute}:00`;
}


function addInput() {
const inputContainer = document.getElementById('input-container');
const input = document.createElement('input');
Expand Down
23 changes: 21 additions & 2 deletions frontEnd/training.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ async function trainingGet() {
async function createTraining() {
const idCoach = document.getElementById('id-coach-post').value;
const idPlace = document.getElementById('id-place-post').value;
const dateOfTraining = document.getElementById('date-of-training-post').value;
const dateOfTraining = convertDatetimeLocal(document.getElementById('date-of-training-post').value);
const description = document.getElementById('description-post').value;

const createTrainingDto = {
Expand All @@ -28,7 +28,7 @@ async function updateTraining() {
const id = document.getElementById('id-update').value;
const idCoach = document.getElementById('id-coach-update').value;
const idPlace = document.getElementById('id-place-update').value;
const dateOfTraining = document.getElementById('date-of-training-update').value;
const dateOfTraining = convertDatetimeLocal(document.getElementById('date-of-training-update').value);
const description = document.getElementById('description-update').value;
const inputs = document.querySelectorAll('.traineesInput');
const participatingTraineesIds = Array.from(inputs).map(input => Number(input.value));
Expand Down Expand Up @@ -130,4 +130,23 @@ async function update(dto, at) {
console.error("Error: one of the ids does not exist.");
document.getElementById('responseUpdate').value = "Error: one of the ids does not exist.";
}
}

function convertDatetimeLocal(input) {
const timestamp = Date.parse(input);

if (isNaN(timestamp)) {
return 'Invalid Date';
}

const date = new Date(timestamp);

const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');

const hour = String(date.getHours()).padStart(2, '0');
const minute = String(date.getMinutes()).padStart(2, '0');

return `${year}-${month}-${day} ${hour}:${minute}:00`;
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public ResponseEntity getTrainingInTimeFrame(@RequestParam String from, @Request
return ResponseEntity.ok().body(ret);
}

@GetMapping("/bussiness")
@PostMapping("/bussiness")
public ResponseEntity findMatch(@RequestParam int range, @RequestBody TraineeDto challenger) {
TraineeDto ret;

Expand Down

0 comments on commit b18be0a

Please sign in to comment.