Merge pull request 'gui: Update add/create Skill,fSS.js, config' (#96) from 2021323/Backend:restfull into restfull

Reviewed-on: Maradona/Backend#96
pull/1/head
Piotr Jakubiak 2024-11-12 13:04:15 +01:00
commit a875854241
5 changed files with 97 additions and 76 deletions

View File

@ -20,7 +20,7 @@ spring:
show-sql: true show-sql: true
properties: properties:
hibernate: hibernate:
dialect: org.hibernate.dialect.H2Dialect open-in-view: true # Enable/Disable OpenEntityManagerInViewInterceptor
thymeleaf: thymeleaf:
prefix: "classpath:/templates/" # Path where Thymeleaf templates are stored prefix: "classpath:/templates/" # Path where Thymeleaf templates are stored

View File

@ -1,6 +1,6 @@
/** /**
* @fileoverview Handles the dynamic population of secondary skills dropdown based on primary skill selection * @fileoverview Handles the dynamic population of secondary skills dropdown based on primary skill selection
* @version 4.1.0 * @version 4.2.0
*/ */
/** /**
@ -59,7 +59,7 @@ function showTemporaryMessage(message, type, duration = 5000, container) {
* @param {HTMLSelectElement} selectElement - The secondary skills select element * @param {HTMLSelectElement} selectElement - The secondary skills select element
*/ */
function updateSecondarySkillsDropdown(secondarySkills, selectElement) { function updateSecondarySkillsDropdown(secondarySkills, selectElement) {
selectElement.innerHTML = ""; // Clear existing options selectElement.innerHTML = "";
if (!secondarySkills || secondarySkills.length === 0) { if (!secondarySkills || secondarySkills.length === 0) {
selectElement.appendChild( selectElement.appendChild(
@ -103,73 +103,83 @@ function initializeSkillsDropdowns() {
} }
secondarySkillSelect.disabled = true; secondarySkillSelect.disabled = true;
}
primarySkillSelect.addEventListener("change", async function () { async function fetchSecondarySkills() {
const selectedPrimarySkillId = this.value; const primarySkillSelect = document.getElementById("primarySkill");
const secondarySkillSelect = document.getElementById("secondarySkill");
const selectedPrimarySkillId = primarySkillSelect.value;
if (!selectedPrimarySkillId) {
secondarySkillSelect.innerHTML = ""; secondarySkillSelect.innerHTML = "";
secondarySkillSelect.appendChild( secondarySkillSelect.appendChild(
createOption("Select a secondary skill", true, true) createOption("Select a secondary skill", true, true)
); );
secondarySkillSelect.disabled = true;
return;
}
if (!selectedPrimarySkillId) { secondarySkillSelect.innerHTML = "";
secondarySkillSelect.disabled = true; secondarySkillSelect.appendChild(createOption("Loading...", true, true));
return;
try {
const response = await fetch(
`/api/secondary-skill/from-primary-skill?psid=${selectedPrimarySkillId}`,
{
method: "GET",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
},
}
);
if (!response.ok) {
const errorMessage = `Server returned ${response.status}: ${response.statusText}`;
throw new Error(errorMessage);
} }
secondarySkillSelect.innerHTML = ""; const responseText = await response.text();
secondarySkillSelect.appendChild(createOption("Loading...", true, true)); console.log("Response Text:", responseText);
let secondarySkills;
try { try {
const response = await fetch( secondarySkills = JSON.parse(responseText);
`/api/skills/secondary/${selectedPrimarySkillId}`, } catch (jsonError) {
{ throw new Error(`Failed to parse JSON: ${jsonError.message}`);
method: "GET",
headers: {
"Content-Type": "application/json",
},
}
);
if (!response.ok) {
const errorMessage = `Server returned ${response.status}: ${response.statusText}`;
throw new Error(errorMessage);
}
const secondarySkills = await response.json();
updateSecondarySkillsDropdown(secondarySkills, secondarySkillSelect);
} catch (error) {
console.error("Error fetching secondary skills:", error);
secondarySkillSelect.innerHTML = "";
secondarySkillSelect.appendChild(
createOption("Error loading secondary skills", true, true)
);
secondarySkillSelect.disabled = true;
let userMessage = "";
if (error.name === "TypeError" && !window.navigator.onLine) {
userMessage =
"No internet connection. Please check your network and try again.";
} else if (error.message.includes("Server returned 404")) {
userMessage =
"The selected primary skill was not found. Please refresh and try again.";
} else if (error.message.includes("Server returned 500")) {
userMessage =
"Server error occurred. Please try again in a few minutes.";
} else if (error.message.includes("Server returned 403")) {
userMessage =
"You don't have permission to access these skills. Please contact support.";
} else {
userMessage = `Failed to load secondary skills: ${error.message}`;
}
showTemporaryMessage(
userMessage,
"error",
5000,
secondarySkillSelect.parentNode
);
} }
});
updateSecondarySkillsDropdown(secondarySkills, secondarySkillSelect);
} catch (error) {
console.error("Error fetching secondary skills:", error);
secondarySkillSelect.innerHTML = "";
secondarySkillSelect.appendChild(
createOption("Error loading secondary skills", true, true)
);
secondarySkillSelect.disabled = true;
let userMessage = "";
if (error.name === "TypeError" && !window.navigator.onLine) {
userMessage =
"No internet connection. Please check your network and try again.";
} else if (error.message.includes("Server returned 404")) {
userMessage =
"The selected primary skill was not found. Please refresh and try again.";
} else if (error.message.includes("Server returned 500")) {
userMessage = "Server error occurred. Please try again in a few minutes.";
} else if (error.message.includes("Server returned 403")) {
userMessage =
"You don't have permission to access these skills. Please contact support.";
} else {
userMessage = `Failed to load secondary skills: ${error.message}`;
}
showTemporaryMessage(
userMessage,
"error",
5000,
secondarySkillSelect.parentNode
);
}
} }
document.addEventListener("DOMContentLoaded", initializeSkillsDropdowns); document.addEventListener("DOMContentLoaded", initializeSkillsDropdowns);

View File

@ -20,8 +20,8 @@
<div class="content container mt-4"> <div class="content container mt-4">
<h2 class="mb-4">Add Skill</h2> <h2 class="mb-4">Add Skill</h2>
<form <form
th:action="@{/skills/add}" th:action="@{/api/employee/skill/prototype}"
th:object="${skillProtoype}" th:object="${skillPrototype}"
method="post" method="post"
class="project-card" class="project-card"
> >
@ -31,9 +31,10 @@
<label for="primarySkill">Primary Skill</label> <label for="primarySkill">Primary Skill</label>
<select <select
id="primarySkill" id="primarySkill"
name="primarySkillId" name="psid"
class="form-control" class="form-control"
th:field="*{primarySkillId}" th:field="*{psid}"
onchange="fetchSecondarySkills()"
> >
<option value="" disabled selected> <option value="" disabled selected>
Select a primary skill Select a primary skill
@ -50,9 +51,9 @@
<label for="secondarySkill">Secondary Skill</label> <label for="secondarySkill">Secondary Skill</label>
<select <select
id="secondarySkill" id="secondarySkill"
name="secondarySkillId" name="ssid"
class="form-control" class="form-control"
th:field="*{secondarySkillId}" th:field="*{ssid}"
> >
<option value="" disabled selected> <option value="" disabled selected>
Select a secondary skill Select a secondary skill

View File

@ -10,43 +10,53 @@
</head> </head>
<body> <body>
<div class="wrapper"> <div class="wrapper">
<div <div th:replace="~{/core/_header :: header(activePage='createSkill')}"></div>
th:replace="~{/core/_header :: header(activePage=${createSkill})}"
></div>
<div class="content container mt-4"> <div class="content container mt-4">
<h2 class="mb-4">Create Skill</h2> <h2 class="mb-4">Create Skill</h2>
<form <form
th:action="@{/skills/save}" th:action="@{/skills/save}"
th:object="${secondarySkill}" th:object="${skillPrototype}"
method="post" method="post"
class="project-card" class="project-card"
> >
<div class="card-body"> <div class="card-body">
<!-- Primary Skill Input -->
<div class="form-group"> <div class="form-group">
<label for="primarySkill">Primary Skill:</label> <label for="primarySkill">Primary Skill:</label>
<input <input
type="text" type="text"
id="primarySkill" id="primarySkill"
th:field="*{primarySkill.description}" th:field="*{psid}"
class="form-control" class="form-control"
required required
/> />
</div> </div>
<!-- Secondary Skill Input -->
<div class="form-group"> <div class="form-group">
<label for="secondarySkill">Secondary Skill:</label> <label for="secondarySkill">Secondary Skill:</label>
<input <input
type="text" type="text"
id="secondarySkill" id="secondarySkill"
th:field="*{description}" th:field="*{ssid}"
class="form-control" class="form-control"
required required
/> />
</div> </div>
<!-- Skill Level Input -->
<div class="form-group"> <div class="form-group">
<button type="submit" class="btn-create-project"> <label for="level">Skill Level:</label>
Save Skill <input
</button> type="number"
id="level"
th:field="*{level}"
class="form-control"
min="1"
max="5"
required
/>
</div> </div>
<!-- Submit Button -->
<button type="submit" class="btn-create-project">Create Skill</button>
</div> </div>
</form> </form>
</div> </div>

View File

@ -10,9 +10,9 @@
</head> </head>
<body> <body>
<div class="wrapper"> <div class="wrapper">
<div th:replace="~{/core/_header :: header(activePage=${skills})}"></div> <div th:replace="~{/core/_header :: header(activePage='skills')}"></div>
<div class="content container mt-4"> <div class="content container mt-4">
<h2 class="mb-4">Profil</h2> <h2 class="mb-4">Profile</h2>
<div class="project-card mb-4"> <div class="project-card mb-4">
<div class="card-body"> <div class="card-body">
<p> <p>