Compare commits
9 Commits
feature/59
...
v1.3.1
| Author | SHA1 | Date | |
|---|---|---|---|
| 9f13cc20a5 | |||
| 3ab9024152 | |||
| f15008a8db | |||
| 514f970233 | |||
| db94838249 | |||
| f76244d00c | |||
| 98f50641c8 | |||
| 0f1e303c27 | |||
| 08498a64d8 |
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "api",
|
"name": "api",
|
||||||
"version": "1.2.0",
|
"version": "1.3.1",
|
||||||
"description": "",
|
"description": "",
|
||||||
"author": "",
|
"author": "",
|
||||||
"private": true,
|
"private": true,
|
||||||
@@ -19,6 +19,7 @@
|
|||||||
"test:e2e": "jest --config ./test/jest-e2e.json"
|
"test:e2e": "jest --config ./test/jest-e2e.json"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@azure/storage-blob": "^12.27.0",
|
||||||
"@microsoft/microsoft-graph-client": "^3.0.7",
|
"@microsoft/microsoft-graph-client": "^3.0.7",
|
||||||
"@nestjs/axios": "^3.0.3",
|
"@nestjs/axios": "^3.0.3",
|
||||||
"@nestjs/common": "^10.0.0",
|
"@nestjs/common": "^10.0.0",
|
||||||
@@ -29,10 +30,12 @@
|
|||||||
"@noahspan/azure-database": "^3.1.2",
|
"@noahspan/azure-database": "^3.1.2",
|
||||||
"@noahspan/noahspan-modules": "^1.1.5",
|
"@noahspan/noahspan-modules": "^1.1.5",
|
||||||
"@schematics/angular": "^17.3.7",
|
"@schematics/angular": "^17.3.7",
|
||||||
|
"@types/multer": "^1.4.12",
|
||||||
"dotenv": "^16.4.7",
|
"dotenv": "^16.4.7",
|
||||||
"reflect-metadata": "^0.2.2",
|
"reflect-metadata": "^0.2.2",
|
||||||
"rxjs": "^7.8.1",
|
"rxjs": "^7.8.1",
|
||||||
"uuid": "^10.0.0"
|
"uuid": "^10.0.0",
|
||||||
|
"uuidv4": "^6.2.13"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@microsoft/microsoft-graph-types": "^2.40.0",
|
"@microsoft/microsoft-graph-types": "^2.40.0",
|
||||||
|
|||||||
@@ -44,11 +44,6 @@ import configuration from './config/configuration';
|
|||||||
provide: APP_FILTER,
|
provide: APP_FILTER,
|
||||||
useClass: HttpExceptionFilter
|
useClass: HttpExceptionFilter
|
||||||
},
|
},
|
||||||
// {
|
|
||||||
// provide: APP_GUARD,
|
|
||||||
// useClass: AuthGuard
|
|
||||||
// },
|
|
||||||
// Reflector
|
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class AppModule {}
|
export class AppModule {}
|
||||||
|
|||||||
68
api/src/file/file.service.ts
Normal file
68
api/src/file/file.service.ts
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
import { BlobServiceClient, BlockBlobClient } from '@azure/storage-blob';
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { ConfigService } from '@nestjs/config';
|
||||||
|
|
||||||
|
@Injectable() export class FileService {
|
||||||
|
constructor(private readonly configService: ConfigService) {}
|
||||||
|
|
||||||
|
private containerName: string;
|
||||||
|
|
||||||
|
private streamToBuffer(readableStream: NodeJS.ReadableStream) {
|
||||||
|
return new Promise<Buffer>((resolve, reject) => {
|
||||||
|
const chunks = [];
|
||||||
|
|
||||||
|
readableStream.on('data', (data) => {
|
||||||
|
chunks.push(data instanceof Buffer ? data : Buffer.from(data));
|
||||||
|
});
|
||||||
|
readableStream.on('end', () => {
|
||||||
|
resolve(Buffer.concat(chunks));
|
||||||
|
});
|
||||||
|
readableStream.on('error', reject)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async getBlobServiceInstance() {
|
||||||
|
const connectionString = this.configService.get<string>('azureStorageConnectionString');
|
||||||
|
const blobServiceClient: BlobServiceClient = await BlobServiceClient.fromConnectionString(connectionString)
|
||||||
|
|
||||||
|
return blobServiceClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
async getBlobClient(fileName: string): Promise<BlockBlobClient> {
|
||||||
|
const blobService = await this.getBlobServiceInstance();
|
||||||
|
const containerName = this.containerName;
|
||||||
|
const containerClient = blobService.getContainerClient(containerName);
|
||||||
|
const blockBlobClient = containerClient.getBlockBlobClient(fileName);
|
||||||
|
|
||||||
|
return blockBlobClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
async uploadFile(file: Express.Multer.File, containerName: string, rowKey: string): Promise<string> {
|
||||||
|
this.containerName = containerName;
|
||||||
|
|
||||||
|
const blockBlobClient = await this.getBlobClient(`${rowKey}/${file.originalname}`);
|
||||||
|
const fileUrl = blockBlobClient.url;
|
||||||
|
|
||||||
|
await blockBlobClient.uploadData(file.buffer);
|
||||||
|
|
||||||
|
return fileUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
async downloadFile(containerName: string, rowKey: string, fileName: string): Promise<string> {
|
||||||
|
this.containerName = containerName;
|
||||||
|
|
||||||
|
const blockBlobClient = await this.getBlobClient(`${rowKey}/${fileName}`);
|
||||||
|
const downloadBlockBlobResponse = await blockBlobClient.download();
|
||||||
|
const downloaded: string = (await this.streamToBuffer(downloadBlockBlobResponse.readableStreamBody)).toString()
|
||||||
|
|
||||||
|
return downloaded
|
||||||
|
}
|
||||||
|
|
||||||
|
async deleteFile(containerName: string, rowKey:string, fileName: string): Promise<void> {
|
||||||
|
this.containerName = containerName;
|
||||||
|
|
||||||
|
const blockBlobClient = await this.getBlobClient(`${rowKey}/${fileName}`);
|
||||||
|
|
||||||
|
await blockBlobClient.deleteIfExists();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ export class LogInterceptor implements NestInterceptor {
|
|||||||
const req = context.switchToHttp().getRequest();
|
const req = context.switchToHttp().getRequest();
|
||||||
const authHeader = req.headers.authorization;
|
const authHeader = req.headers.authorization;
|
||||||
const token = authHeader && authHeader.split(' ')[1];
|
const token = authHeader && authHeader.split(' ')[1];
|
||||||
|
console.log(token)
|
||||||
|
|
||||||
if (!token) {
|
if (!token) {
|
||||||
return handler.handle().pipe(
|
return handler.handle().pipe(
|
||||||
@@ -22,6 +23,7 @@ export class LogInterceptor implements NestInterceptor {
|
|||||||
routeFrom: log.routeFrom,
|
routeFrom: log.routeFrom,
|
||||||
routeTo: log.routeTo,
|
routeTo: log.routeTo,
|
||||||
durationOfFlight: log.durationOfFlight,
|
durationOfFlight: log.durationOfFlight,
|
||||||
|
tracks: log.tracks,
|
||||||
notes: log.notes
|
notes: log.notes
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -7,6 +7,9 @@ import {
|
|||||||
Param,
|
Param,
|
||||||
Post,
|
Post,
|
||||||
Put,
|
Put,
|
||||||
|
Query,
|
||||||
|
StreamableFile,
|
||||||
|
UploadedFile,
|
||||||
UseGuards,
|
UseGuards,
|
||||||
UseInterceptors
|
UseInterceptors
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
@@ -16,14 +19,19 @@ import { LogService } from './log.service';
|
|||||||
import { CustomError } from '../error/customError';
|
import { CustomError } from '../error/customError';
|
||||||
import { AuthGuard } from '@noahspan/noahspan-modules';
|
import { AuthGuard } from '@noahspan/noahspan-modules';
|
||||||
import { LogInterceptor } from './interceptors/log.interceptor';
|
import { LogInterceptor } from './interceptors/log.interceptor';
|
||||||
|
import { FileService } from '../file/file.service';
|
||||||
|
import { FileInterceptor } from '@nestjs/platform-express';
|
||||||
|
|
||||||
@Controller('logs')
|
@Controller('logs')
|
||||||
@UseInterceptors(new LogInterceptor())
|
|
||||||
export class LogController {
|
export class LogController {
|
||||||
constructor(private readonly logService: LogService) {}
|
constructor(
|
||||||
|
private readonly fileService: FileService,
|
||||||
|
private readonly logService: LogService
|
||||||
|
) {}
|
||||||
|
|
||||||
|
|
||||||
@Get(':partitionKey/:rowKey')
|
@Get(':partitionKey/:rowKey')
|
||||||
|
@UseInterceptors(new LogInterceptor())
|
||||||
async find(
|
async find(
|
||||||
@Param('partitionKey') partitionKey: string,
|
@Param('partitionKey') partitionKey: string,
|
||||||
@Param('rowKey') rowKey: string
|
@Param('rowKey') rowKey: string
|
||||||
@@ -38,6 +46,7 @@ export class LogController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
|
@UseInterceptors(new LogInterceptor())
|
||||||
async findAll(): Promise<Log[]> {
|
async findAll(): Promise<Log[]> {
|
||||||
try {
|
try {
|
||||||
return await this.logService.findAll();
|
return await this.logService.findAll();
|
||||||
@@ -98,4 +107,42 @@ export class LogController {
|
|||||||
throw new HttpException(customError.message, customError.statusCode);
|
throw new HttpException(customError.message, customError.statusCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthGuard)
|
||||||
|
@Post(':partitionKey/:rowKey/track')
|
||||||
|
@UseInterceptors(FileInterceptor('file'))
|
||||||
|
async createTrack(@Param('rowKey') rowKey: string, @UploadedFile() file: Express.Multer.File) {
|
||||||
|
try {
|
||||||
|
const containerName = 'tracks';
|
||||||
|
const url = await this.fileService.uploadFile(file, containerName, rowKey);
|
||||||
|
|
||||||
|
return { url }
|
||||||
|
} catch (error) {
|
||||||
|
const customError = error as CustomError;
|
||||||
|
|
||||||
|
throw new HttpException(customError.message, customError.statusCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get(':partitionKey/:rowKey/track')
|
||||||
|
async downloadTrack(@Param('rowKey') rowKey: string, @Query('fileName') fileName: string): Promise<string> {
|
||||||
|
const containerName = 'tracks';
|
||||||
|
const downloadedFile: string = await this.fileService.downloadFile(containerName, rowKey, fileName)
|
||||||
|
|
||||||
|
return downloadedFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthGuard)
|
||||||
|
@Delete(':partitionKey/:rowKey/track')
|
||||||
|
async deleteTrack(@Param('rowKey') rowKey: string, @Query('fileName') fileName: string): Promise<void> {
|
||||||
|
try {
|
||||||
|
const containerName = 'tracks';
|
||||||
|
|
||||||
|
return await this.fileService.deleteFile(containerName, rowKey, fileName)
|
||||||
|
} catch (error) {
|
||||||
|
const customError = error as CustomError;
|
||||||
|
|
||||||
|
throw new HttpException(customError.message, customError.statusCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,5 +22,6 @@ export class LogDto {
|
|||||||
night: number;
|
night: number;
|
||||||
solo: number;
|
solo: number;
|
||||||
pilotInCommand: number;
|
pilotInCommand: number;
|
||||||
|
tracks: string[];
|
||||||
notes: string;
|
notes: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,5 +24,6 @@ export class Log {
|
|||||||
instrumentApproaches?: number | null;
|
instrumentApproaches?: number | null;
|
||||||
instrumentHolds?: number | null;
|
instrumentHolds?: number | null;
|
||||||
instrumentNavTrack?: number | null;
|
instrumentNavTrack?: number | null;
|
||||||
|
tracks?: string[];
|
||||||
notes?: string;
|
notes?: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { LogService } from './log.service';
|
|||||||
import { AzureTableStorageModule } from '@noahspan/azure-database';
|
import { AzureTableStorageModule } from '@noahspan/azure-database';
|
||||||
import { Log } from './log.entity';
|
import { Log } from './log.entity';
|
||||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||||
|
import { FileService } from '../file/file.service';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
@@ -22,6 +23,10 @@ import { ConfigModule, ConfigService } from '@nestjs/config';
|
|||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
controllers: [LogController],
|
controllers: [LogController],
|
||||||
providers: [LogService]
|
providers: [
|
||||||
|
ConfigService,
|
||||||
|
FileService,
|
||||||
|
LogService
|
||||||
|
]
|
||||||
})
|
})
|
||||||
export class LogModule {}
|
export class LogModule {}
|
||||||
|
|||||||
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.1",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
@@ -13,16 +13,21 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@azure/msal-browser": "^4.0.1",
|
"@azure/msal-browser": "^4.0.1",
|
||||||
"@azure/msal-react": "^3.0.1",
|
"@azure/msal-react": "^3.0.1",
|
||||||
"@noahspan/noahspan-components": "^1.5.1",
|
"@noahspan/noahspan-components": "1.6.0",
|
||||||
"axios": "^1.7.2",
|
"axios": "^1.7.2",
|
||||||
"dotenv": "^16.4.7",
|
"dotenv": "^16.4.7",
|
||||||
"react": "^18.3.1",
|
"leaflet": "^1.9.4",
|
||||||
"react-dom": "^18.3.1",
|
"react": "19.0.0-rc.1",
|
||||||
|
"react-dom": "19.0.0-rc.1",
|
||||||
"react-hook-form": "^7.51.4",
|
"react-hook-form": "^7.51.4",
|
||||||
"react-router-dom": "^6.23.0"
|
"react-leaflet": "^5.0.0",
|
||||||
|
"react-leaflet-kml": "^2.1.2",
|
||||||
|
"react-router-dom": "^6.23.0",
|
||||||
|
"swiper": "^11.2.6"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@microsoft/microsoft-graph-types": "^2.40.0",
|
"@microsoft/microsoft-graph-types": "^2.40.0",
|
||||||
|
"@types/leaflet": "^1.9.16",
|
||||||
"@types/react": "^18.2.66",
|
"@types/react": "^18.2.66",
|
||||||
"@types/react-dom": "^18.2.22",
|
"@types/react-dom": "^18.2.22",
|
||||||
"@vitejs/plugin-react": "^4.2.1",
|
"@vitejs/plugin-react": "^4.2.1",
|
||||||
|
|||||||
BIN
app/public/layers-2x.png
Normal file
BIN
app/public/layers-2x.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.2 KiB |
BIN
app/public/layers.png
Normal file
BIN
app/public/layers.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 696 B |
BIN
app/public/marker-icon-2x.png
Normal file
BIN
app/public/marker-icon-2x.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.4 KiB |
BIN
app/public/marker-icon.png
Normal file
BIN
app/public/marker-icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.4 KiB |
BIN
app/public/marker-shadow.png
Normal file
BIN
app/public/marker-shadow.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 618 B |
@@ -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>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import {
|
|||||||
import { FormMode } from '../../enums/formMode';
|
import { FormMode } from '../../enums/formMode';
|
||||||
import { useIsAuthenticated } from '@azure/msal-react';
|
import { useIsAuthenticated } from '@azure/msal-react';
|
||||||
|
|
||||||
const ActionMenu = ({ id, onDelete, onOpenCloseForm }: IActionMenuProps) => {
|
const ActionMenu = ({ id, onDelete, onOpenCloseForm, onOpenCloseTracks }: IActionMenuProps) => {
|
||||||
const [anchorElAction, setAnchorElAction] = useState<null | HTMLElement>(
|
const [anchorElAction, setAnchorElAction] = useState<null | HTMLElement>(
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
@@ -38,12 +38,23 @@ const ActionMenu = ({ id, onDelete, onOpenCloseForm }: IActionMenuProps) => {
|
|||||||
onClose={onCloseActionMenu}
|
onClose={onCloseActionMenu}
|
||||||
>
|
>
|
||||||
{isAuthenticated &&
|
{isAuthenticated &&
|
||||||
|
<>
|
||||||
<MenuItem onClick={() => onOpenCloseForm(FormMode.EDIT, id)}>
|
<MenuItem onClick={() => onOpenCloseForm(FormMode.EDIT, id)}>
|
||||||
<ListItemIcon>
|
<ListItemIcon>
|
||||||
<Icon iconName={IconName.PEN} size="lg" />
|
<Icon iconName={IconName.PEN} size="lg" />
|
||||||
</ListItemIcon>
|
</ListItemIcon>
|
||||||
<ListItemText>Edit</ListItemText>
|
<ListItemText>Edit</ListItemText>
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
|
{onOpenCloseTracks &&
|
||||||
|
<MenuItem onClick={() => onOpenCloseTracks!(FormMode.EDIT, id)}>
|
||||||
|
<ListItemIcon>
|
||||||
|
<Icon iconName={IconName.MAP_LOCATION_DOT} size="lg" />
|
||||||
|
</ListItemIcon>
|
||||||
|
<ListItemText>Tracks</ListItemText>
|
||||||
|
</MenuItem>
|
||||||
|
}
|
||||||
|
</>
|
||||||
|
|
||||||
}
|
}
|
||||||
<MenuItem onClick={() => onOpenCloseForm(FormMode.VIEW, id)}>
|
<MenuItem onClick={() => onOpenCloseForm(FormMode.VIEW, id)}>
|
||||||
<ListItemIcon>
|
<ListItemIcon>
|
||||||
|
|||||||
@@ -4,4 +4,5 @@ export interface IActionMenuProps {
|
|||||||
id: string;
|
id: string;
|
||||||
onDelete: (entryId: string) => void;
|
onDelete: (entryId: string) => void;
|
||||||
onOpenCloseForm: (formMode: FormMode, id: string) => void;
|
onOpenCloseForm: (formMode: FormMode, id: string) => void;
|
||||||
|
onOpenCloseTracks?: (formMode: FormMode, id: string) => void;
|
||||||
}
|
}
|
||||||
|
|||||||
48
app/src/components/flights/Flights.tsx
Normal file
48
app/src/components/flights/Flights.tsx
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
import { Box, Container, Grid, Spinner } 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, isLoading } = 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' }}>
|
||||||
|
<Grid container spacing={2}>
|
||||||
|
{isLoading &&
|
||||||
|
<>
|
||||||
|
<Grid display="flex" justifyContent="center" size={12}>
|
||||||
|
<Spinner />
|
||||||
|
</Grid>
|
||||||
|
<Grid display="flex" justifyContent="center" size={12}>
|
||||||
|
Loading...
|
||||||
|
</Grid>
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
{!isLoading &&
|
||||||
|
<Grid size={12}>
|
||||||
|
<LogbookCard logs={flights} mode='flights' />
|
||||||
|
</Grid>
|
||||||
|
}
|
||||||
|
</Grid>
|
||||||
|
</Box>
|
||||||
|
</Container>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Flights;
|
||||||
@@ -174,7 +174,7 @@ const LogForm: React.FC<ILogFormProps> = ({
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<FormProvider {...methods}>
|
<FormProvider {...methods}>
|
||||||
<form onSubmit={methods.handleSubmit(onSubmit)}>
|
<form onSubmit={methods.handleSubmit(onSubmit)} style={{ paddingBottom: '50px' }}>
|
||||||
<Grid container spacing={2}>
|
<Grid container spacing={2}>
|
||||||
<Grid size={11}>
|
<Grid size={11}>
|
||||||
<Typography variant="h4">{`${mode.toString().toLowerCase().charAt(0).toUpperCase() + mode.toString().slice(1).toLowerCase()} Entry`}</Typography>
|
<Typography variant="h4">{`${mode.toString().toLowerCase().charAt(0).toUpperCase() + mode.toString().slice(1).toLowerCase()} Entry`}</Typography>
|
||||||
|
|||||||
53
app/src/components/logTrackMaps/LogTrackMaps.css
Normal file
53
app/src/components/logTrackMaps/LogTrackMaps.css
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
#app {
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
html,
|
||||||
|
body {
|
||||||
|
position: relative;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
background: #eee;
|
||||||
|
font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
|
||||||
|
font-size: 14px;
|
||||||
|
color: #000;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.swiper {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.swiper-wrapper {
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.swiper-slide {
|
||||||
|
text-align: center;
|
||||||
|
font-size: 18px;
|
||||||
|
background: #fff;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.swiper-slide img {
|
||||||
|
display: block;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
object-fit: cover;
|
||||||
|
}
|
||||||
|
|
||||||
|
.swiper-pagination-bullet {
|
||||||
|
background-color: #000000;
|
||||||
|
height: 13px;
|
||||||
|
width: 13px;
|
||||||
|
border: 2px solid #FFFFFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
.swiper-pagination-bullet-active {
|
||||||
|
box-shadow: 0 0 0 1px #000000;
|
||||||
|
}
|
||||||
81
app/src/components/logTrackMaps/LogTrackMaps.tsx
Normal file
81
app/src/components/logTrackMaps/LogTrackMaps.tsx
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import { LogTrackMapsProps } from './LogTrackMapsProps.interface';
|
||||||
|
import { useHttpClient } from '../../hooks/httpClient/UseHttpClient';
|
||||||
|
import { AxiosInstance, AxiosResponse } from 'axios';
|
||||||
|
import { useAccessToken } from '../../hooks/accessToken/UseAcessToken';
|
||||||
|
import { useIsAuthenticated } from '@azure/msal-react';
|
||||||
|
import { Swiper, SwiperSlide } from 'swiper/react';
|
||||||
|
import { Pagination } from 'swiper/modules';
|
||||||
|
import { MapContainer, TileLayer } from 'react-leaflet';
|
||||||
|
import ReactLeafletKml from 'react-leaflet-kml';
|
||||||
|
import 'swiper/css';
|
||||||
|
import 'swiper/css/pagination';
|
||||||
|
import 'swiper/css';
|
||||||
|
import './LogTrackMaps.css';
|
||||||
|
import 'leaflet/dist/leaflet.css';
|
||||||
|
|
||||||
|
const LogTrackMaps = ({ rowKey, trackUrls }: LogTrackMapsProps) => {
|
||||||
|
const [tracks, setTracks] = useState<any[]>([])
|
||||||
|
const httpClient: AxiosInstance = useHttpClient();
|
||||||
|
const { getAccessToken } = useAccessToken();
|
||||||
|
const isAuthenticated = useIsAuthenticated();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const getTracks = async () => {
|
||||||
|
const convertedTracks: any[] = []
|
||||||
|
|
||||||
|
for (const trackUrl of trackUrls) {
|
||||||
|
const trackUrlSplit = trackUrl.split('/')
|
||||||
|
const filename = trackUrlSplit[trackUrlSplit.length - 1];
|
||||||
|
const config = isAuthenticated
|
||||||
|
? { headers: { Authorization: await getAccessToken() } }
|
||||||
|
: {};
|
||||||
|
const response: AxiosResponse = await httpClient.get(
|
||||||
|
`api/logs/log/${rowKey}/track?fileName=${filename}`,
|
||||||
|
config
|
||||||
|
);
|
||||||
|
const kml = new DOMParser().parseFromString(response.data, 'text/xml')
|
||||||
|
|
||||||
|
convertedTracks.push(kml);
|
||||||
|
}
|
||||||
|
|
||||||
|
setTracks(convertedTracks)
|
||||||
|
}
|
||||||
|
|
||||||
|
getTracks();
|
||||||
|
}, [trackUrls])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Swiper
|
||||||
|
spaceBetween={30}
|
||||||
|
pagination={{
|
||||||
|
clickable: true,
|
||||||
|
}}
|
||||||
|
modules={[Pagination]}
|
||||||
|
className="mySwiper"
|
||||||
|
>
|
||||||
|
{tracks.length > 0 && tracks.map((track) => {
|
||||||
|
return (
|
||||||
|
<SwiperSlide>
|
||||||
|
<MapContainer
|
||||||
|
center={[45.14489, -93.21019]}
|
||||||
|
scrollWheelZoom={false}
|
||||||
|
style={{ height: '500px', width: '100%' }}
|
||||||
|
zoom={8}
|
||||||
|
>
|
||||||
|
<TileLayer
|
||||||
|
attribution='© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
|
||||||
|
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
|
||||||
|
/>
|
||||||
|
<ReactLeafletKml kml={track} />
|
||||||
|
</MapContainer>
|
||||||
|
</SwiperSlide>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</Swiper>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default LogTrackMaps;
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
export interface LogTrackMapsProps {
|
||||||
|
rowKey: string;
|
||||||
|
trackUrls: string[];
|
||||||
|
}
|
||||||
209
app/src/components/logTracks/LogTracks.tsx
Normal file
209
app/src/components/logTracks/LogTracks.tsx
Normal file
@@ -0,0 +1,209 @@
|
|||||||
|
import { useEffect, useReducer } from "react";
|
||||||
|
import { Button, Drawer, Grid, Icon, IconButton, IconName, Spinner, TextField, theme, Typography, useMediaQuery } from "@noahspan/noahspan-components";
|
||||||
|
import { useHttpClient } from "../../hooks/httpClient/UseHttpClient";
|
||||||
|
import { AxiosInstance, AxiosResponse } from "axios";
|
||||||
|
import { useAccessToken } from "../../hooks/accessToken/UseAcessToken";
|
||||||
|
import { LogTracksProps } from "./LogTracksProps.interface";
|
||||||
|
import { FormMode } from "../../enums/formMode";
|
||||||
|
import { useIsAuthenticated } from "@azure/msal-react";
|
||||||
|
import { ILogbookEntry } from "../logbook/ILogbookEntry";
|
||||||
|
import ConfirmationDialog from "../confirmationDialog/ConfirmationDialog";
|
||||||
|
import { initialState, reducer } from "./reducer";
|
||||||
|
import LogTrackMaps from "../logTrackMaps/LogTrackMaps";
|
||||||
|
|
||||||
|
const LogTracks = ({ isDrawerOpen, mode, onOpenClose, selectedRowKey }: LogTracksProps) => {
|
||||||
|
const [state, dispatch] = useReducer(reducer, initialState)
|
||||||
|
const httpClient: AxiosInstance = useHttpClient();
|
||||||
|
const { getAccessToken } = useAccessToken();
|
||||||
|
const isAuthenticated = useIsAuthenticated();
|
||||||
|
|
||||||
|
const isMedium = useMediaQuery(theme.breakpoints.up('md'));
|
||||||
|
|
||||||
|
const getConfig = async () => {
|
||||||
|
const config = isAuthenticated
|
||||||
|
? { headers: { Authorization: await getAccessToken() } }
|
||||||
|
: {};
|
||||||
|
|
||||||
|
return config
|
||||||
|
}
|
||||||
|
|
||||||
|
const getLog = async (): Promise<ILogbookEntry> => {
|
||||||
|
const logResponse: AxiosResponse = await httpClient.get(
|
||||||
|
`api/logs/log/${selectedRowKey}`,
|
||||||
|
await getConfig()
|
||||||
|
);
|
||||||
|
const logData: ILogbookEntry = logResponse.data;
|
||||||
|
|
||||||
|
return logData
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleFileUpload = async (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
try {
|
||||||
|
dispatch({ type: 'SET_IS_LOADING', payload: true})
|
||||||
|
|
||||||
|
const file = event.target.files![0]
|
||||||
|
const formData = new FormData();
|
||||||
|
const config = await getConfig();
|
||||||
|
const formDataConfig = {
|
||||||
|
headers: {
|
||||||
|
...config.headers,
|
||||||
|
'Content-Type': 'multipart/form-data'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
formData.append('file', file);
|
||||||
|
|
||||||
|
const uploadResponse: AxiosResponse = await httpClient.post(`api/logs/log/${selectedRowKey}/track`, formData, formDataConfig);
|
||||||
|
const uploadUrl = uploadResponse.data.url;
|
||||||
|
const log = await getLog();
|
||||||
|
const tracks: string[] = log.tracks ? JSON.parse(log.tracks!) : [];
|
||||||
|
|
||||||
|
tracks.push(uploadUrl)
|
||||||
|
log.tracks = JSON.stringify(tracks);
|
||||||
|
await httpClient.put(`api/logs/log/${selectedRowKey}`, log, config);
|
||||||
|
|
||||||
|
const updatedLog = await getLog();
|
||||||
|
|
||||||
|
dispatch({ type: 'SET_TRACKS', payload: JSON.parse(updatedLog.tracks!) })
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error)
|
||||||
|
} finally {
|
||||||
|
dispatch({ type: 'SET_IS_LOADING', payload: false });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const onCancel = () => {
|
||||||
|
onOpenClose(FormMode.CANCEL)
|
||||||
|
}
|
||||||
|
|
||||||
|
const onDeleteTrack = async (fileName: string, index: number) => {
|
||||||
|
dispatch({ type: 'SET_ON_DELETE_TRACK', payload: { isConfirmDialogOpen: true, selectedTrack: { fileName: fileName, index: index }}})
|
||||||
|
}
|
||||||
|
|
||||||
|
const onConfirmDialogConfirm = async () => {
|
||||||
|
try {
|
||||||
|
const config = await getConfig();
|
||||||
|
|
||||||
|
await httpClient.delete(`api/logs/log/${selectedRowKey}/track?fileName=${state.selectedTrack!.fileName}`, config);
|
||||||
|
|
||||||
|
const log = await getLog();
|
||||||
|
const tracks: string[] = JSON.parse(log.tracks!);
|
||||||
|
|
||||||
|
tracks.splice(state.selectedTrack!.index, 1);
|
||||||
|
log.tracks = JSON.stringify(tracks);
|
||||||
|
await httpClient.put(`api/logs/log/${selectedRowKey}`, log, config);
|
||||||
|
|
||||||
|
const updatedLog = await getLog();
|
||||||
|
|
||||||
|
dispatch({ type: 'SET_TRACKS', payload: JSON.parse(updatedLog.tracks!) })
|
||||||
|
dispatch({ type: 'SET_IS_CONFIRM_DIALOG_OPEN', payload: false })
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const onConfirmDialogCancel = async () => {
|
||||||
|
dispatch({ type: 'SET_IS_CONFIRM_DIALOG_OPEN', payload: false })
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const updateTracks = async () => {
|
||||||
|
const log = await getLog();
|
||||||
|
|
||||||
|
dispatch({ type: 'SET_TRACKS', payload: JSON.parse(log.tracks!) });
|
||||||
|
}
|
||||||
|
|
||||||
|
updateTracks();
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Drawer
|
||||||
|
open={isDrawerOpen}
|
||||||
|
anchor='right'
|
||||||
|
PaperProps={{
|
||||||
|
sx: {
|
||||||
|
padding: '30px',
|
||||||
|
width: isMedium ? '33%' : '75%'
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Grid container spacing={2}>
|
||||||
|
<Grid size={11}>
|
||||||
|
<Typography variant="h4">{`${mode.toString().toLowerCase().charAt(0).toUpperCase() + mode.toString().slice(1).toLowerCase()} Tracks`}</Typography>
|
||||||
|
</Grid>
|
||||||
|
<Grid display="flex" justifyContent="right" size={1}>
|
||||||
|
<IconButton disabled={state.isLoading ? true : false} onClick={onCancel}>
|
||||||
|
<Icon iconName={IconName.XMARK} />
|
||||||
|
</IconButton>
|
||||||
|
</Grid>
|
||||||
|
{mode === FormMode.EDIT &&
|
||||||
|
<>
|
||||||
|
{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 filename = trackSplit[trackSplit.length - 1];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Grid size={11}>
|
||||||
|
<TextField disabled={true} fullWidth value={filename} />
|
||||||
|
</Grid>
|
||||||
|
<Grid size={1}>
|
||||||
|
<IconButton onClick={() => onDeleteTrack(filename, index)}><Icon iconName={IconName.TRASH} /></IconButton>
|
||||||
|
</Grid>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
<Grid display='flex' gap={2} justifyContent='right' size={12}>
|
||||||
|
<Button
|
||||||
|
disabled={state.isLoading ? true : false}
|
||||||
|
startIcon={<Icon iconName={IconName.XMARK} />}
|
||||||
|
variant="outlined"
|
||||||
|
onClick={onCancel}
|
||||||
|
size="small"
|
||||||
|
>
|
||||||
|
Close
|
||||||
|
</Button>
|
||||||
|
{mode.toString() !== FormMode.VIEW && (
|
||||||
|
<Button
|
||||||
|
component='label'
|
||||||
|
disabled={state.isLoading ? true : false}
|
||||||
|
startIcon={<Icon iconName={IconName.UPLOAD} />}
|
||||||
|
variant='contained'
|
||||||
|
>
|
||||||
|
Upload Track
|
||||||
|
<input hidden onChange={handleFileUpload} type='file' />
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</Grid>
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
{mode === FormMode.VIEW &&
|
||||||
|
<LogTrackMaps rowKey={selectedRowKey!} trackUrls={state.tracks} />
|
||||||
|
}
|
||||||
|
</Grid>
|
||||||
|
{state.isConfirmDialogOpen && (
|
||||||
|
<ConfirmationDialog
|
||||||
|
contentText="Are you sure you want to delete this track?"
|
||||||
|
isLoading={state.isConfirmDialogLoading}
|
||||||
|
isOpen={state.isConfirmDialogOpen}
|
||||||
|
onCancel={onConfirmDialogCancel}
|
||||||
|
onConfirm={onConfirmDialogConfirm}
|
||||||
|
title="Confirm Delete"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
</Drawer>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default LogTracks;
|
||||||
8
app/src/components/logTracks/LogTracksProps.interface.ts
Normal file
8
app/src/components/logTracks/LogTracksProps.interface.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import { FormMode } from "../../enums/formMode";
|
||||||
|
|
||||||
|
export interface LogTracksProps {
|
||||||
|
isDrawerOpen: boolean;
|
||||||
|
mode: FormMode;
|
||||||
|
onOpenClose: (mode: FormMode) => void;
|
||||||
|
selectedRowKey: string | undefined;
|
||||||
|
}
|
||||||
10
app/src/components/logTracks/LogTracksState.interface.ts
Normal file
10
app/src/components/logTracks/LogTracksState.interface.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
export interface LogTracksState {
|
||||||
|
isConfirmDialogOpen: boolean;
|
||||||
|
isConfirmDialogLoading: boolean;
|
||||||
|
isLoading: boolean;
|
||||||
|
selectedTrack: {
|
||||||
|
fileName: string,
|
||||||
|
index: number
|
||||||
|
} | undefined;
|
||||||
|
tracks: string[];
|
||||||
|
}
|
||||||
55
app/src/components/logTracks/reducer.ts
Normal file
55
app/src/components/logTracks/reducer.ts
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
import { LogTracksState } from "./LogTracksState.interface";
|
||||||
|
|
||||||
|
type Action =
|
||||||
|
| { type: 'SET_IS_CONFIRM_DIALOG_OPEN'; payload: boolean }
|
||||||
|
| { type: 'SET_IS_CONFORM_DIALOG_LOADING'; payload: boolean }
|
||||||
|
| { type: 'SET_IS_LOADING'; payload: boolean }
|
||||||
|
| { type: 'SET_ON_DELETE_TRACK'; payload: { isConfirmDialogOpen: boolean, selectedTrack: { fileName: string, index: number } }}
|
||||||
|
| { type: 'SET_TRACKS'; payload: string[] };
|
||||||
|
|
||||||
|
export const initialState: LogTracksState = {
|
||||||
|
isConfirmDialogOpen: false,
|
||||||
|
isConfirmDialogLoading: false,
|
||||||
|
isLoading: false,
|
||||||
|
selectedTrack: undefined,
|
||||||
|
tracks: []
|
||||||
|
}
|
||||||
|
|
||||||
|
export const reducer = (state: LogTracksState, action: Action): LogTracksState => {
|
||||||
|
switch (action.type) {
|
||||||
|
case 'SET_IS_CONFIRM_DIALOG_OPEN': {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
isConfirmDialogOpen: action.payload
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case 'SET_IS_CONFORM_DIALOG_LOADING': {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
isConfirmDialogLoading: action.payload
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case 'SET_IS_LOADING': {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
isLoading: action.payload
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case 'SET_ON_DELETE_TRACK': {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
isConfirmDialogOpen: action.payload.isConfirmDialogOpen,
|
||||||
|
selectedTrack: action.payload.selectedTrack
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case 'SET_TRACKS': {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
tracks: action.payload
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
return state
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { ColumnDef } from "@noahspan/noahspan-components";
|
||||||
|
|
||||||
export interface ILogbookEntry {
|
export interface ILogbookEntry {
|
||||||
partitionKey: string;
|
partitionKey: string;
|
||||||
rowKey: string;
|
rowKey: string;
|
||||||
@@ -25,5 +27,6 @@ export interface ILogbookEntry {
|
|||||||
night: number | null;
|
night: number | null;
|
||||||
solo: number | null;
|
solo: number | null;
|
||||||
pilotInCommand: number | null;
|
pilotInCommand: number | null;
|
||||||
|
tracks: string | undefined;
|
||||||
notes: string;
|
notes: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,18 @@
|
|||||||
|
import { ColumnDef } from '@noahspan/noahspan-components';
|
||||||
import { FormMode } from '../../enums/formMode';
|
import { FormMode } from '../../enums/formMode';
|
||||||
import { Alert } from '../../interfaces/Alert.interface';
|
import { Alert } from '../../interfaces/Alert.interface';
|
||||||
import { ILogbookEntry } from './ILogbookEntry';
|
import { ILogbookEntry } from './ILogbookEntry';
|
||||||
|
|
||||||
export interface ILogbookState {
|
export interface ILogbookState {
|
||||||
alert: Alert | undefined;
|
alert: Alert | undefined;
|
||||||
|
columns: ColumnDef<ILogbookEntry>[];
|
||||||
entries: ILogbookEntry[];
|
entries: ILogbookEntry[];
|
||||||
formMode: FormMode;
|
formMode: FormMode;
|
||||||
isConfirmDialogLoading: boolean;
|
isConfirmDialogLoading: boolean;
|
||||||
isConfirmDialogOpen: boolean;
|
isConfirmDialogOpen: boolean;
|
||||||
isFormOpen: boolean;
|
isFormOpen: boolean;
|
||||||
isLoading: boolean;
|
isLoading: boolean;
|
||||||
|
isTracksOpen: boolean;
|
||||||
selectedEntryId: string | undefined;
|
selectedEntryId: string | undefined;
|
||||||
|
tracksMode: FormMode;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import {
|
|||||||
ColumnDef,
|
ColumnDef,
|
||||||
Grid,
|
Grid,
|
||||||
Icon,
|
Icon,
|
||||||
|
IconButton,
|
||||||
IconName,
|
IconName,
|
||||||
Spinner,
|
Spinner,
|
||||||
Table,
|
Table,
|
||||||
@@ -20,10 +21,12 @@ import { AxiosError, AxiosInstance, AxiosResponse } from 'axios';
|
|||||||
import { useAccessToken } from '../../hooks/accessToken/UseAcessToken';
|
import { useAccessToken } from '../../hooks/accessToken/UseAcessToken';
|
||||||
import { useIsAuthenticated } from '@azure/msal-react';
|
import { useIsAuthenticated } from '@azure/msal-react';
|
||||||
import { FormMode } from '../../enums/formMode';
|
import { FormMode } from '../../enums/formMode';
|
||||||
|
import { authColumns, unauthColumns } from './columns';
|
||||||
import ActionMenu from '../actionMenu/ActionMenu';
|
import ActionMenu from '../actionMenu/ActionMenu';
|
||||||
import ConfirmationDialog from '../confirmationDialog/ConfirmationDialog';
|
import ConfirmationDialog from '../confirmationDialog/ConfirmationDialog';
|
||||||
import { ILogbookEntry } from './ILogbookEntry';
|
import { ILogbookEntry } from './ILogbookEntry';
|
||||||
import LogbookCard from '../logbookCard/LogbookCard';
|
import LogbookCard from '../logbookCard/LogbookCard';
|
||||||
|
import LogTracks from '../logTracks/LogTracks';
|
||||||
|
|
||||||
const Logbook: React.FC<unknown> = () => {
|
const Logbook: React.FC<unknown> = () => {
|
||||||
const [state, dispatch] = useReducer(reducer, initialState);
|
const [state, dispatch] = useReducer(reducer, initialState);
|
||||||
@@ -31,12 +34,41 @@ const Logbook: React.FC<unknown> = () => {
|
|||||||
const isAuthenticated = useIsAuthenticated();
|
const isAuthenticated = useIsAuthenticated();
|
||||||
const { getAccessToken } = useAccessToken();
|
const { getAccessToken } = useAccessToken();
|
||||||
const isMedium = useMediaQuery(theme.breakpoints.up('md'));
|
const isMedium = useMediaQuery(theme.breakpoints.up('md'));
|
||||||
|
const actionsColumn: ColumnDef<ILogbookEntry> = {
|
||||||
|
header: 'Actions',
|
||||||
|
meta: {
|
||||||
|
align: 'center',
|
||||||
|
headerAlign: 'center'
|
||||||
|
},
|
||||||
|
cell: (info: any) => (
|
||||||
|
<ActionMenu
|
||||||
|
id={info.row.original.rowKey}
|
||||||
|
onDelete={onDeleteEntry}
|
||||||
|
onOpenCloseForm={onOpenCloseEntryForm}
|
||||||
|
onOpenCloseTracks={onOpenCloseTracks}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
const tracksColumn: ColumnDef<ILogbookEntry> = {
|
||||||
|
accessorKey: 'tracks',
|
||||||
|
header: 'Tracks',
|
||||||
|
cell: (info: any) => {
|
||||||
|
if (info.row.original.tracks && JSON.parse(info.row.original.tracks).length > 0) {
|
||||||
|
return (
|
||||||
|
<IconButton onClick={() => onOpenCloseTracks(FormMode.VIEW, info.row.original.rowKey)}><Icon iconName={IconName.MAP_LOCATION_DOT} /></IconButton>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const getLogbookEntries = async () => {
|
const getLogbookEntries = async () => {
|
||||||
try {
|
try {
|
||||||
dispatch({ type: 'SET_IS_LOADING', payload: true });
|
dispatch({ type: 'SET_IS_LOADING', payload: true });
|
||||||
|
|
||||||
const response: AxiosResponse = await httpClient.get(`api/logs`);
|
const config = isAuthenticated
|
||||||
|
? { headers: { Authorization: await getAccessToken() } }
|
||||||
|
: {};
|
||||||
|
const response: AxiosResponse = await httpClient.get(`api/logs`, config);
|
||||||
const entries: ILogbookEntry[] = response.data;
|
const entries: ILogbookEntry[] = response.data;
|
||||||
|
|
||||||
entries.sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime())
|
entries.sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime())
|
||||||
@@ -91,6 +123,34 @@ const Logbook: React.FC<unknown> = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const onOpenCloseTracks = (mode: FormMode, rowKey?: string) => {
|
||||||
|
switch(mode) {
|
||||||
|
case FormMode.EDIT:
|
||||||
|
case FormMode.VIEW:
|
||||||
|
dispatch({
|
||||||
|
type: 'SET_OPEN_CLOSE_TRACKS',
|
||||||
|
payload: {
|
||||||
|
tracksMode: mode,
|
||||||
|
isTracksOpen: true,
|
||||||
|
selectedRowKey: rowKey
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
break;
|
||||||
|
case FormMode.CANCEL:
|
||||||
|
dispatch({
|
||||||
|
type: 'SET_OPEN_CLOSE_TRACKS',
|
||||||
|
payload: {
|
||||||
|
tracksMode: mode,
|
||||||
|
isTracksOpen: false,
|
||||||
|
selectedRowKey: undefined
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const onDeleteEntry = (entryId: string) => {
|
const onDeleteEntry = (entryId: string) => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: 'SET_DELETE',
|
type: 'SET_DELETE',
|
||||||
@@ -133,292 +193,36 @@ const Logbook: React.FC<unknown> = () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const unauthColumns: ColumnDef<ILogbookEntry>[] = [
|
useEffect(() => {
|
||||||
{
|
let newColumns: ColumnDef<ILogbookEntry>[];
|
||||||
accessorKey: 'pilotName',
|
|
||||||
header: 'Pilot',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: 'date',
|
|
||||||
header: 'Date'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: 'aircraftMakeModel',
|
|
||||||
header: 'Aircraft Make & Model'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'route',
|
|
||||||
header: 'Route of Flight',
|
|
||||||
meta: {
|
|
||||||
headerAlign: 'center'
|
|
||||||
},
|
|
||||||
columns: [
|
|
||||||
{
|
|
||||||
accessorKey: 'routeFrom',
|
|
||||||
header: 'From'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: 'routeTo',
|
|
||||||
header: 'To'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: 'durationOfFlight',
|
|
||||||
header: 'Duration Of Flight',
|
|
||||||
meta: {
|
|
||||||
align: 'right',
|
|
||||||
headerAlign: 'right'
|
|
||||||
},
|
|
||||||
cell: (info: any) =>
|
|
||||||
info.getValue() ? parseFloat(info.getValue()).toFixed(1) : ''
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: 'notes',
|
|
||||||
header: 'Notes'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
header: 'Actions',
|
|
||||||
meta: {
|
|
||||||
align: 'center',
|
|
||||||
headerAlign: 'center'
|
|
||||||
},
|
|
||||||
cell: (info: any) => (
|
|
||||||
<ActionMenu
|
|
||||||
id={info.row.original.rowKey}
|
|
||||||
onDelete={onDeleteEntry}
|
|
||||||
onOpenCloseForm={onOpenCloseEntryForm}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
const authColumns: ColumnDef<ILogbookEntry>[] = [
|
if (isAuthenticated) {
|
||||||
{
|
newColumns = [...authColumns];
|
||||||
accessorKey: 'pilotName',
|
} else {
|
||||||
header: 'Pilot',
|
newColumns = [...unauthColumns];
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: 'date',
|
|
||||||
header: 'Date'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: 'aircraftMakeModel',
|
|
||||||
header: 'Aircraft Make & Model'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: 'aircraftIdentity',
|
|
||||||
header: 'Aircraft Identity',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'route',
|
|
||||||
header: 'Route of Flight',
|
|
||||||
meta: {
|
|
||||||
headerAlign: 'center'
|
|
||||||
},
|
|
||||||
columns: [
|
|
||||||
{
|
|
||||||
accessorKey: 'routeFrom',
|
|
||||||
header: 'From'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: 'routeTo',
|
|
||||||
header: 'To'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: 'durationOfFlight',
|
|
||||||
header: 'Duration Of Flight',
|
|
||||||
meta: {
|
|
||||||
align: 'right',
|
|
||||||
headerAlign: 'right'
|
|
||||||
},
|
|
||||||
cell: (info: any) =>
|
|
||||||
info.getValue() ? parseFloat(info.getValue()).toFixed(1) : ''
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: 'singleEngineLand',
|
|
||||||
header: 'Single Engine Land',
|
|
||||||
meta: {
|
|
||||||
align: 'right',
|
|
||||||
headerAlign: 'right'
|
|
||||||
},
|
|
||||||
cell: (info: any) =>
|
|
||||||
info.getValue() ? parseFloat(info.getValue()).toFixed(1) : ''
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'landings',
|
|
||||||
header: 'Landings',
|
|
||||||
meta: {
|
|
||||||
headerAlign: 'center'
|
|
||||||
},
|
|
||||||
columns: [
|
|
||||||
{
|
|
||||||
accessorKey: 'landingsDay',
|
|
||||||
header: 'Day',
|
|
||||||
meta: {
|
|
||||||
align: 'right',
|
|
||||||
headerAlign: 'right'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: 'landingsNight',
|
|
||||||
header: 'Night',
|
|
||||||
meta: {
|
|
||||||
align: 'right',
|
|
||||||
headerAlign: 'right'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'instrument',
|
|
||||||
header: 'Instrument',
|
|
||||||
meta: {
|
|
||||||
headerAlign: 'center'
|
|
||||||
},
|
|
||||||
columns: [
|
|
||||||
{
|
|
||||||
accessorKey: 'instrumentActual',
|
|
||||||
header: 'Actual',
|
|
||||||
meta: {
|
|
||||||
align: 'right',
|
|
||||||
headerAlign: 'right'
|
|
||||||
},
|
|
||||||
cell: (info: any) =>
|
|
||||||
info.getValue() ? parseFloat(info.getValue()).toFixed(1) : ''
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: 'instrumentSimulated',
|
|
||||||
header: 'Simulated',
|
|
||||||
meta: {
|
|
||||||
align: 'right',
|
|
||||||
headerAlign: 'right'
|
|
||||||
},
|
|
||||||
cell: (info: any) =>
|
|
||||||
info.getValue() ? parseFloat(info.getValue()).toFixed(1) : ''
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: 'instrumentApproaches',
|
|
||||||
header: 'Approaches',
|
|
||||||
meta: {
|
|
||||||
align: 'right',
|
|
||||||
headerAlign: 'right'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: 'instrumentHolds',
|
|
||||||
header: 'Holds',
|
|
||||||
meta: {
|
|
||||||
align: 'right',
|
|
||||||
headerAlign: 'right'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: 'instrumentNavTrack',
|
|
||||||
header: 'Nav/Track',
|
|
||||||
meta: {
|
|
||||||
align: 'right',
|
|
||||||
headerAlign: 'right'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'experienceTraining',
|
|
||||||
header: 'Type of pilot experience or training',
|
|
||||||
meta: {
|
|
||||||
headerAlign: 'center'
|
|
||||||
},
|
|
||||||
columns: [
|
|
||||||
{
|
|
||||||
accessorKey: 'groundTrainingReceived',
|
|
||||||
header: 'Ground Training Received',
|
|
||||||
meta: {
|
|
||||||
align: 'right',
|
|
||||||
headerAlign: 'right'
|
|
||||||
},
|
|
||||||
cell: (info: any) =>
|
|
||||||
info.getValue() ? parseFloat(info.getValue()).toFixed(1) : ''
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: 'flightTrainingReceived',
|
|
||||||
header: 'Flight Training Received',
|
|
||||||
meta: {
|
|
||||||
align: 'right',
|
|
||||||
headerAlign: 'right'
|
|
||||||
},
|
|
||||||
cell: (info: any) =>
|
|
||||||
info.getValue() ? parseFloat(info.getValue()).toFixed(1) : ''
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: 'crossCountry',
|
|
||||||
header: 'Cross Country',
|
|
||||||
meta: {
|
|
||||||
align: 'right',
|
|
||||||
headerAlign: 'right'
|
|
||||||
},
|
|
||||||
cell: (info: any) =>
|
|
||||||
info.getValue() ? parseFloat(info.getValue()).toFixed(1) : ''
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: 'night',
|
|
||||||
header: 'Night',
|
|
||||||
meta: {
|
|
||||||
align: 'right',
|
|
||||||
headerAlign: 'right'
|
|
||||||
},
|
|
||||||
cell: (info: any) =>
|
|
||||||
info.getValue() ? parseFloat(info.getValue()).toFixed(1) : ''
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: 'solo',
|
|
||||||
header: 'Solo',
|
|
||||||
meta: {
|
|
||||||
align: 'right',
|
|
||||||
headerAlign: 'right'
|
|
||||||
},
|
|
||||||
cell: (info: any) =>
|
|
||||||
info.getValue() ? parseFloat(info.getValue()).toFixed(1) : ''
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: 'pilotInCommand',
|
|
||||||
header: 'Pilot In Command',
|
|
||||||
meta: {
|
|
||||||
align: 'right',
|
|
||||||
headerAlign: 'right'
|
|
||||||
},
|
|
||||||
cell: (info: any) =>
|
|
||||||
info.getValue() ? parseFloat(info.getValue()).toFixed(1) : ''
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: 'notes',
|
|
||||||
header: 'Notes'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
header: 'Actions',
|
|
||||||
meta: {
|
|
||||||
align: 'center',
|
|
||||||
headerAlign: 'center'
|
|
||||||
},
|
|
||||||
cell: (info: any) => (
|
|
||||||
<ActionMenu
|
|
||||||
id={info.row.original.rowKey}
|
|
||||||
onDelete={onDeleteEntry}
|
|
||||||
onOpenCloseForm={onOpenCloseEntryForm}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
];
|
|
||||||
|
const actionsColumnExists = newColumns.find((column) => column.id === 'actions');
|
||||||
|
const tracksColumnExists = newColumns.find((column) => column.id === 'actions');
|
||||||
|
|
||||||
|
if (!actionsColumnExists) {
|
||||||
|
newColumns.push(actionsColumn);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!tracksColumnExists) {
|
||||||
|
const notesColumnIndex = newColumns.findIndex((column) => column.id === 'notes')
|
||||||
|
|
||||||
|
newColumns.splice(notesColumnIndex, 0, tracksColumn)
|
||||||
|
}
|
||||||
|
|
||||||
|
dispatch({ type: 'SET_COLUMNS', payload: newColumns })
|
||||||
|
}, [isAuthenticated])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!state.isFormOpen) {
|
if (!state.isFormOpen) {
|
||||||
getLogbookEntries();
|
getLogbookEntries();
|
||||||
}
|
}
|
||||||
}, [state.isFormOpen]);
|
}, [state.isFormOpen, state.isTracksOpen]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box sx={{ margin: '20px' }}>
|
<Box sx={{ margin: '20px' }}>
|
||||||
@@ -453,11 +257,11 @@ const Logbook: React.FC<unknown> = () => {
|
|||||||
)}
|
)}
|
||||||
{!state.isLoading && (
|
{!state.isLoading && (
|
||||||
<Grid size={12}>
|
<Grid size={12}>
|
||||||
{isMedium && state.entries.length > 0 && (
|
{isMedium && state.columns && state.columns.length > 0 && state.entries.length > 0 && (
|
||||||
<Table columns={isAuthenticated ? authColumns : unauthColumns} 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>
|
||||||
)}
|
)}
|
||||||
@@ -490,6 +294,14 @@ const Logbook: React.FC<unknown> = () => {
|
|||||||
title="Confirm Delete"
|
title="Confirm Delete"
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
{state.isTracksOpen &&
|
||||||
|
<LogTracks
|
||||||
|
isDrawerOpen={state.isTracksOpen}
|
||||||
|
mode={state.tracksMode}
|
||||||
|
onOpenClose={(mode) => onOpenCloseTracks(mode)}
|
||||||
|
selectedRowKey={state.selectedEntryId}
|
||||||
|
/>
|
||||||
|
}
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
252
app/src/components/logbook/columns.tsx
Normal file
252
app/src/components/logbook/columns.tsx
Normal file
@@ -0,0 +1,252 @@
|
|||||||
|
import {
|
||||||
|
ColumnDef,
|
||||||
|
Icon,
|
||||||
|
IconButton,
|
||||||
|
IconName
|
||||||
|
} from '@noahspan/noahspan-components';
|
||||||
|
import { ILogbookEntry } from './ILogbookEntry';
|
||||||
|
|
||||||
|
const pilotName: ColumnDef<ILogbookEntry> = {
|
||||||
|
id: 'pilotName',
|
||||||
|
accessorKey: 'pilotName',
|
||||||
|
header: 'Pilot'
|
||||||
|
}
|
||||||
|
const date: ColumnDef<ILogbookEntry> = {
|
||||||
|
id: 'date',
|
||||||
|
accessorKey: 'date',
|
||||||
|
header: 'Date'
|
||||||
|
}
|
||||||
|
const aircraftMakeModel: ColumnDef<ILogbookEntry> = {
|
||||||
|
id: 'aircraftMakeModel',
|
||||||
|
accessorKey: 'aircraftMakeModel',
|
||||||
|
header: 'Aircraft Make & Model'
|
||||||
|
}
|
||||||
|
const route: ColumnDef<ILogbookEntry> = {
|
||||||
|
id: 'route',
|
||||||
|
header: 'Route of Flight',
|
||||||
|
meta: {
|
||||||
|
headerAlign: 'center'
|
||||||
|
},
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
id: 'routeFrom',
|
||||||
|
accessorKey: 'routeFrom',
|
||||||
|
header: 'From'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'routeTo',
|
||||||
|
accessorKey: 'routeTo',
|
||||||
|
header: 'To'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
const durationOfFlight: ColumnDef<ILogbookEntry> = {
|
||||||
|
id: 'durationOfFlight',
|
||||||
|
accessorKey: 'durationOfFlight',
|
||||||
|
header: 'Duration Of Flight',
|
||||||
|
meta: {
|
||||||
|
align: 'right',
|
||||||
|
headerAlign: 'right'
|
||||||
|
},
|
||||||
|
cell: (info: any) =>
|
||||||
|
info.getValue() ? parseFloat(info.getValue()).toFixed(1) : ''
|
||||||
|
}
|
||||||
|
const notes: ColumnDef<ILogbookEntry> = {
|
||||||
|
id: 'notes',
|
||||||
|
accessorKey: 'notes',
|
||||||
|
header: 'Notes'
|
||||||
|
}
|
||||||
|
|
||||||
|
export const unauthColumns: ColumnDef<ILogbookEntry>[] = [
|
||||||
|
pilotName,
|
||||||
|
date,
|
||||||
|
aircraftMakeModel,
|
||||||
|
route,
|
||||||
|
durationOfFlight,
|
||||||
|
notes
|
||||||
|
]
|
||||||
|
|
||||||
|
export const authColumns: ColumnDef<ILogbookEntry>[] = [
|
||||||
|
pilotName,
|
||||||
|
date,
|
||||||
|
aircraftMakeModel,
|
||||||
|
{
|
||||||
|
id: 'aircraftIdentity',
|
||||||
|
accessorKey: 'aircraftIdentity',
|
||||||
|
header: 'Aircraft Identity',
|
||||||
|
},
|
||||||
|
route,
|
||||||
|
durationOfFlight,
|
||||||
|
{
|
||||||
|
id: 'singleEngineLand',
|
||||||
|
accessorKey: 'singleEngineLand',
|
||||||
|
header: 'Single Engine Land',
|
||||||
|
meta: {
|
||||||
|
align: 'right',
|
||||||
|
headerAlign: 'right'
|
||||||
|
},
|
||||||
|
cell: (info: any) =>
|
||||||
|
info.getValue() ? parseFloat(info.getValue()).toFixed(1) : ''
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'landings',
|
||||||
|
header: 'Landings',
|
||||||
|
meta: {
|
||||||
|
headerAlign: 'center'
|
||||||
|
},
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
id: 'landingsDay',
|
||||||
|
accessorKey: 'landingsDay',
|
||||||
|
header: 'Day',
|
||||||
|
meta: {
|
||||||
|
align: 'right',
|
||||||
|
headerAlign: 'right'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'landingsNight',
|
||||||
|
accessorKey: 'landingsNight',
|
||||||
|
header: 'Night',
|
||||||
|
meta: {
|
||||||
|
align: 'right',
|
||||||
|
headerAlign: 'right'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'instrument',
|
||||||
|
header: 'Instrument',
|
||||||
|
meta: {
|
||||||
|
headerAlign: 'center'
|
||||||
|
},
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
id: 'instrumentActual',
|
||||||
|
accessorKey: 'instrumentActual',
|
||||||
|
header: 'Actual',
|
||||||
|
meta: {
|
||||||
|
align: 'right',
|
||||||
|
headerAlign: 'right'
|
||||||
|
},
|
||||||
|
cell: (info: any) =>
|
||||||
|
info.getValue() ? parseFloat(info.getValue()).toFixed(1) : ''
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'instrumentSimulated',
|
||||||
|
accessorKey: 'instrumentSimulated',
|
||||||
|
header: 'Simulated',
|
||||||
|
meta: {
|
||||||
|
align: 'right',
|
||||||
|
headerAlign: 'right'
|
||||||
|
},
|
||||||
|
cell: (info: any) =>
|
||||||
|
info.getValue() ? parseFloat(info.getValue()).toFixed(1) : ''
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'instrumentApproaches',
|
||||||
|
accessorKey: 'instrumentApproaches',
|
||||||
|
header: 'Approaches',
|
||||||
|
meta: {
|
||||||
|
align: 'right',
|
||||||
|
headerAlign: 'right'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'instrumentHolds',
|
||||||
|
accessorKey: 'instrumentHolds',
|
||||||
|
header: 'Holds',
|
||||||
|
meta: {
|
||||||
|
align: 'right',
|
||||||
|
headerAlign: 'right'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'instrumentNavTrack',
|
||||||
|
accessorKey: 'instrumentNavTrack',
|
||||||
|
header: 'Nav/Track',
|
||||||
|
meta: {
|
||||||
|
align: 'right',
|
||||||
|
headerAlign: 'right'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'experienceTraining',
|
||||||
|
header: 'Type of pilot experience or training',
|
||||||
|
meta: {
|
||||||
|
headerAlign: 'center'
|
||||||
|
},
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
id: 'groundTrainingReceived',
|
||||||
|
accessorKey: 'groundTrainingReceived',
|
||||||
|
header: 'Ground Training Received',
|
||||||
|
meta: {
|
||||||
|
align: 'right',
|
||||||
|
headerAlign: 'right'
|
||||||
|
},
|
||||||
|
cell: (info: any) =>
|
||||||
|
info.getValue() ? parseFloat(info.getValue()).toFixed(1) : ''
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'flightTrainingReceived',
|
||||||
|
accessorKey: 'flightTrainingReceived',
|
||||||
|
header: 'Flight Training Received',
|
||||||
|
meta: {
|
||||||
|
align: 'right',
|
||||||
|
headerAlign: 'right'
|
||||||
|
},
|
||||||
|
cell: (info: any) =>
|
||||||
|
info.getValue() ? parseFloat(info.getValue()).toFixed(1) : ''
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'crossCountry',
|
||||||
|
accessorKey: 'crossCountry',
|
||||||
|
header: 'Cross Country',
|
||||||
|
meta: {
|
||||||
|
align: 'right',
|
||||||
|
headerAlign: 'right'
|
||||||
|
},
|
||||||
|
cell: (info: any) =>
|
||||||
|
info.getValue() ? parseFloat(info.getValue()).toFixed(1) : ''
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'night',
|
||||||
|
accessorKey: 'night',
|
||||||
|
header: 'Night',
|
||||||
|
meta: {
|
||||||
|
align: 'right',
|
||||||
|
headerAlign: 'right'
|
||||||
|
},
|
||||||
|
cell: (info: any) =>
|
||||||
|
info.getValue() ? parseFloat(info.getValue()).toFixed(1) : ''
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'solo',
|
||||||
|
accessorKey: 'solo',
|
||||||
|
header: 'Solo',
|
||||||
|
meta: {
|
||||||
|
align: 'right',
|
||||||
|
headerAlign: 'right'
|
||||||
|
},
|
||||||
|
cell: (info: any) =>
|
||||||
|
info.getValue() ? parseFloat(info.getValue()).toFixed(1) : ''
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'pilotInCommand',
|
||||||
|
accessorKey: 'pilotInCommand',
|
||||||
|
header: 'Pilot In Command',
|
||||||
|
meta: {
|
||||||
|
align: 'right',
|
||||||
|
headerAlign: 'right'
|
||||||
|
},
|
||||||
|
cell: (info: any) =>
|
||||||
|
info.getValue() ? parseFloat(info.getValue()).toFixed(1) : ''
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
notes
|
||||||
|
]
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
|
import { ColumnDef } from '@noahspan/noahspan-components';
|
||||||
import { FormMode } from '../../enums/formMode';
|
import { FormMode } from '../../enums/formMode';
|
||||||
import { Alert } from '../../interfaces/Alert.interface';
|
import { Alert } from '../../interfaces/Alert.interface';
|
||||||
import { ILogbookEntry } from './ILogbookEntry';
|
import { ILogbookEntry } from './ILogbookEntry';
|
||||||
import { ILogbookState } from './ILogbookState';
|
import { ILogbookState } from './ILogbookState';
|
||||||
|
|
||||||
type Action =
|
type Action =
|
||||||
|
| { type: 'SET_COLUMNS'; payload: ColumnDef<ILogbookEntry>[] }
|
||||||
| {
|
| {
|
||||||
type: 'SET_DELETE';
|
type: 'SET_DELETE';
|
||||||
payload: {
|
payload: {
|
||||||
@@ -23,17 +25,21 @@ type Action =
|
|||||||
selectedEntryId: string | undefined;
|
selectedEntryId: string | undefined;
|
||||||
isFormOpen: boolean;
|
isFormOpen: boolean;
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
| { type: 'SET_OPEN_CLOSE_TRACKS'; payload: { tracksMode: FormMode, selectedRowKey: string | undefined, isTracksOpen: boolean; }};
|
||||||
|
|
||||||
export const initialState: ILogbookState = {
|
export const initialState: ILogbookState = {
|
||||||
alert: undefined,
|
alert: undefined,
|
||||||
|
columns: [],
|
||||||
entries: [],
|
entries: [],
|
||||||
formMode: FormMode.CANCEL,
|
formMode: FormMode.CANCEL,
|
||||||
isConfirmDialogLoading: false,
|
isConfirmDialogLoading: false,
|
||||||
isConfirmDialogOpen: false,
|
isConfirmDialogOpen: false,
|
||||||
isFormOpen: false,
|
isFormOpen: false,
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
selectedEntryId: undefined
|
isTracksOpen: false,
|
||||||
|
selectedEntryId: undefined,
|
||||||
|
tracksMode: FormMode.CANCEL
|
||||||
};
|
};
|
||||||
|
|
||||||
export const reducer = (
|
export const reducer = (
|
||||||
@@ -41,6 +47,12 @@ export const reducer = (
|
|||||||
action: Action
|
action: Action
|
||||||
): ILogbookState => {
|
): ILogbookState => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
|
case 'SET_COLUMNS': {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
columns: action.payload
|
||||||
|
}
|
||||||
|
}
|
||||||
case 'SET_DELETE': {
|
case 'SET_DELETE': {
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
@@ -86,6 +98,14 @@ export const reducer = (
|
|||||||
selectedEntryId: action.payload.selectedEntryId
|
selectedEntryId: action.payload.selectedEntryId
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
case 'SET_OPEN_CLOSE_TRACKS': {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
tracksMode: action.payload.tracksMode,
|
||||||
|
isTracksOpen: action.payload.isTracksOpen,
|
||||||
|
selectedEntryId: action.payload.selectedRowKey
|
||||||
|
}
|
||||||
|
}
|
||||||
default: {
|
default: {
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
@@ -197,7 +197,7 @@ const PilotForm: React.FC<IPilotFormProps> = ({
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<FormProvider {...methods}>
|
<FormProvider {...methods}>
|
||||||
<form onSubmit={methods.handleSubmit(onSubmit)}>
|
<form onSubmit={methods.handleSubmit(onSubmit)} style={{ paddingBottom: '50px' }}>
|
||||||
<Grid container spacing={2}>
|
<Grid container spacing={2}>
|
||||||
<Grid size={11}>
|
<Grid size={11}>
|
||||||
<Typography variant="h4">{`${mode.toString().toLowerCase().charAt(0).toUpperCase() + mode.toString().slice(1).toLowerCase()} Pilot`}</Typography>
|
<Typography variant="h4">{`${mode.toString().toLowerCase().charAt(0).toUpperCase() + mode.toString().slice(1).toLowerCase()} Pilot`}</Typography>
|
||||||
|
|||||||
@@ -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();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
46
app/src/hooks/logs/UseLogs.tsx
Normal file
46
app/src/hooks/logs/UseLogs.tsx
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
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 [isLoading, setIsLoading] = useState<boolean>(false);
|
||||||
|
const httpClient: AxiosInstance = useHttpClient();
|
||||||
|
const { getAccessToken } = useAccessToken();
|
||||||
|
const isAuthenticated = useIsAuthenticated();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const getLogs = async () => {
|
||||||
|
try {
|
||||||
|
setIsLoading(true);
|
||||||
|
|
||||||
|
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;
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getLogs();
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
return {
|
||||||
|
logs,
|
||||||
|
isLoading
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
body {
|
body {
|
||||||
background-color: #f2f2f2;
|
background-color: #f2f2f2;
|
||||||
|
margin: 8px;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ services:
|
|||||||
- '10000:10000'
|
- '10000:10000'
|
||||||
- '10001:10001'
|
- '10001:10001'
|
||||||
- '10002:10002'
|
- '10002:10002'
|
||||||
command: 'azurite --blobHost 0.0.0.0 --queueHost 0.0.0.0 --tableHost 0.0.0.0 --loose'
|
command: 'azurite --blobHost 0.0.0.0 --queueHost 0.0.0.0 --tableHost 0.0.0.0 --loose --skipApiVersionCheck'
|
||||||
volumes:
|
volumes:
|
||||||
- ./azurite-flying:/data
|
- ./azurite-flying:/data
|
||||||
|
|
||||||
|
|||||||
@@ -59,6 +59,11 @@ locals {
|
|||||||
prod = "noahspanflyingprod"
|
prod = "noahspanflyingprod"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
storage_containers = {
|
||||||
|
test = ["tracks"]
|
||||||
|
prod = ["tracks"]
|
||||||
|
}
|
||||||
|
|
||||||
storage_tables = {
|
storage_tables = {
|
||||||
test = ["logs", "pilots"]
|
test = ["logs", "pilots"]
|
||||||
prod = ["logs", "pilots"]
|
prod = ["logs", "pilots"]
|
||||||
|
|||||||
@@ -46,6 +46,10 @@ output "storage_account_name" {
|
|||||||
value = local.storage_account_name[var.environment]
|
value = local.storage_account_name[var.environment]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
output "storage_containers" {
|
||||||
|
value = local.storage_containers[var.environment]
|
||||||
|
}
|
||||||
|
|
||||||
output "storage_tables" {
|
output "storage_tables" {
|
||||||
value = local.storage_tables[var.environment]
|
value = local.storage_tables[var.environment]
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,7 @@ module "storage" {
|
|||||||
source = "github.com/noahspannbauer/noahspan-terraform/modules/storage"
|
source = "github.com/noahspannbauer/noahspan-terraform/modules/storage"
|
||||||
resource_group_name = var.RESOURCE_GROUP_NAME
|
resource_group_name = var.RESOURCE_GROUP_NAME
|
||||||
storage_account_name = module.environment.storage_account_name
|
storage_account_name = module.environment.storage_account_name
|
||||||
|
storage_containers = module.environment.storage_containers
|
||||||
storage_tables = module.environment.storage_tables
|
storage_tables = module.environment.storage_tables
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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\"",
|
||||||
|
|||||||
1369
pnpm-lock.yaml
generated
1369
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user