88 lines
2.3 KiB
JavaScript
88 lines
2.3 KiB
JavaScript
// Global variables
|
|
let global_project_list;
|
|
let current_project = "";
|
|
|
|
function formatDate(isoString) {
|
|
const date = new Date(isoString);
|
|
|
|
const options = {
|
|
year: "numeric",
|
|
month: "long",
|
|
day: "numeric",
|
|
hour: "numeric",
|
|
minute: "numeric",
|
|
second: "numeric",
|
|
timeZoneName: "short",
|
|
};
|
|
|
|
return date.toLocaleString("en-US", options);
|
|
}
|
|
// Function to get data from API
|
|
|
|
function getAllProject() {
|
|
return $.ajax({
|
|
url: api_url.concat("/projects"),
|
|
method: "GET",
|
|
dataType: "json"
|
|
}).then((data) => {
|
|
return data;
|
|
});
|
|
}
|
|
|
|
function getDataMetrics(projectId){
|
|
return $.ajax({
|
|
url: api_url.concat(`/projects/${projectId}/measurements`),
|
|
method: "GET",
|
|
dataType: "json",
|
|
}).then((data) => {
|
|
// If the request is successful, store the data in the cache and return it
|
|
localStorage.setItem("project_list", JSON.stringify(data));
|
|
return data;
|
|
});
|
|
}
|
|
|
|
|
|
async function getDataProjectVideosFromApi(id) {
|
|
try {
|
|
const response = await $.ajax({
|
|
url: api_url.concat(`/projects/${id}/videos`),
|
|
method: "GET",
|
|
dataType: "json",
|
|
});
|
|
// If the request is successful, store the data in the cache and return it
|
|
return response;
|
|
} catch (error) {
|
|
console.error("Error fetching data:", error);
|
|
throw error; // Re-throw the error to handle it outside the function if needed
|
|
}
|
|
}
|
|
|
|
async function getDataVideoFromApi(id) {
|
|
try {
|
|
const response = await $.ajax({
|
|
url: api_url.concat(`/videos/${id}`),
|
|
method: "GET",
|
|
dataType: "json",
|
|
});
|
|
// If the request is successful, store the data in the cache and return it
|
|
return response;
|
|
} catch (error) {
|
|
console.error("Error fetching data:", error);
|
|
throw error; // Re-throw the error to handle it outside the function if needed
|
|
}
|
|
}
|
|
|
|
async function postNewVideo(project_id, measurements_id, name_video, resolution, duration){
|
|
try {
|
|
const response = await $.ajax({
|
|
url: api_url.concat(`/videos/`),
|
|
method: "POST",
|
|
dataType: "json",
|
|
});
|
|
// If the request is successful, store the data in the cache and return it
|
|
} catch (error) {
|
|
console.error("Error fetching data:", error);
|
|
throw error; // Re-throw the error to handle it outside the function if needed
|
|
}
|
|
}
|