forked from PeachCloud/peach-workspace
remove status update logic
This commit is contained in:
parent
e5f9a9be83
commit
ee1da0599c
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
|
|
||||||
behavioural layer for the `network_card.html.tera` template,
|
behavioural layer for the `network_card.html.tera` template,
|
||||||
corresponding to the web route `/network`
|
corresponding to the web route `/settings/network`
|
||||||
|
|
||||||
- intercept form submissions
|
- intercept form submissions
|
||||||
- perform json api calls
|
- perform json api calls
|
||||||
@ -11,10 +11,8 @@ methods:
|
|||||||
|
|
||||||
PEACH_NETWORK.activateAp();
|
PEACH_NETWORK.activateAp();
|
||||||
PEACH_NETWORK.activateClient();
|
PEACH_NETWORK.activateClient();
|
||||||
PEACH_NETWORK.apOnline();
|
PEACH_NETWORK.apMode();
|
||||||
PEACH_NETWORK.clientOffline();
|
PEACH_NETWORK.clientMode();
|
||||||
PEACH_NETWORK.clientOnline();
|
|
||||||
PEACH_NETWORK.flashMsg(status, msg);
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -29,7 +27,7 @@ PEACH_NETWORK.activateAp = function() {
|
|||||||
// prevent form submission (default behavior)
|
// prevent form submission (default behavior)
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
// write in-progress status message to ui
|
// write in-progress status message to ui
|
||||||
PEACH_NETWORK.flashMsg("info", "Deploying access point...");
|
PEACH.flashMsg("info", "Deploying access point...");
|
||||||
// send activate_ap POST request
|
// send activate_ap POST request
|
||||||
fetch("/api/v1/network/activate_ap", {
|
fetch("/api/v1/network/activate_ap", {
|
||||||
method: "post",
|
method: "post",
|
||||||
@ -44,10 +42,10 @@ PEACH_NETWORK.activateAp = function() {
|
|||||||
.then( (jsonData) => {
|
.then( (jsonData) => {
|
||||||
console.log(jsonData.msg);
|
console.log(jsonData.msg);
|
||||||
// write json response message to ui
|
// write json response message to ui
|
||||||
PEACH_NETWORK.flashMsg(jsonData.status, jsonData.msg);
|
PEACH.flashMsg(jsonData.status, jsonData.msg);
|
||||||
// if ap activation is successful, update the ui
|
// if ap activation is successful, update the ui
|
||||||
if (jsonData.status === "success") {
|
if (jsonData.status === "success") {
|
||||||
PEACH_NETWORK.apOnline();
|
PEACH_NETWORK.apMode();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}, false);
|
}, false);
|
||||||
@ -64,7 +62,7 @@ PEACH_NETWORK.activateClient = function() {
|
|||||||
// prevent form submission (default behavior)
|
// prevent form submission (default behavior)
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
// write in-progress status message to ui
|
// write in-progress status message to ui
|
||||||
PEACH_NETWORK.flashMsg("info", "Enabling WiFi client...");
|
PEACH.flashMsg("info", "Enabling WiFi client...");
|
||||||
// send activate_ap POST request
|
// send activate_ap POST request
|
||||||
fetch("/api/v1/network/activate_client", {
|
fetch("/api/v1/network/activate_client", {
|
||||||
method: "post",
|
method: "post",
|
||||||
@ -79,10 +77,10 @@ PEACH_NETWORK.activateClient = function() {
|
|||||||
.then( (jsonData) => {
|
.then( (jsonData) => {
|
||||||
console.log(jsonData.msg);
|
console.log(jsonData.msg);
|
||||||
// write json response message to ui
|
// write json response message to ui
|
||||||
PEACH_NETWORK.flashMsg(jsonData.status, jsonData.msg);
|
PEACH.flashMsg(jsonData.status, jsonData.msg);
|
||||||
// if client activation is successful, update the ui
|
// if client activation is successful, update the ui
|
||||||
if (jsonData.status === "success") {
|
if (jsonData.status === "success") {
|
||||||
PEACH_NETWORK.clientOnline();
|
PEACH_NETWORK.clientMode();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}, false);
|
}, false);
|
||||||
@ -90,21 +88,12 @@ PEACH_NETWORK.activateClient = function() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// update ui for access point mode (status: online)
|
// replace 'Deploy Access Point' button with 'Enable WiFi' button
|
||||||
PEACH_NETWORK.apOnline = function() {
|
PEACH_NETWORK.apMode = function() {
|
||||||
console.log('Activating AP Mode');
|
|
||||||
|
|
||||||
// update network mode and status (icon & label)
|
|
||||||
let i = document.getElementById("netModeIcon");
|
|
||||||
i.className = "center icon icon-active";
|
|
||||||
i.src = "icons/router.svg";
|
|
||||||
let l = document.getElementById("netModeLabel");
|
|
||||||
l.textContent = "ONLINE";
|
|
||||||
|
|
||||||
// create Enable WiFi button and add it to button div
|
// create Enable WiFi button and add it to button div
|
||||||
var wifiButton = document.createElement("A");
|
var wifiButton = document.createElement("A");
|
||||||
wifiButton.className = "button center";
|
wifiButton.className = "button center";
|
||||||
wifiButton.href = "/network/wifi/activate";
|
wifiButton.href = "/settings/network/wifi/activate";
|
||||||
wifiButton.id = "connectWifi";
|
wifiButton.id = "connectWifi";
|
||||||
var label = "Enable WiFi";
|
var label = "Enable WiFi";
|
||||||
var buttonText = document.createTextNode(label);
|
var buttonText = document.createTextNode(label);
|
||||||
@ -114,88 +103,31 @@ PEACH_NETWORK.apOnline = function() {
|
|||||||
let buttons = document.getElementById("buttons");
|
let buttons = document.getElementById("buttons");
|
||||||
buttons.appendChild(wifiButton);
|
buttons.appendChild(wifiButton);
|
||||||
|
|
||||||
// remove the old 'Activate Access Point' button
|
// remove the old 'Deploy Access Point' button
|
||||||
let apButton = document.getElementById("deployAccessPoint");
|
let apButton = document.getElementById("deployAccessPoint");
|
||||||
apButton.style = "display: none;";
|
apButton.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
// update ui for wifi client mode (status: online)
|
// replace 'Enable WiFi' button with 'Deploy Access Point' button
|
||||||
PEACH_NETWORK.clientOnline = function() {
|
PEACH_NETWORK.clientMode = function() {
|
||||||
console.log('Activating Client Mode');
|
// create Deploy Access Point button and add it to button div
|
||||||
|
var apButton = document.createElement("A");
|
||||||
|
apButton.className = "button center";
|
||||||
|
apButton.href = "/settings/network/ap/activate";
|
||||||
|
apButton.id = "deployAccessPoint";
|
||||||
|
var label = "Deploy Access Point";
|
||||||
|
var buttonText = document.createTextNode(label);
|
||||||
|
apButton.appendChild(buttonText);
|
||||||
|
|
||||||
// update network mode and status (icon & label)
|
// append the new button to the buttons div
|
||||||
let i = document.getElementById("netModeIcon");
|
let buttons = document.getElementById("buttons");
|
||||||
i.className = "center icon icon-active";
|
buttons.appendChild(apButton);
|
||||||
i.src = "icons/wifi.svg";
|
|
||||||
let l = document.getElementById("netModeLabel");
|
|
||||||
l.textContent = "ONLINE";
|
|
||||||
|
|
||||||
// TODO: think about updates for buttons (transition from ap mode)
|
// remove the old 'Enable Wifi' button
|
||||||
}
|
let wifiButton = document.getElementById("connectWifi");
|
||||||
|
wifiButton.remove();
|
||||||
// update ui for wifi client mode (status: offline)
|
|
||||||
PEACH_NETWORK.clientOffline = function() {
|
|
||||||
console.log('Activating Client Mode');
|
|
||||||
|
|
||||||
// update network mode and status (icon & label)
|
|
||||||
let i = document.getElementById("netModeIcon");
|
|
||||||
i.className = "center icon icon-inactive";
|
|
||||||
i.src = "icons/wifi.svg";
|
|
||||||
let l = document.getElementById("netModeLabel");
|
|
||||||
l.textContent = "OFFLINE";
|
|
||||||
|
|
||||||
// TODO: think about updates for buttons (transition from ap mode)
|
|
||||||
}
|
|
||||||
|
|
||||||
// display a message by appending a paragraph element
|
|
||||||
PEACH_NETWORK.flashMsg = function(status, msg) {
|
|
||||||
// set the class of the element according to status
|
|
||||||
var elementClass;
|
|
||||||
if (status === "success") {
|
|
||||||
elementClass = "capsule center-text flash-message font-success";
|
|
||||||
} else if (status === "info") {
|
|
||||||
elementClass = "capsule center-text flash-message font-info";
|
|
||||||
} else {
|
|
||||||
elementClass = "capsule center-text flash-message font-failure";
|
|
||||||
};
|
|
||||||
|
|
||||||
var flashElement = document.getElementById("flashMsg");
|
|
||||||
// if flashElement exists, update the class & text
|
|
||||||
if (flashElement) {
|
|
||||||
flashElement.className = elementClass;
|
|
||||||
flashElement.innerText = msg;
|
|
||||||
// if flashElement does not exist, create it, set id, class, text & append
|
|
||||||
} else {
|
|
||||||
// create new div for flash message
|
|
||||||
var flashDiv = document.createElement("DIV");
|
|
||||||
// set div attributes
|
|
||||||
flashDiv.id = "flashMsg";
|
|
||||||
flashDiv.className = elementClass;
|
|
||||||
// add json response message to flash message div
|
|
||||||
var flashMsg = document.createTextNode(msg);
|
|
||||||
flashDiv.appendChild(flashMsg);
|
|
||||||
// insert the flash message div above the three icon grid div
|
|
||||||
var gridDiv = document.getElementById("gridDiv");
|
|
||||||
gridDiv.parentNode.insertBefore(flashDiv, gridDiv);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var networkInstance = PEACH_NETWORK;
|
var networkInstance = PEACH_NETWORK;
|
||||||
networkInstance.activateAp();
|
networkInstance.activateAp();
|
||||||
networkInstance.activateClient();
|
networkInstance.activateClient();
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
async function exampleFetch() {
|
|
||||||
const response = await fetch('/api/v1/network/state');
|
|
||||||
const myJson = await response.json();
|
|
||||||
//const jsonData = JSON.parse(myJson);
|
|
||||||
console.log(myJson.data.wlan0);
|
|
||||||
//var state = document.createElement("P");
|
|
||||||
//state.innerText = ""jsonData.wlan0;
|
|
||||||
//document.body.appendChild(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
exampleFetch()
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user