Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/parlemonde/1village into …
Browse files Browse the repository at this point in the history
…ft/VIL-632
  • Loading branch information
SimNed committed Nov 20, 2024
2 parents f91b846 + a81edc7 commit 4fb0fa0
Show file tree
Hide file tree
Showing 17 changed files with 272 additions and 144 deletions.
21 changes: 12 additions & 9 deletions server/controllers/archive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@ import { Controller } from './controller';
const archiveController = new Controller('/archives');

// get file
archiveController.get({ path: '/*', userType: UserType.ADMIN }, async (req: Request, res: Response, next: NextFunction) => {
const url = decodeURI(req.url);
const key = `archives${url}${url.split('/').length === 2 ? '/index.html' : url.indexOf('.') === -1 ? '.html' : ''}`;
try {
streamFile(key, req, res, next);
} catch {
next();
}
});
archiveController.get(
{ path: '/*', userType: [UserType.SUPER_ADMIN, UserType.ADMIN, UserType.MEDIATOR] },
async (req: Request, res: Response, next: NextFunction) => {
const url = decodeURI(req.url);
const key = `archives${url}${url.split('/').length === 2 ? '/index.html' : url.indexOf('.') === -1 ? '.html' : ''}`;
try {
streamFile(key, req, res, next);
} catch {
next();
}
},
);

/**
* Liste les dossiers dans un préfixe S3 spécifié.
Expand Down
2 changes: 1 addition & 1 deletion server/controllers/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { diskStorage } from '../middlewares/multer';

type RouteOptions = {
path: string;
userType?: UserType;
userType?: UserType | UserType[];
};

fs.ensureDir(path.join(__dirname, '../fileUpload/videos')).catch();
Expand Down
2 changes: 2 additions & 0 deletions server/controllers/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ type EditUserData = {
firstname?: string;
lastname?: string;
countryCode?: string;
createdAt?: string;
level?: string;
school?: string;
city?: string;
Expand All @@ -324,6 +325,7 @@ const EDIT_SCHEMA: JSONSchemaType<EditUserData> = {
firstname: { type: 'string', nullable: true },
lastname: { type: 'string', nullable: true },
countryCode: { type: 'string', nullable: true },
createdAt: { type: 'string', nullable: true },
level: { type: 'string', nullable: true },
school: { type: 'string', nullable: true },
city: { type: 'string', nullable: true },
Expand Down
22 changes: 18 additions & 4 deletions src/api/archive/archive.get.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
import axios from 'axios';
import React from 'react';
import { useQuery } from 'react-query';

import { UserType } from '../../../types/user.type';
import { UserContext } from '../../contexts/userContext';

const BASE_URL = '/api/archives';

// Récupérer la liste des années déjà archivées
export const useListArchives = () => {
return useQuery(['archives'], async () => {
const { data } = await axios.get(`${BASE_URL}`);
return data;
});
const { user } = React.useContext(UserContext);

const hasAccess = user !== null && user.type in [UserType.ADMIN, UserType.SUPER_ADMIN, UserType.MEDIATOR];

return useQuery(
['archives'],
async () => {
const { data } = await axios.get(`${BASE_URL}`);
return data;
},
{
enabled: hasAccess,
},
);
};
1 change: 0 additions & 1 deletion src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ export const Header = () => {
{hasAccessToNewAdmin && <MenuItem onClick={() => goToPage('/admin/newportal/create')}>Portail admin</MenuItem>}
{hasAccessToOldAdmin && <MenuItem onClick={() => goToPage('/admin/villages')}>Admin (old)</MenuItem>}
<MenuItem onClick={() => goToPage('/mon-compte')}>Mon compte</MenuItem>
{user.type !== UserType.FAMILY && <MenuItem onClick={() => goToPage('/mes-videos')}>Mes vidéos</MenuItem>}
<AccessControl featureName="id-family" key={user?.id || 'default'}>
{user.type === UserType.TEACHER ? <MenuItem onClick={() => goToPage('/familles/1')}>Mes familles</MenuItem> : null}{' '}
</AccessControl>
Expand Down
83 changes: 83 additions & 0 deletions src/components/VideoTable.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import React from 'react';

import VisibilityIcon from '@mui/icons-material/Visibility';
import { Table, TableBody, TableCell, TableHead, TableRow, Tooltip, IconButton } from '@mui/material';

import { DeleteButton } from './buttons/DeleteButton';
import { bgPage } from 'src/styles/variables.const';
import type { Video } from 'types/video.type';

interface VideoTableProps {
videos: Video[];
onView: (video: Video) => void;
onDelete: (id: number) => void;
}

export const VideoTable: React.FC<VideoTableProps> = ({ videos, onView, onDelete }) => {
const cellStyles = {
padding: '5px',
margin: 0,
};

return (
<Table size="medium" style={{ marginTop: '1rem' }}>
<TableHead style={{ borderBottom: '1px solid white' }}>
<TableRow>
<TableCell sx={(theme) => ({ [theme.breakpoints.only('xs')]: cellStyles })} style={{ fontWeight: 'bold' }}>
#
</TableCell>
<TableCell sx={(theme) => ({ [theme.breakpoints.only('xs')]: cellStyles })} style={{ fontWeight: 'bold' }}>
Nom de la vidéo
</TableCell>
<TableCell sx={(theme) => ({ [theme.breakpoints.only('xs')]: cellStyles })} style={{ fontWeight: 'bold' }}>
Lien de la vidéo (URL)
</TableCell>
<TableCell sx={(theme) => ({ [theme.breakpoints.only('xs')]: cellStyles })} style={{ fontWeight: 'bold' }} align="right">
Actions
</TableCell>
</TableRow>
</TableHead>
<TableBody>
{videos.map((video, index) => (
<TableRow
key={video.id}
sx={{
backgroundColor: 'white',
'&:nth-of-type(even)': {
backgroundColor: bgPage,
},
'&.sortable-ghost': {
opacity: 0,
},
}}
>
<TableCell sx={(theme) => ({ [theme.breakpoints.only('xs')]: cellStyles })}>{index + 1}</TableCell>
<TableCell sx={(theme) => ({ [theme.breakpoints.only('xs')]: cellStyles })}>{video.name}</TableCell>
<TableCell sx={(theme) => ({ [theme.breakpoints.only('xs')]: cellStyles })}>https://player.vimeo.com/video/{video.id}</TableCell>
<TableCell sx={(theme) => ({ [theme.breakpoints.only('xs')]: cellStyles })} align="right" padding="none" style={{ minWidth: '96px' }}>
<Tooltip title="Regarder">
<IconButton
aria-label="Voir"
onClick={() => {
onView(video);
}}
size="small"
style={{ border: '1px solid', marginRight: '0.25rem' }}
>
<VisibilityIcon />
</IconButton>
</Tooltip>
<Tooltip title="Supprimer">
<DeleteButton
color="red"
onDelete={() => onDelete(video.id)}
confirmLabel="Voulez vous vraiment supprimer cette vidéo ? Attention, elle ne sera plus accessible par les activités qui l'utilisent."
/>
</Tooltip>
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
);
};
17 changes: 8 additions & 9 deletions src/components/WelcomeModal/SecondPhase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,15 @@ export const SecondPhase = () => {
<>
<div
id="new-user-desc"
style={{ minHeight: '15rem', display: 'flex', flexDirection: 'column', alignItems: 'center', textAlign: 'center', marginTop: '2rem' }}
style={{ minHeight: '15rem', display: 'flex', flexDirection: 'column', alignItems: 'center', textAlign: 'center' }}
>
<div style={{ display: 'flex', justifyContent: 'center', gap: '2rem' }}>
<div>
<p>Avant de passer à la phase suivante, prenez 5 minutes pour nous faire vos retours sur la phase 1 :</p>
<a href={urlForm} target="_blank" rel="noopener noreferrer" style={{ textDecoration: 'underline', color: '#4c3ed9' }}>
Vos retours sur la phase 1 d&apos;1Village 2024/25
</a>
</div>
<div style={{ display: 'flex', justifyContent: 'center', gap: '2rem', marginTop: '2rem' }}>
<div>
<p>Si vous n&apos;avez pas encore résolu l&apos;énigme avec votre classe, retournez sur la phase 1.</p>
<Button
Expand Down Expand Up @@ -96,13 +102,6 @@ export const SecondPhase = () => {
</Button>
</div>
</div>

<div style={{ marginTop: '2rem' }}>
Avant de passer à la phase suivante, prenez 5 minutes pour nous faire vos retours sur la phase 1 :{' '}
<a href={urlForm} target="_blank" rel="noopener noreferrer" style={{ textDecoration: 'underline', color: '#4c3ed9' }}>
Vos retours sur la phase 1 d&apos;1Village 2024/25
</a>
</div>
</div>
</>
}
Expand Down
19 changes: 9 additions & 10 deletions src/components/WelcomeModal/ThirdPhase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const ThirdPhase = () => {
const { enqueueSnackbar } = useSnackbar();
const [isModalOpen, setIsModalOpen] = React.useState(true);
const urlForm = 'https://docs.google.com/forms/d/e/1FAIpQLSfncEkPDYsPjK3RCjX_YBUC2uNxD-RAd2Bn_KGlimv765M-Vw/viewform';
const textToDisplay = 'Avant de passer à la phase suivante, prenez 5 minutes pour nous faire vos retours sur la phase 1 : ';
const textToDisplay = 'Avant de passer à la phase suivante, prenez 5 minutes pour nous faire vos retours sur la phase 2 : ';
const textForUrl = "Vos retours sur la phase 2 d'1Village 2024/25";

if (!user) {
Expand Down Expand Up @@ -51,9 +51,15 @@ export const ThirdPhase = () => {
<>
<div
id="new-user-desc"
style={{ minHeight: '15rem', display: 'flex', flexDirection: 'column', alignItems: 'center', textAlign: 'center', marginTop: '2rem' }}
style={{ minHeight: '15rem', display: 'flex', flexDirection: 'column', alignItems: 'center', textAlign: 'center' }}
>
<div style={{ display: 'flex', justifyContent: 'center', gap: '2rem' }}>
<div>
<p>{textToDisplay}</p>
<a href={urlForm} target="_blank" rel="noopener noreferrer" style={{ textDecoration: 'underline', color: '#4c3ed9' }}>
{textForUrl}
</a>
</div>
<div style={{ display: 'flex', justifyContent: 'center', gap: '2rem', marginTop: '2rem' }}>
<div>
<p>{'Si vous voulez poursuivre les échanges avec vos pélicopains, retournez sur la phase 2'}</p>
<Button
Expand Down Expand Up @@ -98,13 +104,6 @@ export const ThirdPhase = () => {
</Button>
</div>
</div>

<div style={{ marginTop: '2rem' }}>
{textToDisplay}
<a href={urlForm} target="_blank" rel="noopener noreferrer" style={{ textDecoration: 'underline', color: '#4c3ed9' }}>
{textForUrl}
</a>
</div>
</div>
</>
}
Expand Down
10 changes: 9 additions & 1 deletion src/components/accueil/Accueil.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useRouter } from 'next/router';
import React from 'react';

import { Button } from '@mui/material';
Expand All @@ -23,6 +24,13 @@ export const Accueil = () => {
const { village, selectedPhase, setSelectedPhase } = React.useContext(VillageContext);
const { user } = React.useContext(UserContext);
const isMediator = user && user.type <= UserType.MEDIATOR;
const router = useRouter();
const [withPagination, setWithPagination] = React.useState(true);

React.useEffect(() => {
if (!router.isReady) return;
setWithPagination(!('nopagination' in router.query));
}, [router.isReady, router.query]);

//TODO: redo conditions and switchs
const filterCountries = React.useMemo(() => {
Expand Down Expand Up @@ -106,7 +114,7 @@ export const Accueil = () => {
</KeepRatio>
<h1 style={{ marginTop: '1rem' }}>Dernières activités</h1>
<Filters countries={filterCountries} filters={filters} onChange={setFilters} phase={selectedPhase} />
<Activities activities={activitiesFiltered} withLinks withPagination />
<Activities activities={activitiesFiltered} withLinks withPagination={withPagination} />
</>
) : (
<div style={{ display: 'flex', flexDirection: 'column', padding: '0 1rem', alignItems: 'center' }}>
Expand Down
20 changes: 16 additions & 4 deletions src/components/activities/List.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useState } from 'react';
import { useRouter } from 'next/router';
import React from 'react';

import type { SelectChangeEvent } from '@mui/material';
import { Button } from '@mui/material';
Expand Down Expand Up @@ -59,6 +60,7 @@ export const Activities = ({ activities, noButtons = false, withLinks = false, w
responseActivityId: null,
});
const { activity: responseActivity } = useActivity(responseActivityId ?? -1);
const router = useRouter();
const { user } = React.useContext(UserContext);
const { users } = useVillageUsers();
const userMap = React.useMemo(
Expand All @@ -69,8 +71,16 @@ export const Activities = ({ activities, noButtons = false, withLinks = false, w
}, {}),
[users],
);
const [page, setPage] = useState<number>(1);
const [page, setPage] = React.useState<number>(1);
const [activitiesPerPage, setActivitiesPerPage] = React.useState(25);
const [usePagination, setUsePagination] = React.useState(withPagination);

React.useEffect(() => {
if (!router.isReady) {
return;
}
setUsePagination(!('nopagination' in router.query));
}, [router.isReady, router.query, withPagination]);

React.useEffect(() => {
window.scrollTo({ top: 0, behavior: 'smooth' });
Expand All @@ -96,7 +106,9 @@ export const Activities = ({ activities, noButtons = false, withLinks = false, w
onSelect,
};

const currentPageActivities = activities.filter((activity) => !isAnthem(activity)).slice(startIdx, endIdx);
const currentPageActivities = usePagination
? activities.filter((activity) => !isAnthem(activity)).slice(startIdx, endIdx)
: activities.filter((activity) => !isAnthem(activity));

return (
<div>
Expand Down Expand Up @@ -180,7 +192,7 @@ export const Activities = ({ activities, noButtons = false, withLinks = false, w
<Card key={index} activity={activity} index={index} {...cardProps} />
),
)}
{withPagination && (
{usePagination && (
<PaginationNav
page={page}
itemsPerPage={activitiesPerPage}
Expand Down
2 changes: 1 addition & 1 deletion src/components/admin/NewAdminNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const NewAdminNavigation = () => {
const tabs: Tab[] = [
{ path: '/admin/newportal/create', label: 'Créer', Icon: CreerIcon, rights: [UserType.ADMIN, UserType.SUPER_ADMIN, UserType.MEDIATOR] },
{ path: '/admin/newportal/publier', label: 'Publier', Icon: PublierIcon, rights: [UserType.ADMIN, UserType.SUPER_ADMIN] },
{ path: '/admin/newportal/manage', label: 'Gérer', Icon: GererIcon, rights: [UserType.ADMIN, UserType.SUPER_ADMIN] },
{ path: '/admin/newportal/manage', label: 'Gérer', Icon: GererIcon, rights: [UserType.ADMIN, UserType.SUPER_ADMIN, UserType.MEDIATOR] },
{
path: '/admin/newportal/analyze',
label: 'Analyser',
Expand Down
Loading

0 comments on commit 4fb0fa0

Please sign in to comment.