This commit is contained in:
Leo
2024-01-24 15:51:56 +08:00
54 changed files with 812 additions and 999 deletions

View File

@ -144,6 +144,34 @@ app.api = (function (app) {
return { post: post, get: get, put: put, delete: remove };
})(app);
//socket.io
//socket.io
app.socket = (function (app) {
//need to replace with domain name of server when published
var socket = io();
socket.on("disconnect", () => {
console.log("disconnected");
});
socket.on('connect', ()=>{
console.info('WS connected');
})
socket.io.on("reconnect", () => {
console.log("reconnected");
});
socket.io.on("connect_error", (err) => {
console.log(err);
});
return socket;
})(app);
//sensor data
app.sensordata = (function (app) {
})(app);
app.auth = (function (app) {
var user = {};
function setToken(token) {
@ -154,18 +182,20 @@ app.auth = (function (app) {
return localStorage.getItem("APIToken");
}
function isLoggedIn(callback) {
if (getToken()) {
return app.api.get("user/me", function (error, data) {
if (!error) app.auth.user = data;
//for navbar to show username
$.scope.getUsername.update(data);
if (!location.pathname === "/login")
{
$.scope.getUsername.update(data);
}
//for edit profile to show user details
//if not in edit profile page, it will not show
if (location.pathname === "/profile")
{
if (location.pathname === "/profile") {
$.scope.getUserDetails.update(data);
}
return callback(error, data);
@ -232,12 +262,9 @@ app.auth = (function (app) {
logInRedirect,
homeRedirect,
profileRedirect,
//showUser,
//redirectIfLoggedIn,
};
})(app);
app.user = (function (app) {
//delete profile
function deleteProfile() {
@ -250,12 +277,10 @@ app.user = (function (app) {
});
}
});
}
return {
deleteProfile,
};
})(app);
//ajax form submit and pass to api