Feature/73 add flights page #75
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "api",
|
"name": "api",
|
||||||
"version": "1.2.0",
|
"version": "1.3.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"author": "",
|
"author": "",
|
||||||
"private": true,
|
"private": true,
|
||||||
|
|||||||
1
app/.gitignore
vendored
1
app/.gitignore
vendored
@@ -1,5 +1,4 @@
|
|||||||
# Logs
|
# Logs
|
||||||
logs
|
|
||||||
*.log
|
*.log
|
||||||
npm-debug.log*
|
npm-debug.log*
|
||||||
yarn-debug.log*
|
yarn-debug.log*
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "app",
|
"name": "app",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "1.2.0",
|
"version": "1.3.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { Navigate, Route, Routes } from 'react-router-dom';
|
import { Navigate, Route, Routes } from 'react-router-dom';
|
||||||
import Pilots from './components/pilots/Pilots';
|
import Flights from './components/flights/Flights';
|
||||||
import Logbook from './components/logbook/Logbook';
|
import Logbook from './components/logbook/Logbook';
|
||||||
|
import Pilots from './components/pilots/Pilots';
|
||||||
import SiteNav from './components/siteNav/SiteNav';
|
import SiteNav from './components/siteNav/SiteNav';
|
||||||
import { useIsAuthenticated } from '@azure/msal-react';
|
import { useIsAuthenticated } from '@azure/msal-react';
|
||||||
|
|
||||||
@@ -19,8 +20,10 @@ const App = () => {
|
|||||||
<>
|
<>
|
||||||
<SiteNav />
|
<SiteNav />
|
||||||
<Routes>
|
<Routes>
|
||||||
|
<Route path='/' element={<Flights />} />
|
||||||
|
<Route path="/logbook" element={<Logbook />} />
|
||||||
<Route path="/pilots" element={<Pilots />} />
|
<Route path="/pilots" element={<Pilots />} />
|
||||||
<Route path="/" element={<Logbook />} />
|
|
||||||
</Routes>
|
</Routes>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
32
app/src/components/flights/Flights.tsx
Normal file
32
app/src/components/flights/Flights.tsx
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
import { Box, Container } from "@noahspan/noahspan-components";
|
||||||
|
import LogbookCard from "../logbookCard/LogbookCard";
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
import { useLogs } from "../../hooks/logs/UseLogs";
|
||||||
|
import { ILogbookEntry } from "../logbook/ILogbookEntry";
|
||||||
|
|
||||||
|
const Flights = () => {
|
||||||
|
const [flights, setFlights] = useState<ILogbookEntry[]>([])
|
||||||
|
const { logs } = useLogs();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const flights: ILogbookEntry[] | undefined = logs?.filter((log: ILogbookEntry) => {
|
||||||
|
if (log.tracks && JSON.parse(log.tracks).length > 0) {
|
||||||
|
return log;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (flights && flights.length > 0) {
|
||||||
|
setFlights(flights)
|
||||||
|
}
|
||||||
|
}, [logs])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Container>
|
||||||
|
<Box sx={{ margin: '20px' }}>
|
||||||
|
<LogbookCard logs={flights} mode='flights' />
|
||||||
|
</Box>
|
||||||
|
</Container>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Flights;
|
||||||
@@ -35,9 +35,6 @@ const LogTrackMaps = ({ rowKey, trackUrls }: LogTrackMapsProps) => {
|
|||||||
config
|
config
|
||||||
);
|
);
|
||||||
const kml = new DOMParser().parseFromString(response.data, 'text/xml')
|
const kml = new DOMParser().parseFromString(response.data, 'text/xml')
|
||||||
// const converted = toGeoJSON.kml(dom);
|
|
||||||
|
|
||||||
// rewind(converted, false);
|
|
||||||
|
|
||||||
convertedTracks.push(kml);
|
convertedTracks.push(kml);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { useEffect, useReducer } from "react";
|
import { useEffect, useReducer } from "react";
|
||||||
import { Button, Drawer, Grid, Icon, IconButton, IconName, TextField, theme, Typography, useMediaQuery } from "@noahspan/noahspan-components";
|
import { Button, Drawer, Grid, Icon, IconButton, IconName, Spinner, TextField, theme, Typography, useMediaQuery } from "@noahspan/noahspan-components";
|
||||||
import { useHttpClient } from "../../hooks/httpClient/UseHttpClient";
|
import { useHttpClient } from "../../hooks/httpClient/UseHttpClient";
|
||||||
import { AxiosInstance, AxiosResponse } from "axios";
|
import { AxiosInstance, AxiosResponse } from "axios";
|
||||||
import { useAccessToken } from "../../hooks/accessToken/UseAcessToken";
|
import { useAccessToken } from "../../hooks/accessToken/UseAcessToken";
|
||||||
@@ -132,13 +132,23 @@ const LogTracks = ({ isDrawerOpen, mode, onOpenClose, selectedRowKey }: LogTrack
|
|||||||
<Typography variant="h4">{`${mode.toString().toLowerCase().charAt(0).toUpperCase() + mode.toString().slice(1).toLowerCase()} Tracks`}</Typography>
|
<Typography variant="h4">{`${mode.toString().toLowerCase().charAt(0).toUpperCase() + mode.toString().slice(1).toLowerCase()} Tracks`}</Typography>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid display="flex" justifyContent="right" size={1}>
|
<Grid display="flex" justifyContent="right" size={1}>
|
||||||
<IconButton onClick={onCancel}>
|
<IconButton disabled={state.isLoading ? true : false} onClick={onCancel}>
|
||||||
<Icon iconName={IconName.XMARK} />
|
<Icon iconName={IconName.XMARK} />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</Grid>
|
</Grid>
|
||||||
{mode === FormMode.EDIT &&
|
{mode === FormMode.EDIT &&
|
||||||
<>
|
<>
|
||||||
{state.tracks.length > 0 && state.tracks.map((track, index) => {
|
{state.isLoading &&
|
||||||
|
<>
|
||||||
|
<Grid display="flex" justifyContent="center" size={12}>
|
||||||
|
<Spinner />
|
||||||
|
</Grid>
|
||||||
|
<Grid display="flex" justifyContent="center" size={12}>
|
||||||
|
Loading...
|
||||||
|
</Grid>
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
{!state.isLoading && state.tracks.length > 0 && state.tracks.map((track, index) => {
|
||||||
const trackSplit = track.split('/')
|
const trackSplit = track.split('/')
|
||||||
const filename = trackSplit[trackSplit.length - 1];
|
const filename = trackSplit[trackSplit.length - 1];
|
||||||
|
|
||||||
@@ -155,6 +165,7 @@ const LogTracks = ({ isDrawerOpen, mode, onOpenClose, selectedRowKey }: LogTrack
|
|||||||
})}
|
})}
|
||||||
<Grid display='flex' gap={2} justifyContent='right' size={12}>
|
<Grid display='flex' gap={2} justifyContent='right' size={12}>
|
||||||
<Button
|
<Button
|
||||||
|
disabled={state.isLoading ? true : false}
|
||||||
startIcon={<Icon iconName={IconName.XMARK} />}
|
startIcon={<Icon iconName={IconName.XMARK} />}
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
onClick={onCancel}
|
onClick={onCancel}
|
||||||
@@ -165,7 +176,7 @@ const LogTracks = ({ isDrawerOpen, mode, onOpenClose, selectedRowKey }: LogTrack
|
|||||||
{mode.toString() !== FormMode.VIEW && (
|
{mode.toString() !== FormMode.VIEW && (
|
||||||
<Button
|
<Button
|
||||||
component='label'
|
component='label'
|
||||||
loading={state.isLoading}
|
disabled={state.isLoading ? true : false}
|
||||||
startIcon={<Icon iconName={IconName.UPLOAD} />}
|
startIcon={<Icon iconName={IconName.UPLOAD} />}
|
||||||
variant='contained'
|
variant='contained'
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ const Logbook: React.FC<unknown> = () => {
|
|||||||
accessorKey: 'tracks',
|
accessorKey: 'tracks',
|
||||||
header: 'Tracks',
|
header: 'Tracks',
|
||||||
cell: (info: any) => {
|
cell: (info: any) => {
|
||||||
if (info.row.original.tracks && info.row.original.tracks.length > 0) {
|
if (info.row.original.tracks && JSON.parse(info.row.original.tracks).length > 0) {
|
||||||
return (
|
return (
|
||||||
<IconButton onClick={() => onOpenCloseTracks(FormMode.VIEW, info.row.original.rowKey)}><Icon iconName={IconName.MAP_LOCATION_DOT} /></IconButton>
|
<IconButton onClick={() => onOpenCloseTracks(FormMode.VIEW, info.row.original.rowKey)}><Icon iconName={IconName.MAP_LOCATION_DOT} /></IconButton>
|
||||||
)
|
)
|
||||||
@@ -261,7 +261,7 @@ const Logbook: React.FC<unknown> = () => {
|
|||||||
<Table columns={state.columns} data={state.entries} />
|
<Table columns={state.columns} data={state.entries} />
|
||||||
)}
|
)}
|
||||||
{!isMedium && state.entries.length > 0 &&
|
{!isMedium && state.entries.length > 0 &&
|
||||||
<LogbookCard logs={state.entries} onDelete={onDeleteEntry} onOpenCloseForm={onOpenCloseEntryForm} />
|
<LogbookCard logs={state.entries} onDelete={onDeleteEntry} mode='logbook' onOpenCloseForm={onOpenCloseEntryForm} />
|
||||||
}
|
}
|
||||||
</Grid>
|
</Grid>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -1,18 +1,19 @@
|
|||||||
import { Card, CardContent, CardHeader, Grid, Typography } from "@noahspan/noahspan-components";
|
import { Card, CardContent, CardHeader, Grid, Typography } from "@noahspan/noahspan-components";
|
||||||
import { LogbookCardProps } from "./LogbookCardProps.interface";
|
import { LogbookCardProps } from "./LogbookCardProps.interface";
|
||||||
import { useEffect } from "react";
|
|
||||||
import ActionMenu from "../actionMenu/ActionMenu";
|
import ActionMenu from "../actionMenu/ActionMenu";
|
||||||
|
import LogTrackMaps from "../logTrackMaps/LogTrackMaps";
|
||||||
|
|
||||||
|
|
||||||
const LogbookCard = ({ logs, onDelete, onOpenCloseForm }: LogbookCardProps) => {
|
const LogbookCard = ({ logs, mode, onDelete, onOpenCloseForm }: LogbookCardProps) => {
|
||||||
return (
|
return (
|
||||||
<Grid container spacing={2}>
|
<Grid container spacing={2}>
|
||||||
{logs.map((log) => {
|
{logs.map((log) => {
|
||||||
|
console.log(log)
|
||||||
return (
|
return (
|
||||||
<Grid size={12}>
|
<Grid size={12}>
|
||||||
<Card key={log.rowKey}>
|
<Card key={log.rowKey}>
|
||||||
<CardHeader
|
<CardHeader
|
||||||
action={<ActionMenu id={log.rowKey} onDelete={onDelete} onOpenCloseForm={onOpenCloseForm} />}
|
action={mode === 'logbook' ? <ActionMenu id={log.rowKey} onDelete={onDelete!} onOpenCloseForm={onOpenCloseForm!} /> : null}
|
||||||
subheader={log.pilotName}
|
subheader={log.pilotName}
|
||||||
title={log.date}
|
title={log.date}
|
||||||
slotProps={{
|
slotProps={{
|
||||||
@@ -26,6 +27,14 @@ const LogbookCard = ({ logs, onDelete, onOpenCloseForm }: LogbookCardProps) => {
|
|||||||
/>
|
/>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<Grid container spacing={1}>
|
<Grid container spacing={1}>
|
||||||
|
{mode === 'flights' && log.tracks && JSON.parse(log.tracks).length > 0 &&
|
||||||
|
<Grid size={12}>
|
||||||
|
<LogTrackMaps
|
||||||
|
rowKey={log.rowKey}
|
||||||
|
trackUrls={JSON.parse(log.tracks)}
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
}
|
||||||
<Grid size={12}>
|
<Grid size={12}>
|
||||||
<Typography variant="subtitle2">Aircraft Make and Model</Typography>
|
<Typography variant="subtitle2">Aircraft Make and Model</Typography>
|
||||||
</Grid>
|
</Grid>
|
||||||
@@ -50,6 +59,24 @@ const LogbookCard = ({ logs, onDelete, onOpenCloseForm }: LogbookCardProps) => {
|
|||||||
<Grid size={12}>
|
<Grid size={12}>
|
||||||
<Typography variant="body1">{log.durationOfFlight}</Typography>
|
<Typography variant="body1">{log.durationOfFlight}</Typography>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
{mode === 'logbook' && log.tracks && JSON.parse(log.tracks).length > 0 &&
|
||||||
|
<>
|
||||||
|
<Grid size={12}>
|
||||||
|
<Typography variant="subtitle2">Tracks</Typography>
|
||||||
|
</Grid>
|
||||||
|
{JSON.parse(log.tracks).map((track: string) => {
|
||||||
|
const trackSplit = track.split('/')
|
||||||
|
const filename = trackSplit[trackSplit.length - 1];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Grid size={12}>
|
||||||
|
<Typography variant="body1">{filename}</Typography>
|
||||||
|
</Grid>
|
||||||
|
)
|
||||||
|
|
||||||
|
})}
|
||||||
|
</>
|
||||||
|
}
|
||||||
{log.notes &&
|
{log.notes &&
|
||||||
<>
|
<>
|
||||||
<Grid size={12}>
|
<Grid size={12}>
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { ILogbookEntry } from "../logbook/ILogbookEntry";
|
|||||||
|
|
||||||
export interface LogbookCardProps {
|
export interface LogbookCardProps {
|
||||||
logs: ILogbookEntry[];
|
logs: ILogbookEntry[];
|
||||||
onDelete: (entryId: string) => void;
|
mode: 'flights' | 'logbook';
|
||||||
onOpenCloseForm: (formMode: FormMode, id: string) => void;
|
onDelete?: (entryId: string) => void;
|
||||||
|
onOpenCloseForm?: (formMode: FormMode, id: string) => void;
|
||||||
}
|
}
|
||||||
@@ -32,9 +32,13 @@ const SiteNav = () => {
|
|||||||
const getPages = () => {
|
const getPages = () => {
|
||||||
const pages = [
|
const pages = [
|
||||||
{
|
{
|
||||||
name: 'Logbook',
|
name: 'Flights',
|
||||||
url: '/'
|
url: '/'
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'Logbook',
|
||||||
|
url: '/logbook'
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'Pilots',
|
name: 'Pilots',
|
||||||
url: '/pilots'
|
url: '/pilots'
|
||||||
@@ -79,7 +83,6 @@ const SiteNav = () => {
|
|||||||
|
|
||||||
return imageUrl;
|
return imageUrl;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
|
||||||
throw new Error();
|
throw new Error();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
40
app/src/hooks/logs/UseLogs.tsx
Normal file
40
app/src/hooks/logs/UseLogs.tsx
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
import { useEffect, useState } from "react";
|
||||||
|
import { useHttpClient } from "../httpClient/UseHttpClient";
|
||||||
|
import { useAccessToken } from "../accessToken/UseAcessToken";
|
||||||
|
import { useIsAuthenticated } from "@azure/msal-react";
|
||||||
|
import { AxiosInstance, AxiosResponse } from "axios";
|
||||||
|
import { ILogbookEntry } from "../../components/logbook/ILogbookEntry";
|
||||||
|
|
||||||
|
export const useLogs = () => {
|
||||||
|
const [logs, setLogs] = useState<ILogbookEntry[]>();
|
||||||
|
const httpClient: AxiosInstance = useHttpClient();
|
||||||
|
const { getAccessToken } = useAccessToken();
|
||||||
|
const isAuthenticated = useIsAuthenticated();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const getLogs = async () => {
|
||||||
|
try {
|
||||||
|
const config = isAuthenticated
|
||||||
|
? { headers: { Authorization: await getAccessToken() } }
|
||||||
|
: {};
|
||||||
|
const response: AxiosResponse = await httpClient.get(
|
||||||
|
`api/logs`,
|
||||||
|
config
|
||||||
|
);
|
||||||
|
const logs: ILogbookEntry[] = response.data;
|
||||||
|
|
||||||
|
logs.sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime())
|
||||||
|
|
||||||
|
setLogs(logs)
|
||||||
|
} catch (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getLogs();
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
return {
|
||||||
|
logs
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
body {
|
body {
|
||||||
background-color: #f2f2f2;
|
background-color: #f2f2f2;
|
||||||
|
margin: 8px;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@noahspan/flying",
|
"name": "@noahspan/flying",
|
||||||
"version": "1.2.0",
|
"version": "1.3.0",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "concurrently 'npm run start:azure -w api' 'wait-on tcp:0.0.0.0:7071 && npm run dev -w app'",
|
"start": "concurrently 'npm run start:azure -w api' 'wait-on tcp:0.0.0.0:7071 && npm run dev -w app'",
|
||||||
"format": "prettier --write \"**/src/**/*.ts\" \"**/test/**/*.ts\"",
|
"format": "prettier --write \"**/src/**/*.ts\" \"**/test/**/*.ts\"",
|
||||||
|
|||||||
Reference in New Issue
Block a user