Skip to content
Snippets Groups Projects
Commit 223432f8 authored by Nigel  Sahl's avatar Nigel Sahl
Browse files

feat: add ajax to soap service (not done yet)

parent 6e0d5dfe
No related merge requests found
...@@ -27,6 +27,8 @@ AuthMiddleware::getInstance()->secureRoute(true); ...@@ -27,6 +27,8 @@ AuthMiddleware::getInstance()->secureRoute(true);
<div class="app"> <div class="app">
<script> <script>
const apikey = <?php echo json_encode($_ENV['API_KEY']) ?>; const apikey = <?php echo json_encode($_ENV['API_KEY']) ?>;
const soapkey = <?php echo json_encode($_ENV['AUTHORIZATION']) ?>;
const soapurl = <?php echo json_encode($_ENV['SOAP_URL']) ?>;
</script> </script>
<?php <?php
echo NavbarAdmin(); echo NavbarAdmin();
...@@ -118,7 +120,7 @@ AuthMiddleware::getInstance()->secureRoute(true); ...@@ -118,7 +120,7 @@ AuthMiddleware::getInstance()->secureRoute(true);
<script src="/public/javascript/gym/application.js"></script> <script src="/public/javascript/gym/application.js"></script>
<script src="/public/javascript/gym/trainer.js"></script> <script src="/public/javascript/gym/trainer.js"></script>
<script> <script>
getGymTrainers(); // getGymTrainers(<?php echo $gym_id ?>);
getGymApplication(<?php echo $gym_id ?>); getGymApplication(<?php echo $gym_id ?>);
</script> </script>
</body> </body>
......
...@@ -4,23 +4,33 @@ function hidePopupRej() { document.querySelector(`#pop-up-reject`).style.display ...@@ -4,23 +4,33 @@ function hidePopupRej() { document.querySelector(`#pop-up-reject`).style.display
function showPopupRej() { document.querySelector(`#pop-up-reject`).style.display = "flex";} function showPopupRej() { document.querySelector(`#pop-up-reject`).style.display = "flex";}
// dummy data // dummy data
let trainer = { // let trainer = {
username: "johndoe", // username: "johndoe",
gym_id: 43, // gym_id: 43,
acceptance: 0, // acceptance: 0,
trainer_name: "John Doe", // trainer_name: "John Doe",
trainer_description: "Aku ingin bekerja", // trainer_description: "Aku ingin bekerja",
application_description: "Aku ingin bekerja di sebuah gym, aku memiliki semangat di gym 43 ini semoga bisa keterima. Sekian dan terima kasih atas perhatian dan kesan dan pesannya", // application_description: "Aku ingin bekerja di sebuah gym, aku memiliki semangat di gym 43 ini semoga bisa keterima. Sekian dan terima kasih atas perhatian dan kesan dan pesannya",
} // }
let trainer2 = { // let trainer2 = {
username: "johndoedfdf", // username: "johndoedfdf",
gym_id: 43, // gym_id: 43,
acceptance: 0, // acceptance: 0,
trainer_name: "John Doe", // trainer_name: "John Doe",
trainer_description: "Aku ingin bekerja", // trainer_description: "Aku ingin bekerja",
application_description: "Aku ingin bekerja", // application_description: "Aku ingin bekerja",
} // }
let data = [trainer, trainer2]; // let data = [trainer, trainer2];
const response = `<?xml version="1.0"?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:getAllAplicationResponse xmlns:ns2="http://service.gymtracker.com/">
<return>[nerbi1, 37, 0, Rayhan, Let's get some gainz brah, Give me a job]
[nerbi2, 37, 1, Rayhan, Let's get some gainz brah, Give me a job]
[nerbi3, 37, 0, Nigel, Let's get some gainz brah, Give me a job]</return>
</ns2:getAllAplicationResponse>
</S:Body>
</S:Envelope>`
function modifyGymApplicationList(data) { function modifyGymApplicationList(data) {
...@@ -29,7 +39,7 @@ function modifyGymApplicationList(data) { ...@@ -29,7 +39,7 @@ function modifyGymApplicationList(data) {
if (data.length == 0) { if (data.length == 0) {
gymApplicationList.innerHTML = ` gymApplicationList.innerHTML = `
<div class="space"></div> <div class="space"></div>
<div class="gym-card-text"> No Aplication found </div> <div class="gym-card-text"> No Application found </div>
`; `;
} }
data.forEach((trainer) => { data.forEach((trainer) => {
...@@ -38,24 +48,39 @@ function modifyGymApplicationList(data) { ...@@ -38,24 +48,39 @@ function modifyGymApplicationList(data) {
} }
function getGymApplication(gymId) { function getGymApplication(gymId) {
modifyGymApplicationList(data); modifyGymApplicationList(filterApplication(parseXmlResponse(response), 0));
const xhr = new XMLHttpRequest(); showGymTrainers(filterApplication(parseXmlResponse(response), 1));
xhr.onreadystatechange = function () {
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (this.readyState === 4) { if (this.readyState === 4) {
if (this.status === 200) { if (this.status === 200) {
modifyGymApplicationList(JSON.parse(this.responseText)["trainers"]); const applications = parseXmlResponse(this.responseText);
} else { alert("trainer : " + applications);
const json = JSON.parse(this.responseText); modifyGymApplicationList(filterApplication(applications, 0));
alert(json["error"]); showGymTrainers(filterApplication(applications, 1));
} } else {
const xml = this.responseXML;
alert("error status : " + this.status + " error text : " + xml);
}
} }
}; };
// xhr.open("GET", `/api/gym/rating?gym_id=${gymId}`, true); const soapBody = `<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
// xhr.setRequestHeader("X-API-KEY", apikey); <Body>
xhr.send(); <getAllAplication xmlns="http://service.gymtracker.com/">
<gym_id xmlns="">${gymId}</gym_id>
</getAllAplication>
</Body>
</Envelope>`;
// alert("soapbody : " + soapBody);
xhr.open("POST", soapurl, true);
xhr.setRequestHeader("Content-Type", "text/xml");
xhr.setRequestHeader("Authorization", soapkey);
xhr.send(soapBody);
} }
function getApplication(username, gymId) { function getApplication(username, gymId) {
// alert("get application with username: " + username + " and gym id: " + gymId); // alert("get application with username: " + username + " and gym id: " + gymId);
modifyApplication(trainer); modifyApplication(trainer);
...@@ -128,4 +153,34 @@ function modifyApplication(trainer) { ...@@ -128,4 +153,34 @@ function modifyApplication(trainer) {
</tr> </tr>
</table> </table>
` `
}
function parseXmlResponse(xmlString) {
const parser = new DOMParser();
const xmlDoc = parser.parseFromString(xmlString, "text/xml");
const returnElement = xmlDoc.getElementsByTagName("return")[0];
const returnText = returnElement.textContent;
// Split the return text into an array of trainer strings
const trainerStrings = returnText.split("\n").filter(str => str.trim() !== "");
// Parse each trainer string into a trainer object
const trainers = trainerStrings.map(trainerString => {
const values = trainerString.replace("[", "").replace("]", "").split(", ");
return {
username: values[0],
gym_id: parseInt(values[1]),
acceptance: parseInt(values[2]),
trainer_name: values[3],
trainer_description: values[4],
application_description: values[5]
};
});
return trainers;
}
function filterApplication(Applications, acc){
// filter Application with Acceptance acc
return Applications.filter(application => application.acceptance == acc);
} }
\ No newline at end of file
...@@ -29,9 +29,9 @@ let trainer_1 = { ...@@ -29,9 +29,9 @@ let trainer_1 = {
let trainerData = [trainer_1, trainer_2]; let trainerData = [trainer_1, trainer_2];
// Functions // Functions
function getGymTrainers() { // function getGymTrainers(gymId) {
showGymTrainers(trainerData); // showGymTrainers(trainerData);
} // }
function showGymTrainers(data) { function showGymTrainers(data) {
const gymTrainerList = document.getElementById("gym-trainer-list"); const gymTrainerList = document.getElementById("gym-trainer-list");
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment