Compare commits
7 Commits
v1.4.0
...
feature/71
| Author | SHA1 | Date | |
|---|---|---|---|
| c6e98314a6 | |||
| d4be759dab | |||
| 113ccbf440 | |||
| e99f3ecafe | |||
| c5cb63e457 | |||
| 432dbb178f | |||
| e09566e270 |
@@ -7,6 +7,20 @@ import { ConfigService } from '@nestjs/config';
|
||||
|
||||
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)
|
||||
@@ -23,7 +37,7 @@ import { ConfigService } from '@nestjs/config';
|
||||
return blockBlobClient;
|
||||
}
|
||||
|
||||
async uploadFile(file: Express.Multer.File, containerName: string, rowKey: string) {
|
||||
async uploadFile(file: Express.Multer.File, containerName: string, rowKey: string): Promise<string> {
|
||||
this.containerName = containerName;
|
||||
|
||||
const blockBlobClient = await this.getBlobClient(`${rowKey}/${file.originalname}`);
|
||||
@@ -34,7 +48,17 @@ import { ConfigService } from '@nestjs/config';
|
||||
return fileUrl;
|
||||
}
|
||||
|
||||
async deleteFile(containerName: string, rowKey:string, fileName: string) {
|
||||
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}`);
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
Post,
|
||||
Put,
|
||||
Query,
|
||||
StreamableFile,
|
||||
UploadedFile,
|
||||
UseGuards,
|
||||
UseInterceptors
|
||||
@@ -22,14 +23,15 @@ import { FileService } from '../file/file.service';
|
||||
import { FileInterceptor } from '@nestjs/platform-express';
|
||||
|
||||
@Controller('logs')
|
||||
@UseInterceptors(new LogInterceptor())
|
||||
export class LogController {
|
||||
constructor(
|
||||
private readonly fileService: FileService,
|
||||
private readonly logService: LogService
|
||||
) {}
|
||||
|
||||
|
||||
@Get(':partitionKey/:rowKey')
|
||||
@UseInterceptors(new LogInterceptor())
|
||||
async find(
|
||||
@Param('partitionKey') partitionKey: string,
|
||||
@Param('rowKey') rowKey: string
|
||||
@@ -44,6 +46,7 @@ export class LogController {
|
||||
}
|
||||
|
||||
@Get()
|
||||
@UseInterceptors(new LogInterceptor())
|
||||
async findAll(): Promise<Log[]> {
|
||||
try {
|
||||
return await this.logService.findAll();
|
||||
@@ -121,11 +124,18 @@ export class LogController {
|
||||
}
|
||||
}
|
||||
|
||||
@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 {
|
||||
console.log(fileName)
|
||||
const containerName = 'tracks';
|
||||
|
||||
return await this.fileService.deleteFile(containerName, rowKey, fileName)
|
||||
|
||||
@@ -13,16 +13,23 @@
|
||||
"dependencies": {
|
||||
"@azure/msal-browser": "^4.0.1",
|
||||
"@azure/msal-react": "^3.0.1",
|
||||
"@noahspan/noahspan-components": "^1.6.0",
|
||||
"@noahspan/noahspan-components": "1.6.0",
|
||||
"axios": "^1.7.2",
|
||||
"dotenv": "^16.4.7",
|
||||
"react": "^18.3.1",
|
||||
"react-dom": "^18.3.1",
|
||||
"install": "^0.13.0",
|
||||
"leaflet": "^1.9.4",
|
||||
"pure-react-carousel": "^1.32.0",
|
||||
"react": "19.0.0-rc.1",
|
||||
"react-dom": "19.0.0-rc.1",
|
||||
"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": {
|
||||
"@microsoft/microsoft-graph-types": "^2.40.0",
|
||||
"@types/leaflet": "^1.9.16",
|
||||
"@types/react": "^18.2.66",
|
||||
"@types/react-dom": "^18.2.22",
|
||||
"@vitejs/plugin-react": "^4.2.1",
|
||||
|
||||
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;
|
||||
}
|
||||
84
app/src/components/logTrackMaps/LogTrackMaps.tsx
Normal file
84
app/src/components/logTrackMaps/LogTrackMaps.tsx
Normal file
@@ -0,0 +1,84 @@
|
||||
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')
|
||||
// const converted = toGeoJSON.kml(dom);
|
||||
|
||||
// rewind(converted, false);
|
||||
|
||||
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[];
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useEffect, useReducer, useState } from "react";
|
||||
import { useEffect, useReducer } from "react";
|
||||
import { Button, Drawer, Grid, Icon, IconButton, IconName, TextField, theme, Typography, useMediaQuery } from "@noahspan/noahspan-components";
|
||||
import { useHttpClient } from "../../hooks/httpClient/UseHttpClient";
|
||||
import { AxiosInstance, AxiosResponse } from "axios";
|
||||
@@ -9,6 +9,7 @@ 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)
|
||||
@@ -135,6 +136,8 @@ const LogTracks = ({ isDrawerOpen, mode, onOpenClose, selectedRowKey }: LogTrack
|
||||
<Icon iconName={IconName.XMARK} />
|
||||
</IconButton>
|
||||
</Grid>
|
||||
{mode === FormMode.EDIT &&
|
||||
<>
|
||||
{state.tracks.length > 0 && state.tracks.map((track, index) => {
|
||||
const trackSplit = track.split('/')
|
||||
const filename = trackSplit[trackSplit.length - 1];
|
||||
@@ -149,8 +152,7 @@ const LogTracks = ({ isDrawerOpen, mode, onOpenClose, selectedRowKey }: LogTrack
|
||||
</Grid>
|
||||
</>
|
||||
)
|
||||
})
|
||||
}
|
||||
})}
|
||||
<Grid display='flex' gap={2} justifyContent='right' size={12}>
|
||||
<Button
|
||||
startIcon={<Icon iconName={IconName.XMARK} />}
|
||||
@@ -172,6 +174,11 @@ const LogTracks = ({ isDrawerOpen, mode, onOpenClose, selectedRowKey }: LogTrack
|
||||
</Button>
|
||||
)}
|
||||
</Grid>
|
||||
</>
|
||||
}
|
||||
{mode === FormMode.VIEW &&
|
||||
<LogTrackMaps rowKey={selectedRowKey!} trackUrls={state.tracks} />
|
||||
}
|
||||
</Grid>
|
||||
{state.isConfirmDialogOpen && (
|
||||
<ConfirmationDialog
|
||||
@@ -183,6 +190,7 @@ const LogTracks = ({ isDrawerOpen, mode, onOpenClose, selectedRowKey }: LogTrack
|
||||
title="Confirm Delete"
|
||||
/>
|
||||
)}
|
||||
|
||||
</Drawer>
|
||||
)
|
||||
}
|
||||
|
||||
1364
pnpm-lock.yaml
generated
1364
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user