Skip to content

Commit

Permalink
Merge branch 'main' into GenericSuperClassType
Browse files Browse the repository at this point in the history
  • Loading branch information
TomDijkema authored Oct 30, 2024
2 parents d4c99eb + 167fdd4 commit 645308c
Show file tree
Hide file tree
Showing 39 changed files with 2,007 additions and 166 deletions.
4 changes: 4 additions & 0 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ p {
color: var(--accent);
}

.tc-black {
color: #333333;
}

.tc-white {
color: #ffffff;
}
Expand Down
58 changes: 49 additions & 9 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,70 @@
/* Import Dependencies */
import { BrowserRouter as Router, Routes } from 'react-router-dom';
import { useState } from 'react';

/* Import Utilities */
import { MobileCheck } from 'app/Utilities';

/* Import Routes */
import AppRoutes from 'app/Routes';

/* Import Hooks */
import { useAppDispatch, useTrigger } from 'app/Hooks';

/* Import Store */
import { setBootState } from "redux-store/BootSlice";

/* Import Types */
import { Dict } from 'app/Types';

/* Import Styles */
import './App.css';

/* Import Boot file */
import Boot from 'app/Boot';

/* Import Components */
import Loading from 'components/Loading';
import Notifications from 'components/elements/notifications/Notifications';
import Mobile from './Mobile';


/* Props type */
type Props = {
bootState: {
aggregations: Dict,
phylopicBuild: number
}
};


/**
* Function to render the application body and its routes
* @returns JSX component
*/
const App = () => {
/* Boot application */
const booted: boolean = Boot();
const App = (props: Props) => {
const { bootState } = props;

/* Hooks */
const dispatch = useAppDispatch();
const trigger = useTrigger();

/* Base variables */
const [isMobile, setIsMobile] = useState<boolean>(false);

/* Set boot state to global state and check if device being used is mobile */
trigger.SetTrigger(() => {
/* Set global boot state */
dispatch(setBootState(bootState));

/* Check for mobile device */
const CheckForMobileDevice = () => {
setIsMobile(MobileCheck());
};

window.addEventListener("resize", CheckForMobileDevice);

return () => window.removeEventListener("resize", CheckForMobileDevice);
}, []);

/* If booted: return routes for application, otherwise show loading screen */
if (booted) {
if (!isMobile) {
return (
<div className="h-100 w-100">
<Router>
Expand All @@ -38,7 +78,7 @@ const App = () => {
);
} else {
return (
<Loading />
<Mobile />
);
}
};
Expand Down
61 changes: 61 additions & 0 deletions src/Mobile.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/* Import Dependencies */
import { Container, Row, Col } from 'react-bootstrap';

/* Import Styles */
import './App.css';

/* Import Webroot */
import DiSSCoLogo from 'webroot/logos/dissco-logo.svg';


/**
* Function to render the application body and its routes
* @returns JSX component
*/
const Mobile = () => {
return (
<div className="h-100 w-100 overflow-hidden">
<Container fluid className="h-100 w-100 d-flex align-items-center">
<div className="px-5">
{/* DiSSCover Title */}
<Row className="mt-5">
<Col className="text-center">
<h1 className="tc-primary fw-bold"
style={{
fontSize: '50px'
}}
>
DiSSCover
</h1>
</Col>
</Row>
{/* DiSSCo Logo */}
<Row className="mt-5 justify-content-center">
<Col className="col-auto">
<img src={DiSSCoLogo}
alt="DiSSCo Logo"
style={{
height: '40px'
}}
/>
</Col>
</Row>
{/* Text */}
<Row className="mt-5">
<Col className="text-center">
<p style={{
fontSize: '16px'
}}>
Thanks for your interest in DiSSCover!
Unfortunately we do not yet support mobile devices,
please use a desktop or laptop for access in the meantime.
</p>
</Col>
</Row>
</div>
</Container>
</div>
);
};

export default Mobile;
2 changes: 1 addition & 1 deletion src/api/digitalSpecimen/GetDigitalSpecimen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ const GetDigitalSpecimen = async({ handle, version } : { handle: string, version
};

return digitalSpecimen;
}
};

export default GetDigitalSpecimen;
2 changes: 1 addition & 1 deletion src/api/digitalSpecimen/GetDigitalSpecimenAnnotations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const GetDigitalSpecimenAnnotations = async({ handle } : { handle: string }) =>
const data: JSONResultArray = result.data;

/* Set Digital Specimen Annotation items */
data.data.forEach((dataRow) => {
data.data.forEach(dataRow => {
digitalSpecimenAnnotations.push(dataRow.attributes as Annotation);
});
} catch (error: any) {
Expand Down
45 changes: 45 additions & 0 deletions src/api/digitalSpecimen/GetDigitalSpecimenMAS.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* Import Dependencies */
import axios from 'axios';

/* Import Types */
import { MachineAnnotationService } from 'app/types/MachineAnnotationService';
import { JSONResultArray, Dict } from 'app/Types';

/* Import Exceptions */
import { NotFoundException } from 'app/Exceptions';


/**
* Function for fetching a digital specimen's potential MASs to be run
* @param handle The identifier of the digital specimen
* @returns List of
*/
const GetDigitalSpecimenMASs = async ({ handle }: { handle: string }) => {
const digitalSpecimenMASs: MachineAnnotationService[] = [];

if (handle) {
const endPoint: string = `/digital-specimen/${handle}/mas`;

try {
const result = await axios({
method: 'get',
url: endPoint,
responseType: 'json'
});

/* Get result data from JSON */
const data: JSONResultArray = result.data;

/* Set MASs */
data.data.forEach((dataRow: Dict) => {
digitalSpecimenMASs.push(dataRow.attributes);
});
} catch (error: any) {
throw (NotFoundException('Digital Specimen MASs', error.request.responseURL));
};
};

return digitalSpecimenMASs;
};

export default GetDigitalSpecimenMASs;
57 changes: 57 additions & 0 deletions src/api/digitalSpecimen/GetDigitalSpecimenMASJobRecords.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/* Import Dependencies */
import axios from 'axios';

/* Import Types */
import { JSONResultArray, Dict } from 'app/Types';

/* Import Exceptions */
import { NotFoundException } from 'app/Exceptions';


/**
* Function for fetching a digital specimen's machine annotation service (MAS) job records
* @param handle The identifier of the digital specimen
* @param version The version of the digital specimen
* @returns Object of Digital Specimen
*/
const GetDigitalSpecimenMASJobRecords = async ({ handle, pageSize, pageNumber, state }: { handle: string, pageSize?: number, pageNumber: number, state?: string }) => {
let returnData: {
MASJobRecords: Dict[],
links?: Dict
} = {
MASJobRecords: []
};

if (handle) {
const endPoint: string = `/digital-specimen/${handle.replace(import.meta.env.VITE_DOI_URL, '')}/mjr`;

try {
const result = await axios({
method: 'get',
url: endPoint,
params: {
pageSize: pageSize,
pageNumber: pageNumber ?? 1,
...(state && { state })
},
responseType: 'json'
});

/* Get result data from JSON */
const data: JSONResultArray = result.data;

data.data.forEach(dataFragment => {
returnData.MASJobRecords.push(dataFragment.attributes);
});

/* Set return data */
returnData.links = data.links;
} catch (error: any) {
console.error(NotFoundException('Digital Specimen MAS Job Records', error.request.responseURL));
};
};

return returnData;
};

export default GetDigitalSpecimenMASJobRecords;
66 changes: 66 additions & 0 deletions src/api/digitalSpecimen/ScheduleDigitalSpecimenMAS.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/* Import Dependencies */
import axios from 'axios';
import KeycloakService from 'app/Keycloak';

/* Import Exceptions */
import { PostException } from 'app/Exceptions';

/* Import Types */
import { JSONResultArray, Dict } from 'app/Types';


/**
* Function for posting a scheduling job for scheduling MASs for the digital specimen
* @param digitalSpecimenId The identifier of the digital specimen to schedule MASs for
* @param masList A list of MASs to be scheduled
* @returns Array of scheduled MASs
*/
const ScheduleDigitalSpecimenMAS = async ({ digitalSpecimenId, masList }: { digitalSpecimenId: string, masList: { masId: string }[] }) => {
let digitalSpecimenMAS: Dict = {};

if (digitalSpecimenId) {
const token = KeycloakService.GetToken();

const masRecord: {
data: {
type: 'MasRequest',
attributes: {
mass: {
masId: string
}[]
}
}
} = {
data: {
type: 'MasRequest',
attributes: {
mass: masList
}
}
};

try {
const result = await axios({
method: 'post',
url: `digital-specimen/${digitalSpecimenId.replace(import.meta.env.VITE_DOI_URL, '')}/mas`,
responseType: 'json',
data: masRecord,
headers: {
'Content-type': 'application/json',
'Authorization': `Bearer ${token}`
}
});

/* Set Specimen MAS */
const data: JSONResultArray = result.data;

digitalSpecimenMAS = data.data[0].attributes;
} catch (error: any) {
throw PostException('Machine Annotation Services', error.request.responseURL);
};
};

return digitalSpecimenMAS;
};

export default ScheduleDigitalSpecimenMAS;
Loading

0 comments on commit 645308c

Please sign in to comment.