Skip to content

Commit

Permalink
new login/logout handling; new UI testing
Browse files Browse the repository at this point in the history
  • Loading branch information
phoenixbf committed Feb 1, 2025
1 parent 507fce7 commit f890caa
Show file tree
Hide file tree
Showing 11 changed files with 277 additions and 83 deletions.
2 changes: 1 addition & 1 deletion public/dist/ATON.min.js

Large diffs are not rendered by default.

22 changes: 21 additions & 1 deletion public/res/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ canvas:active {
position: fixed;
z-index: 100;

background-color: rgba(var(--bs-body-bg-rgb), 0.5) !important;
background-color: rgba(var(--bs-secondary-bg-rgb), 0.7) !important;

-webkit-backdrop-filter: blur(var(--aton-blur-radius));
backdrop-filter: blur(var(--aton-blur-radius));
Expand Down Expand Up @@ -289,6 +289,26 @@ canvas:active {
margin-right: 4px;
}

/* Dropdowns
============*/
.aton-dropdown-menu {
box-shadow: 0px 0px 10px rgba(0,0,0, 0.2);
/*
background-color: rgba(var(--bs-body-bg-rgb), 0.5) !important;
-webkit-backdrop-filter: blur(var(--aton-blur-radius));
backdrop-filter: blur(var(--aton-blur-radius));
*/
}


.aton-dropdown-item {
display: inline-block;
}

.aton-dropdown-item:hover {
background-color: var(--bs-secondary-bg);
}

/* Tabs
============*/
Expand Down
9 changes: 2 additions & 7 deletions public/src/ATON.js
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,7 @@ ATON.realize = ( bNoRender )=>{
//canvas.style.height = "100%";

ATON.UI.init();
ATON.REQ.init();

// Multimedia
ATON._vpanoPlaying = false;
Expand Down Expand Up @@ -907,15 +908,9 @@ ATON.realize2D = ()=>{
ATON._b2D = true;

ATON.UI.init();
ATON.REQ.init();

document.body.classList.add("aton-body2D");
/*
const bs = document.body.style;
bs["overflow"] = "auto";
bs["touch-action"] = "auto";
bs["-webkit-user-drag"] = "auto";
bs["-webkit-tap-highlight-color"] = ""
*/
document.body.oncontextmenu = null;

ATON.EventHub.init();
Expand Down
154 changes: 117 additions & 37 deletions public/src/ATON.req.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,59 @@
/*
ATON Requests Utils
Utilities to perform GET, POST, PUT, PATCH or DELETE requests
Utilities to perform RESTful requests
author: bruno.fanini_AT_gmail.com
===========================================================*/

/**
Utilities to perform GET, POST, PUT, PATCH or DELETE requests
Utilities to perform RESTful requests
@namespace REQ
*/
let REQ = {};

REQ.init = ()=>{
REQ._base = ATON.PATH_RESTAPI2;
};


/**
Change base path/domain to perform RESTful requests
@param {string} base - new base domain for REST API (http://.../api/v1/)
@example
ATON.REQ.setBaseDomain("http://..../api/v1/")
*/
REQ.setBaseDomain = (base)=>{
if (!base.startsWith("http")) return REQ;

REQ._base = base;
return REQ;
};

/**
Perform a GET request
@param {string} endpoint - Endpoint. If local path ("scenes/") perform the request on current server node
@param {function} onResponse - JSON response
@param {function} onResponse - Routine to handle a valid JSON response
@param {function} onError - Routine to handle error
@example
ATON.REQ.get("scenes", data => { console.log(data) })
*/
REQ.get = (endpoint, onResponse, onError)=>{
if (!endpoint.startsWith("http")) endpoint = ATON.PATH_RESTAPI2 + endpoint;
if (!endpoint.startsWith("http")) endpoint = REQ._base + endpoint;

fetch(endpoint, {
credentials: 'include'
})
.then(response => response.json())
.then( onResponse )
.catch( (err)=>{
console.log("ERROR: "+err);
if (onError) onError(err);
.then(response => {
if (!response.ok){
if (onError) onError();
return;
}

response.json().then( onResponse ).catch( (err)=>{
console.log("ERROR: "+err);
if (onError) onError(err);
});
});

return REQ;
Expand All @@ -39,10 +63,11 @@ REQ.get = (endpoint, onResponse, onError)=>{
Perform a POST request
@param {string} endpoint - Endpoint. If local path ("scenes/") perform the request on current server node
@param {object} bodyobj - Body object
@param {function} onResponse - JSON response
@param {function} onResponse - Routine to handle a valid JSON response
@param {function} onError - Routine to handle error
*/
REQ.post = (endpoint, bodyobj, onResponse, onError)=>{
if (!endpoint.startsWith("http")) endpoint = ATON.PATH_RESTAPI2 + endpoint;
if (!endpoint.startsWith("http")) endpoint = REQ._base + endpoint;

fetch(endpoint, {
method: 'POST',
Expand All @@ -52,11 +77,16 @@ REQ.post = (endpoint, bodyobj, onResponse, onError)=>{
'Content-type': 'application/json; charset=UTF-8'
}
})
.then(response => response.json())
.then( onResponse )
.catch( (err)=>{
console.log("ERROR: "+err);
if (onError) onError(err);
.then(response => {
if (!response.ok){
if (onError) onError();
return;
}

response.json().then( onResponse ).catch( (err)=>{
console.log("ERROR: "+err);
if (onError) onError(err);
});
});

return REQ;
Expand All @@ -66,10 +96,11 @@ REQ.post = (endpoint, bodyobj, onResponse, onError)=>{
Perform a PUT request
@param {string} endpoint - Endpoint. If local path ("scenes/") perform the request on current server node
@param {object} bodyobj - Body object
@param {function} onResponse - JSON response
@param {function} onResponse - Routine to handle a valid JSON response
@param {function} onError - Routine to handle error
*/
REQ.put = (endpoint, bodyobj, onResponse, onError)=>{
if (!endpoint.startsWith("http")) endpoint = ATON.PATH_RESTAPI2 + endpoint;
if (!endpoint.startsWith("http")) endpoint = REQ._base + endpoint;

fetch(endpoint, {
method: 'PUT',
Expand All @@ -79,11 +110,16 @@ REQ.put = (endpoint, bodyobj, onResponse, onError)=>{
'Content-type': 'application/json; charset=UTF-8'
}
})
.then(response => response.json())
.then( onResponse )
.catch( (err)=>{
console.log("ERROR: "+err);
if (onError) onError(err);
.then(response => {
if (!response.ok){
if (onError) onError();
return;
}

response.json().then( onResponse ).catch( (err)=>{
console.log("ERROR: "+err);
if (onError) onError(err);
});
});

return REQ;
Expand All @@ -94,10 +130,11 @@ REQ.put = (endpoint, bodyobj, onResponse, onError)=>{
Perform a PATCH request
@param {string} endpoint - Endpoint. If local path ("scenes/") perform the request on current server node
@param {object} bodyobj - Body object
@param {function} onResponse - JSON response
@param {function} onResponse - Routine to handle a valid JSON response
@param {function} onError - Routine to handle error
*/
REQ.patch = (endpoint, bodyobj, onResponse, onError)=>{
if (!endpoint.startsWith("http")) endpoint = ATON.PATH_RESTAPI2 + endpoint;
if (!endpoint.startsWith("http")) endpoint = REQ._base + endpoint;

fetch(endpoint, {
method: 'PATCH',
Expand All @@ -107,11 +144,16 @@ REQ.patch = (endpoint, bodyobj, onResponse, onError)=>{
'Content-type': 'application/json; charset=UTF-8'
}
})
.then(response => response.json())
.then( onResponse )
.catch( (err)=>{
console.log("ERROR: "+err);
if (onError) onError(err);
.then(response => {
if (!response.ok){
if (onError) onError();
return;
}

response.json().then( onResponse ).catch( (err)=>{
console.log("ERROR: "+err);
if (onError) onError(err);
});
});

return REQ;
Expand All @@ -120,24 +162,62 @@ REQ.patch = (endpoint, bodyobj, onResponse, onError)=>{
/**
Perform a DELETE request
@param {string} endpoint - Endpoint. If local path ("scenes/") perform the request on current server node
@param {function} onResponse - JSON response
@param {function} onResponse - Routine to handle a valid JSON response
@param {function} onError - Routine to handle error
*/
REQ.delete = (endpoint, onResponse, onError)=>{
if (!endpoint.startsWith("http")) endpoint = ATON.PATH_RESTAPI2 + endpoint;
if (!endpoint.startsWith("http")) endpoint = REQ._base + endpoint;

fetch(endpoint, {
method: 'DELETE',
credentials: 'include',
})
.then(response => response.json())
.then( onResponse )
.catch( (err)=>{
console.log("ERROR: "+err);
if (onError) onError(err);
.then(response => {
if (!response.ok){
if (onError) onError();
return;
}

response.json().then( onResponse ).catch( (err)=>{
console.log("ERROR: "+err);
if (onError) onError(err);
});
});

return REQ;
};

/**
Request login on current node
@param {string} uname - Username
@param {string} passw - Password
@param {function} onSuccess - Routine to handle successful login, data is user
@param {function} onFail - Routine to handle failed login
*/
REQ.login = (uname, passw, onSuccess, onFail)=>{
return REQ.post("login",
{
username: uname,
password: passw
},
(r)=>{
if (r && onSuccess) onSuccess(r);
else if (onFail) onFail();
},
(e)=>{
if (onFail) onFail();
}
);
};

/**
Request logout on current node
@param {function} onSuccess - Routine to handle successful login, data is user
@param {function} onFail - Routine to handle failed login
*/
REQ.logout = (onSuccess, onFail)=>{
return REQ.get("logout", onSuccess, onFail);
};


export default REQ;
Loading

0 comments on commit f890caa

Please sign in to comment.