-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Saving changes. Continuing reworking of validation CRUD system and be…
…ginning application of feedback changes.
- Loading branch information
1 parent
555e307
commit cbfd04d
Showing
16 changed files
with
477 additions
and
291 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,133 +1,5 @@ | ||
'use client'; | ||
import React, { useState } from 'react'; | ||
import { GridRowModes, GridRowModesModel, GridRowsProp } from '@mui/x-data-grid'; | ||
import { Alert, AlertProps } from '@mui/material'; | ||
import { initialMeasurementsSummaryViewRDSRow } from '@/config/sqlrdsdefinitions/views/measurementssummaryviewrds'; | ||
import { Box, Button, Snackbar, Stack, Typography } from '@mui/joy'; | ||
import { useOrgCensusContext, usePlotContext } from '@/app/contexts/userselectionprovider'; | ||
import { randomId } from '@mui/x-data-grid-generator'; | ||
import UploadParentModal from '@/components/uploadsystemhelpers/uploadparentmodal'; | ||
import MeasurementSummaryGrid from '@/components/datagrids/msvdatagrid'; | ||
import { msvGridColumns } from '@/components/client/datagridcolumns'; | ||
import MeasurementsSummaryViewDataGrid from '@/components/datagrids/applications/measurementssummaryviewdatagrid'; | ||
|
||
export default function SummaryPage() { | ||
const currentPlot = usePlotContext(); | ||
const currentCensus = useOrgCensusContext(); | ||
const [isUploadModalOpen, setIsUploadModalOpen] = useState(false); | ||
const [triggerGlobalError, setTriggerGlobalError] = useState(false); | ||
const [globalError, setGlobalError] = useState<string | null>(null); | ||
|
||
const [rows, setRows] = React.useState([initialMeasurementsSummaryViewRDSRow] as GridRowsProp); | ||
const [rowCount, setRowCount] = useState(0); | ||
const [rowModesModel, setRowModesModel] = React.useState<GridRowModesModel>({}); | ||
const [snackbar, setSnackbar] = React.useState<Pick<AlertProps, 'children' | 'severity'> | null>(null); | ||
const [refresh, setRefresh] = useState(false); | ||
const [paginationModel, setPaginationModel] = useState({ | ||
page: 0, | ||
pageSize: 10 | ||
}); | ||
const [isNewRowAdded, setIsNewRowAdded] = useState<boolean>(false); | ||
const [shouldAddRowAfterFetch, setShouldAddRowAfterFetch] = useState(false); | ||
|
||
const addNewRowToGrid = () => { | ||
const id = randomId(); | ||
// Define new row structure based on MeasurementsSummaryRDS type | ||
const newRow = { | ||
...initialMeasurementsSummaryViewRDSRow, | ||
id: id, | ||
coreMeasurementID: 0, | ||
plotID: currentPlot?.plotID, | ||
plotName: currentPlot?.plotName, | ||
censusID: currentCensus?.dateRanges[0].censusID, | ||
censusStartDate: currentCensus?.dateRanges[0]?.startDate, | ||
censusEndDate: currentCensus?.dateRanges[0]?.endDate, | ||
isNew: true | ||
}; | ||
setRows(oldRows => [...oldRows, newRow]); | ||
setRowModesModel(oldModel => ({ | ||
...oldModel, | ||
[id]: { mode: GridRowModes.Edit } | ||
})); | ||
}; | ||
|
||
const handleCloseGlobalError = () => { | ||
setGlobalError(null); | ||
setTriggerGlobalError(false); | ||
}; | ||
|
||
return ( | ||
<> | ||
{globalError && ( | ||
<Snackbar open={triggerGlobalError} autoHideDuration={6000} onClose={handleCloseGlobalError}> | ||
<Alert onClose={handleCloseGlobalError} severity="error"> | ||
{globalError} | ||
</Alert> | ||
</Snackbar> | ||
)} | ||
<Box sx={{ display: 'flex', alignItems: 'center', mb: 3, width: '100%' }}> | ||
<Box | ||
sx={{ | ||
width: '100%', | ||
display: 'flex', | ||
justifyContent: 'space-between', | ||
alignItems: 'center', | ||
backgroundColor: 'warning.main', | ||
borderRadius: '4px', | ||
p: 2 | ||
}} | ||
> | ||
<Stack direction="column"> | ||
<Box sx={{ display: 'flex', flexDirection: 'column', flexGrow: 1 }}> | ||
<Box | ||
sx={{ | ||
flex: 1, | ||
display: 'flex', | ||
justifyContent: 'left', | ||
flexDirection: 'column', | ||
marginTop: 2 | ||
}} | ||
> | ||
<Typography level={'title-md'} sx={{ color: '#ffa726' }}> | ||
Note: This plot does not accept subquadrats. <br /> | ||
Please ensure that you use quadrat names when submitting new measurements instead of subquadrat names | ||
</Typography> | ||
</Box> | ||
</Box> | ||
</Stack> | ||
<Box sx={{ display: 'flex', alignItems: 'center', gap: 2 }}> | ||
<Button>Upload</Button> | ||
</Box> | ||
</Box> | ||
</Box> | ||
<UploadParentModal | ||
isUploadModalOpen={isUploadModalOpen} | ||
handleCloseUploadModal={() => { | ||
setIsUploadModalOpen(false); | ||
setRefresh(true); | ||
}} | ||
formType={'measurements'} | ||
/> | ||
<MeasurementSummaryGrid | ||
gridType={'measurementssummary'} | ||
gridColumns={msvGridColumns} | ||
rows={rows} | ||
setRows={setRows} | ||
rowCount={rowCount} | ||
setRowCount={setRowCount} | ||
rowModesModel={rowModesModel} | ||
setRowModesModel={setRowModesModel} | ||
snackbar={snackbar} | ||
setSnackbar={setSnackbar} | ||
refresh={refresh} | ||
setRefresh={setRefresh} | ||
paginationModel={paginationModel} | ||
setPaginationModel={setPaginationModel} | ||
isNewRowAdded={isNewRowAdded} | ||
setIsNewRowAdded={setIsNewRowAdded} | ||
shouldAddRowAfterFetch={shouldAddRowAfterFetch} | ||
setShouldAddRowAfterFetch={setShouldAddRowAfterFetch} | ||
addNewRowToGrid={addNewRowToGrid} | ||
/> | ||
</> | ||
); | ||
return <MeasurementsSummaryViewDataGrid />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { NextRequest, NextResponse } from 'next/server'; | ||
import { PoolConnection } from 'mysql2/promise'; | ||
import { getConn, runQuery } from '@/components/processors/processormacros'; | ||
import MapperFactory from '@/config/datamapper'; | ||
|
||
export async function GET(request: NextRequest) { | ||
const schema = request.nextUrl.searchParams.get('schema'); | ||
if (!schema) throw new Error('no schema variable provided!'); | ||
const plotIDParam = request.nextUrl.searchParams.get('plotID'); | ||
const censusIDParam = request.nextUrl.searchParams.get('censusID'); | ||
const plotID = plotIDParam ? parseInt(plotIDParam) : null; | ||
const censusID = censusIDParam ? parseInt(censusIDParam) : null; | ||
const query = ` | ||
SELECT | ||
cm.* | ||
FROM | ||
${schema}.coremeasurements cm | ||
JOIN | ||
${schema}.stems s ON cm.StemID = s.StemID | ||
JOIN | ||
${schema}.quadrats q ON s.QuadratID = q.QuadratID | ||
WHERE | ||
cm.IsValidated IS NULL | ||
${plotID !== null ? `AND q.PlotID = ${plotID}` : ''} | ||
${censusID !== null ? `AND cm.CensusID = ${censusID}` : ''} ORDER BY MeasurementDate LIMIT 10;`; | ||
let conn: PoolConnection | null = null; | ||
try { | ||
conn = await getConn(); | ||
const results = await runQuery(conn, query); | ||
return new NextResponse(JSON.stringify(MapperFactory.getMapper<any, any>('coremeasurements').mapData(results)), { | ||
status: 200 | ||
}); | ||
} catch (error: any) { | ||
console.error('Error in update operation:', error.message); | ||
return new NextResponse(JSON.stringify({ error: error.message }), { | ||
status: 500 | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.