From d80fff5d9ede01b602223b205f89c02ceb51cf69 Mon Sep 17 00:00:00 2001 From: juanmglzs Date: Thu, 30 Mar 2023 07:07:19 +0200 Subject: [PATCH] Update changes until now. Data access and Session manager --- webapp/src/App.js | 37 +++++-------------- webapp/src/components/ModalDialogue.js | 2 +- webapp/src/handlers/controller.js | 31 ++++++++++++++++ .../handlers/{PodAccess.js => podAccess.js} | 19 +++++----- .../handlers/{PodHandler.js => podHandler.js} | 0 webapp/src/handlers/sessionManager.js | 35 ++++++++++++++++++ .../src/models/{Location.js => location.js} | 2 +- webapp/src/models/{Review.js => review.js} | 0 webapp/src/models/{User.js => user.js} | 6 ++- .../{Exceptions.js => exceptions.js} | 0 10 files changed, 91 insertions(+), 41 deletions(-) create mode 100644 webapp/src/handlers/controller.js rename webapp/src/handlers/{PodAccess.js => podAccess.js} (93%) rename webapp/src/handlers/{PodHandler.js => podHandler.js} (100%) create mode 100644 webapp/src/handlers/sessionManager.js rename webapp/src/models/{Location.js => location.js} (97%) rename webapp/src/models/{Review.js => review.js} (100%) rename webapp/src/models/{User.js => user.js} (96%) rename webapp/src/util/Exceptions/{Exceptions.js => exceptions.js} (100%) diff --git a/webapp/src/App.js b/webapp/src/App.js index e570c7e..b2406f1 100644 --- a/webapp/src/App.js +++ b/webapp/src/App.js @@ -2,38 +2,23 @@ import './views/styles/App.css'; import { SessionProvider} from "@inrupt/solid-ui-react"; import { useState} from "react"; import LoginForm from "./views/loginView" -import { useSession } from "@inrupt/solid-ui-react/dist"; -import { checkForLomap } from './handlers/PodHandler'; -import { requestAccessToLomap } from './handlers/PodHandler'; import AuthenticatedUserView from "./views/mapView"; -import {User} from "./models/User"; -import {writeLocations1} from "./handlers/PodAccess"; +import {Controller} from "./handlers/controller"; + -const {session} = useSession(); export default function App() { -//We use this state variable + //We use this state variable const [isLoggedIn, setIsLoggedIn] = useState(false); + const crl = new Controller(); + //With this we can control the login status for solid + //const {session} = useSession(); -//With this we can control the login status for solid - - const user = new User(); - -//We have logged in - session.onLogin(async () => { - - user.podURL = await checkForLomap(session); - setIsLoggedIn(true); - - }); -//We have logged out - session.onLogout(async () => { + crl.sessionHandler(isLoggedIn); + setIsLoggedIn(crl.getSessionState()); - await writeLocations1(session, user); - setIsLoggedIn(false) - }) return ( @@ -43,8 +28,4 @@ export default function App() ) -} - - - - +} \ No newline at end of file diff --git a/webapp/src/components/ModalDialogue.js b/webapp/src/components/ModalDialogue.js index 6f8ddc1..4271476 100644 --- a/webapp/src/components/ModalDialogue.js +++ b/webapp/src/components/ModalDialogue.js @@ -1,5 +1,5 @@ import React, {useEffect} from "react"; -import {requestAccessToLomap} from "../handlers/PodHandler"; +import {requestAccessToLomap} from "../handlers/podHandler"; //import DropdownList from "react-widgets/DropdownList"; import {Box, Button, Modal, Typography} from "@mui/material"; import {LogoutButton, SessionProvider, useSession} from "@inrupt/solid-ui-react"; diff --git a/webapp/src/handlers/controller.js b/webapp/src/handlers/controller.js new file mode 100644 index 0000000..cb0421c --- /dev/null +++ b/webapp/src/handlers/controller.js @@ -0,0 +1,31 @@ +import {SessionManager} from "./sessionManager"; + +class Controller{ + sessionMng; + constructor() { + this.sessionMng = new SessionManager(); + this.user = new User(); + } + + /** + * This method handles the session + * @param isLoggedInValue + * @returns {Controller} + */ + sessionHandler(){ + this.sessionMng.sessionState(); + return this; + } + + getSessionState(){ + return this.sessionMng.isLoggedIn; + } + + getSession(){ + return this.sessionMng.session; + } +} + +export{ + Controller, +} \ No newline at end of file diff --git a/webapp/src/handlers/PodAccess.js b/webapp/src/handlers/podAccess.js similarity index 93% rename from webapp/src/handlers/PodAccess.js rename to webapp/src/handlers/podAccess.js index a5fa0b8..d0d2529 100644 --- a/webapp/src/handlers/PodAccess.js +++ b/webapp/src/handlers/podAccess.js @@ -1,6 +1,6 @@ import{ User -} from "../models/User"; +} from "../models/user"; // Import from "@inrupt/solid-client" import { @@ -15,9 +15,9 @@ import { } from "@inrupt/solid-client"; import { SCHEMA_INRUPT, RDF} from "@inrupt/vocab-common-rdf"; import {getDefaultSession} from "@inrupt/solid-client-authn-browser"; -import {checkForLomap} from "./PodHandler"; -import {LocationLM} from "../models/Location"; -import {CoordinatesInvalidFormatException, StringInvalidFormatException} from "../util/Exceptions/Exceptions"; +import {checkForLomap} from "./podHandler"; +import {LocationLM} from "../models/location"; +import {CoordinatesInvalidFormatException, StringInvalidFormatException} from "../util/Exceptions/exceptions"; /** * Save user's session changes into de POD. @@ -117,10 +117,9 @@ async function readLocations(resourceURL) { // Get all Things in a SolidDataset. Returns: Thing[] let items = getThingAll(mySolidDataset); //Initialize aux list - let listcontentAux = []; - for (let i = 0; i < items.length; i++) { + let listContentAux = []; + items.forEach(item => { //Get a Thing - let item = items[i]; try { //Convert into LocationLM object let loc = new LocationLM( @@ -132,7 +131,7 @@ async function readLocations(resourceURL) { getStringNoLocale(item, SCHEMA_INRUPT.alternateName), // category ); //Add locationLM into List - listcontentAux.push(loc); + listContentAux.push(loc); } catch (error){ if(error instanceof CoordinatesInvalidFormatException || error instanceof StringInvalidFormatException){ //Handle error while parsing @@ -140,9 +139,9 @@ async function readLocations(resourceURL) { console.error(error.message); } } - } + }) //Return list - return listcontentAux; + return listContentAux; } export { diff --git a/webapp/src/handlers/PodHandler.js b/webapp/src/handlers/podHandler.js similarity index 100% rename from webapp/src/handlers/PodHandler.js rename to webapp/src/handlers/podHandler.js diff --git a/webapp/src/handlers/sessionManager.js b/webapp/src/handlers/sessionManager.js new file mode 100644 index 0000000..dea45bc --- /dev/null +++ b/webapp/src/handlers/sessionManager.js @@ -0,0 +1,35 @@ +import {useSession} from "@inrupt/solid-ui-react"; +import {checkForLomap} from "./podHandler"; +import * as sessionMetho from "@inrupt/solid-client-authn-browser"; +import {User} from "../models/user"; + +class SessionManager{ + //With this we can control the login status for solid + //session; + session = sessionMetho; + isLoggedIn = false; + user + constructor() { + //this.session = useSession(); + this.session.getDefaultSession() + //this.session = sessionMetho.getDefaultSession(); + } + + sessionState() { + //We have logged in + this.session.onLogin(async () => { + let pod = await checkForLomap(this.session); + this.user.setPodURL(pod); + this.isLoggedIn = true; + + }); + //We have logged out + this.session.onLogout(() => { + this.isLoggedIn = false; + }) + } +} + +export { + SessionManager, +} \ No newline at end of file diff --git a/webapp/src/models/Location.js b/webapp/src/models/location.js similarity index 97% rename from webapp/src/models/Location.js rename to webapp/src/models/location.js index f230742..1485ca5 100644 --- a/webapp/src/models/Location.js +++ b/webapp/src/models/location.js @@ -6,7 +6,7 @@ import { import { CoordinatesInvalidFormatException, StringInvalidFormatException -} from '../util/Exceptions/Exceptions.js'; +} from '../util/Exceptions/exceptions.js'; /** * Location LoMap class diff --git a/webapp/src/models/Review.js b/webapp/src/models/review.js similarity index 100% rename from webapp/src/models/Review.js rename to webapp/src/models/review.js diff --git a/webapp/src/models/User.js b/webapp/src/models/user.js similarity index 96% rename from webapp/src/models/User.js rename to webapp/src/models/user.js index 60a09fc..8c76f38 100644 --- a/webapp/src/models/User.js +++ b/webapp/src/models/user.js @@ -1,4 +1,4 @@ -import {LocationLM} from "./Location"; +import {LocationLM} from "./location"; /** * User LoMap class */ @@ -71,6 +71,10 @@ class User{ } } } + + setPodURL(pod){ + this.podURL = pod; + } } export {User}; \ No newline at end of file diff --git a/webapp/src/util/Exceptions/Exceptions.js b/webapp/src/util/Exceptions/exceptions.js similarity index 100% rename from webapp/src/util/Exceptions/Exceptions.js rename to webapp/src/util/Exceptions/exceptions.js