From d15b09f1506fa65ef9e673f1b94ad0578c957e87 Mon Sep 17 00:00:00 2001 From: sebferrer Date: Wed, 19 May 2021 17:19:52 +0200 Subject: [PATCH 1/9] switch server .github.io --> .fr --- back/src/environments/environment.prod.ts | 2 +- front/src/index.html | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/back/src/environments/environment.prod.ts b/back/src/environments/environment.prod.ts index 8271ecc..49117a8 100644 --- a/back/src/environments/environment.prod.ts +++ b/back/src/environments/environment.prod.ts @@ -2,5 +2,5 @@ import { IEnvironment } from "../models/environment"; export const PROD_ENV: IEnvironment = { isProduction: true, - frontendUrl: 'https://curry-chronicles.github.io' + frontendUrl: 'https://curry-chronicles.fr' }; diff --git a/front/src/index.html b/front/src/index.html index c9e7ff5..6601067 100644 --- a/front/src/index.html +++ b/front/src/index.html @@ -23,8 +23,8 @@ - - + + From 2c198e13cbcb5daf6c74d987e5a7287174f247bb Mon Sep 17 00:00:00 2001 From: sebferrer Date: Thu, 20 May 2021 16:16:01 +0200 Subject: [PATCH 2/9] sort recipes by publication date --- back/src/controllers/abstract.controller.ts | 6 +++--- back/src/controllers/recipes.controller.ts | 2 +- back/src/models/request.model.ts | 13 ++++++++++--- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/back/src/controllers/abstract.controller.ts b/back/src/controllers/abstract.controller.ts index a6e63c3..66af09d 100644 --- a/back/src/controllers/abstract.controller.ts +++ b/back/src/controllers/abstract.controller.ts @@ -1,4 +1,4 @@ -import { IRequest, Paging } from '../models'; +import { IRequest, Paging, ISortParams } from '../models'; const IGNORED_FILTERS = new Set(['fields', 'paging']); @@ -29,7 +29,7 @@ export abstract class AController { return (request?.query?.fields || '').split(','); } - protected getPaging(request: IRequest): Paging { - return Paging.parse(request?.query?.paging); + protected getPaging(request: IRequest, sortParams?: ISortParams): Paging { + return Paging.parse(request?.query?.paging, sortParams); } } diff --git a/back/src/controllers/recipes.controller.ts b/back/src/controllers/recipes.controller.ts index 8fdb650..bee605f 100644 --- a/back/src/controllers/recipes.controller.ts +++ b/back/src/controllers/recipes.controller.ts @@ -11,7 +11,7 @@ export class RecipesController extends AController { RecipeSchema.find( this.getFilters(request), this.getFields(request), - this.getPaging(request), + this.getPaging(request, { key: "publicationDate", direction: -1 }), (error: Error, recipes: Document[]) => { if (error != null) { response.send(error); diff --git a/back/src/models/request.model.ts b/back/src/models/request.model.ts index 739cb2d..28529e4 100644 --- a/back/src/models/request.model.ts +++ b/back/src/models/request.model.ts @@ -5,18 +5,25 @@ export interface IQuery { paging?: string; } +export interface ISortParams { + key: string, + direction: number +} + export class Paging { constructor( public skip: number, - public limit: number + public limit: number, + public sort?: any ) { } - public static parse(rawPaging: string): Paging { + public static parse(rawPaging: string, sortParams?: ISortParams): Paging { const splitted = (rawPaging || '').split(',').map(value => parseInt(value)); if (splitted == null || splitted.length == null) { return null; } - return new Paging(splitted[0], splitted[1]); + const sort = sortParams == null ? {} : {[sortParams.key]: sortParams.direction}; + return new Paging(splitted[0], splitted[1], sort); } } From 2490ed13b9a01bc65e0de642c523560ac8d3571a Mon Sep 17 00:00:00 2001 From: sebferrer Date: Thu, 20 May 2021 17:51:16 +0200 Subject: [PATCH 3/9] home grid tiles equal size --- .../recipe-thumbnail.component.scss | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/front/src/app/pages/home/components/recipe-thumbnail/recipe-thumbnail.component.scss b/front/src/app/pages/home/components/recipe-thumbnail/recipe-thumbnail.component.scss index a84da0f..9709143 100644 --- a/front/src/app/pages/home/components/recipe-thumbnail/recipe-thumbnail.component.scss +++ b/front/src/app/pages/home/components/recipe-thumbnail/recipe-thumbnail.component.scss @@ -19,12 +19,19 @@ content { display: block; overflow: hidden; + @media screen and (min-width: $mobile-width-breakpoint) { + height: 13.5rem; + } img { display: block; border: 0; - width: 100%; - height: auto; + @media screen and (min-width: $tablet-width-breakpoint) { + height: 100%; + } + @media screen and (max-width: $tablet-width-breakpoint) { + width: 100%; + } transition: transform 0.25s ease, filter 0.25s ease; } } @@ -35,6 +42,13 @@ color: $grey; font-size: 1rem; text-align: center; + @media screen and (min-width: $mobile-width-breakpoint) { + height: 2.2rem; + display: flex; + justify-content: center; + align-content: center; + flex-direction: column; + } } &:hover { From 892580f74279bc4e5931aac0af780ca8f14ee4c9 Mon Sep 17 00:00:00 2001 From: sebferrer Date: Fri, 21 May 2021 11:41:00 +0200 Subject: [PATCH 4/9] search filter update regex --- back/src/controllers/abstract.controller.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/back/src/controllers/abstract.controller.ts b/back/src/controllers/abstract.controller.ts index 66af09d..8a7c6ec 100644 --- a/back/src/controllers/abstract.controller.ts +++ b/back/src/controllers/abstract.controller.ts @@ -11,7 +11,7 @@ export abstract class AController { keys.filter(key => !IGNORED_FILTERS.has(key)) .forEach(key => { // Like operator? - const likeRegex = /like,([a-zA-Z0-9]+)/mg.exec(query[key]); + const likeRegex = /like,([A-Za-zÀ-ÖØ-öø-ÿœ]+)/mg.exec(query[key]); if (likeRegex != null) { result[key] = { $regex: likeRegex[1], From 91d1541189f7a776688753c75da67cf8270c7606 Mon Sep 17 00:00:00 2001 From: sebferrer Date: Fri, 21 May 2021 12:06:55 +0200 Subject: [PATCH 5/9] home Observable recipes to BehaviourSubjet --> smooth loading on search --- front/src/app/pages/home/home.component.ts | 23 +++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/front/src/app/pages/home/home.component.ts b/front/src/app/pages/home/home.component.ts index 8691cd0..7e1d960 100644 --- a/front/src/app/pages/home/home.component.ts +++ b/front/src/app/pages/home/home.component.ts @@ -1,7 +1,7 @@ import { Component, ElementRef, OnInit, ViewChild } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; import { IRecipeOverview, Page, RecipesService } from '@curry-chronicles/shared'; -import { fromEvent, Observable, of } from 'rxjs'; +import { fromEvent, BehaviorSubject } from 'rxjs'; import { debounceTime, map } from 'rxjs/operators'; const SEARCH_DEBOUNCE_TIME_IN_MS = 300; @@ -13,7 +13,8 @@ const SEARCH_DEBOUNCE_TIME_IN_MS = 300; }) export class HomeComponent implements OnInit { - public recipesPage$: Observable>; + private recipesPage: Page; + public recipesPage$: BehaviorSubject>; @ViewChild('searchInputElement', { static: true }) public searchInputElement: ElementRef; @@ -29,7 +30,9 @@ export class HomeComponent implements OnInit { private readonly recipesService: RecipesService, private readonly activatedRoute: ActivatedRoute ) { - this.recipesPage$ = of(this.activatedRoute.snapshot.data.recipesPage as Page); + this.recipesPage = this.activatedRoute.snapshot.data.recipesPage as Page; + this.recipesPage$ = new BehaviorSubject>(null); + this.recipesPage$.next(this.recipesPage); } public ngOnInit(): void { @@ -57,11 +60,21 @@ export class HomeComponent implements OnInit { private onSearchChanged(): void { if (this.isSearchInputEmpty) { - this.recipesPage$ = this.recipesService.getPagedRecipes(); + this.recipesService.getPagedRecipes().subscribe( + recipes => { + this.recipesPage = recipes; + this.recipesPage$.next(this.recipesPage); + } + ); return; } - this.recipesPage$ = this.recipesService.getRecipesByClue(this.searchInput).pipe( + this.recipesService.getRecipesByClue(this.searchInput).pipe( map(recipes => new Page(0, 0, recipes, true)) + ).subscribe( + recipes => { + this.recipesPage = recipes; + this.recipesPage$.next(this.recipesPage); + } ); } } From 9aacf8c8b209704c4ec3c6462278988d625acae8 Mon Sep 17 00:00:00 2001 From: sebferrer Date: Fri, 21 May 2021 16:56:55 +0200 Subject: [PATCH 6/9] admin routes + security fix --- back/src/controllers/recipes.controller.ts | 7 +++++++ front/src/app/pages/admin/admin.component.html | 2 +- front/src/app/pages/login/login.module.ts | 3 ++- front/src/app/routing/app-routing.module.ts | 12 ++++++++---- .../app/shared/routing/resolvers/recipe.resolver.ts | 1 - 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/back/src/controllers/recipes.controller.ts b/back/src/controllers/recipes.controller.ts index bee605f..1f90253 100644 --- a/back/src/controllers/recipes.controller.ts +++ b/back/src/controllers/recipes.controller.ts @@ -77,6 +77,13 @@ export class RecipesController extends AController { } public update(request: Request, response: Response): void { + let loginController = new LoginController() + if (!loginController.isLogged(request)) { + response.status(403); + response.send('Vous devez être identifié en tant qu\'admin'); + return; + } + delete request.body._id; const pictureRegex = new RegExp('^data:image', 'i'); const picture = request.body.mainPicture; diff --git a/front/src/app/pages/admin/admin.component.html b/front/src/app/pages/admin/admin.component.html index ac643ec..ea4aa4e 100644 --- a/front/src/app/pages/admin/admin.component.html +++ b/front/src/app/pages/admin/admin.component.html @@ -25,7 +25,7 @@

{{ recipe.name }}

- diff --git a/front/src/app/pages/login/login.module.ts b/front/src/app/pages/login/login.module.ts index 5cc3f5b..b9570b0 100644 --- a/front/src/app/pages/login/login.module.ts +++ b/front/src/app/pages/login/login.module.ts @@ -8,6 +8,7 @@ import { AuthGuard, IAuthGuardData, SharedModule } from '@curry-chronicles/share import { FormlyModule } from '@ngx-formly/core'; import { FormlyMaterialModule } from '@ngx-formly/material'; import { LoginComponent } from './login.component'; +import { CURRY_CHRONICLES_FORMLY_CONFIG } from '../recipe-edition/forms'; const routes: Routes = [ { @@ -30,7 +31,7 @@ const routes: Routes = [ MatCardModule, MatButtonModule, FormsModule, - FormlyModule, + FormlyModule.forRoot(CURRY_CHRONICLES_FORMLY_CONFIG), FormlyMaterialModule, ReactiveFormsModule ], diff --git a/front/src/app/routing/app-routing.module.ts b/front/src/app/routing/app-routing.module.ts index 3b1ca99..71848c1 100644 --- a/front/src/app/routing/app-routing.module.ts +++ b/front/src/app/routing/app-routing.module.ts @@ -4,7 +4,7 @@ import { RouterModule, Routes } from '@angular/router'; const routes: Routes = [ { path: '', - loadChildren: () => import('../pages/home').then(m => m.HomeModule), + loadChildren: () => import('../pages/home').then(m => m.HomeModule) }, { path: 'login', @@ -15,12 +15,16 @@ const routes: Routes = [ loadChildren: () => import('../pages/admin').then(m => m.AdminModule) }, { - path: ':recipeId', - loadChildren: () => import('../pages/recipe').then(m => m.RecipeModule), + path: 'admin/add-recipe', + loadChildren: () => import('../pages/recipe-edition').then(m => m.RecipeEditionModule) }, { - path: 'edit/:recipeId', + path: 'admin/edit/:recipeId', loadChildren: () => import('../pages/recipe-edition').then(m => m.RecipeEditionModule) + }, + { + path: ':recipeId', + loadChildren: () => import('../pages/recipe').then(m => m.RecipeModule) } ]; diff --git a/front/src/app/shared/routing/resolvers/recipe.resolver.ts b/front/src/app/shared/routing/resolvers/recipe.resolver.ts index 7e23aa8..6bf80ec 100644 --- a/front/src/app/shared/routing/resolvers/recipe.resolver.ts +++ b/front/src/app/shared/routing/resolvers/recipe.resolver.ts @@ -15,7 +15,6 @@ export class RecipeResolver implements Resolve { public resolve(route: ActivatedRouteSnapshot, _: RouterStateSnapshot): Observable { const recipeId = route?.params?.recipeId as string; if (recipeId == null) { - this.router.navigateByUrl('/'); return of(null); } return this.recipesService.getRecipeById(recipeId).pipe( From f884b4fb5116ad7a2d182f8cc7417f78c3ec15fb Mon Sep 17 00:00:00 2001 From: sebferrer Date: Mon, 24 May 2021 12:33:14 +0200 Subject: [PATCH 7/9] home thumbnails tweaking --- .../recipe-thumbnail.component.html | 1 + .../recipe-thumbnail.component.scss | 29 +++++++++++++++---- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/front/src/app/pages/home/components/recipe-thumbnail/recipe-thumbnail.component.html b/front/src/app/pages/home/components/recipe-thumbnail/recipe-thumbnail.component.html index d1df114..1c846b5 100644 --- a/front/src/app/pages/home/components/recipe-thumbnail/recipe-thumbnail.component.html +++ b/front/src/app/pages/home/components/recipe-thumbnail/recipe-thumbnail.component.html @@ -2,6 +2,7 @@

{{ recipe.name }}

+