Skip to content

Commit

Permalink
fix user_feedbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
valentin-vrps committed May 28, 2024
1 parent 115a13b commit e3f8e99
Show file tree
Hide file tree
Showing 22 changed files with 384 additions and 140 deletions.
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
DKC = docker compose
DK = docker
.DEFAULT_GOAL = help

help:
@grep -E '(^[a-zA-Z0-9_-]+:.*?##.*$$)|(^##)' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}{printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}' | sed -e 's/\[32m##/[33m/'

## —— Docker ———————————————————————————————————————————————————————————————————
up: ## start containers in the background
@$(DKC) up -d
run: ## start containers in attached mode
@$(DKC) up
down: ## stop containers
@$(DKC) down
Binary file removed public/black.jpg
Binary file not shown.
2 changes: 2 additions & 0 deletions server/authentication/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ export async function login(req: Request, res: Response): Promise<void> {
.execute();

const { accessToken, refreshToken } = await getAccessToken(user.id, !!data.getRefreshToken);
user.loginCount += 1;
await getRepository(User).save(user);
res.cookie('access-token', accessToken, {
maxAge: 4 * 60 * 60000,
expires: new Date(Date.now() + 4 * 60 * 60000),
Expand Down
4 changes: 4 additions & 0 deletions server/authentication/plmSSO.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { JSONSchemaType } from 'ajv';
import type { NextFunction, Request, Response } from 'express';
import { getRepository } from 'typeorm';

import { User } from '../entities/user';
import { getUserFromPLM } from '../legacy-plm/api';
import { ajv, sendInvalidDataError } from '../lib/json-schema-validator';
import { AppError } from '../middlewares/handle-errors';
Expand Down Expand Up @@ -40,6 +42,8 @@ export async function loginWithPlmSSO(req: Request, res: Response, next: NextFun
throw new AppError('forbidden', ['Please use normal login'], 6);
}
const { accessToken, refreshToken } = await getAccessToken(user.id, true);
user.loginCount += 1;
await getRepository(User).save(user);
res.cookie('access-token', accessToken, {
maxAge: 4 * 60 * 60000,
expires: new Date(Date.now() + 4 * 60 * 60000),
Expand Down
39 changes: 38 additions & 1 deletion server/controllers/plans.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { JSONSchemaType } from 'ajv';
import { getRepository } from 'typeorm';
import { getManager, getRepository } from 'typeorm';

import { Plan } from '../entities/plan';
import { UserType } from '../entities/user';
Expand Down Expand Up @@ -79,6 +79,43 @@ planController.post({ path: '/', userType: UserType.CLASS }, async (req, res, ne
res.sendJSON(newPlan);
});

type PutPlanOrderData = {
order: number[];
};
const PUT_PLAN_ORDER_SCHEMA: JSONSchemaType<PutPlanOrderData> = {
type: 'object',
properties: {
order: {
type: 'array',
items: {
type: 'number',
},
},
},
required: ['order'],
additionalProperties: false,
};
const putPlanOrderValidator = ajv.compile(PUT_PLAN_ORDER_SCHEMA);
planController.put({ path: '/order', userType: UserType.CLASS }, async (req, res) => {
const data = req.body;
if (!putPlanOrderValidator(data)) {
sendInvalidDataError(putPlanOrderValidator);
return;
}

const plans: Plan[] = [];
for (let i = 0; i < data.order.length; i++) {
const plan = new Plan();
plan.id = data.order[i];
plan.index = i;
plans.push(plan);
}
await getManager().transaction(async (transactionalEntityManager) => {
await transactionalEntityManager.save(plans);
});
res.status(204).send();
});

type PutPlanData = {
description?: string;
index?: number;
Expand Down
10 changes: 8 additions & 2 deletions server/controllers/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,14 @@ userController.get({ path: '' }, async (req, res) => {
}
if (req.query.order !== undefined || req.query.orderBy !== undefined) {
const orderBy = (req.query.order as string) || (req.query.orderBy as string);
if (orderBy === 'id' || orderBy === 'pseudo' || orderBy === 'email' || orderBy === 'level' || orderBy === 'school') {
if (
orderBy === 'id' ||
orderBy === 'pseudo' ||
orderBy === 'email' ||
orderBy === 'level' ||
orderBy === 'school' ||
orderBy === 'createDate'
) {
queryParams.order = {
[orderBy]: direction,
};
Expand All @@ -58,7 +65,6 @@ userController.get({ path: '' }, async (req, res) => {
{ pseudo: Like(`%${req.query.search}%`) },
{ email: Like(`%${req.query.search}%`) },
{ school: Like(`%${req.query.search}%`) },
{ level: Like(`%${req.query.search}%`) },
];
}
const users: User[] = await getRepository(User).find(queryParams);
Expand Down
8 changes: 7 additions & 1 deletion server/entities/user.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
import { Column, Entity, PrimaryGeneratedColumn, CreateDateColumn } from 'typeorm';

import type { User as UserInterface } from '../../types/models/user.type';
import { UserType } from '../../types/models/user.type';
Expand All @@ -25,6 +25,9 @@ export class User implements UserInterface {
@Column({ default: 0 })
public accountRegistration: number; // 0 to 3 -> Ok, 4 -> Account blocked, 10 -> Account use PLM SSO

@Column({ default: 0 })
public loginCount: number;

@Column({ type: 'varchar', length: 180, select: false })
public passwordHash?: string;

Expand All @@ -39,4 +42,7 @@ export class User implements UserInterface {
type: UserType;

teacherId?: number | undefined;

@CreateDateColumn()
public createDate: string;
}
5 changes: 4 additions & 1 deletion server/translations/defaultLocales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ export const locales = {
small: "petit",
medium: "moyen",
big: "grand",
left: "gauche",
center: "centre",
right: "droite",
//--- part4 ---
part4_title: 'Prémontez votre <1>film</1>',
part4_subtitle1: 'Pour chaque séquence vous pouvez écrire et enregistrer une voix-off.',
Expand Down Expand Up @@ -114,7 +117,7 @@ export const locales = {
part6_mp4_user_disabled: 'Connectez-vous et créez un projet pour générer une vidéo.',
part6_mp4_project_disabled: 'Créez un projet pour générer une vidéo.',
part6_subtitle2:
'Vous pouvez également télécharger ce diaporama sonore comme film, télécharger le storyboard ainsi qu’un fichier de montage pour y intégrer vos plans vidéos.',
'Vous pouvez maintenant télécharger ce diaporama ou son fichier de montage pour y intégrer vos plans vidéos.',
//--- project ---
project: 'Projet :',
project_name: 'Nom du projet',
Expand Down
6 changes: 3 additions & 3 deletions server/xml/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ export function projectToMlt(allQuestions: Question[], project: Project, urlTran
size: fontSize,
weight: '500',
style: 'normal',
fgcolour: '#ffffffff',
bgcolour: '#00000000',
olcolour: '#aa000000',
fgcolour: '#000000',
bgcolour: '#ffffffff',
olcolour: '#ffffffff',
halign: 'center',
valign: 'middle',
mlt_service: 'dynamictext',
Expand Down
36 changes: 36 additions & 0 deletions src/api/plans/plans.order.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import type { UseMutationOptions } from 'react-query';
import { useMutation, useQueryClient } from 'react-query';

import type { HttpRequestError } from 'src/utils/http-request';
import { httpRequest } from 'src/utils/http-request';

type PUTParams = {
order: number[];
};

export const reorderPlans = async (data: PUTParams): Promise<void> => {
const response = await httpRequest<void>({
method: 'PUT',
url: `/plans/order`,
data,
});
if (response.success) {
return;
} else {
throw response;
}
};

export const useReorderPlansMutation = (mutationOpts: Omit<UseMutationOptions<void, HttpRequestError, PUTParams>, 'mutationFn'> = {}) => {
const queryClient = useQueryClient();
return useMutation(reorderPlans, {
...mutationOpts,
onSuccess: (data, variables, context) => {
queryClient.invalidateQueries('plans');
queryClient.invalidateQueries('plan');
if (mutationOpts.onSuccess !== undefined) {
mutationOpts.onSuccess(data, variables, context);
}
},
});
};
9 changes: 4 additions & 5 deletions src/api/questions/questions.order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { useMutation, useQueryClient } from 'react-query';
import type { HttpRequestError } from 'src/utils/http-request';
import { httpRequest } from 'src/utils/http-request';

type POSTParams = {
type PUTParams = {
order: number[];
};

export const reorderQuestions = async (data: POSTParams): Promise<void> => {
export const reorderQuestions = async (data: PUTParams): Promise<void> => {
const response = await httpRequest<void>({
method: 'POST',
method: 'PUT',
url: `/questions/order`,
data,
});
Expand All @@ -21,9 +21,8 @@ export const reorderQuestions = async (data: POSTParams): Promise<void> => {
}
};

export const useReorderQuestionsMutation = (mutationOpts: Omit<UseMutationOptions<void, HttpRequestError, POSTParams>, 'mutationFn'> = {}) => {
export const useReorderQuestionsMutation = (mutationOpts: Omit<UseMutationOptions<void, HttpRequestError, PUTParams>, 'mutationFn'> = {}) => {
const queryClient = useQueryClient();

return useMutation(reorderQuestions, {
...mutationOpts,
onSuccess: (data, variables, context) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
height: 100%;
background-color: black;
position: relative;
overflow: hidden;

&__container {
width: 100%;
Expand Down
30 changes: 27 additions & 3 deletions src/components/create/TitleCanvas/TitleCanvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const getStyle = (style: string) => {
}
};

type TextAlign = 'left' | 'center' | 'right';

type TitleCanvasProps = {
title: Title;
onChange: React.Dispatch<React.SetStateAction<Title>>;
Expand All @@ -29,6 +31,7 @@ export function TitleCanvas({ title, onChange }: TitleCanvasProps) {
const [titleText, setTitleText] = React.useState(title.text || '');
const [fontFamily, setFontFamily] = React.useState<string>(style.fontFamily || 'serif');
const [fontSize, setFontSize] = React.useState<number>(style.fontSize || 8); // %
const [textAlign, setTextAlign] = React.useState<TextAlign>(style.textAlign || 'center');
// relative pos
const [textXPer, setTextXPer] = React.useState<number>(style.x ?? 15); // %
const [textYPer, setTextYPer] = React.useState<number>(style.y ?? 30); // %
Expand All @@ -42,6 +45,7 @@ export function TitleCanvas({ title, onChange }: TitleCanvasProps) {
setTextXPer(style.x ?? 25);
setTextYPer(style.y ?? 35);
setTextWidthPer(style.width || 50);
setTextAlign(style.textAlign || 'center');
}, [title, style]);

const onChangeStyle = (newPartialSyle: Record<string, string | number>) => {
Expand All @@ -65,7 +69,7 @@ export function TitleCanvas({ title, onChange }: TitleCanvasProps) {
if (textAreaRef.current) {
setTextAreaRefHeight(textAreaRef.current.scrollHeight);
}
}, [titleText, textWidthPer, canvasWidth, fontSize, fontFamily]); // update textAreaRefHeight on title change.
}, [titleText, textWidthPer, canvasWidth, fontSize, fontFamily, textAlign]); // update textAreaRefHeight on title change.

// Absolute pos
const { textX, textY, textWidth } = React.useMemo(
Expand Down Expand Up @@ -205,6 +209,26 @@ export function TitleCanvas({ title, onChange }: TitleCanvasProps) {
<option value={8}>{t('medium')}</option>
<option value={10}>{t('big')}</option>
</select>
<select
value={textAlign}
onChange={(event) => {
const newTextAlign = event.target.value as TextAlign;
setTextAlign(newTextAlign);
onChangeStyle({ textAlign: newTextAlign });
}}
style={{
margin: '0 0.5rem',
backgroundColor: PrimaryColor,
color: '#fff',
border: 'none',
outline: 'none',
cursor: 'pointer',
}}
>
<option value={'left'}>{t('left')}</option>
<option value={'center'}>{t('center')}</option>
<option value={'right'}>{t('right')}</option>
</select>
</div>
<textarea
value={titleText}
Expand All @@ -229,7 +253,7 @@ export function TitleCanvas({ title, onChange }: TitleCanvasProps) {
fontSize: `${(fontSize * canvasHeight) / 100}px`,
lineHeight: `${(fontSize * canvasHeight) / 100}px`,
fontFamily: fontFamily,
textAlign: 'center',
textAlign: textAlign,
resize: 'none',
}}
/>
Expand All @@ -251,7 +275,7 @@ export function TitleCanvas({ title, onChange }: TitleCanvasProps) {
fontSize: `${(fontSize * canvasHeight) / 100}px`,
lineHeight: `${(fontSize * canvasHeight) / 100}px`,
fontFamily: fontFamily,
textAlign: 'center',
textAlign: textAlign,
resize: 'none',
whiteSpace: 'pre-wrap',
wordBreak: 'break-word',
Expand Down
1 change: 1 addition & 0 deletions src/components/navigation/Steps/steps.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
flex-direction: row;
align-self: stretch;
padding: 24px 0;
cursor: pointer;
}
@include mixins.for-tablet-up {
.steps {
Expand Down
Loading

0 comments on commit e3f8e99

Please sign in to comment.