diff --git a/neurofusion/next-client/src/components/layouts/dashboard-layout/sidebar/data.ts b/neurofusion/next-client/src/components/layouts/dashboard-layout/sidebar/data.ts index 027da752..3decaf02 100644 --- a/neurofusion/next-client/src/components/layouts/dashboard-layout/sidebar/data.ts +++ b/neurofusion/next-client/src/components/layouts/dashboard-layout/sidebar/data.ts @@ -4,17 +4,17 @@ export const sidebarLinks = [ { icon: LayoutDashboard, title: "Lab", - href: "/lab/playground", + href: "/playground", }, { icon: Plug, title: "Integrations", - href: "/lab/integrations", + href: "/integrations", }, { icon: HardDrive, title: "Datasets", - href: "/lab/datasets", + href: "/datasets", }, { icon: SignalHigh, diff --git a/neurofusion/next-client/src/lib/azure.ts b/neurofusion/next-client/src/lib/azure.ts index 1b70fcb0..101ce2d9 100644 --- a/neurofusion/next-client/src/lib/azure.ts +++ b/neurofusion/next-client/src/lib/azure.ts @@ -4,7 +4,7 @@ import JSZip from 'jszip'; import { saveAs } from 'file-saver'; import { getSession } from 'next-auth/react' -export const getDatasets = async (startDate:any, endDate:any) => { +export const getDatasets = async (startDate:string, endDate:string) => { const session = await getSession() if(!session?.user) return [] const res = await axios.get( @@ -21,8 +21,6 @@ export const getDatasets = async (startDate:any, endDate:any) => { ); if (res.status == 200) { - console.log("avaliable datasets"); - console.log(res.data); return res.data.blobNames; } else { console.error(`unable to fetch datasets`); diff --git a/neurofusion/next-client/src/pages/api/auth/[...nextauth].ts b/neurofusion/next-client/src/pages/api/auth/[...nextauth].ts index d7c38bbd..971d6326 100644 --- a/neurofusion/next-client/src/pages/api/auth/[...nextauth].ts +++ b/neurofusion/next-client/src/pages/api/auth/[...nextauth].ts @@ -24,7 +24,7 @@ export const authOptions: NextAuthOptions = { }, callbacks: { async redirect() { - return "/lab/playground"; + return "/playground"; }, async jwt({ token, user }) { if (user) { diff --git a/neurofusion/next-client/src/pages/auth/login.tsx b/neurofusion/next-client/src/pages/auth/login.tsx index 23ff9b0c..25505225 100644 --- a/neurofusion/next-client/src/pages/auth/login.tsx +++ b/neurofusion/next-client/src/pages/auth/login.tsx @@ -52,7 +52,7 @@ export const getServerSideProps: GetServerSideProps = async ({ req, res }) => { if (session) { return { redirect: { - destination: "/lab/integrations", + destination: "/integrations", permanent: false, }, }; diff --git a/neurofusion/next-client/src/pages/lab/datasets.tsx b/neurofusion/next-client/src/pages/lab/datasets.tsx deleted file mode 100644 index b435e9d6..00000000 --- a/neurofusion/next-client/src/pages/lab/datasets.tsx +++ /dev/null @@ -1,294 +0,0 @@ -import { GetServerSideProps, NextPage } from "next"; -import { getServerSession } from "next-auth"; - - -import { IntegrationsContainer } from "~/components/features/integrations"; -import { DashboardLayout } from "~/components/layouts"; - -import axios from "axios"; -import { FC, useState, useEffect } from "react"; - -import { authOptions } from "../api/auth/[...nextauth]"; - - -import dayjs from "dayjs"; - -import {Button - -} from "~/components/ui/button/button"; // Replace this with the actual path to your dropdown menu script -import { timeStamp } from "console"; -import { Type } from "lucide-react"; -import { object } from "zod"; - -import {getDatasets,downloadDatasets} from "~/lib"; - -const dataSetParser = (data:Array) => { - var recordings:{[key:number]:any} = {} - - data.forEach((item: string) => { - const fname = item.split("/").pop(); - if(fname !== undefined){ - const timestamp:number = parseInt(fname.substring(fname.lastIndexOf("_") + 1, fname.lastIndexOf(".json"))); - if(!(timestamp in recordings)) recordings[timestamp] = []; - recordings[timestamp].push(item) - } - }); - - return recordings - -} - -const DatasetPage: NextPage = () => { - return ( - - - - ); -}; -export const DataDisplay: FC = () => { - - - const [filterStartDate, setFilterStartDate] = useState( - dayjs().subtract(15, "week").format("YYYY-MM-DD") - ); - - const [datasets, setDatasets] = useState<{[key: string]: any}>(({})); - - - const getRange = () => { - - } - - - const [checkedDict, setCheckedDict] = useState({}); - - const createCheckedDict = (dict:any,setter:any) => { - - const createMirrorRecurse = (dictLevel:any) => { - var returnDict:{[key:string]:any} = {checked:false,dict:{}} - if(isDictionary(dictLevel)){ - Object.keys(dictLevel).forEach((x:string)=>{ - returnDict.dict[x] = createMirrorRecurse(dictLevel[x]) - }) - }else{ - returnDict.dict = [...dictLevel] - } - - return returnDict; - } - var copydict = createMirrorRecurse(dict) - // console.log(copydict); - - setter(copydict); - } - - - useEffect(() => { - (async () => { - const dataSets = dataSetParser(await getDatasets( - dayjs.unix(1).format("YYYY-MM-DD"),// add 1 day to include today - dayjs().add(1, "day").format("YYYY-MM-DD"))); - - const orderedTimes = Object.keys(dataSets).map((str)=>parseInt(str)).sort(); - var orgDataSets: {[key:string]:any} = {"All":{}}; - - orderedTimes.forEach((time) =>{ - const timeStamp = dayjs.unix(time); - if(!(timeStamp.format("YYYY") in orgDataSets["All"]))orgDataSets["All"][timeStamp.format("YYYY")] = {} - if(!(timeStamp.format("MMMM") in orgDataSets["All"][timeStamp.format("YYYY")])) orgDataSets["All"][timeStamp.format("YYYY")][timeStamp.format("MMMM")] = {} - if(!(timeStamp.format("DD") in orgDataSets["All"][timeStamp.format("YYYY")][timeStamp.format("MMMM")])) orgDataSets["All"][timeStamp.format("YYYY")][timeStamp.format("MMMM")][timeStamp.format("DD")] = {} - orgDataSets["All"][timeStamp.format("YYYY")][timeStamp.format("MMMM")][timeStamp.format("DD")][timeStamp.format("YYYY-MM-DD h:mm:ss A")+" - EEG"] = dataSets[time]; - }); - - createCheckedDict(orgDataSets["All"],setCheckedDict); - - setDatasets( - orgDataSets["All"] - ); - - // TODO: parse datasets into provider, dataName, time format - })(); - }, []); - - const [fSelected,setFSelected]= useState(Array) - - function isDictionary(variable:any) { - return typeof variable === 'object' && !Array.isArray(variable) && variable !== null; - } - - const recurseSet = (level:any,checked:boolean,checkCopy:object) => { - var head:any = checkCopy; - - level.forEach((ele:any)=>{ - head = head.dict[ele]; - }); - - head.checked = (checked) - - if(isDictionary(head.dict)){ - Object.keys(head.dict).forEach((x:any)=>{ - const arr = [...level]; - arr.push(x); - recurseSet(arr,checked,checkCopy)}) - }else{ - - } - return checkCopy - } - - const genHandler = (level:Array) => { - const handleCheckboxChange = (event:any) => { - var subDirs: {[key:string]:any} = datasets - level.forEach((ele)=>{ - subDirs = subDirs[ele]; - }); - setCheckedDict(recurseSet(level,event.target.checked,structuredClone(checkedDict))); - } - - var head : {[key:string]:any} = checkedDict - level.forEach((ele:any)=>{ - head = head.dict[ele]; - }); - - return {"handler":handleCheckboxChange,"checked":head.checked}; - }; - - useEffect(() => { - const recurseAdd = (head:any) => { - - var arr:Array = []; - - if(isDictionary(head.dict)){ - Object.keys(head.dict).forEach((x:any)=>{ - arr = arr.concat(recurseAdd(head.dict[x]))}) - }else{ - if(head.checked){ - arr = arr.concat(head.dict) - } - } - return arr; - } - setFSelected(recurseAdd(checkedDict)); - }, [checkedDict]); - - const clearSelection = () =>{ - setCheckedDict(recurseSet([],false,structuredClone(checkedDict))); - }; - - const [downloadStatus,setDownloadStatus] = useState(100) - - async function downloadSelection(){ - if(!fSelected.length) return; - setDownloadStatus(0); - console.log(`Downloading`,fSelected) - - await downloadDatasets(structuredClone(fSelected),setDownloadStatus) - setDownloadStatus(100); - }; - - const CircularProgress: React.FC<{percentage: number}> = ({percentage}) => { - return ( - - - - {`${Math.floor(percentage)}%`} - - - ); -} - -return ( - <> -
-
- - {downloadStatus != 100 ? <>

Downloading files please remain on page

: - <> -

{fSelected.length} Files selected

- - } -
- { - - - { - return ( { - return( { - return ( { - return( { - return rec.split("/").pop() - })}>) - })}> - - )})}> - - )})}> - )})}> - - - } - -
- - ); - -}; - -interface CollapsibleListProps { // the parameters requrired for collaspable list, makes ts happy - listElements: Array; - title: string; - checkhandler: any; - defaultOpen?: boolean; // The ? indicates that this prop is optional -} - -const CollapsibleList: React.FC = ({ - listElements, - title, - checkhandler, - defaultOpen = false // Default values are set here -}) =>{ - const [isExpanded, setIsExpanded] = useState(defaultOpen); - const [checked, setChecked] = useState(false) - - useEffect(()=>{setChecked(checkhandler.checked);},[checkhandler.checked]) - - return ( -
-
- - -
-
    - {listElements.map((item:any) => ( -
  • {item} -
  • - ))} -
-
- ); -}; - -export default DatasetPage; - -export const getServerSideProps: GetServerSideProps = async ({ req, res }) => { - const session = await getServerSession(req, res, authOptions); - - if (!session) { - return { - redirect: { - destination: "/auth/login", - permanent: false, - }, - }; - } - - return { - props: { session }, - }; -}; diff --git a/neurofusion/next-client/src/pages/lab/integrations.tsx b/neurofusion/next-client/src/pages/lab/integrations.tsx deleted file mode 100644 index 93601aa3..00000000 --- a/neurofusion/next-client/src/pages/lab/integrations.tsx +++ /dev/null @@ -1,34 +0,0 @@ -import { GetServerSideProps, NextPage } from "next"; -import { getServerSession } from "next-auth"; - -import { authOptions } from "../api/auth/[...nextauth]"; - -import { IntegrationsContainer } from "~/components/features/integrations"; -import { DashboardLayout } from "~/components/layouts"; - -const IntegrationsPage: NextPage = () => { - return ( - - - - ); -}; - -export default IntegrationsPage; - -export const getServerSideProps: GetServerSideProps = async ({ req, res }) => { - const session = await getServerSession(req, res, authOptions); - - if (!session) { - return { - redirect: { - destination: "/auth/login", - permanent: false, - }, - }; - } - - return { - props: { session }, - }; -}; diff --git a/neurofusion/next-client/src/pages/lab/neurosity-callback.tsx b/neurofusion/next-client/src/pages/lab/neurosity-callback.tsx deleted file mode 100644 index 7dd63968..00000000 --- a/neurofusion/next-client/src/pages/lab/neurosity-callback.tsx +++ /dev/null @@ -1,27 +0,0 @@ -import { useEffect } from "react"; - -import { API_URL } from "~/config"; -import { useNeurosityState, useOAuthResult } from "~/hooks"; - -export default function NeurosityCallback() { - const { loading, user } = useNeurosityState(); - // This is absolutely necessary to get the oauth result - const oauthResult = useOAuthResult(); - - useEffect(() => { - // validate auth result and then redirect to settings page - if (!loading && user) { - // make api to backend that oauth is complete - fetch(`${API_URL}/api/neurosity-oauth-complete`, { - method: "POST", - body: JSON.stringify(oauthResult), - }); - // alert("user is logged in successfully"); - window.location.href = "/integrations"; - } - - window.location.href = "/integrations"; - }, [loading, user, oauthResult]); - - return <>; -} diff --git a/neurofusion/next-client/src/pages/lab/playground.tsx b/neurofusion/next-client/src/pages/lab/playground.tsx deleted file mode 100644 index 2219427c..00000000 --- a/neurofusion/next-client/src/pages/lab/playground.tsx +++ /dev/null @@ -1,35 +0,0 @@ -import { GetServerSideProps, NextPage } from "next"; -import { getServerSession } from "next-auth"; -import React from "react"; - -import { authOptions } from "../api/auth/[...nextauth]"; - -import { Experiment } from "~/components/lab"; -import { DashboardLayout } from "~/components/layouts"; - -const PlaygroundPage: NextPage = () => { - return ( - - - - ); -}; - -export default PlaygroundPage; - -export const getServerSideProps: GetServerSideProps = async ({ req, res }) => { - const session = await getServerSession(req, res, authOptions); - - if (!session) { - return { - redirect: { - destination: "/auth/login", - permanent: false, - }, - }; - } - - return { - props: { session }, - }; -}; diff --git a/neurofusion/next-client/src/pages/lab/recordings.tsx b/neurofusion/next-client/src/pages/lab/recordings.tsx deleted file mode 100644 index e5f3d9e7..00000000 --- a/neurofusion/next-client/src/pages/lab/recordings.tsx +++ /dev/null @@ -1,29 +0,0 @@ -import { GetServerSideProps, NextPage } from "next"; -import { getServerSession } from "next-auth"; - -import { authOptions } from "../api/auth/[...nextauth]"; - -const RecodingPage: NextPage = () => { - return
Good, you're authenticated if you were able to make it here
; -}; - -export default RecodingPage; - - - -export const getServerSideProps: GetServerSideProps = async ({ req, res }) => { - const session = await getServerSession(req, res, authOptions); - - if (!session) { - return { - redirect: { - destination: "/auth/login", - permanent: false, - }, - }; - } - - return { - props: { session }, - }; -};