Skip to content

Commit

Permalink
[frontend/backend] format exercise report pdf
Browse files Browse the repository at this point in the history
Signed-off-by: Marine LM <[email protected]>
  • Loading branch information
MarineLeM committed Oct 14, 2024
1 parent db39652 commit d492950
Show file tree
Hide file tree
Showing 36 changed files with 769 additions and 689 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public Report createExerciseReport(@PathVariable String exerciseId, @Valid @Requ
@PutMapping("/api/exercises/{exerciseId}/reports/{reportId}/inject-comments")
@PreAuthorize("isExercisePlanner(#exerciseId)")
@Transactional(rollbackOn = Exception.class)
public Iterable<ReportInjectComment> updateReportInjectComment(@PathVariable String exerciseId, @PathVariable String reportId, @Valid @RequestBody ReportInjectCommentInput input) {
public Report updateReportInjectComment(@PathVariable String exerciseId, @PathVariable String reportId, @Valid @RequestBody ReportInjectCommentInput input) {
Report report = this.reportService.report(UUID.fromString(reportId));
assert exerciseId.equals(report.getExercise().getId());
Inject inject = this.injectService.inject(input.getInjectId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public Report updateReport(@NotNull final Report report, @NotNull final ReportIn
return this.reportRepository.save(report);
}

public List<ReportInjectComment> updateReportInjectComment(@NotNull final Report report, @NotNull final Inject inject, @NotNull final ReportInjectCommentInput input){
public Report updateReportInjectComment(@NotNull final Report report, @NotNull final Inject inject, @NotNull final ReportInjectCommentInput input){
Optional<ReportInjectComment> reportInjectComment = this.reportRepository.findReportInjectComment(UUID.fromString(report.getId()), inject.getId());
ReportInjectComment injectComment;
if (reportInjectComment.isPresent()) {
Expand All @@ -64,8 +64,7 @@ public List<ReportInjectComment> updateReportInjectComment(@NotNull final Report
injectComment.setComment(input.getComment());
report.getReportInjectsComments().add(injectComment);
}
this.reportRepository.save(report);
return report.getReportInjectsComments();
return this.reportRepository.save(report);
}

public void deleteReport(@NotBlank final UUID reportId) {
Expand Down
2 changes: 0 additions & 2 deletions openbas-front/src/actions/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ export const updateUserPassword = (userId, data) => (dispatch) => putReferential

export const updateUser = (userId, data) => (dispatch) => putReferential(schema.user, `/api/users/${userId}`, data)(dispatch);

export const localUpdateUser = (data) => (dispatch) => dispatch({ type: Constants.DATA_UPDATE_SUCCESS, payload: data });

export const deleteUser = (userId) => (dispatch) => delReferential(`/api/users/${userId}`, 'users', userId)(dispatch);
// endregion

Expand Down
2 changes: 1 addition & 1 deletion openbas-front/src/actions/exercises/exercise-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const searchExerciseInjects = (exerciseId: Exercise['exercise_id'], searc
};

export const exerciseInjectsResultDTO = (exerciseId: Exercise['exercise_id']) => {
const uri = `${EXERCISE_URI}${exerciseId}/injects/resultdto`;
const uri = `${EXERCISE_URI}/${exerciseId}/injects/resultdto`;
return simpleCall(uri);
};

Expand Down
15 changes: 3 additions & 12 deletions openbas-front/src/actions/reports/report-actions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Dispatch } from 'redux';
import type { Exercise, Report, ReportInjectComment, ReportInput } from '../../utils/api-types';
import { delReferential, getReferential, postReferential, putReferential, simplePutCall } from '../../utils/Action';
import { delReferential, getReferential, postReferential, putReferential } from '../../utils/Action';
import * as schema from '../Schema';

export const fetchReportsForExercise = (exerciseId: Exercise['exercise_id']) => (dispatch: Dispatch) => {
Expand All @@ -27,22 +27,13 @@ export const updateReportForExercise = (
return putReferential(schema.report, uri, data)(dispatch);
};

export const updateReportGlobalObservation = (
exerciseId: Exercise['exercise_id'],
reportId: Report['report_id'],
data: ReportInput,
) => {
const uri = `/api/exercises/${exerciseId}/reports/${reportId}`;
return simplePutCall(uri, data);
};

export const updateReportInjectCommentForExercise = (
exerciseId: Exercise['exercise_id'],
reportId: Report['report_id'],
data: ReportInjectComment,
) => {
) => (dispatch: Dispatch) => {
const uri = `/api/exercises/${exerciseId}/reports/${reportId}/inject-comments`;
return simplePutCall(uri, data);
return putReferential(schema.report, uri, data)(dispatch);
};

export const deleteReportForExercise = (exerciseId: Exercise['exercise_id'], reportId: Report['report_id']) => (dispatch: Dispatch) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { SensorOccupiedOutlined, ShieldOutlined, TrackChangesOutlined } from '@mui/icons-material';
import { makeStyles } from '@mui/styles';
import type { ExpectationResultsByType } from '../../../../utils/api-types';
import type { ExpectationResultsByType, InjectResultDTO } from '../../../../utils/api-types';

const useStyles = makeStyles(() => ({
inline: {
Expand All @@ -13,9 +13,10 @@ const useStyles = makeStyles(() => ({

interface Props {
expectations: ExpectationResultsByType[] | undefined;
injectId?: InjectResultDTO['inject_id']
}

const AtomicTestingResult: React.FC<Props> = ({ expectations }) => {
const AtomicTestingResult: React.FC<Props> = ({ expectations, injectId }) => {
const classes = useStyles();
const getColor = (result: string | undefined): string => {
const colorMap: Record<string, string> = {
Expand All @@ -36,7 +37,7 @@ const AtomicTestingResult: React.FC<Props> = ({ expectations }) => {
);
}
return (
<div className={classes.inline}>
<div className={classes.inline} id={`inject_expectations_${injectId}`}>
{expectations.map((expectation, index) => {
const color = getColor(expectation.avgResult);
let IconComponent;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Chart from 'react-apexcharts';
import React, { FunctionComponent } from 'react';
import React, { memo } from 'react';
import { makeStyles, useTheme } from '@mui/styles';
import { Button, Grid } from '@mui/material';
import { InfoOutlined, SensorOccupiedOutlined, ShieldOutlined, TrackChangesOutlined } from '@mui/icons-material';
Expand Down Expand Up @@ -46,11 +46,7 @@ interface Props {
immutable?: boolean;
}

const ResponsePie: FunctionComponent<Props> = ({
expectationResultsByTypes,
humanValidationLink,
immutable,
}) => {
const ResponsePie = (({ expectationResultsByTypes, humanValidationLink, immutable }: Props) => {
// Standard hooks
const classes = useStyles();
const { t } = useFormatter();
Expand Down Expand Up @@ -147,6 +143,6 @@ const ResponsePie: FunctionComponent<Props> = ({
</Grid>
</Grid>
);
};
});

export default ResponsePie;
export default memo(ResponsePie);
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const LessonsCategories = ({
R.fromPairs,
)(lessonsAnswers);
return (
<div style={{ marginTop: '30px', ...style }}>
<div id='lessons_categories' style={{ marginTop: '30px', ...style }}>
{sortedCategories.map((category) => {
const questions = sortQuestions(
lessonsQuestions.filter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const ExerciseMainInformation: React.FC<Props> = ({ exercise }) => {
const sortByOrder = R.sortWith([R.ascend(R.prop('phase_order'))]);

return (
<Paper sx={{ padding: '15px' }} variant="outlined">
<Paper id='main_information' sx={{ padding: '15px' }} variant="outlined">
<Grid container spacing={3}>
<Grid item xs={12} style={{ paddingTop: 10 }}>
<Typography
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const ExerciseDistribution: FunctionComponent<Props> = ({
return <div />;
}
return (
<Grid container={true} spacing={3}>
<Grid id='exercise_distribution' container={true} spacing={3}>
<Grid item xs={6} style={{ marginTop: 25 }}>
<Typography variant="h4">
{t('Distribution of score by team (in % of expectations)')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const ExerciseDistributionByInjectorContract: FunctionComponent<Props> = ({
<>
{sortedInjectorContractsByTotalScore.length > 0 ? (
<Chart
id='exercise_distribution_total_score_by_inject_type'
// @ts-expect-error: Need to migrate Chart.js file
options={horizontalBarsChartOptions(
theme,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const ExerciseDistributionScoreByInject: FunctionComponent<Props> = ({
<>
{injectsTotalScores.length > 0 ? (
<Chart
id='exercise_distribution_total_score_by_inject'
// @ts-expect-error: Need to migrate Chart.js file
options={horizontalBarsChartOptions(
theme,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ const ExerciseDistributionScoreByOrganization: FunctionComponent<Props> = ({
<>
{organizationsTotalScores.length > 0 ? (
<Chart
id='exercise_distribution_total_score_by_organization'
// @ts-expect-error: Need to migrate Chart.js file
options={horizontalBarsChartOptions(theme)}
series={totalScoreByOrganizationData}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const ExerciseDistributionScoreByPlayer: FunctionComponent<Props> = ({
<>
{usersTotalScores.length > 0 ? (
<Chart
id='exercise_distribution_total_score_by_player'
// @ts-expect-error: Need to migrate Chart.js file
options={horizontalBarsChartOptions(theme)}
series={totalScoreByUserData}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const ExerciseDistributionScoreByTeam: FunctionComponent<Props> = ({
<>
{teamsTotalScores.length > 0 ? (
<Chart
id='exercise_distribution_total_score_by_team'
// @ts-expect-error: Need to migrate Chart.js file
options={horizontalBarsChartOptions(theme)}
series={totalScoreByTeamData}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ const ExerciseDistributionScoreByTeamInPercentage: FunctionComponent<Props> = ({
<>
{teamsTotalScores.length > 0 ? (
<Chart
id='exercise_distribution_score_by_team'
// @ts-expect-error: Need to migrate Chart.js file
options={horizontalBarsChartOptions(theme)}
series={percentScoreByTeamData}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const ExerciseDistributionScoreOverTimeByInjectorContract: FunctionComponent<Pro
<>
{injectsTypesScores.length > 0 ? (
<Chart
id='exercise_distribution_score_over_time_by_inject'
// @ts-expect-error: Need to migrate Chart.js file
options={lineChartOptions(
theme,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const ExerciseDistributionScoreOverTimeByTeam: FunctionComponent<Props> = ({
<>
{teamsScores.length > 0 ? (
<Chart
id='exercise_distribution_score_over_time_by_team'
// @ts-expect-error: Need to migrate Chart.js file
options={lineChartOptions(
theme,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ const ExerciseDistributionScoreOverTimeByTeamInPercentage: FunctionComponent<Pro
<>
{teamsTotalScores.length > 0 ? (
<Chart
id='exercise_distribution_score_over_time'
// @ts-expect-error: Need to migrate Chart.js file
options={lineChartOptions(
theme,
Expand Down
Loading

0 comments on commit d492950

Please sign in to comment.