Profile management added.

This commit is contained in:
2024-03-09 08:29:51 +00:00
parent 6fffdc8743
commit cefa5d99b0
3 changed files with 190 additions and 23 deletions

View File

@@ -24,7 +24,60 @@ setInterval(function () {
});
myChart.update();
}
}, 4000);
}, 40000);
async function fetchData(url) {
let raw = await fetch(url);
let data = await raw.json();
return data;
}
async function listProfiles() {
let list = document.getElementById('profilesList');
list.innerHTML = '';
let raw = await fetch("/profile/list");
let profiles = await raw.json();
profiles.forEach((profile, idx)=>{
const node = document.createElement('li');
node.classList.add("collection-item");
node.innerHTML = '<div>'+profile+'<a href="#!" class="secondary-content" onclick="getProfile(\'' + profile + '\')"><i class="material-icons">cloud_download</i></a></div>';
list.appendChild(node);
});
}
async function getProfile(name) {
let raw = await fetch('/profile/?name='+name);
let profile = await raw.json();
myChart.data.datasets[0].data = profile.values;
document.getElementById("profileName").value = profile.name;
myChart.update();
}
function saveProfile() {
const data = new URLSearchParams();
data.append('name',document.getElementById('profileName').value);
data.append('values',myChart.data.datasets[0].data);
fetch('/profile/save', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: data
})
listProfiles();
}
function deleteProfile() {
const data = new URLSearchParams();
data.append('name',document.getElementById('profileName').value);
fetch('/profile/delete', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: data
})
listProfiles();
}
function setXmax() {
myChart.data.datasets[0].data[9].x = document.getElementById('xmax').value;
@@ -42,18 +95,15 @@ function setTarget() {
})
}
function getPID() {
const url = '/pid';
fetch(url)
.then((respone)=>{
return respone.json();
})
.then((data)=>{
document.getElementById('kp').value = data.kp || -1;
document.getElementById('ki').value = data.ki || -1;
document.getElementById('kd').value = data.kd || -1;
M.updateTextFields();
})
async function getPID() {
let raw = await fetch('/pid');
let data = await raw.json();
document.getElementById('kp').value = data.kp || -1;
document.getElementById('ki').value = data.ki || -1;
document.getElementById('kd').value = data.kd || -1;
M.updateTextFields();
}
function setPID() {
@@ -62,7 +112,7 @@ function setPID() {
data.append('ki', document.getElementById('ki').value);
data.append('kd', document.getElementById('kd').value);
fetch('/pid', {
method: 'GET',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},