Skip to content

Commit

Permalink
Merge branch 'website-files' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanVelez-code authored Jul 25, 2023
2 parents 43e2dd5 + 664ea54 commit 045d841
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions ROUSProj/ROUSApp/static/js/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
let starttime;
let dropdown;
let baseUrl = 'http://127.0.0.1:8000/';

document.addEventListener('DOMContentLoaded', function () {
if (document.getElementById('calendar')) {
Expand Down Expand Up @@ -65,7 +64,7 @@ document.addEventListener('DOMContentLoaded', function () {
};

// Make a GET request to the API endpoint
fetch(baseUrl + 'resource/geoloc/' + encodeURIComponent(selectedGeoLoc) + '/')
fetch('resource/geoloc/' + encodeURIComponent(selectedGeoLoc) + '/')
.then(response => response.json())
.then(data => {
const dropdown = document.getElementById('eventDropdown');
Expand Down Expand Up @@ -182,6 +181,7 @@ document.addEventListener('DOMContentLoaded', function () {
// If the input is empty, add the red border
input.style.borderColor = "red";
isAnyInputEmpty = true;

} else {
// If the input is not empty, remove the red border
input.style.borderColor = ""; // This will reset the border color to the default or remove it completely
Expand Down Expand Up @@ -267,7 +267,6 @@ document.addEventListener('DOMContentLoaded', function () {
.catch(error => {
console.error('Error:', error);
});

// post for resource
fetch(baseUrl + 'resource/', {
method: 'POST',
Expand Down Expand Up @@ -498,7 +497,6 @@ document.addEventListener('DOMContentLoaded', function () {
console.error('Error:', error);
});
} else {

// the other methods for plane and calendar data
fetch(baseUrl + 'plane-maintenance/', {
method: 'POST',
Expand All @@ -519,6 +517,7 @@ document.addEventListener('DOMContentLoaded', function () {
E_F: engineFlight,
title: title
})

})
.then(response => response.json())
.then(data => {
Expand Down Expand Up @@ -797,6 +796,7 @@ document.addEventListener('DOMContentLoaded', function () {
Type: updatedType,
TFrame: updatedTFrame
})

})
.then(response => {
if (response.ok) {
Expand Down Expand Up @@ -881,7 +881,7 @@ document.addEventListener('DOMContentLoaded', function () {
input.style.borderColor = ""; // This will reset the border color to the default or remove it completely
}
}

if (checkInput) {
Swal.fire({
icon: 'error',
Expand Down Expand Up @@ -927,6 +927,7 @@ document.addEventListener('DOMContentLoaded', function () {
.catch(function (error) {
console.error('Error updating event:', error);
});

}
fetch(baseUrl + 'part-maintenance/' + planeSN + '/' + mds + '/' + eqp + '/' + partsn + '/' + partnum + '/', {
method: 'PATCH',
Expand Down Expand Up @@ -1073,7 +1074,7 @@ document.addEventListener('DOMContentLoaded', function () {
function callCalendar(fetchInfo, successCallback, failureCallback, selectedGeoLoc) {
// Make an API call to retrieve the events
// Replace 'YOUR_API_ENDPOINT' with the actual API endpoint URL
fetch(baseUrl + 'calendar/geoloc/' + encodeURIComponent(selectedGeoLoc) + '/')
fetch('calendar/geoloc/' + encodeURIComponent(selectedGeoLoc) + '/')
.then(function (response) {
return response.json();
})
Expand Down Expand Up @@ -1115,8 +1116,9 @@ function callCalendar(fetchInfo, successCallback, failureCallback, selectedGeoLo
});
}

function updateData(successCallback, failureCallback, selectedGeoLoc) {
fetch(baseUrl + 'calendar/geoloc/' + encodeURIComponent(selectedGeoLoc) + '/')

function updateData(fetchInfo, successCallback, failureCallback, selectedGeoLoc) {
fetch('calendar/geoloc/' + encodeURIComponent(selectedGeoLoc) + '/')
.then(response => response.json())
.then(data => {
// Get today's date
Expand All @@ -1130,13 +1132,13 @@ function updateData(successCallback, failureCallback, selectedGeoLoc) {
filteredObjects.forEach(obj => {
// Update the time for each filtered object
if (obj.PlaneMaintenanceID > 0) {
var updatePromise = fetch(baseUrl + 'calendar/planemaintenance/' + obj.PlaneMaintenanceID + '/')
var updatePromise = fetch('calendar/planemaintenance/' + obj.PlaneMaintenanceID + '/')
.then(response => response.json())
.then(data => {
var newDueTime = data.DueTime + data.Freq;
var newTimeRemain = data.Freq;

return fetch(baseUrl + 'calendar/planemaintenance/' + obj.PlaneMaintenanceID + '/', {
return fetch('calendar/planemaintenance/' + obj.PlaneMaintenanceID + '/', {
method: 'PATCH',
headers: {
'Content-Type': 'application/json'
Expand All @@ -1150,7 +1152,7 @@ function updateData(successCallback, failureCallback, selectedGeoLoc) {
.then(response => {
if (response.ok) {
console.log('Object with PlaneMaintenanceID ' + obj.PlaneMaintenanceID + ' updated successfully.');
return fetch(baseUrl + 'calendar/' + obj.CalendarID + '/', {
return fetch('calendar/' + obj.CalendarID + '/', {
method: 'PATCH',
headers: {
'Content-Type': 'application/json'
Expand Down Expand Up @@ -1179,13 +1181,13 @@ function updateData(successCallback, failureCallback, selectedGeoLoc) {

updatePromises.push(updatePromise);
} else if (obj.PartMaintenanceID > 0) {
var updatePromise = fetch(baseUrl + 'calendar/partmaintenance/' + obj.PartMaintenanceID + '/')
var updatePromise = fetch('calendar/partmaintenance/' + obj.PartMaintenanceID + '/')
.then(response => response.json())
.then(data => {
var newDueTime = data.DueTime + data.Freq;
var newTimeRemain = data.Freq;

return fetch(baseUrl + 'calendar/partmaintenance/' + obj.PartMaintenanceID + '/', {
return fetch('calendar/partmaintenance/' + obj.PartMaintenanceID + '/', {
method: 'PATCH',
headers: {
'Content-Type': 'application/json'
Expand All @@ -1199,7 +1201,7 @@ function updateData(successCallback, failureCallback, selectedGeoLoc) {
.then(response => {
if (response.ok) {
console.log('Object with PartMaintenanceID ' + obj.PartMaintenanceID + ' updated successfully.');
return fetch(baseUrl + 'calendar/' + obj.CalendarID + '/', {
return fetch('calendar/' + obj.CalendarID + '/', {
method: 'PATCH',
headers: {
'Content-Type': 'application/json'
Expand Down Expand Up @@ -1244,7 +1246,7 @@ function updateData(successCallback, failureCallback, selectedGeoLoc) {

function callResources(fetchInfo, successCallback, failureCallback, selectedGeoLoc) {
// Fetch the tail numbers from the Plane data model
fetch(baseUrl + 'calendar/geoloc/' + encodeURIComponent(selectedGeoLoc) + '/')
fetch('calendar/geoloc/' + encodeURIComponent(selectedGeoLoc) + '/')
.then(function (response) {
return response.json();
})
Expand Down Expand Up @@ -1275,7 +1277,7 @@ function dropEvent(info) {
var newStart = info.event.start.toISOString().substring(0, 10);
var newEnd = info.event.end.toISOString().substring(0, 10);

fetch(baseUrl + 'calendar/' + eventId + '/', {
fetch('calendar/' + eventId + '/', {
method: 'PATCH',
headers: {
'Content-Type': 'application/json'
Expand Down Expand Up @@ -1306,7 +1308,7 @@ function resizeEvent(info) {
var newEnd = info.event.end.toISOString().substring(0, 10);


fetch(baseUrl + 'calendar/' + eventId + '/', {
fetch('calendar/' + eventId + '/', {
method: 'PATCH',
headers: {
'Content-Type': 'application/json'
Expand Down Expand Up @@ -1339,7 +1341,7 @@ document.addEventListener('DOMContentLoaded', function () {

async function fetchOptions() {
try {
const response = await fetch(baseUrl + 'loc/');
const response = await fetch('loc/');
const data = await response.json();

dropdown = document.getElementById('select');
Expand Down Expand Up @@ -1389,7 +1391,7 @@ function addlocation() {
// Replace the 'API_CALL_URL' with the actual API endpoint
// You can use AJAX, Fetch, or any other method to make the API call
// Example using Fetch API
fetch(baseUrl + 'loc/', {
fetch('loc/', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
Expand Down Expand Up @@ -1424,7 +1426,7 @@ function getSelectedGeoLoc() {
}
function passgeoloc(filename) {
const selectedGeoLoc = getSelectedGeoLoc();
window.location.href = baseUrl + filename + '?geoloc=' + encodeURIComponent(selectedGeoLoc);
window.location.href = filename + '?geoloc=' + encodeURIComponent(selectedGeoLoc);
}

document.addEventListener('DOMContentLoaded', function () {
Expand Down

0 comments on commit 045d841

Please sign in to comment.